Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_StepperBackwardEuler_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_StepperBackwardEuler_decl_hpp
10 #define Tempus_StepperBackwardEuler_decl_hpp
11 
12 #include "Tempus_StepperImplicit.hpp"
16 
17 
18 namespace Tempus {
19 
20 /** \brief Backward Euler time stepper.
21  *
22  * For the implicit ODE system, \f$\mathcal{F}(\dot{x},x,t) = 0\f$,
23  * the solution, \f$\dot{x}\f$ and \f$x\f$, is determined using a
24  * solver (e.g., a non-linear solver, like NOX).
25  *
26  * <b> Algorithm </b>
27  * The single-timestep algorithm for Backward Euler is simply,
28  * - Solve \f$f(\dot{x}=(x_n-x_{n-1})/\Delta t_n, x_n, t_n)=0\f$ for \f$x_n\f$
29  * - \f$\dot{x}_n \leftarrow (x_n-x_{n-1})/\Delta t_n\f$
30  *
31  * The First-Step-As-Last (FSAL) principle is not needed with Backward Euler.
32  * The default is to set useFSAL=false, however useFSAL=true will also work
33  * but have no affect (i.e., no-op).
34  */
35 template<class Scalar>
37  virtual public Tempus::StepperImplicit<Scalar>,
38  virtual public Tempus::StepperOptimizationInterface<Scalar>
39 {
40 public:
41 
42  /** \brief Default constructor.
43  *
44  * - Constructs with a default ParameterList.
45  * - Can reset ParameterList with setParameterList().
46  * - Requires subsequent setModel() and initialize() calls before calling
47  * takeStep().
48  */
50 
51  /// Constructor
53  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel,
54  Teuchos::RCP<Teuchos::ParameterList> pList = Teuchos::null);
55 
56  /// \name Basic stepper methods
57  //@{
58  virtual void setObserver(
59  Teuchos::RCP<StepperObserver<Scalar> > obs = Teuchos::null);
60 
61  /// Set the predictor
62  void setPredictor(std::string predictorName);
63  void setPredictor(Teuchos::RCP<Teuchos::ParameterList>predPL=Teuchos::null);
64 
65  /// Initialize during construction and after changing input parameters.
66  virtual void initialize();
67 
68  /// Set the initial conditions and make them consistent.
69  virtual void setInitialConditions (
70  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
71 
72  /// Take the specified timestep, dt, and return true if successful.
73  virtual void takeStep(
74  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
75 
76  /// Get a default (initial) StepperState
77  virtual Teuchos::RCP<Tempus::StepperState<Scalar> > getDefaultStepperState();
78  virtual Scalar getOrder() const {return 1.0;}
79  virtual Scalar getOrderMin() const {return 1.0;}
80  virtual Scalar getOrderMax() const {return 1.0;}
81 
82  virtual bool isExplicit() const {return false;}
83  virtual bool isImplicit() const {return true;}
84  virtual bool isExplicitImplicit() const
85  {return isExplicit() and isImplicit();}
86  virtual bool isOneStepMethod() const {return true;}
87  virtual bool isMultiStepMethod() const {return !isOneStepMethod();}
88 
89  virtual OrderODE getOrderODE() const {return FIRST_ORDER_ODE;}
90  //@}
91 
92  /// Return alpha = d(xDot)/dx.
93  virtual Scalar getAlpha(const Scalar dt) const { return Scalar(1.0)/dt; }
94  /// Return beta = d(x)/dx.
95  virtual Scalar getBeta (const Scalar ) const { return Scalar(1.0); }
96 
97  /// Compute predictor given the supplied stepper
98  virtual void computePredictor(
99  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
100 
101  /// \name ParameterList methods
102  //@{
103  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & pl);
104  Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList();
105  Teuchos::RCP<Teuchos::ParameterList> unsetParameterList();
106  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
107  Teuchos::RCP<Teuchos::ParameterList> getDefaultParameters() const;
108  //@}
109 
110  /// \name Overridden from Teuchos::Describable
111  //@{
112  virtual std::string description() const;
113  virtual void describe(Teuchos::FancyOStream & out,
114  const Teuchos::EVerbosityLevel verbLevel) const;
115  //@}
116 
117  /// \name Implementation of StepperOptimizationInterface
118  //@{
119  virtual int stencilLength() const;
120  virtual void computeStepResidual(
121  Thyra::VectorBase<Scalar>& residual,
122  const Teuchos::Array< Teuchos::RCP<const Thyra::VectorBase<Scalar> > >& x,
123  const Teuchos::Array<Scalar>& t,
124  const Thyra::VectorBase<Scalar>& p,
125  const int param_index) const;
126  virtual void computeStepJacobian(
127  Thyra::LinearOpBase<Scalar>& jacobian,
128  const Teuchos::Array< Teuchos::RCP<const Thyra::VectorBase<Scalar> > >& x,
129  const Teuchos::Array<Scalar>& t,
130  const Thyra::VectorBase<Scalar>& p,
131  const int param_index,
132  const int deriv_index) const;
133  virtual void computeStepParamDeriv(
134  Thyra::LinearOpBase<Scalar>& deriv,
135  const Teuchos::Array< Teuchos::RCP<const Thyra::VectorBase<Scalar> > >& x,
136  const Teuchos::Array<Scalar>& t,
137  const Thyra::VectorBase<Scalar>& p,
138  const int param_index) const;
139  virtual void computeStepSolver(
140  Thyra::LinearOpWithSolveBase<Scalar>& jacobian_solver,
141  const Teuchos::Array< Teuchos::RCP<const Thyra::VectorBase<Scalar> > >& x,
142  const Teuchos::Array<Scalar>& t,
143  const Thyra::VectorBase<Scalar>& p,
144  const int param_index) const;
145  //@}
146 
147 private:
148 
149  /// Implementation of computeStep*() methods
151  const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs,
152  const Teuchos::Array< Teuchos::RCP<const Thyra::VectorBase<Scalar> > >& x,
153  const Teuchos::Array<Scalar>& t,
154  const Thyra::VectorBase<Scalar>& p,
155  const int param_index,
156  const int deriv_index = 0) const;
157 
158 private:
159 
160  Teuchos::RCP<Stepper<Scalar> > predictorStepper_;
161  Teuchos::RCP<StepperBackwardEulerObserver<Scalar> > stepperBEObserver_;
162 
163 };
164 
165 /** \brief Time-derivative interface for Backward Euler.
166  *
167  * Given the state \f$x\f$, compute the Backward Euler time-derivative,
168  * \f[
169  * \dot{x}_{n} = \frac{(x_{n} - x_{n-1})}{\Delta t_{n}}.
170  * \f]
171  * \f$\ddot{x}\f$ is not used and set to null.
172  */
173 template <typename Scalar>
175  : virtual public Tempus::TimeDerivative<Scalar>
176 {
177 public:
178 
179  /// Constructor
181  Scalar s, Teuchos::RCP<const Thyra::VectorBase<Scalar> > xOld)
182  { initialize(s, xOld); }
183 
184  /// Destructor
186 
187  /// Compute the time derivative.
188  virtual void compute(
189  Teuchos::RCP<const Thyra::VectorBase<Scalar> > x,
190  Teuchos::RCP< Thyra::VectorBase<Scalar> > xDot,
191  Teuchos::RCP< Thyra::VectorBase<Scalar> > xDotDot = Teuchos::null)
192  {
193  xDotDot = Teuchos::null;
194  // Calculate the Backward Euler x dot vector
195  Thyra::V_StVpStV(xDot.ptr(),s_,*x,-s_,*xOld_);
196  }
197 
198  virtual void initialize(Scalar s,
199  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xOld)
200  { s_ = s; xOld_ = xOld; }
201 
202 private:
203 
204  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xOld_;
205  Scalar s_; // = 1.0/dt
206 };
207 
208 
209 } // namespace Tempus
210 
211 #endif // Tempus_StepperBackwardEuler_decl_hpp
Teuchos::RCP< const Thyra::VectorBase< Scalar > > xOld_
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
void computeStepResidDerivImpl(const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs, const Teuchos::Array< Teuchos::RCP< const Thyra::VectorBase< Scalar > > > &x, const Teuchos::Array< Scalar > &t, const Thyra::VectorBase< Scalar > &p, const int param_index, const int deriv_index=0) const
Implementation of computeStep*() methods.
virtual void computeStepResidual(Thyra::VectorBase< Scalar > &residual, const Teuchos::Array< Teuchos::RCP< const Thyra::VectorBase< Scalar > > > &x, const Teuchos::Array< Scalar > &t, const Thyra::VectorBase< Scalar > &p, const int param_index) const
Compute time step residual.
virtual void compute(Teuchos::RCP< const Thyra::VectorBase< Scalar > > x, Teuchos::RCP< Thyra::VectorBase< Scalar > > xDot, Teuchos::RCP< Thyra::VectorBase< Scalar > > xDotDot=Teuchos::null)
Compute the time derivative.
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
virtual void computePredictor(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Compute predictor given the supplied stepper.
virtual int stencilLength() const
Return the number of solution vectors in the time step stencil.
virtual Scalar getBeta(const Scalar) const
Return beta = d(x)/dx.
Teuchos::RCP< Teuchos::ParameterList > getDefaultParameters() const
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
void setPredictor(std::string predictorName)
Set the predictor.
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)
Set Observer.
virtual void computeStepSolver(Thyra::LinearOpWithSolveBase< Scalar > &jacobian_solver, const Teuchos::Array< Teuchos::RCP< const Thyra::VectorBase< Scalar > > > &x, const Teuchos::Array< Scalar > &t, const Thyra::VectorBase< Scalar > &p, const int param_index) const
Compute time step Jacobian solver.
Thyra Base interface for implicit time steppers.
virtual void computeStepJacobian(Thyra::LinearOpBase< Scalar > &jacobian, const Teuchos::Array< Teuchos::RCP< const Thyra::VectorBase< Scalar > > > &x, const Teuchos::Array< Scalar > &t, const Thyra::VectorBase< Scalar > &p, const int param_index, const int deriv_index) const
Compute time step Jacobian.
virtual void computeStepParamDeriv(Thyra::LinearOpBase< Scalar > &deriv, const Teuchos::Array< Teuchos::RCP< const Thyra::VectorBase< Scalar > > > &x, const Teuchos::Array< Scalar > &t, const Thyra::VectorBase< Scalar > &p, const int param_index) const
Compute time step derivative w.r.t. model parameters.
StepperObserver class for Stepper class.
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
virtual Scalar getAlpha(const Scalar dt) const
Return alpha = d(xDot)/dx.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Teuchos::RCP< Stepper< Scalar > > predictorStepper_
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
Stepper integrates first-order ODEs.
StepperBackwardEulerTimeDerivative(Scalar s, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xOld)
Constructor.
This interface defines the time derivative connection between an implicit Stepper and WrapperModelEva...
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Teuchos::RCP< StepperBackwardEulerObserver< Scalar > > stepperBEObserver_
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl)
virtual void initialize(Scalar s, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xOld)
Stepper interface to support full-space optimization.
Time-derivative interface for Backward Euler.
virtual void initialize()
Initialize during construction and after changing input parameters.