9 #ifndef Tempus_TimeStepControlStrategyComposite_hpp
10 #define Tempus_TimeStepControlStrategyComposite_hpp
12 #include "Tempus_config.hpp"
17 #include "Tempus_SolutionHistory.hpp"
41 template<
class Scalar>
61 Status & integratorStatus)
override
64 s->setNextTimeStep(tsc, sh, integratorStatus);
70 {
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;
93 s->describe(*l_out, verbLevel);
95 *l_out << std::string(this->
description().length()+8,
'-') <<std::endl;
109 "Error - Cannot mix 'Constant' and 'Variable' step types.\n"
110 "strategies in composite! Need at least one.\n");
120 virtual std::vector<Teuchos::RCP<TimeStepControlStrategy<Scalar>>>
129 "Error - No strategies in composite! Need at least one.\n");
134 auto strategy0 = strategies_[0];
135 for (
auto& s : strategies_) {
137 "Error - Composite strategy, "<< s->getName() <<
" is not initialized!\n");
139 if (strategy0->getStepType() != s->getStepType()) {
140 std::ostringstream msg;
141 msg <<
"Error - All the Strategy Step Types must match.\n";
142 for(std::size_t i = 0; i < strategies_.size(); ++i) {
143 msg <<
" Strategy[" << i <<
"] = "
144 << strategies_[i]->getStepType()
145 <<
" (" << strategies_[i]->getName() <<
")\n";
158 Teuchos::parameterList(
"Time Step Control Strategy");
162 std::stringstream sList;
163 for(std::size_t i = 0; i <
strategies_.size(); ++i) {
167 pl->
set<std::string>(
"Strategy List", sList.str());
170 pl->
set(s->getName(), *s->getValidParameters());
177 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);
215 token = (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));
235 }
else if (strategyType ==
"Basic VS") {
237 createTimeStepControlStrategyBasicVS<Scalar>(pl, tscsName));
238 }
else if (strategyType ==
"Integral Controller") {
240 createTimeStepControlStrategyIntegralController<Scalar>(pl, tscsName));
241 }
else if (strategyType ==
"Composite") {
243 createTimeStepControlStrategyComposite<Scalar>(pl, tscsName));
245 RCP<Teuchos::FancyOStream> out =
246 Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
247 out->setOutputToRootOnly(0);
248 Teuchos::OSTab ostab(out,1,
"createTimeStepControlStrategyComposite()");
249 *out <<
"Warning -- Unknown strategy type!\n"
250 <<
"'Strategy Type' = '" << strategyType <<
"'\n"
251 <<
"Should call addStrategy() with this\n"
252 <<
"(app-specific?) strategy, and initialize().\n" << std::endl;
257 tscsc->setName(name);
259 if (tscsc->size() == 0) {
260 RCP<Teuchos::FancyOStream> out =
261 Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
262 out->setOutputToRootOnly(0);
263 Teuchos::OSTab ostab(out,1,
"createTimeStepControlStrategyComposite()");
264 *out <<
"Warning -- Did not find a Tempus strategy to create!\n"
265 <<
"Should call addStrategy() with (app-specific?) strategy(ies),\n"
266 <<
"and initialize().\n" << std::endl;
277 template<
class Scalar>
282 t->addStrategy(tscs);
288 #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)
std::vector< Teuchos::RCP< TimeStepControlStrategy< Scalar > > > strategies_
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)
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...
virtual void setNextTimeStep(const TimeStepControl< Scalar > &tsc, Teuchos::RCP< SolutionHistory< Scalar > > sh, Status &integratorStatus) override
Determine the time step size.
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
void addStrategy(const Teuchos::RCP< TimeStepControlStrategy< Scalar > > &strategy)
Append strategy to the composite list.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
TimeStepControlStrategyComposite()
Constructor.
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