71 this->setIntegratorType(iB->getIntegratorType());
72 this->setIntegratorName(iB->getIntegratorName());
73 this->setStepper(iB->getStepper());
74 this->setSolutionHistory(iB->getNonConstSolutionHistory());
75 this->setTimeStepControl(iB->getNonConstTimeStepControl());
76 this->setObserver(iB->getObserver());
77 this->setScreenOutputIndexList(iB->getScreenOutputIndexList());
78 this->setScreenOutputIndexInterval(iB->getScreenOutputIndexInterval());
79 this->setStatus(iB->getStatus());
80 integratorTimer_ = iB->getIntegratorTimer();
81 stepperTimer_ = iB->getStepperTimer();
121 if (solutionHistory_ == Teuchos::null) {
125 solutionHistory_->clear();
128 TEUCHOS_TEST_FOR_EXCEPTION(
129 stepper_ == Teuchos::null, std::logic_error,
130 "Error - initializeSolutionHistory(), need to set stepper first!\n");
132 if (state == Teuchos::null) {
133 TEUCHOS_TEST_FOR_EXCEPTION(stepper_->getModel() == Teuchos::null,
135 "Error - initializeSolutionHistory(), need to "
136 "set stepper's model first!\n");
139 stepper_->getDefaultStepperState());
141 if (timeStepControl_ != Teuchos::null) {
143 state->setTime(timeStepControl_->getInitTime());
144 state->setIndex(timeStepControl_->getInitIndex());
145 state->setTimeStep(timeStepControl_->getInitTimeStep());
146 state->setTolRel(timeStepControl_->getMaxRelError());
147 state->setTolAbs(timeStepControl_->getMaxAbsError());
149 state->setOrder(stepper_->getOrder());
153 solutionHistory_->addState(state);
155 stepper_->setInitialConditions(solutionHistory_);
167 RCP<Thyra::VectorBase<Scalar> > xdot = x0->clone_v();
168 RCP<Thyra::VectorBase<Scalar> > xdotdot = x0->clone_v();
169 if (xdot0 == Teuchos::null)
170 Thyra::assign(xdot.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
172 Thyra::assign(xdot.ptr(), *(xdot0));
173 if (xdotdot0 == Teuchos::null)
174 Thyra::assign(xdotdot.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
176 Thyra::assign(xdotdot.ptr(), *(xdotdot0));
178 TEUCHOS_TEST_FOR_EXCEPTION(
179 stepper_ == Teuchos::null, std::logic_error,
180 "Error - initializeSolutionHistory(), need to set stepper first!\n");
183 state->setStepperState(stepper_->getDefaultStepperState());
186 if (timeStepControl_ != Teuchos::null) {
188 state->setIndex(timeStepControl_->getInitIndex());
189 state->setTimeStep(timeStepControl_->getInitTimeStep());
190 state->setTolRel(timeStepControl_->getMaxRelError());
191 state->setTolAbs(timeStepControl_->getMaxAbsError());
193 state->setOrder(stepper_->getOrder());
196 initializeSolutionHistory(state);
242 TEUCHOS_TEST_FOR_EXCEPTION(
243 stepper_ == Teuchos::null, std::logic_error,
244 "Error - Need to set the Stepper, setStepper(), before calling "
245 "IntegratorBasic::initialize()\n");
247 TEUCHOS_TEST_FOR_EXCEPTION(
248 solutionHistory_->getNumStates() < 1, std::out_of_range,
249 "Error - SolutionHistory requires at least one SolutionState.\n"
250 <<
" Supplied SolutionHistory has only "
251 << solutionHistory_->getNumStates() <<
" SolutionStates.\n");
253 stepper_->initialize();
254 solutionHistory_->initialize();
255 timeStepControl_->initialize();
257 isInitialized_ =
true;
269 Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel)
const
271 auto l_out = Teuchos::fancyOStream(out.getOStream());
272 Teuchos::OSTab ostab(*l_out, 2, this->description());
273 l_out->setOutputToRootOnly(0);
275 *l_out <<
"\n--- " << this->description() <<
" ---" << std::endl;
277 if (solutionHistory_ != Teuchos::null) {
278 solutionHistory_->describe(*l_out, verbLevel);
281 *l_out <<
"solutionHistory = " << solutionHistory_ << std::endl;
284 if (timeStepControl_ != Teuchos::null) {
285 timeStepControl_->describe(out, verbLevel);
288 *l_out <<
"timeStepControl = " << timeStepControl_ << std::endl;
291 if (stepper_ != Teuchos::null) {
292 stepper_->describe(out, verbLevel);
295 *l_out <<
"stepper = " << stepper_ << std::endl;
297 *l_out << std::string(this->description().length() + 8,
'-') << std::endl;
312 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
313 out->setOutputToRootOnly(0);
314 if (isInitialized_ ==
false) {
315 Teuchos::OSTab ostab(out, 1,
"StartIntegrator");
316 *out <<
"Failure - IntegratorBasic is not initialized." << std::endl;
322 auto cs = solutionHistory_->getCurrentState();
323 cs->setTolRel(timeStepControl_->getMaxRelError());
324 cs->setTolAbs(timeStepControl_->getMaxAbsError());
326 integratorTimer_->start();
328 const Scalar initDt = std::min(timeStepControl_->getInitTimeStep(),
329 stepper_->getInitTimeStep(solutionHistory_));
331 timeStepControl_->setInitTimeStep(initDt);
332 timeStepControl_->initialize();
339 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::IntegratorBasic::advanceTime()");
342 integratorObserver_->observeStartIntegrator(*
this);
345 integratorStatus_ ==
WORKING &&
346 timeStepControl_->timeInRange(solutionHistory_->getCurrentTime()) &&
347 timeStepControl_->indexInRange(solutionHistory_->getCurrentIndex())) {
348 stepperTimer_->reset();
349 stepperTimer_->start();
350 solutionHistory_->initWorkingState();
353 integratorObserver_->observeStartTimeStep(*
this);
355 timeStepControl_->setNextTimeStep(solutionHistory_, integratorStatus_);
356 integratorObserver_->observeNextTimeStep(*
this);
359 solutionHistory_->getWorkingState()->setSolutionStatus(
WORKING);
361 integratorObserver_->observeBeforeTakeStep(*
this);
363 stepper_->takeStep(solutionHistory_);
365 integratorObserver_->observeAfterTakeStep(*
this);
367 stepperTimer_->stop();
369 integratorObserver_->observeAfterCheckTimeStep(*
this);
371 solutionHistory_->promoteWorkingState();
372 integratorObserver_->observeEndTimeStep(*
this);
376 integratorObserver_->observeEndIntegrator(*
this);
385 auto ws = solutionHistory_->getWorkingState();
388 ws->setTolRel(timeStepControl_->getMaxRelError());
389 ws->setTolAbs(timeStepControl_->getMaxAbsError());
392 std::vector<int>::const_iterator it = std::find(
393 outputScreenIndices_.begin(), outputScreenIndices_.end(), ws->getIndex());
394 if (it == outputScreenIndices_.end())
395 ws->setOutputScreen(
false);
397 ws->setOutputScreen(
true);
399 const int initial = timeStepControl_->getInitIndex();
400 if ((ws->getIndex() - initial) % outputScreenInterval_ == 0)
401 ws->setOutputScreen(
true);
408 auto ws = solutionHistory_->getWorkingState();
411 if (ws->getNFailures() >= timeStepControl_->getMaxFailures()) {
412 RCP<Teuchos::FancyOStream> out = this->getOStream();
413 out->setOutputToRootOnly(0);
414 Teuchos::OSTab ostab(out, 2,
"checkTimeStep");
415 *out <<
"Failure - Stepper has failed more than the maximum allowed.\n"
416 <<
" (nFailures = " << ws->getNFailures()
417 <<
") >= (nFailuresMax = " << timeStepControl_->getMaxFailures() <<
")"
422 if (ws->getNConsecutiveFailures() >=
423 timeStepControl_->getMaxConsecFailures()) {
424 RCP<Teuchos::FancyOStream> out = this->getOStream();
425 out->setOutputToRootOnly(0);
426 Teuchos::OSTab ostab(out, 1,
"checkTimeStep");
427 *out <<
"Failure - Stepper has failed more than the maximum "
428 <<
"consecutive allowed.\n"
429 <<
" (nConsecutiveFailures = " << ws->getNConsecutiveFailures()
430 <<
") >= (nConsecutiveFailuresMax = "
431 << timeStepControl_->getMaxConsecFailures() <<
")" << std::endl;
437 if (ws->getTimeStep() <= timeStepControl_->getMinTimeStep() &&
439 RCP<Teuchos::FancyOStream> out = this->getOStream();
440 out->setOutputToRootOnly(0);
441 Teuchos::OSTab ostab(out, 1,
"checkTimeStep");
442 *out <<
"Failure - Stepper has failed and the time step size is "
443 <<
"at the minimum.\n"
444 <<
" Solution Status = " <<
toString(ws->getSolutionStatus())
446 <<
" (TimeStep = " << ws->getTimeStep()
447 <<
") <= (Minimum TimeStep = " << timeStepControl_->getMinTimeStep()
456 ((timeStepControl_->getStepType() ==
"Constant") &&
457 !
approxEqual(ws->getTimeStep(), timeStepControl_->getInitTimeStep()))) {
458 RCP<Teuchos::FancyOStream> out = this->getOStream();
459 out->setOutputToRootOnly(0);
460 Teuchos::OSTab ostab(out, 0,
"checkTimeStep");
461 *out << std::scientific << std::setw(6) << std::setprecision(3)
462 << ws->getIndex() << std::setw(11) << std::setprecision(3)
463 << ws->getTime() << std::setw(11) << std::setprecision(3)
464 << ws->getTimeStep() <<
" STEP FAILURE!! - ";
466 *out <<
"Solution Status = " <<
toString(ws->getSolutionStatus())
469 else if ((timeStepControl_->getStepType() ==
"Constant") &&
470 (ws->getTimeStep() != timeStepControl_->getInitTimeStep())) {
471 *out <<
"dt != Constant dt (=" << timeStepControl_->getInitTimeStep()
475 ws->setNFailures(ws->getNFailures() + 1);
476 ws->setNRunningFailures(ws->getNRunningFailures() + 1);
477 ws->setNConsecutiveFailures(ws->getNConsecutiveFailures() + 1);
507 std::string delimiters(
",");
508 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
509 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
510 while ((pos != std::string::npos) || (lastPos != std::string::npos)) {
511 std::string token = str.substr(lastPos, pos - lastPos);
512 outputScreenIndices_.push_back(
int(std::stoi(token)));
513 if (pos == std::string::npos)
break;
515 lastPos = str.find_first_not_of(delimiters, pos);
516 pos = str.find_first_of(delimiters, lastPos);
520 std::sort(outputScreenIndices_.begin(), outputScreenIndices_.end());
521 outputScreenIndices_.erase(
522 std::unique(outputScreenIndices_.begin(), outputScreenIndices_.end()),
523 outputScreenIndices_.end());
544 Teuchos::RCP<Teuchos::ParameterList> pl =
545 Teuchos::parameterList(getIntegratorName());
547 pl->set(
"Integrator Type", getIntegratorType(),
548 "'Integrator Type' must be 'Integrator Basic'.");
550 pl->set(
"Screen Output Index List", getScreenOutputIndexListString(),
551 "Screen Output Index List. Required to be in TimeStepControl range "
552 "['Minimum Time Step Index', 'Maximum Time Step Index']");
554 pl->set(
"Screen Output Index Interval", getScreenOutputIndexInterval(),
555 "Screen Output Index Interval (e.g., every 100 time steps)");
557 pl->set(
"Stepper Name", stepper_->getStepperName(),
558 "'Stepper Name' selects the Stepper block to construct (Required).");
560 pl->set(
"Solution History", *solutionHistory_->getValidParameters());
561 pl->set(
"Time Step Control", *timeStepControl_->getValidParameters());
563 Teuchos::RCP<Teuchos::ParameterList> tempusPL =
564 Teuchos::parameterList(
"Tempus");
566 tempusPL->set(
"Integrator Name", pl->name());
567 tempusPL->set(pl->name(), *pl);
568 tempusPL->set(stepper_->getStepperName(), *stepper_->getValidParameters());
577 Teuchos::RCP<Teuchos::ParameterList> tempusPL,
bool runInitialize)
580 if (tempusPL == Teuchos::null || tempusPL->numParams() == 0)
583 auto integratorName = tempusPL->get<std::string>(
"Integrator Name");
584 auto integratorPL = Teuchos::sublist(tempusPL, integratorName,
true);
586 std::string integratorType =
587 integratorPL->get<std::string>(
"Integrator Type");
588 TEUCHOS_TEST_FOR_EXCEPTION(
589 integratorType !=
"Integrator Basic", std::logic_error,
590 "Error - For IntegratorBasic, 'Integrator Type' should be "
591 <<
"'Integrator Basic'.\n"
592 <<
" Integrator Type = " << integratorType <<
"\n");
594 integrator->setIntegratorName(integratorName);
597 auto validPL = Teuchos::rcp_const_cast<Teuchos::ParameterList>(
598 integrator->getValidParameters());
599 auto vIntegratorName = validPL->template get<std::string>(
"Integrator Name");
600 auto vIntegratorPL = Teuchos::sublist(validPL, vIntegratorName,
true);
601 integratorPL->validateParametersAndSetDefaults(*vIntegratorPL, 1);
604 if (integratorPL->isParameter(
"Stepper Name")) {
606 auto stepperName = integratorPL->get<std::string>(
"Stepper Name");
607 auto stepperPL = Teuchos::sublist(tempusPL, stepperName,
true);
608 stepperPL->setName(stepperName);
610 integrator->setStepper(sf->createStepper(stepperPL));
615 integrator->setStepper(stepper);
619 if (integratorPL->isSublist(
"Time Step Control")) {
621 auto tscPL = Teuchos::sublist(integratorPL,
"Time Step Control",
true);
622 integrator->setTimeStepControl(
623 createTimeStepControl<Scalar>(tscPL, runInitialize));
631 if (integratorPL->isSublist(
"Solution History")) {
633 auto shPL = Teuchos::sublist(integratorPL,
"Solution History",
true);
634 auto sh = createSolutionHistoryPL<Scalar>(shPL);
635 integrator->setSolutionHistory(sh);
639 integrator->setSolutionHistory(createSolutionHistory<Scalar>());
643 integrator->setObserver(Teuchos::null);
646 integrator->setScreenOutputIndexInterval(
647 integratorPL->get<
int>(
"Screen Output Index Interval",
648 integrator->getScreenOutputIndexInterval()));
651 auto str = integratorPL->get<std::string>(
"Screen Output Index List",
"");
652 integrator->setScreenOutputIndexList(str);
661 Teuchos::RCP<Teuchos::ParameterList> tempusPL,
665 auto integrator = createIntegratorBasic<Scalar>(tempusPL, runInitialize);
666 if (model == Teuchos::null)
return integrator;
668 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > constModel = model;
669 integrator->setModel(constModel);
674 integrator->getStepper()->getDefaultStepperState());
675 newState->setTime(integrator->getTimeStepControl()->getInitTime());
676 newState->setIndex(integrator->getTimeStepControl()->getInitIndex());
677 newState->setTimeStep(integrator->getTimeStepControl()->getInitTimeStep());
678 newState->setTolRel(integrator->getTimeStepControl()->getMaxRelError());
679 newState->setTolAbs(integrator->getTimeStepControl()->getMaxAbsError());
680 newState->setOrder(integrator->getStepper()->getOrder());
684 auto sh = integrator->getNonConstSolutionHistory();
685 sh->addState(newState);
686 integrator->getStepper()->setInitialConditions(sh);
688 if (runInitialize) integrator->initialize();
720 Teuchos::RCP<Teuchos::ParameterList> tempusPL,
724 auto integratorName = tempusPL->get<std::string>(
"Integrator Name");
725 auto integratorPL = Teuchos::sublist(tempusPL, integratorName,
true);
727 std::string integratorType =
728 integratorPL->get<std::string>(
"Integrator Type");
729 TEUCHOS_TEST_FOR_EXCEPTION(
730 integratorType !=
"Integrator Basic", std::logic_error,
731 "Error - For IntegratorBasic, 'Integrator Type' should be "
732 <<
"'Integrator Basic'.\n"
733 <<
" Integrator Type = " << integratorType <<
"\n");
736 integrator->setIntegratorName(integratorName);
738 TEUCHOS_TEST_FOR_EXCEPTION(
739 !integratorPL->isParameter(
"Stepper Name"), std::logic_error,
740 "Error - Need to set the 'Stepper Name' in 'Integrator Basic'.\n");
742 auto stepperName = integratorPL->get<std::string>(
"Stepper Name");
743 TEUCHOS_TEST_FOR_EXCEPTION(
744 stepperName ==
"Operator Split", std::logic_error,
745 "Error - 'Stepper Name' should be 'Operator Split'.\n");
748 auto stepperPL = Teuchos::sublist(tempusPL, stepperName,
true);
749 stepperPL->setName(stepperName);
751 integrator->setStepper(sf->createStepper(stepperPL, models));
754 if (integratorPL->isSublist(
"Time Step Control")) {
756 auto tscPL = Teuchos::sublist(integratorPL,
"Time Step Control",
true);
757 integrator->setTimeStepControl(
758 createTimeStepControl<Scalar>(tscPL, runInitialize));
768 integrator->getStepper()->getDefaultStepperState());
769 newState->setTime(integrator->getTimeStepControl()->getInitTime());
770 newState->setIndex(integrator->getTimeStepControl()->getInitIndex());
771 newState->setTimeStep(integrator->getTimeStepControl()->getInitTimeStep());
772 newState->setTolRel(integrator->getTimeStepControl()->getMaxRelError());
773 newState->setTolAbs(integrator->getTimeStepControl()->getMaxAbsError());
774 newState->setOrder(integrator->getStepper()->getOrder());
778 auto shPL = Teuchos::sublist(integratorPL,
"Solution History",
true);
779 auto sh = createSolutionHistoryPL<Scalar>(shPL);
780 sh->addState(newState);
781 integrator->getStepper()->setInitialConditions(sh);
782 integrator->setSolutionHistory(sh);
785 integrator->setObserver(Teuchos::null);
788 integrator->setScreenOutputIndexInterval(
789 integratorPL->get<
int>(
"Screen Output Index Interval",
790 integrator->getScreenOutputIndexInterval()));
793 auto str = integratorPL->get<std::string>(
"Screen Output Index List",
"");
794 integrator->setScreenOutputIndexList(str);
796 auto validPL = Teuchos::rcp_const_cast<Teuchos::ParameterList>(
797 integrator->getValidParameters());
800 auto vIntegratorName = validPL->template get<std::string>(
"Integrator Name");
801 auto vIntegratorPL = Teuchos::sublist(validPL, vIntegratorName,
true);
802 integratorPL->validateParametersAndSetDefaults(*vIntegratorPL);
805 auto vStepperName = vIntegratorPL->template get<std::string>(
"Stepper Name");
806 auto vStepperPL = Teuchos::sublist(validPL, vStepperName,
true);
807 stepperPL->validateParametersAndSetDefaults(*vStepperPL);
809 integrator->initialize();
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...