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->setStepperType(
"BDF2");
29 this->setUseFSAL( this->getUseFSALDefault());
30 this->setICConsistency( this->getICConsistencyDefault());
31 this->setICConsistencyCheck( this->getICConsistencyCheckDefault());
32 this->setZeroInitialGuess(
false);
38 template<
class Scalar>
40 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
42 const Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
45 std::string ICConsistency,
46 bool ICConsistencyCheck,
47 bool zeroInitialGuess)
50 this->setStepperType(
"BDF2");
51 this->setUseFSAL( useFSAL);
52 this->setICConsistency( ICConsistency);
53 this->setICConsistencyCheck( ICConsistencyCheck);
54 this->setZeroInitialGuess( zeroInitialGuess);
56 this->setObserver(obs);
58 if (appModel != Teuchos::null) {
60 this->setModel(appModel);
61 this->setSolver(solver);
62 this->setStartUpStepper(startUpStepper);
69 template<
class Scalar>
72 TEUCHOS_TEST_FOR_EXCEPTION(
73 this->wrapperModel_->getAppModel() == Teuchos::null, std::logic_error,
74 "Error - Need to set the model, setModel(), before calling "
75 "StepperBDF2::setStartUpStepper()\n");
80 sf->createStepper(startupStepperType, this->wrapperModel_->getAppModel());
85 template<
class Scalar>
89 TEUCHOS_TEST_FOR_EXCEPTION(
90 this->wrapperModel_->getAppModel() == Teuchos::null, std::logic_error,
91 "Error - Need to set the model, setModel(), before calling "
92 "StepperBDF2::setStartUpStepper()\n");
94 startUpStepper_ = startUpStepper;
95 startUpStepper_->setModel(this->wrapperModel_->getAppModel());
96 startUpStepper_->initialize();
100 template<
class Scalar>
105 if (this->stepperObserver_ == Teuchos::null)
106 this->stepperObserver_ =
109 if (( obs == Teuchos::null ) and (this->stepperObserver_->getSize() == 0) )
112 this->stepperObserver_->addObserver(
118 template<
class Scalar>
121 TEUCHOS_TEST_FOR_EXCEPTION( this->wrapperModel_ == Teuchos::null,
123 "Error - Need to set the model, setModel(), before calling "
124 "StepperBDF2::initialize()\n");
127 order_ = Scalar(2.0);
131 template<
class Scalar>
137 RCP<SolutionState<Scalar> > initialState =
solutionHistory->getCurrentState();
140 if (initialState->getXDot() == Teuchos::null)
141 this->setStepperXDot(initialState->getX()->clone_v());
145 if (this->getUseFSAL()) {
146 RCP<Teuchos::FancyOStream> out = this->getOStream();
147 Teuchos::OSTab ostab(out,1,
"StepperBDF2::setInitialConditions()");
148 *out <<
"\nWarning -- The First-Step-As-Last (FSAL) principle is not "
149 <<
"needed with Backward Euler. The default is to set useFSAL=false, "
150 <<
"however useFSAL=true will also work but have no affect "
151 <<
"(i.e., no-op).\n" << std::endl;
156 template<
class Scalar>
162 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperBDF2::takeStep()");
166 RCP<Thyra::VectorBase<Scalar> > xOld;
167 RCP<Thyra::VectorBase<Scalar> > xOldOld;
175 TEUCHOS_TEST_FOR_EXCEPTION( (numStates < 3), std::logic_error,
176 "Error in Tempus::StepperBDF2::takeStep(): numStates after \n"
177 <<
"startup stepper must be at least 3, whereas numStates = "
178 << numStates <<
"!\n" <<
"If running with Storage Type = Static, "
179 <<
"make sure Storage Limit > 2.\n");
186 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
187 RCP<SolutionState<Scalar> > currentState=
solutionHistory->getCurrentState();
189 RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
190 RCP<Thyra::VectorBase<Scalar> > xDot = this->getStepperXDot(workingState);
193 const Scalar time = workingState->getTime();
194 const Scalar dt = workingState->getTimeStep();
195 const Scalar dtOld = currentState->getTimeStep();
199 order_ = Scalar(2.0);
202 Teuchos::RCP<TimeDerivative<Scalar> > timeDer =
205 const Scalar alpha = getAlpha(dt, dtOld);
206 const Scalar beta = getBeta (dt);
209 timeDer, dt, alpha, beta));
211 if (!Teuchos::is_null(stepperBDF2Observer_))
214 const Thyra::SolveStatus<Scalar> sStatus =
215 this->solveImplicitODE(x, xDot, time, p);
217 if (!Teuchos::is_null(stepperBDF2Observer_))
220 if (workingState->getXDot() != Teuchos::null)
221 timeDer->compute(x, xDot);
223 workingState->setSolutionStatus(sStatus);
224 workingState->setOrder(getOrder());
230 template<
class Scalar>
234 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
235 Teuchos::OSTab ostab(out,1,
"StepperBDF2::computeStartUp()");
236 *out <<
"Warning -- Taking a startup step for BDF2 using '"
237 << startUpStepper_->getStepperType()<<
"'!" << std::endl;
242 order_ = startUpStepper_->getOrder();
251 template<
class Scalar>
252 Teuchos::RCP<Tempus::StepperState<Scalar> >
256 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
262 template<
class Scalar>
264 Teuchos::FancyOStream &out,
265 const Teuchos::EVerbosityLevel )
const
267 out << this->getStepperType() <<
"::describe:" << std::endl
268 <<
"wrapperModel_ = " << this->wrapperModel_->description() << std::endl;
272 template<
class Scalar>
273 Teuchos::RCP<const Teuchos::ParameterList>
276 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
278 pl->set<
bool>(
"Initial Condition Consistency Check",
279 this->getICConsistencyCheckDefault());
280 pl->set<std::string>(
"Solver Name",
"Default Solver");
281 pl->set<
bool>(
"Zero Initial Guess",
false);
282 pl->set<std::string>(
"Start Up Stepper Type",
"DIRK 1 Stage Theta Method");
284 pl->set(
"Default Solver", *solverPL);
291 #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.
void setStartUpStepper(std::string startupStepperType="DIRK 1 Stage Theta Method")
Set the stepper to use in first step.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
virtual void computeStartUp(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Compute the first time step given the supplied startup stepper.
Thyra Base interface for time steppers.
This observer is a composite observer,.
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< const Teuchos::ParameterList > getValidParameters() const
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
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.
StepperBDF2()
Default constructor.
StepperBDF2Observer class for StepperBDF2.