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>
59 if (this->stepperObserver_ == Teuchos::null)
60 this->stepperObserver_ =
63 if (( obs == Teuchos::null ) and (this->stepperObserver_->getSize() == 0) )
66 this->stepperObserver_->addObserver(
71 template<
class Scalar>
74 TEUCHOS_TEST_FOR_EXCEPTION(
75 this->appModel_ == Teuchos::null, std::logic_error,
76 "Error - Need to set the model, setModel(), before calling "
77 "StepperLeapfrog::initialize()\n");
82 template<
class Scalar>
88 RCP<SolutionState<Scalar> > initialState =
solutionHistory->getCurrentState();
91 if (initialState->getXDotDot() == Teuchos::null)
92 this->setStepperXDotDot(initialState->getX()->clone_v());
96 if (this->getUseFSAL()) {
97 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
98 Teuchos::OSTab ostab(out,1,
"StepperLeapfrog::setInitialConditions()");
99 *out <<
"Warning -- The First-Step-As-Last (FSAL) principle is not "
100 <<
"used with Leapfrog because of the algorithm's prescribed "
101 <<
"order of solution update. The default is to set useFSAL=false, "
102 <<
"however useFSAL=true will also work but have no affect "
103 <<
"(i.e., no-op).\n" << std::endl;
107 template<
class Scalar>
113 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperLeapfrog::takeStep()");
117 "Error - StepperLeapfrog<Scalar>::takeStep(...)\n"
118 "Need at least two SolutionStates for Leapfrog.\n"
120 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
121 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
124 RCP<SolutionState<Scalar> > currentState=
solutionHistory->getCurrentState();
125 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
126 const Scalar time = currentState->getTime();
127 const Scalar dt = workingState->getTimeStep();
131 if (workingState->getIsSynced() ==
true) {
132 if (!Teuchos::is_null(stepperLFObserver_))
133 stepperLFObserver_->observeBeforeXDotUpdateInitialize(
136 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
137 *(currentState->getXDot()),0.5*dt,*(currentState->getXDotDot()));
140 if (!Teuchos::is_null(stepperLFObserver_))
143 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getX())),
144 *(currentState->getX()),dt,*(workingState->getXDot()));
146 if (!Teuchos::is_null(stepperLFObserver_))
152 this->evaluateExplicitODE(workingState->getXDotDot(),
153 workingState->getX(),
154 Teuchos::null, time+dt, p);
156 if (!Teuchos::is_null(stepperLFObserver_))
158 if (workingState->getOutput() ==
true) {
160 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
161 *(workingState->getXDot()),0.5*dt,*(workingState->getXDotDot()));
162 workingState->setIsSynced(
true);
165 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
166 *(workingState->getXDot()),dt,*(workingState->getXDotDot()));
167 workingState->setIsSynced(
false);
171 workingState->setOrder(this->getOrder());
184 template<
class Scalar>
188 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
194 template<
class Scalar>
196 Teuchos::FancyOStream &out,
197 const Teuchos::EVerbosityLevel )
const
199 out << this->getStepperType() <<
"::describe:" << std::endl
200 <<
"appModel_ = " << this->appModel_->description() << std::endl;
204 template<
class Scalar>
205 Teuchos::RCP<const Teuchos::ParameterList>
208 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
210 pl->set<std::string>(
"Initial Condition Consistency",
211 this->getICConsistencyDefault());
217 #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.
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 setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions, make them consistent, and set needed memory.
StepperObserver class for Stepper class.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
StepperLeapfrog()
Default constructor.
StepperLeapfrogObserver class for StepperLeapfrog.
void getValidParametersBasic(Teuchos::RCP< Teuchos::ParameterList > pl, std::string stepperType)
Provide basic parameters to Steppers.
virtual void initialize()
Initialize during construction and after changing input parameters.