9 #ifndef Tempus_TimeStepControlStrategyComposite_hpp
10 #define Tempus_TimeStepControlStrategyComposite_hpp
12 #include "Tempus_config.hpp"
17 #include "Tempus_SolutionHistory.hpp"
41 template <
class Scalar>
59 Status& integratorStatus)
override
61 for (
auto& s :
strategies_) s->setNextTimeStep(tsc, sh, integratorStatus);
68 return "Tempus::TimeStepControlComposite";
74 auto l_out = Teuchos::fancyOStream(out.
getOStream());
76 l_out->setOutputToRootOnly(0);
78 *l_out <<
"\n--- " << this->
description() <<
" ---" << std::endl;
82 <<
" Step Type = " << this->
getStepType() << std::endl;
84 std::stringstream sList;
85 for (std::size_t i = 0; i <
strategies_.size(); ++i) {
89 *l_out <<
" Strategy List = " << sList.str() << std::endl;
91 for (
auto& s :
strategies_) s->describe(*l_out, verbLevel);
93 *l_out << std::string(this->
description().length() + 8,
'-') << std::endl;
106 this->
getStepType() != strategy->getStepType(), std::logic_error,
107 "Error - Cannot mix 'Constant' and 'Variable' step types.\n"
108 "strategies in composite! Need at least one.\n");
118 virtual std::vector<Teuchos::RCP<TimeStepControlStrategy<Scalar>>>
131 "Error - No strategies in composite! Need at least one.\n");
135 auto strategy0 = strategies_[0];
136 for (
auto& s : strategies_) {
138 "Error - Composite strategy, "
140 <<
" is not initialized!\n");
142 if (strategy0->getStepType() != s->getStepType()) {
143 std::ostringstream msg;
144 msg <<
"Error - All the Strategy Step Types must match.\n";
145 for (std::size_t i = 0; i < strategies_.size(); ++i) {
146 msg <<
" Strategy[" << i <<
"] = " << strategies_[i]->getStepType()
147 <<
" (" << strategies_[i]->getName() <<
")\n";
161 Teuchos::parameterList(
"Time Step Control Strategy");
165 std::stringstream sList;
166 for (std::size_t i = 0; i <
strategies_.size(); ++i) {
170 pl->
set<std::string>(
"Strategy List", sList.str());
172 for (
auto& s :
strategies_) pl->
set(s->getName(), *s->getValidParameters());
178 std::vector<Teuchos::RCP<TimeStepControlStrategy<Scalar>>>
strategies_;
183 template <
class Scalar>
187 std::string name =
"Composite")
192 std::vector<std::string> tscsList;
195 pList->
get<std::string>(
"Strategy Type") !=
"Composite", std::logic_error,
196 "Error - Strategy Type != 'Composite'. (='" +
197 pList->
get<std::string>(
"Strategy Type") +
"')\n");
201 std::string str = pList->
get<std::string>(
"Strategy List");
202 std::string delimiters(
",");
203 const char* WhiteSpace =
" \t\v\r\n";
205 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
207 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
208 while ((pos != std::string::npos) || (lastPos != std::string::npos)) {
210 std::string token = str.substr(lastPos, pos - lastPos);
212 std::size_t start = token.find_first_not_of(WhiteSpace);
213 std::size_t end = token.find_last_not_of(WhiteSpace);
215 (start == end ? std::string() : token.substr(start, end - start + 1));
217 tscsList.push_back(token);
218 if (pos == std::string::npos)
break;
220 lastPos = str.find_first_not_of(delimiters, pos);
221 pos = str.find_first_of(delimiters, lastPos);
227 for (
auto tscsName : tscsList) {
228 RCP<ParameterList> pl =
231 auto strategyType = pl->get<std::string>(
"Strategy Type",
"Unknown");
232 if (strategyType ==
"Constant") {
234 createTimeStepControlStrategyConstant<Scalar>(pl, tscsName));
236 else if (strategyType ==
"Basic VS") {
238 createTimeStepControlStrategyBasicVS<Scalar>(pl, tscsName));
240 else if (strategyType ==
"Integral Controller") {
242 createTimeStepControlStrategyIntegralController<Scalar>(pl,
245 else if (strategyType ==
"Composite") {
247 createTimeStepControlStrategyComposite<Scalar>(pl, tscsName));
250 RCP<Teuchos::FancyOStream> out =
251 Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
252 out->setOutputToRootOnly(0);
253 Teuchos::OSTab ostab(out, 1,
"createTimeStepControlStrategyComposite()");
254 *out <<
"Warning -- Unknown strategy type!\n"
255 <<
"'Strategy Type' = '" << strategyType <<
"'\n"
256 <<
"Should call addStrategy() with this\n"
257 <<
"(app-specific?) strategy, and initialize().\n"
262 tscsc->setName(name);
264 if (tscsc->size() == 0) {
265 RCP<Teuchos::FancyOStream> out =
266 Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
267 out->setOutputToRootOnly(0);
268 Teuchos::OSTab ostab(out, 1,
"createTimeStepControlStrategyComposite()");
269 *out <<
"Warning -- Did not find a Tempus strategy to create!\n"
270 <<
"Should call addStrategy() with (app-specific?) strategy(ies),\n"
271 <<
"and initialize().\n"
282 template <
class Scalar>
287 t->addStrategy(tscs);
289 t->getValidParameters());
293 #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)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
bool nonnull(const std::shared_ptr< T > &p)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual std::string getStrategyType() const
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