9 #ifndef Tempus_StepperOperatorSplit_impl_hpp 10 #define Tempus_StepperOperatorSplit_impl_hpp 12 #include "Teuchos_VerboseObjectParameterListHelpers.hpp" 13 #include "Thyra_VectorStdOps.hpp" 19 template<
class Scalar>
21 std::vector<Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> > > appModels,
22 Teuchos::RCP<Teuchos::ParameterList> pList)
24 stepperOSObserver_(
Teuchos::null)
31 template<
class Scalar>
34 stepperOSObserver_(
Teuchos::null)
42 template<
class Scalar>
44 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel)
46 if (appModel != Teuchos::null) {
47 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
48 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setModel()");
49 *out <<
"Warning -- No ModelEvaluator to set for StepperOperatorSplit, " 50 <<
"because it is a Stepper of Steppers.\n" << std::endl;
55 template<
class Scalar>
57 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& appModel)
59 if (appModel != Teuchos::null) {
60 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
61 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setModel()");
62 *out <<
"Warning -- No ModelEvaluator to set for StepperOperatorSplit, " 63 <<
"because it is a Stepper of Steppers.\n" << std::endl;
68 template<
class Scalar>
69 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
72 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > model;
73 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
74 subStepperIter = subStepperList_.begin();
75 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
76 model = (*subStepperIter)->getModel();
77 if (model != Teuchos::null)
break;
79 if ( model == Teuchos::null ) {
80 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
81 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::getModel()");
82 *out <<
"Warning -- StepperOperatorSplit::getModel() " 83 <<
"Could not find a valid model! Returning null!" << std::endl;
89 template<
class Scalar>
92 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
93 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setSolver()");
94 *out <<
"Warning -- No solver to set for StepperOperatorSplit, " 95 <<
"because it is a Stepper of Steppers.\n" << std::endl;
99 template<
class Scalar>
101 Teuchos::RCP<Teuchos::ParameterList> solverPL)
103 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
104 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setSolver()");
105 *out <<
"Warning -- No solver to set for StepperOperatorSplit " 106 <<
"because it is a Stepper of Steppers.\n" << std::endl;
110 template<
class Scalar>
112 Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > solver)
114 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
115 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setSolver()");
116 *out <<
"Warning -- No solver to set for StepperOperatorSplit " 117 <<
"because it is a Stepper of Steppers.\n" << std::endl;
121 template<
class Scalar>
125 if (obs == Teuchos::null) {
127 if (stepperOSObserver_ == Teuchos::null) {
137 template<
class Scalar>
139 std::vector<Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> > > appModels)
142 using Teuchos::ParameterList;
145 std::vector<std::string> stepperListStr;
146 stepperListStr.clear();
147 std::string str = stepperPL_->get<std::string>(
"Stepper List");
148 std::string delimiters(
",");
150 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
152 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
153 while ((pos != std::string::npos) || (lastPos != std::string::npos)) {
154 std::string token = str.substr(lastPos,pos-lastPos);
156 std::string::size_type beg = token.find_first_of(
"'") + 1;
157 std::string::size_type end = token.find_last_of (
"'");
158 stepperListStr.push_back(token.substr(beg,end-beg));
160 lastPos = str.find_first_not_of(delimiters, pos);
161 pos = str.find_first_of(delimiters, lastPos);
164 TEUCHOS_TEST_FOR_EXCEPTION(stepperListStr.size() != appModels.size(),
165 std::logic_error,
"Error - Number of models and Steppers do not match!\n" 166 <<
" There are " << appModels.size() <<
" models.\n" 167 <<
" There are " << stepperListStr.size() <<
" steppers.\n" 168 <<
" " << str <<
"\n");
172 std::vector<RCP<const Thyra::ModelEvaluator<Scalar> > >::iterator
173 aMI = appModels.begin();
174 typename std::vector<std::string>::iterator sLSI = stepperListStr.begin();
176 for (; aMI<appModels.end() || sLSI<stepperListStr.end(); aMI++, sLSI++) {
177 RCP<ParameterList> subStepperPL = Teuchos::sublist(stepperPL_,*sLSI,
true);
178 subStepperList_.push_back(sf->createStepper(*aMI, subStepperPL));
182 template<
class Scalar>
185 TEUCHOS_TEST_FOR_EXCEPTION( subStepperList_.size() == 0, std::logic_error,
186 "Error - Need to set the subSteppers, createSubSteppers(), before calling " 187 "StepperOperatorSplit::initialize()\n");
190 OpSpSolnHistory_->setStorageLimit(2);
193 if (tempState_ == Teuchos::null) {
194 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >model = this->getModel();
195 TEUCHOS_TEST_FOR_EXCEPTION( model == Teuchos::null, std::logic_error,
196 "Error - StepperOperatorSplit::initialize() Could not find " 199 model, this->getDefaultStepperState()));
201 this->setParameterList(this->stepperPL_);
204 if (!isOneStepMethod() ) {
205 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
206 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::initialize()");
207 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
208 subStepperIter = subStepperList_.begin();
209 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
210 *out <<
"SubStepper, " << (*subStepperIter)->description()
211 <<
", isOneStepMethod = " << (*subStepperIter)->isOneStepMethod()
214 TEUCHOS_TEST_FOR_EXCEPTION(!isOneStepMethod(), std::logic_error,
215 "Error - OperatorSplit only works for one-step methods!\n");
219 template<
class Scalar>
225 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperOperatorSplit::takeStep()");
229 "Error - StepperOperatorSplit<Scalar>::takeStep(...)\n" 230 "Need at least two SolutionStates for OperatorSplit.\n" 232 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n" 233 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
237 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
241 OpSpSolnHistory_->clear();
242 OpSpSolnHistory_->addState(tempState_);
243 OpSpSolnHistory_->addWorkingState(workingState,
false);
245 RCP<SolutionState<Scalar> > currentSubState =
246 OpSpSolnHistory_->getCurrentState();
247 RCP<SolutionState<Scalar> > workingSubState =
248 OpSpSolnHistory_->getWorkingState();
251 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
252 subStepperIter = subStepperList_.begin();
253 for (; subStepperIter < subStepperList_.end() and pass; subStepperIter++) {
254 int index = subStepperIter - subStepperList_.begin();
256 stepperOSObserver_->observeBeforeStepper(index,
solutionHistory, *
this);
258 (*subStepperIter)->takeStep(OpSpSolnHistory_);
260 stepperOSObserver_->observeAfterStepper(index,
solutionHistory, *
this);
264 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
265 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::takeStep()");
266 *out <<
"SubStepper, " << (*subStepperIter)->description()
267 <<
", failed!" << std::endl;
272 currentSubState = OpSpSolnHistory_->getCurrentState();
273 currentSubState->copySolutionData(workingSubState);
276 if (pass ==
true) workingState->setSolutionStatus(
Status::PASSED);
278 workingState->setOrder(this->getOrder());
279 OpSpSolnHistory_->clear();
292 template<
class Scalar>
296 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
302 template<
class Scalar>
305 std::string name =
"Operator Split";
310 template<
class Scalar>
312 Teuchos::FancyOStream &out,
313 const Teuchos::EVerbosityLevel verbLevel)
const 315 out << description() <<
"::describe:" << std::endl;
319 template <
class Scalar>
321 const Teuchos::RCP<Teuchos::ParameterList> & pList)
323 Teuchos::RCP<Teuchos::ParameterList> stepperPL = this->stepperPL_;
324 if (pList == Teuchos::null) {
326 if (stepperPL == Teuchos::null) stepperPL = this->getDefaultParameters();
333 std::string stepperType = stepperPL->get<std::string>(
"Stepper Type");
334 TEUCHOS_TEST_FOR_EXCEPTION( stepperType !=
"Operator Split", std::logic_error,
335 "Error - Stepper Type is not 'Operator Split'!\n" 336 <<
" Stepper Type = "<< pList->get<std::string>(
"Stepper Type") <<
"\n");
338 this->stepperPL_ = stepperPL;
342 template<
class Scalar>
343 Teuchos::RCP<const Teuchos::ParameterList>
346 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
347 pl->setName(
"Default Stepper - " + this->description());
348 pl->set<std::string>(
"Stepper Type",
"Operator Split",
349 "'Stepper Type' must be 'Operator Split'.");
350 pl->set<
int> (
"Minimum Order", 1,
351 "Minimum Operator-split order. (default = 1)\n");
352 pl->set<
int> (
"Order", 1,
353 "Operator-split order. (default = 1)\n");
354 pl->set<
int> (
"Maximum Order", 1,
355 "Maximum Operator-split order. (default = 1)\n");
357 pl->set<std::string>(
"Stepper List",
"",
358 "Comma deliminated list of single quoted Steppers, e.g., \"'Operator 1', 'Operator 2'\".");
364 template<
class Scalar>
365 Teuchos::RCP<Teuchos::ParameterList>
368 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
369 *pl = *(this->getValidParameters());
374 template <
class Scalar>
375 Teuchos::RCP<Teuchos::ParameterList>
382 template <
class Scalar>
383 Teuchos::RCP<Teuchos::ParameterList>
386 Teuchos::RCP<Teuchos::ParameterList> temp_plist = stepperPL_;
387 stepperPL_ = Teuchos::null;
393 #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 void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getModel()
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)
Set Observer.
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()
Constructor which is setup except for models and steppers (i.e., addStepper()), and an initialize() b...
StepperState is a simple class to hold state information about the stepper.
StepperOperatorSplitObserver class for StepperOperatorSplit.
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
Keep a fix number of states.
virtual std::string description() const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() 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...