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 : OpSpSolnHistory_(Teuchos::null)
36 template<
class Scalar>
38 std::vector<Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> > > appModels,
42 std::string ICConsistency,
43 bool ICConsistencyCheck,
47 : OpSpSolnHistory_(Teuchos::null)
61 if ( !(appModels.empty()) ) {
67 template<
class Scalar>
69 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel)
71 if (appModel != Teuchos::null) {
72 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
73 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setModel()");
74 *out <<
"Warning -- No ModelEvaluator to set for StepperOperatorSplit, "
75 <<
"because it is a Stepper of Steppers.\n" << std::endl;
80 template<
class Scalar>
82 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& appModel)
84 if (appModel != Teuchos::null) {
85 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
86 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setModel()");
87 *out <<
"Warning -- No ModelEvaluator to set for StepperOperatorSplit, "
88 <<
"because it is a Stepper of Steppers.\n" << std::endl;
93 template<
class Scalar>
94 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
97 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > model;
98 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
99 subStepperIter = subStepperList_.begin();
100 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
101 model = (*subStepperIter)->getModel();
102 if (model != Teuchos::null)
break;
104 if ( model == Teuchos::null ) {
105 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
106 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::getModel()");
107 *out <<
"Warning -- StepperOperatorSplit::getModel() "
108 <<
"Could not find a valid model! Returning null!" << std::endl;
114 template<
class Scalar>
116 Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > )
118 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
119 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::setSolver()");
120 *out <<
"Warning -- No solver to set for StepperOperatorSplit "
121 <<
"because it is a Stepper of Steppers.\n" << std::endl;
125 template<
class Scalar>
129 if (obs == Teuchos::null) {
131 if (stepperOSObserver_ == Teuchos::null) {
141 template<
class Scalar>
146 using Teuchos::ParameterList;
148 subStepperList_ = subStepperList;
150 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
151 subStepperIter = subStepperList_.begin();
153 for (; subStepperIter<subStepperList_.end(); subStepperIter++) {
154 auto subStepper = *(subStepperIter);
155 bool useFSAL = subStepper->getUseFSAL();
157 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
158 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::createSubSteppers()");
159 *out <<
"Warning -- subStepper = '"
160 << subStepper->getStepperType() <<
"' has \n"
161 <<
" subStepper->getUseFSAL() = " << useFSAL <<
".\n"
162 <<
" subSteppers usually can not use the FSAL priniciple with\n"
163 <<
" operator splitting. Proceeding with it set to true.\n"
169 template<
class Scalar>
171 std::vector<Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> > > appModels)
174 using Teuchos::ParameterList;
176 TEUCHOS_TEST_FOR_EXCEPTION(subStepperList_.size() != appModels.size(),
177 std::logic_error,
"Error - Number of models and Steppers do not match!\n"
178 <<
" There are " << appModels.size() <<
" models.\n"
179 <<
" There are " << subStepperList_.size() <<
" steppers.\n");
181 typename std::vector<RCP<const Thyra::ModelEvaluator<Scalar> > >::iterator
182 appModelIter = appModels.begin();
184 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
185 subStepperIter = subStepperList_.begin();
187 for (; appModelIter<appModels.end() || subStepperIter<subStepperList_.end();
188 appModelIter++, subStepperIter++)
190 auto appModel = *(appModelIter);
191 auto subStepper = *(subStepperIter);
192 subStepper->setModel(appModel);
193 subStepper->initialize();
197 template<
class Scalar>
200 TEUCHOS_TEST_FOR_EXCEPTION( subStepperList_.size() == 0, std::logic_error,
201 "Error - Need to set the subSteppers, createSubSteppers(), before calling "
202 "StepperOperatorSplit::initialize()\n");
205 OpSpSolnHistory_->setStorageLimit(2);
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 "
215 model, this->getDefaultStepperState()));
218 if (!isOneStepMethod() ) {
219 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
220 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::initialize()");
221 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
222 subStepperIter = subStepperList_.begin();
223 for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
224 *out <<
"SubStepper, " << (*subStepperIter)->getStepperType()
225 <<
", isOneStepMethod = " << (*subStepperIter)->isOneStepMethod()
228 TEUCHOS_TEST_FOR_EXCEPTION(!isOneStepMethod(), std::logic_error,
229 "Error - OperatorSplit only works for one-step methods!\n");
233 template<
class Scalar>
237 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
238 subStepperIter = subStepperList_.begin();
239 for (; subStepperIter < subStepperList_.end(); subStepperIter++)
243 template<
class Scalar>
249 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperOperatorSplit::takeStep()");
253 "Error - StepperOperatorSplit<Scalar>::takeStep(...)\n"
254 "Need at least two SolutionStates for OperatorSplit.\n"
256 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
257 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
261 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
265 OpSpSolnHistory_->clear();
266 OpSpSolnHistory_->addState(tempState_);
267 OpSpSolnHistory_->addWorkingState(workingState,
false);
269 RCP<SolutionState<Scalar> > currentSubState =
270 OpSpSolnHistory_->getCurrentState();
271 RCP<SolutionState<Scalar> > workingSubState =
272 OpSpSolnHistory_->getWorkingState();
275 typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::iterator
276 subStepperIter = subStepperList_.begin();
277 for (; subStepperIter < subStepperList_.end() and pass; subStepperIter++) {
278 int index = subStepperIter - subStepperList_.begin();
280 stepperOSObserver_->observeBeforeStepper(index,
solutionHistory, *
this);
282 (*subStepperIter)->takeStep(OpSpSolnHistory_);
284 stepperOSObserver_->observeAfterStepper(index,
solutionHistory, *
this);
288 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
289 Teuchos::OSTab ostab(out,1,
"StepperOperatorSplit::takeStep()");
290 *out <<
"SubStepper, " << (*subStepperIter)->getStepperType()
291 <<
", failed!" << std::endl;
296 currentSubState = OpSpSolnHistory_->getCurrentState();
297 currentSubState->copySolutionData(workingSubState);
300 if (pass ==
true) workingState->setSolutionStatus(
Status::PASSED);
302 workingState->setOrder(this->getOrder());
303 OpSpSolnHistory_->clear();
316 template<
class Scalar>
320 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
326 template<
class Scalar>
328 Teuchos::FancyOStream &out,
329 const Teuchos::EVerbosityLevel )
const
331 out << this->getStepperType() <<
"::describe:" << std::endl;
335 template<
class Scalar>
336 Teuchos::RCP<const Teuchos::ParameterList>
339 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
341 pl->set<
int> (
"Minimum Order", 1,
342 "Minimum Operator-split order. (default = 1)\n");
343 pl->set<
int> (
"Order", 1,
344 "Operator-split order. (default = 1)\n");
345 pl->set<
int> (
"Maximum Order", 1,
346 "Maximum Operator-split order. (default = 1)\n");
348 pl->set<std::string>(
"Stepper List",
"",
349 "Comma deliminated list of single quoted Steppers, e.g., \"'Operator 1', 'Operator 2'\".");
356 #endif // Tempus_StepperOperatorSplit_impl_hpp
virtual void setOrderMin(Scalar o)
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 setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver)
Set solver.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
virtual bool getICConsistencyCheckDefault() const
virtual void setModels(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > > appModels)
virtual void setOrder(Scalar o)
virtual std::string getICConsistencyDefault() const
Thyra Base interface for time steppers.
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
void setICConsistencyCheck(bool c)
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...
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
Keep a fix number of states.
virtual void setOrderMax(Scalar o)
virtual bool getUseFSALDefault() const
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
void getValidParametersBasic(Teuchos::RCP< Teuchos::ParameterList > pl, std::string stepperType)
Provide basic parameters to Steppers.
void setStepperType(std::string s)
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...
virtual void setSubStepperList(std::vector< Teuchos::RCP< Stepper< Scalar > > > subStepperList)
void setICConsistency(std::string s)