9 #ifndef Tempus_StepperLeapfrog_impl_hpp
10 #define Tempus_StepperLeapfrog_impl_hpp
12 #include "Thyra_VectorStdOps.hpp"
18 template <
class Scalar>
21 this->setStepperName(
"Leapfrog");
22 this->setStepperType(
"Leapfrog");
23 this->setUseFSAL(
false);
24 this->setICConsistency(
"Consistent");
25 this->setICConsistencyCheck(
false);
27 this->setAppAction(Teuchos::null);
30 template <
class Scalar>
33 bool useFSAL, std::string ICConsistency,
bool ICConsistencyCheck,
36 this->setStepperName(
"Leapfrog");
37 this->setStepperType(
"Leapfrog");
38 this->setUseFSAL(useFSAL);
39 this->setICConsistency(ICConsistency);
40 this->setICConsistencyCheck(ICConsistencyCheck);
41 this->setAppAction(stepperLFAppAction);
42 if (appModel != Teuchos::null) {
43 this->setModel(appModel);
48 template <
class Scalar>
52 if (appAction == Teuchos::null) {
58 stepperLFAppAction_ = appAction;
62 template <
class Scalar>
68 RCP<SolutionState<Scalar> > initialState = solutionHistory->getCurrentState();
71 if (initialState->getXDotDot() == Teuchos::null)
72 this->setStepperXDotDot(initialState->getX()->clone_v());
74 this->setStepperXDotDot(initialState->getXDotDot());
78 if (this->getUseFSAL()) {
80 Teuchos::OSTab ostab(out, 1,
"StepperLeapfrog::setInitialConditions()");
81 *out <<
"Warning -- The First-Same-As-Last (FSAL) principle is not "
82 <<
"used with Leapfrog because of the algorithm's prescribed "
83 <<
"order of solution update. The default is to set useFSAL=false, "
84 <<
"however useFSAL=true will also work but have no affect "
90 template <
class Scalar>
94 this->checkInitialized();
98 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperLeapfrog::takeStep()");
101 solutionHistory->getNumStates() < 2, std::logic_error,
102 "Error - StepperLeapfrog<Scalar>::takeStep(...)\n"
103 <<
"Need at least two SolutionStates for Leapfrog.\n"
104 <<
" Number of States = " << solutionHistory->getNumStates()
105 <<
"\nTry setting in \"Solution History\" \"Storage Type\" = "
107 <<
" or \"Storage Type\" = \"Static\" and \"Storage Limit\" = "
110 RCP<SolutionState<Scalar> > currentState =
111 solutionHistory->getCurrentState();
112 RCP<SolutionState<Scalar> > workingState =
113 solutionHistory->getWorkingState();
114 const Scalar time = currentState->getTime();
115 const Scalar dt = workingState->getTimeStep();
117 RCP<StepperLeapfrog<Scalar> > thisStepper = Teuchos::rcpFromRef(*
this);
119 stepperLFAppAction_->execute(
120 solutionHistory, thisStepper,
125 if (workingState->getIsSynced() ==
true) {
127 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
128 *(currentState->getXDot()), 0.5 * dt,
129 *(currentState->getXDotDot()));
131 stepperLFAppAction_->execute(
132 solutionHistory, thisStepper,
135 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getX())),
136 *(currentState->getX()), dt, *(workingState->getXDot()));
138 stepperLFAppAction_->execute(
139 solutionHistory, thisStepper,
141 Scalar>::ACTION_LOCATION::BEFORE_EXPLICIT_EVAL);
145 this->evaluateExplicitODE(workingState->getXDotDot(), workingState->getX(),
146 Teuchos::null, time + dt, p);
147 stepperLFAppAction_->execute(
148 solutionHistory, thisStepper,
150 if (workingState->getOutput() ==
true) {
152 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
153 *(workingState->getXDot()), 0.5 * dt,
154 *(workingState->getXDotDot()));
155 workingState->setIsSynced(
true);
159 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
160 *(workingState->getXDot()), dt,
161 *(workingState->getXDotDot()));
162 workingState->setIsSynced(
false);
166 workingState->setOrder(this->getOrder());
167 workingState->computeNorms(currentState);
169 stepperLFAppAction_->execute(
170 solutionHistory, thisStepper,
182 template <
class Scalar>
191 template <
class Scalar>
200 out <<
"--- StepperLeapfrog ---\n";
201 out <<
" stepperLFAppAction_ = " << stepperLFAppAction_
203 out <<
"-----------------------" << std::endl;
206 template <
class Scalar>
210 bool isValidSetup =
true;
214 if (stepperLFAppAction_ == Teuchos::null) {
215 isValidSetup =
false;
216 out <<
"The Leapfrog AppAction is not set!\n";
224 template <
class Scalar>
230 stepper->setStepperExplicitValues(pl);
232 if (model != Teuchos::null) {
233 stepper->setModel(model);
234 stepper->initialize();
241 #endif // Tempus_StepperLeapfrog_impl_hpp
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
Teuchos::RCP< StepperLeapfrog< Scalar > > createStepperLeapfrog(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
Default modifier for StepperLeapfrog.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
Thyra Base interface for time steppers.
StepperState is a simple class to hold state information about the stepper.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Application Action for StepperLeapfrog.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions, make them consistent, and set needed memory.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
StepperLeapfrog()
Default constructor.
virtual void setAppAction(Teuchos::RCP< StepperLeapfrogAppAction< Scalar > > appAction)
Thyra Base interface for implicit time steppers.