9 #ifndef Tempus_TimeStepControlStrategy_IntegralController_hpp
10 #define Tempus_TimeStepControlStrategy_IntegralController_hpp
12 #include "Tempus_config.hpp"
15 #include "Tempus_SolutionState.hpp"
16 #include "Tempus_SolutionHistory.hpp"
57 template <
class Scalar>
76 this->
setName(
"Integral Controller");
82 std::string controller, Scalar KI, Scalar KP, Scalar KD,
83 Scalar safetyFactor, Scalar safetyFactorAfterReject, Scalar facMax,
84 Scalar facMin, std::string name =
"Integral Controller")
121 RCP<SolutionState<Scalar> > workingState =
122 solutionHistory->getWorkingState();
126 int order = workingState->getOrder() - 1;
127 Scalar dt = workingState->getTimeStep();
130 Scalar errN = workingState->getErrorRel();
131 Scalar errNm1 = workingState->getErrorRelNm1();
132 Scalar errNm2 = workingState->getErrorRelNm2();
134 if (errN < numericalTol<Scalar>()) errN = 1.0;
135 if (errNm1 < numericalTol<Scalar>()) errNm1 = 1.0;
136 if (errNm2 < numericalTol<Scalar>()) errNm2 = 1.0;
138 Scalar k1 = Teuchos::as<Scalar>(-
KI_ / order);
139 Scalar k2 = Teuchos::as<Scalar>(
KP_ / order);
140 Scalar k3 = Teuchos::as<Scalar>(-
KD_ / order);
142 k1 = std::pow(errN, k1);
143 k2 = std::pow(errNm1, k2);
144 k3 = std::pow(errNm2, k3);
153 beta = std::max(
facMin_, beta);
154 beta = std::min(
facMax_, beta);
162 dt = std::min(dt, workingState->getTimeStep());
175 workingState->setTimeStep(dt);
176 workingState->setTime(solutionHistory->getCurrentState()->getTime() + dt);
183 return "Tempus::TimeStepControlStrategyIntegralController";
189 auto l_out = Teuchos::fancyOStream(out.
getOStream());
191 l_out->setOutputToRootOnly(0);
193 *l_out <<
"\n--- " << this->
description() <<
" ---" << std::endl;
196 *l_out <<
" Strategy Type = "
202 <<
" KI = " <<
getKI()
204 <<
" KP = " <<
getKP()
206 <<
" KD = " <<
getKD()
210 <<
" Safety Factor After Step Rejection = "
214 <<
" Maximum Safety Factor = " <<
getFacMax()
216 <<
" Minimum Safety Factor = " <<
getFacMin()
218 *l_out << std::string(this->
description().length() + 8,
'-') << std::endl;
228 Teuchos::parameterList(
"Time Step Control Strategy");
231 "Integral Controller");
233 "Proportional-Integral-Derivative");
234 pl->
set<Scalar>(
"KI",
getKI(),
"Integral gain");
235 pl->
set<Scalar>(
"KP",
getKP(),
"Proportional gain");
236 pl->
set<Scalar>(
"KD",
getKD(),
"Derivative gain");
238 pl->
set<Scalar>(
"Safety Factor After Step Rejection",
240 "Safety Factor Following Step Rejection");
242 "Maximum Safety Factor");
244 "Minimum Safety Factor");
251 "Error - Invalid value of Safety Factory= "
253 <<
"Safety Factor must be > 0.0.\n");
256 facMax_ <= 0.0, std::out_of_range,
257 "Error - Invalid value of Maximum Safety Factory= "
259 <<
"Maximum Safety Factor must be > 0.0.\n");
262 facMax_ <= 0.0, std::out_of_range,
263 "Error - Invalid value of Minimum Safety Factory= "
265 <<
"Minimum Safety Factor must be > 0.0.\n");
269 std::invalid_argument,
270 "Error - Invalid choice of Controller Type = "
272 <<
"Valid Choice are ['I', 'PI', 'PID'].\n");
346 template <
class Scalar>
350 std::string name =
"Integral Controller")
354 if (pList == Teuchos::null || pList->
numParams() == 0)
return tscs;
357 pList->
get<std::string>(
"Strategy Type") !=
"Integral Controller",
359 "Error - Strategy Type != 'Integral Controller'. (='" +
360 pList->
get<std::string>(
"Strategy Type") +
"')\n");
364 tscs->setController(pList->
get<std::string>(
"Controller Type"));
365 tscs->setKI(pList->
get<Scalar>(
"KI"));
366 tscs->setKP(pList->
get<Scalar>(
"KP"));
367 tscs->setKD(pList->
get<Scalar>(
"KD"));
368 tscs->setSafetyFactor(pList->
get<Scalar>(
"Safety Factor"));
369 tscs->setSafetyFactorAfterReject(
370 pList->
get<Scalar>(
"Safety Factor After Step Rejection"));
371 tscs->setFacMax(pList->
get<Scalar>(
"Maximum Safety Factor"));
372 tscs->setFacMin(pList->
get<Scalar>(
"Minimum Safety Factor"));
381 template <
class Scalar>
387 t->getValidParameters());
391 #endif // Tempus_TimeStepControlStrategy_IntegralController_hpp
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Return ParameterList with current values.
Scalar facMin_
Minimum Safety Factor.
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)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual Scalar getSafetyFactor() const
virtual void checkInitialized()
virtual Scalar getKI() const
virtual std::string getStrategyType() const
virtual std::string getController() const
Ordinal numParams() const
virtual Scalar getFacMax() const
virtual void setController(std::string c)
virtual Scalar getKP() const
virtual void setKD(Scalar k)
virtual Scalar getSafetyFactorAfterReject() const
std::string description() const override
virtual void setKP(Scalar k)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Scalar KD_
Derivative gain.
Status
Status for the Integrator, the Stepper and the SolutionState.
virtual Scalar getKD() const
virtual void setStepType(std::string s)
Scalar safetyFactor_
Safety Factor.
bool isInitialized_
Bool if strategy is initialized.
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
virtual void setName(std::string s)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void setSafetyFactor(Scalar f)
virtual void setSafetyFactorAfterReject(Scalar f)
std::string controller_
Control type ['I', 'PI', 'PID'].
virtual void setKI(Scalar k)
Teuchos::RCP< Teuchos::ParameterList > getTimeStepControlStrategyIntegralControllerPL()
Nonmember function to return ParameterList with default values.
Scalar facMaxINPUT_
Maximum Safety Factor from input.
TimeStepControlStrategyIntegralController(std::string controller, Scalar KI, Scalar KP, Scalar KD, Scalar safetyFactor, Scalar safetyFactorAfterReject, Scalar facMax, Scalar facMin, std::string name="Integral Controller")
Full Constructor.
virtual void setNextTimeStep(const TimeStepControl< Scalar > &tsc, Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory, Status &) override
Set the time step size.
Teuchos::RCP< TimeStepControlStrategyIntegralController< Scalar > > createTimeStepControlStrategyIntegralController(const Teuchos::RCP< Teuchos::ParameterList > pList, std::string name="Integral Controller")
virtual Scalar getFacMin() const
RCP< std::basic_ostream< char_type, traits_type > > getOStream()
virtual void setFacMax(Scalar f)
virtual ~TimeStepControlStrategyIntegralController()
Destructor.
TimeStepControlStrategyIntegralController()
Default Constructor.
virtual void initialize() const override
StepControlStrategy class for TimeStepControl.
virtual void setStrategyType(std::string s)
bool firstSuccessfulStep_
TimeStepControlStrategy class for TimeStepControl.
Scalar safetyFactorAfterReject_
Safety Factor Following Step Rejection.
virtual std::string getStepType() const
virtual void setFacMin(Scalar f)
Scalar facMax_
Maximum Safety Factor.
Scalar KP_
Proportional gain.