9 #ifndef Tempus_StepperHHTAlpha_impl_hpp
10 #define Tempus_StepperHHTAlpha_impl_hpp
12 #include "Tempus_config.hpp"
14 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
15 #include "NOX_Thyra.H"
23 template<
class Scalar>
class StepperFactory;
26 template<
class Scalar>
29 const Thyra::VectorBase<Scalar>& v,
30 const Thyra::VectorBase<Scalar>& a,
31 const Scalar dt)
const
33 #ifdef VERBOSE_DEBUG_OUTPUT
34 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
37 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0, v, dt*(1.0-gamma_), a);
40 template<
class Scalar>
43 const Thyra::VectorBase<Scalar>& d,
44 const Thyra::VectorBase<Scalar>& v,
45 const Thyra::VectorBase<Scalar>& a,
46 const Scalar dt)
const
48 #ifdef VERBOSE_DEBUG_OUTPUT
49 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
52 Scalar aConst = dt*dt/2.0*(1.0-2.0*beta_);
53 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), dt, v, aConst, a);
55 Thyra::Vp_V(Teuchos::ptrFromRef(dPred), d, 1.0);
59 template<
class Scalar>
62 const Thyra::VectorBase<Scalar>& v)
const
64 #ifdef VERBOSE_DEBUG_OUTPUT
65 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
68 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0-alpha_f_, vPred, alpha_f_, v);
72 template<
class Scalar>
75 const Thyra::VectorBase<Scalar>& d)
const
77 #ifdef VERBOSE_DEBUG_OUTPUT
78 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
81 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), 1.0-alpha_f_, dPred, alpha_f_, d);
84 template<
class Scalar>
87 const Thyra::VectorBase<Scalar>& a_n)
const
89 #ifdef VERBOSE_DEBUG_OUTPUT
90 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
92 Scalar c = 1.0/(1.0-alpha_m_);
94 Thyra::V_StVpStV(Teuchos::ptrFromRef(a_n_plus1), c, a_n_plus1, -c*alpha_m_, a_n);
99 template<
class Scalar>
102 const Thyra::VectorBase<Scalar>& vPred,
103 const Thyra::VectorBase<Scalar>& a,
104 const Scalar dt)
const
106 #ifdef VERBOSE_DEBUG_OUTPUT
107 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
110 Thyra::V_StVpStV(Teuchos::ptrFromRef(v), 1.0, vPred, dt*gamma_, a);
113 template<
class Scalar>
116 const Thyra::VectorBase<Scalar>& dPred,
117 const Thyra::VectorBase<Scalar>& a,
118 const Scalar dt)
const
120 #ifdef VERBOSE_DEBUG_OUTPUT
121 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
124 Thyra::V_StVpStV(Teuchos::ptrFromRef(d), 1.0, dPred, beta_*dt*dt, a);
129 template<
class Scalar>
132 if (schemeName_ !=
"Newmark Beta User Defined") {
133 *out_ <<
"\nWARNING: schemeName != 'Newmark Beta User Defined' (= '"
134 << schemeName_ <<
"').\n"
135 <<
" Leaving as beta = " << beta_ <<
"!\n";
142 *out_ <<
"\nWARNING: Running (implicit implementation of) Newmark "
143 <<
"Implicit a-Form Stepper with Beta = 0.0, which \n"
144 <<
"specifies an explicit scheme. Mass lumping is not possible, "
145 <<
"so this will be slow! To run explicit \n"
146 <<
"implementation of Newmark Implicit a-Form Stepper, please "
147 <<
"re-run with 'Stepper Type' = 'Newmark Explicit a-Form'.\n"
148 <<
"This stepper allows for mass lumping when called through "
149 <<
"Piro::TempusSolver.\n";
152 TEUCHOS_TEST_FOR_EXCEPTION( (beta_ > 1.0) || (beta_ < 0.0),
154 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Beta = "
155 << beta_ <<
". Please select Beta >= 0 and <= 1. \n");
157 this->isInitialized_ =
false;
161 template<
class Scalar>
164 if (schemeName_ !=
"Newmark Beta User Defined") {
165 *out_ <<
"\nWARNING: schemeName != 'Newmark Beta User Defined' (= '"
166 << schemeName_ <<
"').\n"
167 <<
" Leaving as gamma = " << gamma_ <<
"!\n";
173 TEUCHOS_TEST_FOR_EXCEPTION( (gamma_ > 1.0) || (gamma_ < 0.0),
175 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Gamma ="
176 <<gamma_ <<
". Please select Gamma >= 0 and <= 1. \n");
178 this->isInitialized_ =
false;
182 template<
class Scalar>
187 TEUCHOS_TEST_FOR_EXCEPTION( (alpha_f_ > 1.0) || (alpha_f_ < 0.0),
189 "\nError in 'HHT-Alpha' stepper: invalid value of Alpha_f = "
190 << alpha_f_ <<
". Please select Alpha_f >= 0 and <= 1. \n");
192 this->isInitialized_ =
false;
196 template<
class Scalar>
201 TEUCHOS_TEST_FOR_EXCEPTION( (alpha_m_ >= 1.0) || (alpha_m_ < 0.0),
203 "\nError in 'HHT-Alpha' stepper: invalid value of Alpha_m = "
204 << alpha_m_ <<
". Please select Alpha_m >= 0 and < 1. \n");
206 this->isInitialized_ =
false;
210 template<
class Scalar>
212 std::string schemeName)
214 schemeName_ = schemeName;
216 if (schemeName_ ==
"Newmark Beta Average Acceleration") {
217 beta_= 0.25; gamma_ = 0.5;
219 else if (schemeName_ ==
"Newmark Beta Linear Acceleration") {
220 beta_= 0.25; gamma_ = 1.0/6.0;
222 else if (schemeName_ ==
"Newmark Beta Central Difference") {
223 beta_= 0.0; gamma_ = 0.5;
225 else if (schemeName_ ==
"Newmark Beta User Defined") {
226 beta_= 0.25; gamma_ = 0.5;
229 TEUCHOS_TEST_FOR_EXCEPTION(
true,
231 "\nError in Tempus::StepperHHTAlpha! "
232 <<
"Invalid Scheme Name = " << schemeName_ <<
". \n"
233 <<
"Valid Scheme Names are: 'Newmark Beta Average Acceleration', "
234 <<
"'Newmark Beta Linear Acceleration', \n"
235 <<
"'Newmark Beta Central Difference' and 'Newmark Beta User Defined'.\n");
238 this->isInitialized_ =
false;
242 template<
class Scalar>
244 out_(Teuchos::VerboseObjectBase::getDefaultOStream())
246 #ifdef VERBOSE_DEBUG_OUTPUT
247 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
264 template<
class Scalar>
266 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
268 const Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
270 std::string ICConsistency,
271 bool ICConsistencyCheck,
272 bool zeroInitialGuess,
273 std::string schemeName,
278 : out_(Teuchos::VerboseObjectBase::getDefaultOStream())
286 if (schemeName ==
"Newmark Beta User Defined") {
296 if (appModel != Teuchos::null) {
303 template<
class Scalar>
305 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel)
307 #ifdef VERBOSE_DEBUG_OUTPUT
308 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
311 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
314 this->wrapperModel_ = wrapperModel;
316 TEUCHOS_TEST_FOR_EXCEPTION(this->solver_ == Teuchos::null, std::logic_error,
317 "Error - Solver is not set!\n");
318 if (this->wrapperModel_ != Teuchos::null)
319 this->solver_->setModel(this->wrapperModel_);
321 this->isInitialized_ =
false;
325 template<
class Scalar>
329 #ifdef VERBOSE_DEBUG_OUTPUT
330 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
332 this->checkInitialized();
336 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperHHTAlpha::takeStep()");
338 TEUCHOS_TEST_FOR_EXCEPTION(solutionHistory->getNumStates() < 2,
340 "Error - StepperHHTAlpha<Scalar>::takeStep(...)\n"
341 "Need at least two SolutionStates for HHTAlpha.\n"
342 " Number of States = " << solutionHistory->getNumStates() <<
"\n"
343 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
344 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
346 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
347 RCP<SolutionState<Scalar> > currentState=solutionHistory->getCurrentState();
349 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
351 this->wrapperModel_);
354 RCP<const Thyra::VectorBase<Scalar> > d_old = currentState->getX();
355 RCP<const Thyra::VectorBase<Scalar> > v_old = currentState->getXDot();
356 RCP<Thyra::VectorBase<Scalar> > a_old = currentState->getXDotDot();
361 *out_ <<
"IKT d_old = " << Thyra::max(*d_old) <<
"\n";
362 *out_ <<
"IKT v_old = " << Thyra::max(*v_old) <<
"\n";
367 RCP<Thyra::VectorBase<Scalar> > d_new = workingState->getX();
368 RCP<Thyra::VectorBase<Scalar> > v_new = workingState->getXDot();
369 RCP<Thyra::VectorBase<Scalar> > a_new = workingState->getXDotDot();
372 const Scalar time = currentState->getTime();
373 const Scalar dt = workingState->getTimeStep();
379 if (time == solutionHistory->minTime()) {
380 RCP<Thyra::VectorBase<Scalar> > d_init = Thyra::createMember(d_old->space());
381 RCP<Thyra::VectorBase<Scalar> > v_init = Thyra::createMember(v_old->space());
382 RCP<Thyra::VectorBase<Scalar> > a_init = Thyra::createMember(a_old->space());
383 Thyra::copy(*d_old, d_init.ptr());
384 Thyra::copy(*v_old, v_init.ptr());
385 if (this->initialGuess_ != Teuchos::null) {
387 bool is_compatible = (a_init->space())->isCompatible(*this->initialGuess_->space());
388 TEUCHOS_TEST_FOR_EXCEPTION(
389 is_compatible !=
true, std::logic_error,
390 "Error in Tempus::NemwarkImplicitAForm takeStep(): user-provided initial guess'!\n"
391 <<
"for Newton is not compatible with solution vector!\n");
392 Thyra::copy(*this->initialGuess_, a_init.ptr());
395 Thyra::put_scalar(0.0, a_init.ptr());
397 wrapperModel->initializeNewmark(v_init,d_init,0.0,time,beta_,gamma_);
398 const Thyra::SolveStatus<Scalar> sStatus=this->solveImplicitODE(a_init);
400 workingState->setSolutionStatus(sStatus);
401 Thyra::copy(*a_init, a_old.ptr());
405 *out_ <<
"IKT a_old = " << Thyra::max(*a_old) <<
"\n";
410 RCP<Thyra::VectorBase<Scalar> > d_pred =Thyra::createMember(d_old->space());
411 RCP<Thyra::VectorBase<Scalar> > v_pred =Thyra::createMember(v_old->space());
414 predictDisplacement(*d_pred, *d_old, *v_old, *a_old, dt);
415 predictVelocity(*v_pred, *v_old, *a_old, dt);
418 predictDisplacement_alpha_f(*d_pred, *d_old);
419 predictVelocity_alpha_f(*v_pred, *v_old);
422 wrapperModel->initializeNewmark(v_pred,d_pred,dt,t,beta_,gamma_);
425 const Thyra::SolveStatus<Scalar> sStatus = this->solveImplicitODE(a_new);
428 correctAcceleration(*a_new, *a_old);
431 correctVelocity(*v_new, *v_pred, *a_new, dt);
432 correctDisplacement(*d_new, *d_pred, *a_new, dt);
434 workingState->setSolutionStatus(sStatus);
435 workingState->setOrder(this->getOrder());
436 workingState->computeNorms(currentState);
449 template<
class Scalar>
450 Teuchos::RCP<Tempus::StepperState<Scalar> >
454 #ifdef VERBOSE_DEBUG_OUTPUT
455 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
457 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
463 template<
class Scalar>
465 Teuchos::FancyOStream &out,
466 const Teuchos::EVerbosityLevel verbLevel)
const
468 #ifdef VERBOSE_DEBUG_OUTPUT
469 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
476 out <<
"--- StepperHHTAlpha ---\n";
477 out <<
" schemeName_ = " << schemeName_ << std::endl;
478 out <<
" beta_ = " << beta_ << std::endl;
479 out <<
" gamma_ = " << gamma_ << std::endl;
480 out <<
" alpha_f_ = " << alpha_f_ << std::endl;
481 out <<
" alpha_m_ = " << alpha_m_ << std::endl;
482 out <<
"-----------------------" << std::endl;
486 template<
class Scalar>
489 bool isValidSetup =
true;
494 if (this->wrapperModel_->getAppModel() == Teuchos::null) {
495 isValidSetup =
false;
496 out <<
"The application ModelEvaluator is not set!\n";
499 if (this->wrapperModel_ == Teuchos::null) {
500 isValidSetup =
false;
501 out <<
"The wrapper ModelEvaluator is not set!\n";
504 if (this->solver_ == Teuchos::null) {
505 isValidSetup =
false;
506 out <<
"The solver is not set!\n";
513 template<
class Scalar>
514 Teuchos::RCP<const Teuchos::ParameterList>
517 #ifdef VERBOSE_DEBUG_OUTPUT
518 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
520 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
522 pl->set<std::string>(
"Scheme Name",
"Newmark Beta Average Acceleration");
523 pl->set<
double> (
"Beta", 0.25);
524 pl->set<
double> (
"Gamma", 0.5 );
525 pl->set<
double> (
"Alpha_f", 0.0 );
526 pl->set<
double> (
"Alpha_m", 0.0 );
527 pl->set<std::string>(
"Solver Name",
"Default Solver");
528 pl->set<
bool> (
"Zero Initial Guess",
false);
530 pl->set(
"Default Solver", *solverPL);
537 #endif // Tempus_StepperHHTAlpha_impl_hpp
void setBeta(Scalar beta)
void correctDisplacement(Thyra::VectorBase< Scalar > &d, const Thyra::VectorBase< Scalar > &dPred, const Thyra::VectorBase< Scalar > &a, const Scalar dt) const
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
void correctVelocity(Thyra::VectorBase< Scalar > &v, const Thyra::VectorBase< Scalar > &vPred, const Thyra::VectorBase< Scalar > &a, const Scalar dt) const
void correctAcceleration(Thyra::VectorBase< Scalar > &a_n_plus1, const Thyra::VectorBase< Scalar > &a_n) const
virtual bool getICConsistencyCheckDefault() const
void setAlphaF(Scalar alpha_f)
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
virtual std::string getICConsistencyDefault() const
virtual void initialize()
Initialize after construction and changing input parameters.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
StepperHHTAlpha()
Default constructor.
A ModelEvaluator for residual evaluations given a state. This ModelEvaluator takes a state...
Thyra Base interface for time steppers.
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > >=Teuchos::null)
Set Observer.
StepperState is a simple class to hold state information about the stepper.
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver)
Set solver.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void setDefaultSolver()
void setAlphaM(Scalar alpha_m)
void predictVelocity_alpha_f(Thyra::VectorBase< Scalar > &vPred, const Thyra::VectorBase< Scalar > &v) const
void setICConsistencyCheck(bool c)
void setSchemeName(std::string schemeName)
StepperObserver class for Stepper class.
virtual void setZeroInitialGuess(bool zIG)
Set parameter so that the initial guess is set to zero (=True) or use last timestep (=False)...
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
void predictDisplacement_alpha_f(Thyra::VectorBase< Scalar > &dPred, const Thyra::VectorBase< Scalar > &d) const
void predictDisplacement(Thyra::VectorBase< Scalar > &dPred, const Thyra::VectorBase< Scalar > &d, const Thyra::VectorBase< Scalar > &v, const Thyra::VectorBase< Scalar > &a, const Scalar dt) const
void validSecondOrderODE_DAE(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Validate ME supports 2nd order implicit ODE/DAE evaluation, f(xdotdot,xdot,x,t) [= 0]...
Teuchos::RCP< Teuchos::FancyOStream > out_
void predictVelocity(Thyra::VectorBase< Scalar > &vPred, const Thyra::VectorBase< Scalar > &v, const Thyra::VectorBase< Scalar > &a, const Scalar dt) const
void setGamma(Scalar gamma)
virtual bool getUseFSALDefault() const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void getValidParametersBasic(Teuchos::RCP< Teuchos::ParameterList > pl, std::string stepperType)
Provide basic parameters to Steppers.
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
void setStepperType(std::string s)
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
void setICConsistency(std::string s)