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) {}
71 
72 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
73  virtual void setNonConstModel(
74  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& /* appModel */){}
75 
76 #endif // TEMPUS_HIDE_DEPRECATED_CODE
77  virtual Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > getModel()
78  { return Teuchos::null; }
79 
80  /// Set solver.
81  virtual void setSolver(
82  Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > solver) {}
83 
84  /// Get solver
85  virtual Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > getSolver() const
86  { return Teuchos::null; }
87 
88  /// Set Observer
89  virtual void setObserver(
90  Teuchos::RCP<StepperObserver<Scalar> > obs = Teuchos::null){}
91 
92  /// Get Observer
93  virtual Teuchos::RCP<StepperObserver<Scalar> > getObserver() const
94  { return Teuchos::null; }
95 
96  /// Initialize after construction and changing input parameters.
97  virtual void initialize();
98 
99  /// True if stepper's member data is initialized.
100  virtual bool isInitialized() { return isInitialized_; }
101 
102  /// Check initialization, and error out on failure.
103  virtual void checkInitialized();
104 
105  /// Set initial conditions, make them consistent, and set stepper memory.
106  virtual void setInitialConditions (
107  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory) = 0;
108 
109  /// Take the specified timestep, dt, and return true if successful.
110  virtual void takeStep(
111  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory) = 0;
112 
113  /// Pass initial guess to Newton solver (for implicit schemes)
114  virtual void setInitialGuess(Teuchos::RCP<const Thyra::VectorBase<Scalar> >
115  initialGuess = Teuchos::null) = 0;
116 
117  virtual Teuchos::RCP<Tempus::StepperState<Scalar> >
119  virtual Scalar getOrder() const = 0;
120  virtual Scalar getOrderMin() const = 0;
121  virtual Scalar getOrderMax() const = 0;
122  virtual Scalar getInitTimeStep(
123  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory) const = 0;
124 
125  virtual bool isExplicit() const = 0;
126  virtual bool isImplicit() const = 0;
127  virtual bool isExplicitImplicit() const = 0;
128 
129  virtual bool isOneStepMethod() const = 0;
130  virtual bool isMultiStepMethod() const = 0;
131 
132  void setStepperType(std::string s) { stepperType_ = s;
133  isInitialized_ = false; }
134  std::string getStepperType() const { return stepperType_; }
135 
136  void setUseFSAL(bool a) { useFSAL_ = a; isInitialized_ = false; }
137  bool getUseFSAL() const { return useFSAL_; }
138  virtual bool getUseFSALDefault() const { return false; }
139 
140  void setICConsistency(std::string s) { ICConsistency_ = s;
141  isInitialized_ = false; }
142  std::string getICConsistency() const { return ICConsistency_; }
143  virtual std::string getICConsistencyDefault() const { return "None"; }
144 
146  isInitialized_ = false; }
148  virtual bool getICConsistencyCheckDefault() const { return false; }
149 
150  virtual OrderODE getOrderODE() const = 0;
151 
152  /// Get x from SolutionState or Stepper storage.
153  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getStepperX(
154  Teuchos::RCP<SolutionState<Scalar> > state);
155 
156  /// Get xDot from SolutionState or Stepper storage.
157  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getStepperXDot(
158  Teuchos::RCP<SolutionState<Scalar> > state);
159 
160  /// Get xDotDot from SolutionState or Stepper storage.
161  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getStepperXDotDot(
162  Teuchos::RCP<SolutionState<Scalar> > state);
163  //@}
164 
165  /// \name Overridden from Teuchos::Describable
166  //@{
167  virtual std::string description() const { return stepperType_; }
168  //@}
169 
170  /// \name Overridden from Teuchos::Describable
171  //@{
172  virtual void describe(Teuchos::FancyOStream & out,
173  const Teuchos::EVerbosityLevel verbLevel) const;
174  //@}
175 
176  virtual bool isValidSetup(Teuchos::FancyOStream & out) const;
177 
178  /// \name Functions for Steppers with subSteppers (e.g., OperatorSplit)
179  //@{
180  virtual void createSubSteppers(
181  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > /* models */){}
182  //@}
183 
184  virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const = 0;
185 
186 private:
187 
188  std::string stepperType_; ///< Name of stepper type
189  bool useFSAL_ = false; ///< Use First-Step-As-Last (FSAL) principle
190  std::string ICConsistency_ = std::string("None"); ///< Type of consistency to apply to ICs.
191  bool ICConsistencyCheck_ = true; ///< Check if the initial condition is consistent
192 
193  // RCP to SolutionState memory or Stepper temporary memory (if needed).
194  Teuchos::RCP<Thyra::VectorBase<Scalar> > stepperX_;
195  Teuchos::RCP<Thyra::VectorBase<Scalar> > stepperXDot_;
196  Teuchos::RCP<Thyra::VectorBase<Scalar> > stepperXDotDot_;
197 
198 protected:
199 
200  /// Set x for Stepper storage.
201  virtual void setStepperX(Teuchos::RCP<Thyra::VectorBase<Scalar> > x)
202  { stepperX_ = x; }
203 
204  /// Set xDot for Stepper storage.
205  virtual void setStepperXDot(Teuchos::RCP<Thyra::VectorBase<Scalar> > xDot)
206  { stepperXDot_ = xDot; }
207 
208  /// Set x for Stepper storage.
209  virtual void setStepperXDotDot(Teuchos::RCP<Thyra::VectorBase<Scalar> > xDotDot)
210  { stepperXDotDot_ = xDotDot; }
211 
212  bool isInitialized_ = false; ///< True if stepper's member data is initialized.
213 };
214 
215 
216 /// \name Helper functions
217 //@{
218  /// Provide basic parameters to Steppers.
220  Teuchos::RCP<Teuchos::ParameterList> pl, std::string stepperType);
221 
222  /// Validate that the model supports explicit ODE evaluation, f(x,t) [=xdot]
223  /** Currently the convention to evaluate f(x,t) is to set xdot=null!
224  * There is no InArgs support to test if xdot is null, so we set
225  * xdot=null and hopefully the ModelEvaluator can handle it.
226  */
227  template<class Scalar>
229  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model)
230  {
231  TEUCHOS_TEST_FOR_EXCEPT( is_null(model) );
232  typedef Thyra::ModelEvaluatorBase MEB;
233  const MEB::InArgs<Scalar> inArgs = model->createInArgs();
234  const MEB::OutArgs<Scalar> outArgs = model->createOutArgs();
235  const bool supports = inArgs.supports(MEB::IN_ARG_x) and
236  outArgs.supports(MEB::OUT_ARG_f);
237 
238  TEUCHOS_TEST_FOR_EXCEPTION( supports == false, std::logic_error,
239  model->description() << "can not support an explicit ODE with\n"
240  << " IN_ARG_x = " << inArgs.supports(MEB::IN_ARG_x) << "\n"
241  << " OUT_ARG_f = " << outArgs.supports(MEB::OUT_ARG_f) << "\n"
242  << "Explicit ODE requires:\n"
243  << " IN_ARG_x = true\n"
244  << " OUT_ARG_f = true\n"
245  << "\n"
246  << "NOTE: Currently the convention to evaluate f(x,t) is to set\n"
247  << "xdot=null! There is no InArgs support to test if xdot is null,\n"
248  << "so we set xdot=null and hope the ModelEvaluator can handle it.\n");
249 
250  return;
251  }
252 
253 
254  /// Validate that the model supports explicit second order ODE evaluation, f(x,xdot,t) [=xdotdot]
255  /** Currently the convention to evaluate f(x,xdot,t) is to set xdotdot=null!
256  * There is no InArgs support to test if xdotdot is null, so we set
257  * xdotdot=null and hopefully the ModelEvaluator can handle it.
258  */
259  template<class Scalar>
261  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model)
262  {
263  TEUCHOS_TEST_FOR_EXCEPT( is_null(model) );
264  typedef Thyra::ModelEvaluatorBase MEB;
265  const MEB::InArgs<Scalar> inArgs = model->createInArgs();
266  const MEB::OutArgs<Scalar> outArgs = model->createOutArgs();
267  const bool supports = inArgs.supports(MEB::IN_ARG_x) and
268  inArgs.supports(MEB::IN_ARG_x_dot) and
269  outArgs.supports(MEB::OUT_ARG_f);
270 
271  TEUCHOS_TEST_FOR_EXCEPTION( supports == false, std::logic_error,
272  model->description() << "can not support an explicit ODE with\n"
273  << " IN_ARG_x = " << inArgs.supports(MEB::IN_ARG_x) << "\n"
274  << " IN_ARG_x_dot = " << inArgs.supports(MEB::IN_ARG_x_dot) << "\n"
275  << " OUT_ARG_f = " << outArgs.supports(MEB::OUT_ARG_f) << "\n"
276  << "Explicit ODE requires:\n"
277  << " IN_ARG_x = true\n"
278  << " IN_ARG_x_dot = true\n"
279  << " OUT_ARG_f = true\n"
280  << "\n"
281  << "NOTE: Currently the convention to evaluate f(x, xdot, t) is to\n"
282  << "set xdotdot=null! There is no InArgs support to test if xdotdot\n"
283  << "is null, so we set xdotdot=null and hope the ModelEvaluator can\n"
284  << "handle it.\n");
285 
286  return;
287  }
288 
289 
290  /// Validate ME supports implicit ODE/DAE evaluation, f(xdot,x,t) [= 0]
291  template<class Scalar>
293  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model)
294  {
295  TEUCHOS_TEST_FOR_EXCEPT( is_null(model) );
296  typedef Thyra::ModelEvaluatorBase MEB;
297  const MEB::InArgs<Scalar> inArgs = model->createInArgs();
298  const MEB::OutArgs<Scalar> outArgs = model->createOutArgs();
299  const bool supports = inArgs.supports(MEB::IN_ARG_x) and
300  inArgs.supports(MEB::IN_ARG_x_dot) and
301  inArgs.supports(MEB::IN_ARG_alpha) and
302  inArgs.supports(MEB::IN_ARG_beta) and
303  !inArgs.supports(MEB::IN_ARG_W_x_dot_dot_coeff) and
304  outArgs.supports(MEB::OUT_ARG_f) and
305  outArgs.supports(MEB::OUT_ARG_W);
306 
307  TEUCHOS_TEST_FOR_EXCEPTION( supports == false, std::logic_error,
308  model->description() << " can not support an implicit ODE with\n"
309  << " IN_ARG_x = "
310  << inArgs.supports(MEB::IN_ARG_x) << "\n"
311  << " IN_ARG_x_dot = "
312  << inArgs.supports(MEB::IN_ARG_x_dot) << "\n"
313  << " IN_ARG_alpha = "
314  << inArgs.supports(MEB::IN_ARG_alpha) << "\n"
315  << " IN_ARG_beta = "
316  << inArgs.supports(MEB::IN_ARG_beta) << "\n"
317  << " IN_ARG_W_x_dot_dot_coeff = "
318  << inArgs.supports(MEB::IN_ARG_W_x_dot_dot_coeff) << "\n"
319  << " OUT_ARG_f = "
320  << outArgs.supports(MEB::OUT_ARG_f) << "\n"
321  << " OUT_ARG_W = "
322  << outArgs.supports(MEB::OUT_ARG_W) << "\n"
323  << "Implicit ODE requires:\n"
324  << " IN_ARG_x = true\n"
325  << " IN_ARG_x_dot = true\n"
326  << " IN_ARG_alpha = true\n"
327  << " IN_ARG_beta = true\n"
328  << " IN_ARG_W_x_dot_dot_coeff = false\n"
329  << " OUT_ARG_f = true\n"
330  << " OUT_ARG_W = true\n");
331 
332  return;
333  }
334 
335 
336  /// Validate ME supports 2nd order implicit ODE/DAE evaluation, f(xdotdot,xdot,x,t) [= 0]
337  template<class Scalar>
339  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model)
340  {
341  TEUCHOS_TEST_FOR_EXCEPT( is_null(model) );
342  typedef Thyra::ModelEvaluatorBase MEB;
343  const MEB::InArgs<Scalar> inArgs = model->createInArgs();
344  const MEB::OutArgs<Scalar> outArgs = model->createOutArgs();
345  const bool supports = inArgs.supports(MEB::IN_ARG_x) and
346  inArgs.supports(MEB::IN_ARG_x_dot) and
347  inArgs.supports(MEB::IN_ARG_x_dot_dot) and
348  inArgs.supports(MEB::IN_ARG_alpha) and
349  inArgs.supports(MEB::IN_ARG_beta) and
350  inArgs.supports(MEB::IN_ARG_W_x_dot_dot_coeff) and
351  outArgs.supports(MEB::OUT_ARG_f) and
352  outArgs.supports(MEB::OUT_ARG_W);
353 
354  TEUCHOS_TEST_FOR_EXCEPTION( supports == false, std::logic_error,
355  model->description() << " can not support an implicit ODE with\n"
356  << " IN_ARG_x = "
357  << inArgs.supports(MEB::IN_ARG_x) << "\n"
358  << " IN_ARG_x_dot = "
359  << inArgs.supports(MEB::IN_ARG_x_dot) << "\n"
360  << " IN_ARG_x_dot_dot = "
361  << inArgs.supports(MEB::IN_ARG_x_dot_dot) << "\n"
362  << " IN_ARG_alpha = "
363  << inArgs.supports(MEB::IN_ARG_alpha) << "\n"
364  << " IN_ARG_beta = "
365  << inArgs.supports(MEB::IN_ARG_beta) << "\n"
366  << " IN_ARG_W_x_dot_dot_coeff = "
367  << inArgs.supports(MEB::IN_ARG_W_x_dot_dot_coeff) << "\n"
368  << " OUT_ARG_f = "
369  << outArgs.supports(MEB::OUT_ARG_f) << "\n"
370  << " OUT_ARG_W = "
371  << outArgs.supports(MEB::OUT_ARG_W) << "\n"
372  << "Implicit Second Order ODE requires:\n"
373  << " IN_ARG_x = true\n"
374  << " IN_ARG_x_dot = true\n"
375  << " IN_ARG_x_dot_dot = true\n"
376  << " IN_ARG_alpha = true\n"
377  << " IN_ARG_beta = true\n"
378  << " IN_ARG_W_x_dot_dot_coeff = true\n"
379  << " OUT_ARG_f = true\n"
380  << " OUT_ARG_W = true\n");
381 
382  return;
383  }
384 
385 
386  /// Returns the default solver ParameterList for implicit Steppers.
387  Teuchos::RCP<Teuchos::ParameterList> defaultSolverParameters();
388 //@}
389 
390 
391 } // namespace Tempus
392 #endif // Tempus_Stepper_decl_hpp
virtual bool isInitialized()
True if stepper&#39;s member data is initialized.
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 bool isValidSetup(Teuchos::FancyOStream &out) const
virtual OrderODE getOrderODE() const =0
std::string getStepperType() const
bool getUseFSAL() const
virtual void setNonConstModel(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &)
virtual Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > getSolver() const
Get solver.
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getModel()
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver)
Set solver.
bool getICConsistencyCheck() const
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getStepperX(Teuchos::RCP< SolutionState< Scalar > > state)
Get x from SolutionState or Stepper storage.
virtual bool isExplicit() const =0
virtual bool getICConsistencyCheckDefault() const
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
virtual void setStepperXDot(Teuchos::RCP< Thyra::VectorBase< Scalar > > xDot)
Set xDot for Stepper storage.
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 initialize()
Initialize after construction and changing input parameters.
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getStepperXDotDot(Teuchos::RCP< SolutionState< Scalar > > state)
Get xDotDot from SolutionState or Stepper storage.
bool isInitialized_
True if stepper&#39;s member data is initialized.
virtual bool isOneStepMethod() const =0
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
virtual Scalar getOrderMin() const =0
std::string getICConsistency() const
virtual bool isMultiStepMethod() const =0
Stepper integrates second-order ODEs.
virtual void checkInitialized()
Check initialization, and error out on failure.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Teuchos::RCP< Thyra::VectorBase< Scalar > > stepperXDot_
bool useFSAL_
Use First-Step-As-Last (FSAL) principle.
virtual void setStepperX(Teuchos::RCP< Thyra::VectorBase< Scalar > > x)
Set x for Stepper storage.
virtual std::string description() const
virtual Scalar getInitTimeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory) const =0
virtual void setInitialGuess(Teuchos::RCP< const Thyra::VectorBase< Scalar > > initialGuess=Teuchos::null)=0
Pass initial guess to Newton solver (for implicit schemes)
virtual Teuchos::RCP< StepperObserver< Scalar > > getObserver() const
Get Observer.
void setICConsistencyCheck(bool c)
StepperObserver class for Stepper class.
Teuchos::RCP< Thyra::VectorBase< Scalar > > stepperXDotDot_
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void setStepperXDotDot(Teuchos::RCP< Thyra::VectorBase< Scalar > > xDotDot)
Set x for Stepper storage.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()=0
std::string ICConsistency_
Type of consistency to apply to ICs.
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]...
bool ICConsistencyCheck_
Check if the initial condition is consistent.
Teuchos::RCP< Thyra::VectorBase< Scalar > > stepperX_
virtual bool getUseFSALDefault() const
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)
Set Observer.
std::string stepperType_
Name of stepper type.
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 Teuchos::RCP< Thyra::VectorBase< Scalar > > getStepperXDot(Teuchos::RCP< SolutionState< Scalar > > state)
Get xDot from SolutionState or Stepper storage.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
virtual bool isExplicitImplicit() const =0
virtual Scalar getOrder() const =0
void setICConsistency(std::string s)