Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_Stepper_decl.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_Stepper_decl_hpp
10 #define Tempus_Stepper_decl_hpp
11 
12 //Teuchos
13 #include "Teuchos_TimeMonitor.hpp"
14 //
15 // Thyra
16 #include "Thyra_ModelEvaluator.hpp"
17 #include "Thyra_NonlinearSolverBase.hpp"
18 
19 // Tempus
20 #include "Tempus_config.hpp"
21 #include "Tempus_SolutionHistory.hpp"
23 
24 
25 namespace Tempus {
26 
27 enum OrderODE {
28  FIRST_ORDER_ODE = 1, ///< Stepper integrates first-order ODEs
29  SECOND_ORDER_ODE = 2, ///< Stepper integrates second-order ODEs
30 };
31 
32 /** \brief Thyra Base interface for time steppers.
33  *
34  * <b>Design Considerations</b>
35  * - Time steppers are designed to take a single time step.
36  * - a single implicit solve for a time step
37  * - a single solve for a IMEX time step
38  * - Multiple time steps should be managed by Integrators.
39  * - Steppers can be built from other Sub-Steppers.
40  * - An operator-split Stepper is possible with interoperable Steppers.
41  * - For explicit steppers, only one ModelEvaluator and one solution
42  * vector are required.
43  * - For implicit steppers, only one ModelEvaluator, one solution
44  * vector, and one solver are required.
45  * - Steppers will PASS/FAIL the time step based on Solver, error and
46  * order requirements, and not adjust the time step size.
47  * - Steppers can provide a suggested time step size for the next time step.
48  * - For more complex steppers, multiple ModelEvaluators, solution
49  * vectors, and solvers are possible when a common single time-integration
50  * method is desired for all solutions. Examples:
51  * - Solution A with ModelEvaluator A and Solution B with ModelEvaluator B
52  * using the same solver
53  * - Solution A with ModelEvaluator A using Solver A and Solution B with
54  * ModelEvaluator B using Solver B
55  * - Solution A with ModelEvaluator A using Solver A and Solutions A and B
56  * with ModelEvaluator C using Solver B
57  * - Steppers may maintain their own time history of the solution, e.g.,
58  * BDF steppers.
59  */
60 template<class Scalar>
61 class Stepper
62  : virtual public Teuchos::Describable,
63  virtual public Teuchos::VerboseObject<Stepper<Scalar> >
64 {
65 public:
66 
67  /// \name Basic stepper methods
68  //@{
69  virtual void setModel(
70  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel) = 0;
71  virtual void setNonConstModel(
72  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& appModel) = 0;
73  virtual Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > getModel() = 0;
74 
75  /// Set solver.
76  virtual void setSolver(
77  Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > solver = Teuchos::null) = 0;
78 
79  /// Get solver
80  virtual Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >
81  getSolver() const = 0;
82 
83  /// Set Observer
84  virtual void setObserver(
85  Teuchos::RCP<StepperObserver<Scalar> > obs = Teuchos::null) = 0;
86 
87  /// Get Observer
88  virtual Teuchos::RCP<StepperObserver<Scalar> > getObserver() const = 0;
89 
90 
91  /// Initialize during construction and after changing input parameters.
92  virtual void initialize() = 0;
93 
94  /// Set initial conditions, make them consistent, and set stepper memory.
95  virtual void setInitialConditions (
96  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory) = 0;
97 
98 
99  /// Take the specified timestep, dt, and return true if successful.
100  virtual void takeStep(
101  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory) = 0;
102 
103  /// Pass initial guess to Newton solver (for implicit schemes)
104  virtual void setInitialGuess(
105  Teuchos::RCP<const Thyra::VectorBase<Scalar> > initial_guess = Teuchos::null) = 0;
106 
107  virtual Teuchos::RCP<Tempus::StepperState<Scalar> >
109  virtual Scalar getOrder() const = 0;
110  virtual Scalar getOrderMin() const = 0;
111  virtual Scalar getOrderMax() const = 0;
112  virtual Scalar getInitTimeStep(
113  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory) const = 0;
114 
115  virtual bool isExplicit() const = 0;
116  virtual bool isImplicit() const = 0;
117  virtual bool isExplicitImplicit() const = 0;
118 
119  virtual bool isOneStepMethod() const = 0;
120  virtual bool isMultiStepMethod() const = 0;
121 
122  void setStepperType(std::string s) { stepperType_ = s;}
123  std::string getStepperType() const { return stepperType_; }
124 
125  void setUseFSAL(bool a) { useFSAL_ = a; }
126  bool getUseFSAL() const { return useFSAL_; }
127  virtual bool getUseFSALDefault() const { return false; }
128 
129  void setICConsistency(std::string s) { ICConsistency_ = s;}
130  std::string getICConsistency() const { return ICConsistency_; }
131  virtual std::string getICConsistencyDefault() const { return "None"; }
132 
135  virtual bool getICConsistencyCheckDefault() const { return false; }
136 
137  virtual OrderODE getOrderODE() const = 0;
138  //@}
139 
140  /// \name Overridden from Teuchos::Describable
141  //@{
142  virtual std::string description() const { return stepperType_; }
143  //@}
144 
145  /// \name Functions for Steppers with subSteppers (e.g., OperatorSplit)
146  //@{
147  virtual void createSubSteppers(
148  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > /* models */){}
149  //@}
150 
151  virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const = 0;
152 
153 private:
154  std::string stepperType_; //< Name of stepper type
155  bool useFSAL_; //< Use First-Step-As-Last (FSAL) principle
156  std::string ICConsistency_; //< Type of consistency to apply to ICs.
157  bool ICConsistencyCheck_; //< Check if the initial condition is consistent
158 };
159 
160 
161 /// \name Helper functions
162 //@{
163  /// Provide basic parameters to Steppers.
165  Teuchos::RCP<Teuchos::ParameterList> pl, std::string stepperType);
166 
167  /// Validate that the model supports explicit ODE evaluation, f(x,t) [=xdot]
168  /** Currently the convention to evaluate f(x,t) is to set xdot=null!
169  * There is no InArgs support to test if xdot is null, so we set
170  * xdot=null and hopefully the ModelEvaluator can handle it.
171  */
172  template<class Scalar>
174  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model)
175  {
176  TEUCHOS_TEST_FOR_EXCEPT( is_null(model) );
177  typedef Thyra::ModelEvaluatorBase MEB;
178  const MEB::InArgs<Scalar> inArgs = model->createInArgs();
179  const MEB::OutArgs<Scalar> outArgs = model->createOutArgs();
180  const bool supports = inArgs.supports(MEB::IN_ARG_x) and
181  outArgs.supports(MEB::OUT_ARG_f);
182 
183  TEUCHOS_TEST_FOR_EXCEPTION( supports == false, std::logic_error,
184  model->description() << "can not support an explicit ODE with\n"
185  << " IN_ARG_x = " << inArgs.supports(MEB::IN_ARG_x) << "\n"
186  << " OUT_ARG_f = " << outArgs.supports(MEB::OUT_ARG_f) << "\n"
187  << "Explicit ODE requires:\n"
188  << " IN_ARG_x = true\n"
189  << " OUT_ARG_f = true\n"
190  << "\n"
191  << "NOTE: Currently the convention to evaluate f(x,t) is to set\n"
192  << "xdot=null! There is no InArgs support to test if xdot is null,\n"
193  << "so we set xdot=null and hope the ModelEvaluator can handle it.\n");
194 
195  return;
196  }
197 
198 
199  /// Validate that the model supports explicit second order ODE evaluation, f(x,xdot,t) [=xdotdot]
200  /** Currently the convention to evaluate f(x,xdot,t) is to set xdotdot=null!
201  * There is no InArgs support to test if xdotdot is null, so we set
202  * xdotdot=null and hopefully the ModelEvaluator can handle it.
203  */
204  template<class Scalar>
206  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model)
207  {
208  TEUCHOS_TEST_FOR_EXCEPT( is_null(model) );
209  typedef Thyra::ModelEvaluatorBase MEB;
210  const MEB::InArgs<Scalar> inArgs = model->createInArgs();
211  const MEB::OutArgs<Scalar> outArgs = model->createOutArgs();
212  const bool supports = inArgs.supports(MEB::IN_ARG_x) and
213  inArgs.supports(MEB::IN_ARG_x_dot) and
214  outArgs.supports(MEB::OUT_ARG_f);
215 
216  TEUCHOS_TEST_FOR_EXCEPTION( supports == false, std::logic_error,
217  model->description() << "can not support an explicit ODE with\n"
218  << " IN_ARG_x = " << inArgs.supports(MEB::IN_ARG_x) << "\n"
219  << " IN_ARG_x_dot = " << inArgs.supports(MEB::IN_ARG_x_dot) << "\n"
220  << " OUT_ARG_f = " << outArgs.supports(MEB::OUT_ARG_f) << "\n"
221  << "Explicit ODE requires:\n"
222  << " IN_ARG_x = true\n"
223  << " IN_ARG_x_dot = true\n"
224  << " OUT_ARG_f = true\n"
225  << "\n"
226  << "NOTE: Currently the convention to evaluate f(x, xdot, t) is to\n"
227  << "set xdotdot=null! There is no InArgs support to test if xdotdot\n"
228  << "is null, so we set xdotdot=null and hope the ModelEvaluator can\n"
229  << "handle it.\n");
230 
231  return;
232  }
233 
234 
235  /// Validate ME supports implicit ODE/DAE evaluation, f(xdot,x,t) [= 0]
236  template<class Scalar>
238  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model)
239  {
240  TEUCHOS_TEST_FOR_EXCEPT( is_null(model) );
241  typedef Thyra::ModelEvaluatorBase MEB;
242  const MEB::InArgs<Scalar> inArgs = model->createInArgs();
243  const MEB::OutArgs<Scalar> outArgs = model->createOutArgs();
244  const bool supports = inArgs.supports(MEB::IN_ARG_x) and
245  inArgs.supports(MEB::IN_ARG_x_dot) and
246  inArgs.supports(MEB::IN_ARG_alpha) and
247  inArgs.supports(MEB::IN_ARG_beta) and
248  !inArgs.supports(MEB::IN_ARG_W_x_dot_dot_coeff) and
249  outArgs.supports(MEB::OUT_ARG_f) and
250  outArgs.supports(MEB::OUT_ARG_W);
251 
252  TEUCHOS_TEST_FOR_EXCEPTION( supports == false, std::logic_error,
253  model->description() << " can not support an implicit ODE with\n"
254  << " IN_ARG_x = "
255  << inArgs.supports(MEB::IN_ARG_x) << "\n"
256  << " IN_ARG_x_dot = "
257  << inArgs.supports(MEB::IN_ARG_x_dot) << "\n"
258  << " IN_ARG_alpha = "
259  << inArgs.supports(MEB::IN_ARG_alpha) << "\n"
260  << " IN_ARG_beta = "
261  << inArgs.supports(MEB::IN_ARG_beta) << "\n"
262  << " IN_ARG_W_x_dot_dot_coeff = "
263  << inArgs.supports(MEB::IN_ARG_W_x_dot_dot_coeff) << "\n"
264  << " OUT_ARG_f = "
265  << outArgs.supports(MEB::OUT_ARG_f) << "\n"
266  << " OUT_ARG_W = "
267  << outArgs.supports(MEB::OUT_ARG_W) << "\n"
268  << "Implicit ODE requires:\n"
269  << " IN_ARG_x = true\n"
270  << " IN_ARG_x_dot = true\n"
271  << " IN_ARG_alpha = true\n"
272  << " IN_ARG_beta = true\n"
273  << " IN_ARG_W_x_dot_dot_coeff = false\n"
274  << " OUT_ARG_f = true\n"
275  << " OUT_ARG_W = true\n");
276 
277  return;
278  }
279 
280 
281  /// Validate ME supports 2nd order implicit ODE/DAE evaluation, f(xdotdot,xdot,x,t) [= 0]
282  template<class Scalar>
284  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model)
285  {
286  TEUCHOS_TEST_FOR_EXCEPT( is_null(model) );
287  typedef Thyra::ModelEvaluatorBase MEB;
288  const MEB::InArgs<Scalar> inArgs = model->createInArgs();
289  const MEB::OutArgs<Scalar> outArgs = model->createOutArgs();
290  const bool supports = inArgs.supports(MEB::IN_ARG_x) and
291  inArgs.supports(MEB::IN_ARG_x_dot) and
292  inArgs.supports(MEB::IN_ARG_x_dot_dot) and
293  inArgs.supports(MEB::IN_ARG_alpha) and
294  inArgs.supports(MEB::IN_ARG_beta) and
295  inArgs.supports(MEB::IN_ARG_W_x_dot_dot_coeff) and
296  outArgs.supports(MEB::OUT_ARG_f) and
297  outArgs.supports(MEB::OUT_ARG_W);
298 
299  TEUCHOS_TEST_FOR_EXCEPTION( supports == false, std::logic_error,
300  model->description() << " can not support an implicit ODE with\n"
301  << " IN_ARG_x = "
302  << inArgs.supports(MEB::IN_ARG_x) << "\n"
303  << " IN_ARG_x_dot = "
304  << inArgs.supports(MEB::IN_ARG_x_dot) << "\n"
305  << " IN_ARG_x_dot_dot = "
306  << inArgs.supports(MEB::IN_ARG_x_dot_dot) << "\n"
307  << " IN_ARG_alpha = "
308  << inArgs.supports(MEB::IN_ARG_alpha) << "\n"
309  << " IN_ARG_beta = "
310  << inArgs.supports(MEB::IN_ARG_beta) << "\n"
311  << " IN_ARG_W_x_dot_dot_coeff = "
312  << inArgs.supports(MEB::IN_ARG_W_x_dot_dot_coeff) << "\n"
313  << " OUT_ARG_f = "
314  << outArgs.supports(MEB::OUT_ARG_f) << "\n"
315  << " OUT_ARG_W = "
316  << outArgs.supports(MEB::OUT_ARG_W) << "\n"
317  << "Implicit Second Order ODE requires:\n"
318  << " IN_ARG_x = true\n"
319  << " IN_ARG_x_dot = true\n"
320  << " IN_ARG_x_dot_dot = true\n"
321  << " IN_ARG_alpha = true\n"
322  << " IN_ARG_beta = true\n"
323  << " IN_ARG_W_x_dot_dot_coeff = true\n"
324  << " OUT_ARG_f = true\n"
325  << " OUT_ARG_W = true\n");
326 
327  return;
328  }
329 
330 
331  /// Returns the default solver ParameterList for implicit Steppers.
332  Teuchos::RCP<Teuchos::ParameterList> defaultSolverParameters();
333 //@}
334 
335 
336 } // namespace Tempus
337 #endif // Tempus_Stepper_decl_hpp
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)=0
Set Observer.
virtual Scalar getOrderMax() const =0
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)=0
Take the specified timestep, dt, and return true if successful.
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getModel()=0
virtual OrderODE getOrderODE() const =0
std::string getStepperType() const
bool getUseFSAL() const
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver=Teuchos::null)=0
Set solver.
bool getICConsistencyCheck() const
virtual bool isExplicit() const =0
virtual Teuchos::RCP< StepperObserver< Scalar > > getObserver() const =0
Get Observer.
virtual bool getICConsistencyCheckDefault() const
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
void validExplicitODE(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Validate that the model supports explicit ODE evaluation, f(x,t) [=xdot].
virtual std::string getICConsistencyDefault() const
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)=0
virtual bool isOneStepMethod() const =0
virtual void setInitialGuess(Teuchos::RCP< const Thyra::VectorBase< Scalar > > initial_guess=Teuchos::null)=0
Pass initial guess to Newton solver (for implicit schemes)
virtual void initialize()=0
Initialize during construction and after changing input parameters.
virtual Scalar getOrderMin() const =0
std::string getICConsistency() const
virtual bool isMultiStepMethod() const =0
Stepper integrates second-order ODEs.
virtual std::string description() const
virtual Scalar getInitTimeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory) const =0
void setICConsistencyCheck(bool c)
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
virtual Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > getSolver() const =0
Get solver.
virtual void setNonConstModel(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &appModel)=0
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()=0
Stepper integrates first-order ODEs.
void validSecondOrderExplicitODE(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Validate that the model supports explicit second order ODE evaluation, f(x,xdot,t) [=xdotdot]...
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)=0
Set initial conditions, make them consistent, and set stepper memory.
void validSecondOrderODE_DAE(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Validate ME supports 2nd order implicit ODE/DAE evaluation, f(xdotdot,xdot,x,t) [= 0]...
virtual bool getUseFSALDefault() const
void validImplicitODE_DAE(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Validate ME supports implicit ODE/DAE evaluation, f(xdot,x,t) [= 0].
virtual bool isImplicit() const =0
virtual void createSubSteppers(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > >)
void getValidParametersBasic(Teuchos::RCP< Teuchos::ParameterList > pl, std::string stepperType)
Provide basic parameters to Steppers.
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const =0
void setStepperType(std::string s)
virtual bool isExplicitImplicit() const =0
virtual Scalar getOrder() const =0
void setICConsistency(std::string s)