9 #ifndef Tempus_StepperNewmarkImplicitDForm_impl_hpp 10 #define Tempus_StepperNewmarkImplicitDForm_impl_hpp 21 template <
class Scalar>
26 #ifdef VERBOSE_DEBUG_OUTPUT 27 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
30 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0, v, dt * (1.0 - gamma_), a);
33 template <
class Scalar>
38 const Scalar dt)
const {
39 #ifdef VERBOSE_DEBUG_OUTPUT 40 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
42 Teuchos::RCP<const Thyra::VectorBase<Scalar>> tmp =
43 Thyra::createMember<Scalar>(dPred.space());
45 Scalar aConst = dt * dt / 2.0 * (1.0 - 2.0 * beta_);
46 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), dt, v, aConst, a);
48 Thyra::Vp_V(Teuchos::ptrFromRef(dPred), d, 1.0);
51 template <
class Scalar>
56 #ifdef VERBOSE_DEBUG_OUTPUT 57 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
60 Thyra::V_StVpStV(Teuchos::ptrFromRef(v), 1.0, vPred, dt * gamma_, a);
63 template <
class Scalar>
68 #ifdef VERBOSE_DEBUG_OUTPUT 69 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
72 Thyra::V_StVpStV(Teuchos::ptrFromRef(d), 1.0, dPred, beta_ * dt * dt, a);
75 template <
class Scalar>
80 #ifdef VERBOSE_DEBUG_OUTPUT 81 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
84 Scalar
const c = 1.0 / beta_ / dt / dt;
85 Thyra::V_StVpStV(Teuchos::ptrFromRef(a), c, d, -c, dPred);
88 template<
class Scalar>
91 if (schemeName_ !=
"User Defined") {
92 *out_ <<
"\nWARNING: schemeName != 'User Defined' (=" <<schemeName_<<
").\n" 93 <<
" Not setting beta, and leaving as beta = " << beta_ <<
"!\n";
100 *out_ <<
"\nWARNING: Running (implicit implementation of) Newmark " 101 <<
"Implicit a-Form Stepper with Beta = 0.0, which \n" 102 <<
"specifies an explicit scheme. Mass lumping is not possible, " 103 <<
"so this will be slow! To run explicit \n" 104 <<
"implementation of Newmark Implicit a-Form Stepper, please " 105 <<
"re-run with 'Stepper Type' = 'Newmark Explicit a-Form'.\n" 106 <<
"This stepper allows for mass lumping when called through " 107 <<
"Piro::TempusSolver.\n";
110 TEUCHOS_TEST_FOR_EXCEPTION( (beta_ > 1.0) || (beta_ < 0.0),
112 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Beta = " 113 << beta_ <<
". Please select Beta >= 0 and <= 1. \n");
115 this->isInitialized_ =
false;
119 template<
class Scalar>
122 if (schemeName_ !=
"User Defined") {
123 *out_ <<
"\nWARNING: schemeName != 'User Defined' (=" <<schemeName_<<
").\n" 124 <<
" Not setting gamma, and leaving as gamma = " << gamma_ <<
"!\n";
130 TEUCHOS_TEST_FOR_EXCEPTION( (gamma_ > 1.0) || (gamma_ < 0.0),
132 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Gamma =" 133 <<gamma_ <<
". Please select Gamma >= 0 and <= 1. \n");
135 this->isInitialized_ =
false;
139 template<
class Scalar>
141 std::string schemeName)
143 schemeName_ = schemeName;
145 if (schemeName_ ==
"Average Acceleration") {
146 beta_= 0.25; gamma_ = 0.5;
148 else if (schemeName_ ==
"Linear Acceleration") {
149 beta_= 0.25; gamma_ = 1.0/6.0;
151 else if (schemeName_ ==
"Central Difference") {
152 beta_= 0.0; gamma_ = 0.5;
154 else if (schemeName_ ==
"User Defined") {
155 beta_= 0.25; gamma_ = 0.5;
158 TEUCHOS_TEST_FOR_EXCEPTION(
true,
160 "\nError in Tempus::StepperNewmarkImplicitDForm! " 161 <<
"Invalid Scheme Name = " << schemeName_ <<
". \n" 162 <<
"Valid Scheme Names are: 'Average Acceleration', " 163 <<
"'Linear Acceleration', \n" 164 <<
"'Central Difference' and 'User Defined'.\n");
167 this->isInitialized_ =
false;
171 template <
class Scalar>
173 : out_(
Teuchos::VerboseObjectBase::getDefaultOStream()) {
174 #ifdef VERBOSE_DEBUG_OUTPUT 175 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
190 template<
class Scalar>
193 const Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > & solver,
195 std::string ICConsistency,
196 bool ICConsistencyCheck,
197 bool zeroInitialGuess,
198 std::string schemeName,
202 : out_(
Teuchos::VerboseObjectBase::getDefaultOStream())
216 if (appModel != Teuchos::null) {
222 template <
class Scalar>
226 #ifdef VERBOSE_DEBUG_OUTPUT 227 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
230 this->wrapperModel_ =
232 appModel,
"Newmark Implicit d-Form"));
234 TEUCHOS_TEST_FOR_EXCEPTION(
235 this->getSolver() == Teuchos::null, std::logic_error,
236 "Error - Solver is not set!\n");
237 this->getSolver()->setModel(this->wrapperModel_);
239 this->isInitialized_ =
false;
243 template<
class Scalar>
248 if (appAction == Teuchos::null) {
250 stepperNewmarkImpAppAction_ =
253 stepperNewmarkImpAppAction_ = appAction;
256 this->isInitialized_ =
false;
260 template <
class Scalar>
264 #ifdef VERBOSE_DEBUG_OUTPUT 265 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
267 this->checkInitialized();
271 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperNewmarkImplicitDForm::takeStep()");
273 TEUCHOS_TEST_FOR_EXCEPTION(solutionHistory->getNumStates() < 2,
275 "Error - StepperNewmarkImplicitDForm<Scalar>::takeStep(...)\n" 276 "Need at least two SolutionStates for NewmarkImplicitDForm.\n" 277 " Number of States = " << solutionHistory->getNumStates() <<
"\n" 278 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n" 279 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
281 auto thisStepper = Teuchos::rcpFromRef(*
this);
282 stepperNewmarkImpAppAction_->execute(solutionHistory, thisStepper,
285 RCP<SolutionState<Scalar>> workingState =solutionHistory->getWorkingState();
286 RCP<SolutionState<Scalar>> currentState =solutionHistory->getCurrentState();
288 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
290 this->wrapperModel_);
293 RCP<const Thyra::VectorBase<Scalar>> d_old = currentState->getX();
294 RCP<Thyra::VectorBase<Scalar>> v_old = currentState->getXDot();
295 RCP<Thyra::VectorBase<Scalar>> a_old = currentState->getXDotDot();
299 RCP<Thyra::VectorBase<Scalar>> d_new = workingState->getX();
300 RCP<Thyra::VectorBase<Scalar>> v_new = workingState->getXDot();
301 RCP<Thyra::VectorBase<Scalar>> a_new = workingState->getXDotDot();
304 const Scalar time = currentState->getTime();
305 const Scalar dt = workingState->getTimeStep();
307 Scalar t = time + dt;
311 Teuchos::Range1D range;
313 *out_ <<
"\n*** d_old ***\n";
314 RTOpPack::ConstSubVectorView<Scalar> dov;
315 d_old->acquireDetachedView(range, &dov);
316 auto doa = dov.values();
317 for (
auto i = 0; i < doa.size(); ++i) *out_ << doa[i] <<
" ";
318 *out_ <<
"\n*** d_old ***\n";
320 *out_ <<
"\n*** v_old ***\n";
321 RTOpPack::ConstSubVectorView<Scalar> vov;
322 v_old->acquireDetachedView(range, &vov);
323 auto voa = vov.values();
324 for (
auto i = 0; i < voa.size(); ++i) *out_ << voa[i] <<
" ";
325 *out_ <<
"\n*** v_old ***\n";
327 *out_ <<
"\n*** a_old ***\n";
328 RTOpPack::ConstSubVectorView<Scalar> aov;
329 a_old->acquireDetachedView(range, &aov);
330 auto aoa = aov.values();
331 for (
auto i = 0; i < aoa.size(); ++i) *out_ << aoa[i] <<
" ";
332 *out_ <<
"\n*** a_old ***\n";
336 RCP<Thyra::VectorBase<Scalar>> d_pred = Thyra::createMember(d_old->space());
337 RCP<Thyra::VectorBase<Scalar>> v_pred = Thyra::createMember(v_old->space());
340 predictDisplacement(*d_pred, *d_old, *v_old, *a_old, dt);
341 predictVelocity(*v_pred, *v_old, *a_old, dt);
344 *out_ <<
"\n*** d_pred ***\n";
345 RTOpPack::ConstSubVectorView<Scalar> dpv;
346 d_pred->acquireDetachedView(range, &dpv);
347 auto dpa = dpv.values();
348 for (
auto i = 0; i < dpa.size(); ++i) *out_ << dpa[i] <<
" ";
349 *out_ <<
"\n*** d_pred ***\n";
351 *out_ <<
"\n*** v_pred ***\n";
352 RTOpPack::ConstSubVectorView<Scalar> vpv;
353 v_pred->acquireDetachedView(range, &vpv);
354 auto vpa = vpv.values();
355 for (
auto i = 0; i < vpa.size(); ++i) *out_ << vpa[i] <<
" ";
356 *out_ <<
"\n*** v_pred ***\n";
360 wrapperModel->initializeNewmark(v_pred, d_pred, dt, t, beta_, gamma_);
363 RCP<Thyra::VectorBase<Scalar>> initial_guess = Thyra::createMember(d_pred->space());
364 if ((time == solutionHistory->minTime()) && (this->initialGuess_ != Teuchos::null)) {
367 bool is_compatible = (initial_guess->space())->isCompatible(*this->initialGuess_->space());
368 TEUCHOS_TEST_FOR_EXCEPTION(
369 is_compatible !=
true, std::logic_error,
370 "Error in Tempus::NemwarkImplicitDForm takeStep(): user-provided initial guess'!\n" 371 <<
"for Newton is not compatible with solution vector!\n");
372 Thyra::copy(*this->initialGuess_, initial_guess.ptr());
376 Thyra::copy(*d_pred, initial_guess.ptr());
379 stepperNewmarkImpAppAction_->execute(solutionHistory, thisStepper,
384 const Thyra::SolveStatus<Scalar> sStatus =
385 this->solveImplicitODE(initial_guess);
387 workingState->setSolutionStatus(sStatus);
389 stepperNewmarkImpAppAction_->execute(solutionHistory, thisStepper,
394 Thyra::copy(*initial_guess, d_new.ptr());
397 correctAcceleration(*a_new, *d_pred, *d_new, dt);
398 correctVelocity(*v_new, *v_pred, *a_new, dt);
401 *out_ <<
"\n*** d_new ***\n";
402 RTOpPack::ConstSubVectorView<Scalar> dnv;
403 d_new->acquireDetachedView(range, &dnv);
404 auto dna = dnv.values();
405 for (
auto i = 0; i < dna.size(); ++i) *out_ << dna[i] <<
" ";
406 *out_ <<
"\n*** d_new ***\n";
408 *out_ <<
"\n*** v_new ***\n";
409 RTOpPack::ConstSubVectorView<Scalar> vnv;
410 v_new->acquireDetachedView(range, &vnv);
411 auto vna = vnv.values();
412 for (
auto i = 0; i < vna.size(); ++i) *out_ << vna[i] <<
" ";
413 *out_ <<
"\n*** v_new ***\n";
415 *out_ <<
"\n*** a_new ***\n";
416 RTOpPack::ConstSubVectorView<Scalar> anv;
417 a_new->acquireDetachedView(range, &anv);
418 auto ana = anv.values();
419 for (
auto i = 0; i < ana.size(); ++i) *out_ << ana[i] <<
" ";
420 *out_ <<
"\n*** a_new ***\n";
423 workingState->setOrder(this->getOrder());
424 workingState->computeNorms(currentState);
426 stepperNewmarkImpAppAction_->execute(solutionHistory, thisStepper,
438 template <
class Scalar>
439 Teuchos::RCP<Tempus::StepperState<Scalar>>
441 #ifdef VERBOSE_DEBUG_OUTPUT 442 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
444 Teuchos::RCP<Tempus::StepperState<Scalar>> stepperState =
449 template <
class Scalar>
452 Teuchos::FancyOStream& out,
453 const Teuchos::EVerbosityLevel verbLevel)
const {
454 #ifdef VERBOSE_DEBUG_OUTPUT 455 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
458 out.setOutputToRootOnly(0);
463 out <<
"--- StepperNewmarkImplicitDForm ---\n";
464 out <<
" schemeName_ = " << schemeName_ << std::endl;
465 out <<
" beta_ = " << beta_ << std::endl;
466 out <<
" gamma_ = " << gamma_ << std::endl;
467 out <<
"-----------------------------------" << std::endl;
471 template<
class Scalar>
474 out.setOutputToRootOnly(0);
475 bool isValidSetup =
true;
480 if (this->wrapperModel_->getAppModel() == Teuchos::null) {
481 isValidSetup =
false;
482 out <<
"The application ModelEvaluator is not set!\n";
485 if (this->wrapperModel_ == Teuchos::null) {
486 isValidSetup =
false;
487 out <<
"The wrapper ModelEvaluator is not set!\n";
490 if (this->solver_ == Teuchos::null) {
491 isValidSetup =
false;
492 out <<
"The solver is not set!\n";
499 template <
class Scalar>
500 Teuchos::RCP<const Teuchos::ParameterList>
502 #ifdef VERBOSE_DEBUG_OUTPUT 503 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
505 auto pl = this->getValidParametersBasicImplicit();
507 auto newmarkPL = Teuchos::parameterList(
"Newmark Parameters");
508 newmarkPL->set<std::string>(
"Scheme Name", schemeName_);
509 newmarkPL->set<
double> (
"Beta", beta_);
510 newmarkPL->set<
double> (
"Gamma", gamma_ );
511 pl->set(
"Newmark Parameters", *newmarkPL);
518 template<
class Scalar>
519 Teuchos::RCP<StepperNewmarkImplicitDForm<Scalar> >
522 Teuchos::RCP<Teuchos::ParameterList> pl)
525 stepper->setStepperImplicitValues(pl);
527 if (pl != Teuchos::null) {
528 if (pl->isSublist(
"Newmark Parameters")) {
529 auto newmarkPL = pl->sublist(
"Newmark Parameters",
true);
530 std::string schemeName =
531 newmarkPL.get<std::string>(
"Scheme Name",
"Average Acceleration");
532 stepper->setSchemeName(schemeName);
533 if (schemeName ==
"User Defined") {
534 stepper->setBeta (newmarkPL.get<
double>(
"Beta", 0.25));
535 stepper->setGamma(newmarkPL.get<
double>(
"Gamma", 0.5 ));
538 stepper->setSchemeName(
"Average Acceleration");
542 if (model != Teuchos::null) {
543 stepper->setModel(model);
544 stepper->initialize();
552 #endif // Tempus_StepperNewmarkImplicitDForm_impl_hpp
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver) override
Set solver.
Teuchos::RCP< StepperNewmarkImplicitDForm< Scalar > > createStepperNewmarkImplicitDForm(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
void setStepperName(std::string s)
Set the stepper name.
virtual void initialize()
Initialize after construction and changing input parameters.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
A ModelEvaluator for residual evaluations given a state. This ModelEvaluator takes a state...
Thyra Base interface for time steppers.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
StepperState is a simple class to hold state information about the stepper.
virtual void setDefaultSolver()
void setICConsistencyCheck(bool c)
virtual void setZeroInitialGuess(bool zIG)
Set parameter so that the initial guess is set to zero (=True) or use last timestep (=False)...
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
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]...
virtual void setUseFSAL(bool a)
void setStepperType(std::string s)
Set the stepper type.
void setICConsistency(std::string s)