10 #ifndef Tempus_TimeStepControlStrategy_IntegralController_hpp
11 #define Tempus_TimeStepControlStrategy_IntegralController_hpp
13 #include "Tempus_config.hpp"
16 #include "Tempus_SolutionState.hpp"
17 #include "Tempus_SolutionHistory.hpp"
58 template <
class Scalar>
77 this->
setName(
"Integral Controller");
83 std::string controller, Scalar KI, Scalar KP, Scalar KD,
84 Scalar safetyFactor, Scalar safetyFactorAfterReject, Scalar facMax,
85 Scalar facMin, std::string name =
"Integral Controller")
122 RCP<SolutionState<Scalar> > workingState =
123 solutionHistory->getWorkingState();
127 int order = workingState->getOrder() - 1;
128 Scalar dt = workingState->getTimeStep();
131 Scalar errN = workingState->getErrorRel();
132 Scalar errNm1 = workingState->getErrorRelNm1();
133 Scalar errNm2 = workingState->getErrorRelNm2();
135 if (errN < numericalTol<Scalar>()) errN = 1.0;
136 if (errNm1 < numericalTol<Scalar>()) errNm1 = 1.0;
137 if (errNm2 < numericalTol<Scalar>()) errNm2 = 1.0;
139 Scalar k1 = Teuchos::as<Scalar>(-
KI_ / order);
140 Scalar k2 = Teuchos::as<Scalar>(
KP_ / order);
141 Scalar k3 = Teuchos::as<Scalar>(-
KD_ / order);
143 k1 = std::pow(errN, k1);
144 k2 = std::pow(errNm1, k2);
145 k3 = std::pow(errNm2, k3);
154 beta = std::max(
facMin_, beta);
155 beta = std::min(
facMax_, beta);
163 dt = std::min(dt, workingState->getTimeStep());
176 workingState->setTimeStep(dt);
177 workingState->setTime(solutionHistory->getCurrentState()->getTime() + dt);
184 return "Tempus::TimeStepControlStrategyIntegralController";
190 auto l_out = Teuchos::fancyOStream(out.
getOStream());
192 l_out->setOutputToRootOnly(0);
194 *l_out <<
"\n--- " << this->
description() <<
" ---" << std::endl;
197 *l_out <<
" Strategy Type = "
203 <<
" KI = " <<
getKI()
205 <<
" KP = " <<
getKP()
207 <<
" KD = " <<
getKD()
211 <<
" Safety Factor After Step Rejection = "
215 <<
" Maximum Safety Factor = " <<
getFacMax()
217 <<
" Minimum Safety Factor = " <<
getFacMin()
219 *l_out << std::string(this->
description().length() + 8,
'-') << std::endl;
229 Teuchos::parameterList(
"Time Step Control Strategy");
232 "Integral Controller");
234 "Proportional-Integral-Derivative");
235 pl->
set<Scalar>(
"KI",
getKI(),
"Integral gain");
236 pl->
set<Scalar>(
"KP",
getKP(),
"Proportional gain");
237 pl->
set<Scalar>(
"KD",
getKD(),
"Derivative gain");
239 pl->
set<Scalar>(
"Safety Factor After Step Rejection",
241 "Safety Factor Following Step Rejection");
243 "Maximum Safety Factor");
245 "Minimum Safety Factor");
252 "Error - Invalid value of Safety Factory= "
254 <<
"Safety Factor must be > 0.0.\n");
257 facMax_ <= 0.0, std::out_of_range,
258 "Error - Invalid value of Maximum Safety Factory= "
260 <<
"Maximum Safety Factor must be > 0.0.\n");
263 facMax_ <= 0.0, std::out_of_range,
264 "Error - Invalid value of Minimum Safety Factory= "
266 <<
"Minimum Safety Factor must be > 0.0.\n");
270 std::invalid_argument,
271 "Error - Invalid choice of Controller Type = "
273 <<
"Valid Choice are ['I', 'PI', 'PID'].\n");
347 template <
class Scalar>
351 std::string name =
"Integral Controller")
355 if (pList == Teuchos::null || pList->
numParams() == 0)
return tscs;
358 pList->
get<std::string>(
"Strategy Type") !=
"Integral Controller",
360 "Error - Strategy Type != 'Integral Controller'. (='" +
361 pList->
get<std::string>(
"Strategy Type") +
"')\n");
365 tscs->setController(pList->
get<std::string>(
"Controller Type"));
366 tscs->setKI(pList->
get<Scalar>(
"KI"));
367 tscs->setKP(pList->
get<Scalar>(
"KP"));
368 tscs->setKD(pList->
get<Scalar>(
"KD"));
369 tscs->setSafetyFactor(pList->
get<Scalar>(
"Safety Factor"));
370 tscs->setSafetyFactorAfterReject(
371 pList->
get<Scalar>(
"Safety Factor After Step Rejection"));
372 tscs->setFacMax(pList->
get<Scalar>(
"Maximum Safety Factor"));
373 tscs->setFacMin(pList->
get<Scalar>(
"Minimum Safety Factor"));
382 template <
class Scalar>
388 t->getValidParameters());
392 #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)
#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
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.