Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_StepperBackwardEulerModifierXBase.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_StepperBackwardEulerModifierXBase_hpp
10 #define Tempus_StepperBackwardEulerModifierXBase_hpp
11 
12 #include "Tempus_config.hpp"
13 #include "Tempus_SolutionHistory.hpp"
15 
16 
17 namespace Tempus {
18 
19 /** \brief Base ModifierX for StepperBackwardEuler.
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 BackwardEuler 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::StepperBackwardEulerAppAction<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  * StepperBackwardEulerAppAction::ACTION_LOCATION to the
63  * StepperBackwardEulerModifierX::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<StepperBackwardEuler<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_SOLVE;
90  x = workingState->getX();
91  break;
92  }
94  {
95  modType = X_AFTER_SOLVE;
96  x = workingState->getX();
97  break;
98  }
100  {
101  modType = XDOT_END_STEP;
102  x = stepper->getStepperXDot(workingState);
103  break;
104  }
105  default:
106  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
107  "Error - unknown action location.\n");
108  }
109 
110  this->modify(x, time, dt, modType);
111  }
112 
113 public:
114 
115  /// Indicates the location of application action (see algorithm).
117  X_BEGIN_STEP, ///< Modify \f$x\f$ at the beginning of the step.
118  X_BEFORE_SOLVE, ///< Modify \f$x\f$ before the implicit solve.
119  X_AFTER_SOLVE, ///< Modify \f$x\f$ after the implicit solve.
120  XDOT_END_STEP ///< Modify \f$\dot{x}\f$ at the end of the step.
121  };
122 
123  /// Modify solution based on the MODIFIER_TYPE.
124  virtual void modify(
125  Teuchos::RCP<Thyra::VectorBase<Scalar> > /* x */,
126  const Scalar /* time */, const Scalar /* dt */,
127  const MODIFIER_TYPE modType) = 0;
128 
129 };
130 
131 } // namespace Tempus
132 
133 #endif // Tempus_StepperBackwardEulerModifierXBase_hpp
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
ACTION_LOCATION
Indicates the location of application action (see algorithm).
virtual void modify(Teuchos::RCP< Thyra::VectorBase< Scalar > >, const Scalar, const Scalar, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.
Application Action for StepperBackwardEuler.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
void execute(Teuchos::RCP< SolutionHistory< Scalar > > sh, Teuchos::RCP< StepperBackwardEuler< Scalar > > stepper, const typename StepperBackwardEulerAppAction< Scalar >::ACTION_LOCATION actLoc)
Execute application action for BackwardEuler Stepper.