Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs Pages
Rythmos_StepperBuilder.hpp
1 //@HEADER
2 // ***********************************************************************
3 //
4 // Rythmos Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
25 //
26 // ***********************************************************************
27 //@HEADER
28 
29 #ifndef Rythmos_STEPPER_BUILDER_NEWNEW_H
30 #define Rythmos_STEPPER_BUILDER_NEWNEW_H
31 
32 #include "Rythmos_Types.hpp"
33 #include "Rythmos_StepperBase.hpp"
34 
35 #include "Teuchos_ObjectBuilder.hpp"
36 #include "Teuchos_ParameterList.hpp"
37 
38 #include "Rythmos_BackwardEulerStepper.hpp"
39 #include "Rythmos_ImplicitBDFStepper.hpp"
40 #include "Rythmos_ForwardEulerStepper.hpp"
41 #include "Rythmos_ExplicitRKStepper.hpp"
42 #include "Rythmos_ImplicitRKStepper.hpp"
43 #ifdef HAVE_THYRA_ME_POLYNOMIAL
44 # include "Rythmos_ExplicitTaylorPolynomialStepper.hpp"
45 #endif // HAVE_THYRA_ME_POLYNOMIAL
46 #ifdef HAVE_RYTHMOS_EXPERIMENTAL
47 #include "Rythmos_ThetaStepper.hpp"
48 #endif // HAVE_RYTHMOS_EXPERIMENTAL
49 
50 namespace Rythmos {
51 
52 
53 template<class Scalar>
54  class StepperBuilder : virtual public Teuchos::ParameterListAcceptor
55 {
56 public:
57 
59  StepperBuilder();
60 
62  ~StepperBuilder();
63 
65  void setStepperFactory(
66  const RCP<const Teuchos::AbstractFactory<StepperBase<Scalar> > > &stepperFactory,
67  const std::string &stepperFactoryName
68  );
69 
73  std::string getStepperName() const;
74 
76  RCP<StepperBase<Scalar> > create(
77  const std::string &stepperName = ""
78  ) const;
79 
82 
84  void setParameterList(const RCP<Teuchos::ParameterList> & paramList);
85 
87  RCP<Teuchos::ParameterList> getNonconstParameterList();
88 
90  RCP<Teuchos::ParameterList> unsetParameterList();
91 
93  RCP<const ParameterList> getParameterList() const;
94 
96  RCP<const Teuchos::ParameterList> getValidParameters() const;
97 
99 
100 private:
101 
102  // //////////////////////////////////////
103  // Private data members
104 
105  Teuchos::ObjectBuilder<StepperBase<Scalar> > builder_;
106 
107  // //////////////////////////////////////
108  // Private member functions
109 
110  void initializeDefaults_();
111 
112 };
113 
114 
115 // Nonmember constructor
116 template<class Scalar>
117 RCP<StepperBuilder<Scalar> > stepperBuilder()
118 {
119  RCP<StepperBuilder<Scalar> > sb = rcp(new StepperBuilder<Scalar> );
120  return sb;
121 }
122 
123 template<class Scalar>
124 StepperBuilder<Scalar>::StepperBuilder()
125 {
126  this->initializeDefaults_();
127 }
128 
129 // Nonmember helper function
130 template<class Scalar>
131 RCP<StepperBase<Scalar> > createStepper(const std::string &stepperName)
132 {
133  RCP<StepperBuilder<Scalar> > sb = stepperBuilder<Scalar>();
134  RCP<StepperBase<Scalar> > stepper = sb->create(stepperName);
135  return stepper;
136 }
137 
138 template<class Scalar>
139 StepperBuilder<Scalar>::~StepperBuilder()
140 {
141 }
142 
143 
144 template<class Scalar>
145 void StepperBuilder<Scalar>::setStepperFactory(
146  const RCP<const Teuchos::AbstractFactory<StepperBase<Scalar> > > &stepperFactory,
147  const std::string &stepperName
148  )
149 {
150  builder_.setObjectFactory(stepperFactory, stepperName);
151 }
152 
153 
154 template<class Scalar>
155 std::string
156 StepperBuilder<Scalar>::getStepperName() const
157 {
158  return builder_.getObjectName();
159 }
160 
161 
162 template<class Scalar>
163 void StepperBuilder<Scalar>::setParameterList(
164  RCP<Teuchos::ParameterList> const& paramList
165  )
166 {
167  builder_.setParameterList(paramList);
168 }
169 
170 
171 template<class Scalar>
172 RCP<Teuchos::ParameterList>
173 StepperBuilder<Scalar>::getNonconstParameterList()
174 {
175  return builder_.getNonconstParameterList();
176 }
177 
178 
179 template<class Scalar>
180 RCP<Teuchos::ParameterList>
181 StepperBuilder<Scalar>::unsetParameterList()
182 {
183  return builder_.unsetParameterList();
184 }
185 
186 
187 template<class Scalar>
188 RCP<const Teuchos::ParameterList>
189 StepperBuilder<Scalar>::getParameterList() const
190 {
191  return builder_.getParameterList();
192 }
193 
194 
195 template<class Scalar>
196 RCP<const Teuchos::ParameterList>
197 StepperBuilder<Scalar>::getValidParameters() const
198 {
199  return builder_.getValidParameters();
200 }
201 
202 
203 template<class Scalar>
204 RCP<StepperBase<Scalar> >
205 StepperBuilder<Scalar>::create(
206  const std::string &stepperName
207  ) const
208 {
209  return builder_.create(stepperName);
210 }
211 
212 
213 template<class Scalar>
214 void StepperBuilder<Scalar>::initializeDefaults_()
215 {
216 
217  using Teuchos::abstractFactoryStd;
218 
219  builder_.setObjectName("Rythmos::Stepper");
220  builder_.setObjectTypeName("Stepper Type");
221 
222  //
223  // Steppers
224  //
225 
226  builder_.setObjectFactory(
227  abstractFactoryStd< StepperBase<Scalar>, ForwardEulerStepper<Scalar> >(),
228  "Forward Euler"
229  );
230 
231  builder_.setObjectFactory(
232  abstractFactoryStd< StepperBase<Scalar>, BackwardEulerStepper<Scalar> >(),
233  "Backward Euler"
234  );
235 
236  builder_.setObjectFactory(
237  abstractFactoryStd< StepperBase<Scalar>, ImplicitBDFStepper<Scalar> >(),
238  "Implicit BDF"
239  );
240 
241  builder_.setObjectFactory(
242  abstractFactoryStd< StepperBase<Scalar>, ExplicitRKStepper<Scalar> >(),
243  "Explicit RK"
244  );
245 
246  builder_.setObjectFactory(
247  abstractFactoryStd< StepperBase<Scalar>, ImplicitRKStepper<Scalar> >(),
248  "Implicit RK"
249  );
250 
251 #ifdef HAVE_THYRA_ME_POLYNOMIAL
252  builder_.setObjectFactory(
253  abstractFactoryStd< StepperBase<Scalar>, ExplicitTaylorPolynomialStepper<Scalar> >(),
254  "Explicit Taylor Polynomial"
255  );
256 #endif // HAVE_THYRA_ME_POLYNOMIAL
257 
258 #ifdef HAVE_RYTHMOS_EXPERIMENTAL
259  builder_.setObjectFactory(
260  abstractFactoryStd< StepperBase<Scalar>, ThetaStepper<Scalar> >(),
261  "Theta"
262  );
263 #endif // HAVE_RYTHMOS_EXPERIMENTAL
264 
265  builder_.setDefaultObject("Backward Euler");
266 
267 }
268 
269 
270 } // namespace Rythmos
271 
272 
273 #endif //Rythmos_STEPPER_BUILDER_NEWNEW_H
274