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;
25 template<
class Scalar>
28 const Thyra::VectorBase<Scalar>& v,
29 const Thyra::VectorBase<Scalar>& a,
30 const Scalar dt)
const
32 #ifdef VERBOSE_DEBUG_OUTPUT
33 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
36 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0, v, dt*(1.0-gamma_), a);
39 template<
class Scalar>
42 const Thyra::VectorBase<Scalar>& d,
43 const Thyra::VectorBase<Scalar>& v,
44 const Thyra::VectorBase<Scalar>& a,
45 const Scalar dt)
const
47 #ifdef VERBOSE_DEBUG_OUTPUT
48 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
50 Teuchos::RCP<const Thyra::VectorBase<Scalar> > tmp =
51 Thyra::createMember<Scalar>(dPred.space());
53 Scalar aConst = dt*dt/2.0*(1.0-2.0*beta_);
54 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), dt, v, aConst, a);
56 Thyra::Vp_V(Teuchos::ptrFromRef(dPred), d, 1.0);
60 template<
class Scalar>
63 const Thyra::VectorBase<Scalar>& v)
const
65 #ifdef VERBOSE_DEBUG_OUTPUT
66 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
69 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0-alpha_f_, vPred, alpha_f_, v);
73 template<
class Scalar>
76 const Thyra::VectorBase<Scalar>& d)
const
78 #ifdef VERBOSE_DEBUG_OUTPUT
79 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
82 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), 1.0-alpha_f_, dPred, alpha_f_, d);
85 template<
class Scalar>
88 const Thyra::VectorBase<Scalar>& a_n)
const
90 #ifdef VERBOSE_DEBUG_OUTPUT
91 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
93 Scalar c = 1.0/(1.0-alpha_m_);
95 Thyra::V_StVpStV(Teuchos::ptrFromRef(a_n_plus1), c, a_n_plus1, -c*alpha_m_, a_n);
100 template<
class Scalar>
103 const Thyra::VectorBase<Scalar>& vPred,
104 const Thyra::VectorBase<Scalar>& a,
105 const Scalar dt)
const
107 #ifdef VERBOSE_DEBUG_OUTPUT
108 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
111 Thyra::V_StVpStV(Teuchos::ptrFromRef(v), 1.0, vPred, dt*gamma_, a);
114 template<
class Scalar>
117 const Thyra::VectorBase<Scalar>& dPred,
118 const Thyra::VectorBase<Scalar>& a,
119 const Scalar dt)
const
121 #ifdef VERBOSE_DEBUG_OUTPUT
122 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
125 Thyra::V_StVpStV(Teuchos::ptrFromRef(d), 1.0, dPred, beta_*dt*dt, a);
129 template<
class Scalar>
131 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
132 Teuchos::RCP<Teuchos::ParameterList> pList) :
133 out_(
Teuchos::VerboseObjectBase::getDefaultOStream())
135 #ifdef VERBOSE_DEBUG_OUTPUT
136 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
139 using Teuchos::ParameterList;
148 template<
class Scalar>
150 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel)
152 #ifdef VERBOSE_DEBUG_OUTPUT
153 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
155 this->validSecondOrderODE_DAE(appModel);
156 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
159 this->wrapperModel_ = wrapperModel;
163 template<
class Scalar>
166 TEUCHOS_TEST_FOR_EXCEPTION( this->wrapperModel_ == Teuchos::null,
168 "Error - Need to set the model, setModel(), before calling "
169 "StepperHHTAlpha::initialize()\n");
171 #ifdef VERBOSE_DEBUG_OUTPUT
172 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
174 this->setParameterList(this->stepperPL_);
179 template<
class Scalar>
183 #ifdef VERBOSE_DEBUG_OUTPUT
184 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
188 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperHHTAlpha::takeStep()");
192 "Error - StepperHHTAlpha<Scalar>::takeStep(...)\n"
193 "Need at least two SolutionStates for HHTAlpha.\n"
195 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
196 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
198 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
199 RCP<SolutionState<Scalar> > currentState=
solutionHistory->getCurrentState();
201 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
203 this->wrapperModel_);
206 RCP<const Thyra::VectorBase<Scalar> > d_old = currentState->getX();
207 RCP<const Thyra::VectorBase<Scalar> > v_old = currentState->getXDot();
208 RCP<Thyra::VectorBase<Scalar> > a_old = currentState->getXDotDot();
213 *out_ <<
"IKT d_old = " << Thyra::max(*d_old) <<
"\n";
214 *out_ <<
"IKT v_old = " << Thyra::max(*v_old) <<
"\n";
219 RCP<Thyra::VectorBase<Scalar> > d_new = workingState->getX();
220 RCP<Thyra::VectorBase<Scalar> > v_new = workingState->getXDot();
221 RCP<Thyra::VectorBase<Scalar> > a_new = workingState->getXDotDot();
224 const Scalar time = currentState->getTime();
225 const Scalar dt = workingState->getTimeStep();
232 RCP<Thyra::VectorBase<Scalar> > d_init = Thyra::createMember(d_old->space());
233 RCP<Thyra::VectorBase<Scalar> > v_init = Thyra::createMember(v_old->space());
234 RCP<Thyra::VectorBase<Scalar> > a_init = Thyra::createMember(a_old->space());
235 Thyra::copy(*d_old, d_init.ptr());
236 Thyra::copy(*v_old, v_init.ptr());
237 if (initial_guess_ != Teuchos::null) {
239 bool is_compatible = (a_init->space())->isCompatible(*initial_guess_->space());
240 TEUCHOS_TEST_FOR_EXCEPTION(
241 is_compatible !=
true, std::logic_error,
242 "Error in Tempus::NemwarkImplicitAForm takeStep(): user-provided initial guess'!\n"
243 <<
"for Newton is not compatible with solution vector!\n");
244 Thyra::copy(*initial_guess_, a_init.ptr());
247 Thyra::put_scalar(0.0, a_init.ptr());
249 wrapperModel->initializeNewmark(v_init,d_init,0.0,time,beta_,gamma_);
250 const Thyra::SolveStatus<Scalar> sStatus=this->solveImplicitODE(a_init);
252 if (sStatus.solveStatus == Thyra::SOLVE_STATUS_CONVERGED )
256 Thyra::copy(*a_init, a_old.ptr());
260 *out_ <<
"IKT a_old = " << Thyra::max(*a_old) <<
"\n";
265 RCP<Thyra::VectorBase<Scalar> > d_pred =Thyra::createMember(d_old->space());
266 RCP<Thyra::VectorBase<Scalar> > v_pred =Thyra::createMember(v_old->space());
269 predictDisplacement(*d_pred, *d_old, *v_old, *a_old, dt);
270 predictVelocity(*v_pred, *v_old, *a_old, dt);
273 predictDisplacement_alpha_f(*d_pred, *d_old);
274 predictVelocity_alpha_f(*v_pred, *v_old);
277 wrapperModel->initializeNewmark(v_pred,d_pred,dt,t,beta_,gamma_);
280 const Thyra::SolveStatus<Scalar> sStatus = this->solveImplicitODE(a_new);
283 correctAcceleration(*a_new, *a_old);
286 correctVelocity(*v_new, *v_pred, *a_new, dt);
287 correctDisplacement(*d_new, *d_pred, *a_new, dt);
289 if (sStatus.solveStatus == Thyra::SOLVE_STATUS_CONVERGED )
293 workingState->setOrder(this->getOrder());
306 template<
class Scalar>
307 Teuchos::RCP<Tempus::StepperState<Scalar> >
311 #ifdef VERBOSE_DEBUG_OUTPUT
312 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
314 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
320 template<
class Scalar>
323 #ifdef VERBOSE_DEBUG_OUTPUT
324 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
326 std::string name =
"HHT-Alpha";
331 template<
class Scalar>
333 Teuchos::FancyOStream &out,
334 const Teuchos::EVerbosityLevel verbLevel)
const
336 #ifdef VERBOSE_DEBUG_OUTPUT
337 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
339 out << description() <<
"::describe:" << std::endl
340 <<
"wrapperModel_ = " << this->wrapperModel_->description() << std::endl;
344 template <
class Scalar>
346 Teuchos::RCP<Teuchos::ParameterList>
const& pList)
348 #ifdef VERBOSE_DEBUG_OUTPUT
349 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
351 if (pList == Teuchos::null) {
353 if (this->stepperPL_ == Teuchos::null) this->stepperPL_ = this->getDefaultParameters();
355 this->stepperPL_ = pList;
362 Teuchos::RCP<Teuchos::ParameterList> stepperPL = this->stepperPL_;
363 std::string stepperType = stepperPL->get<std::string>(
"Stepper Type");
364 TEUCHOS_TEST_FOR_EXCEPTION( stepperType !=
"HHT-Alpha",
366 "\nError - Stepper Type is not 'HHT-Alpha'!\n" <<
"Stepper Type = "
367 << stepperPL->get<std::string>(
"Stepper Type") <<
"\n");
375 Teuchos::RCP<Teuchos::FancyOStream> out =
376 Teuchos::VerboseObjectBase::getDefaultOStream();
377 if (this->stepperPL_->isSublist(
"HHT-Alpha Parameters")) {
378 Teuchos::ParameterList &HHTalphaPL =
379 this->stepperPL_->sublist(
"HHT-Alpha Parameters",
true);
380 std::string scheme_name = HHTalphaPL.get(
"Scheme Name",
"Not Specified");
381 alpha_m_ = HHTalphaPL.get(
"Alpha_m", 0.0);
382 alpha_f_ = HHTalphaPL.get(
"Alpha_f", 0.0);
383 TEUCHOS_TEST_FOR_EXCEPTION( (alpha_m_ >= 1.0) || (alpha_m_ < 0.0),
385 "\nError in 'HHT-Alpha' stepper: invalid value of Alpha_m = "
386 << alpha_m_ <<
". Please select Alpha_m >= 0 and < 1. \n");
387 TEUCHOS_TEST_FOR_EXCEPTION( (alpha_f_ > 1.0) || (alpha_f_ < 0.0),
389 "\nError in 'HHT-Alpha' stepper: invalid value of Alpha_f = "
390 << alpha_f_ <<
". Please select Alpha_f >= 0 and <= 1. \n");
391 TEUCHOS_TEST_FOR_EXCEPTION( (alpha_m_ != 0.0) || (alpha_f_ != 0.0),
393 "\nError - 'HHT-Alpha' stepper has not been verified yet for "
394 "Alpha_m, Alpha_f != 0! \n" <<
"You have specified Alpha_m = "
395 << alpha_m_ <<
", Alpha_f = " << alpha_f_ <<
".\n");
396 if (scheme_name ==
"Newmark Beta") {
397 beta_ = HHTalphaPL.get(
"Beta", 0.25);
398 gamma_ = HHTalphaPL.get(
"Gamma", 0.5);
399 TEUCHOS_TEST_FOR_EXCEPTION( (beta_ > 1.0) || (beta_ < 0.0),
401 "\nError in 'HHT-Alpha' stepper: invalid value of Beta = "
402 << beta_ <<
". Please select Beta >= 0 and <= 1. \n");
403 TEUCHOS_TEST_FOR_EXCEPTION( (gamma_ > 1.0) || (gamma_ < 0.0),
405 "\nError in 'HHT-Alpha' stepper: invalid value of Gamma = "
406 <<gamma_ <<
". Please select Gamma >= 0 and <= 1. \n");
407 *out <<
"\n \nScheme Name = Newmark Beta. Setting Alpha_f = "
408 <<
"Alpha_m = 0. Setting \n" <<
"Beta = " << beta_
409 <<
" and Gamma = " << gamma_
410 <<
" from HHT-Alpha Parameters in input file.\n\n";
413 *out <<
"\n \nScheme Name = " << scheme_name
414 <<
". Using values of Alpha_m, Alpha_f, \n"
415 <<
"Beta and Gamma for this scheme (ignoring values of "
416 <<
"Alpha_m, Alpha_f, Beta and Gamma \n"
417 <<
"in input file, if provided).\n";
418 if (scheme_name ==
"Newmark Beta Average Acceleration") {
419 beta_ = 0.25; gamma_ = 0.5;
421 else if (scheme_name ==
"Newmark Beta Linear Acceleration") {
422 beta_ = 0.25; gamma_ = 1.0/6.0;
424 else if (scheme_name ==
"Newmark Beta Central Difference") {
425 beta_ = 0.0; gamma_ = 0.5;
428 TEUCHOS_TEST_FOR_EXCEPTION(
true,
430 "\nError in Tempus::StepperHHTAlpha! Invalid Scheme Name = "
431 << scheme_name <<
". \n"
432 <<
"Valid Scheme Names are: 'Newmark Beta', 'Newmark Beta "
433 <<
"Average Acceleration', \n"
434 <<
"'Newmark Beta Linear Acceleration', and 'Newmark Beta "
435 <<
"Central Difference'.\n");
437 *out <<
"===> Alpha_m = " << alpha_m_ <<
", Alpha_f = " << alpha_f_
438 <<
", Beta = " << beta_ <<
", Gamma = " << gamma_ <<
"\n";
441 *out <<
"\n \nRunning HHT-Alpha Stepper with Beta = 0.0, which \n"
442 <<
"specifies an explicit scheme. WARNING: code has not been "
443 <<
"optimized \nyet for this case (no mass lumping)\n";
447 *out <<
"\n \nNo HHT-Alpha Parameters sublist found in input file; "
448 <<
"using default values of Beta = "
449 << beta_ <<
" and Gamma = " << gamma_ <<
".\n\n";
454 template<
class Scalar>
455 Teuchos::RCP<const Teuchos::ParameterList>
458 #ifdef VERBOSE_DEBUG_OUTPUT
459 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
461 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
462 pl->setName(
"Default Stepper - " + this->description());
463 pl->set(
"Stepper Type", this->description());
464 pl->set(
"Zero Initial Guess",
false);
465 pl->set(
"Solver Name",
"",
466 "Name of ParameterList containing the solver specifications.");
470 template<
class Scalar>
471 Teuchos::RCP<Teuchos::ParameterList>
474 #ifdef VERBOSE_DEBUG_OUTPUT
475 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
478 using Teuchos::ParameterList;
480 RCP<ParameterList> pl = Teuchos::parameterList();
481 pl->setName(
"Default Stepper - " + this->description());
482 pl->set<std::string>(
"Stepper Type", this->description());
483 pl->set<
bool> (
"Zero Initial Guess",
false);
484 pl->set<std::string>(
"Solver Name",
"Default Solver");
486 RCP<ParameterList> solverPL = this->defaultSolverParameters();
487 pl->set(
"Default Solver", *solverPL);
493 template <
class Scalar>
494 Teuchos::RCP<Teuchos::ParameterList>
497 #ifdef VERBOSE_DEBUG_OUTPUT
498 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
500 return(this->stepperPL_);
504 template <
class Scalar>
505 Teuchos::RCP<Teuchos::ParameterList>
508 #ifdef VERBOSE_DEBUG_OUTPUT
509 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
511 Teuchos::RCP<Teuchos::ParameterList> temp_plist = this->stepperPL_;
512 this->stepperPL_ = Teuchos::null;
518 #endif // Tempus_StepperHHTAlpha_impl_hpp