9 #ifndef Tempus_StepperOperatorSplit_impl_hpp
10 #define Tempus_StepperOperatorSplit_impl_hpp
12 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
13 #include "Thyra_VectorStdOps.hpp"
20 template<
class Scalar>
22 : stepperPL_(Teuchos::null), OpSpSolnHistory_(Teuchos::null),
23 stepperOSObserver_(Teuchos::null)
27 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
29 *out <<
"Warning -- Constructing " << this->
description()
30 <<
" without ModelEvaluators!\n"
31 <<
" - Can reset ParameterList with setParameterList().\n"
32 <<
" - Requires subsequent addStepper()/createSubSteppers()\n"
33 <<
" and initialize() calls before calling takeStep().\n"
37 template<
class Scalar>
39 std::vector<Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> > > appModels,
40 Teuchos::RCP<Teuchos::ParameterList> pList)
41 : stepperPL_(Teuchos::null), OpSpSolnHistory_(Teuchos::null),
42 stepperOSObserver_(Teuchos::null)
46 if (appModels.empty()) {
47 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
49 *out <<
"Warning -- Constructing " << this->
description()
50 <<
" without ModelEvaluators!\n"
51 <<
" - Can reset ParameterList with setParameterList().\n"
52 <<
" - Requires subsequent addStepper()/createSubSteppers\n"
53 <<
" and initialize() calls before calling takeStep().\n"
62 template<
class Scalar>
64 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel)
66 if (appModel != Teuchos::null) {
67 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
68 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setModel()");
69 *out <<
"Warning -- No ModelEvaluator to set for StepperOperatorSplit, "
70 <<
"because it is a Stepper of Steppers.\n" << std::endl;
75 template<
class Scalar>
77 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& appModel)
79 if (appModel != Teuchos::null) {
80 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
81 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setModel()");
82 *out <<
"Warning -- No ModelEvaluator to set for StepperOperatorSplit, "
83 <<
"because it is a Stepper of Steppers.\n" << std::endl;
88 template<
class Scalar>
89 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
92 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > model;
93 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
94 subStepperIter = subStepperList_.begin();
95 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
96 model = (*subStepperIter)->getModel();
97 if (model != Teuchos::null)
break;
99 if ( model == Teuchos::null ) {
100 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
101 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::getModel()");
102 *out <<
"Warning -- StepperOperatorSplit::getModel() "
103 <<
"Could not find a valid model! Returning null!" << std::endl;
109 template<
class Scalar>
112 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
113 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setSolver()");
114 *out <<
"Warning -- No solver to set for StepperOperatorSplit, "
115 <<
"because it is a Stepper of Steppers.\n" << std::endl;
119 template<
class Scalar>
121 Teuchos::RCP<Teuchos::ParameterList> )
123 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
124 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setSolver()");
125 *out <<
"Warning -- No solver to set for StepperOperatorSplit "
126 <<
"because it is a Stepper of Steppers.\n" << std::endl;
130 template<
class Scalar>
132 Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > )
134 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
135 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setSolver()");
136 *out <<
"Warning -- No solver to set for StepperOperatorSplit "
137 <<
"because it is a Stepper of Steppers.\n" << std::endl;
141 template<
class Scalar>
145 if (obs == Teuchos::null) {
147 if (stepperOSObserver_ == Teuchos::null) {
157 template<
class Scalar>
159 std::vector<Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> > > appModels)
162 using Teuchos::ParameterList;
165 std::vector<std::string> stepperListStr;
166 stepperListStr.clear();
167 std::string str = stepperPL_->get<std::string>(
"Stepper List");
168 std::string delimiters(
",");
170 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
172 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
173 while ((pos != std::string::npos) || (lastPos != std::string::npos)) {
174 std::string token = str.substr(lastPos,pos-lastPos);
176 std::string::size_type beg = token.find_first_of(
"'") + 1;
177 std::string::size_type end = token.find_last_of (
"'");
178 stepperListStr.push_back(token.substr(beg,end-beg));
180 lastPos = str.find_first_not_of(delimiters, pos);
181 pos = str.find_first_of(delimiters, lastPos);
184 TEUCHOS_TEST_FOR_EXCEPTION(stepperListStr.size() != appModels.size(),
185 std::logic_error,
"Error - Number of models and Steppers do not match!\n"
186 <<
" There are " << appModels.size() <<
" models.\n"
187 <<
" There are " << stepperListStr.size() <<
" steppers.\n"
188 <<
" " << str <<
"\n");
192 std::vector<RCP<const Thyra::ModelEvaluator<Scalar> > >::iterator
193 aMI = appModels.begin();
194 typename std::vector<std::string>::iterator sLSI = stepperListStr.begin();
196 for (; aMI<appModels.end() || sLSI<stepperListStr.end(); aMI++, sLSI++) {
197 RCP<ParameterList> subStepperPL = Teuchos::sublist(stepperPL_,*sLSI,
true);
198 bool useFSAL = subStepperPL->template get<bool>(
"Use FSAL",
false);
199 auto subStepper = sf->createStepper(subStepperPL, *aMI);
201 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
202 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::createSubSteppers()");
203 *out <<
"Warning -- subStepper = "
204 << subStepper->getStepperType() <<
" has \n"
205 <<
" subStepper->getUseFSAL() = " << useFSAL <<
".\n"
206 <<
" subSteppers usually can not use the FSAL priniciple with\n"
207 <<
" operator splitting. Proceeding with it set to true.\n"
210 addStepper(subStepper, useFSAL);
214 template<
class Scalar>
217 TEUCHOS_TEST_FOR_EXCEPTION( subStepperList_.size() == 0, std::logic_error,
218 "Error - Need to set the subSteppers, createSubSteppers(), before calling "
219 "StepperOperatorSplit::initialize()\n");
222 OpSpSolnHistory_->setStorageLimit(2);
225 if (tempState_ == Teuchos::null) {
226 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >model = this->getModel();
227 TEUCHOS_TEST_FOR_EXCEPTION( model == Teuchos::null, std::logic_error,
228 "Error - StepperOperatorSplit::initialize() Could not find "
232 model, this->getDefaultStepperState()));
234 this->setParameterList(this->stepperPL_);
237 if (!isOneStepMethod() ) {
238 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
239 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::initialize()");
240 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
241 subStepperIter = subStepperList_.begin();
242 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
243 *out <<
"SubStepper, " << (*subStepperIter)->description()
244 <<
", isOneStepMethod = " << (*subStepperIter)->isOneStepMethod()
247 TEUCHOS_TEST_FOR_EXCEPTION(!isOneStepMethod(), std::logic_error,
248 "Error - OperatorSplit only works for one-step methods!\n");
252 template<
class Scalar>
256 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
257 subStepperIter = subStepperList_.begin();
258 for (; subStepperIter < subStepperList_.end(); subStepperIter++)
262 template<
class Scalar>
268 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperOperatorSplit::takeStep()");
272 "Error - StepperOperatorSplit<Scalar>::takeStep(...)\n"
273 "Need at least two SolutionStates for OperatorSplit.\n"
275 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
276 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
280 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
284 OpSpSolnHistory_->clear();
285 OpSpSolnHistory_->addState(tempState_);
286 OpSpSolnHistory_->addWorkingState(workingState,
false);
288 RCP<SolutionState<Scalar> > currentSubState =
289 OpSpSolnHistory_->getCurrentState();
290 RCP<SolutionState<Scalar> > workingSubState =
291 OpSpSolnHistory_->getWorkingState();
294 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
295 subStepperIter = subStepperList_.begin();
296 for (; subStepperIter < subStepperList_.end() and pass; subStepperIter++) {
297 int index = subStepperIter - subStepperList_.begin();
299 stepperOSObserver_->observeBeforeStepper(index,
solutionHistory, *
this);
301 (*subStepperIter)->takeStep(OpSpSolnHistory_);
303 stepperOSObserver_->observeAfterStepper(index,
solutionHistory, *
this);
307 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
308 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::takeStep()");
309 *out <<
"SubStepper, " << (*subStepperIter)->description()
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 OpSpSolnHistory_->clear();
335 template<
class Scalar>
339 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
345 template<
class Scalar>
348 std::string name =
"Operator Split";
353 template<
class Scalar>
355 Teuchos::FancyOStream &out,
356 const Teuchos::EVerbosityLevel )
const
358 out << description() <<
"::describe:" << std::endl;
362 template <
class Scalar>
364 const Teuchos::RCP<Teuchos::ParameterList> & pList)
366 Teuchos::RCP<Teuchos::ParameterList> stepperPL = this->stepperPL_;
367 if (pList == Teuchos::null) {
369 if (stepperPL == Teuchos::null) stepperPL = this->getDefaultParameters();
376 std::string stepperType = stepperPL->get<std::string>(
"Stepper Type");
377 TEUCHOS_TEST_FOR_EXCEPTION( stepperType !=
"Operator Split", std::logic_error,
378 "Error - Stepper Type is not 'Operator Split'!\n"
379 <<
" Stepper Type = "<< pList->get<std::string>(
"Stepper Type") <<
"\n");
381 this->stepperPL_ = stepperPL;
385 template<
class Scalar>
386 Teuchos::RCP<const Teuchos::ParameterList>
389 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
390 pl->setName(
"Default Stepper - " + this->description());
391 pl->set<std::string>(
"Stepper Type",
"Operator Split",
392 "'Stepper Type' must be 'Operator Split'.");
393 this->getValidParametersBasic(pl);
394 pl->set<
int> (
"Minimum Order", 1,
395 "Minimum Operator-split order. (default = 1)\n");
396 pl->set<
int> (
"Order", 1,
397 "Operator-split order. (default = 1)\n");
398 pl->set<
int> (
"Maximum Order", 1,
399 "Maximum Operator-split order. (default = 1)\n");
401 pl->set<std::string>(
"Stepper List",
"",
402 "Comma deliminated list of single quoted Steppers, e.g., \"'Operator 1', 'Operator 2'\".");
408 template<
class Scalar>
409 Teuchos::RCP<Teuchos::ParameterList>
413 using Teuchos::ParameterList;
414 using Teuchos::rcp_const_cast;
416 RCP<ParameterList> pl =
417 rcp_const_cast<ParameterList>(this->getValidParameters());
423 template <
class Scalar>
424 Teuchos::RCP<Teuchos::ParameterList>
431 template <
class Scalar>
432 Teuchos::RCP<Teuchos::ParameterList>
435 Teuchos::RCP<Teuchos::ParameterList> temp_plist = stepperPL_;
436 stepperPL_ = Teuchos::null;
442 #endif // Tempus_StepperOperatorSplit_impl_hpp
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
virtual void setSolver(std::string solverName)
Set solver via ParameterList solver name.
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getModel()
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)
Set Observer.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
virtual void setNonConstModel(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &appModel)
virtual void createSubSteppers(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > > appModels)
Take models and ParameterList and create subSteppers.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl)
StepperOperatorSplit()
Default constructor.
StepperState is a simple class to hold state information about the stepper.
StepperOperatorSplitObserver class for StepperOperatorSplit.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
StepperObserver class for Stepper class.
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Teuchos::RCP< Teuchos::ParameterList > getDefaultParameters() const
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
Keep a fix number of states.
virtual std::string description() const
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
virtual void initialize()
Initialize during construction and after changing input parameters.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...