9 #ifndef Tempus_StepperSubcycling_impl_hpp
10 #define Tempus_StepperSubcycling_impl_hpp
16 #include "Tempus_IntegratorObserverSubcycling.hpp"
17 #include "Tempus_IntegratorObserverNoOp.hpp"
19 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
20 #include "Thyra_VectorStdOps.hpp"
26 template<
class Scalar>
30 using Teuchos::ParameterList;
32 this->setStepperType(
"Subcycling");
33 this->setUseFSAL( this->getUseFSALDefault());
34 this->setICConsistency( this->getICConsistencyDefault());
35 this->setICConsistencyCheck( this->getICConsistencyCheckDefault());
37 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
40 this->setAppAction(Teuchos::null);
42 scIntegrator_->setTimeStepControl();
44 scIntegrator_->setObserver(
47 this->setSubcyclingPrintDtChanges(
false);
49 RCP<ParameterList> tempusPL = scIntegrator_->getTempusParameterList();
52 tempusPL->sublist(
"Default Integrator")
53 .set(
"Stepper Name",
"Default Subcycling Stepper");
54 RCP<ParameterList> stepperPL = Teuchos::parameterList();
55 stepperPL->set(
"Stepper Type",
"Forward Euler");
56 tempusPL->set(
"Default Subcycling Stepper", *stepperPL);
59 auto stepperFE = sf->createStepperForwardEuler(Teuchos::null,Teuchos::null);
60 setSubcyclingStepper(stepperFE);
76 tempusPL->sublist(
"Default Integrator")
77 .sublist(
"Time Step Control")
78 .set(
"Initial Time Step", std::numeric_limits<Scalar>::max());
82 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
83 template<
class Scalar>
85 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
89 std::string ICConsistency,
90 bool ICConsistencyCheck)
92 this->setStepperType(
"Subcycling");
93 this->setUseFSAL( useFSAL);
94 this->setICConsistency( ICConsistency);
95 this->setICConsistencyCheck( ICConsistencyCheck);
97 this->setObserver(obs);
98 this->setAppAction(Teuchos::null);
99 scIntegrator_ = scIntegrator;
100 this->setSubcyclingPrintDtChanges(
false);
102 if (appModel != Teuchos::null) {
103 this->setModel(appModel);
109 template<
class Scalar>
111 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
114 std::string ICConsistency,
115 bool ICConsistencyCheck,
118 this->setStepperType(
"Subcycling");
119 this->setUseFSAL( useFSAL);
120 this->setICConsistency( ICConsistency);
121 this->setICConsistencyCheck( ICConsistencyCheck);
122 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
125 this->setAppAction(stepperSCAppAction);
126 scIntegrator_ = scIntegrator;
127 this->setSubcyclingPrintDtChanges(
false);
129 if (appModel != Teuchos::null) {
130 this->setModel(appModel);
135 template<
class Scalar>
139 scIntegrator_->setStepperWStepper(stepper);
140 this->isInitialized_ =
false;
144 template<
class Scalar>
147 scIntegrator_->getNonConstTimeStepControl()->setMinTimeStep(MinTimeStep);
148 this->isInitialized_ =
false;
152 template<
class Scalar>
155 scIntegrator_->getNonConstTimeStepControl()->setInitTimeStep(InitTimeStep);
156 this->isInitialized_ =
false;
160 template<
class Scalar>
163 scIntegrator_->getNonConstTimeStepControl()->setMaxTimeStep(MaxTimeStep);
164 this->isInitialized_ =
false;
168 template<
class Scalar>
171 scIntegrator_->getNonConstTimeStepControl()->setStepType(stepType);
173 auto tsc = scIntegrator_->getNonConstTimeStepControl();
174 auto tscStrategy = tsc->getTimeStepControlStrategy();
175 tscStrategy->clearObservers();
177 Teuchos::RCP<TimeStepControlStrategy<Scalar> > strategy =
179 if (stepType ==
"Variable")
182 tscStrategy->addStrategy(strategy);
184 this->isInitialized_ =
false;
188 template<
class Scalar>
191 scIntegrator_->getNonConstTimeStepControl()->setMaxFailures(MaxFailures);
192 this->isInitialized_ =
false;
196 template<
class Scalar>
200 scIntegrator_->getNonConstTimeStepControl()->setMaxConsecFailures(MaxConsecFailures);
201 this->isInitialized_ =
false;
205 template<
class Scalar>
209 scIntegrator_->setScreenOutputIndexInterval(i);
210 this->isInitialized_ =
false;
214 template<
class Scalar>
218 scIntegrator_->setScreenOutputIndexList(s);
219 this->isInitialized_ =
false;
223 template<
class Scalar>
228 scIntegrator_->getNonConstTimeStepControl()->getTimeStepControlStrategy()->clearObservers();
229 scIntegrator_->getNonConstTimeStepControl()->setTimeStepControlStrategy(tscs);
230 this->isInitialized_ =
false;
234 template<
class Scalar>
238 scIntegrator_->setObserver(obs);
239 this->isInitialized_ =
false;
243 template<
class Scalar>
247 scIntegrator_->getNonConstTimeStepControl()->setPrintDtChanges(printDtChanges);
248 this->isInitialized_ =
false;
252 template<
class Scalar>
253 Teuchos::RCP<const Stepper<Scalar> >
255 {
return scIntegrator_->getStepper(); }
258 template<
class Scalar>
260 {
return scIntegrator_->getTimeStepControl()->getMinTimeStep(); }
263 template<
class Scalar>
265 {
return scIntegrator_->getTimeStepControl()->getInitTimeStep(); }
268 template<
class Scalar>
270 {
return scIntegrator_->getTimeStepControl()->getMaxTimeStep(); }
273 template<
class Scalar>
275 {
return scIntegrator_->getTimeStepControl()->getStepType(); }
278 template<
class Scalar>
280 {
return scIntegrator_->getTimeStepControl()->getMaxFailures(); }
283 template<
class Scalar>
285 {
return scIntegrator_->getTimeStepControl()->getMaxConsecFailures(); }
288 template<
class Scalar>
290 {
return scIntegrator_->getScreenOutputIndexInterval(); }
293 template<
class Scalar>
295 {
return scIntegrator_->getScreenOutputIndexList(); }
298 template<
class Scalar>
299 Teuchos::RCP<TimeStepControlStrategy<Scalar> >
301 {
return scIntegrator_->getTimeStepControl()->getTimeStepControlStrategy(); }
303 template<
class Scalar>
304 Teuchos::RCP<IntegratorObserver<Scalar> >
306 {
return scIntegrator_->getObserver(); }
308 template<
class Scalar>
310 {
return scIntegrator_->getTimeStepControl()->getPrintDtChanges(); }
313 template<
class Scalar>
315 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel)
317 scIntegrator_->setStepper(appModel);
318 this->isInitialized_ =
false;
322 template<
class Scalar>
324 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& appModel)
327 this->isInitialized_ =
false;
330 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
331 template<
class Scalar>
335 if (obs != Teuchos::null) stepperSCObserver_ =
336 Teuchos::rcp_dynamic_cast<StepperSubcyclingObserver<Scalar> > (obs,
true);
338 if (stepperSCObserver_ == Teuchos::null)
341 this->isInitialized_ =
false;
344 template<
class Scalar>
345 Teuchos::RCP<StepperObserver<Scalar> >
347 {
return stepperSCObserver_; }
350 template<
class Scalar>
354 if (appAction == Teuchos::null) {
356 stepperSCAppAction_ =
359 stepperSCAppAction_ = appAction;
361 this->isInitialized_ =
false;
364 template<
class Scalar>
367 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
368 bool isValidSetup =
true;
370 if ( !(this->getICConsistency() ==
"None" ||
371 this->getICConsistency() ==
"Zero" ||
372 this->getICConsistency() ==
"App" ||
373 this->getICConsistency() ==
"Consistent") ) {
374 isValidSetup =
false;
375 *out <<
"The IC consistency does not have a valid value!\n"
376 <<
"('None', 'Zero', 'App' or 'Consistent')\n"
377 <<
" ICConsistency = " << this->getICConsistency() <<
"\n";
379 scIntegrator_->initialize();
381 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
382 if (stepperSCObserver_ == Teuchos::null) {
383 isValidSetup =
false;
384 *out <<
"The Subcycling observer is not set!\n";
387 if (stepperSCAppAction_ == Teuchos::null) {
388 isValidSetup =
false;
389 *out <<
"The Subcycling AppAction is not set!\n";
393 this->isInitialized_ =
true;
395 this->describe(*out, Teuchos::VERB_MEDIUM);
399 template<
class Scalar>
401 {
return scIntegrator_->getStepper()->isExplicit(); }
404 template<
class Scalar>
406 {
return scIntegrator_->getStepper()->isImplicit(); }
409 template<
class Scalar>
411 {
return scIntegrator_->getStepper()->isExplicitImplicit(); }
414 template<
class Scalar>
416 {
return scIntegrator_->getStepper()->isOneStepMethod(); }
419 template<
class Scalar>
421 {
return scIntegrator_->getStepper()->isMultiStepMethod(); }
424 template<
class Scalar>
426 {
return scIntegrator_->getStepper()->getOrder(); }
429 template<
class Scalar>
431 {
return scIntegrator_->getStepper()->getOrderMin(); }
434 template<
class Scalar>
436 {
return scIntegrator_->getStepper()->getOrderMax(); }
439 template<
class Scalar>
441 {
return scIntegrator_->getStepper()->getOrderODE(); }
444 template<
class Scalar>
447 {
return scIntegrator_->getStepper()->getInitTimeStep(solutionHistory); }
450 template<
class Scalar>
452 Teuchos::RCP<
const Thyra::VectorBase<Scalar> > initialGuess)
454 scIntegrator_->getStepper()->setInitialGuess(initialGuess);
455 this->isInitialized_ =
false;
459 template<
class Scalar>
462 { scIntegrator_->getStepper()->setInitialConditions(solutionHistory); }
465 template<
class Scalar>
467 Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > solver)
469 scIntegrator_->getStepper()->setSolver(solver);
470 this->isInitialized_ =
false;
474 template<
class Scalar>
475 Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >
477 {
return scIntegrator_->getStepper()->getSolver(); }
480 template<
class Scalar>
486 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperSubcycling::takeStep()");
488 TEUCHOS_TEST_FOR_EXCEPTION(solutionHistory->getNumStates() < 2,
490 "Error - StepperSubcycling<Scalar>::takeStep(...)\n"
491 "Need at least two SolutionStates for Subcycling.\n"
492 " Number of States = " << solutionHistory->getNumStates() <<
"\n"
493 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
494 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
496 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
497 stepperSCObserver_->observeBeginTakeStep(solutionHistory, *
this);
499 RCP<StepperSubcycling<Scalar> > thisStepper = Teuchos::rcpFromRef(*
this);
500 stepperSCAppAction_->execute(solutionHistory, thisStepper,
502 RCP<SolutionState<Scalar> > currentState=solutionHistory->getCurrentState();
503 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
505 auto scTSC = scIntegrator_->getNonConstTimeStepControl();
506 scTSC->setInitTime (currentState->getTime());
507 scTSC->setInitIndex (0);
508 scTSC->setFinalTime (workingState->getTime());
510 auto subcyclingState = currentState->clone();
511 subcyclingState->setTimeStep(scTSC->getInitTimeStep());
512 subcyclingState->setOrder(scIntegrator_->getStepper()->getOrder());
513 subcyclingState->setIndex(0);
514 subcyclingState->setNFailures(0);
515 subcyclingState->setNRunningFailures(0);
516 subcyclingState->setNConsecutiveFailures(0);
517 subcyclingState->setOutput(
false);
518 subcyclingState->setOutputScreen(
false);
520 TEUCHOS_TEST_FOR_EXCEPTION(!subcyclingState->getIsSynced(),std::logic_error,
521 "Error - StepperSubcycling<Scalar>::takeStep(...)\n"
522 " Subcycling requires the the solution is synced!\n"
523 " (i.e., x, xDot, and xDotDot at the same time level.\n");
526 scSH->setName(
"Subcycling States");
528 scSH->setStorageLimit(3);
529 scSH->addState(subcyclingState);
531 scIntegrator_->setSolutionHistory(scSH);
533 bool pass = scIntegrator_->advanceTime();
535 RCP<SolutionState<Scalar> > scCS = scSH->getCurrentState();
537 RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
538 RCP<Thyra::VectorBase<Scalar> > scX = scCS->getX();
539 Thyra::V_V(x.ptr(), *(scX));
541 RCP<Thyra::VectorBase<Scalar> > xDot = workingState->getXDot();
542 if (xDot != Teuchos::null) {
543 RCP<Thyra::VectorBase<Scalar> > scXDot = scCS->getXDot();
544 Thyra::V_V(xDot.ptr(), *(scXDot));
547 RCP<Thyra::VectorBase<Scalar> > xDotDot = workingState->getXDotDot();
548 if (xDotDot != Teuchos::null) {
549 RCP<Thyra::VectorBase<Scalar> > scXDotDot = scCS->getXDotDot();
550 Thyra::V_V(xDotDot.ptr(), *(scXDotDot));
553 if (pass ==
true) workingState->setSolutionStatus(
Status::PASSED);
555 workingState->setOrder(scCS->getOrder());
556 workingState->computeNorms(currentState);
558 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
559 stepperSCObserver_->observeEndTakeStep(solutionHistory, *
this);
561 stepperSCAppAction_->execute(solutionHistory, thisStepper,
574 template<
class Scalar>
578 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
584 template<
class Scalar>
586 Teuchos::FancyOStream &out,
587 const Teuchos::EVerbosityLevel verbLevel)
const
592 out <<
"--- StepperSubcycling ---\n";
593 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
594 out <<
" stepperSCObserver = " << stepperSCObserver_ << std::endl;
596 out <<
" stepperSCAppAction = " << stepperSCAppAction_ << std::endl;
597 out <<
" scIntegrator = " << scIntegrator_ << std::endl;
598 out <<
"-------------------------" << std::endl;
599 scIntegrator_->getStepper()->describe(out, verbLevel);
603 template<
class Scalar>
604 Teuchos::RCP<const Teuchos::ParameterList>
607 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
608 "Error - StepperSubcycling<Scalar>::getValidParameters()\n"
609 " is not implemented yet.\n");
611 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
613 pl->set<
bool>(
"Use FSAL",
true);
614 pl->set<std::string>(
"Initial Condition Consistency",
"Consistent");
IntegratorObserverNoOp class for time integrators. This basic class has simple no-op functions,...
IntegratorObserver class for time integrators.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
StepperObserver class for Stepper class.
StepperState is a simple class to hold state information about the stepper.
Application Action for StepperSubcycling.
Default modifier for StepperSubcycling.
StepperSubcyclingObserver class for StepperSubcycling.
virtual void setSubcyclingStepper(Teuchos::RCP< Stepper< Scalar > > stepper)
virtual Teuchos::RCP< IntegratorObserver< Scalar > > getSubcyclingIntegratorObserver() const
virtual Scalar getInitTimeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory) const
virtual void setSubcyclingPrintDtChanges(bool printDtChanges)
virtual bool isExplicit() const
virtual OrderODE getOrderODE() const
virtual void setSubcyclingStepType(std::string StepType)
virtual bool isImplicit() const
virtual Scalar getSubcyclingMaxTimeStep() const
virtual bool isExplicitImplicit() const
virtual Scalar getOrder() const
virtual void initialize()
Initialize during construction and after changing input parameters.
virtual Teuchos::RCP< const Stepper< Scalar > > getSubcyclingStepper() const
virtual int getSubcyclingMaxConsecFailures() const
virtual int getSubcyclingScreenOutputIndexInterval() const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual bool getSubcyclingPrintDtChanges() const
virtual void setAppAction(Teuchos::RCP< StepperSubcyclingAppAction< Scalar > > appAction=Teuchos::null)
StepperSubcycling()
Default constructor.
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver=Teuchos::null)
Set solver.
virtual void setSubcyclingMaxTimeStep(Scalar MaxTimeStep)
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)
Set Observer.
virtual void setNonConstModel(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &appModel)
virtual void setSubcyclingIntegratorObserver(Teuchos::RCP< IntegratorObserver< Scalar > > obs)
virtual void setSubcyclingInitTimeStep(Scalar InitTimeStep)
virtual Scalar getSubcyclingInitTimeStep() const
virtual bool isOneStepMethod() const
virtual Scalar getSubcyclingMinTimeStep() const
virtual Teuchos::RCP< StepperObserver< Scalar > > getObserver() const
Get Observer.
virtual int getSubcyclingMaxFailures() const
virtual std::string getSubcyclingStepType() const
virtual void setInitialGuess(Teuchos::RCP< const Thyra::VectorBase< Scalar > > initial_guess)
Pass initial guess to Newton solver (only relevant for implicit solvers)
virtual void setSubcyclingMinTimeStep(Scalar MinTimeStep)
virtual Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > getSolver() const
Get solver.
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
virtual void setSubcyclingScreenOutputIndexInterval(int i)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
virtual Teuchos::RCP< TimeStepControlStrategy< Scalar > > getSubcyclingTimeStepControlStrategy() const
virtual std::string getSubcyclingScreenOutputIndexList() const
virtual Scalar getOrderMax() const
virtual void setSubcyclingMaxFailures(int MaxFailures)
virtual Scalar getOrderMin() const
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions, make them consistent, and set needed memory.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
virtual void setSubcyclingMaxConsecFailures(int MaxConsecFailures)
virtual void setSubcyclingScreenOutputIndexList(std::string s)
virtual void setSubcyclingTimeStepControlStrategy(Teuchos::RCP< TimeStepControlStrategy< Scalar > > tscs)
virtual bool isMultiStepMethod() const
Thyra Base interface for time steppers.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
StepControlStrategy class for TimeStepControl.
StepControlStrategy class for TimeStepControl.
StepControlStrategy class for TimeStepControl.
@ STORAGE_TYPE_STATIC
Keep a fix number of states.
void getValidParametersBasic(Teuchos::RCP< Teuchos::ParameterList > pl, std::string stepperType)
Provide basic parameters to Steppers.