10 #ifndef Tempus_StepperOperatorSplit_impl_hpp
11 #define Tempus_StepperOperatorSplit_impl_hpp
13 #include "Tempus_StepperFactory.hpp"
18 template <
class Scalar>
21 this->setStepperName(
"Operator Split");
22 this->setStepperType(
"Operator Split");
23 this->setUseFSAL(
false);
24 this->setICConsistency(
"None");
25 this->setICConsistencyCheck(
false);
30 this->setAppAction(Teuchos::null);
33 OpSpSolnHistory_->setStorageLimit(2);
37 template <
class Scalar>
41 std::string ICConsistency,
bool ICConsistencyCheck,
int order,
int orderMin,
46 this->setStepperName(
"Operator Split");
47 this->setStepperType(
"Operator Split");
48 this->setUseFSAL(useFSAL);
49 this->setICConsistency(ICConsistency);
50 this->setICConsistencyCheck(ICConsistencyCheck);
52 this->setSubStepperList(subStepperList);
53 this->setOrder(order);
54 this->setOrderMin(orderMin);
55 this->setOrderMax(orderMax);
57 this->setAppAction(stepperOSAppAction);
59 OpSpSolnHistory_->setStorageLimit(2);
62 if (!(appModels.empty())) {
63 this->setModels(appModels);
68 template <
class Scalar>
72 if (appModel != Teuchos::null) {
75 *out <<
"Warning -- No ModelEvaluator to set for StepperOperatorSplit, "
76 <<
"because it is a Stepper of Steppers.\n"
81 template <
class Scalar>
86 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
87 subStepperIter = subStepperList_.begin();
88 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
89 model = (*subStepperIter)->getModel();
90 if (model != Teuchos::null)
break;
92 if (model == Teuchos::null) {
95 *out <<
"Warning -- StepperOperatorSplit::getModel() "
96 <<
"Could not find a valid model! Returning null!" << std::endl;
102 template <
class Scalar>
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"
112 this->isInitialized_ =
false;
115 template <
class Scalar>
119 if (appAction == Teuchos::null) {
121 if (stepperOSAppAction_ == Teuchos::null) {
122 stepperOSAppAction_ =
127 stepperOSAppAction_ =
131 this->isInitialized_ =
false;
134 template <
class Scalar>
138 stepper->setUseFSAL(useFSAL);
139 subStepperList_.push_back(stepper);
142 template <
class Scalar>
149 subStepperList_ = subStepperList;
151 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
152 subStepperIter = subStepperList_.begin();
154 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
155 auto subStepper = *(subStepperIter);
156 bool useFSAL = subStepper->getUseFSAL();
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"
169 this->isInitialized_ =
false;
172 template <
class Scalar>
180 subStepperList_.size() != appModels.size(), std::logic_error,
181 "Error - Number of models and Steppers do not match!\n"
182 <<
" There are " << appModels.size() <<
" models.\n"
183 <<
" There are " << subStepperList_.size() <<
" steppers.\n");
185 typename std::vector<RCP<const Thyra::ModelEvaluator<Scalar> > >::iterator
186 appModelIter = appModels.begin();
188 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
189 subStepperIter = subStepperList_.begin();
192 appModelIter < appModels.end() || subStepperIter < subStepperList_.end();
193 appModelIter++, subStepperIter++) {
194 auto appModel = *(appModelIter);
195 auto subStepper = *(subStepperIter);
196 subStepper->setModel(appModel);
199 this->isInitialized_ =
false;
202 template <
class Scalar>
205 if (tempState_ == Teuchos::null) {
208 model == Teuchos::null, std::logic_error,
209 "Error - StepperOperatorSplit::initialize() Could not find "
214 if (!isOneStepMethod()) {
216 Teuchos::OSTab ostab(out, 1,
"StepperOperatorSplit::initialize()");
217 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
218 subStepperIter = subStepperList_.begin();
219 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
220 *out <<
"SubStepper, " << (*subStepperIter)->getStepperType()
221 <<
", isOneStepMethod = " << (*subStepperIter)->isOneStepMethod()
225 !isOneStepMethod(), std::logic_error,
226 "Error - OperatorSplit only works for one-step methods!\n");
230 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
231 subStepperIter = subStepperList_.begin();
232 for (; subStepperIter < subStepperList_.end(); subStepperIter++)
233 (*subStepperIter)->initialize();
238 template <
class Scalar>
242 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
243 subStepperIter = subStepperList_.begin();
244 for (; subStepperIter < subStepperList_.end(); subStepperIter++)
245 (*subStepperIter)->setInitialConditions(solutionHistory);
248 solutionHistory->getCurrentState();
251 this->setStepperXDot(initialState->getXDot());
252 if (initialState->getXDot() == Teuchos::null)
253 this->setStepperXDot(initialState->getX()->clone_v());
256 template <
class Scalar>
260 this->checkInitialized();
264 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperOperatorSplit::takeStep()");
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);
276 stepperOSAppAction_->execute(
277 solutionHistory, thisStepper,
280 RCP<SolutionState<Scalar> > workingState =
281 solutionHistory->getWorkingState();
284 tempState_->copy(solutionHistory->getCurrentState());
285 OpSpSolnHistory_->clear();
286 OpSpSolnHistory_->addState(tempState_);
287 OpSpSolnHistory_->addWorkingState(workingState,
false);
289 RCP<SolutionState<Scalar> > currentSubState =
290 OpSpSolnHistory_->getCurrentState();
291 RCP<SolutionState<Scalar> > workingSubState =
292 OpSpSolnHistory_->getWorkingState();
295 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
296 subStepperIter = subStepperList_.begin();
297 for (; subStepperIter < subStepperList_.end() && pass; subStepperIter++) {
298 stepperOSAppAction_->execute(
299 solutionHistory, thisStepper,
301 Scalar>::ACTION_LOCATION::BEFORE_STEPPER);
303 (*subStepperIter)->takeStep(OpSpSolnHistory_);
305 stepperOSAppAction_->execute(solutionHistory, thisStepper,
307 Scalar>::ACTION_LOCATION::AFTER_STEPPER);
313 *out <<
"SubStepper, " << (*subStepperIter)->getStepperType()
314 <<
", failed!" << std::endl;
319 currentSubState = OpSpSolnHistory_->getCurrentState();
320 currentSubState->copySolutionData(workingSubState);
327 workingState->setOrder(this->getOrder());
328 workingState->computeNorms(solutionHistory->getCurrentState());
329 OpSpSolnHistory_->clear();
331 stepperOSAppAction_->execute(
332 solutionHistory, thisStepper,
344 template <
class Scalar>
353 template <
class Scalar>
361 out <<
"--- StepperOperatorSplit ---\n";
362 out <<
" subStepperList_.size() = " << subStepperList_.size() << std::endl;
363 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
364 subStepperIter = subStepperList_.begin();
365 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
366 out <<
" SubStepper = " << (*subStepperIter)->getStepperType()
368 out <<
" = " << (*subStepperIter)->isInitialized()
370 out <<
" = " << (*subStepperIter) << std::endl;
372 out <<
" OpSpSolnHistory_ = " << OpSpSolnHistory_ << std::endl;
373 out <<
" tempState_ = " << tempState_ << std::endl;
374 out <<
" stepperOSAppAction_ = " << stepperOSAppAction_ << std::endl;
375 out <<
" order_ = " << order_ << std::endl;
376 out <<
" orderMin_ = " << orderMin_ << std::endl;
377 out <<
" orderMax_ = " << orderMax_ << std::endl;
378 out <<
"----------------------------" << std::endl;
381 template <
class Scalar>
386 bool isValidSetup =
true;
390 if (subStepperList_.size() == 0) {
391 isValidSetup =
false;
392 out <<
"The substepper list is empty!\n";
395 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
396 subStepperIter = subStepperList_.begin();
398 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
399 auto subStepper = *(subStepperIter);
400 if (!subStepper->isInitialized()) {
401 isValidSetup =
false;
402 out <<
"The subStepper, " << subStepper->description()
403 <<
", is not initialized!\n";
406 if (stepperOSAppAction_ == Teuchos::null) {
407 isValidSetup =
false;
408 out <<
"The Operator-Split AppAction is not set!\n";
414 template <
class Scalar>
418 auto pl = this->getValidParametersBasic();
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;
427 size_t size = subStepperList_.size();
428 for (std::size_t i = 0; i < size - 1; ++i) {
429 list <<
"'" << subStepperList_[i]->getStepperName() <<
"', ";
431 list <<
"'" << subStepperList_[size - 1]->getStepperName() <<
"'";
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) {
438 pl->set(subStepperList_[i]->getStepperName(),
439 *(subStepperList_[i]->getValidParameters()));
445 template <
class Scalar>
450 if (stepperPL != Teuchos::null) {
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);
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);
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"
507 this->addStepper(subStepper, useFSAL);
514 template <
class Scalar>
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();
537 #endif // Tempus_StepperOperatorSplit_impl_hpp
virtual void setAppAction(Teuchos::RCP< StepperOperatorSplitAppAction< Scalar >> appAction)
T & get(const std::string &name, T def_value)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void setSubStepperList(std::vector< Teuchos::RCP< Stepper< Scalar >>> subStepperList)
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
virtual void initialize()
Initialize after construction and changing input parameters.
OperatorSplit stepper loops through the Stepper list.
Thyra Base interface for time steppers.
virtual void setModels(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar >>> appModels)
StepperOperatorSplit()
Default constructor.
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 void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
static RCP< FancyOStream > getDefaultOStream()
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar >> &solutionHistory)
Set the initial conditions and make them consistent.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
void createSubSteppers(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar >>> appModels, Teuchos::RCP< Teuchos::ParameterList > pl)
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getModel() const
Default modifier for StepperOperatorSplit.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
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.
Keep a fix number of states.
Teuchos::RCP< StepperOperatorSplit< Scalar > > createStepperOperatorSplit(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar >>> appModels, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar >> &solutionHistory)
Take the specified timestep, dt, and return true if successful.
StepperOperatorSplitAppAction class for StepperOperatorSplit.
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar >> solver)
virtual void initialize()
Initialize during construction and after changing input parameters.
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 void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar >> &appModel)