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_SolutionStateMetaData.hpp"
16 #include "Tempus_SolutionHistory.hpp"
20 #include "Thyra_VectorStdOps.hpp"
105 template<
class Scalar>
113 Teuchos::RCP<Teuchos::ParameterList> pList = Teuchos::null){
127 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
128 RCP<SolutionStateMetaData<Scalar> > metaData = workingState->getMetaData();
129 const Scalar errorAbs = metaData->getErrorAbs();
130 const Scalar errorRel = metaData->getErrorRel();
131 const int iStep = metaData->getIStep();
132 int order = metaData->getOrder();
133 Scalar dt = metaData->getDt();
135 Teuchos::as<int>(Teuchos::VERB_NONE);
137 RCP<Teuchos::FancyOStream> out = tsc.getOStream();
138 Teuchos::OSTab ostab(out,0,
"getNextTimeStep");
140 auto changeDT = [] (
int istep, Scalar dt_old, Scalar dt_new,
143 std::stringstream message;
144 message << std::scientific
145 <<std::setw(6)<<std::setprecision(3)<<istep
146 <<
" * (dt = "<<std::setw(9)<<std::setprecision(3)<<dt_old
147 <<
", new = "<<std::setw(9)<<std::setprecision(3)<<dt_new
148 <<
") " << reason << std::endl;
149 return message.str();
159 if (printChanges) *out << changeDT(iStep, dt, dt*sigma,
160 "Stepper failure - Decreasing dt.");
165 if (printChanges) *out << changeDT(iStep, dt, dt*rho,
166 "Monitoring Value (eta) is too small ("
167 + std::to_string(eta) +
" < " + std::to_string(
getMinEta())
168 +
"). Increasing dt.");
172 if (printChanges) *out << changeDT(iStep, dt, dt*sigma,
173 "Monitoring Value (eta) is too large ("
174 + std::to_string(eta) +
" > " + std::to_string(
getMaxEta())
175 +
"). Decreasing dt.");
179 if (printChanges) *out << changeDT(iStep, dt, dt*sigma,
180 "Absolute error is too large ("
181 + std::to_string(errorAbs)+
" > "+std::to_string(tsc.
getMaxAbsError())
182 +
"). Decreasing dt.");
186 if (printChanges) *out << changeDT(iStep, dt, dt*sigma,
187 "Relative error is too large ("
188 + std::to_string(errorRel)+
" > "+std::to_string(tsc.
getMaxRelError())
189 +
"). Decreasing dt.");
193 if (printChanges) *out << changeDT(iStep, dt, dt*rho,
194 "Order is too small ("
195 + std::to_string(order) +
" < " + std::to_string(tsc.
getMinOrder())
196 +
"). Increasing dt.");
200 if (printChanges) *out << changeDT(iStep, dt, dt*sigma,
201 "Order is too large ("
202 + std::to_string(order) +
" > " + std::to_string(tsc.
getMaxOrder())
203 +
"). Decreasing dt.");
209 if (printChanges) *out << changeDT(iStep, dt, tsc.
getMinTimeStep(),
210 "dt is too small. Resetting to minimum dt.");
214 if (printChanges) *out << changeDT(iStep, dt, tsc.
getMaxTimeStep(),
215 "dt is too large. Resetting to maximum dt.");
219 metaData->setOrder(order);
226 const Teuchos::RCP<Teuchos::ParameterList> & pList)
override
228 if (pList == Teuchos::null) {
230 if (
tscsPL_ == Teuchos::null) {
231 tscsPL_ = Teuchos::parameterList(
"TimeStepControlStrategyBasicVS");
239 TEUCHOS_TEST_FOR_EXCEPTION(
getAmplFactor() <= 1.0, std::out_of_range,
240 "Error - Invalid value of Amplification Factor = " <<
getAmplFactor()
241 <<
"! \n" <<
"Amplification Factor must be > 1.0.\n");
243 TEUCHOS_TEST_FOR_EXCEPTION(
getReductFactor() >= 1.0, std::out_of_range,
245 <<
"! \n" <<
"Reduction Factor must be < 1.0.\n");
248 "Error - Invalid values of 'Minimum Value Monitoring Function' = "
249 <<
getMinEta() <<
"\n and 'Maximum Value Monitoring Function' = "
250 <<
getMaxEta() <<
"! \n Mininum Value cannot be > Maximum Value! \n");
254 Teuchos::RCP<const Teuchos::ParameterList>
256 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
260 pl->set<
double>(
"Amplification Factor", 1.75,
"Amplification factor");
261 pl->set<
double>(
"Reduction Factor" , 0.5 ,
"Reduction factor");
264 pl->set<
double>(
"Minimum Value Monitoring Function", 0.0 ,
"Min value eta");
265 pl->set<
double>(
"Maximum Value Monitoring Function", 1.0e-16,
"Max value eta");
266 pl->set<std::string>(
"Name",
"Basic VS");
275 Teuchos::RCP<Teuchos::ParameterList> temp_plist =
tscsPL_;
282 {
return tscsPL_->get<
double>(
"Amplification Factor"); }
284 {
return tscsPL_->get<
double>(
"Reduction Factor");}
286 {
return tscsPL_->get<
double>(
"Minimum Value Monitoring Function"); }
288 {
return tscsPL_->get<
double>(
"Maximum Value Monitoring Function"); }
291 {
tscsPL_->set<
double>(
"Amplification Factor", rho); }
293 {
tscsPL_->set<
double>(
"Reduction Factor", sigma); }
295 {
tscsPL_->set<
double>(
"Minimum Value Monitoring Function", minEta); }
297 {
tscsPL_->set<
double>(
"Maximum Value Monitoring Function", maxEta); }
304 const double eps = 1.0e4*std::numeric_limits<double>::epsilon();
305 RCP<Teuchos::FancyOStream> out = tsc.getOStream();
312 RCP<const Thyra::VectorBase<Scalar> > xOld =
314 RCP<const Thyra::VectorBase<Scalar> > x =
318 #ifdef VERBOSE_DEBUG_OUTPUT
319 Teuchos::Range1D range;
320 *out <<
"\n*** xOld ***\n";
321 RTOpPack::ConstSubVectorView<Scalar> xOldv;
322 xOld->acquireDetachedView(range, &xOldv);
323 auto xoa = xOldv.values();
324 for (
auto i = 0; i < xoa.size(); ++i) *out << xoa[i] <<
" ";
325 *out <<
"\n*** xOld ***\n";
326 *out <<
"\n*** x ***\n";
327 RTOpPack::ConstSubVectorView<Scalar> xv;
328 x->acquireDetachedView(range, &xv);
329 auto xa = xv.values();
330 for (
auto i = 0; i < xa.size(); ++i) *out << xa[i] <<
" ";
331 *out <<
"\n*** x ***\n";
334 RCP<Thyra::VectorBase<Scalar> > xDiff = Thyra::createMember(x->space());
335 Thyra::V_VmV(xDiff.ptr(), *x, *xOld);
336 Scalar xDiffNorm = Thyra::norm(*xDiff);
337 Scalar xOldNorm = Thyra::norm(*xOld);
339 eta = xDiffNorm/(xOldNorm + eps);
340 #ifdef VERBOSE_DEBUG_OUTPUT
341 Scalar xNorm = Thyra::norm(*x);
342 *out <<
"IKT xDiffNorm, xNorm, xOldNorm, eta = " << xDiffNorm <<
", "
343 << xNorm <<
", " << xOldNorm <<
", " << eta <<
"\n";
352 #endif // Tempus_TimeStepControlStrategy_BasicVS_hpp
virtual void setMaxEta(Scalar maxEta)
Scalar computeEta(const TimeStepControl< Scalar > tsc, const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
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 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)
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
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.