9 #ifndef Tempus_StepperSubcycling_impl_hpp
10 #define Tempus_StepperSubcycling_impl_hpp
12 #include "Thyra_VectorStdOps.hpp"
14 #include "Tempus_StepperForwardEuler.hpp"
18 #include "Tempus_IntegratorObserverSubcycling.hpp"
19 #include "Tempus_IntegratorObserverNoOp.hpp"
25 template<
class Scalar>
31 this->setStepperName(
"Subcycling");
32 this->setStepperType(
"Subcycling");
33 this->setUseFSAL(
false);
34 this->setICConsistency(
"None");
35 this->setICConsistencyCheck(
false);
37 this->setAppAction(Teuchos::null);
40 scIntegrator_->setObserver(
43 RCP<ParameterList> tempusPL =
45 scIntegrator_->getValidParameters());
48 tempusPL->
sublist(
"Default Integrator")
49 .
set(
"Stepper Name",
"Default Subcycling Stepper");
50 RCP<ParameterList> stepperPL = Teuchos::parameterList();
51 stepperPL->set(
"Stepper Type",
"Forward Euler");
52 tempusPL->set(
"Default Subcycling Stepper", *stepperPL);
55 setSubcyclingStepper(stepperFE);
71 tempusPL->sublist(
"Default Integrator")
72 .sublist(
"Time Step Control")
73 .set(
"Initial Time Step", std::numeric_limits<Scalar>::max());
76 scIntegrator_->setTimeStepControl();
77 this->setSubcyclingPrintDtChanges(
false);
82 template<
class Scalar>
87 std::string ICConsistency,
88 bool ICConsistencyCheck,
91 this->setStepperName(
"Subcycling");
92 this->setStepperType(
"Subcycling");
93 this->setUseFSAL( useFSAL);
94 this->setICConsistency( ICConsistency);
95 this->setICConsistencyCheck( ICConsistencyCheck);
96 this->setAppAction(stepperSCAppAction);
97 scIntegrator_ = scIntegrator;
98 this->setSubcyclingPrintDtChanges(
false);
100 if (appModel != Teuchos::null) {
101 this->setModel(appModel);
106 template<
class Scalar>
110 scIntegrator_->setStepper(stepper);
111 this->isInitialized_ =
false;
115 template<
class Scalar>
118 scIntegrator_->getNonConstTimeStepControl()->setMinTimeStep(MinTimeStep);
119 this->isInitialized_ =
false;
123 template<
class Scalar>
126 scIntegrator_->getNonConstTimeStepControl()->setInitTimeStep(InitTimeStep);
127 this->isInitialized_ =
false;
131 template<
class Scalar>
134 scIntegrator_->getNonConstTimeStepControl()->setMaxTimeStep(MaxTimeStep);
135 this->isInitialized_ =
false;
139 template<
class Scalar>
142 scIntegrator_->getNonConstTimeStepControl()->setMaxFailures(MaxFailures);
143 this->isInitialized_ =
false;
147 template<
class Scalar>
151 scIntegrator_->getNonConstTimeStepControl()->setMaxConsecFailures(MaxConsecFailures);
152 this->isInitialized_ =
false;
156 template<
class Scalar>
160 scIntegrator_->setScreenOutputIndexInterval(i);
161 this->isInitialized_ =
false;
165 template<
class Scalar>
169 scIntegrator_->setScreenOutputIndexList(s);
170 this->isInitialized_ =
false;
174 template<
class Scalar>
179 scIntegrator_->getNonConstTimeStepControl()->setTimeStepControlStrategy(tscs);
180 this->isInitialized_ =
false;
184 template<
class Scalar>
188 scIntegrator_->setObserver(obs);
189 this->isInitialized_ =
false;
193 template<
class Scalar>
197 scIntegrator_->getNonConstTimeStepControl()->setPrintDtChanges(printDtChanges);
198 this->isInitialized_ =
false;
202 template<
class Scalar>
205 {
return scIntegrator_->getStepper(); }
208 template<
class Scalar>
210 {
return scIntegrator_->getTimeStepControl()->getMinTimeStep(); }
213 template<
class Scalar>
215 {
return scIntegrator_->getTimeStepControl()->getInitTimeStep(); }
218 template<
class Scalar>
220 {
return scIntegrator_->getTimeStepControl()->getMaxTimeStep(); }
223 template<
class Scalar>
225 {
return scIntegrator_->getTimeStepControl()->getStepType(); }
228 template<
class Scalar>
230 {
return scIntegrator_->getTimeStepControl()->getMaxFailures(); }
233 template<
class Scalar>
235 {
return scIntegrator_->getTimeStepControl()->getMaxConsecFailures(); }
238 template<
class Scalar>
240 {
return scIntegrator_->getScreenOutputIndexInterval(); }
243 template<
class Scalar>
245 {
return scIntegrator_->getScreenOutputIndexListString(); }
248 template<
class Scalar>
251 {
return scIntegrator_->getTimeStepControl()->getTimeStepControlStrategy(); }
253 template<
class Scalar>
256 {
return scIntegrator_->getObserver(); }
258 template<
class Scalar>
260 {
return scIntegrator_->getTimeStepControl()->getPrintDtChanges(); }
263 template<
class Scalar>
267 scIntegrator_->setModel(appModel);
268 this->isInitialized_ =
false;
272 template<
class Scalar>
277 this->isInitialized_ =
false;
281 template<
class Scalar>
285 if (appAction == Teuchos::null) {
287 stepperSCAppAction_ =
290 stepperSCAppAction_ = appAction;
292 this->isInitialized_ =
false;
295 template<
class Scalar>
299 bool isValidSetup =
true;
301 if ( !(this->getICConsistency() ==
"None" ||
302 this->getICConsistency() ==
"Zero" ||
303 this->getICConsistency() ==
"App" ||
304 this->getICConsistency() ==
"Consistent") ) {
305 isValidSetup =
false;
306 *out <<
"The IC consistency does not have a valid value!\n"
307 <<
"('None', 'Zero', 'App' or 'Consistent')\n"
308 <<
" ICConsistency = " << this->getICConsistency() <<
"\n";
312 if (stepperSCAppAction_ == Teuchos::null) {
313 isValidSetup =
false;
314 *out <<
"The Subcycling AppAction is not set!\n";
318 this->isInitialized_ =
true;
324 template<
class Scalar>
326 {
return scIntegrator_->getStepper()->isExplicit(); }
329 template<
class Scalar>
331 {
return scIntegrator_->getStepper()->isImplicit(); }
334 template<
class Scalar>
336 {
return scIntegrator_->getStepper()->isExplicitImplicit(); }
339 template<
class Scalar>
341 {
return scIntegrator_->getStepper()->isOneStepMethod(); }
344 template<
class Scalar>
346 {
return scIntegrator_->getStepper()->isMultiStepMethod(); }
349 template<
class Scalar>
351 {
return scIntegrator_->getStepper()->getOrder(); }
354 template<
class Scalar>
356 {
return scIntegrator_->getStepper()->getOrderMin(); }
359 template<
class Scalar>
361 {
return scIntegrator_->getStepper()->getOrderMax(); }
364 template<
class Scalar>
366 {
return scIntegrator_->getStepper()->getOrderODE(); }
369 template<
class Scalar>
372 {
return scIntegrator_->getStepper()->getInitTimeStep(solutionHistory); }
375 template<
class Scalar>
379 scIntegrator_->getStepper()->setInitialGuess(initialGuess);
380 this->isInitialized_ =
false;
384 template<
class Scalar>
388 scIntegrator_->getStepper()->setInitialConditions(solutionHistory);
389 scIntegrator_->setSolutionHistory(solutionHistory);
393 template<
class Scalar>
397 scIntegrator_->getStepper()->setSolver(solver);
398 this->isInitialized_ =
false;
402 template<
class Scalar>
405 {
return scIntegrator_->getStepper()->getSolver(); }
408 template<
class Scalar>
414 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperSubcycling::takeStep()");
418 "Error - StepperSubcycling<Scalar>::takeStep(...)\n"
419 "Need at least two SolutionStates for Subcycling.\n"
420 " Number of States = " << solutionHistory->getNumStates() <<
"\n"
421 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
422 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
424 RCP<StepperSubcycling<Scalar> > thisStepper = Teuchos::rcpFromRef(*
this);
425 stepperSCAppAction_->execute(solutionHistory, thisStepper,
427 RCP<SolutionState<Scalar> > currentState=solutionHistory->getCurrentState();
428 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
430 auto scTSC = scIntegrator_->getNonConstTimeStepControl();
431 scTSC->setInitTime (currentState->getTime());
432 scTSC->setInitIndex (0);
433 scTSC->setFinalTime (workingState->getTime());
435 auto subcyclingState = currentState->clone();
436 subcyclingState->setTimeStep(scTSC->getInitTimeStep());
437 subcyclingState->setOrder(scIntegrator_->getStepper()->getOrder());
438 subcyclingState->setIndex(0);
439 subcyclingState->setNFailures(0);
440 subcyclingState->setNRunningFailures(0);
441 subcyclingState->setNConsecutiveFailures(0);
442 subcyclingState->setOutput(
false);
443 subcyclingState->setOutputScreen(
false);
446 "Error - StepperSubcycling<Scalar>::takeStep(...)\n"
447 " Subcycling requires the the solution is synced!\n"
448 " (i.e., x, xDot, and xDotDot at the same time level.\n");
451 scSH->setName(
"Subcycling States");
453 scSH->setStorageLimit(3);
454 scSH->addState(subcyclingState);
456 scIntegrator_->setSolutionHistory(scSH);
458 bool pass = scIntegrator_->advanceTime();
460 RCP<SolutionState<Scalar> > scCS = scSH->getCurrentState();
462 RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
463 RCP<Thyra::VectorBase<Scalar> > scX = scCS->getX();
464 Thyra::V_V(x.ptr(), *(scX));
466 RCP<Thyra::VectorBase<Scalar> > xDot = workingState->getXDot();
467 if (xDot != Teuchos::null) {
468 RCP<Thyra::VectorBase<Scalar> > scXDot = scCS->getXDot();
469 Thyra::V_V(xDot.ptr(), *(scXDot));
472 RCP<Thyra::VectorBase<Scalar> > xDotDot = workingState->getXDotDot();
473 if (xDotDot != Teuchos::null) {
474 RCP<Thyra::VectorBase<Scalar> > scXDotDot = scCS->getXDotDot();
475 Thyra::V_V(xDotDot.ptr(), *(scXDotDot));
478 if (pass ==
true) workingState->setSolutionStatus(
Status::PASSED);
480 workingState->setOrder(scCS->getOrder());
481 workingState->computeNorms(currentState);
483 stepperSCAppAction_->execute(solutionHistory, thisStepper,
496 template<
class Scalar>
506 template<
class Scalar>
514 out <<
"--- StepperSubcycling ---\n";
515 out <<
" stepperSCAppAction = " << stepperSCAppAction_ << std::endl;
516 out <<
" scIntegrator = " << scIntegrator_ << std::endl;
517 out <<
"-------------------------" << std::endl;
518 scIntegrator_->getStepper()->describe(out, verbLevel);
522 template<
class Scalar>
527 "Error - StepperSubcycling<Scalar>::getValidParameters()\n"
528 " is not implemented yet.\n");
530 return this->getValidParametersBasic();
536 template<
class Scalar>
545 "Error - Construction of StepperSubcycling with a ParameterList\n"
546 "is not implemented yet!\n");
548 if (pl != Teuchos::null) {
549 stepper->setStepperValues(pl);
552 if (model != Teuchos::null) {
553 stepper->setModel(model);
554 stepper->initialize();
562 #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)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.
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...
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)