Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_StepperLeapfrog_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_StepperLeapfrog_decl_hpp
10 #define Tempus_StepperLeapfrog_decl_hpp
11 
12 #include "Tempus_config.hpp"
13 #include "Tempus_StepperExplicit.hpp"
14 #include "Tempus_StepperObserverComposite.hpp"
16 
17 
18 namespace Tempus {
19 
20 /** \brief Leapfrog time stepper.
21  *
22  * For the governing equation,
23  * \f[
24  * M(t) \ddot{x} + K(t) x = F(t),
25  * \f]
26  * one can write the explicit ODE system,
27  * \f[
28  * \ddot{x} = f(x,t),
29  * \f]
30  * where
31  * \f[
32  * f(x,t) = \left(M(t)\right)^{-1} \left( F(t) - K(t) x \right).
33  * \f]
34  * The Leapfrog stepper can be written as
35  * \f{eqnarray*}{
36  * x_{n+1} & = & x_{n} + \Delta t\, \dot{x}_{n+1/2} \\
37  * \ddot{x}_{n+1} & = & f(x_{n+1},t_{n+1}) \\
38  * \dot{x}_{n+3/2} & = & \dot{x}_{n+1/2} + \Delta t\, \ddot{x}_{n+1}
39  * \f}
40  * where the position and velocity are leapfrogged over each other.
41  * On startup the velocity half-step can be obtained with
42  * \f{eqnarray*}{
43  * \dot{x}_{n+1/2} & = & \dot{x}_{n} + \frac{1}{2} \Delta t\, \ddot{x}_{n} \\
44  * \dot{x}_{n+1/2} & = & \dot{x}_{n} + \frac{1}{2} \Delta t\, f(x_{n},t_{n})
45  * \f}
46  * and to complete the time step, the final velocity half-step is obtained
47  * with
48  * \f{eqnarray*}{
49  * \dot{x}_{n+1}&=&\dot{x}_{n+1/2} +\frac{1}{2} \Delta t\, \ddot{x}_{n+1} \\
50  * \dot{x}_{n+1}&=&\dot{x}_{n+1/2} +\frac{1}{2} \Delta t\, f(x_{n+1},t_{n+1})
51  * \f}
52  *
53  * <b> Algorithm </b>
54  *
55  * Beginning with \f$(x_n,\dot{x}_{n+1/2})\f$ or \f$(x_n,\dot{x}_{n})\f$
56  * and/or ending with \f$(x_{n+1},\dot{x}_{n+3/2})\f$ or
57  * \f$(x_{n+1},\dot{x}_{n+1})\f$, the algorithm for Leapfrog is
58  * - if "startup"
59  * - \f$ \ddot{x}_{n} \leftarrow f(x_{n},t_{n}) \f$
60  * - \f$ \dot{x}_{n+1/2} \leftarrow
61  * \dot{x}_{n} + \frac{1}{2} \Delta t\, \ddot{x}_{n} \f$
62  * - \f$x_{n+1} \leftarrow x_{n} + \Delta t\, \dot{x}_{n+1/2} \f$
63  * - \f$\ddot{x}_{n+1} \leftarrow f(x_{n+1},t_{n+1}) \f$
64  * - if "ending"
65  * - \f$ \dot{x}_{n+1} \leftarrow
66  * \dot{x}_{n+1/2} +\frac{1}{2} \Delta t\, \ddot{x}_{n+1} \f$
67  * - else
68  * - \f$ \dot{x}_{n+3/2} \leftarrow
69  * \dot{x}_{n+1/2} + \Delta t\, \ddot{x}_{n+1} \f$
70  *
71  * The First-Step-As-Last (FSAL) principle is not used with Leapfrog
72  * because of the algorithm's prescribed order of solution update.
73  * The default is to set useFSAL=false, however useFSAL=true will also
74  * work (i.e., no-op), but issue a warning that it will have no affect.
75  */
76 template<class Scalar>
77 class StepperLeapfrog : virtual public Tempus::StepperExplicit<Scalar>
78 {
79 public:
80 
81  /** \brief Default constructor.
82  *
83  * - Requires subsequent setModel() and initialize() calls before calling
84  * takeStep().
85  */
87 
88  /// Constructor
90  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel,
91  const Teuchos::RCP<StepperObserver<Scalar> >& obs,
92  bool useFSAL,
93  std::string ICConsistency,
94  bool ICConsistencyCheck);
95 
96  /// \name Basic stepper methods
97  //@{
98  virtual void setObserver(
99  Teuchos::RCP<StepperObserver<Scalar> > obs = Teuchos::null);
100 
101  virtual Teuchos::RCP<StepperObserver<Scalar> > getObserver() const
102  { return this->stepperObserver_; }
103 
104  /// Set the initial conditions and make them consistent.
105  virtual void setInitialConditions (
106  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
107 
108  /// Take the specified timestep, dt, and return true if successful.
109  virtual void takeStep(
110  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
111 
112  /// Get a default (initial) StepperState
113  virtual Teuchos::RCP<Tempus::StepperState<Scalar> > getDefaultStepperState();
114  virtual Scalar getOrder() const {return 2.0;}
115  virtual Scalar getOrderMin() const {return 2.0;}
116  virtual Scalar getOrderMax() const {return 2.0;}
117  virtual Scalar getInitTimeStep(
118  const Teuchos::RCP<SolutionHistory<Scalar> >& /* solutionHistory */) const
119  {return Scalar(1.0e+99);}
120 
121  virtual bool isExplicit() const {return true;}
122  virtual bool isImplicit() const {return false;}
123  virtual bool isExplicitImplicit() const
124  {return isExplicit() and isImplicit();}
125  virtual bool isOneStepMethod() const {return true;}
126  virtual bool isMultiStepMethod() const {return !isOneStepMethod();}
127 
128  virtual OrderODE getOrderODE() const {return SECOND_ORDER_ODE;}
129  //@}
130 
131  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
132 
133  std::string getICConsistencyDefault() const { return "Consistent"; }
134 
135  /// \name Overridden from Teuchos::Describable
136  //@{
137  virtual void describe(Teuchos::FancyOStream & out,
138  const Teuchos::EVerbosityLevel verbLevel) const;
139  //@}
140 
141  virtual bool isValidSetup(Teuchos::FancyOStream & out) const;
142 
143 protected:
144 
145  Teuchos::RCP<StepperObserverComposite<Scalar> > stepperObserver_;
146  Teuchos::RCP<StepperLeapfrogObserver<Scalar> > stepperLFObserver_;
147 
148 };
149 
150 } // namespace Tempus
151 
152 #endif // Tempus_StepperLeapfrog_decl_hpp
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
std::string getICConsistencyDefault() const
virtual Teuchos::RCP< StepperObserver< Scalar > > getObserver() const
Get Observer.
virtual Scalar getInitTimeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &) const
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)
Set Observer.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
Stepper integrates second-order ODEs.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
StepperObserver class for Stepper class.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Teuchos::RCP< StepperObserverComposite< Scalar > > stepperObserver_
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
StepperLeapfrog()
Default constructor.
Teuchos::RCP< StepperLeapfrogObserver< Scalar > > stepperLFObserver_
virtual bool isExplicitImplicit() const
virtual OrderODE getOrderODE() const
Thyra Base interface for implicit time steppers.