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  private:
42  /* \brief Adaptor execute function
43  *
44  * This is an adaptor function to bridge between the AppAction
45  * interface and the ModifierX interface. It is meant to be private
46  * and non-virtual as deriving from this class should only need to
47  * implement the modify function.
48  *
49  * For the ModifierX interface, this adaptor maps the
50  * StepperRKAppAction::ACTION_LOCATION to the
51  * StepperRKModifierX::MODIFIERX_TYPE, and only pass the solution
52  * (\f$x\f$ and/or \f$\dot{x}\f$ and other parameters to the modify
53  * function.
54  */
55  void execute(
58  const typename StepperRKAppAction<Scalar>::ACTION_LOCATION actLoc)
59  {
60  using Teuchos::RCP;
61 
62  MODIFIER_TYPE modType = X_BEGIN_STEP;
63  const int stageNumber = stepper->getStageNumber();
64  Teuchos::SerialDenseVector<int, Scalar> c = stepper->getTableau()->c();
65  RCP<SolutionState<Scalar> > workingState = sh->getWorkingState();
66  const Scalar dt = workingState->getTimeStep();
67  Scalar time = sh->getCurrentState()->getTime();
68  if (stageNumber >= 0) time += c(stageNumber) * dt;
69  RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
70 
71  switch (actLoc) {
73  modType = X_BEGIN_STEP;
74  break;
75  }
77  modType = X_BEGIN_STAGE;
78  break;
79  }
81  modType = X_BEFORE_SOLVE;
82  break;
83  }
85  modType = X_AFTER_SOLVE;
86  break;
87  }
89  modType = X_BEFORE_EXPLICIT_EVAL;
90  break;
91  }
93  modType = X_END_STAGE;
94  break;
95  }
97  modType = X_END_STEP;
98  time = workingState->getTime();
99  break;
100  }
101  default:
102  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
103  "Error - unknown action location.\n");
104  }
105 
106  this->modify(x, time, dt, stageNumber, modType);
107  }
108 
109  public:
119  };
120 
122  virtual void modify(Teuchos::RCP<Thyra::VectorBase<Scalar> > /* x */,
123  const Scalar /* time */, const Scalar /* dt */,
124  const int /* stageNumber */,
125  const MODIFIER_TYPE modType) = 0;
126 };
127 
128 } // namespace Tempus
129 
130 #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.