9 #ifndef Tempus_StepperNewmarkImplicitDForm_impl_hpp
10 #define Tempus_StepperNewmarkImplicitDForm_impl_hpp
12 #include "NOX_Thyra.H"
14 #include "Tempus_config.hpp"
15 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
23 template <
class Scalar>
26 template <
class Scalar>
29 Thyra::VectorBase<Scalar>& vPred,
const Thyra::VectorBase<Scalar>& v,
30 const Thyra::VectorBase<Scalar>& a,
const Scalar dt)
const {
31 #ifdef VERBOSE_DEBUG_OUTPUT
32 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
35 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0, v, dt * (1.0 - gamma_), a);
38 template <
class Scalar>
41 Thyra::VectorBase<Scalar>& dPred,
const Thyra::VectorBase<Scalar>& d,
42 const Thyra::VectorBase<Scalar>& v,
const Thyra::VectorBase<Scalar>& a,
43 const Scalar dt)
const {
44 #ifdef VERBOSE_DEBUG_OUTPUT
45 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
47 Teuchos::RCP<const Thyra::VectorBase<Scalar>> tmp =
48 Thyra::createMember<Scalar>(dPred.space());
50 Scalar aConst = dt * dt / 2.0 * (1.0 - 2.0 * beta_);
51 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), dt, v, aConst, a);
53 Thyra::Vp_V(Teuchos::ptrFromRef(dPred), d, 1.0);
56 template <
class Scalar>
59 Thyra::VectorBase<Scalar>& v,
const Thyra::VectorBase<Scalar>& vPred,
60 const Thyra::VectorBase<Scalar>& a,
const Scalar dt)
const {
61 #ifdef VERBOSE_DEBUG_OUTPUT
62 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
65 Thyra::V_StVpStV(Teuchos::ptrFromRef(v), 1.0, vPred, dt * gamma_, a);
68 template <
class Scalar>
71 Thyra::VectorBase<Scalar>& d,
const Thyra::VectorBase<Scalar>& dPred,
72 const Thyra::VectorBase<Scalar>& a,
const Scalar dt)
const {
73 #ifdef VERBOSE_DEBUG_OUTPUT
74 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
77 Thyra::V_StVpStV(Teuchos::ptrFromRef(d), 1.0, dPred, beta_ * dt * dt, a);
80 template <
class Scalar>
83 Thyra::VectorBase<Scalar>& a,
const Thyra::VectorBase<Scalar>& dPred,
84 const Thyra::VectorBase<Scalar>& d,
const Scalar dt)
const {
85 #ifdef VERBOSE_DEBUG_OUTPUT
86 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
89 Scalar
const c = 1.0 / beta_ / dt / dt;
90 Thyra::V_StVpStV(Teuchos::ptrFromRef(a), c, d, -c, dPred);
94 template <
class Scalar>
96 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar>>& appModel,
97 Teuchos::RCP<Teuchos::ParameterList> pList)
98 : out_(
Teuchos::VerboseObjectBase::getDefaultOStream()) {
99 #ifdef VERBOSE_DEBUG_OUTPUT
100 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
103 using Teuchos::ParameterList;
111 template <
class Scalar>
114 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar>>& appModel) {
115 #ifdef VERBOSE_DEBUG_OUTPUT
116 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
118 this->validSecondOrderODE_DAE(appModel);
119 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
121 appModel,
"Newmark Implicit d-Form"));
122 this->wrapperModel_ = wrapperModel;
123 inArgs_ = this->wrapperModel_->getNominalValues();
124 outArgs_ = this->wrapperModel_->createOutArgs();
127 template <
class Scalar>
131 TEUCHOS_TEST_FOR_EXCEPTION( this->wrapperModel_ == Teuchos::null,
133 "Error - Need to set the model, setModel(), before calling "
134 "StepperNewmarkImplicitDForm::initialize()\n");
136 #ifdef VERBOSE_DEBUG_OUTPUT
137 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
139 this->setParameterList(this->stepperPL_);
143 template <
class Scalar>
147 #ifdef VERBOSE_DEBUG_OUTPUT
148 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
152 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperNewmarkImplicitDForm::takeStep()");
156 "Error - StepperNewmarkImplicitDForm<Scalar>::takeStep(...)\n"
157 "Need at least two SolutionStates for NewmarkImplicitDForm.\n"
159 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
160 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
162 RCP<SolutionState<Scalar>> workingState =
solutionHistory->getWorkingState();
163 RCP<SolutionState<Scalar>> currentState =
solutionHistory->getCurrentState();
165 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
167 this->wrapperModel_);
170 RCP<const Thyra::VectorBase<Scalar>> d_old = currentState->getX();
171 RCP<Thyra::VectorBase<Scalar>> v_old = currentState->getXDot();
172 RCP<Thyra::VectorBase<Scalar>> a_old = currentState->getXDotDot();
176 RCP<Thyra::VectorBase<Scalar>> d_new = workingState->getX();
177 RCP<Thyra::VectorBase<Scalar>> v_new = workingState->getXDot();
178 RCP<Thyra::VectorBase<Scalar>> a_new = workingState->getXDotDot();
181 const Scalar time = currentState->getTime();
182 const Scalar dt = workingState->getTimeStep();
184 Scalar t = time + dt;
190 RCP<Thyra::VectorBase<Scalar>>
191 d_init = Thyra::createMember(d_old->space());
193 RCP<Thyra::VectorBase<Scalar>>
194 v_init = Thyra::createMember(v_old->space());
196 RCP<Thyra::VectorBase<Scalar>>
197 a_init = Thyra::createMember(a_old->space());
199 Thyra::copy(*a_old, a_init.ptr());
200 Thyra::copy(*v_old, v_init.ptr());
201 Thyra::copy(*d_old, d_init.ptr());
204 Teuchos::Range1D range;
206 *out_ <<
"\n*** d_init ***\n";
207 RTOpPack::ConstSubVectorView<Scalar> div;
208 d_init->acquireDetachedView(range, &div);
209 auto dia = div.values();
210 for (
auto i = 0; i < dia.size(); ++i) *out_ << dia[i] <<
" ";
211 *out_ <<
"\n*** d_init ***\n";
213 *out_ <<
"\n*** v_init ***\n";
214 RTOpPack::ConstSubVectorView<Scalar> viv;
215 v_init->acquireDetachedView(range, &viv);
216 auto via = viv.values();
217 for (
auto i = 0; i < via.size(); ++i) *out_ << via[i] <<
" ";
218 *out_ <<
"\n*** v_init ***\n";
220 *out_ <<
"\n*** a_init ***\n";
221 RTOpPack::ConstSubVectorView<Scalar> aiv;
222 a_init->acquireDetachedView(range, &aiv);
223 auto aia = aiv.values();
224 for (
auto i = 0; i < aia.size(); ++i) *out_ << aia[i] <<
" ";
225 *out_ <<
"\n*** a_init ***\n";
229 a_init, v_init, d_init, dt, time, beta_, gamma_);
231 const Thyra::SolveStatus<Scalar>
232 status = this->solveNonLinear(this->wrapperModel_, *this->solver_, d_init, inArgs_);
234 if (status.solveStatus == Thyra::SOLVE_STATUS_CONVERGED ) {
240 correctAcceleration(*a_old, *d_old, *d_init, dt);
241 Thyra::copy(*d_init, d_old.ptr());
246 Teuchos::Range1D range;
248 *out_ <<
"\n*** d_old ***\n";
249 RTOpPack::ConstSubVectorView<Scalar> dov;
250 d_old->acquireDetachedView(range, &dov);
251 auto doa = dov.values();
252 for (
auto i = 0; i < doa.size(); ++i) *out_ << doa[i] <<
" ";
253 *out_ <<
"\n*** d_old ***\n";
255 *out_ <<
"\n*** v_old ***\n";
256 RTOpPack::ConstSubVectorView<Scalar> vov;
257 v_old->acquireDetachedView(range, &vov);
258 auto voa = vov.values();
259 for (
auto i = 0; i < voa.size(); ++i) *out_ << voa[i] <<
" ";
260 *out_ <<
"\n*** v_old ***\n";
262 *out_ <<
"\n*** a_old ***\n";
263 RTOpPack::ConstSubVectorView<Scalar> aov;
264 a_old->acquireDetachedView(range, &aov);
265 auto aoa = aov.values();
266 for (
auto i = 0; i < aoa.size(); ++i) *out_ << aoa[i] <<
" ";
267 *out_ <<
"\n*** a_old ***\n";
271 RCP<Thyra::VectorBase<Scalar>> d_pred = Thyra::createMember(d_old->space());
272 RCP<Thyra::VectorBase<Scalar>> v_pred = Thyra::createMember(v_old->space());
275 predictDisplacement(*d_pred, *d_old, *v_old, *a_old, dt);
276 predictVelocity(*v_pred, *v_old, *a_old, dt);
279 *out_ <<
"\n*** d_pred ***\n";
280 RTOpPack::ConstSubVectorView<Scalar> dpv;
281 d_pred->acquireDetachedView(range, &dpv);
282 auto dpa = dpv.values();
283 for (
auto i = 0; i < dpa.size(); ++i) *out_ << dpa[i] <<
" ";
284 *out_ <<
"\n*** d_pred ***\n";
286 *out_ <<
"\n*** v_pred ***\n";
287 RTOpPack::ConstSubVectorView<Scalar> vpv;
288 v_pred->acquireDetachedView(range, &vpv);
289 auto vpa = vpv.values();
290 for (
auto i = 0; i < vpa.size(); ++i) *out_ << vpa[i] <<
" ";
291 *out_ <<
"\n*** v_pred ***\n";
295 wrapperModel->initializeNewmark(v_pred, d_pred, dt, t, beta_, gamma_);
298 RCP<Thyra::VectorBase<Scalar>> initial_guess = Thyra::createMember(d_pred->space());
299 if ((time ==
solutionHistory->minTime()) && (initial_guess_ != Teuchos::null)) {
302 bool is_compatible = (initial_guess->space())->isCompatible(*initial_guess_->space());
303 TEUCHOS_TEST_FOR_EXCEPTION(
304 is_compatible !=
true, std::logic_error,
305 "Error in Tempus::NemwarkImplicitDForm takeStep(): user-provided initial guess'!\n"
306 <<
"for Newton is not compatible with solution vector!\n");
307 Thyra::copy(*initial_guess_, initial_guess.ptr());
311 Thyra::copy(*d_pred, initial_guess.ptr());
315 const Thyra::SolveStatus<Scalar> status =
316 this->solveImplicitODE(initial_guess);
318 if (status.solveStatus == Thyra::SOLVE_STATUS_CONVERGED)
325 Thyra::copy(*initial_guess, d_new.ptr());
328 correctAcceleration(*a_new, *d_pred, *d_new, dt);
329 correctVelocity(*v_new, *v_pred, *a_new, dt);
332 *out_ <<
"\n*** d_new ***\n";
333 RTOpPack::ConstSubVectorView<Scalar> dnv;
334 d_new->acquireDetachedView(range, &dnv);
335 auto dna = dnv.values();
336 for (
auto i = 0; i < dna.size(); ++i) *out_ << dna[i] <<
" ";
337 *out_ <<
"\n*** d_new ***\n";
339 *out_ <<
"\n*** v_new ***\n";
340 RTOpPack::ConstSubVectorView<Scalar> vnv;
341 v_new->acquireDetachedView(range, &vnv);
342 auto vna = vnv.values();
343 for (
auto i = 0; i < vna.size(); ++i) *out_ << vna[i] <<
" ";
344 *out_ <<
"\n*** v_new ***\n";
346 *out_ <<
"\n*** a_new ***\n";
347 RTOpPack::ConstSubVectorView<Scalar> anv;
348 a_new->acquireDetachedView(range, &anv);
349 auto ana = anv.values();
350 for (
auto i = 0; i < ana.size(); ++i) *out_ << ana[i] <<
" ";
351 *out_ <<
"\n*** a_new ***\n";
354 workingState->setOrder(this->getOrder());
365 template <
class Scalar>
366 Teuchos::RCP<Tempus::StepperState<Scalar>>
368 #ifdef VERBOSE_DEBUG_OUTPUT
369 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
371 Teuchos::RCP<Tempus::StepperState<Scalar>> stepperState =
376 template <
class Scalar>
379 #ifdef VERBOSE_DEBUG_OUTPUT
380 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
382 std::string name =
"Newmark Implicit d-Form";
386 template <
class Scalar>
389 Teuchos::FancyOStream& out,
390 const Teuchos::EVerbosityLevel verbLevel)
const {
391 #ifdef VERBOSE_DEBUG_OUTPUT
392 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
394 out << description() <<
"::describe:" << std::endl
395 <<
"wrapperModel_ = " << this->wrapperModel_->description() << std::endl;
398 template <
class Scalar>
401 Teuchos::RCP<Teuchos::ParameterList>
const& pList) {
402 #ifdef VERBOSE_DEBUG_OUTPUT
403 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
405 if (pList == Teuchos::null) {
407 if (this->stepperPL_ == Teuchos::null) this->stepperPL_ = this->getDefaultParameters();
409 this->stepperPL_ = pList;
417 Teuchos::RCP<Teuchos::ParameterList> stepperPL = this->stepperPL_;
418 std::string stepperType = stepperPL->get<std::string>(
"Stepper Type");
419 TEUCHOS_TEST_FOR_EXCEPTION(
420 stepperType !=
"Newmark Implicit d-Form", std::logic_error,
421 "Error - Stepper Type is not 'Newmark Implicit d-Form'!\n"
422 <<
" Stepper Type = " << stepperPL->get<std::string>(
"Stepper Type")
426 Teuchos::VerboseObjectBase::getDefaultOStream();
427 if (this->stepperPL_->isSublist(
"Newmark Parameters")) {
428 Teuchos::ParameterList& newmarkPL =
429 this->stepperPL_->sublist(
"Newmark Parameters",
true);
430 std::string scheme_name = newmarkPL.get(
"Scheme Name",
"Not Specified");
431 if (scheme_name ==
"Not Specified") {
432 beta_ = newmarkPL.get(
"Beta", 0.25);
433 gamma_ = newmarkPL.get(
"Gamma", 0.5);
434 TEUCHOS_TEST_FOR_EXCEPTION(
435 (beta_ > 1.0) || (beta_ < 0.0), std::logic_error,
436 "\nError in 'Newmark Implicit d-Form' stepper: invalid value of Beta = "
437 << beta_ <<
". Please select Beta >= 0 and <= 1. \n");
438 TEUCHOS_TEST_FOR_EXCEPTION(
439 (gamma_ > 1.0) || (gamma_ < 0.0), std::logic_error,
440 "\nError in 'Newmark Implicit d-Form' stepper: invalid value of Gamma = "
441 << gamma_ <<
". Please select Gamma >= 0 and <= 1. \n");
442 *out_ <<
"\nSetting Beta = " << beta_ <<
" and Gamma = " << gamma_
443 <<
" from Newmark Parameters in input file.\n";
445 *out_ <<
"\nScheme Name = " << scheme_name <<
". Using values \n"
446 <<
"of Beta and Gamma for this scheme (ignoring values of Beta and "
448 <<
"in input file, if provided).\n";
449 if (scheme_name ==
"Average Acceleration") {
452 }
else if (scheme_name ==
"Linear Acceleration") {
455 }
else if (scheme_name ==
"Central Difference") {
459 TEUCHOS_TEST_FOR_EXCEPTION(
460 true, std::logic_error,
461 "\nError in Tempus::StepperNewmarkImplicitDForm! Invalid Scheme Name = "
462 << scheme_name <<
". \n"
463 <<
"Valid Scheme Names are: 'Average Acceleration', 'Linear "
465 <<
"'Central Difference' and 'Not Specified'.\n");
467 *out_ <<
"===> Beta = " << beta_ <<
", Gamma = " << gamma_ <<
"\n";
471 TEUCHOS_TEST_FOR_EXCEPTION(
472 true, std::logic_error,
473 "Error - d-Form of Newmark scheme is not defined for explicit (Beta = 0).\n");
476 *out_ <<
"\nNo Newmark Parameters sublist found in input file; using "
477 "default values of Beta = "
478 << beta_ <<
" and Gamma = " << gamma_ <<
".\n";
482 template <
class Scalar>
483 Teuchos::RCP<const Teuchos::ParameterList>
485 #ifdef VERBOSE_DEBUG_OUTPUT
486 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
488 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
489 pl->setName(
"Default Stepper - " + this->description());
490 pl->set(
"Stepper Type", this->description());
491 pl->set(
"Zero Initial Guess",
false);
492 pl->set(
"Solver Name",
"",
493 "Name of ParameterList containing the solver specifications.");
497 template <
class Scalar>
498 Teuchos::RCP<Teuchos::ParameterList>
500 #ifdef VERBOSE_DEBUG_OUTPUT
501 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
504 using Teuchos::ParameterList;
506 RCP<ParameterList> pl = Teuchos::parameterList();
507 pl->setName(
"Default Stepper - " + this->description());
508 pl->set<std::string>(
"Stepper Type", this->description());
509 pl->set<
bool> (
"Zero Initial Guess",
false);
510 pl->set<std::string>(
"Solver Name",
"Default Solver");
512 RCP<ParameterList> solverPL = this->defaultSolverParameters();
513 pl->set(
"Default Solver", *solverPL);
518 template <
class Scalar>
519 Teuchos::RCP<Teuchos::ParameterList>
521 #ifdef VERBOSE_DEBUG_OUTPUT
522 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
524 return (this->stepperPL_);
527 template <
class Scalar>
528 Teuchos::RCP<Teuchos::ParameterList>
530 #ifdef VERBOSE_DEBUG_OUTPUT
531 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
533 Teuchos::RCP<Teuchos::ParameterList> temp_plist = this->stepperPL_;
534 this->stepperPL_ = Teuchos::null;
539 #endif // Tempus_StepperNewmarkImplicitDForm_impl_hpp