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";
51 Teuchos::RCP<const Thyra::VectorBase<Scalar> > tmp =
52 Thyra::createMember<Scalar>(dPred.space());
54 Scalar aConst = dt*dt/2.0*(1.0-2.0*beta_);
55 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), dt, v, aConst, a);
57 Thyra::Vp_V(Teuchos::ptrFromRef(dPred), d, 1.0);
61 template<
class Scalar>
64 const Thyra::VectorBase<Scalar>& v)
const
66 #ifdef VERBOSE_DEBUG_OUTPUT
67 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
70 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0-alpha_f_, vPred, alpha_f_, v);
74 template<
class Scalar>
77 const Thyra::VectorBase<Scalar>& d)
const
79 #ifdef VERBOSE_DEBUG_OUTPUT
80 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
83 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), 1.0-alpha_f_, dPred, alpha_f_, d);
86 template<
class Scalar>
89 const Thyra::VectorBase<Scalar>& a_n)
const
91 #ifdef VERBOSE_DEBUG_OUTPUT
92 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
94 Scalar c = 1.0/(1.0-alpha_m_);
96 Thyra::V_StVpStV(Teuchos::ptrFromRef(a_n_plus1), c, a_n_plus1, -c*alpha_m_, a_n);
101 template<
class Scalar>
104 const Thyra::VectorBase<Scalar>& vPred,
105 const Thyra::VectorBase<Scalar>& a,
106 const Scalar dt)
const
108 #ifdef VERBOSE_DEBUG_OUTPUT
109 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
112 Thyra::V_StVpStV(Teuchos::ptrFromRef(v), 1.0, vPred, dt*gamma_, a);
115 template<
class Scalar>
118 const Thyra::VectorBase<Scalar>& dPred,
119 const Thyra::VectorBase<Scalar>& a,
120 const Scalar dt)
const
122 #ifdef VERBOSE_DEBUG_OUTPUT
123 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
126 Thyra::V_StVpStV(Teuchos::ptrFromRef(d), 1.0, dPred, beta_*dt*dt, a);
130 template<
class Scalar>
132 out_(Teuchos::VerboseObjectBase::getDefaultOStream())
134 #ifdef VERBOSE_DEBUG_OUTPUT
135 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
143 template<
class Scalar>
145 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
146 Teuchos::RCP<Teuchos::ParameterList> pList) :
147 out_(Teuchos::VerboseObjectBase::getDefaultOStream())
149 #ifdef VERBOSE_DEBUG_OUTPUT
150 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
155 if (appModel == Teuchos::null) {
165 template<
class Scalar>
167 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel)
169 #ifdef VERBOSE_DEBUG_OUTPUT
170 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
172 this->validSecondOrderODE_DAE(appModel);
173 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
176 this->wrapperModel_ = wrapperModel;
180 template<
class Scalar>
183 TEUCHOS_TEST_FOR_EXCEPTION( this->wrapperModel_ == Teuchos::null,
185 "Error - Need to set the model, setModel(), before calling "
186 "StepperHHTAlpha::initialize()\n");
188 #ifdef VERBOSE_DEBUG_OUTPUT
189 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
191 this->setParameterList(this->stepperPL_);
196 template<
class Scalar>
200 #ifdef VERBOSE_DEBUG_OUTPUT
201 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
205 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperHHTAlpha::takeStep()");
209 "Error - StepperHHTAlpha<Scalar>::takeStep(...)\n"
210 "Need at least two SolutionStates for HHTAlpha.\n"
212 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
213 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
215 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
216 RCP<SolutionState<Scalar> > currentState=
solutionHistory->getCurrentState();
218 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
220 this->wrapperModel_);
223 RCP<const Thyra::VectorBase<Scalar> > d_old = currentState->getX();
224 RCP<const Thyra::VectorBase<Scalar> > v_old = currentState->getXDot();
225 RCP<Thyra::VectorBase<Scalar> > a_old = currentState->getXDotDot();
230 *out_ <<
"IKT d_old = " << Thyra::max(*d_old) <<
"\n";
231 *out_ <<
"IKT v_old = " << Thyra::max(*v_old) <<
"\n";
236 RCP<Thyra::VectorBase<Scalar> > d_new = workingState->getX();
237 RCP<Thyra::VectorBase<Scalar> > v_new = workingState->getXDot();
238 RCP<Thyra::VectorBase<Scalar> > a_new = workingState->getXDotDot();
241 const Scalar time = currentState->getTime();
242 const Scalar dt = workingState->getTimeStep();
249 RCP<Thyra::VectorBase<Scalar> > d_init = Thyra::createMember(d_old->space());
250 RCP<Thyra::VectorBase<Scalar> > v_init = Thyra::createMember(v_old->space());
251 RCP<Thyra::VectorBase<Scalar> > a_init = Thyra::createMember(a_old->space());
252 Thyra::copy(*d_old, d_init.ptr());
253 Thyra::copy(*v_old, v_init.ptr());
254 if (this->initial_guess_ != Teuchos::null) {
256 bool is_compatible = (a_init->space())->isCompatible(*this->initial_guess_->space());
257 TEUCHOS_TEST_FOR_EXCEPTION(
258 is_compatible !=
true, std::logic_error,
259 "Error in Tempus::NemwarkImplicitAForm takeStep(): user-provided initial guess'!\n"
260 <<
"for Newton is not compatible with solution vector!\n");
261 Thyra::copy(*this->initial_guess_, a_init.ptr());
264 Thyra::put_scalar(0.0, a_init.ptr());
266 wrapperModel->initializeNewmark(v_init,d_init,0.0,time,beta_,gamma_);
267 const Thyra::SolveStatus<Scalar> sStatus=this->solveImplicitODE(a_init);
269 workingState->setSolutionStatus(sStatus);
270 Thyra::copy(*a_init, a_old.ptr());
274 *out_ <<
"IKT a_old = " << Thyra::max(*a_old) <<
"\n";
279 RCP<Thyra::VectorBase<Scalar> > d_pred =Thyra::createMember(d_old->space());
280 RCP<Thyra::VectorBase<Scalar> > v_pred =Thyra::createMember(v_old->space());
283 predictDisplacement(*d_pred, *d_old, *v_old, *a_old, dt);
284 predictVelocity(*v_pred, *v_old, *a_old, dt);
287 predictDisplacement_alpha_f(*d_pred, *d_old);
288 predictVelocity_alpha_f(*v_pred, *v_old);
291 wrapperModel->initializeNewmark(v_pred,d_pred,dt,t,beta_,gamma_);
294 const Thyra::SolveStatus<Scalar> sStatus = this->solveImplicitODE(a_new);
297 correctAcceleration(*a_new, *a_old);
300 correctVelocity(*v_new, *v_pred, *a_new, dt);
301 correctDisplacement(*d_new, *d_pred, *a_new, dt);
303 workingState->setSolutionStatus(sStatus);
304 workingState->setOrder(this->getOrder());
317 template<
class Scalar>
318 Teuchos::RCP<Tempus::StepperState<Scalar> >
322 #ifdef VERBOSE_DEBUG_OUTPUT
323 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
325 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
331 template<
class Scalar>
334 #ifdef VERBOSE_DEBUG_OUTPUT
335 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
337 std::string name =
"HHT-Alpha";
342 template<
class Scalar>
344 Teuchos::FancyOStream &out,
345 const Teuchos::EVerbosityLevel )
const
347 #ifdef VERBOSE_DEBUG_OUTPUT
348 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
350 out << description() <<
"::describe:" << std::endl
351 <<
"wrapperModel_ = " << this->wrapperModel_->description() << std::endl;
355 template <
class Scalar>
357 Teuchos::RCP<Teuchos::ParameterList>
const& pList)
359 #ifdef VERBOSE_DEBUG_OUTPUT
360 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
362 if (pList == Teuchos::null) {
364 if (this->stepperPL_ == Teuchos::null) this->stepperPL_ = this->getDefaultParameters();
366 this->stepperPL_ = pList;
373 Teuchos::RCP<Teuchos::ParameterList> stepperPL = this->stepperPL_;
374 std::string stepperType = stepperPL->get<std::string>(
"Stepper Type");
375 TEUCHOS_TEST_FOR_EXCEPTION( stepperType !=
"HHT-Alpha",
377 "\nError - Stepper Type is not 'HHT-Alpha'!\n" <<
"Stepper Type = "
378 << stepperPL->get<std::string>(
"Stepper Type") <<
"\n");
386 Teuchos::RCP<Teuchos::FancyOStream> out =
387 Teuchos::VerboseObjectBase::getDefaultOStream();
388 if (this->stepperPL_->isSublist(
"HHT-Alpha Parameters")) {
389 Teuchos::ParameterList &HHTalphaPL =
390 this->stepperPL_->sublist(
"HHT-Alpha Parameters",
true);
391 std::string scheme_name = HHTalphaPL.get(
"Scheme Name",
"Not Specified");
392 alpha_m_ = HHTalphaPL.get(
"Alpha_m", 0.0);
393 alpha_f_ = HHTalphaPL.get(
"Alpha_f", 0.0);
394 TEUCHOS_TEST_FOR_EXCEPTION( (alpha_m_ >= 1.0) || (alpha_m_ < 0.0),
396 "\nError in 'HHT-Alpha' stepper: invalid value of Alpha_m = "
397 << alpha_m_ <<
". Please select Alpha_m >= 0 and < 1. \n");
398 TEUCHOS_TEST_FOR_EXCEPTION( (alpha_f_ > 1.0) || (alpha_f_ < 0.0),
400 "\nError in 'HHT-Alpha' stepper: invalid value of Alpha_f = "
401 << alpha_f_ <<
". Please select Alpha_f >= 0 and <= 1. \n");
402 TEUCHOS_TEST_FOR_EXCEPTION( (alpha_m_ != 0.0) || (alpha_f_ != 0.0),
404 "\nError - 'HHT-Alpha' stepper has not been verified yet for "
405 "Alpha_m, Alpha_f != 0! \n" <<
"You have specified Alpha_m = "
406 << alpha_m_ <<
", Alpha_f = " << alpha_f_ <<
".\n");
407 if (scheme_name ==
"Newmark Beta") {
408 beta_ = HHTalphaPL.get(
"Beta", 0.25);
409 gamma_ = HHTalphaPL.get(
"Gamma", 0.5);
410 TEUCHOS_TEST_FOR_EXCEPTION( (beta_ > 1.0) || (beta_ < 0.0),
412 "\nError in 'HHT-Alpha' stepper: invalid value of Beta = "
413 << beta_ <<
". Please select Beta >= 0 and <= 1. \n");
414 TEUCHOS_TEST_FOR_EXCEPTION( (gamma_ > 1.0) || (gamma_ < 0.0),
416 "\nError in 'HHT-Alpha' stepper: invalid value of Gamma = "
417 <<gamma_ <<
". Please select Gamma >= 0 and <= 1. \n");
418 *out <<
"\n \nScheme Name = Newmark Beta. Setting Alpha_f = "
419 <<
"Alpha_m = 0. Setting \n" <<
"Beta = " << beta_
420 <<
" and Gamma = " << gamma_
421 <<
" from HHT-Alpha Parameters in input file.\n\n";
424 *out <<
"\n \nScheme Name = " << scheme_name
425 <<
". Using values of Alpha_m, Alpha_f, \n"
426 <<
"Beta and Gamma for this scheme (ignoring values of "
427 <<
"Alpha_m, Alpha_f, Beta and Gamma \n"
428 <<
"in input file, if provided).\n";
429 if (scheme_name ==
"Newmark Beta Average Acceleration") {
430 beta_ = 0.25; gamma_ = 0.5;
432 else if (scheme_name ==
"Newmark Beta Linear Acceleration") {
433 beta_ = 0.25; gamma_ = 1.0/6.0;
435 else if (scheme_name ==
"Newmark Beta Central Difference") {
436 beta_ = 0.0; gamma_ = 0.5;
439 TEUCHOS_TEST_FOR_EXCEPTION(
true,
441 "\nError in Tempus::StepperHHTAlpha! Invalid Scheme Name = "
442 << scheme_name <<
". \n"
443 <<
"Valid Scheme Names are: 'Newmark Beta', 'Newmark Beta "
444 <<
"Average Acceleration', \n"
445 <<
"'Newmark Beta Linear Acceleration', and 'Newmark Beta "
446 <<
"Central Difference'.\n");
448 *out <<
"===> Alpha_m = " << alpha_m_ <<
", Alpha_f = " << alpha_f_
449 <<
", Beta = " << beta_ <<
", Gamma = " << gamma_ <<
"\n";
452 *out <<
"\n \nRunning HHT-Alpha Stepper with Beta = 0.0, which \n"
453 <<
"specifies an explicit scheme. WARNING: code has not been "
454 <<
"optimized \nyet for this case (no mass lumping)\n";
458 *out <<
"\n \nNo HHT-Alpha Parameters sublist found in input file; "
459 <<
"using default values of Beta = "
460 << beta_ <<
" and Gamma = " << gamma_ <<
".\n\n";
465 template<
class Scalar>
466 Teuchos::RCP<const Teuchos::ParameterList>
469 #ifdef VERBOSE_DEBUG_OUTPUT
470 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
472 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
473 pl->setName(
"Default Stepper - " + this->description());
474 pl->set<std::string>(
"Stepper Type", this->description());
475 this->getValidParametersBasic(pl);
476 pl->set<
bool> (
"Zero Initial Guess",
false);
477 pl->set<std::string>(
"Solver Name",
"",
478 "Name of ParameterList containing the solver specifications.");
482 template<
class Scalar>
483 Teuchos::RCP<Teuchos::ParameterList>
486 #ifdef VERBOSE_DEBUG_OUTPUT
487 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
490 using Teuchos::ParameterList;
491 using Teuchos::rcp_const_cast;
493 RCP<ParameterList> pl =
494 rcp_const_cast<ParameterList>(this->getValidParameters());
496 pl->set<std::string>(
"Solver Name",
"Default Solver");
497 RCP<ParameterList> solverPL = this->defaultSolverParameters();
498 pl->set(
"Default Solver", *solverPL);
504 template <
class Scalar>
505 Teuchos::RCP<Teuchos::ParameterList>
508 #ifdef VERBOSE_DEBUG_OUTPUT
509 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
511 return(this->stepperPL_);
515 template <
class Scalar>
516 Teuchos::RCP<Teuchos::ParameterList>
519 #ifdef VERBOSE_DEBUG_OUTPUT
520 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
522 Teuchos::RCP<Teuchos::ParameterList> temp_plist = this->stepperPL_;
523 this->stepperPL_ = Teuchos::null;
529 #endif // Tempus_StepperHHTAlpha_impl_hpp
void correctDisplacement(Thyra::VectorBase< Scalar > &d, const Thyra::VectorBase< Scalar > &dPred, const Thyra::VectorBase< Scalar > &a, const Scalar dt) 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
virtual void modelWarning() const
void correctAcceleration(Thyra::VectorBase< Scalar > &a_n_plus1, const Thyra::VectorBase< Scalar > &a_n) const
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...
StepperState is a simple class to hold state information about the stepper.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl)
void predictVelocity_alpha_f(Thyra::VectorBase< Scalar > &vPred, const Thyra::VectorBase< Scalar > &v) const
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
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
virtual std::string description() const
Teuchos::RCP< Teuchos::FancyOStream > out_
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
void predictVelocity(Thyra::VectorBase< Scalar > &vPred, const Thyra::VectorBase< Scalar > &v, const Thyra::VectorBase< Scalar > &a, const Scalar dt) const
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
virtual void initialize()
Initialize during construction and after changing input parameters.
Teuchos::RCP< Teuchos::ParameterList > getDefaultParameters() const
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.