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  * Requires subsequent setModel(), setSolver() and initialize()
45  * calls before calling takeStep().
46  */
48 
49  /// Constructor
51  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel,
52  const Teuchos::RCP<StepperObserver<Scalar> >& obs,
53  const Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
54  bool useFSAL,
55  std::string ICConsistency,
56  bool ICConsistencyCheck,
57  bool zeroInitialGuess);
58 
59  /// \name Basic stepper methods
60  //@{
61  virtual void setObserver(
62  Teuchos::RCP<StepperObserver<Scalar> > obs = Teuchos::null);
63 
64  virtual Teuchos::RCP<StepperObserver<Scalar> > getObserver() const
65  { return this->stepperBEObserver_; }
66 
67  /// Set the predictor
68  void setPredictor(std::string predictorType = "None");
69  void setPredictor(Teuchos::RCP<Stepper<Scalar> > predictorStepper);
70 
71  /// Initialize during construction and after changing input parameters.
72  virtual void initialize();
73 
74  /// Set the initial conditions and make them consistent.
75  virtual void setInitialConditions (
76  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
77 
78  /// Take the specified timestep, dt, and return true if successful.
79  virtual void takeStep(
80  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
81 
82  /// Get a default (initial) StepperState
83  virtual Teuchos::RCP<Tempus::StepperState<Scalar> > getDefaultStepperState();
84  virtual Scalar getOrder() const {return 1.0;}
85  virtual Scalar getOrderMin() const {return 1.0;}
86  virtual Scalar getOrderMax() const {return 1.0;}
87 
88  virtual bool isExplicit() const {return false;}
89  virtual bool isImplicit() const {return true;}
90  virtual bool isExplicitImplicit() const
91  {return isExplicit() and isImplicit();}
92  virtual bool isOneStepMethod() const {return true;}
93  virtual bool isMultiStepMethod() const {return !isOneStepMethod();}
94 
95  virtual OrderODE getOrderODE() const {return FIRST_ORDER_ODE;}
96  //@}
97 
98  /// Return alpha = d(xDot)/dx.
99  virtual Scalar getAlpha(const Scalar dt) const { return Scalar(1.0)/dt; }
100  /// Return beta = d(x)/dx.
101  virtual Scalar getBeta (const Scalar ) const { return Scalar(1.0); }
102 
103  /// Compute predictor given the supplied stepper
104  virtual void computePredictor(
105  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
106 
107  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
108 
109  /// \name Overridden from Teuchos::Describable
110  //@{
111  virtual void describe(Teuchos::FancyOStream & out,
112  const Teuchos::EVerbosityLevel verbLevel) const;
113  //@}
114 
115  /// \name Implementation of StepperOptimizationInterface
116  //@{
117  virtual int stencilLength() const;
118  virtual void computeStepResidual(
119  Thyra::VectorBase<Scalar>& residual,
120  const Teuchos::Array< Teuchos::RCP<const Thyra::VectorBase<Scalar> > >& x,
121  const Teuchos::Array<Scalar>& t,
122  const Thyra::VectorBase<Scalar>& p,
123  const int param_index) const;
124  virtual void computeStepJacobian(
125  Thyra::LinearOpBase<Scalar>& jacobian,
126  const Teuchos::Array< Teuchos::RCP<const Thyra::VectorBase<Scalar> > >& x,
127  const Teuchos::Array<Scalar>& t,
128  const Thyra::VectorBase<Scalar>& p,
129  const int param_index,
130  const int deriv_index) const;
131  virtual void computeStepParamDeriv(
132  Thyra::LinearOpBase<Scalar>& deriv,
133  const Teuchos::Array< Teuchos::RCP<const Thyra::VectorBase<Scalar> > >& x,
134  const Teuchos::Array<Scalar>& t,
135  const Thyra::VectorBase<Scalar>& p,
136  const int param_index) const;
137  virtual void computeStepSolver(
138  Thyra::LinearOpWithSolveBase<Scalar>& jacobian_solver,
139  const Teuchos::Array< Teuchos::RCP<const Thyra::VectorBase<Scalar> > >& x,
140  const Teuchos::Array<Scalar>& t,
141  const Thyra::VectorBase<Scalar>& p,
142  const int param_index) const;
143  //@}
144 
145 private:
146 
147  /// Implementation of computeStep*() methods
149  const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs,
150  const Teuchos::Array< Teuchos::RCP<const Thyra::VectorBase<Scalar> > >& x,
151  const Teuchos::Array<Scalar>& t,
152  const Thyra::VectorBase<Scalar>& p,
153  const int param_index,
154  const int deriv_index = 0) const;
155 
156 private:
157 
158  Teuchos::RCP<Stepper<Scalar> > predictorStepper_;
159  Teuchos::RCP<StepperBackwardEulerObserver<Scalar> > stepperBEObserver_;
160 
161 };
162 
163 /** \brief Time-derivative interface for Backward Euler.
164  *
165  * Given the state \f$x\f$, compute the Backward Euler time-derivative,
166  * \f[
167  * \dot{x}_{n} = \frac{(x_{n} - x_{n-1})}{\Delta t_{n}}.
168  * \f]
169  * \f$\ddot{x}\f$ is not used and set to null.
170  */
171 template <typename Scalar>
173  : virtual public Tempus::TimeDerivative<Scalar>
174 {
175 public:
176 
177  /// Constructor
179  Scalar s, Teuchos::RCP<const Thyra::VectorBase<Scalar> > xOld)
180  { initialize(s, xOld); }
181 
182  /// Destructor
184 
185  /// Compute the time derivative.
186  virtual void compute(
187  Teuchos::RCP<const Thyra::VectorBase<Scalar> > x,
188  Teuchos::RCP< Thyra::VectorBase<Scalar> > xDot,
189  Teuchos::RCP< Thyra::VectorBase<Scalar> > xDotDot = Teuchos::null)
190  {
191  xDotDot = Teuchos::null;
192  // Calculate the Backward Euler x dot vector
193  Thyra::V_StVpStV(xDot.ptr(),s_,*x,-s_,*xOld_);
194  }
195 
196  virtual void initialize(Scalar s,
197  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xOld)
198  { s_ = s; xOld_ = xOld; }
199 
200 private:
201 
202  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xOld_;
203  Scalar s_; // = 1.0/dt
204 };
205 
206 
207 } // namespace Tempus
208 
209 #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.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)
Set Observer.
Thyra Base interface for time steppers.
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.
void setPredictor(std::string predictorType="None")
Set the predictor.
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...
virtual Teuchos::RCP< StepperObserver< Scalar > > getObserver() const
Get Observer.
Teuchos::RCP< Stepper< Scalar > > predictorStepper_
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_
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.