Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros 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 
16 
17 namespace Tempus {
18 
19 /** \brief Base ModifierX for StepperRK.
20  *
21  * This class provides a means to modify just the solution values
22  * (i.e., \f$x\f$ and \f$dot{x}\f$), and nothing else, but time and
23  * timestep are also provided.
24  *
25  * Users deriving from this class can access and change the solution
26  * during the timestep (e.g., limiting the solution for monoticity).
27  * It is expected that the user knows what changes are allowable without
28  * affecting the Stepper correctness, performance, accuracy and stability
29  * (i.e., USER BEWARE!!).
30  *
31  * Below is the RK algorithm with the locations of the ModifierX calls
32  * italicized.
33  *
34  * \f{algorithm}{
35  * \renewcommand{\thealgorithm}{}
36  * \caption{Backward Euler with modify calls indicated.}
37  * \begin{algorithmic}[1]
38  * \State \quad {\it modifierX.modify(x, time, dt, X\_BEGIN\_STEP)}
39  * \State Compute the predictor (e.g., apply stepper to $x_n$).
40  * \State \quad {\it modifierX.modify(x, time, dt, X\_BEFORE\_SOLVE)}
41  * \State Solve $\mathcal{F}_n(\dot{x}=(x_n-x_{n-1})/\Delta t_n, x_n, t_n)=0$ for $x_n$
42  * \State \quad {\it modifierX.modify(x, time, dt, X\_AFTER\_SOLVE)}
43  * \State $\dot{x}_n \leftarrow (x_n-x_{n-1})/\Delta t_n$
44  * \State \quad {\it modifierX.modify(x, time, dt, XDOT\_END\_STEP)}
45  * \end{algorithmic}
46  * \f}
47  */
48 template<class Scalar>
50  : virtual public Tempus::StepperRKAppAction<Scalar>
51 {
52 private:
53 
54  /* \brief Adaptor execute function
55  *
56  * This is an adaptor function to bridge between the AppAction
57  * interface and the ModifierX interface. It is meant to be private
58  * and non-virtual as deriving from this class should only need to
59  * implement the modify function.
60  *
61  * For the ModifierX interface, this adaptor maps the
62  * StepperRKAppAction::ACTION_LOCATION to the
63  * StepperRKModifierX::MODIFIERX_TYPE, and only pass the solution
64  * (\f$x\f$ and/or \f$\dot{x}\f$ and other parameters to the modify
65  * function.
66  */
67  void execute(
68  Teuchos::RCP<SolutionHistory<Scalar> > sh,
69  Teuchos::RCP<StepperRKBase<Scalar> > stepper,
70  const typename StepperRKAppAction<Scalar>::ACTION_LOCATION actLoc)
71  {
72  using Teuchos::RCP;
73 
74  MODIFIER_TYPE modType = X_BEGIN_STEP;
75  RCP<SolutionState<Scalar> > workingState = sh->getWorkingState();
76  const Scalar time = workingState->getTime();
77  const Scalar dt = workingState->getTimeStep();
78  const int stageNumber = stepper->getStageNumber();
79  RCP<Thyra::VectorBase<Scalar> > x;
80 
81  switch(actLoc) {
83  {
84  modType = X_BEGIN_STEP;
85  x = workingState->getX();
86  break;
87  }
89  {
90  modType = X_BEGIN_STAGE;
91  x = workingState->getX();
92  break;
93  }
95  {
96  modType = X_BEFORE_SOLVE;
97  x = workingState->getX();
98  break;
99  }
101  {
102  modType = X_AFTER_SOLVE;
103  x = workingState->getX();
104  break;
105  }
107  {
108  modType = X_BEFORE_EXPLICIT_EVAL;
109  x = stepper->getStageX();
110  break;
111  }
113  {
114  modType = X_END_STAGE;
115  x = stepper->getStageX();
116  break;
117  }
119  {
120  modType = X_END_STEP;
121  x = workingState->getX();
122  break;
123  }
124  default:
125  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
126  "Error - unknown action location.\n");
127  }
128 
129  this->modify(x, time, dt, stageNumber, modType);
130  }
131 
132 public:
133 
134  /// Indicates the location of application action (see algorithm).
136  X_BEGIN_STEP, ///< Modify \f$x\f$ at the beginning of the step.
137  X_BEGIN_STAGE, ///< Modify \f$x\f$ at the beginning of the stage.
138  X_BEFORE_SOLVE, ///< Modify \f$x\f$ before the implicit solve.
139  X_AFTER_SOLVE, ///< Modify \f$x\f$ after the implicit solve.
140  X_BEFORE_EXPLICIT_EVAL, ///< Modify \f$x\f$ before the explicit evaluation.
141  X_END_STAGE, ///< Modify \f$x\f$ at the end of the stage.
142  X_END_STEP ///< Modify \f$x\f$ at the end of the step.
143  };
144 
145  /// Modify solution based on the MODIFIER_TYPE.
146  virtual void modify(
147  Teuchos::RCP<Thyra::VectorBase<Scalar> > /* x */,
148  const Scalar /* time */, const Scalar /* dt */,
149  const int /* stageNumber */,
150  const MODIFIER_TYPE modType) = 0;
151 
152 };
153 
154 } // namespace Tempus
155 
156 #endif // Tempus_StepperRKModifierXBase_hpp
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.