9 #ifndef Tempus_TimeStepControlStrategy_BasicVS_hpp
10 #define Tempus_TimeStepControlStrategy_BasicVS_hpp
12 #include "Tempus_TimeStepControl.hpp"
14 #include "Tempus_SolutionState.hpp"
15 #include "Tempus_SolutionHistory.hpp"
19 #include "Thyra_VectorStdOps.hpp"
104 template<
class Scalar>
112 Teuchos::RCP<Teuchos::ParameterList> pList = Teuchos::null){
126 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
127 const Scalar errorAbs = workingState->getErrorAbs();
128 const Scalar errorRel = workingState->getErrorRel();
129 const int iStep = workingState->getIndex();
130 int order = workingState->getOrder();
131 Scalar dt = workingState->getTimeStep();
134 RCP<Teuchos::FancyOStream> out = tsc.getOStream();
135 Teuchos::OSTab ostab(out,0,
"getNextTimeStep");
137 auto changeDT = [] (
int istep, Scalar dt_old, Scalar dt_new,
140 std::stringstream message;
141 message << std::scientific
142 <<std::setw(6)<<std::setprecision(3)<<istep
143 <<
" * (dt = "<<std::setw(9)<<std::setprecision(3)<<dt_old
144 <<
", new = "<<std::setw(9)<<std::setprecision(3)<<dt_new
145 <<
") " << reason << std::endl;
146 return message.str();
151 Scalar eta = solutionHistory->getCurrentState()->getDxNormL2Rel();
156 if (printDtChanges) *out << changeDT(iStep, dt, dt*sigma,
157 "Stepper failure - Decreasing dt.");
162 if (printDtChanges) *out << changeDT(iStep, dt, dt*rho,
164 + std::to_string(eta) +
" < " + std::to_string(
getMinEta())
165 +
"). Increasing dt.");
169 if (printDtChanges) *out << changeDT(iStep, dt, dt*sigma,
171 + std::to_string(eta) +
" > " + std::to_string(
getMaxEta())
172 +
"). Decreasing dt.");
176 if (printDtChanges) *out << changeDT(iStep, dt, dt*sigma,
177 "Absolute error is too large ("
178 + std::to_string(errorAbs)+
" > "+std::to_string(tsc.
getMaxAbsError())
179 +
"). Decreasing dt.");
183 if (printDtChanges) *out << changeDT(iStep, dt, dt*sigma,
184 "Relative error is too large ("
185 + std::to_string(errorRel)+
" > "+std::to_string(tsc.
getMaxRelError())
186 +
"). Decreasing dt.");
190 if (printDtChanges) *out << changeDT(iStep, dt, dt*rho,
191 "Order is too small ("
192 + std::to_string(order) +
" < " + std::to_string(tsc.
getMinOrder())
193 +
"). Increasing dt.");
197 if (printDtChanges) *out << changeDT(iStep, dt, dt*sigma,
198 "Order is too large ("
199 + std::to_string(order) +
" > " + std::to_string(tsc.
getMaxOrder())
200 +
"). Decreasing dt.");
206 if (printDtChanges) *out << changeDT(iStep, dt, tsc.
getMinTimeStep(),
207 "dt is too small. Resetting to minimum dt.");
211 if (printDtChanges) *out << changeDT(iStep, dt, tsc.
getMaxTimeStep(),
212 "dt is too large. Resetting to maximum dt.");
216 workingState->setOrder(order);
217 workingState->setTimeStep(dt);
218 workingState->setComputeNorms(
true);
224 const Teuchos::RCP<Teuchos::ParameterList> & pList)
override
226 if (pList == Teuchos::null) {
228 if (
tscsPL_ == Teuchos::null) {
229 tscsPL_ = Teuchos::parameterList(
"TimeStepControlStrategyBasicVS");
237 TEUCHOS_TEST_FOR_EXCEPTION(
getAmplFactor() <= 1.0, std::out_of_range,
238 "Error - Invalid value of Amplification Factor = " <<
getAmplFactor()
239 <<
"! \n" <<
"Amplification Factor must be > 1.0.\n");
241 TEUCHOS_TEST_FOR_EXCEPTION(
getReductFactor() >= 1.0, std::out_of_range,
243 <<
"! \n" <<
"Reduction Factor must be < 1.0.\n");
246 "Error - Invalid values of 'Minimum Value Monitoring Function' = "
247 <<
getMinEta() <<
"\n and 'Maximum Value Monitoring Function' = "
248 <<
getMaxEta() <<
"! \n Mininum Value cannot be > Maximum Value! \n");
252 Teuchos::RCP<const Teuchos::ParameterList>
254 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
258 pl->set<
double>(
"Amplification Factor", 1.75,
"Amplification factor");
259 pl->set<
double>(
"Reduction Factor" , 0.5 ,
"Reduction factor");
262 pl->set<
double>(
"Minimum Value Monitoring Function", 0.0 ,
"Min value eta");
263 pl->set<
double>(
"Maximum Value Monitoring Function", 1.0e-16,
"Max value eta");
264 pl->set<std::string>(
"Name",
"Basic VS");
273 Teuchos::RCP<Teuchos::ParameterList> temp_plist =
tscsPL_;
280 {
return tscsPL_->get<
double>(
"Amplification Factor"); }
282 {
return tscsPL_->get<
double>(
"Reduction Factor");}
284 {
return tscsPL_->get<
double>(
"Minimum Value Monitoring Function"); }
286 {
return tscsPL_->get<
double>(
"Maximum Value Monitoring Function"); }
289 {
tscsPL_->set<
double>(
"Amplification Factor", rho); }
291 {
tscsPL_->set<
double>(
"Reduction Factor", sigma); }
293 {
tscsPL_->set<
double>(
"Minimum Value Monitoring Function", minEta); }
295 {
tscsPL_->set<
double>(
"Maximum Value Monitoring Function", maxEta); }
305 #endif // Tempus_TimeStepControlStrategy_BasicVS_hpp
virtual void setMaxEta(Scalar maxEta)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
virtual void getNextTimeStep(const TimeStepControl< Scalar > tsc, Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory, Status &) override
Determine the time step size.
StepControlStrategy class for TimeStepControl.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pList) override
virtual Scalar getMaxRelError() const
virtual ~TimeStepControlStrategyBasicVS()
Destructor.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList() override
virtual Scalar getReductFactor() const
virtual Scalar getMinEta() const
virtual bool getPrintDtChanges() const
virtual int getMinOrder() const
virtual Scalar getAmplFactor() const
virtual void setAmplFactor(Scalar rho)
Teuchos::RCP< Teuchos::ParameterList > tscsPL_
TimeStepControlStrategyBasicVS(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Constructor.
Status
Status for the Integrator, the Stepper and the SolutionState.
virtual Scalar getMaxAbsError() const
TimeStepControl manages the time step size. There several mechanicisms that effect the time step size...
virtual void setMinEta(Scalar minEta)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void setReductFactor(Scalar sigma)
virtual Scalar getMaxTimeStep() const
virtual Scalar getMinTimeStep() const
virtual Scalar getMaxEta() const
virtual int getMaxOrder() const
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList() override
StepControlStrategy class for TimeStepControl.