9#ifndef Tempus_StepperOperatorSplit_impl_hpp
10#define Tempus_StepperOperatorSplit_impl_hpp
12#include "Tempus_StepperFactory.hpp"
44 std::string ICConsistency,
45 bool ICConsistencyCheck,
67 if ( !(appModels.empty()) ) {
78 if (appModel != Teuchos::null) {
79 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
80 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setModel()");
81 *out <<
"Warning -- No ModelEvaluator to set for StepperOperatorSplit, "
82 <<
"because it is a Stepper of Steppers.\n" << std::endl;
87Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
90 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > model;
91 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
94 model = (*subStepperIter)->getModel();
95 if (model != Teuchos::null)
break;
97 if ( model == Teuchos::null ) {
98 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
99 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::getModel()");
100 *out <<
"Warning -- StepperOperatorSplit::getModel() "
101 <<
"Could not find a valid model! Returning null!" << std::endl;
107template<
class Scalar>
109 Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > )
111 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
112 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setSolver()");
113 *out <<
"Warning -- No solver to set for StepperOperatorSplit "
114 <<
"because it is a Stepper of Steppers.\n" << std::endl;
119template<
class Scalar>
123 if (appAction == Teuchos::null) {
131 Teuchos::rcp_dynamic_cast<StepperOperatorSplitAppAction<Scalar> > (appAction,
true);
137template<
class Scalar>
141 stepper->setUseFSAL(useFSAL);
146template<
class Scalar>
151 using Teuchos::ParameterList;
155 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
159 auto subStepper = *(subStepperIter);
160 bool useFSAL = subStepper->getUseFSAL();
162 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
163 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setSubStepperList()");
164 *out <<
"Warning -- subStepper = '"
165 << subStepper->getStepperType() <<
"' has \n"
166 <<
" subStepper->getUseFSAL() = " << useFSAL <<
".\n"
167 <<
" subSteppers usually can not use the FSAL priniciple with\n"
168 <<
" operator splitting. Proceeding with it set to true.\n"
176template<
class Scalar>
181 using Teuchos::ParameterList;
184 std::logic_error,
"Error - Number of models and Steppers do not match!\n"
185 <<
" There are " << appModels.size() <<
" models.\n"
188 typename std::vector<RCP<const Thyra::ModelEvaluator<Scalar> > >::iterator
189 appModelIter = appModels.begin();
191 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
194 for (; appModelIter<appModels.end() || subStepperIter<
subStepperList_.end();
195 appModelIter++, subStepperIter++)
197 auto appModel = *(appModelIter);
198 auto subStepper = *(subStepperIter);
199 subStepper->setModel(appModel);
205template<
class Scalar>
209 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >model = this->
getModel();
210 TEUCHOS_TEST_FOR_EXCEPTION( model == Teuchos::null, std::logic_error,
211 "Error - StepperOperatorSplit::initialize() Could not find "
217 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
218 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::initialize()");
219 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
222 *out <<
"SubStepper, " << (*subStepperIter)->getStepperType()
223 <<
", isOneStepMethod = " << (*subStepperIter)->isOneStepMethod()
227 "Error - OperatorSplit only works for one-step methods!\n");
231 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
234 (*subStepperIter)->initialize();
239template<
class Scalar>
243 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
246 (*subStepperIter)->setInitialConditions(solutionHistory);
248 Teuchos::RCP<SolutionState<Scalar> > initialState =
249 solutionHistory->getCurrentState();
253 if (initialState->getXDot() == Teuchos::null)
258template<
class Scalar>
266 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperOperatorSplit::takeStep()");
268 TEUCHOS_TEST_FOR_EXCEPTION(solutionHistory->getNumStates() < 2,
270 "Error - StepperOperatorSplit<Scalar>::takeStep(...)\n"
271 "Need at least two SolutionStates for OperatorSplit.\n"
272 " Number of States = " << solutionHistory->getNumStates() <<
"\n"
273 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
274 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
275 RCP<StepperOperatorSplit<Scalar> > thisStepper = Teuchos::rcpFromRef(*
this);
279 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
282 tempState_->copy(solutionHistory->getCurrentState());
287 RCP<SolutionState<Scalar> > currentSubState =
289 RCP<SolutionState<Scalar> > workingSubState =
293 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
295 for (; subStepperIter <
subStepperList_.end() && pass; subStepperIter++) {
307 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
308 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::takeStep()");
309 *out <<
"SubStepper, " << (*subStepperIter)->getStepperType()
310 <<
", failed!" << std::endl;
316 currentSubState->copySolutionData(workingSubState);
319 if (pass ==
true) workingState->setSolutionStatus(
Status::PASSED);
321 workingState->setOrder(this->
getOrder());
322 workingState->computeNorms(solutionHistory->getCurrentState());
338template<
class Scalar>
342 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
348template<
class Scalar>
350 Teuchos::FancyOStream &out,
351 const Teuchos::EVerbosityLevel verbLevel)
const
353 out.setOutputToRootOnly(0);
357 out <<
"--- StepperOperatorSplit ---\n";
358 out <<
" subStepperList_.size() = " <<
subStepperList_.size() << std::endl;
359 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
362 out <<
" SubStepper = " << (*subStepperIter)->getStepperType()<<std::endl;
363 out <<
" = " << (*subStepperIter)->isInitialized() << std::endl;
364 out <<
" = " << (*subStepperIter) << std::endl;
367 out <<
" tempState_ = " <<
tempState_ << std::endl;
369 out <<
" order_ = " <<
order_ << std::endl;
370 out <<
" orderMin_ = " <<
orderMin_ << std::endl;
371 out <<
" orderMax_ = " <<
orderMax_ << std::endl;
372 out <<
"----------------------------" << std::endl;
376template<
class Scalar>
379 out.setOutputToRootOnly(0);
386 out <<
"The substepper list is empty!\n";
389 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
393 auto subStepper = *(subStepperIter);
394 if ( !subStepper->isInitialized() ) {
396 out <<
"The subStepper, " << subStepper->description()
397 <<
", is not initialized!\n";
402 out <<
"The Operator-Split AppAction is not set!\n";
409template<
class Scalar>
410Teuchos::RCP<const Teuchos::ParameterList>
414 pl->template set<int>(
"Minimum Order",
orderMin_,
415 "Minimum Operator-split order. (default = 1)\n");
416 pl->template set<int>(
"Order",
order_,
417 "Operator-split order. (default = 1)\n");
418 pl->template set<int>(
"Maximum Order",
orderMax_,
419 "Maximum Operator-split order. (default = 1)\n");
421 std::ostringstream list;
423 for(std::size_t i = 0; i < size-1; ++i) {
427 pl->template set<std::string>(
"Stepper List", list.str(),
428 "Comma deliminated list of single quoted Steppers, e.g., \"'Operator 1', 'Operator 2'\".");
430 for(std::size_t i = 0; i < size; ++i) {
438template<
class Scalar>
441 Teuchos::RCP<Teuchos::ParameterList> stepperPL)
443 if (stepperPL != Teuchos::null) {
445 using Teuchos::ParameterList;
448 std::vector<std::string> stepperListStr;
449 stepperListStr.clear();
450 std::string str = stepperPL->get<std::string>(
"Stepper List");
451 std::string delimiters(
",");
453 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
455 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
456 while ((pos != std::string::npos) || (lastPos != std::string::npos)) {
457 std::string token = str.substr(lastPos,pos-lastPos);
459 std::string::size_type beg = token.find_first_of(
"'") + 1;
460 std::string::size_type end = token.find_last_of (
"'");
461 stepperListStr.push_back(token.substr(beg,end-beg));
463 lastPos = str.find_first_not_of(delimiters, pos);
464 pos = str.find_first_of(delimiters, lastPos);
467 TEUCHOS_TEST_FOR_EXCEPTION(stepperListStr.size() != appModels.size(),
468 std::logic_error,
"Error - Number of models and Steppers do not match!\n"
469 <<
" There are " << appModels.size() <<
" models.\n"
470 <<
" There are " << stepperListStr.size() <<
" steppers.\n"
471 <<
" " << str <<
"\n");
474 std::vector<RCP<const Thyra::ModelEvaluator<Scalar> > >::iterator
475 aMI = appModels.begin();
476 typename std::vector<std::string>::iterator sLSI = stepperListStr.begin();
478 for (; aMI<appModels.end() || sLSI<stepperListStr.end(); aMI++, sLSI++) {
479 RCP<ParameterList> subStepperPL = Teuchos::sublist(stepperPL,*sLSI,
true);
480 auto name = subStepperPL->name();
481 lastPos = name.rfind(
"->");
482 std::string newName = name.substr(lastPos+2,name.length());
483 subStepperPL->setName(newName);
484 bool useFSAL = subStepperPL->template get<bool>(
"Use FSAL",
false);
486 auto subStepper = sf->createStepper(subStepperPL, *aMI);
488 Teuchos::RCP<Teuchos::FancyOStream> out =
489 Teuchos::VerboseObjectBase::getDefaultOStream();
490 Teuchos::OSTab ostab(out,1,
"StepperFactory::createSubSteppers()");
491 *out <<
"Warning -- subStepper = '"
492 << subStepper->getStepperType() <<
"' has \n"
493 <<
" subStepper->getUseFSAL() = " << useFSAL <<
".\n"
494 <<
" subSteppers usually can not use the FSAL priniciple with\n"
495 <<
" operator splitting. Proceeding with it set to true.\n"
506template<
class Scalar>
507Teuchos::RCP<StepperOperatorSplit<Scalar> >
510 Teuchos::RCP<Teuchos::ParameterList> pl)
514 if (pl != Teuchos::null) {
515 stepper->setStepperValues(pl);
516 stepper->setOrderMin(pl->get<
int>(
"Minimum Order", 1));
517 stepper->setOrder (pl->get<
int>(
"Order", 1));
518 stepper->setOrderMax(pl->get<
int>(
"Maximum Order", 1));
521 if ( !(appModels.empty()) ) {
522 stepper->createSubSteppers(appModels, pl);
523 stepper->initialize();
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
StepperOperatorSplitAppAction class for StepperOperatorSplit.
@ AFTER_STEPPER
After a stepper evaluation.
@ BEFORE_STEPPER
Before a stepper evaluation.
@ BEGIN_STEP
At the beginning of the step.
@ END_STEP
At the end of the step.
Default modifier for StepperOperatorSplit.
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
StepperState is a simple class to hold state information about the stepper.
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
@ 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.