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"
104 template<
class Scalar>
112 Teuchos::RCP<Teuchos::ParameterList> pList = Teuchos::null){
126 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
127 RCP<SolutionStateMetaData<Scalar> > metaData = workingState->getMetaData();
128 const Scalar errorAbs = metaData->getErrorAbs();
129 const Scalar errorRel = metaData->getErrorRel();
130 const int iStep = metaData->getIStep();
131 int order = metaData->getOrder();
132 Scalar dt = metaData->getDt();
134 Teuchos::as<int>(Teuchos::VERB_NONE);
136 RCP<Teuchos::FancyOStream> out = tsc.getOStream();
137 Teuchos::OSTab ostab(out,0,
"getNextTimeStep");
139 auto changeDT = [] (
int istep, Scalar dt_old, Scalar dt_new,
142 std::stringstream message;
143 message << std::scientific
144 <<std::setw(6)<<std::setprecision(3)<<istep
145 <<
" * (dt = "<<std::setw(9)<<std::setprecision(3)<<dt_old
146 <<
", new = "<<std::setw(9)<<std::setprecision(3)<<dt_new
147 <<
") " << reason << std::endl;
148 return message.str();
157 if (printChanges) *out << changeDT(iStep, dt, dt*sigma,
158 "Stepper failure - Decreasing dt.");
163 if (printChanges) *out << changeDT(iStep, dt, dt*rho,
164 "Monitoring Value (eta) is too small ("
165 + std::to_string(eta) +
" < " + std::to_string(
getMinEta())
166 +
"). Increasing dt.");
170 if (printChanges) *out << changeDT(iStep, dt, dt*sigma,
171 "Monitoring Value (eta) is too large ("
172 + std::to_string(eta) +
" > " + std::to_string(
getMaxEta())
173 +
"). Decreasing dt.");
177 if (printChanges) *out << changeDT(iStep, dt, dt*sigma,
178 "Absolute error is too large ("
179 + std::to_string(errorAbs)+
" > "+std::to_string(tsc.
getMaxAbsError())
180 +
"). Decreasing dt.");
184 if (printChanges) *out << changeDT(iStep, dt, dt*sigma,
185 "Relative error is too large ("
186 + std::to_string(errorRel)+
" > "+std::to_string(tsc.
getMaxRelError())
187 +
"). Decreasing dt.");
191 if (printChanges) *out << changeDT(iStep, dt, dt*rho,
192 "Order is too small ("
193 + std::to_string(order) +
" < " + std::to_string(tsc.
getMinOrder())
194 +
"). Increasing dt.");
198 if (printChanges) *out << changeDT(iStep, dt, dt*sigma,
199 "Order is too large ("
200 + std::to_string(order) +
" > " + std::to_string(tsc.
getMaxOrder())
201 +
"). Decreasing dt.");
207 if (printChanges) *out << changeDT(iStep, dt, tsc.
getMinTimeStep(),
208 "dt is too small. Resetting to minimum dt.");
212 if (printChanges) *out << changeDT(iStep, dt, tsc.
getMaxTimeStep(),
213 "dt is too large. Resetting to maximum dt.");
217 metaData->setOrder(order);
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"); }
293 const double eps = 1.0e4*std::numeric_limits<double>::epsilon();
294 RCP<Teuchos::FancyOStream> out = tsc.getOStream();
301 RCP<const Thyra::VectorBase<Scalar> > xOld = (*solutionHistory)[numStates-3]->getX();
302 RCP<const Thyra::VectorBase<Scalar> > x = (*solutionHistory)[numStates-1]->getX();
305 #ifdef VERBOSE_DEBUG_OUTPUT
306 Teuchos::Range1D range;
307 *out <<
"\n*** xOld ***\n";
308 RTOpPack::ConstSubVectorView<Scalar> xOldv;
309 xOld->acquireDetachedView(range, &xOldv);
310 auto xoa = xOldv.values();
311 for (
auto i = 0; i < xoa.size(); ++i) *out << xoa[i] <<
" ";
312 *out <<
"\n*** xOld ***\n";
313 *out <<
"\n*** x ***\n";
314 RTOpPack::ConstSubVectorView<Scalar> xv;
315 x->acquireDetachedView(range, &xv);
316 auto xa = xv.values();
317 for (
auto i = 0; i < xa.size(); ++i) *out << xa[i] <<
" ";
318 *out <<
"\n*** x ***\n";
321 RCP<Thyra::VectorBase<Scalar> > xDiff = Thyra::createMember(x->space());
322 Thyra::V_VmV(xDiff.ptr(), *x, *xOld);
323 Scalar xDiffNorm = Thyra::norm(*xDiff);
324 Scalar xOldNorm = Thyra::norm(*xOld);
326 eta = xDiffNorm/(xOldNorm + eps);
327 #ifdef VERBOSE_DEBUG_OUTPUT
328 *out <<
"IKT xDiffNorm, xOldNorm, eta = " << xDiffNorm <<
", " << xOldNorm
329 <<
", " << eta <<
"\n";
338 #endif // Tempus_TimeStepControlStrategy_BasicVS_hpp
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
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...
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 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.