9 #ifndef Tempus_StepperBDF2_impl_hpp
10 #define Tempus_StepperBDF2_impl_hpp
12 #include "Tempus_config.hpp"
14 #include "Tempus_WrapperModelEvaluatorBasic.hpp"
15 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
16 #include "NOX_Thyra.H"
22 template<
class Scalar>
class StepperFactory;
25 template<
class Scalar>
28 this->setParameterList(Teuchos::null);
33 template<
class Scalar>
35 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
36 Teuchos::RCP<Teuchos::ParameterList> pList)
38 this->setParameterList(pList);
40 if (appModel == Teuchos::null) {
44 this->setModel(appModel);
56 template<
class Scalar>
60 using Teuchos::ParameterList;
62 RCP<ParameterList> startupStepperPL =
63 Teuchos::sublist(this->stepperPL_, startupStepperName,
true);
64 this->stepperPL_->set(
"Start Up Stepper Name", startupStepperName);
67 sf->createStepper(startupStepperPL, this->wrapperModel_->getAppModel());
77 template<
class Scalar>
79 Teuchos::RCP<Teuchos::ParameterList> startupStepperPL)
82 using Teuchos::ParameterList;
84 Teuchos::RCP<Teuchos::ParameterList> stepperPL = this->stepperPL_;
85 std::string startupStepperName =
86 stepperPL->get<std::string>(
"Start Up Stepper Name",
"None");
87 if (is_null(startupStepperPL)) {
89 if (startUpStepper_ == Teuchos::null) {
90 if (startupStepperName !=
"None") {
93 Teuchos::sublist(this->stepperPL_, startupStepperName,
true);
94 RCP<StepperFactory<Scalar> > sf =
97 sf->createStepper(startupStepperPL,this->wrapperModel_->getAppModel());
100 RCP<StepperFactory<Scalar> > sf =
103 sf->createStepper(
"IRK 1 Stage Theta Method",
104 this->wrapperModel_->getAppModel());
106 startupStepperName = startUpStepper_->description();
107 startupStepperPL = startUpStepper_->getNonconstParameterList();
108 this->stepperPL_->set(
"Start Up Stepper Name", startupStepperName);
109 this->stepperPL_->set(startupStepperName, *startupStepperPL);
113 TEUCHOS_TEST_FOR_EXCEPTION( startupStepperName == startupStepperPL->name(),
115 "Error - Trying to add a startup stepper that is already in "
116 <<
"ParameterList!\n"
117 <<
" Stepper Type = "<< stepperPL->get<std::string>(
"Stepper Type")
118 <<
"\n" <<
" Start Up Stepper Name = "<<startupStepperName<<
"\n");
119 startupStepperName = startupStepperPL->name();
120 this->stepperPL_->set(
"Start Up Stepper Name", startupStepperName);
121 this->stepperPL_->set(startupStepperName, *startupStepperPL);
122 RCP<StepperFactory<Scalar> > sf =
125 sf->createStepper(startupStepperPL, this->wrapperModel_->getAppModel());
130 template<
class Scalar>
134 if (obs == Teuchos::null) {
136 if (this->stepperObserver_ == Teuchos::null) {
137 stepperBDF2Observer_ =
139 this->stepperObserver_ =
141 (stepperBDF2Observer_);
144 this->stepperObserver_ = obs;
145 stepperBDF2Observer_ =
151 template<
class Scalar>
154 TEUCHOS_TEST_FOR_EXCEPTION( this->wrapperModel_ == Teuchos::null,
156 "Error - Need to set the model, setModel(), before calling "
157 "StepperBDF2::initialize()\n");
159 this->setParameterList(this->stepperPL_);
161 this->setStartUpStepper();
163 order_ = Scalar(2.0);
167 template<
class Scalar>
173 RCP<SolutionState<Scalar> > initialState =
solutionHistory->getCurrentState();
176 if (initialState->getXDot() == Teuchos::null)
177 this->setStepperXDot(initialState->getX()->clone_v());
181 if (this->getUseFSAL()) {
182 RCP<Teuchos::FancyOStream> out = this->getOStream();
183 Teuchos::OSTab ostab(out,1,
"StepperBDF2::setInitialConditions()");
184 *out <<
"\nWarning -- The First-Step-As-Last (FSAL) principle is not "
185 <<
"needed with Backward Euler. The default is to set useFSAL=false, "
186 <<
"however useFSAL=true will also work but have no affect "
187 <<
"(i.e., no-op).\n" << std::endl;
192 template<
class Scalar>
198 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperBDF2::takeStep()");
202 RCP<Thyra::VectorBase<Scalar> > xOld;
203 RCP<Thyra::VectorBase<Scalar> > xOldOld;
211 TEUCHOS_TEST_FOR_EXCEPTION( (numStates < 3), std::logic_error,
212 "Error in Tempus::StepperBDF2::takeStep(): numStates after \n"
213 <<
"startup stepper must be at least 3, whereas numStates = "
214 << numStates <<
"!\n" <<
"If running with Storage Type = Static, "
215 <<
"make sure Storage Limit > 2.\n");
222 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
223 RCP<SolutionState<Scalar> > currentState=
solutionHistory->getCurrentState();
225 RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
226 RCP<Thyra::VectorBase<Scalar> > xDot = this->getStepperXDot(workingState);
229 const Scalar time = workingState->getTime();
230 const Scalar dt = workingState->getTimeStep();
231 const Scalar dtOld = currentState->getTimeStep();
235 order_ = Scalar(2.0);
238 Teuchos::RCP<TimeDerivative<Scalar> > timeDer =
241 const Scalar alpha = getAlpha(dt, dtOld);
242 const Scalar beta = getBeta (dt);
244 Teuchos::RCP<ImplicitODEParameters<Scalar> > p =
248 const Thyra::SolveStatus<Scalar> sStatus =
249 this->solveImplicitODE(x, xDot, time, p);
251 if (!Teuchos::is_null(stepperBDF2Observer_))
254 if (workingState->getXDot() != Teuchos::null)
255 timeDer->compute(x, xDot);
257 workingState->setSolutionStatus(sStatus);
258 workingState->setOrder(getOrder());
264 template<
class Scalar>
268 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
269 Teuchos::OSTab ostab(out,1,
"StepperBDF2::computeStartUp()");
270 *out <<
"Warning -- Taking a startup step for BDF2 using '"
271 << startUpStepper_->description()<<
"'!" << std::endl;
276 order_ = startUpStepper_->getOrder();
285 template<
class Scalar>
286 Teuchos::RCP<Tempus::StepperState<Scalar> >
290 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
296 template<
class Scalar>
299 std::string name =
"BDF2";
304 template<
class Scalar>
306 Teuchos::FancyOStream &out,
307 const Teuchos::EVerbosityLevel )
const
309 out << description() <<
"::describe:" << std::endl
310 <<
"wrapperModel_ = " << this->wrapperModel_->description() << std::endl;
314 template <
class Scalar>
316 Teuchos::RCP<Teuchos::ParameterList>
const& pList)
318 Teuchos::RCP<Teuchos::ParameterList> stepperPL = this->stepperPL_;
319 if (pList == Teuchos::null) {
321 if (stepperPL == Teuchos::null) stepperPL = this->getDefaultParameters();
325 if (!(stepperPL->isParameter(
"Solver Name"))) {
326 stepperPL->set<std::string>(
"Solver Name",
"Default Solver");
327 Teuchos::RCP<Teuchos::ParameterList> solverPL =
328 this->defaultSolverParameters();
329 stepperPL->set(
"Default Solver", *solverPL);
334 std::string stepperType = stepperPL->get<std::string>(
"Stepper Type");
335 TEUCHOS_TEST_FOR_EXCEPTION( stepperType !=
"BDF2", std::logic_error,
336 "Error - Stepper Type is not 'BDF2'!\n"
337 <<
" Stepper Type = "<<stepperPL->get<std::string>(
"Stepper Type")<<
"\n");
339 this->stepperPL_ = stepperPL;
343 template<
class Scalar>
344 Teuchos::RCP<const Teuchos::ParameterList>
347 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
348 pl->setName(
"Default Stepper - " + this->description());
349 pl->set<std::string>(
"Stepper Type", this->description());
350 this->getValidParametersBasic(pl);
351 pl->set<
bool>(
"Initial Condition Consistency Check",
false);
352 pl->set<
bool>(
"Zero Initial Guess",
false);
353 pl->set<std::string>(
"Solver Name",
"",
354 "Name of ParameterList containing the solver specifications.");
360 template<
class Scalar>
361 Teuchos::RCP<Teuchos::ParameterList>
365 using Teuchos::ParameterList;
366 using Teuchos::rcp_const_cast;
368 RCP<ParameterList> pl =
369 rcp_const_cast<ParameterList>(this->getValidParameters());
371 pl->set<std::string>(
"Solver Name",
"Default Solver");
372 RCP<ParameterList> solverPL = this->defaultSolverParameters();
373 pl->set(
"Default Solver", *solverPL);
379 template <
class Scalar>
380 Teuchos::RCP<Teuchos::ParameterList>
383 return(this->stepperPL_);
387 template <
class Scalar>
388 Teuchos::RCP<Teuchos::ParameterList>
391 Teuchos::RCP<Teuchos::ParameterList> temp_plist = this->stepperPL_;
392 this->stepperPL_ = Teuchos::null;
398 #endif // Tempus_StepperBDF2_impl_hpp
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
Time-derivative interface for BDF2.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)
Set Observer.
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl)
virtual void computeStartUp(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Compute the first time step given the supplied startup stepper.
StepperState is a simple class to hold state information about the stepper.
StepperObserver class for Stepper class.
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...
Teuchos::RCP< Teuchos::ParameterList > getDefaultParameters() const
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
virtual std::string description() const
void setStartUpStepper(std::string startupStepperName)
Set the stepper to use in first step.
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.
Solve for x and determine xDot from x.
virtual void initialize()
Initialize during construction and after changing input parameters.
StepperBDF2()
Default constructor.
StepperBDF2Observer class for StepperBDF2.