Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_StepperDIRK_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_StepperDIRK_decl_hpp
11 #define Tempus_StepperDIRK_decl_hpp
12 
13 #include "Tempus_config.hpp"
14 #include "Tempus_StepperRKBase.hpp"
15 #include "Tempus_StepperImplicit.hpp"
17 
18 namespace Tempus {
19 
143 template <class Scalar>
144 class StepperDIRK : virtual public Tempus::StepperImplicit<Scalar>,
145  virtual public Tempus::StepperRKBase<Scalar> {
146  public:
148 
149  virtual void initialize() override;
151 
153  virtual void setModel(
154  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel)
155  override;
156 
158  virtual void setInitialConditions(
159  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory) override;
160 
163  virtual void setResetInitialGuess(bool reset_guess)
164  {
165  resetGuess_ = reset_guess;
166  }
167  virtual bool getResetInitialGuess() const { return resetGuess_; }
168 
170  virtual void takeStep(
171  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory) override;
172 
175  override;
176 
177  virtual bool isExplicit() const override
178  {
179  const int numStages = this->tableau_->numStages();
181  bool isExplicit = false;
182  for (int i = 0; i < numStages; ++i)
183  if (A(i, i) == 0.0) isExplicit = true;
184  return isExplicit && this->tableau_->isDIRK();
185  }
186  virtual bool isImplicit() const override { return true; }
187  virtual bool isExplicitImplicit() const override
188  {
189  return isExplicit() && isImplicit();
190  }
191  virtual bool isOneStepMethod() const override { return true; }
192  virtual bool isMultiStepMethod() const override { return !isOneStepMethod(); }
193 
194  virtual OrderODE getOrderODE() const override { return FIRST_ORDER_ODE; }
195 
196  virtual std::string getDescription() const = 0;
198 
199  std::vector<Teuchos::RCP<Thyra::VectorBase<Scalar> > >& getStageXDot()
200  {
201  return stageXDot_;
202  }
204 
206  virtual Scalar getAlpha(const Scalar dt) const override
207  {
208  const int i = this->getStageNumber();
209  const int numStages = this->tableau_->numStages();
211  (i < 0 || i > numStages - 1), std::logic_error,
212  "Invalid stage number, "
213  << i << ". Valid range is 0 to " << (numStages - 1) << "\n"
214  << "(-1 indicates not currently in the stage loop). Try calling\n"
215  << "getAlpha(dt, i) directly with a valid stage number.\n");
216 
217  return getAlpha(dt, i);
218  }
219 
221  virtual Scalar getBeta(const Scalar) const override { return Scalar(1.0); }
222 
224  virtual Scalar getAlpha(const Scalar dt, int i) const
225  {
227  return (A(i, i) == 0.0) ? std::numeric_limits<Scalar>::infinity()
228  : Scalar(1.0) / (dt * A(i, i));
229  }
230 
232  const override;
233 
235 
237 
238  virtual void describe(
240  const Teuchos::EVerbosityLevel verbLevel) const override;
242 
243  virtual bool isValidSetup(Teuchos::FancyOStream& out) const override;
244 
247  {
248  if (pl != Teuchos::null) {
249  // Can not validate because of optional Parameters, e.g., 'Solver Name'.
250  // pl->validateParametersAndSetDefaults(*this->getValidParameters());
251  this->setStepperValues(pl);
252  if (pl->isParameter("Use Embedded"))
253  this->setUseEmbedded(pl->get<bool>("Use Embedded"));
254  if (pl->isParameter("Zero Initial Guess"))
255  this->setZeroInitialGuess(pl->get<bool>("Zero Initial Guess"));
256  if (pl->isParameter("Solver Name")) this->setStepperSolverValues(pl);
257  }
258  }
259 
260  protected:
262  virtual void setupDefault();
263 
265  virtual void setup(
266  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& wrapperModel,
268  bool useFSAL, std::string ICConsistency, bool ICConsistencyCheck,
269  bool useEmbedded, bool zeroInitialGuess,
270  const Teuchos::RCP<StepperRKAppAction<Scalar> >& stepperRKAppAction);
271 
272  virtual void setupTableau() = 0;
273 
274  virtual void setEmbeddedMemory() override;
275 
276  std::vector<Teuchos::RCP<Thyra::VectorBase<Scalar> > > stageXDot_;
278 
279  bool resetGuess_ = true;
280 };
281 
294 template <typename Scalar>
296  : virtual public Tempus::TimeDerivative<Scalar> {
297  public:
300  Scalar s, Teuchos::RCP<const Thyra::VectorBase<Scalar> > xTilde)
301  {
302  initialize(s, xTilde);
303  }
304 
307 
309  virtual void compute(
312  Teuchos::RCP<Thyra::VectorBase<Scalar> > xDotDot = Teuchos::null)
313  {
314  xDotDot = Teuchos::null;
315  Thyra::V_StVpStV(xDot.ptr(), s_, *x, -s_, *xTilde_);
316  }
317 
318  virtual void initialize(Scalar s,
320  {
321  s_ = s;
322  xTilde_ = xTilde;
323  }
324 
325  private:
327  Scalar s_; // = 1/(dt*a_ii)
328 };
329 
330 } // namespace Tempus
331 
332 #endif // Tempus_StepperDIRK_decl_hpp
Teuchos::RCP< Thyra::VectorBase< Scalar > > xTilde_
Teuchos::RCP< const Thyra::VectorBase< Scalar > > xTilde_
virtual bool isMultiStepMethod() const override
virtual Scalar getBeta(const Scalar) const override
Return beta = d(x)/dx.
Teuchos::RCP< Teuchos::ParameterList > getValidParametersBasicDIRK() const
virtual bool isImplicit() const override
virtual bool isExplicitImplicit() const override
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel) override
Set the model.
Teuchos::RCP< RKButcherTableau< Scalar > > tableau_
T & get(const std::string &name, T def_value)
virtual Scalar getAlpha(const Scalar dt) const override
Return alpha = d(xDot)/dx.
virtual void setUseEmbedded(bool a)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void setupTableau()=0
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
virtual bool isExplicit() const override
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 setResetInitialGuess(bool reset_guess)
Base class for Runge-Kutta methods, ExplicitRK, DIRK and IMEX.
virtual OrderODE getOrderODE() const override
bool isParameter(const std::string &name) const
Diagonally Implicit Runge-Kutta (DIRK) time stepper.
Thyra Base interface for implicit time steppers.
Application Action for StepperRKBase.
virtual bool isOneStepMethod() const override
Time-derivative interface for DIRK.
virtual void setupDefault()
Default setup for constructor.
virtual void setStepperDIRKValues(Teuchos::RCP< Teuchos::ParameterList > pl)
Set StepperDIRK member data from the ParameterList.
virtual Scalar getAlpha(const Scalar dt, int i) const
Return alpha = d(xDot)/dx for stage i.
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
void setStepperSolverValues(Teuchos::RCP< Teuchos::ParameterList > pl)
Set solver from ParameterList.
virtual void setZeroInitialGuess(bool zIG)
virtual int getStageNumber() const
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual bool isValidSetup(Teuchos::FancyOStream &out) const override
void setStepperValues(const Teuchos::RCP< Teuchos::ParameterList > pl)
Set Stepper member data from ParameterList.
std::vector< Teuchos::RCP< Thyra::VectorBase< Scalar > > > & getStageXDot()
Stepper integrates first-order ODEs.
virtual void initialize() override
Initialize after construction and changing input parameters.
virtual std::string getDescription() const =0
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory) override
Set the initial conditions and make them consistent.
This interface defines the time derivative connection between an implicit Stepper and WrapperModelEva...
virtual void setEmbeddedMemory() override
virtual void setup(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &wrapperModel, const Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > &solver, bool useFSAL, std::string ICConsistency, bool ICConsistencyCheck, bool useEmbedded, bool zeroInitialGuess, const Teuchos::RCP< StepperRKAppAction< Scalar > > &stepperRKAppAction)
Setup for constructor.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState() override
Get a default (initial) StepperState.
std::vector< Teuchos::RCP< Thyra::VectorBase< Scalar > > > stageXDot_
virtual void initialize(Scalar s, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xTilde)
virtual bool getResetInitialGuess() const
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory) override
Take the specified timestep, dt, and return true if successful.
Teuchos::RCP< Thyra::VectorBase< Scalar > > & getXTilde()
StepperDIRKTimeDerivative(Scalar s, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xTilde)
Constructor.