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 out = Teuchos::fancyOStream( in_out.
getOStream() );
 
   76       out->setOutputToRootOnly(0);
 
   80            << 
"Step Type     = " << this->
getStepType()<< std::endl;
 
   82       std::stringstream sList;
 
   83       for(std::size_t i = 0; i < 
strategies_.size(); ++i) {
 
   87       *out << 
"Strategy List = " << sList.str() << std::endl;
 
   90         s->describe(*out, verbLevel);
 
  103         "Error - Cannot mix 'Constant' and 'Variable' step types.\n" 
  104         "strategies in composite!  Need at least one.\n");
 
  114   virtual std::vector<Teuchos::RCP<TimeStepControlStrategy<Scalar>>>
 
  123       "Error - No strategies in composite!  Need at least one.\n");
 
  128     auto strategy0 = strategies_[0];
 
  129     for (
auto& s : strategies_) {
 
  131         "Error - Composite strategy, "<< s->getName() <<
" is not initialized!\n");
 
  133       if (strategy0->getStepType() != s->getStepType()) {
 
  134         std::ostringstream msg;
 
  135         msg << 
"Error - All the Strategy Step Types must match.\n";
 
  136         for(std::size_t i = 0; i < strategies_.size(); ++i) {
 
  137           msg << 
"  Strategy[" << i << 
"] = " 
  138               << strategies_[i]->getStepType()
 
  139               << 
"  (" << strategies_[i]->getName() << 
")\n";
 
  152       Teuchos::parameterList(
"Time Step Control Strategy");
 
  156     std::stringstream sList;
 
  157     for(std::size_t i = 0; i < 
strategies_.size(); ++i) {
 
  161     pl->
set<std::string>(
"Strategy List", sList.str());
 
  164       pl->
set(s->getName(), *s->getValidParameters());
 
  171   std::vector<Teuchos::RCP<TimeStepControlStrategy<Scalar > > > 
strategies_;
 
  178 template <
class Scalar>
 
  182   std::string name = 
"Composite")
 
  187   std::vector<std::string> tscsList;
 
  190     pList->
get<std::string>(
"Strategy Type", 
"Composite") !=
 
  191       "Composite", std::logic_error,
 
  192     "Error - Strategy Type != 'Composite'.  (='" 
  193     +pList->
get<std::string>(
"Strategy Type")+
"')\n");
 
  197   std::string str = pList->
get<std::string>(
"Strategy List");
 
  198   std::string delimiters(
",");
 
  199   const char* WhiteSpace = 
" \t\v\r\n";
 
  201   std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
 
  203   std::string::size_type pos     = str.find_first_of(delimiters, lastPos);
 
  204   while ((pos != std::string::npos) || (lastPos != std::string::npos)) {
 
  206     std::string token = str.substr(lastPos,pos-lastPos);
 
  208     std::size_t start = token.find_first_not_of(WhiteSpace);
 
  209     std::size_t end = token.find_last_not_of(WhiteSpace);
 
  210     token = (start == end ? std::string() : token.substr(start, end-start+1));
 
  212     tscsList.push_back(token);
 
  213     if(pos==std::string::npos) 
break;
 
  215     lastPos = str.find_first_not_of(delimiters, pos); 
 
  216     pos = str.find_first_of(delimiters, lastPos);     
 
  222   for ( 
auto tscsName: tscsList) {
 
  223     RCP<ParameterList> pl =
 
  226     auto strategyType = pl->get<std::string>(
"Strategy Type", 
"Unknown");
 
  227     if (strategyType == 
"Constant") {
 
  229         createTimeStepControlStrategyConstant<Scalar>(pl, tscsName));
 
  230     } 
else if (strategyType == 
"Basic VS") {
 
  232         createTimeStepControlStrategyBasicVS<Scalar>(pl, tscsName));
 
  233     } 
else if (strategyType == 
"Integral Controller") {
 
  235         createTimeStepControlStrategyIntegralController<Scalar>(pl, tscsName));
 
  236     } 
else if (strategyType == 
"Composite") {
 
  238         createTimeStepControlStrategyComposite<Scalar>(pl, tscsName));
 
  240       RCP<Teuchos::FancyOStream> out =
 
  241         Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
 
  242       out->setOutputToRootOnly(0);
 
  243       Teuchos::OSTab ostab(out,1, 
"createTimeStepControlStrategyComposite()");
 
  244       *out << 
"Warning -- Unknown strategy type!\n" 
  245            << 
"'Strategy Type' = '" << strategyType << 
"'\n" 
  246            << 
"Should call addStrategy() with this\n" 
  247            << 
"(app-specific?) strategy, and initialize().\n" << std::endl;
 
  252   tscsc->setName(name);
 
  254   if (tscsc->size() == 0) {
 
  255     RCP<Teuchos::FancyOStream> out =
 
  256       Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
 
  257     out->setOutputToRootOnly(0);
 
  258     Teuchos::OSTab ostab(out,1, 
"createTimeStepControlStrategyComposite()");
 
  259     *out << 
"Warning -- Did not find a Tempus strategy to create!\n" 
  260          << 
"Should call addStrategy() with (app-specific?) strategy(ies),\n" 
  261          << 
"and initialize().\n" << std::endl;
 
  272 template<
class Scalar>
 
  277   t->addStrategy(tscs);
 
  283 #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)
void describe(Teuchos::FancyOStream &in_out, const Teuchos::EVerbosityLevel verbLevel) const override
std::vector< Teuchos::RCP< TimeStepControlStrategy< Scalar > > > strategies_
virtual std::string getStrategyType() const 
void clearStrategies()
Clear the composite list. 
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