42 std::vector<Teuchos::RCP<Stepper<Scalar> > > subStepperList,
44 std::string ICConsistency,
45 bool ICConsistencyCheck,
49 const Teuchos::RCP<StepperOperatorSplitAppAction<Scalar> >& stepperOSAppAction)
51 this->setStepperName(
"Operator Split");
52 this->setStepperType(
"Operator Split");
53 this->setUseFSAL( useFSAL);
54 this->setICConsistency( ICConsistency);
55 this->setICConsistencyCheck( ICConsistencyCheck);
57 this->setSubStepperList(subStepperList);
58 this->setOrder (order);
59 this->setOrderMin(orderMin);
60 this->setOrderMax(orderMax);
62 this->setAppAction(stepperOSAppAction);
63 OpSpSolnHistory_ = rcp(
new SolutionHistory<Scalar>());
64 OpSpSolnHistory_->setStorageLimit(2);
67 if ( !(appModels.empty()) ) {
68 this->setModels(appModels);
90 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > model;
91 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
92 subStepperIter = subStepperList_.begin();
93 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
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;
121 Teuchos::RCP<StepperOperatorSplitAppAction<Scalar> > appAction)
123 if (appAction == Teuchos::null) {
125 if (stepperOSAppAction_ == Teuchos::null) {
126 stepperOSAppAction_ =
127 Teuchos::rcp(
new StepperOperatorSplitModifierDefault<Scalar>());
130 stepperOSAppAction_ =
131 Teuchos::rcp_dynamic_cast<StepperOperatorSplitAppAction<Scalar> > (appAction,
true);
133 this->isInitialized_ =
false;
148 std::vector<Teuchos::RCP<Stepper<Scalar> > > subStepperList)
151 using Teuchos::ParameterList;
153 subStepperList_ = subStepperList;
155 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
156 subStepperIter = subStepperList_.begin();
158 for (; subStepperIter<subStepperList_.end(); subStepperIter++) {
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"
173 this->isInitialized_ =
false;
181 using Teuchos::ParameterList;
183 TEUCHOS_TEST_FOR_EXCEPTION(subStepperList_.size() != appModels.size(),
184 std::logic_error,
"Error - Number of models and Steppers do not match!\n"
185 <<
" There are " << appModels.size() <<
" models.\n"
186 <<
" There are " << subStepperList_.size() <<
" steppers.\n");
188 typename std::vector<RCP<const Thyra::ModelEvaluator<Scalar> > >::iterator
189 appModelIter = appModels.begin();
191 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
192 subStepperIter = subStepperList_.begin();
194 for (; appModelIter<appModels.end() || subStepperIter<subStepperList_.end();
195 appModelIter++, subStepperIter++)
197 auto appModel = *(appModelIter);
198 auto subStepper = *(subStepperIter);
199 subStepper->setModel(appModel);
202 this->isInitialized_ =
false;
208 if (tempState_ == Teuchos::null) {
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 "
216 if (!isOneStepMethod() ) {
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
220 subStepperIter = subStepperList_.begin();
221 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
222 *out <<
"SubStepper, " << (*subStepperIter)->getStepperType()
223 <<
", isOneStepMethod = " << (*subStepperIter)->isOneStepMethod()
226 TEUCHOS_TEST_FOR_EXCEPTION(!isOneStepMethod(), std::logic_error,
227 "Error - OperatorSplit only works for one-step methods!\n");
231 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
232 subStepperIter = subStepperList_.begin();
233 for (; subStepperIter < subStepperList_.end(); subStepperIter++)
234 (*subStepperIter)->initialize();
241 const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory)
243 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
244 subStepperIter = subStepperList_.begin();
245 for (; subStepperIter < subStepperList_.end(); subStepperIter++)
246 (*subStepperIter)->setInitialConditions(solutionHistory);
248 Teuchos::RCP<SolutionState<Scalar> > initialState =
249 solutionHistory->getCurrentState();
252 this->setStepperXDot(initialState->getXDot());
253 if (initialState->getXDot() == Teuchos::null)
254 this->setStepperXDot(initialState->getX()->clone_v());
260 const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory)
262 this->checkInitialized();
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);
276 stepperOSAppAction_->execute(solutionHistory, thisStepper,
279 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
282 tempState_->copy(solutionHistory->getCurrentState());
283 OpSpSolnHistory_->clear();
284 OpSpSolnHistory_->addState(tempState_);
285 OpSpSolnHistory_->addWorkingState(workingState,
false);
287 RCP<SolutionState<Scalar> > currentSubState =
288 OpSpSolnHistory_->getCurrentState();
289 RCP<SolutionState<Scalar> > workingSubState =
290 OpSpSolnHistory_->getWorkingState();
293 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
294 subStepperIter = subStepperList_.begin();
295 for (; subStepperIter < subStepperList_.end() && pass; subStepperIter++) {
297 stepperOSAppAction_->execute(solutionHistory, thisStepper,
300 (*subStepperIter)->takeStep(OpSpSolnHistory_);
302 stepperOSAppAction_->execute(solutionHistory, thisStepper,
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;
315 currentSubState = OpSpSolnHistory_->getCurrentState();
316 currentSubState->copySolutionData(workingSubState);
319 if (pass ==
true) workingState->setSolutionStatus(
Status::PASSED);
321 workingState->setOrder(this->getOrder());
322 workingState->computeNorms(solutionHistory->getCurrentState());
323 OpSpSolnHistory_->clear();
325 stepperOSAppAction_->execute(solutionHistory, thisStepper,
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
360 subStepperIter = subStepperList_.begin();
361 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
362 out <<
" SubStepper = " << (*subStepperIter)->getStepperType()<<std::endl;
363 out <<
" = " << (*subStepperIter)->isInitialized() << std::endl;
364 out <<
" = " << (*subStepperIter) << std::endl;
366 out <<
" OpSpSolnHistory_ = " << OpSpSolnHistory_ << std::endl;
367 out <<
" tempState_ = " << tempState_ << std::endl;
368 out <<
" stepperOSAppAction_ = " << stepperOSAppAction_ << std::endl;
369 out <<
" order_ = " << order_ << std::endl;
370 out <<
" orderMin_ = " << orderMin_ << std::endl;
371 out <<
" orderMax_ = " << orderMax_ << std::endl;
372 out <<
"----------------------------" << std::endl;
379 out.setOutputToRootOnly(0);
380 bool isValidSetup =
true;
384 if (subStepperList_.size() == 0) {
385 isValidSetup =
false;
386 out <<
"The substepper list is empty!\n";
389 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
390 subStepperIter = subStepperList_.begin();
392 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
393 auto subStepper = *(subStepperIter);
394 if ( !subStepper->isInitialized() ) {
395 isValidSetup =
false;
396 out <<
"The subStepper, " << subStepper->description()
397 <<
", is not initialized!\n";
400 if (stepperOSAppAction_ == Teuchos::null) {
401 isValidSetup =
false;
402 out <<
"The Operator-Split AppAction is not set!\n";
413 auto pl = this->getValidParametersBasic();
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;
422 size_t size = subStepperList_.size();
423 for(std::size_t i = 0; i < size-1; ++i) {
424 list <<
"'" << subStepperList_[i]->getStepperName() <<
"', ";
426 list <<
"'" << subStepperList_[size-1]->getStepperName() <<
"'";
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) {
431 pl->set(subStepperList_[i]->getStepperName(), *(subStepperList_[i]->getValidParameters()));
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);
485 auto sf = Teuchos::rcp(
new StepperFactory<Scalar>());
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"
498 this->addStepper(subStepper, useFSAL);
510 Teuchos::RCP<Teuchos::ParameterList> pl)
512 auto stepper = Teuchos::rcp(
new StepperOperatorSplit<Scalar>());
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();
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.