10 #ifndef Tempus_TimeStepControlStrategyComposite_hpp
11 #define Tempus_TimeStepControlStrategyComposite_hpp
13 #include "Tempus_config.hpp"
18 #include "Tempus_SolutionHistory.hpp"
42 template <
class Scalar>
60 Status& integratorStatus)
override
62 for (
auto& s :
strategies_) s->setNextTimeStep(tsc, sh, integratorStatus);
69 return "Tempus::TimeStepControlComposite";
75 auto l_out = Teuchos::fancyOStream(out.
getOStream());
77 l_out->setOutputToRootOnly(0);
79 *l_out <<
"\n--- " << this->
description() <<
" ---" << std::endl;
83 <<
" Step Type = " << this->
getStepType() << std::endl;
85 std::stringstream sList;
86 for (std::size_t i = 0; i <
strategies_.size(); ++i) {
90 *l_out <<
" Strategy List = " << sList.str() << std::endl;
92 for (
auto& s :
strategies_) s->describe(*l_out, verbLevel);
94 *l_out << std::string(this->
description().length() + 8,
'-') << std::endl;
107 this->
getStepType() != strategy->getStepType(), std::logic_error,
108 "Error - Cannot mix 'Constant' and 'Variable' step types.\n"
109 "strategies in composite! Need at least one.\n");
119 virtual std::vector<Teuchos::RCP<TimeStepControlStrategy<Scalar>>>
132 "Error - No strategies in composite! Need at least one.\n");
136 auto strategy0 = strategies_[0];
137 for (
auto& s : strategies_) {
139 "Error - Composite strategy, "
141 <<
" is not initialized!\n");
143 if (strategy0->getStepType() != s->getStepType()) {
144 std::ostringstream msg;
145 msg <<
"Error - All the Strategy Step Types must match.\n";
146 for (std::size_t i = 0; i < strategies_.size(); ++i) {
147 msg <<
" Strategy[" << i <<
"] = " << strategies_[i]->getStepType()
148 <<
" (" << strategies_[i]->getName() <<
")\n";
162 Teuchos::parameterList(
"Time Step Control Strategy");
166 std::stringstream sList;
167 for (std::size_t i = 0; i <
strategies_.size(); ++i) {
171 pl->
set<std::string>(
"Strategy List", sList.str());
173 for (
auto& s :
strategies_) pl->
set(s->getName(), *s->getValidParameters());
179 std::vector<Teuchos::RCP<TimeStepControlStrategy<Scalar>>>
strategies_;
184 template <
class Scalar>
188 std::string name =
"Composite")
193 std::vector<std::string> tscsList;
196 pList->
get<std::string>(
"Strategy Type") !=
"Composite", std::logic_error,
197 "Error - Strategy Type != 'Composite'. (='" +
198 pList->
get<std::string>(
"Strategy Type") +
"')\n");
202 std::string str = pList->
get<std::string>(
"Strategy List");
203 std::string delimiters(
",");
204 const char* WhiteSpace =
" \t\v\r\n";
206 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
208 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
209 while ((pos != std::string::npos) || (lastPos != std::string::npos)) {
211 std::string token = str.substr(lastPos, pos - lastPos);
213 std::size_t start = token.find_first_not_of(WhiteSpace);
214 std::size_t end = token.find_last_not_of(WhiteSpace);
216 (start == end ? std::string() : token.substr(start, end - start + 1));
218 tscsList.push_back(token);
219 if (pos == std::string::npos)
break;
221 lastPos = str.find_first_not_of(delimiters, pos);
222 pos = str.find_first_of(delimiters, lastPos);
228 for (
auto tscsName : tscsList) {
229 RCP<ParameterList> pl =
232 auto strategyType = pl->get<std::string>(
"Strategy Type",
"Unknown");
233 if (strategyType ==
"Constant") {
235 createTimeStepControlStrategyConstant<Scalar>(pl, tscsName));
237 else if (strategyType ==
"Basic VS") {
239 createTimeStepControlStrategyBasicVS<Scalar>(pl, tscsName));
241 else if (strategyType ==
"Integral Controller") {
243 createTimeStepControlStrategyIntegralController<Scalar>(pl,
246 else if (strategyType ==
"Composite") {
248 createTimeStepControlStrategyComposite<Scalar>(pl, tscsName));
251 RCP<Teuchos::FancyOStream> out =
252 Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
253 out->setOutputToRootOnly(0);
254 Teuchos::OSTab ostab(out, 1,
"createTimeStepControlStrategyComposite()");
255 *out <<
"Warning -- Unknown strategy type!\n"
256 <<
"'Strategy Type' = '" << strategyType <<
"'\n"
257 <<
"Should call addStrategy() with this\n"
258 <<
"(app-specific?) strategy, and initialize().\n"
263 tscsc->setName(name);
265 if (tscsc->size() == 0) {
266 RCP<Teuchos::FancyOStream> out =
267 Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
268 out->setOutputToRootOnly(0);
269 Teuchos::OSTab ostab(out, 1,
"createTimeStepControlStrategyComposite()");
270 *out <<
"Warning -- Did not find a Tempus strategy to create!\n"
271 <<
"Should call addStrategy() with (app-specific?) strategy(ies),\n"
272 <<
"and initialize().\n"
283 template <
class Scalar>
288 t->addStrategy(tscs);
290 t->getValidParameters());
294 #endif // Tempus_TimeStepControlStrategy_hpp
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Return ParameterList with current values.
virtual std::vector< Teuchos::RCP< TimeStepControlStrategy< Scalar > > > getStrategies() const
Return composite list.
T & get(const std::string &name, T def_value)
bool nonnull(const std::shared_ptr< T > &p)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual std::string getStrategyType() const
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void clearStrategies()
Clear the composite list.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
Teuchos::RCP< TimeStepControlStrategyComposite< Scalar > > createTimeStepControlStrategyComposite(Teuchos::RCP< Teuchos::ParameterList > const &pList, std::string name="Composite")
std::string description() const override
virtual int size() const
Size of composite list.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void addStrategy(const Teuchos::RCP< TimeStepControlStrategy< Scalar >> &strategy)
Append strategy to the composite list.
Status
Status for the Integrator, the Stepper and the SolutionState.
virtual void setStepType(std::string s)
bool isInitialized_
Bool if strategy is initialized.
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
StepControlStrategy class for TimeStepControl.
virtual ~TimeStepControlStrategyComposite()
Destructor.
RCP< std::basic_ostream< char_type, traits_type > > getOStream()
TimeStepControlStrategyComposite loops over a vector of TimeStepControlStrategies.
virtual void initialize() const override
virtual void setNextTimeStep(const TimeStepControl< Scalar > &tsc, Teuchos::RCP< SolutionHistory< Scalar >> sh, Status &integratorStatus) override
Determine the time step size.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
TimeStepControlStrategyComposite()
Constructor.
std::vector< Teuchos::RCP< TimeStepControlStrategy< Scalar > > > strategies_
virtual void setStrategyType(std::string s)
TimeStepControlStrategy class for TimeStepControl.
Teuchos::RCP< Teuchos::ParameterList > getTimeStepControlStrategyCompositePL()
Nonmember function to return ParameterList with default values.
virtual std::string getStepType() const