9 #ifndef Tempus_StepperLeapfrog_impl_hpp
10 #define Tempus_StepperLeapfrog_impl_hpp
12 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
13 #include "Thyra_VectorStdOps.hpp"
18 template<
class Scalar>
21 this->setParameterList(Teuchos::null);
25 template<
class Scalar>
27 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
28 Teuchos::RCP<Teuchos::ParameterList> pList)
30 this->setParameterList(pList);
32 if (appModel == Teuchos::null) {
36 this->setModel(appModel);
41 template<
class Scalar>
45 if (obs == Teuchos::null) {
47 if (this->stepperObserver_ == Teuchos::null) {
50 this->stepperObserver_ =
54 this->stepperObserver_ = obs;
57 (this->stepperObserver_);
61 template<
class Scalar>
64 TEUCHOS_TEST_FOR_EXCEPTION(
65 this->appModel_ == Teuchos::null, std::logic_error,
66 "Error - Need to set the model, setModel(), before calling "
67 "StepperLeapfrog::initialize()\n");
69 this->setParameterList(this->stepperPL_);
73 template<
class Scalar>
79 RCP<SolutionState<Scalar> > initialState =
solutionHistory->getCurrentState();
82 if (initialState->getXDotDot() == Teuchos::null)
83 this->setStepperXDotDot(initialState->getX()->clone_v());
87 if (this->getUseFSAL()) {
88 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
89 Teuchos::OSTab ostab(out,1,
"StepperLeapfrog::setInitialConditions()");
90 *out <<
"Warning -- The First-Step-As-Last (FSAL) principle is not "
91 <<
"used with Leapfrog because of the algorithm's prescribed "
92 <<
"order of solution update. The default is to set useFSAL=false, "
93 <<
"however useFSAL=true will also work but have no affect "
94 <<
"(i.e., no-op).\n" << std::endl;
98 template<
class Scalar>
104 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperLeapfrog::takeStep()");
108 "Error - StepperLeapfrog<Scalar>::takeStep(...)\n"
109 "Need at least two SolutionStates for Leapfrog.\n"
111 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
112 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
115 RCP<SolutionState<Scalar> > currentState=
solutionHistory->getCurrentState();
116 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
117 const Scalar time = currentState->getTime();
118 const Scalar dt = workingState->getTimeStep();
122 if (workingState->getIsSynced() ==
true) {
123 if (!Teuchos::is_null(stepperLFObserver_))
124 stepperLFObserver_->observeBeforeXDotUpdateInitialize(
127 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
128 *(currentState->getXDot()),0.5*dt,*(currentState->getXDotDot()));
131 if (!Teuchos::is_null(stepperLFObserver_))
134 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getX())),
135 *(currentState->getX()),dt,*(workingState->getXDot()));
137 if (!Teuchos::is_null(stepperLFObserver_))
141 this->evaluateExplicitODE(workingState->getXDotDot(),
142 workingState->getX(),
143 Teuchos::null, time+dt);
145 if (!Teuchos::is_null(stepperLFObserver_))
147 if (workingState->getOutput() ==
true) {
149 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
150 *(workingState->getXDot()),0.5*dt,*(workingState->getXDotDot()));
151 workingState->setIsSynced(
true);
154 Thyra::V_VpStV(Teuchos::outArg(*(workingState->getXDot())),
155 *(workingState->getXDot()),dt,*(workingState->getXDotDot()));
156 workingState->setIsSynced(
false);
160 workingState->setOrder(this->getOrder());
173 template<
class Scalar>
177 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
183 template<
class Scalar>
186 std::string name =
"Leapfrog";
191 template<
class Scalar>
193 Teuchos::FancyOStream &out,
194 const Teuchos::EVerbosityLevel )
const
196 out << description() <<
"::describe:" << std::endl
197 <<
"appModel_ = " << this->appModel_->description() << std::endl;
201 template <
class Scalar>
203 const Teuchos::RCP<Teuchos::ParameterList> & pList)
205 if (pList == Teuchos::null) {
207 if (this->stepperPL_ == Teuchos::null)
208 this->stepperPL_ = this->getDefaultParameters();
210 this->stepperPL_ = pList;
212 this->stepperPL_->validateParametersAndSetDefaults(*this->getValidParameters());
214 std::string stepperType =
215 this->stepperPL_->template get<std::string>(
"Stepper Type");
216 TEUCHOS_TEST_FOR_EXCEPTION( stepperType !=
"Leapfrog",
218 "Error - Stepper Type is not 'Leapfrog'!\n"
219 <<
" Stepper Type = "<< pList->get<std::string>(
"Stepper Type") <<
"\n");
223 template<
class Scalar>
224 Teuchos::RCP<const Teuchos::ParameterList>
227 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
228 pl->setName(
"Default Stepper - " + this->description());
229 pl->set<std::string>(
"Stepper Type",
"Leapfrog",
230 "'Stepper Type' must be 'Leapfrog'.");
231 this->getValidParametersBasic(pl);
232 pl->set<std::string>(
"Initial Condition Consistency",
"Consistent");
237 template<
class Scalar>
238 Teuchos::RCP<Teuchos::ParameterList>
242 using Teuchos::ParameterList;
243 using Teuchos::rcp_const_cast;
245 RCP<ParameterList> pl =
246 rcp_const_cast<ParameterList>(this->getValidParameters());
252 template <
class Scalar>
253 Teuchos::RCP<Teuchos::ParameterList>
256 return(this->stepperPL_);
260 template <
class Scalar>
261 Teuchos::RCP<Teuchos::ParameterList>
264 Teuchos::RCP<Teuchos::ParameterList> temp_plist = this->stepperPL_;
265 this->stepperPL_ = Teuchos::null;
271 #endif // Tempus_StepperLeapfrog_impl_hpp
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
Teuchos::RCP< Teuchos::ParameterList > getDefaultParameters() const
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl)
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.
StepperState is a simple class to hold state information about the stepper.
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
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.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
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...
virtual std::string description() const
StepperLeapfrog()
Default constructor.
StepperLeapfrogObserver class for StepperLeapfrog.
virtual void initialize()
Initialize during construction and after changing input parameters.