Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_StepperForwardEulerModifierXBase.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_StepperForwardEulerModifierXBase_hpp
10 #define Tempus_StepperForwardEulerModifierXBase_hpp
11 
12 #include "Tempus_config.hpp"
13 #include "Tempus_SolutionHistory.hpp"
15 
16 
17 namespace Tempus {
18 
19 /** \brief Base ModifierX for StepperForwardEuler.
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 ForwardEuler algorithm with the locations of the ModifierX calls
32  * italicized.
33  *
34  * \f{algorithm}{
35  * \renewcommand{\thealgorithm}{}
36  * \caption{Forward Euler with the locations of the application actions indicated}
37  * \begin{algorithmic}[1]
38  * \State Start with $x_n$, $\Delta t_n$
39  * \State {\it appAction.execute(solutionHistory, stepper, BEGIN\_STEP)}
40  * \State Form $f(x_{n},t_{n})$
41  * \State {\it appAction.execute(solutionHistory, stepper, BEFORE\_EXPLICIT\_EVAL)}
42  * \State Form $x_n \leftarrow x_{n} + \Delta t_n f(x_{n},t_n)$
43  * \State {\it appAction.execute(solutionHistory, stepper, END\_STEP)}
44  * \end{algorithmic}
45  * \f}
46  */
47 
48 template<class Scalar>
50  : virtual public Tempus::StepperForwardEulerAppAction<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  * StepperForwardEulerAppAction::ACTION_LOCATION to the
63  * StepperForwardEulerModifierX::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<StepperForwardEuler<Scalar> > stepper,
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  RCP<Thyra::VectorBase<Scalar> > x;
79 
80  switch(actLoc) {
82  {
83  modType = X_BEGIN_STEP;
84  x = workingState->getX();
85  break;
86  }
88  {
89  modType = X_BEFORE_EXPLICIT_EVAL;
90  x = workingState->getX();
91  break;
92  }
94  {
95  modType = XDOT_END_STEP;
96  x = stepper->getStepperXDot(workingState);
97  break;
98  }
99  default:
100  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
101  "Error - unknown action location.\n");
102  }
103 
104  this->modify(x, time, dt, modType);
105  }
106 
107 public:
108 
109  /// Indicates the location of application action (see algorithm).
111  X_BEGIN_STEP, ///< Modify \f$x\f$ at the beginning of the step.
112  X_BEFORE_EXPLICIT_EVAL, ///< Modify \f$x\f$ before the implicit solve.
113  XDOT_END_STEP ///< Modify \f$\dot{x}\f$ at the end of the step.
114  };
115 
116  /// Modify solution based on the MODIFIER_TYPE.
117  virtual void modify(
118  Teuchos::RCP<Thyra::VectorBase<Scalar> > /* x */,
119  const Scalar /* time */, const Scalar /* dt */,
120  const MODIFIER_TYPE modType) = 0;
121 
122 };
123 
124 } // namespace Tempus
125 
126 #endif // Tempus_StepperForwardEulerModifierXBase_hpp
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Application Action for StepperForwardEuler.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
void execute(Teuchos::RCP< SolutionHistory< Scalar > > sh, Teuchos::RCP< StepperForwardEuler< Scalar > > stepper, const typename StepperForwardEulerAppAction< Scalar >::ACTION_LOCATION actLoc)
Execute application action for ForwardEuler Stepper.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< Scalar > >, const Scalar, const Scalar, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.