10 #ifndef Tempus_StepperSubcycling_impl_hpp
11 #define Tempus_StepperSubcycling_impl_hpp
13 #include "Thyra_VectorStdOps.hpp"
15 #include "Tempus_StepperForwardEuler.hpp"
19 #include "Tempus_IntegratorObserverSubcycling.hpp"
20 #include "Tempus_IntegratorObserverNoOp.hpp"
24 template <
class Scalar>
30 this->setStepperName(
"Subcycling");
31 this->setStepperType(
"Subcycling");
32 this->setUseFSAL(
false);
33 this->setICConsistency(
"None");
34 this->setICConsistencyCheck(
false);
36 this->setAppAction(Teuchos::null);
39 scIntegrator_->setObserver(
43 scIntegrator_->getValidParameters());
46 tempusPL->
sublist(
"Default Integrator")
47 .
set(
"Stepper Name",
"Default Subcycling Stepper");
48 RCP<ParameterList> stepperPL = Teuchos::parameterList();
49 stepperPL->set(
"Stepper Type",
"Forward Euler");
50 tempusPL->set(
"Default Subcycling Stepper", *stepperPL);
53 setSubcyclingStepper(stepperFE);
69 tempusPL->sublist(
"Default Integrator")
70 .sublist(
"Time Step Control")
71 .set(
"Initial Time Step", std::numeric_limits<Scalar>::max());
74 scIntegrator_->setTimeStepControl();
75 this->setSubcyclingPrintDtChanges(
false);
78 template <
class Scalar>
82 std::string ICConsistency,
bool ICConsistencyCheck,
85 this->setStepperName(
"Subcycling");
86 this->setStepperType(
"Subcycling");
87 this->setUseFSAL(useFSAL);
88 this->setICConsistency(ICConsistency);
89 this->setICConsistencyCheck(ICConsistencyCheck);
90 this->setAppAction(stepperSCAppAction);
91 scIntegrator_ = scIntegrator;
92 this->setSubcyclingPrintDtChanges(
false);
94 if (appModel != Teuchos::null) {
95 this->setModel(appModel);
100 template <
class Scalar>
104 scIntegrator_->setStepper(stepper);
105 this->isInitialized_ =
false;
108 template <
class Scalar>
111 scIntegrator_->getNonConstTimeStepControl()->setMinTimeStep(MinTimeStep);
112 this->isInitialized_ =
false;
115 template <
class Scalar>
118 scIntegrator_->getNonConstTimeStepControl()->setInitTimeStep(InitTimeStep);
119 this->isInitialized_ =
false;
122 template <
class Scalar>
125 scIntegrator_->getNonConstTimeStepControl()->setMaxTimeStep(MaxTimeStep);
126 this->isInitialized_ =
false;
129 template <
class Scalar>
132 scIntegrator_->getNonConstTimeStepControl()->setMaxFailures(MaxFailures);
133 this->isInitialized_ =
false;
136 template <
class Scalar>
138 int MaxConsecFailures)
140 scIntegrator_->getNonConstTimeStepControl()->setMaxConsecFailures(
142 this->isInitialized_ =
false;
145 template <
class Scalar>
148 scIntegrator_->setScreenOutputIndexInterval(i);
149 this->isInitialized_ =
false;
152 template <
class Scalar>
156 scIntegrator_->setScreenOutputIndexList(s);
157 this->isInitialized_ =
false;
160 template <
class Scalar>
164 scIntegrator_->getNonConstTimeStepControl()->setTimeStepControlStrategy(tscs);
165 this->isInitialized_ =
false;
168 template <
class Scalar>
172 scIntegrator_->setObserver(obs);
173 this->isInitialized_ =
false;
176 template <
class Scalar>
179 scIntegrator_->getNonConstTimeStepControl()->setPrintDtChanges(
181 this->isInitialized_ =
false;
184 template <
class Scalar>
188 return scIntegrator_->getStepper();
191 template <
class Scalar>
194 return scIntegrator_->getTimeStepControl()->getMinTimeStep();
197 template <
class Scalar>
200 return scIntegrator_->getTimeStepControl()->getInitTimeStep();
203 template <
class Scalar>
206 return scIntegrator_->getTimeStepControl()->getMaxTimeStep();
209 template <
class Scalar>
212 return scIntegrator_->getTimeStepControl()->getStepType();
215 template <
class Scalar>
218 return scIntegrator_->getTimeStepControl()->getMaxFailures();
221 template <
class Scalar>
224 return scIntegrator_->getTimeStepControl()->getMaxConsecFailures();
227 template <
class Scalar>
230 return scIntegrator_->getScreenOutputIndexInterval();
233 template <
class Scalar>
237 return scIntegrator_->getScreenOutputIndexListString();
240 template <
class Scalar>
244 return scIntegrator_->getTimeStepControl()->getTimeStepControlStrategy();
247 template <
class Scalar>
251 return scIntegrator_->getObserver();
254 template <
class Scalar>
257 return scIntegrator_->getTimeStepControl()->getPrintDtChanges();
260 template <
class Scalar>
264 scIntegrator_->setModel(appModel);
265 this->isInitialized_ =
false;
268 template <
class Scalar>
273 this->isInitialized_ =
false;
276 template <
class Scalar>
280 if (appAction == Teuchos::null) {
282 stepperSCAppAction_ =
286 stepperSCAppAction_ = appAction;
288 this->isInitialized_ =
false;
291 template <
class Scalar>
295 bool isValidSetup =
true;
297 if (!(this->getICConsistency() ==
"None" ||
298 this->getICConsistency() ==
"Zero" ||
299 this->getICConsistency() ==
"App" ||
300 this->getICConsistency() ==
"Consistent")) {
301 isValidSetup =
false;
302 *out <<
"The IC consistency does not have a valid value!\n"
303 <<
"('None', 'Zero', 'App' or 'Consistent')\n"
304 <<
" ICConsistency = " << this->getICConsistency() <<
"\n";
308 if (stepperSCAppAction_ == Teuchos::null) {
309 isValidSetup =
false;
310 *out <<
"The Subcycling AppAction is not set!\n";
314 this->isInitialized_ =
true;
319 template <
class Scalar>
322 return scIntegrator_->getStepper()->isExplicit();
325 template <
class Scalar>
328 return scIntegrator_->getStepper()->isImplicit();
331 template <
class Scalar>
334 return scIntegrator_->getStepper()->isExplicitImplicit();
337 template <
class Scalar>
340 return scIntegrator_->getStepper()->isOneStepMethod();
343 template <
class Scalar>
346 return scIntegrator_->getStepper()->isMultiStepMethod();
349 template <
class Scalar>
352 return scIntegrator_->getStepper()->getOrder();
355 template <
class Scalar>
358 return scIntegrator_->getStepper()->getOrderMin();
361 template <
class Scalar>
364 return scIntegrator_->getStepper()->getOrderMax();
367 template <
class Scalar>
370 return scIntegrator_->getStepper()->getOrderODE();
373 template <
class Scalar>
377 return scIntegrator_->getStepper()->getInitTimeStep(solutionHistory);
380 template <
class Scalar>
384 scIntegrator_->getStepper()->setInitialGuess(initialGuess);
385 this->isInitialized_ =
false;
388 template <
class Scalar>
392 scIntegrator_->getStepper()->setInitialConditions(solutionHistory);
393 scIntegrator_->setSolutionHistory(solutionHistory);
396 template <
class Scalar>
400 scIntegrator_->getStepper()->setSolver(solver);
401 this->isInitialized_ =
false;
404 template <
class Scalar>
408 return scIntegrator_->getStepper()->getSolver();
411 template <
class Scalar>
417 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperSubcycling::takeStep()");
420 solutionHistory->getNumStates() < 2, std::logic_error,
421 "Error - StepperSubcycling<Scalar>::takeStep(...)\n"
422 <<
"Need at least two SolutionStates for Subcycling.\n"
423 <<
" Number of States = " << solutionHistory->getNumStates()
424 <<
"\nTry setting in \"Solution History\" \"Storage Type\" = "
426 <<
" or \"Storage Type\" = \"Static\" and \"Storage Limit\" = "
429 RCP<StepperSubcycling<Scalar> > thisStepper = Teuchos::rcpFromRef(*
this);
430 stepperSCAppAction_->execute(
431 solutionHistory, thisStepper,
433 RCP<SolutionState<Scalar> > currentState =
434 solutionHistory->getCurrentState();
435 RCP<SolutionState<Scalar> > workingState =
436 solutionHistory->getWorkingState();
438 auto scTSC = scIntegrator_->getNonConstTimeStepControl();
439 scTSC->setInitTime(currentState->getTime());
440 scTSC->setInitIndex(0);
441 scTSC->setFinalTime(workingState->getTime());
443 auto subcyclingState = currentState->clone();
444 subcyclingState->setTimeStep(scTSC->getInitTimeStep());
445 subcyclingState->setOrder(scIntegrator_->getStepper()->getOrder());
446 subcyclingState->setIndex(0);
447 subcyclingState->setNFailures(0);
448 subcyclingState->setNRunningFailures(0);
449 subcyclingState->setNConsecutiveFailures(0);
450 subcyclingState->setOutput(
false);
451 subcyclingState->setOutputScreen(
false);
454 !subcyclingState->getIsSynced(), std::logic_error,
455 "Error - StepperSubcycling<Scalar>::takeStep(...)\n"
456 " Subcycling requires the the solution is synced!\n"
457 " (i.e., x, xDot, and xDotDot at the same time level.\n");
460 scSH->setName(
"Subcycling States");
462 scSH->setStorageLimit(3);
463 scSH->addState(subcyclingState);
465 scIntegrator_->setSolutionHistory(scSH);
467 bool pass = scIntegrator_->advanceTime();
469 RCP<SolutionState<Scalar> > scCS = scSH->getCurrentState();
471 RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
472 RCP<Thyra::VectorBase<Scalar> > scX = scCS->getX();
473 Thyra::V_V(x.ptr(), *(scX));
475 RCP<Thyra::VectorBase<Scalar> > xDot = workingState->getXDot();
476 if (xDot != Teuchos::null) {
477 RCP<Thyra::VectorBase<Scalar> > scXDot = scCS->getXDot();
478 Thyra::V_V(xDot.ptr(), *(scXDot));
481 RCP<Thyra::VectorBase<Scalar> > xDotDot = workingState->getXDotDot();
482 if (xDotDot != Teuchos::null) {
483 RCP<Thyra::VectorBase<Scalar> > scXDotDot = scCS->getXDotDot();
484 Thyra::V_V(xDotDot.ptr(), *(scXDotDot));
491 workingState->setOrder(scCS->getOrder());
492 workingState->computeNorms(currentState);
494 stepperSCAppAction_->execute(
495 solutionHistory, thisStepper,
507 template <
class Scalar>
516 template <
class Scalar>
524 out <<
"--- StepperSubcycling ---\n";
525 out <<
" stepperSCAppAction = " << stepperSCAppAction_ << std::endl;
526 out <<
" scIntegrator = " << scIntegrator_ << std::endl;
527 out <<
"-------------------------" << std::endl;
528 scIntegrator_->getStepper()->describe(out, verbLevel);
531 template <
class Scalar>
536 true, std::logic_error,
537 "Error - StepperSubcycling<Scalar>::getValidParameters()\n"
538 " is not implemented yet.\n");
540 return this->getValidParametersBasic();
545 template <
class Scalar>
553 pl != Teuchos::null, std::logic_error,
554 "Error - Construction of StepperSubcycling with a ParameterList\n"
555 "is not implemented yet!\n");
557 if (pl != Teuchos::null) {
558 stepper->setStepperValues(pl);
561 if (model != Teuchos::null) {
562 stepper->setModel(model);
563 stepper->initialize();
570 #endif // Tempus_StepperSubcycling_impl_hpp
virtual int getSubcyclingMaxConsecFailures() const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
virtual bool isExplicitImplicit() const
virtual void setSubcyclingStepper(Teuchos::RCP< Stepper< Scalar > > stepper)
virtual void initialize()
Initialize during construction and after changing input parameters.
virtual void setSubcyclingMinTimeStep(Scalar MinTimeStep)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void setSubcyclingScreenOutputIndexInterval(int i)
virtual void setSubcyclingMaxTimeStep(Scalar MaxTimeStep)
Forward Euler time stepper.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Default modifier for StepperSubcycling.
virtual Scalar getSubcyclingMaxTimeStep() const
Teuchos::RCP< StepperSubcycling< Scalar > > createStepperSubcycling(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void initialize(const RCP< std::basic_ostream< char_type, traits_type > > &oStream, const std::basic_string< char_type, traits_type > &tabIndentStr=" ", const int startingTab=0, const bool showLinePrefix=false, const int maxLenLinePrefix=10, const bool showTabCount=false, const bool showProcRank=false)
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
virtual bool isOneStepMethod() const
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver=Teuchos::null)
Set solver.
virtual void setSubcyclingMaxConsecFailures(int MaxConsecFailures)
virtual int getSubcyclingMaxFailures() const
virtual void setSubcyclingTimeStepControlStrategy(Teuchos::RCP< TimeStepControlStrategy< Scalar > > tscs)
Application Action for StepperSubcycling.
Thyra Base interface for time steppers.
virtual Teuchos::RCP< IntegratorObserver< Scalar > > getSubcyclingIntegratorObserver() const
virtual int getSubcyclingScreenOutputIndexInterval() const
virtual void setSubcyclingIntegratorObserver(Teuchos::RCP< IntegratorObserver< Scalar > > obs)
StepperState is a simple class to hold state information about the stepper.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual bool isImplicit() const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
IntegratorObserverNoOp class for time integrators. This basic class has simple no-op functions...
virtual Scalar getOrderMax() const
IntegratorObserver class for time integrators.
virtual Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > getSolver() const
Get solver.
virtual void setSubcyclingScreenOutputIndexList(std::string s)
virtual std::string getSubcyclingStepType() const
virtual bool isExplicit() const
virtual bool isMultiStepMethod() const
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
virtual Scalar getInitTimeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory) const
Keep a fix number of states.
virtual void setSubcyclingInitTimeStep(Scalar InitTimeStep)
virtual void setInitialGuess(Teuchos::RCP< const Thyra::VectorBase< Scalar > > initial_guess)
Pass initial guess to Newton solver (only relevant for implicit solvers)
virtual Teuchos::RCP< const Stepper< Scalar > > getSubcyclingStepper() const
virtual Scalar getOrderMin() const
virtual OrderODE getOrderODE() const
virtual Scalar getOrder() const
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
virtual void setSubcyclingPrintDtChanges(bool printDtChanges)
virtual std::string getSubcyclingScreenOutputIndexList() const
StepperSubcycling()
Default constructor.
virtual Scalar getSubcyclingMinTimeStep() const
virtual bool getSubcyclingPrintDtChanges() const
TimeStepControlStrategy class for TimeStepControl.
virtual Teuchos::RCP< TimeStepControlStrategy< Scalar > > getSubcyclingTimeStepControlStrategy() const
virtual Scalar getSubcyclingInitTimeStep() const
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions, make them consistent, and set needed memory.
virtual void setNonConstModel(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &appModel)
virtual void setAppAction(Teuchos::RCP< StepperSubcyclingAppAction< Scalar > > appAction=Teuchos::null)
virtual void setSubcyclingMaxFailures(int MaxFailures)