9 #ifndef Tempus_StepperLeapfrog_impl_hpp
10 #define Tempus_StepperLeapfrog_impl_hpp
12 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
13 #include "Thyra_VectorStdOps.hpp"
19 template<
class Scalar>
22 this->setStepperType(
"Leapfrog");
23 this->setUseFSAL( this->getUseFSALDefault());
24 this->setICConsistency( this->getICConsistencyDefault());
25 this->setICConsistencyCheck( this->getICConsistencyCheckDefault());
31 template<
class Scalar>
33 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
36 std::string ICConsistency,
37 bool ICConsistencyCheck)
39 this->setStepperType(
"Leapfrog");
40 this->setUseFSAL( useFSAL);
41 this->setICConsistency( ICConsistency);
42 this->setICConsistencyCheck( ICConsistencyCheck);
44 this->setObserver(obs);
46 if (appModel != Teuchos::null) {
48 this->setModel(appModel);
54 template<
class Scalar>
58 if (this->stepperObserver_ == Teuchos::null)
59 this->stepperObserver_ =
62 if (obs == Teuchos::null) {
63 if (stepperLFObserver_ == Teuchos::null)
65 if (this->stepperObserver_->getSize() == 0)
66 this->stepperObserver_->addObserver(stepperLFObserver_);
70 this->stepperObserver_->addObserver(stepperLFObserver_);
73 this->isInitialized_ =
false;
77 template<
class Scalar>
83 RCP<SolutionState<Scalar> > initialState = solutionHistory->getCurrentState();
86 if (initialState->getXDotDot() == Teuchos::null)
87 this->setStepperXDotDot(initialState->getX()->clone_v());
91 if (this->getUseFSAL()) {
92 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
93 Teuchos::OSTab ostab(out,1,
"StepperLeapfrog::setInitialConditions()");
94 *out <<
"Warning -- The First-Step-As-Last (FSAL) principle is not "
95 <<
"used with Leapfrog because of the algorithm's prescribed "
96 <<
"order of solution update. The default is to set useFSAL=false, "
97 <<
"however useFSAL=true will also work but have no affect "
98 <<
"(i.e., no-op).\n" << std::endl;
102 template<
class Scalar>
106 this->checkInitialized();
110 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperLeapfrog::takeStep()");
112 TEUCHOS_TEST_FOR_EXCEPTION(solutionHistory->getNumStates() < 2,
114 "Error - StepperLeapfrog<Scalar>::takeStep(...)\n"
115 "Need at least two SolutionStates for Leapfrog.\n"
116 " Number of States = " << solutionHistory->getNumStates() <<
"\n"
117 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
118 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
121 RCP<SolutionState<Scalar> > currentState=solutionHistory->getCurrentState();
122 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
123 const Scalar time = currentState->getTime();
124 const Scalar dt = workingState->getTimeStep();
128 if (workingState->getIsSynced() ==
true) {
129 if (!Teuchos::is_null(stepperLFObserver_))
130 stepperLFObserver_->observeBeforeXDotUpdateInitialize(
131 solutionHistory, *
this);
133 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
134 *(currentState->getXDot()),0.5*dt,*(currentState->getXDotDot()));
137 if (!Teuchos::is_null(stepperLFObserver_))
138 stepperLFObserver_->observeBeforeXUpdate(solutionHistory, *
this);
140 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getX())),
141 *(currentState->getX()),dt,*(workingState->getXDot()));
143 if (!Teuchos::is_null(stepperLFObserver_))
144 stepperLFObserver_->observeBeforeExplicit(solutionHistory, *
this);
149 this->evaluateExplicitODE(workingState->getXDotDot(),
150 workingState->getX(),
151 Teuchos::null, time+dt, p);
153 if (!Teuchos::is_null(stepperLFObserver_))
154 stepperLFObserver_->observeBeforeXDotUpdate(solutionHistory, *
this);
155 if (workingState->getOutput() ==
true) {
157 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
158 *(workingState->getXDot()),0.5*dt,*(workingState->getXDotDot()));
159 workingState->setIsSynced(
true);
162 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
163 *(workingState->getXDot()),dt,*(workingState->getXDotDot()));
164 workingState->setIsSynced(
false);
168 workingState->setOrder(this->getOrder());
169 workingState->computeNorms(currentState);
182 template<
class Scalar>
186 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
192 template<
class Scalar>
194 Teuchos::FancyOStream &out,
195 const Teuchos::EVerbosityLevel verbLevel)
const
201 out <<
"--- StepperLeapfrog ---\n";
202 out <<
" stepperLFObserver_ = " << stepperLFObserver_ << std::endl;
203 out <<
"-----------------------" << std::endl;
207 template<
class Scalar>
210 bool isValidSetup =
true;
215 if (stepperLFObserver_ == Teuchos::null) {
216 isValidSetup =
false;
217 out <<
"The Leapfrog observer is not set!\n";
224 template<
class Scalar>
225 Teuchos::RCP<const Teuchos::ParameterList>
228 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
230 pl->set<std::string>(
"Initial Condition Consistency",
231 this->getICConsistencyDefault());
237 #endif // Tempus_StepperLeapfrog_impl_hpp
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)
Set Observer.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
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.
This observer is a composite observer,.
StepperState is a simple class to hold state information about the stepper.
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
StepperObserver class for Stepper class.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
StepperLeapfrog()
Default constructor.
StepperLeapfrogObserver class for StepperLeapfrog.
Thyra Base interface for implicit time steppers.
void getValidParametersBasic(Teuchos::RCP< Teuchos::ParameterList > pl, std::string stepperType)
Provide basic parameters to Steppers.