Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_StepperRKModifierXBase.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_StepperRKModifierXBase_hpp
10 #define Tempus_StepperRKModifierXBase_hpp
11 
12 #include "Tempus_config.hpp"
13 #include "Tempus_SolutionHistory.hpp"
15 
17 
18 namespace Tempus {
19 
38 template<class Scalar>
40  : virtual public Tempus::StepperRKAppAction<Scalar>
41 {
42 private:
43 
44  /* \brief Adaptor execute function
45  *
46  * This is an adaptor function to bridge between the AppAction
47  * interface and the ModifierX interface. It is meant to be private
48  * and non-virtual as deriving from this class should only need to
49  * implement the modify function.
50  *
51  * For the ModifierX interface, this adaptor maps the
52  * StepperRKAppAction::ACTION_LOCATION to the
53  * StepperRKModifierX::MODIFIERX_TYPE, and only pass the solution
54  * (\f$x\f$ and/or \f$\dot{x}\f$ and other parameters to the modify
55  * function.
56  */
57  void execute(
60  const typename StepperRKAppAction<Scalar>::ACTION_LOCATION actLoc)
61  {
62  using Teuchos::RCP;
63 
64  MODIFIER_TYPE modType = X_BEGIN_STEP;
65  const int stageNumber = stepper->getStageNumber();
66  Teuchos::SerialDenseVector<int,Scalar> c = stepper->getTableau()->c();
67  RCP<SolutionState<Scalar> > workingState = sh->getWorkingState();
68  const Scalar dt = workingState->getTimeStep();
69  Scalar time = sh->getCurrentState()->getTime();
70  if (stageNumber >= 0) time += c(stageNumber)*dt;
71  RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
72 
73  switch(actLoc) {
75  {
76  modType = X_BEGIN_STEP;
77  break;
78  }
80  {
81  modType = X_BEGIN_STAGE;
82  break;
83  }
85  {
86  modType = X_BEFORE_SOLVE;
87  break;
88  }
90  {
91  modType = X_AFTER_SOLVE;
92  break;
93  }
95  {
96  modType = X_BEFORE_EXPLICIT_EVAL;
97  break;
98  }
100  {
101  modType = X_END_STAGE;
102  break;
103  }
105  {
106  modType = X_END_STEP;
107  time = workingState->getTime();
108  break;
109  }
110  default:
111  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
112  "Error - unknown action location.\n");
113  }
114 
115  this->modify(x, time, dt, stageNumber, modType);
116  }
117 
118 public:
119 
129  };
130 
132  virtual void modify(
134  const Scalar /* time */, const Scalar /* dt */,
135  const int /* stageNumber */,
136  const MODIFIER_TYPE modType) = 0;
137 
138 };
139 
140 } // namespace Tempus
141 
142 #endif // Tempus_StepperRKModifierXBase_hpp
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Base class for Runge-Kutta methods, ExplicitRK, DIRK and IMEX.
Application Action for StepperRKBase.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
ACTION_LOCATION
Indicates the location of application action (see algorithm).
void execute(Teuchos::RCP< SolutionHistory< Scalar > > sh, Teuchos::RCP< StepperRKBase< Scalar > > stepper, const typename StepperRKAppAction< Scalar >::ACTION_LOCATION actLoc)
Execute application action for RK Stepper.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< Scalar > >, const Scalar, const Scalar, const int, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.