10 #ifndef Tempus_TimeStepControlStrategy_Constant_hpp
11 #define Tempus_TimeStepControlStrategy_Constant_hpp
13 #include "Tempus_config.hpp"
15 #include "Tempus_SolutionState.hpp"
16 #include "Tempus_SolutionHistory.hpp"
24 template <
class Scalar>
39 std::string name =
"Constant")
55 Status &integratorStatus)
override
61 RCP<SolutionState<Scalar> > workingState =
62 solutionHistory->getWorkingState();
63 const Scalar errorAbs = workingState->getErrorAbs();
64 const Scalar errorRel = workingState->getErrorRel();
65 Scalar dt = workingState->getTimeStep();
67 RCP<Teuchos::FancyOStream> out = tsc.
getOStream();
69 out->setOutputToRootOnly(0);
74 "Resetting constant dt.");
80 *out <<
"Failure - Stepper failed and can not change time step size!\n"
81 <<
" Time step type == CONSTANT_STEP_SIZE\n"
89 *out <<
"Failure - Absolute error failed and can not change time step!\n"
90 <<
" Time step type == CONSTANT_STEP_SIZE\n"
91 <<
" (errorAbs =" << errorAbs
92 <<
") > (errorMaxAbs =" << tsc.
getMaxAbsError() <<
")" << std::endl;
99 *out <<
"Failure - Relative error failed and can not change time step!\n"
100 <<
" Time step type == CONSTANT_STEP_SIZE\n"
101 <<
" (errorRel =" << errorRel
102 <<
") > (errorMaxRel =" << tsc.
getMaxRelError() <<
")" << std::endl;
103 integratorStatus =
FAILED;
108 workingState->setTimeStep(dt);
113 const int index = workingState->getIndex();
114 const Scalar time = (index - initIndex) * dt + initTime;
115 workingState->setTime(time);
122 return "Tempus::TimeStepControlStrategyConstant";
128 auto l_out = Teuchos::fancyOStream(out.
getOStream());
130 l_out->setOutputToRootOnly(0);
132 *l_out <<
"\n--- " << this->
description() <<
" ---" << std::endl;
136 <<
" Step Type = " << this->
getStepType() << std::endl
139 *l_out << std::string(this->
description().length() + 8,
'-') << std::endl;
149 Teuchos::parameterList(
"Time Step Control Strategy");
175 template <
class Scalar>
179 std::string name =
"Constant")
182 if (pList == Teuchos::null || pList->
numParams() == 0)
return tscs;
185 pList->
get<std::string>(
"Strategy Type") !=
"Constant", std::logic_error,
186 "Error - Strategy Type != 'Constant'. (='" +
187 pList->
get<std::string>(
"Strategy Type") +
"')\n");
191 tscs->setConstantTimeStep(pList->
get<
double>(
"Time Step"));
200 template <
class Scalar>
205 t->getValidParameters());
209 #endif // Tempus_TimeStepControlStrategy_Constant_hpp
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Return ParameterList with current values.
virtual void initialize() const override
virtual int getInitIndex() const
T & get(const std::string &name, T def_value)
virtual Scalar getMaxRelError() const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void checkInitialized()
virtual std::string getStrategyType() const
Ordinal numParams() const
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
TimeStepControlStrategyConstant(Scalar constantTimeStep, std::string name="Constant")
Full Constructor.
virtual Scalar getInitTimeStep() const
virtual void printDtChanges(int istep, Scalar dt_old, Scalar dt_new, std::string reason) const
virtual void setNextTimeStep(const TimeStepControl< Scalar > &tsc, Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory, Status &integratorStatus) override
Determine the time step size.
Teuchos::RCP< TimeStepControlStrategyConstant< Scalar > > createTimeStepControlStrategyConstant(const Teuchos::RCP< Teuchos::ParameterList > &pList, std::string name="Constant")
Nonmember constructor.
TimeStepControlStrategyConstant()
Default Constructor.
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)
virtual ~TimeStepControlStrategyConstant()
Destructor.
bool isInitialized_
Bool if strategy is initialized.
virtual Scalar getMaxAbsError() const
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
Teuchos::RCP< Teuchos::ParameterList > getTimeStepControlStrategyConstantPL()
Nonmember function to return ParameterList with default values.
virtual void setConstantTimeStep(Scalar dt)
virtual void setName(std::string s)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
StepControlStrategy class for TimeStepControl.
Scalar constantTimeStep_
Constant time step size.
RCP< std::basic_ostream< char_type, traits_type > > getOStream()
std::string description() const override
virtual Scalar getConstantTimeStep() const
virtual void setStrategyType(std::string s)
TimeStepControlStrategy class for TimeStepControl.
virtual Scalar getInitTime() const
virtual std::string getStepType() const
virtual RCP< FancyOStream > getOStream() const