10#ifndef Tempus_StepperOperatorSplit_impl_hpp
11#define Tempus_StepperOperatorSplit_impl_hpp
13#include "Tempus_StepperFactory.hpp"
18template <
class Scalar>
37template <
class Scalar>
40 std::vector<Teuchos::RCP<
Stepper<Scalar> > > subStepperList,
bool useFSAL,
41 std::string ICConsistency,
bool ICConsistencyCheck,
int order,
int orderMin,
62 if (!(appModels.empty())) {
68template <
class Scalar>
72 if (appModel != Teuchos::null) {
73 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
74 Teuchos::OSTab ostab(out, 1,
"StepperOperatorSplit::setModel()");
75 *out <<
"Warning -- No ModelEvaluator to set for StepperOperatorSplit, "
76 <<
"because it is a Stepper of Steppers.\n"
81template <
class Scalar>
82Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
85 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > model;
86 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
89 model = (*subStepperIter)->getModel();
90 if (model != Teuchos::null)
break;
92 if (model == Teuchos::null) {
93 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
94 Teuchos::OSTab ostab(out, 1,
"StepperOperatorSplit::getModel()");
95 *out <<
"Warning -- StepperOperatorSplit::getModel() "
96 <<
"Could not find a valid model! Returning null!" << std::endl;
102template <
class Scalar>
104 Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > )
106 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
107 Teuchos::OSTab ostab(out, 1,
"StepperOperatorSplit::setSolver()");
108 *out <<
"Warning -- No solver to set for StepperOperatorSplit "
109 <<
"because it is a Stepper of Steppers.\n"
115template <
class Scalar>
119 if (appAction == Teuchos::null) {
128 Teuchos::rcp_dynamic_cast<StepperOperatorSplitAppAction<Scalar> >(
134template <
class Scalar>
138 stepper->setUseFSAL(useFSAL);
142template <
class Scalar>
146 using Teuchos::ParameterList;
151 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
155 auto subStepper = *(subStepperIter);
156 bool useFSAL = subStepper->getUseFSAL();
158 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
159 Teuchos::OSTab ostab(out, 1,
"StepperOperatorSplit::setSubStepperList()");
160 *out <<
"Warning -- subStepper = '" << subStepper->getStepperType()
162 <<
" subStepper->getUseFSAL() = " << useFSAL <<
".\n"
163 <<
" subSteppers usually can not use the FSAL priniciple with\n"
164 <<
" operator splitting. Proceeding with it set to true.\n"
172template <
class Scalar>
176 using Teuchos::ParameterList;
179 TEUCHOS_TEST_FOR_EXCEPTION(
181 "Error - Number of models and Steppers do not match!\n"
182 <<
" There are " << appModels.size() <<
" models.\n"
185 typename std::vector<RCP<const Thyra::ModelEvaluator<Scalar> > >::iterator
186 appModelIter = appModels.begin();
188 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
192 appModelIter < appModels.end() || subStepperIter <
subStepperList_.end();
193 appModelIter++, subStepperIter++) {
194 auto appModel = *(appModelIter);
195 auto subStepper = *(subStepperIter);
196 subStepper->setModel(appModel);
202template <
class Scalar>
206 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > model = this->
getModel();
207 TEUCHOS_TEST_FOR_EXCEPTION(
208 model == Teuchos::null, std::logic_error,
209 "Error - StepperOperatorSplit::initialize() Could not find "
215 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
216 Teuchos::OSTab ostab(out, 1,
"StepperOperatorSplit::initialize()");
217 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
220 *out <<
"SubStepper, " << (*subStepperIter)->getStepperType()
221 <<
", isOneStepMethod = " << (*subStepperIter)->isOneStepMethod()
224 TEUCHOS_TEST_FOR_EXCEPTION(
226 "Error - OperatorSplit only works for one-step methods!\n");
230 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
233 (*subStepperIter)->initialize();
238template <
class Scalar>
242 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
245 (*subStepperIter)->setInitialConditions(solutionHistory);
247 Teuchos::RCP<SolutionState<Scalar> > initialState =
248 solutionHistory->getCurrentState();
252 if (initialState->getXDot() == Teuchos::null)
256template <
class Scalar>
264 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperOperatorSplit::takeStep()");
266 TEUCHOS_TEST_FOR_EXCEPTION(
267 solutionHistory->getNumStates() < 2, std::logic_error,
268 "Error - StepperOperatorSplit<Scalar>::takeStep(...)\n"
269 <<
"Need at least two SolutionStates for OperatorSplit.\n"
270 <<
" Number of States = " << solutionHistory->getNumStates()
271 <<
"\nTry setting in \"Solution History\" \"Storage Type\" = "
273 <<
" or \"Storage Type\" = \"Static\" and \"Storage Limit\" = "
275 RCP<StepperOperatorSplit<Scalar> > thisStepper = Teuchos::rcpFromRef(*
this);
277 solutionHistory, thisStepper,
280 RCP<SolutionState<Scalar> > workingState =
281 solutionHistory->getWorkingState();
284 tempState_->copy(solutionHistory->getCurrentState());
289 RCP<SolutionState<Scalar> > currentSubState =
291 RCP<SolutionState<Scalar> > workingSubState =
295 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
297 for (; subStepperIter <
subStepperList_.end() && pass; subStepperIter++) {
299 solutionHistory, thisStepper,
301 Scalar>::ACTION_LOCATION::BEFORE_STEPPER);
307 Scalar>::ACTION_LOCATION::AFTER_STEPPER);
311 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
312 Teuchos::OSTab ostab(out, 1,
"StepperOperatorSplit::takeStep()");
313 *out <<
"SubStepper, " << (*subStepperIter)->getStepperType()
314 <<
", failed!" << std::endl;
320 currentSubState->copySolutionData(workingSubState);
327 workingState->setOrder(this->
getOrder());
328 workingState->computeNorms(solutionHistory->getCurrentState());
332 solutionHistory, thisStepper,
344template <
class Scalar>
345Teuchos::RCP<Tempus::StepperState<Scalar> >
348 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
353template <
class Scalar>
355 Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel)
const
357 out.setOutputToRootOnly(0);
361 out <<
"--- StepperOperatorSplit ---\n";
362 out <<
" subStepperList_.size() = " <<
subStepperList_.size() << std::endl;
363 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
366 out <<
" SubStepper = " << (*subStepperIter)->getStepperType()
368 out <<
" = " << (*subStepperIter)->isInitialized()
370 out <<
" = " << (*subStepperIter) << std::endl;
373 out <<
" tempState_ = " <<
tempState_ << std::endl;
375 out <<
" order_ = " <<
order_ << std::endl;
376 out <<
" orderMin_ = " <<
orderMin_ << std::endl;
377 out <<
" orderMax_ = " <<
orderMax_ << std::endl;
378 out <<
"----------------------------" << std::endl;
381template <
class Scalar>
383 Teuchos::FancyOStream& out)
const
385 out.setOutputToRootOnly(0);
392 out <<
"The substepper list is empty!\n";
395 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
399 auto subStepper = *(subStepperIter);
400 if (!subStepper->isInitialized()) {
402 out <<
"The subStepper, " << subStepper->description()
403 <<
", is not initialized!\n";
408 out <<
"The Operator-Split AppAction is not set!\n";
414template <
class Scalar>
415Teuchos::RCP<const Teuchos::ParameterList>
419 pl->template set<int>(
"Minimum Order",
orderMin_,
420 "Minimum Operator-split order. (default = 1)\n");
421 pl->template set<int>(
"Order",
order_,
422 "Operator-split order. (default = 1)\n");
423 pl->template set<int>(
"Maximum Order",
orderMax_,
424 "Maximum Operator-split order. (default = 1)\n");
426 std::ostringstream list;
428 for (std::size_t i = 0; i < size - 1; ++i) {
432 pl->template set<std::string>(
433 "Stepper List", list.str(),
434 "Comma deliminated list of single quoted Steppers, e.g., \"'Operator 1', "
437 for (std::size_t i = 0; i < size; ++i) {
445template <
class Scalar>
448 Teuchos::RCP<Teuchos::ParameterList> stepperPL)
450 if (stepperPL != Teuchos::null) {
451 using Teuchos::ParameterList;
455 std::vector<std::string> stepperListStr;
456 stepperListStr.clear();
457 std::string str = stepperPL->get<std::string>(
"Stepper List");
458 std::string delimiters(
",");
460 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
462 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
463 while ((pos != std::string::npos) || (lastPos != std::string::npos)) {
464 std::string token = str.substr(lastPos, pos - lastPos);
466 std::string::size_type beg = token.find_first_of(
"'") + 1;
467 std::string::size_type end = token.find_last_of(
"'");
468 stepperListStr.push_back(token.substr(beg, end - beg));
470 lastPos = str.find_first_not_of(delimiters, pos);
471 pos = str.find_first_of(delimiters, lastPos);
474 TEUCHOS_TEST_FOR_EXCEPTION(
475 stepperListStr.size() != appModels.size(), std::logic_error,
476 "Error - Number of models and Steppers do not match!\n"
477 <<
" There are " << appModels.size() <<
" models.\n"
478 <<
" There are " << stepperListStr.size() <<
" steppers.\n"
479 <<
" " << str <<
"\n");
481 typename std::vector<RCP<const Thyra::ModelEvaluator<Scalar> > >::iterator
482 aMI = appModels.begin();
483 typename std::vector<std::string>::iterator sLSI = stepperListStr.begin();
485 for (; aMI < appModels.end() || sLSI < stepperListStr.end();
487 RCP<ParameterList> subStepperPL =
488 Teuchos::sublist(stepperPL, *sLSI,
true);
489 auto name = subStepperPL->name();
490 lastPos = name.rfind(
"->");
491 std::string newName = name.substr(lastPos + 2, name.length());
492 subStepperPL->setName(newName);
493 bool useFSAL = subStepperPL->template get<bool>(
"Use FSAL",
false);
495 auto subStepper = sf->createStepper(subStepperPL, *aMI);
497 Teuchos::RCP<Teuchos::FancyOStream> out =
498 Teuchos::VerboseObjectBase::getDefaultOStream();
499 Teuchos::OSTab ostab(out, 1,
"StepperFactory::createSubSteppers()");
500 *out <<
"Warning -- subStepper = '" << subStepper->getStepperType()
502 <<
" subStepper->getUseFSAL() = " << useFSAL <<
".\n"
503 <<
" subSteppers usually can not use the FSAL priniciple with\n"
504 <<
" operator splitting. Proceeding with it set to true.\n"
514template <
class Scalar>
517 Teuchos::RCP<Teuchos::ParameterList> pl)
521 if (pl != Teuchos::null) {
522 stepper->setStepperValues(pl);
523 stepper->setOrderMin(pl->get<
int>(
"Minimum Order", 1));
524 stepper->setOrder(pl->get<
int>(
"Order", 1));
525 stepper->setOrderMax(pl->get<
int>(
"Maximum Order", 1));
528 if (!(appModels.empty())) {
529 stepper->createSubSteppers(appModels, pl);
530 stepper->initialize();
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Thyra Base interface for time steppers.
bool isInitialized_
True if stepper's member data is initialized.
std::string getStepperName() const
Get the stepper name.
void setICConsistencyCheck(bool c)
virtual void setStepperXDot(Teuchos::RCP< Thyra::VectorBase< Scalar > > xDot)
Set xDot for Stepper storage.
void setStepperName(std::string s)
Set the stepper name.
virtual void initialize()
Initialize after construction and changing input parameters.
std::string getStepperType() const
Get the stepper type. The stepper type is used as an identifier for the stepper, and can only be set ...
Teuchos::RCP< Teuchos::ParameterList > getValidParametersBasic() const
Add basic parameters to Steppers ParameterList.
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
virtual void checkInitialized()
Check initialization, and error out on failure.
void setStepperType(std::string s)
Set the stepper type.
void setICConsistency(std::string s)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
StepperOperatorSplitAppAction class for StepperOperatorSplit.
@ BEGIN_STEP
At the beginning of the step.
@ END_STEP
At the end of the step.
OperatorSplit stepper loops through the Stepper list.
std::vector< Teuchos::RCP< Stepper< Scalar > > > subStepperList_
virtual void setModels(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > > appModels)
virtual void setOrderMin(Scalar o)
virtual void setOrderMax(Scalar o)
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
virtual void setUseFSAL(bool a)
virtual void setAppAction(Teuchos::RCP< StepperOperatorSplitAppAction< Scalar > > appAction)
virtual void initialize()
Initialize during construction and after changing input parameters.
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver)
Set solver.
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
virtual void setSubStepperList(std::vector< Teuchos::RCP< Stepper< Scalar > > > subStepperList)
Teuchos::RCP< StepperOperatorSplitAppAction< Scalar > > stepperOSAppAction_
void createSubSteppers(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > > appModels, Teuchos::RCP< Teuchos::ParameterList > pl)
virtual bool isOneStepMethod() const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
Teuchos::RCP< SolutionState< Scalar > > tempState_
virtual void setOrder(Scalar o)
Teuchos::RCP< SolutionHistory< Scalar > > OpSpSolnHistory_
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getModel() const
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
StepperOperatorSplit()
Default constructor.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
virtual void addStepper(Teuchos::RCP< Stepper< Scalar > > stepper, bool useFSAL=false)
Add Stepper to subStepper list. In most cases, subSteppers cannot use xDotOld (thus the default),...
virtual Scalar getOrder() const
Default modifier for StepperOperatorSplit.
StepperState is a simple class to hold state information about the stepper.
@ STORAGE_TYPE_STATIC
Keep a fix number of states.
Teuchos::RCP< SolutionState< Scalar > > createSolutionStateME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, const Teuchos::RCP< StepperState< Scalar > > &stepperState=Teuchos::null, const Teuchos::RCP< PhysicsState< Scalar > > &physicsState=Teuchos::null)
Nonmember constructor from Thyra ModelEvaluator.
Teuchos::RCP< StepperOperatorSplit< Scalar > > createStepperOperatorSplit(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > > appModels, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.