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