Tempus  Version of the Day
Time Integration
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  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model,
50  std::string stepperType = "Forward Euler")
51  {
52  if (stepperType == "") stepperType = "Forward Euler";
53  return this->createStepper(model, stepperType, Teuchos::null);
54  }
55 
56  /// Create stepper from ParameterList with its details.
57  Teuchos::RCP<Stepper<Scalar> > createStepper(
58  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model,
59  Teuchos::RCP<Teuchos::ParameterList> stepperPL)
60  {
61  std::string stepperType = "Forward Euler";
62  if (stepperPL != Teuchos::null)
63  stepperType = stepperPL->get<std::string>("Stepper Type","Forward Euler");
64  return this->createStepper(model, stepperType, stepperPL);
65  }
66 
67  /// Create stepper from ParameterList with its details.
68  Teuchos::RCP<Stepper<Scalar> > createStepper(
69  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > models,
70  Teuchos::RCP<Teuchos::ParameterList> stepperPL)
71  {
72  std::string stepperType = stepperPL->get<std::string>("Stepper Type");
73  return this->createStepper(models, stepperType, stepperPL);
74  }
75 
76 private:
77  /// Very simple factory method
78  Teuchos::RCP<Stepper<Scalar> > createStepper(
79  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model,
80  std::string stepperType,
81  Teuchos::RCP<Teuchos::ParameterList> stepperPL)
82  {
83  using Teuchos::rcp;
84  if (stepperType == "Forward Euler")
85  return rcp(new StepperForwardEuler<Scalar>(model, stepperPL));
86  else if (stepperType == "Backward Euler")
87  return rcp(new StepperBackwardEuler<Scalar>(model, stepperPL));
88  else if (stepperType == "Trapezoidal Method")
89  return rcp(new StepperTrapezoidal<Scalar>(model, stepperPL));
90  else if (stepperType == "BDF2")
91  return rcp(new StepperBDF2<Scalar>(model, stepperPL));
92  else if (stepperType == "Newmark Implicit a-Form")
93  return rcp(new StepperNewmarkImplicitAForm<Scalar>(model, stepperPL));
94  else if (stepperType == "Newmark Implicit d-Form")
95  return rcp(new StepperNewmarkImplicitDForm<Scalar>(model, stepperPL));
96  else if (stepperType == "Newmark Explicit a-Form")
97  return rcp(new StepperNewmarkExplicitAForm<Scalar>(model, stepperPL));
98  else if (stepperType == "HHT-Alpha")
99  return rcp(new StepperHHTAlpha<Scalar>(model, stepperPL));
100  else if (
101  stepperType == "RK Forward Euler" ||
102  stepperType == "RK Explicit 4 Stage" ||
103  stepperType == "RK Explicit 3/8 Rule" ||
104  stepperType == "RK Explicit 4 Stage 3rd order by Runge" ||
105  stepperType == "RK Explicit 5 Stage 3rd order by Kinnmark and Gray"||
106  stepperType == "RK Explicit 3 Stage 3rd order" ||
107  stepperType == "RK Explicit 3 Stage 3rd order TVD" ||
108  stepperType == "RK Explicit 3 Stage 3rd order by Heun" ||
109  stepperType == "RK Explicit 2 Stage 2nd order by Runge" ||
110  stepperType == "RK Explicit Trapezoidal" ||
111  stepperType == "Bogacki-Shampine 3(2) Pair" ||
112  stepperType == "Merson 4(5) Pair" ||
113  stepperType == "General ERK" )
114  return rcp(new StepperExplicitRK<Scalar>(model, stepperType, stepperPL));
115  else if (
116  stepperType == "RK Backward Euler" ||
117  stepperType == "IRK 1 Stage Theta Method" ||
118  stepperType == "Implicit Midpoint" ||
119  stepperType == "SDIRK 1 Stage 1st order" ||
120  stepperType == "SDIRK 2 Stage 2nd order" ||
121  stepperType == "SDIRK 2 Stage 3rd order" ||
122  stepperType == "EDIRK 2 Stage 3rd order" ||
123  stepperType == "EDIRK 2 Stage Theta Method" ||
124  stepperType == "SDIRK 3 Stage 4th order" ||
125  stepperType == "SDIRK 5 Stage 4th order" ||
126  stepperType == "SDIRK 5 Stage 5th order" ||
127  stepperType == "SDIRK 2(1) Pair" ||
128  stepperType == "General DIRK"
129  )
130  return rcp(new StepperDIRK<Scalar>(model, stepperType, stepperPL));
131  else if (
132  stepperType == "RK Implicit 3 Stage 6th Order Kuntzmann & Butcher" ||
133  stepperType == "RK Implicit 4 Stage 8th Order Kuntzmann & Butcher" ||
134  stepperType == "RK Implicit 2 Stage 4th Order Hammer & Hollingsworth" ||
135  stepperType == "RK Implicit 1 Stage 2nd order Gauss" ||
136  stepperType == "RK Implicit 2 Stage 4th order Gauss" ||
137  stepperType == "RK Implicit 3 Stage 6th order Gauss" ||
138  stepperType == "RK Implicit 1 Stage 1st order Radau left" ||
139  stepperType == "RK Implicit 2 Stage 3rd order Radau left" ||
140  stepperType == "RK Implicit 3 Stage 5th order Radau left" ||
141  stepperType == "RK Implicit 1 Stage 1st order Radau right" ||
142  stepperType == "RK Implicit 2 Stage 3rd order Radau right" ||
143  stepperType == "RK Implicit 3 Stage 5th order Radau right" ||
144  stepperType == "RK Implicit 2 Stage 2nd order Lobatto A" ||
145  stepperType == "RK Implicit 3 Stage 4th order Lobatto A" ||
146  stepperType == "RK Implicit 4 Stage 6th order Lobatto A" ||
147  stepperType == "RK Implicit 2 Stage 2nd order Lobatto B" ||
148  stepperType == "RK Implicit 3 Stage 4th order Lobatto B" ||
149  stepperType == "RK Implicit 4 Stage 6th order Lobatto B" ||
150  stepperType == "RK Implicit 2 Stage 2nd order Lobatto C" ||
151  stepperType == "RK Implicit 3 Stage 4th order Lobatto C" ||
152  stepperType == "RK Implicit 4 Stage 6th order Lobatto C" ) {
153  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
154  "Error - Implicit RK not implemented yet!.\n");
155  }
156  else if (
157  stepperType == "IMEX RK 1st order" ||
158  stepperType == "IMEX RK SSP2" ||
159  stepperType == "IMEX RK ARS 233" ||
160  stepperType == "General IMEX RK" )
161  return rcp(new StepperIMEX_RK<Scalar>(model, stepperType, stepperPL));
162  else if (
163  stepperType == "Partitioned IMEX RK 1st order" ||
164  stepperType == "Partitioned IMEX RK SSP2" ||
165  stepperType == "Partitioned IMEX RK ARS 233" ||
166  stepperType == "General Partitioned IMEX RK" )
167  return rcp(new StepperIMEX_RK_Partition<Scalar>(
168  model, stepperType, stepperPL));
169  else if (stepperType == "Leapfrog")
170  return rcp(new StepperLeapfrog<Scalar>(model, stepperPL));
171  else {
172  Teuchos::RCP<Teuchos::FancyOStream> out =
173  Teuchos::VerboseObjectBase::getDefaultOStream();
174  Teuchos::OSTab ostab(out,1,"StepperFactory::createStepper");
175  *out
176  << "Unknown Stepper Type! Here is a list of available Steppers.\n"
177  << " One-Step Methods:\n"
178  << " 'Forward Euler'\n"
179  << " 'Backward Euler'\n"
180  << " 'Trapezoidal Method'\n"
181  << " Multi-Step Methods:\n"
182  << " 'BDF2'\n"
183  << " Second-order PDE Methods:\n"
184  << " 'Leapfrog'\n"
185  << " 'Newmark Implicit a-Form'\n"
186  << " 'Newmark Implicit d-Form'\n"
187  << " 'Newmark Explicit a-Form'\n"
188  << " 'HHT-Alpha'\n"
189  << " Explicit Runge-Kutta Methods:\n"
190  << " 'RK Forward Euler'\n"
191  << " 'RK Explicit 4 Stage'\n"
192  << " 'RK Explicit 3/8 Rule'\n"
193  << " 'RK Explicit 4 Stage 3rd order by Runge'\n"
194  << " 'RK Explicit 5 Stage 3rd order by Kinnmark and Gray'\n"
195  << " 'RK Explicit 3 Stage 3rd order'\n"
196  << " 'RK Explicit 3 Stage 3rd order TVD'\n"
197  << " 'RK Explicit 3 Stage 3rd order by Heun'\n"
198  << " 'RK Explicit 2 Stage 2nd order by Runge'\n"
199  << " 'RK Explicit Trapezoidal'\n"
200  << " 'Bogacki-Shampine 3(2) Pair'\n"
201  << " 'General ERK'\n"
202  << " Implicit Runge-Kutta Methods:\n"
203  << " 'RK Backward Euler'\n"
204  << " 'IRK 1 Stage Theta Method'\n"
205  << " 'SDIRK 1 Stage 1st order'\n"
206  << " 'SDIRK 2 Stage 2nd order'\n"
207  << " 'SDIRK 2 Stage 3rd order'\n"
208  << " 'EDIRK 2 Stage 3rd order'\n"
209  << " 'EDIRK 2 Stage Theta Method'\n"
210  << " 'SDIRK 3 Stage 4th order'\n"
211  << " 'SDIRK 5 Stage 4th order'\n"
212  << " 'SDIRK 5 Stage 5th order'\n"
213  << " 'General DIRK'\n"
214  << " Implicit-Explicit (IMEX) Methods:\n"
215  << " 'IMEX RK 1st order'\n"
216  << " 'IMEX RK SSP2'\n"
217  << " 'IMEX RK ARS 233'\n"
218  << " 'General IMEX RK'\n"
219  << " 'Partitioned IMEX RK 1st order'\n"
220  << " 'Partitioned IMEX RK SSP2'\n"
221  << " 'Partitioned IMEX RK ARS 233'\n"
222  << " 'General Partitioned IMEX RK'\n"
223  << " Steppers with subSteppers:\n"
224  << " 'Operator Split'\n"
225  << std::endl;
226  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
227  "Unknown 'Stepper Type' = " << stepperType);
228  }
229  }
230 
231  Teuchos::RCP<Stepper<Scalar> > createStepper(
232  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > models,
233  std::string stepperType,
234  Teuchos::RCP<Teuchos::ParameterList> stepperPL)
235  {
236  if (stepperType == "Operator Split")
237  return rcp(new StepperOperatorSplit<Scalar>(models, stepperPL));
238  else {
239  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
240  "Unknown 'Stepper Type' = " << stepperType);
241  }
242  }
243 
244 };
245 
246 
247 } // namespace Tempus
248 #endif // Tempus_StepperFactory_hpp
Tempus::StepperExplicitRK
Explicit Runge-Kutta time stepper.
Definition: Tempus_StepperExplicitRK_decl.hpp:64
Tempus::StepperFactory::~StepperFactory
virtual ~StepperFactory()
Destructor.
Definition: Tempus_StepperFactory.hpp:45
Tempus::StepperLeapfrog
Leapfrog time stepper.
Definition: Tempus_StepperLeapfrog_decl.hpp:71
Tempus::StepperFactory::createStepper
Teuchos::RCP< Stepper< Scalar > > createStepper(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > > models, std::string stepperType, Teuchos::RCP< Teuchos::ParameterList > stepperPL)
Definition: Tempus_StepperFactory.hpp:231
Tempus
Definition: Tempus_AdjointAuxSensitivityModelEvaluator_decl.hpp:20
Tempus::StepperForwardEuler
Forward Euler time stepper.
Definition: Tempus_StepperForwardEuler_decl.hpp:42
Tempus::StepperFactory::createStepper
Teuchos::RCP< Stepper< Scalar > > createStepper(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, std::string stepperType="Forward Euler")
Create default stepper from stepper type (e.g., "Forward Euler").
Definition: Tempus_StepperFactory.hpp:48
Tempus::StepperIMEX_RK_Partition
Partitioned Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
Definition: Tempus_StepperIMEX_RK_Partition_decl.hpp:228
Tempus::StepperFactory::StepperFactory
StepperFactory()
Constructor.
Definition: Tempus_StepperFactory.hpp:42
Tempus::StepperNewmarkExplicitAForm
Newmark Explicit time stepper. This is the specific case of the more general Newmark time stepper in ...
Definition: Tempus_StepperNewmarkExplicitAForm_decl.hpp:23
Tempus::StepperNewmarkImplicitAForm
Newmark time stepper in acceleration form (a-form).
Definition: Tempus_StepperNewmarkImplicitAForm_decl.hpp:41
Tempus::StepperOperatorSplit
OperatorSplit stepper loops through the Stepper list.
Definition: Tempus_StepperOperatorSplit_decl.hpp:35
Tempus::StepperFactory::createStepper
Teuchos::RCP< Stepper< Scalar > > createStepper(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > stepperPL)
Create stepper from ParameterList with its details.
Definition: Tempus_StepperFactory.hpp:57
Tempus::StepperHHTAlpha
HHT-Alpha time stepper.
Definition: Tempus_StepperHHTAlpha_decl.hpp:41
Tempus::StepperDIRK
Diagonally Implicit Runge-Kutta (DIRK) time stepper.
Definition: Tempus_StepperDIRK_decl.hpp:84
Tempus::StepperBackwardEuler
Backward Euler time stepper.
Definition: Tempus_StepperBackwardEuler_decl.hpp:33
Tempus::StepperFactory::createStepper
Teuchos::RCP< Stepper< Scalar > > createStepper(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > > models, Teuchos::RCP< Teuchos::ParameterList > stepperPL)
Create stepper from ParameterList with its details.
Definition: Tempus_StepperFactory.hpp:68
Tempus::StepperIMEX_RK
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
Definition: Tempus_StepperIMEX_RK_decl.hpp:230
Tempus::StepperNewmarkImplicitDForm
Newmark time stepper.
Definition: Tempus_StepperNewmarkImplicitDForm_decl.hpp:38
Tempus::StepperBDF2
BDF2 (Backward-Difference-Formula-2) time stepper.
Definition: Tempus_StepperBDF2_decl.hpp:44
Tempus::StepperTrapezoidal
Trapezoidal method time stepper.
Definition: Tempus_StepperTrapezoidal_decl.hpp:32
Tempus::StepperFactory::createStepper
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.
Definition: Tempus_StepperFactory.hpp:78