10 #ifndef Tempus_StepperHHTAlpha_impl_hpp
11 #define Tempus_StepperHHTAlpha_impl_hpp
13 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
22 template <
class Scalar>
27 #ifdef VERBOSE_DEBUG_OUTPUT
28 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
31 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0, v, dt * (1.0 - gamma_), a);
34 template <
class Scalar>
38 const Scalar dt)
const
40 #ifdef VERBOSE_DEBUG_OUTPUT
41 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
44 Scalar aConst = dt * dt / 2.0 * (1.0 - 2.0 * beta_);
45 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), dt, v, aConst, a);
47 Thyra::Vp_V(Teuchos::ptrFromRef(dPred), d, 1.0);
50 template <
class Scalar>
54 #ifdef VERBOSE_DEBUG_OUTPUT
55 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
58 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0 - alpha_f_, vPred, alpha_f_,
62 template <
class Scalar>
66 #ifdef VERBOSE_DEBUG_OUTPUT
67 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
70 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), 1.0 - alpha_f_, dPred, alpha_f_,
74 template <
class Scalar>
79 #ifdef VERBOSE_DEBUG_OUTPUT
80 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
82 Scalar c = 1.0 / (1.0 - alpha_m_);
85 Thyra::V_StVpStV(Teuchos::ptrFromRef(a_n_plus1), c, a_n_plus1, -c * alpha_m_,
89 template <
class Scalar>
94 #ifdef VERBOSE_DEBUG_OUTPUT
95 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
98 Thyra::V_StVpStV(Teuchos::ptrFromRef(v), 1.0, vPred, dt * gamma_, a);
101 template <
class Scalar>
106 #ifdef VERBOSE_DEBUG_OUTPUT
107 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
110 Thyra::V_StVpStV(Teuchos::ptrFromRef(d), 1.0, dPred, beta_ * dt * dt, a);
113 template <
class Scalar>
116 if (schemeName_ !=
"Newmark Beta User Defined") {
117 out_->setOutputToRootOnly(0);
118 *out_ <<
"\nWARNING: schemeName != 'Newmark Beta User Defined' (= '"
119 << schemeName_ <<
"').\n"
120 <<
" Leaving as beta = " << beta_ <<
"!\n";
127 out_->setOutputToRootOnly(0);
128 *out_ <<
"\nWARNING: Running (implicit implementation of) Newmark "
129 <<
"Implicit a-Form Stepper with Beta = 0.0, which \n"
130 <<
"specifies an explicit scheme. Mass lumping is not possible, "
131 <<
"so this will be slow! To run explicit \n"
132 <<
"implementation of Newmark Implicit a-Form Stepper, please "
133 <<
"re-run with 'Stepper Type' = 'Newmark Explicit a-Form'.\n"
134 <<
"This stepper allows for mass lumping when called through "
135 <<
"Piro::TempusSolver.\n";
139 (beta_ > 1.0) || (beta_ < 0.0), std::logic_error,
140 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Beta = "
141 << beta_ <<
". Please select Beta >= 0 and <= 1. \n");
143 this->isInitialized_ =
false;
146 template <
class Scalar>
149 if (schemeName_ !=
"Newmark Beta User Defined") {
150 out_->setOutputToRootOnly(0);
151 *out_ <<
"\nWARNING: schemeName != 'Newmark Beta User Defined' (= '"
152 << schemeName_ <<
"').\n"
153 <<
" Leaving as gamma = " << gamma_ <<
"!\n";
160 (gamma_ > 1.0) || (gamma_ < 0.0), std::logic_error,
161 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Gamma ="
162 << gamma_ <<
". Please select Gamma >= 0 and <= 1. \n");
164 this->isInitialized_ =
false;
167 template <
class Scalar>
173 (alpha_f_ > 1.0) || (alpha_f_ < 0.0), std::logic_error,
174 "\nError in 'HHT-Alpha' stepper: invalid value of Alpha_f = "
175 << alpha_f_ <<
". Please select Alpha_f >= 0 and <= 1. \n");
177 this->isInitialized_ =
false;
180 template <
class Scalar>
186 (alpha_m_ >= 1.0) || (alpha_m_ < 0.0), std::logic_error,
187 "\nError in 'HHT-Alpha' stepper: invalid value of Alpha_m = "
188 << alpha_m_ <<
". Please select Alpha_m >= 0 and < 1. \n");
190 this->isInitialized_ =
false;
193 template <
class Scalar>
196 schemeName_ = schemeName;
198 if (schemeName_ ==
"Newmark Beta Average Acceleration") {
202 else if (schemeName_ ==
"Newmark Beta Linear Acceleration") {
206 else if (schemeName_ ==
"Newmark Beta Central Difference") {
210 else if (schemeName_ ==
"Newmark Beta User Defined") {
216 true, std::logic_error,
217 "\nError in Tempus::StepperHHTAlpha! "
218 <<
"Invalid Scheme Name = " << schemeName_ <<
". \n"
219 <<
"Valid Scheme Names are: 'Newmark Beta Average Acceleration', "
220 <<
"'Newmark Beta Linear Acceleration', \n"
221 <<
"'Newmark Beta Central Difference' and 'Newmark Beta User "
225 this->isInitialized_ =
false;
228 template <
class Scalar>
230 : out_(Teuchos::VerboseObjectBase::getDefaultOStream())
232 #ifdef VERBOSE_DEBUG_OUTPUT
233 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
249 template <
class Scalar>
253 bool useFSAL, std::string ICConsistency,
bool ICConsistencyCheck,
254 bool zeroInitialGuess, std::string schemeName, Scalar beta, Scalar gamma,
255 Scalar alpha_f, Scalar alpha_m,
257 stepperHHTAlphaAppAction)
258 : out_(Teuchos::VerboseObjectBase::getDefaultOStream())
267 if (schemeName ==
"Newmark Beta User Defined") {
276 if (appModel != Teuchos::null) {
282 template <
class Scalar>
286 if (appAction == Teuchos::null) {
288 stepperHHTAlphaAppAction_ =
292 stepperHHTAlphaAppAction_ = appAction;
296 template <
class Scalar>
300 #ifdef VERBOSE_DEBUG_OUTPUT
301 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
307 this->wrapperModel_ = wrapperModel;
310 "Error - Solver is not set!\n");
311 if (this->wrapperModel_ != Teuchos::null)
312 this->solver_->setModel(this->wrapperModel_);
314 this->isInitialized_ =
false;
317 template <
class Scalar>
321 #ifdef VERBOSE_DEBUG_OUTPUT
322 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
324 this->checkInitialized();
328 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperHHTAlpha::takeStep()");
331 solutionHistory->getNumStates() < 2, std::logic_error,
332 "Error - StepperHHTAlpha<Scalar>::takeStep(...)\n"
333 <<
"Need at least two SolutionStates for HHTAlpha.\n"
334 <<
" Number of States = " << solutionHistory->getNumStates()
335 <<
"\nTry setting in \"Solution History\" \"Storage Type\" = "
336 <<
"\"Undo\"\n or \"Storage Type\" = \"Static\" and \"Storage Limit\" = "
339 RCP<StepperHHTAlpha<Scalar> > thisStepper = Teuchos::rcpFromRef(*
this);
340 stepperHHTAlphaAppAction_->execute(
341 solutionHistory, thisStepper,
344 RCP<SolutionState<Scalar> > workingState =
345 solutionHistory->getWorkingState();
346 RCP<SolutionState<Scalar> > currentState =
347 solutionHistory->getCurrentState();
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();
375 Scalar t = time + dt;
379 if (time == solutionHistory->minTime()) {
380 RCP<Thyra::VectorBase<Scalar> > d_init =
381 Thyra::createMember(d_old->space());
382 RCP<Thyra::VectorBase<Scalar> > v_init =
383 Thyra::createMember(v_old->space());
384 RCP<Thyra::VectorBase<Scalar> > a_init =
385 Thyra::createMember(a_old->space());
386 Thyra::copy(*d_old, d_init.ptr());
387 Thyra::copy(*v_old, v_init.ptr());
388 if (this->initialGuess_ !=
392 (a_init->space())->isCompatible(*this->initialGuess_->space());
394 is_compatible !=
true, std::logic_error,
395 "Error in Tempus::NemwarkImplicitAForm takeStep(): user-provided "
397 <<
"for Newton is not compatible with solution vector!\n");
398 Thyra::copy(*this->initialGuess_, a_init.ptr());
401 Thyra::put_scalar(0.0, a_init.ptr());
403 wrapperModel->initializeNewmark(v_init, d_init, 0.0, time, beta_, gamma_);
405 (*(this->solver_)).solve(&*a_init);
407 workingState->setSolutionStatus(sStatus);
408 Thyra::copy(*a_init, a_old.ptr());
412 *out_ <<
"IKT a_old = " << Thyra::max(*a_old) <<
"\n";
416 RCP<Thyra::VectorBase<Scalar> > d_pred =
417 Thyra::createMember(d_old->space());
418 RCP<Thyra::VectorBase<Scalar> > v_pred =
419 Thyra::createMember(v_old->space());
422 predictDisplacement(*d_pred, *d_old, *v_old, *a_old, dt);
423 predictVelocity(*v_pred, *v_old, *a_old, dt);
427 predictDisplacement_alpha_f(*d_pred, *d_old);
428 predictVelocity_alpha_f(*v_pred, *v_old);
431 wrapperModel->initializeNewmark(v_pred, d_pred, dt, t, beta_, gamma_);
433 stepperHHTAlphaAppAction_->execute(
434 solutionHistory, thisStepper,
439 (*(this->solver_)).solve(&*a_new);
441 stepperHHTAlphaAppAction_->execute(
442 solutionHistory, thisStepper,
446 correctAcceleration(*a_new, *a_old);
449 correctVelocity(*v_new, *v_pred, *a_new, dt);
450 correctDisplacement(*d_new, *d_pred, *a_new, dt);
452 workingState->setSolutionStatus(sStatus);
453 workingState->setOrder(this->getOrder());
454 workingState->computeNorms(currentState);
456 stepperHHTAlphaAppAction_->execute(
457 solutionHistory, thisStepper,
469 template <
class Scalar>
473 #ifdef VERBOSE_DEBUG_OUTPUT
474 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
481 template <
class Scalar>
485 auto l_out = Teuchos::fancyOStream(out.
getOStream());
487 l_out->setOutputToRootOnly(0);
489 #ifdef VERBOSE_DEBUG_OUTPUT
490 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
497 *l_out <<
"--- StepperHHTAlpha ---\n";
498 *l_out <<
" schemeName_ = " << schemeName_ << std::endl;
499 *l_out <<
" beta_ = " << beta_ << std::endl;
500 *l_out <<
" gamma_ = " << gamma_ << std::endl;
501 *l_out <<
" alpha_f_ = " << alpha_f_ << std::endl;
502 *l_out <<
" alpha_m_ = " << alpha_m_ << std::endl;
503 *l_out <<
"-----------------------" << std::endl;
506 template <
class Scalar>
510 bool isValidSetup =
true;
515 if (this->wrapperModel_->getAppModel() == Teuchos::null) {
516 isValidSetup =
false;
517 out <<
"The application ModelEvaluator is not set!\n";
520 if (this->wrapperModel_ == Teuchos::null) {
521 isValidSetup =
false;
522 out <<
"The wrapper ModelEvaluator is not set!\n";
525 if (this->solver_ == Teuchos::null) {
526 isValidSetup =
false;
527 out <<
"The solver is not set!\n";
533 template <
class Scalar>
537 #ifdef VERBOSE_DEBUG_OUTPUT
538 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
540 auto pl = this->getValidParametersBasicImplicit();
542 auto hhtalphaPL = Teuchos::parameterList(
"HHT-Alpha Parameters");
543 hhtalphaPL->set<std::string>(
"Scheme Name", schemeName_);
544 hhtalphaPL->set<
double>(
"Beta", beta_);
545 hhtalphaPL->set<
double>(
"Gamma", gamma_);
546 hhtalphaPL->set<
double>(
"Alpha_f", alpha_f_);
547 hhtalphaPL->set<
double>(
"Alpha_m", alpha_m_);
548 pl->set(
"HHT-Alpha Parameters", *hhtalphaPL);
555 template <
class Scalar>
561 stepper->setStepperImplicitValues(pl);
563 if (pl != Teuchos::null) {
564 if (pl->
isSublist(
"HHT-Alpha Parameters")) {
565 auto hhtalphaPL = pl->
sublist(
"HHT-Alpha Parameters",
true);
566 std::string schemeName = hhtalphaPL.
get<std::string>(
567 "Scheme Name",
"Newmark Beta Average Acceleration");
568 stepper->setSchemeName(schemeName);
569 if (schemeName ==
"Newmark Beta User Defined") {
570 stepper->setBeta(hhtalphaPL.get<
double>(
"Beta", 0.25));
571 stepper->setGamma(hhtalphaPL.get<
double>(
"Gamma", 0.5));
573 stepper->setAlphaF(hhtalphaPL.get<
double>(
"Alpha_f", 0.0));
574 stepper->setAlphaM(hhtalphaPL.get<
double>(
"Alpha_m", 0.0));
577 stepper->setSchemeName(
"Newmark Beta Average Acceleration");
578 stepper->setAlphaF(0.0);
579 stepper->setAlphaM(0.0);
583 if (model != Teuchos::null) {
584 stepper->setModel(model);
585 stepper->initialize();
592 #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 void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver) override
Set solver.
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.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
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.
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)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
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)
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 setUseFSAL(bool a)
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
Set the model.
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)