Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_StepperBDF2_decl.hpp
Go to the documentation of this file.
1 //@HEADER
2 // *****************************************************************************
3 // Tempus: Time Integration and Sensitivity Analysis Package
4 //
5 // Copyright 2017 NTESS and the Tempus contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 //@HEADER
9 
10 #ifndef Tempus_StepperBDF2_decl_hpp
11 #define Tempus_StepperBDF2_decl_hpp
12 
13 #include "Tempus_config.hpp"
14 #include "Tempus_StepperImplicit.hpp"
17 
18 namespace Tempus {
19 
102 template <class Scalar>
103 class StepperBDF2 : virtual public Tempus::StepperImplicit<Scalar> {
104  public:
110  StepperBDF2();
111 
112  StepperBDF2(
113  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel,
115  const Teuchos::RCP<Stepper<Scalar> >& startUpStepper, bool useFSAL,
116  std::string ICConsistency, bool ICConsistencyCheck, bool zeroInitialGuess,
117  const Teuchos::RCP<StepperBDF2AppAction<Scalar> >& stepperBDF2AppAction);
118 
120 
121  virtual void setModel(
122  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel);
123 
124  virtual void setAppAction(
126 
128  {
129  return stepperBDF2AppAction_;
130  }
131 
133  void setStartUpStepper(std::string startupStepperType);
134  void setStartUpStepper(Teuchos::RCP<Stepper<Scalar> > startupStepper);
135 
137  virtual void initialize();
138 
140  virtual void setInitialConditions(
141  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
142 
144  virtual void takeStep(
145  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
146 
149  virtual Scalar getOrder() const { return order_; }
150  virtual Scalar getOrderMin() const { return 1.0; }
151  virtual Scalar getOrderMax() const { return 2.0; }
152 
153  virtual bool isExplicit() const { return false; }
154  virtual bool isImplicit() const { return true; }
155  virtual bool isExplicitImplicit() const
156  {
157  return isExplicit() && isImplicit();
158  }
159  virtual bool isOneStepMethod() const { return false; }
160  virtual bool isMultiStepMethod() const { return !isOneStepMethod(); }
161  virtual OrderODE getOrderODE() const { return FIRST_ORDER_ODE; }
163 
165  virtual Scalar getAlpha(const Scalar dt) const { return getAlpha(dt, dt); }
166  virtual Scalar getAlpha(const Scalar dt, const Scalar dtOld) const
167  {
168  return (Scalar(2.0) * dt + dtOld) / (dt * (dt + dtOld));
169  }
171  virtual Scalar getBeta(const Scalar) const { return Scalar(1.0); }
172 
174  virtual void computeStartUp(
175  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
176 
178 
180 
181  virtual void describe(Teuchos::FancyOStream& out,
182  const Teuchos::EVerbosityLevel verbLevel) const;
184 
185  virtual bool isValidSetup(Teuchos::FancyOStream& out) const;
186 
187  private:
190  Scalar order_ = Scalar(2.0);
191 };
192 
208 template <typename Scalar>
210  : virtual public Tempus::TimeDerivative<Scalar> {
211  public:
214  Scalar dt, Scalar dtOld,
216  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xOldOld)
217  {
218  initialize(dt, dtOld, xOld, xOldOld);
219  }
220 
223 
225  virtual void compute(
228  Teuchos::RCP<Thyra::VectorBase<Scalar> > xDotDot = Teuchos::null)
229  {
230  xDotDot = Teuchos::null;
231  // Calculate the BDF2 x dot vector
232  const Scalar a = ((Scalar(2.0) * dt_ + dtOld_) / (dt_ + dtOld_)) / dt_;
233  const Scalar b = (dt_ / (dt_ + dtOld_)) / dtOld_;
234  // xDot = a*(x_n - x_{n-1}) - b*(x_{n-1} - x_{n-2})
235  Thyra::V_StVpStV(xDot.ptr(), a, *x, -(a + b), *xOld_);
236  Thyra::Vp_StV(xDot.ptr(), b, *xOldOld_);
237  }
238 
239  virtual void initialize(
240  Scalar dt, Scalar dtOld,
242  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xOldOld)
243  {
244  dt_ = dt;
245  dtOld_ = dtOld;
246  xOld_ = xOld;
247  xOldOld_ = xOldOld;
248  }
249 
250  private:
253  Scalar dt_; // = t_n - t_{n-1}
254  Scalar dtOld_; // = t_{n-1} - t_{n-2}
255 };
256 
258 // ------------------------------------------------------------------------
259 template <class Scalar>
261  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model,
263 
264 } // namespace Tempus
265 
266 #endif // Tempus_StepperBDF2_decl_hpp
BDF2 (Backward-Difference-Formula-2) time stepper.
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
Time-derivative interface for BDF2.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
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 bool isExplicit() const
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
Set the model.
virtual Teuchos::RCP< StepperBDF2AppAction< Scalar > > getAppAction() const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual Scalar getBeta(const Scalar) const
Return beta = d(x)/dx.
Teuchos::RCP< StepperBDF2AppAction< Scalar > > stepperBDF2AppAction_
Teuchos::RCP< Stepper< Scalar > > startUpStepper_
virtual void computeStartUp(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Compute the first time step given the supplied startup stepper.
Thyra Base interface for time steppers.
Thyra Base interface for implicit time steppers.
virtual Scalar getAlpha(const Scalar dt) const
Return alpha = d(xDot)/dx.
virtual Scalar getOrderMin() const
virtual void setAppAction(Teuchos::RCP< StepperBDF2AppAction< Scalar > > appAction)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Teuchos::RCP< const Thyra::VectorBase< Scalar > > xOld_
virtual OrderODE getOrderODE() const
Stepper integrates first-order ODEs.
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
virtual Scalar getOrder() const
StepperBDF2TimeDerivative(Scalar dt, Scalar dtOld, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xOld, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xOldOld)
Constructor.
virtual bool isOneStepMethod() const
Teuchos::RCP< StepperBDF2< Scalar > > createStepperBDF2(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
virtual bool isExplicitImplicit() const
This interface defines the time derivative connection between an implicit Stepper and WrapperModelEva...
virtual bool isMultiStepMethod() const
Application Action for StepperBDF2.
virtual void initialize(Scalar dt, Scalar dtOld, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xOld, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xOldOld)
virtual Scalar getAlpha(const Scalar dt, const Scalar dtOld) const
virtual Scalar getOrderMax() const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Teuchos::RCP< const Thyra::VectorBase< Scalar > > xOldOld_
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
void setStartUpStepper(std::string startupStepperType)
Set the stepper to use in first step.
virtual void initialize()
Initialize during construction and after changing input parameters.
StepperBDF2()
Default constructor.
virtual bool isImplicit() const