Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_StepperIMEX_RK_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_StepperIMEX_RK_decl_hpp
11 #define Tempus_StepperIMEX_RK_decl_hpp
12 
13 #include "Tempus_config.hpp"
14 #include "Tempus_StepperRKBase.hpp"
15 #include "Tempus_StepperImplicit.hpp"
16 #include "Tempus_WrapperModelEvaluatorPairIMEX_Basic.hpp"
17 
18 namespace Tempus {
19 
283 template <class Scalar>
284 class StepperIMEX_RK : virtual public Tempus::StepperImplicit<Scalar>,
285  virtual public Tempus::StepperRKBase<Scalar> {
286  public:
292  StepperIMEX_RK(std::string stepperType = "IMEX RK SSP2");
293 
296  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel,
298  bool useFSAL, std::string ICConsistency, bool ICConsistencyCheck,
299  bool zeroInitialGuess,
300  const Teuchos::RCP<StepperRKAppAction<Scalar> >& stepperRKAppAction,
301  std::string stepperType,
302  Teuchos::RCP<const RKButcherTableau<Scalar> > explicitTableau,
303  Teuchos::RCP<const RKButcherTableau<Scalar> > implicitTableau,
304  Scalar order);
305 
307 
310  {
311  return getExplicitTableau();
312  }
313 
315  virtual void setTableaus(
316  std::string stepperType = "",
317  Teuchos::RCP<const RKButcherTableau<Scalar> > explicitTableau =
318  Teuchos::null,
319  Teuchos::RCP<const RKButcherTableau<Scalar> > implicitTableau =
320  Teuchos::null);
321 
322  virtual void setTableaus(Teuchos::RCP<Teuchos::ParameterList> stepperPL,
323  std::string stepperType);
324 
327  const
328  {
329  return explicitTableau_;
330  }
331 
333  virtual void setExplicitTableau(
334  Teuchos::RCP<const RKButcherTableau<Scalar> > explicitTableau);
335 
338  const
339  {
340  return implicitTableau_;
341  }
342 
344  virtual void setImplicitTableau(
345  Teuchos::RCP<const RKButcherTableau<Scalar> > implicitTableau);
346 
347  virtual void setModel(
348  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel);
349 
351  {
352  return this->wrapperModel_;
353  }
354 
355  virtual void setModelPair(
357 
358  virtual void setModelPair(
359  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& explicitModel,
360  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& implicitModel);
361 
363  virtual void initialize();
364 
366  virtual void setInitialConditions(
367  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
368 
370  virtual void takeStep(
371  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
372 
374  virtual Scalar getOrder() const { return order_; }
375  virtual Scalar getOrderMin() const { return order_; }
376  virtual Scalar getOrderMax() const { return order_; }
377 
378  virtual bool isExplicit() const { return true; }
379  virtual bool isImplicit() const { return true; }
380  virtual bool isExplicitImplicit() const
381  {
382  return isExplicit() && isImplicit();
383  }
384  virtual bool isOneStepMethod() const { return true; }
385  virtual bool isMultiStepMethod() const { return !isOneStepMethod(); }
386  virtual OrderODE getOrderODE() const { return FIRST_ORDER_ODE; }
388 
389  std::vector<Teuchos::RCP<Thyra::VectorBase<Scalar> > >& getStageF()
390  {
391  return stageF_;
392  }
393  std::vector<Teuchos::RCP<Thyra::VectorBase<Scalar> > >& getStageG()
394  {
395  return stageG_;
396  }
398 
400  virtual Scalar getAlpha(const Scalar dt) const
401  {
403  return Scalar(1.0) / (dt * A(0, 0)); // Getting the first diagonal coeff!
404  }
406  virtual Scalar getBeta(const Scalar) const { return Scalar(1.0); }
407 
409 
411 
412  virtual void describe(Teuchos::FancyOStream& out,
413  const Teuchos::EVerbosityLevel verbLevel) const;
415 
416  virtual bool isValidSetup(Teuchos::FancyOStream& out) const;
417 
419  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& X, Scalar time,
420  Scalar stepSize, Scalar stageNumber,
421  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& G) const;
422 
423  void evalExplicitModel(
424  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& X, Scalar time,
425  Scalar stepSize, Scalar stageNumber,
426  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& F) const;
427 
428  void setOrder(Scalar order) { order_ = order; }
429 
430  protected:
433 
434  Scalar order_;
435 
436  std::vector<Teuchos::RCP<Thyra::VectorBase<Scalar> > > stageF_;
437  std::vector<Teuchos::RCP<Thyra::VectorBase<Scalar> > > stageG_;
438 
440 };
441 
454 template <typename Scalar>
456  : virtual public Tempus::TimeDerivative<Scalar> {
457  public:
460  Scalar s, Teuchos::RCP<const Thyra::VectorBase<Scalar> > xTilde)
461  {
462  initialize(s, xTilde);
463  }
464 
467 
469  virtual void compute(
472  Teuchos::RCP<Thyra::VectorBase<Scalar> > xDotDot = Teuchos::null)
473  {
474  xDotDot = Teuchos::null;
475 
476  // ith stage
477  // s = 1/(dt*a_ii)
478  // xOld = solution at beginning of time step
479  // xTilde = xOld + dt*(Sum_{j=1}^{i-1} a_ij x_dot_j)
480  // xDotTilde = - (s*x_i - s*xTilde)
481  Thyra::V_StVpStV(xDot.ptr(), s_, *x, -s_, *xTilde_);
482  }
483 
484  virtual void initialize(Scalar s,
486  {
487  s_ = s;
488  xTilde_ = xTilde;
489  }
490 
491  private:
493  Scalar s_; // = 1/(dt*a_ii)
494 };
495 
497 // ------------------------------------------------------------------------
498 template <class Scalar>
500  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model,
501  std::string stepperType, Teuchos::RCP<Teuchos::ParameterList> pl);
502 
503 } // namespace Tempus
504 #endif // Tempus_StepperIMEX_RK_decl_hpp
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void setImplicitTableau(Teuchos::RCP< const RKButcherTableau< Scalar > > implicitTableau)
Set the implicit tableau from tableau.
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getModel() const
virtual Teuchos::RCP< const RKButcherTableau< Scalar > > getImplicitTableau() const
Return implicit tableau.
virtual Scalar getOrder() const
Teuchos::RCP< WrapperModelEvaluator< Scalar > > wrapperModel_
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
std::vector< Teuchos::RCP< Thyra::VectorBase< Scalar > > > & getStageF()
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
virtual void setExplicitTableau(Teuchos::RCP< const RKButcherTableau< Scalar > > explicitTableau)
Set the explicit tableau from tableau.
Teuchos::RCP< Thyra::VectorBase< Scalar > > xTilde_
virtual bool isMultiStepMethod() const
virtual void initialize(Scalar s, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xTilde)
StepperIMEX_RKTimeDerivative(Scalar s, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xTilde)
Constructor.
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.
Teuchos::RCP< const RKButcherTableau< Scalar > > implicitTableau_
Teuchos::RCP< Thyra::VectorBase< Scalar > > & getXTilde()
StepperIMEX_RK(std::string stepperType="IMEX RK SSP2")
Default constructor.
virtual Teuchos::RCP< const RKButcherTableau< Scalar > > getExplicitTableau() const
Return explicit tableau.
Base class for Runge-Kutta methods, ExplicitRK, DIRK and IMEX.
virtual void setModelPair(const Teuchos::RCP< WrapperModelEvaluatorPairIMEX_Basic< Scalar > > &mePair)
Create WrapperModelPairIMEX from user-supplied ModelEvaluator pair.
Thyra Base interface for implicit time steppers.
Application Action for StepperRKBase.
Teuchos::RCP< const RKButcherTableau< Scalar > > explicitTableau_
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
virtual void initialize()
Initialize during construction and after changing input parameters.
virtual Scalar getOrderMin() const
virtual bool isExplicitImplicit() const
void evalExplicitModel(const Teuchos::RCP< const Thyra::VectorBase< Scalar > > &X, Scalar time, Scalar stepSize, Scalar stageNumber, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &F) const
std::vector< Teuchos::RCP< Thyra::VectorBase< Scalar > > > stageF_
std::vector< Teuchos::RCP< Thyra::VectorBase< Scalar > > > & getStageG()
virtual void setTableaus(std::string stepperType="", Teuchos::RCP< const RKButcherTableau< Scalar > > explicitTableau=Teuchos::null, Teuchos::RCP< const RKButcherTableau< Scalar > > implicitTableau=Teuchos::null)
Set both the explicit and implicit tableau from ParameterList.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual OrderODE getOrderODE() const
virtual Scalar getBeta(const Scalar) const
Return beta = d(x)/dx.
Stepper integrates first-order ODEs.
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
void evalImplicitModelExplicitly(const Teuchos::RCP< const Thyra::VectorBase< Scalar > > &X, Scalar time, Scalar stepSize, Scalar stageNumber, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &G) const
virtual Scalar getOrderMax() const
This interface defines the time derivative connection between an implicit Stepper and WrapperModelEva...
virtual bool isOneStepMethod() const
virtual Teuchos::RCP< const RKButcherTableau< Scalar > > getTableau() const
Returns the explicit tableau!
std::vector< Teuchos::RCP< Thyra::VectorBase< Scalar > > > stageG_
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Provide a StepperState to the SolutionState. This Stepper does not have any special state data...
Time-derivative interface for IMEX RK.
Teuchos::RCP< const Thyra::VectorBase< Scalar > > xTilde_
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
Set the model.
Teuchos::RCP< StepperIMEX_RK< Scalar > > createStepperIMEX_RK(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, std::string stepperType, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
virtual Scalar getAlpha(const Scalar dt) const
Return alpha = d(xDot)/dx.