9 #ifndef Tempus_StepperHHTAlpha_impl_hpp
10 #define Tempus_StepperHHTAlpha_impl_hpp
12 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
22 template<
class Scalar>
27 const Scalar dt)
const
29 #ifdef VERBOSE_DEBUG_OUTPUT
30 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
33 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0, v, dt*(1.0-gamma_), a);
36 template<
class Scalar>
42 const Scalar dt)
const
44 #ifdef VERBOSE_DEBUG_OUTPUT
45 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
48 Scalar aConst = dt*dt/2.0*(1.0-2.0*beta_);
49 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), dt, v, aConst, a);
51 Thyra::Vp_V(Teuchos::ptrFromRef(dPred), d, 1.0);
55 template<
class Scalar>
60 #ifdef VERBOSE_DEBUG_OUTPUT
61 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
64 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0-alpha_f_, vPred, alpha_f_, v);
68 template<
class Scalar>
73 #ifdef VERBOSE_DEBUG_OUTPUT
74 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
77 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), 1.0-alpha_f_, dPred, alpha_f_, d);
80 template<
class Scalar>
85 #ifdef VERBOSE_DEBUG_OUTPUT
86 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
88 Scalar c = 1.0/(1.0-alpha_m_);
90 Thyra::V_StVpStV(Teuchos::ptrFromRef(a_n_plus1), c, a_n_plus1, -c*alpha_m_, a_n);
95 template<
class Scalar>
100 const Scalar dt)
const
102 #ifdef VERBOSE_DEBUG_OUTPUT
103 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
106 Thyra::V_StVpStV(Teuchos::ptrFromRef(v), 1.0, vPred, dt*gamma_, a);
109 template<
class Scalar>
114 const Scalar dt)
const
116 #ifdef VERBOSE_DEBUG_OUTPUT
117 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
120 Thyra::V_StVpStV(Teuchos::ptrFromRef(d), 1.0, dPred, beta_*dt*dt, a);
125 template<
class Scalar>
128 if (schemeName_ !=
"Newmark Beta User Defined") {
129 out_->setOutputToRootOnly(0);
130 *out_ <<
"\nWARNING: schemeName != 'Newmark Beta User Defined' (= '"
131 << schemeName_ <<
"').\n"
132 <<
" Leaving as beta = " << beta_ <<
"!\n";
139 out_->setOutputToRootOnly(0);
140 *out_ <<
"\nWARNING: Running (implicit implementation of) Newmark "
141 <<
"Implicit a-Form Stepper with Beta = 0.0, which \n"
142 <<
"specifies an explicit scheme. Mass lumping is not possible, "
143 <<
"so this will be slow! To run explicit \n"
144 <<
"implementation of Newmark Implicit a-Form Stepper, please "
145 <<
"re-run with 'Stepper Type' = 'Newmark Explicit a-Form'.\n"
146 <<
"This stepper allows for mass lumping when called through "
147 <<
"Piro::TempusSolver.\n";
152 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Beta = "
153 << beta_ <<
". Please select Beta >= 0 and <= 1. \n");
155 this->isInitialized_ =
false;
159 template<
class Scalar>
162 if (schemeName_ !=
"Newmark Beta User Defined") {
163 out_->setOutputToRootOnly(0);
164 *out_ <<
"\nWARNING: schemeName != 'Newmark Beta User Defined' (= '"
165 << schemeName_ <<
"').\n"
166 <<
" Leaving as gamma = " << gamma_ <<
"!\n";
174 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Gamma ="
175 <<gamma_ <<
". Please select Gamma >= 0 and <= 1. \n");
177 this->isInitialized_ =
false;
181 template<
class Scalar>
188 "\nError in 'HHT-Alpha' stepper: invalid value of Alpha_f = "
189 << alpha_f_ <<
". Please select Alpha_f >= 0 and <= 1. \n");
191 this->isInitialized_ =
false;
195 template<
class Scalar>
202 "\nError in 'HHT-Alpha' stepper: invalid value of Alpha_m = "
203 << alpha_m_ <<
". Please select Alpha_m >= 0 and < 1. \n");
205 this->isInitialized_ =
false;
209 template<
class Scalar>
211 std::string schemeName)
213 schemeName_ = schemeName;
215 if (schemeName_ ==
"Newmark Beta Average Acceleration") {
216 beta_= 0.25; gamma_ = 0.5;
218 else if (schemeName_ ==
"Newmark Beta Linear Acceleration") {
219 beta_= 0.25; gamma_ = 1.0/6.0;
221 else if (schemeName_ ==
"Newmark Beta Central Difference") {
222 beta_= 0.0; gamma_ = 0.5;
224 else if (schemeName_ ==
"Newmark Beta User Defined") {
225 beta_= 0.25; gamma_ = 0.5;
230 "\nError in Tempus::StepperHHTAlpha! "
231 <<
"Invalid Scheme Name = " << schemeName_ <<
". \n"
232 <<
"Valid Scheme Names are: 'Newmark Beta Average Acceleration', "
233 <<
"'Newmark Beta Linear Acceleration', \n"
234 <<
"'Newmark Beta Central Difference' and 'Newmark Beta User Defined'.\n");
237 this->isInitialized_ =
false;
240 template<
class Scalar>
242 out_(Teuchos::VerboseObjectBase::getDefaultOStream())
244 #ifdef VERBOSE_DEBUG_OUTPUT
245 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
261 template<
class Scalar>
266 std::string ICConsistency,
267 bool ICConsistencyCheck,
268 bool zeroInitialGuess,
269 std::string schemeName,
275 : out_(Teuchos::VerboseObjectBase::getDefaultOStream())
284 if (schemeName ==
"Newmark Beta User Defined") {
293 if (appModel != Teuchos::null) {
299 template<
class Scalar>
303 if (appAction == Teuchos::null) {
305 stepperHHTAlphaAppAction_ =
309 stepperHHTAlphaAppAction_ = appAction;
313 template<
class Scalar>
317 #ifdef VERBOSE_DEBUG_OUTPUT
318 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
324 this->wrapperModel_ = wrapperModel;
327 "Error - Solver is not set!\n");
328 if (this->wrapperModel_ != Teuchos::null)
329 this->solver_->setModel(this->wrapperModel_);
331 this->isInitialized_ =
false;
335 template<
class Scalar>
339 #ifdef VERBOSE_DEBUG_OUTPUT
340 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
342 this->checkInitialized();
346 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperHHTAlpha::takeStep()");
350 "Error - StepperHHTAlpha<Scalar>::takeStep(...)\n"
351 "Need at least two SolutionStates for HHTAlpha.\n"
352 " Number of States = " << solutionHistory->getNumStates() <<
"\n"
353 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
354 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
356 RCP<StepperHHTAlpha<Scalar> > thisStepper = Teuchos::rcpFromRef(*
this);
357 stepperHHTAlphaAppAction_->execute(solutionHistory, thisStepper,
360 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
361 RCP<SolutionState<Scalar> > currentState=solutionHistory->getCurrentState();
365 this->wrapperModel_);
368 RCP<const Thyra::VectorBase<Scalar> > d_old = currentState->getX();
369 RCP<const Thyra::VectorBase<Scalar> > v_old = currentState->getXDot();
370 RCP<Thyra::VectorBase<Scalar> > a_old = currentState->getXDotDot();
375 *out_ <<
"IKT d_old = " << Thyra::max(*d_old) <<
"\n";
376 *out_ <<
"IKT v_old = " << Thyra::max(*v_old) <<
"\n";
381 RCP<Thyra::VectorBase<Scalar> > d_new = workingState->getX();
382 RCP<Thyra::VectorBase<Scalar> > v_new = workingState->getXDot();
383 RCP<Thyra::VectorBase<Scalar> > a_new = workingState->getXDotDot();
386 const Scalar time = currentState->getTime();
387 const Scalar dt = workingState->getTimeStep();
393 if (time == solutionHistory->minTime()) {
394 RCP<Thyra::VectorBase<Scalar> > d_init = Thyra::createMember(d_old->space());
395 RCP<Thyra::VectorBase<Scalar> > v_init = Thyra::createMember(v_old->space());
396 RCP<Thyra::VectorBase<Scalar> > a_init = Thyra::createMember(a_old->space());
397 Thyra::copy(*d_old, d_init.ptr());
398 Thyra::copy(*v_old, v_init.ptr());
399 if (this->initialGuess_ != Teuchos::null) {
401 bool is_compatible = (a_init->space())->isCompatible(*this->initialGuess_->space());
403 is_compatible !=
true, std::logic_error,
404 "Error in Tempus::NemwarkImplicitAForm takeStep(): user-provided initial guess'!\n"
405 <<
"for Newton is not compatible with solution vector!\n");
406 Thyra::copy(*this->initialGuess_, a_init.ptr());
409 Thyra::put_scalar(0.0, a_init.ptr());
411 wrapperModel->initializeNewmark(v_init,d_init,0.0,time,beta_,gamma_);
414 workingState->setSolutionStatus(sStatus);
415 Thyra::copy(*a_init, a_old.ptr());
419 *out_ <<
"IKT a_old = " << Thyra::max(*a_old) <<
"\n";
423 RCP<Thyra::VectorBase<Scalar> > d_pred =Thyra::createMember(d_old->space());
424 RCP<Thyra::VectorBase<Scalar> > v_pred =Thyra::createMember(v_old->space());
427 predictDisplacement(*d_pred, *d_old, *v_old, *a_old, dt);
428 predictVelocity(*v_pred, *v_old, *a_old, dt);
431 predictDisplacement_alpha_f(*d_pred, *d_old);
432 predictVelocity_alpha_f(*v_pred, *v_old);
435 wrapperModel->initializeNewmark(v_pred,d_pred,dt,t,beta_,gamma_);
438 stepperHHTAlphaAppAction_->execute(solutionHistory, thisStepper,
444 stepperHHTAlphaAppAction_->execute(solutionHistory, thisStepper,
448 correctAcceleration(*a_new, *a_old);
451 correctVelocity(*v_new, *v_pred, *a_new, dt);
452 correctDisplacement(*d_new, *d_pred, *a_new, dt);
454 workingState->setSolutionStatus(sStatus);
455 workingState->setOrder(this->getOrder());
456 workingState->computeNorms(currentState);
458 stepperHHTAlphaAppAction_->execute(solutionHistory, thisStepper,
472 template<
class Scalar>
477 #ifdef VERBOSE_DEBUG_OUTPUT
478 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
486 template<
class Scalar>
492 #ifdef VERBOSE_DEBUG_OUTPUT
493 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
500 auto l_out = Teuchos::fancyOStream( out.
getOStream() );
501 l_out->setOutputToRootOnly(0);
502 *l_out <<
"--- StepperHHTAlpha ---\n";
503 *l_out <<
" schemeName_ = " << schemeName_ << std::endl;
504 *l_out <<
" beta_ = " << beta_ << std::endl;
505 *l_out <<
" gamma_ = " << gamma_ << std::endl;
506 *l_out <<
" alpha_f_ = " << alpha_f_ << std::endl;
507 *l_out <<
" alpha_m_ = " << alpha_m_ << std::endl;
508 *l_out <<
"-----------------------" << std::endl;
512 template<
class Scalar>
515 bool isValidSetup =
true;
520 if (this->wrapperModel_->getAppModel() == Teuchos::null) {
521 isValidSetup =
false;
522 out <<
"The application ModelEvaluator is not set!\n";
525 if (this->wrapperModel_ == Teuchos::null) {
526 isValidSetup =
false;
527 out <<
"The wrapper ModelEvaluator is not set!\n";
530 if (this->solver_ == Teuchos::null) {
531 isValidSetup =
false;
532 out <<
"The solver is not set!\n";
539 template<
class Scalar>
543 #ifdef VERBOSE_DEBUG_OUTPUT
544 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
546 auto pl = this->getValidParametersBasicImplicit();
548 auto hhtalphaPL = Teuchos::parameterList(
"HHT-Alpha Parameters");
549 hhtalphaPL->set<std::string>(
"Scheme Name", schemeName_);
550 hhtalphaPL->set<
double> (
"Beta", beta_);
551 hhtalphaPL->set<
double> (
"Gamma", gamma_ );
552 hhtalphaPL->set<
double> (
"Alpha_f", alpha_f_ );
553 hhtalphaPL->set<
double> (
"Alpha_m", alpha_m_ );
554 pl->set(
"HHT-Alpha Parameters", *hhtalphaPL);
562 template<
class Scalar>
569 stepper->setStepperImplicitValues(pl);
571 if (pl != Teuchos::null) {
572 if (pl->
isSublist(
"HHT-Alpha Parameters")) {
573 auto hhtalphaPL = pl->
sublist(
"HHT-Alpha Parameters",
true);
574 std::string schemeName =
575 hhtalphaPL.
get<std::string>(
"Scheme Name",
"Newmark Beta Average Acceleration");
576 stepper->setSchemeName(schemeName);
577 if (schemeName ==
"Newmark Beta User Defined") {
578 stepper->setBeta (hhtalphaPL.get<
double>(
"Beta", 0.25));
579 stepper->setGamma(hhtalphaPL.get<
double>(
"Gamma", 0.5 ));
581 stepper->setAlphaF(hhtalphaPL.get<
double>(
"Alpha_f", 0.0));
582 stepper->setAlphaM(hhtalphaPL.get<
double>(
"Alpha_m", 0.0));
584 stepper->setSchemeName(
"Newmark Beta Average Acceleration");
585 stepper->setAlphaF(0.0);
586 stepper->setAlphaM(0.0);
590 if (model != Teuchos::null) {
591 stepper->setModel(model);
592 stepper->initialize();
600 #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
T & get(const std::string &name, T def_value)
Application Action for HHT Alpha.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void setStepperName(std::string s)
Set the stepper name.
void correctAcceleration(Thyra::VectorBase< Scalar > &a_n_plus1, const Thyra::VectorBase< Scalar > &a_n) const
void setAlphaF(Scalar alpha_f)
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.
StepperState is a simple class to hold state information about the stepper.
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver)
Set solver.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
bool isSublist(const std::string &name) 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)
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...
Default modifier for StepperHHTAlpha.
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
Teuchos::RCP< StepperHHTAlpha< Scalar > > createStepperHHTAlpha(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
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_
RCP< std::basic_ostream< char_type, traits_type > > getOStream()
void predictVelocity(Thyra::VectorBase< Scalar > &vPred, const Thyra::VectorBase< Scalar > &v, const Thyra::VectorBase< Scalar > &a, const Scalar dt) const
virtual void setAppAction(Teuchos::RCP< StepperHHTAlphaAppAction< Scalar > > appAction)
void setGamma(Scalar gamma)
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void setUseFSAL(bool a)
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
void setStepperType(std::string s)
Set the stepper type.
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
void setICConsistency(std::string s)