37 const Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
39 std::string ICConsistency,
bool ICConsistencyCheck,
bool zeroInitialGuess,
42 this->setStepperName(
"BDF2");
43 this->setStepperType(
"BDF2");
44 this->setUseFSAL(useFSAL);
45 this->setICConsistency(ICConsistency);
46 this->setICConsistencyCheck(ICConsistencyCheck);
47 this->setZeroInitialGuess(zeroInitialGuess);
49 this->setAppAction(stepperBDF2AppAction);
50 this->setSolver(solver);
51 this->setStartUpStepper(startUpStepper);
53 if (appModel != Teuchos::null) {
54 this->setModel(appModel);
93 startUpStepper_ = startUpStepper;
95 if (this->wrapperModel_ != Teuchos::null) {
96 TEUCHOS_TEST_FOR_EXCEPTION(
97 this->wrapperModel_->getAppModel() == Teuchos::null, std::logic_error,
98 "Error - Can not set the startUpStepper to Teuchos::null.\n");
100 if (startUpStepper->getModel() == Teuchos::null &&
101 this->wrapperModel_->getAppModel() != Teuchos::null) {
102 startUpStepper_->setModel(this->wrapperModel_->getAppModel());
103 startUpStepper_->initialize();
107 this->isInitialized_ =
false;
151 this->checkInitialized();
155 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperBDF2::takeStep()");
157 int numStates = solutionHistory->getNumStates();
159 RCP<Thyra::VectorBase<Scalar> > xOld;
160 RCP<Thyra::VectorBase<Scalar> > xOldOld;
165 computeStartUp(solutionHistory);
168 TEUCHOS_TEST_FOR_EXCEPTION(
169 (numStates < 3), std::logic_error,
170 "Error in Tempus::StepperBDF2::takeStep(): numStates after \n"
171 <<
"startup stepper must be at least 3, whereas numStates = "
172 << numStates <<
"!\n"
173 <<
"If running with Storage Type = Static, "
174 <<
"make sure Storage Limit > 2.\n");
179 RCP<StepperBDF2<Scalar> > thisStepper = Teuchos::rcpFromRef(*
this);
180 stepperBDF2AppAction_->execute(
181 solutionHistory, thisStepper,
184 RCP<SolutionState<Scalar> > workingState =
185 solutionHistory->getWorkingState();
186 RCP<SolutionState<Scalar> > currentState =
187 solutionHistory->getCurrentState();
189 RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
190 if (workingState->getXDot() != Teuchos::null)
191 this->setStepperXDot(workingState->getXDot());
192 RCP<Thyra::VectorBase<Scalar> > xDot = this->getStepperXDot();
195 const Scalar time = workingState->getTime();
196 const Scalar dt = workingState->getTimeStep();
197 const Scalar dtOld = currentState->getTimeStep();
199 xOld = solutionHistory->getStateTimeIndexNM1()->getX();
200 xOldOld = solutionHistory->getStateTimeIndexNM2()->getX();
201 order_ = Scalar(2.0);
204 Teuchos::RCP<TimeDerivative<Scalar> > timeDer = Teuchos::rcp(
207 const Scalar alpha = getAlpha(dt, dtOld);
208 const Scalar beta = getBeta(dt);
210 auto p = Teuchos::rcp(
212 stepperBDF2AppAction_->execute(
213 solutionHistory, thisStepper,
216 const Thyra::SolveStatus<Scalar> sStatus =
217 this->solveImplicitODE(x, xDot, time, p);
219 stepperBDF2AppAction_->execute(
220 solutionHistory, thisStepper,
223 if (workingState->getXDot() != Teuchos::null) timeDer->compute(x, xDot);
225 workingState->setSolutionStatus(sStatus);
226 workingState->setOrder(getOrder());
227 workingState->computeNorms(currentState);
228 stepperBDF2AppAction_->execute(
229 solutionHistory, thisStepper,
239 auto out = Teuchos::fancyOStream(this->getOStream());
240 out->setOutputToRootOnly(0);
241 Teuchos::OSTab ostab(out, 1,
"StepperBDF2::computeStartUp()");
242 *out <<
"Warning -- Taking a startup step for BDF2 using '"
243 << startUpStepper_->getStepperType() <<
"'!" << std::endl;
246 startUpStepper_->takeStep(solutionHistory);
248 order_ = startUpStepper_->getOrder();
268 Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel)
const
270 auto l_out = Teuchos::fancyOStream(out.getOStream());
271 Teuchos::OSTab ostab(*l_out, 2, this->description());
272 l_out->setOutputToRootOnly(0);
277 *l_out <<
"--- StepperBDF2 ---\n";
278 if (startUpStepper_ != Teuchos::null) {
279 *l_out <<
" startup stepper type = "
280 << startUpStepper_->description() << std::endl;
282 *l_out <<
" startUpStepper_ = " << startUpStepper_
284 *l_out <<
" startUpStepper_->isInitialized() = "
285 << Teuchos::toString(startUpStepper_->isInitialized()) << std::endl;
286 *l_out <<
" stepperBDF2AppAction_ = " << stepperBDF2AppAction_
288 *l_out <<
"----------------------------" << std::endl;
289 *l_out <<
" order_ = " << order_ << std::endl;
290 *l_out <<
"-------------------" << std::endl;
328 Teuchos::RCP<Teuchos::ParameterList> pl)
331 stepper->setStepperImplicitValues(pl);
333 std::string startUpStepperName =
"DIRK 1 Stage Theta Method";
334 if (pl != Teuchos::null)
336 pl->get<std::string>(
"Start Up Stepper Type", startUpStepperName);
337 stepper->setStartUpStepper(startUpStepperName);
339 if (model != Teuchos::null) {
340 stepper->setModel(model);
341 stepper->initialize();
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...