Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_StepperFactory.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef Tempus_StepperFactory_hpp
10 #define Tempus_StepperFactory_hpp
11 
12 #include "Teuchos_ParameterList.hpp"
13 #include "Tempus_StepperForwardEuler.hpp"
14 #include "Tempus_StepperBackwardEuler.hpp"
15 #include "Tempus_StepperBDF2.hpp"
16 #include "Tempus_StepperNewmarkImplicitAForm.hpp"
17 #include "Tempus_StepperNewmarkImplicitDForm.hpp"
18 #include "Tempus_StepperNewmarkExplicitAForm.hpp"
19 #include "Tempus_StepperHHTAlpha.hpp"
20 #include "Tempus_StepperExplicitRK.hpp"
21 #include "Tempus_StepperDIRK.hpp"
22 #include "Tempus_StepperIMEX_RK.hpp"
23 #include "Tempus_StepperIMEX_RK_Partition.hpp"
24 #include "Tempus_StepperLeapfrog.hpp"
25 #include "Tempus_StepperOperatorSplit.hpp"
26 #include "Tempus_StepperTrapezoidal.hpp"
27 
28 
29 namespace Tempus {
30 
31 /** \brief Stepper factory.
32  *
33  * <b>Adding Steppers</b>
34  * -#
35  */
36 template<class Scalar>
37 class StepperFactory
38 {
39 public:
40 
41  /// Constructor
43 
44  /// Destructor
45  virtual ~StepperFactory() {}
46 
47  /// Create default stepper from stepper type (e.g., "Forward Euler").
48  Teuchos::RCP<Stepper<Scalar> > createStepper(
49  std::string stepperType = "Forward Euler",
50  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >&
51  model = Teuchos::null)
52  {
53  if (stepperType == "") stepperType = "Forward Euler";
54  return this->createStepper(model, stepperType, Teuchos::null);
55  }
56 
57  /// Create stepper from ParameterList with its details.
58  Teuchos::RCP<Stepper<Scalar> > createStepper(
59  Teuchos::RCP<Teuchos::ParameterList> stepperPL,
60  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >&
61  model = Teuchos::null)
62  {
63  std::string stepperType = "Forward Euler";
64  if (stepperPL != Teuchos::null)
65  stepperType = stepperPL->get<std::string>("Stepper Type","Forward Euler");
66  return this->createStepper(model, stepperType, stepperPL);
67  }
68 
69  /// Create stepper from ParameterList with its details.
70  Teuchos::RCP<Stepper<Scalar> > createStepper(
71  Teuchos::RCP<Teuchos::ParameterList> stepperPL,
72  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > >
73  models = Teuchos::null)
74  {
75  std::string stepperType = stepperPL->get<std::string>("Stepper Type");
76  return this->createStepper(models, stepperType, stepperPL);
77  }
78 
79 private:
80  /// Very simple factory method
81  Teuchos::RCP<Stepper<Scalar> > createStepper(
82  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model,
83  std::string stepperType,
84  Teuchos::RCP<Teuchos::ParameterList> stepperPL)
85  {
86  using Teuchos::rcp;
87  if (stepperType == "Forward Euler")
88  return rcp(new StepperForwardEuler<Scalar>(model, stepperPL));
89  else if (stepperType == "Backward Euler")
90  return rcp(new StepperBackwardEuler<Scalar>(model, stepperPL));
91  else if (stepperType == "Trapezoidal Method")
92  return rcp(new StepperTrapezoidal<Scalar>(model, stepperPL));
93  else if (stepperType == "BDF2")
94  return rcp(new StepperBDF2<Scalar>(model, stepperPL));
95  else if (stepperType == "Newmark Implicit a-Form")
96  return rcp(new StepperNewmarkImplicitAForm<Scalar>(model, stepperPL));
97  else if (stepperType == "Newmark Implicit d-Form")
98  return rcp(new StepperNewmarkImplicitDForm<Scalar>(model, stepperPL));
99  else if (stepperType == "Newmark Explicit a-Form")
100  return rcp(new StepperNewmarkExplicitAForm<Scalar>(model, stepperPL));
101  else if (stepperType == "HHT-Alpha")
102  return rcp(new StepperHHTAlpha<Scalar>(model, stepperPL));
103  else if (
104  stepperType == "RK Forward Euler" ||
105  stepperType == "RK Explicit 4 Stage" ||
106  stepperType == "RK Explicit 3/8 Rule" ||
107  stepperType == "RK Explicit 4 Stage 3rd order by Runge" ||
108  stepperType == "RK Explicit 5 Stage 3rd order by Kinnmark and Gray"||
109  stepperType == "RK Explicit 3 Stage 3rd order" ||
110  stepperType == "RK Explicit 3 Stage 3rd order TVD" ||
111  stepperType == "RK Explicit 3 Stage 3rd order by Heun" ||
112  stepperType == "RK Explicit 2 Stage 2nd order by Runge" ||
113  stepperType == "RK Explicit Trapezoidal" ||
114  stepperType == "Bogacki-Shampine 3(2) Pair" ||
115  stepperType == "Merson 4(5) Pair" ||
116  stepperType == "General ERK" )
117  return rcp(new StepperExplicitRK<Scalar>(model, stepperType, stepperPL));
118  else if (
119  stepperType == "RK Backward Euler" ||
120  stepperType == "IRK 1 Stage Theta Method" ||
121  stepperType == "Implicit Midpoint" ||
122  stepperType == "SDIRK 1 Stage 1st order" ||
123  stepperType == "SDIRK 2 Stage 2nd order" ||
124  stepperType == "SDIRK 2 Stage 3rd order" ||
125  stepperType == "EDIRK 2 Stage 3rd order" ||
126  stepperType == "EDIRK 2 Stage Theta Method" ||
127  stepperType == "SDIRK 3 Stage 4th order" ||
128  stepperType == "SDIRK 5 Stage 4th order" ||
129  stepperType == "SDIRK 5 Stage 5th order" ||
130  stepperType == "SDIRK 2(1) Pair" ||
131  stepperType == "General DIRK"
132  )
133  return rcp(new StepperDIRK<Scalar>(model, stepperType, stepperPL));
134  else if (
135  stepperType == "RK Implicit 3 Stage 6th Order Kuntzmann & Butcher" ||
136  stepperType == "RK Implicit 4 Stage 8th Order Kuntzmann & Butcher" ||
137  stepperType == "RK Implicit 2 Stage 4th Order Hammer & Hollingsworth" ||
138  stepperType == "RK Implicit 1 Stage 2nd order Gauss" ||
139  stepperType == "RK Implicit 2 Stage 4th order Gauss" ||
140  stepperType == "RK Implicit 3 Stage 6th order Gauss" ||
141  stepperType == "RK Implicit 1 Stage 1st order Radau left" ||
142  stepperType == "RK Implicit 2 Stage 3rd order Radau left" ||
143  stepperType == "RK Implicit 3 Stage 5th order Radau left" ||
144  stepperType == "RK Implicit 1 Stage 1st order Radau right" ||
145  stepperType == "RK Implicit 2 Stage 3rd order Radau right" ||
146  stepperType == "RK Implicit 3 Stage 5th order Radau right" ||
147  stepperType == "RK Implicit 2 Stage 2nd order Lobatto A" ||
148  stepperType == "RK Implicit 3 Stage 4th order Lobatto A" ||
149  stepperType == "RK Implicit 4 Stage 6th order Lobatto A" ||
150  stepperType == "RK Implicit 2 Stage 2nd order Lobatto B" ||
151  stepperType == "RK Implicit 3 Stage 4th order Lobatto B" ||
152  stepperType == "RK Implicit 4 Stage 6th order Lobatto B" ||
153  stepperType == "RK Implicit 2 Stage 2nd order Lobatto C" ||
154  stepperType == "RK Implicit 3 Stage 4th order Lobatto C" ||
155  stepperType == "RK Implicit 4 Stage 6th order Lobatto C" ) {
156  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
157  "Error - Implicit RK not implemented yet!.\n");
158  }
159  else if (
160  stepperType == "IMEX RK 1st order" ||
161  stepperType == "IMEX RK SSP2" ||
162  stepperType == "IMEX RK ARS 233" ||
163  stepperType == "General IMEX RK" )
164  return rcp(new StepperIMEX_RK<Scalar>(model, stepperType, stepperPL));
165  else if (
166  stepperType == "Partitioned IMEX RK 1st order" ||
167  stepperType == "Partitioned IMEX RK SSP2" ||
168  stepperType == "Partitioned IMEX RK ARS 233" ||
169  stepperType == "General Partitioned IMEX RK" )
170  return rcp(new StepperIMEX_RK_Partition<Scalar>(
171  model, stepperType, stepperPL));
172  else if (stepperType == "Leapfrog")
173  return rcp(new StepperLeapfrog<Scalar>(model, stepperPL));
174  else {
175  Teuchos::RCP<Teuchos::FancyOStream> out =
176  Teuchos::VerboseObjectBase::getDefaultOStream();
177  Teuchos::OSTab ostab(out,1,"StepperFactory::createStepper");
178  *out
179  << "Unknown Stepper Type! Here is a list of available Steppers.\n"
180  << " One-Step Methods:\n"
181  << " 'Forward Euler'\n"
182  << " 'Backward Euler'\n"
183  << " 'Trapezoidal Method'\n"
184  << " Multi-Step Methods:\n"
185  << " 'BDF2'\n"
186  << " Second-order PDE Methods:\n"
187  << " 'Leapfrog'\n"
188  << " 'Newmark Implicit a-Form'\n"
189  << " 'Newmark Implicit d-Form'\n"
190  << " 'Newmark Explicit a-Form'\n"
191  << " 'HHT-Alpha'\n"
192  << " Explicit Runge-Kutta Methods:\n"
193  << " 'RK Forward Euler'\n"
194  << " 'RK Explicit 4 Stage'\n"
195  << " 'RK Explicit 3/8 Rule'\n"
196  << " 'RK Explicit 4 Stage 3rd order by Runge'\n"
197  << " 'RK Explicit 5 Stage 3rd order by Kinnmark and Gray'\n"
198  << " 'RK Explicit 3 Stage 3rd order'\n"
199  << " 'RK Explicit 3 Stage 3rd order TVD'\n"
200  << " 'RK Explicit 3 Stage 3rd order by Heun'\n"
201  << " 'RK Explicit 2 Stage 2nd order by Runge'\n"
202  << " 'RK Explicit Trapezoidal'\n"
203  << " 'Bogacki-Shampine 3(2) Pair'\n"
204  << " 'General ERK'\n"
205  << " Implicit Runge-Kutta Methods:\n"
206  << " 'RK Backward Euler'\n"
207  << " 'IRK 1 Stage Theta Method'\n"
208  << " 'SDIRK 1 Stage 1st order'\n"
209  << " 'SDIRK 2 Stage 2nd order'\n"
210  << " 'SDIRK 2 Stage 3rd order'\n"
211  << " 'EDIRK 2 Stage 3rd order'\n"
212  << " 'EDIRK 2 Stage Theta Method'\n"
213  << " 'SDIRK 3 Stage 4th order'\n"
214  << " 'SDIRK 5 Stage 4th order'\n"
215  << " 'SDIRK 5 Stage 5th order'\n"
216  << " 'General DIRK'\n"
217  << " Implicit-Explicit (IMEX) Methods:\n"
218  << " 'IMEX RK 1st order'\n"
219  << " 'IMEX RK SSP2'\n"
220  << " 'IMEX RK ARS 233'\n"
221  << " 'General IMEX RK'\n"
222  << " 'Partitioned IMEX RK 1st order'\n"
223  << " 'Partitioned IMEX RK SSP2'\n"
224  << " 'Partitioned IMEX RK ARS 233'\n"
225  << " 'General Partitioned IMEX RK'\n"
226  << " Steppers with subSteppers:\n"
227  << " 'Operator Split'\n"
228  << std::endl;
229  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
230  "Unknown 'Stepper Type' = " << stepperType);
231  }
232  }
233 
234  Teuchos::RCP<Stepper<Scalar> > createStepper(
235  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > models,
236  std::string stepperType,
237  Teuchos::RCP<Teuchos::ParameterList> stepperPL)
238  {
239  if (stepperType == "Operator Split")
240  return rcp(new StepperOperatorSplit<Scalar>(models, stepperPL));
241  else {
242  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
243  "Unknown 'Stepper Type' = " << stepperType);
244  }
245  }
246 
247 };
248 
249 
250 } // namespace Tempus
251 #endif // Tempus_StepperFactory_hpp
BDF2 (Backward-Difference-Formula-2) time stepper.
virtual ~StepperFactory()
Destructor.
Teuchos::RCP< Stepper< Scalar > > createStepper(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > > models, std::string stepperType, Teuchos::RCP< Teuchos::ParameterList > stepperPL)
Trapezoidal method time stepper.
Explicit Runge-Kutta time stepper.
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
Partitioned Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
Teuchos::RCP< Stepper< Scalar > > createStepper(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, std::string stepperType, Teuchos::RCP< Teuchos::ParameterList > stepperPL)
Very simple factory method.
OperatorSplit stepper loops through the Stepper list.
Diagonally Implicit Runge-Kutta (DIRK) time stepper.
Teuchos::RCP< Stepper< Scalar > > createStepper(Teuchos::RCP< Teuchos::ParameterList > stepperPL, std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > > models=Teuchos::null)
Create stepper from ParameterList with its details.
Teuchos::RCP< Stepper< Scalar > > createStepper(Teuchos::RCP< Teuchos::ParameterList > stepperPL, const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model=Teuchos::null)
Create stepper from ParameterList with its details.
Teuchos::RCP< Stepper< Scalar > > createStepper(std::string stepperType="Forward Euler", const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model=Teuchos::null)
Create default stepper from stepper type (e.g., &quot;Forward Euler&quot;).
Newmark time stepper in acceleration form (a-form).