9 #ifndef Tempus_StepperNewmarkImplicitAForm_impl_hpp 10 #define Tempus_StepperNewmarkImplicitAForm_impl_hpp 21 template<
class Scalar>
26 const Scalar dt)
const 28 #ifdef VERBOSE_DEBUG_OUTPUT 29 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
32 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0, v, dt*(1.0-gamma_), a);
35 template<
class Scalar>
41 const Scalar dt)
const 43 #ifdef VERBOSE_DEBUG_OUTPUT 44 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
46 Teuchos::RCP<const Thyra::VectorBase<Scalar> > tmp =
47 Thyra::createMember<Scalar>(dPred.space());
49 Scalar aConst = dt*dt/2.0*(1.0-2.0*beta_);
50 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), dt, v, aConst, a);
52 Thyra::Vp_V(Teuchos::ptrFromRef(dPred), d, 1.0);
55 template<
class Scalar>
60 const Scalar dt)
const 62 #ifdef VERBOSE_DEBUG_OUTPUT 63 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
66 Thyra::V_StVpStV(Teuchos::ptrFromRef(v), 1.0, vPred, dt*gamma_, a);
69 template<
class Scalar>
74 const Scalar dt)
const 76 #ifdef VERBOSE_DEBUG_OUTPUT 77 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
80 Thyra::V_StVpStV(Teuchos::ptrFromRef(d), 1.0, dPred, beta_*dt*dt, a);
84 template<
class Scalar>
87 if (schemeName_ !=
"User Defined") {
88 *out_ <<
"\nWARNING: schemeName != 'User Defined' (=" <<schemeName_<<
").\n" 89 <<
" Not setting beta, and leaving as beta = " << beta_ <<
"!\n";
96 *out_ <<
"\nWARNING: Running (implicit implementation of) Newmark " 97 <<
"Implicit a-Form Stepper with Beta = 0.0, which \n" 98 <<
"specifies an explicit scheme. Mass lumping is not possible, " 99 <<
"so this will be slow! To run explicit \n" 100 <<
"implementation of Newmark Implicit a-Form Stepper, please " 101 <<
"re-run with 'Stepper Type' = 'Newmark Explicit a-Form'.\n" 102 <<
"This stepper allows for mass lumping when called through " 103 <<
"Piro::TempusSolver.\n";
106 TEUCHOS_TEST_FOR_EXCEPTION( (beta_ > 1.0) || (beta_ < 0.0),
108 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Beta = " 109 << beta_ <<
". Please select Beta >= 0 and <= 1. \n");
113 template<
class Scalar>
116 if (schemeName_ !=
"User Defined") {
117 *out_ <<
"\nWARNING: schemeName != 'User Defined' (=" <<schemeName_<<
").\n" 118 <<
" Not setting gamma, and leaving as gamma = " << gamma_ <<
"!\n";
124 TEUCHOS_TEST_FOR_EXCEPTION( (gamma_ > 1.0) || (gamma_ < 0.0),
126 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Gamma =" 127 <<gamma_ <<
". Please select Gamma >= 0 and <= 1. \n");
131 template<
class Scalar>
133 std::string schemeName)
135 schemeName_ = schemeName;
137 if (schemeName_ ==
"Average Acceleration") {
138 beta_= 0.25; gamma_ = 0.5;
140 else if (schemeName_ ==
"Linear Acceleration") {
141 beta_= 0.25; gamma_ = 1.0/6.0;
143 else if (schemeName_ ==
"Central Difference") {
144 beta_= 0.0; gamma_ = 0.5;
146 else if (schemeName_ ==
"User Defined") {
147 beta_= 0.25; gamma_ = 0.5;
150 TEUCHOS_TEST_FOR_EXCEPTION(
true,
152 "\nError in Tempus::StepperNewmarkImplicitAForm! " 153 <<
"Invalid Scheme Name = " << schemeName_ <<
". \n" 154 <<
"Valid Scheme Names are: 'Average Acceleration', " 155 <<
"'Linear Acceleration', \n" 156 <<
"'Central Difference' and 'User Defined'.\n");
159 this->isInitialized_ =
false;
162 template<
class Scalar>
167 if (appAction == Teuchos::null) {
169 stepperNewmarkImpAppAction_ =
172 stepperNewmarkImpAppAction_ = appAction;
175 this->isInitialized_ =
false;
179 template<
class Scalar>
181 out_(
Teuchos::VerboseObjectBase::getDefaultOStream())
183 #ifdef VERBOSE_DEBUG_OUTPUT 184 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
200 template<
class Scalar>
203 const Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
205 std::string ICConsistency,
206 bool ICConsistencyCheck,
207 bool zeroInitialGuess,
208 std::string schemeName,
212 : out_(
Teuchos::VerboseObjectBase::getDefaultOStream())
226 if (appModel != Teuchos::null) {
233 template<
class Scalar>
237 #ifdef VERBOSE_DEBUG_OUTPUT 238 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
241 this->wrapperModel_ =
243 "Newmark Implicit a-Form"));
245 TEUCHOS_TEST_FOR_EXCEPTION(
246 this->getSolver() == Teuchos::null, std::logic_error,
247 "Error - Solver is not set!\n");
248 this->getSolver()->setModel(this->wrapperModel_);
250 this->isInitialized_ =
false;
254 template<
class Scalar>
260 int numStates = solutionHistory->getNumStates();
262 TEUCHOS_TEST_FOR_EXCEPTION(numStates < 1, std::logic_error,
263 "Error - setInitialConditions() needs at least one SolutionState\n" 264 " to set the initial condition. Number of States = " << numStates);
267 RCP<Teuchos::FancyOStream> out = this->getOStream();
268 out->setOutputToRootOnly(0);
269 Teuchos::OSTab ostab(out,1,
"StepperNewmarkImplicitAForm::setInitialConditions()");
270 *out <<
"Warning -- SolutionHistory has more than one state!\n" 271 <<
"Setting the initial conditions on the currentState.\n"<<std::endl;
274 RCP<SolutionState<Scalar> > initialState = solutionHistory->getCurrentState();
275 RCP<Thyra::VectorBase<Scalar> > x = initialState->getX();
276 RCP<Thyra::VectorBase<Scalar> > xDot = initialState->getXDot();
278 auto inArgs = this->wrapperModel_->getNominalValues();
279 TEUCHOS_TEST_FOR_EXCEPTION(
280 !((x != Teuchos::null && xDot != Teuchos::null) ||
281 (inArgs.get_x() != Teuchos::null &&
282 inArgs.get_x_dot() != Teuchos::null)), std::logic_error,
283 "Error - We need to set the initial conditions for x and xDot from\n" 284 " either initialState or appModel_->getNominalValues::InArgs\n" 285 " (but not from a mixture of the two).\n");
288 if ( x == Teuchos::null || xDot == Teuchos::null ) {
289 using Teuchos::rcp_const_cast;
290 TEUCHOS_TEST_FOR_EXCEPTION( (inArgs.get_x() == Teuchos::null) ||
291 (inArgs.get_x_dot() == Teuchos::null), std::logic_error,
292 "Error - setInitialConditions() needs the ICs from the initialState\n" 293 " or getNominalValues()!\n");
295 initialState->setX(x);
297 initialState->setXDot(xDot);
301 if (initialState->getXDotDot() == Teuchos::null)
302 initialState->setXDotDot(initialState->getX()->clone_v());
304 this->setStepperXDotDot(initialState->getXDotDot());
307 std::string icConsistency = this->getICConsistency();
308 if (icConsistency ==
"None") {
309 if (initialState->getXDotDot() == Teuchos::null) {
310 RCP<Teuchos::FancyOStream> out = this->getOStream();
311 out->setOutputToRootOnly(0);
312 Teuchos::OSTab ostab(out,1,
313 "StepperNewmarkImplicitAForm::setInitialConditions()");
314 *out <<
"Warning -- Requested IC consistency of 'None' but\n" 315 <<
" initialState does not have an xDot.\n" 316 <<
" Setting a 'Zero' xDot!\n" << std::endl;
318 Thyra::assign(this->getStepperXDotDot(initialState).ptr(), Scalar(0.0));
321 else if (icConsistency ==
"Zero")
322 Thyra::assign(this->getStepperXDotDot(initialState).ptr(), Scalar(0.0));
323 else if (icConsistency ==
"App") {
325 inArgs.get_x_dot_dot());
326 TEUCHOS_TEST_FOR_EXCEPTION(xDotDot == Teuchos::null, std::logic_error,
327 "Error - setInitialConditions() requested 'App' for IC consistency,\n" 328 " but 'App' returned a null pointer for xDotDot!\n");
329 Thyra::assign(this->getStepperXDotDot(initialState).ptr(), *xDotDot);
331 else if (icConsistency ==
"Consistent") {
333 const Scalar time = initialState->getTime();
334 auto xDotDot = this->getStepperXDotDot(initialState);
338 if (this->initialGuess_ != Teuchos::null) {
339 TEUCHOS_TEST_FOR_EXCEPTION(
340 !((xDotDot->space())->isCompatible(*this->initialGuess_->space())),
342 "Error - User-provided initial guess for Newton is not compatible\n" 343 " with solution vector!\n");
344 Thyra::copy(*this->initialGuess_, xDotDot.ptr());
347 Thyra::put_scalar(0.0, xDotDot.ptr());
352 this->wrapperModel_);
355 const Thyra::SolveStatus<Scalar> sStatus = this->solveImplicitODE(xDotDot);
357 TEUCHOS_TEST_FOR_EXCEPTION(
358 sStatus.solveStatus != Thyra::SOLVE_STATUS_CONVERGED, std::logic_error,
359 "Error - Solver failed while determining the initial conditions.\n" 363 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
364 "Error - setInitialConditions() invalid IC consistency, " 365 << icConsistency <<
".\n");
370 initialState->setIsSynced(
true);
373 if (this->getICConsistencyCheck()) {
374 auto f = initialState->getX()->clone_v();
375 auto xDotDot = this->getStepperXDotDot(initialState);
377 typedef Thyra::ModelEvaluatorBase MEB;
378 MEB::InArgs<Scalar> appInArgs =
379 this->wrapperModel_->getAppModel()->createInArgs();
380 MEB::OutArgs<Scalar> appOutArgs =
381 this->wrapperModel_->getAppModel()->createOutArgs();
383 appInArgs.set_x (x );
384 appInArgs.set_x_dot (xDot );
385 appInArgs.set_x_dot_dot(xDotDot);
387 appOutArgs.set_f(appOutArgs.get_f());
389 appInArgs.set_W_x_dot_dot_coeff(Scalar(0.0));
390 appInArgs.set_alpha (Scalar(0.0));
391 appInArgs.set_beta (Scalar(0.0));
393 appInArgs.set_t (initialState->getTime() );
395 this->wrapperModel_->getAppModel()->evalModel(appInArgs, appOutArgs);
397 Scalar reldiff = Thyra::norm(*f);
398 Scalar normx = Thyra::norm(*x);
399 Scalar eps = Scalar(100.0)*std::abs(Teuchos::ScalarTraits<Scalar>::eps());
400 if (normx > eps*reldiff) reldiff /= normx;
403 RCP<Teuchos::FancyOStream> out = this->getOStream();
404 out->setOutputToRootOnly(0);
405 Teuchos::OSTab ostab(out,1,
406 "StepperNewmarkImplicitAForm::setInitialConditions()");
407 *out <<
"Warning -- Failed consistency check but continuing!\n" 408 <<
" ||f(x,xDot,xDotDot,t)||/||x|| > eps" << std::endl
409 <<
" ||f(x,xDot,xDotDot,t)|| = " << Thyra::norm(*f)<< std::endl
410 <<
" ||x|| = " << Thyra::norm(*x)<< std::endl
411 <<
" ||f(x,xDot,xDotDot,t)||/||x|| = " << reldiff << std::endl
412 <<
" eps = " << eps << std::endl;
416 if (!(this->getUseFSAL())) {
417 RCP<Teuchos::FancyOStream> out = this->getOStream();
418 out->setOutputToRootOnly(0);
419 Teuchos::OSTab ostab(out,1,
420 "StepperNewmarkImplicitAForm::setInitialConditions()");
421 *out <<
"\nWarning -- The First-Same-As-Last (FSAL) principle is " 422 <<
"part of the Newmark Implicit A-Form. The default is to " 423 <<
"set useFSAL=true, and useFSAL=false will be ignored." << std::endl;
428 template<
class Scalar>
432 #ifdef VERBOSE_DEBUG_OUTPUT 433 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
435 this->checkInitialized();
439 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperNewmarkImplicitAForm::takeStep()");
441 TEUCHOS_TEST_FOR_EXCEPTION(solutionHistory->getNumStates() < 2,
443 "Error - StepperNewmarkImplicitAForm<Scalar>::takeStep(...)\n" 444 "Need at least two SolutionStates for NewmarkImplicitAForm.\n" 445 " Number of States = " << solutionHistory->getNumStates() <<
"\n" 446 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n" 447 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
449 auto thisStepper = Teuchos::rcpFromRef(*
this);
450 stepperNewmarkImpAppAction_->execute(solutionHistory, thisStepper,
453 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
454 RCP<SolutionState<Scalar> > currentState=solutionHistory->getCurrentState();
458 this->wrapperModel_);
461 RCP<const Thyra::VectorBase<Scalar> > d_old = currentState->getX();
462 RCP<const Thyra::VectorBase<Scalar> > v_old = currentState->getXDot();
463 RCP< Thyra::VectorBase<Scalar> > a_old = currentState->getXDotDot();
466 RCP<Thyra::VectorBase<Scalar> > d_new = workingState->getX();
467 RCP<Thyra::VectorBase<Scalar> > v_new = workingState->getXDot();
468 RCP<Thyra::VectorBase<Scalar> > a_new = workingState->getXDotDot();
471 const Scalar time = currentState->getTime();
472 const Scalar dt = workingState->getTimeStep();
476 predictDisplacement(*d_new, *d_old, *v_old, *a_old, dt);
477 predictVelocity(*v_new, *v_old, *a_old, dt);
480 wrapperModel->initializeNewmark(v_new,d_new,dt,t,beta_,gamma_);
482 stepperNewmarkImpAppAction_->execute(solutionHistory, thisStepper,
486 const Thyra::SolveStatus<Scalar> sStatus = this->solveImplicitODE(a_new);
488 stepperNewmarkImpAppAction_->execute(solutionHistory, thisStepper,
492 correctVelocity(*v_new, *v_new, *a_new, dt);
493 correctDisplacement(*d_new, *d_new, *a_new, dt);
495 workingState->setSolutionStatus(sStatus);
496 workingState->setOrder(this->getOrder());
497 workingState->computeNorms(currentState);
499 stepperNewmarkImpAppAction_->execute(solutionHistory, thisStepper,
513 template<
class Scalar>
514 Teuchos::RCP<Tempus::StepperState<Scalar> >
518 #ifdef VERBOSE_DEBUG_OUTPUT 519 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
521 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
527 template<
class Scalar>
529 Teuchos::FancyOStream &out,
530 const Teuchos::EVerbosityLevel verbLevel)
const 532 out.setOutputToRootOnly(0);
533 #ifdef VERBOSE_DEBUG_OUTPUT 534 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
541 out <<
"--- StepperNewmarkImplicitAForm ---\n";
542 out <<
" schemeName_ = " << schemeName_ << std::endl;
543 out <<
" beta_ = " << beta_ << std::endl;
544 out <<
" gamma_ = " << gamma_ << std::endl;
545 out <<
"-----------------------------------" << std::endl;
549 template<
class Scalar>
552 out.setOutputToRootOnly(0);
553 bool isValidSetup =
true;
554 out.setOutputToRootOnly(0);
559 if (this->wrapperModel_->getAppModel() == Teuchos::null) {
560 isValidSetup =
false;
561 out <<
"The application ModelEvaluator is not set!\n";
564 if (this->wrapperModel_ == Teuchos::null) {
565 isValidSetup =
false;
566 out <<
"The wrapper ModelEvaluator is not set!\n";
569 if (this->solver_ == Teuchos::null) {
570 isValidSetup =
false;
571 out <<
"The solver is not set!\n";
574 if (this->stepperNewmarkImpAppAction_ == Teuchos::null){
575 isValidSetup =
false;
576 out <<
"The Newmark Implicit A-Form AppAction is not set!\n";
583 template<
class Scalar>
584 Teuchos::RCP<const Teuchos::ParameterList>
587 #ifdef VERBOSE_DEBUG_OUTPUT 588 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
590 auto pl = this->getValidParametersBasicImplicit();
592 auto newmarkPL = Teuchos::parameterList(
"Newmark Parameters");
593 newmarkPL->set<std::string>(
"Scheme Name", schemeName_);
594 newmarkPL->set<
double> (
"Beta", beta_);
595 newmarkPL->set<
double> (
"Gamma", gamma_ );
596 pl->set(
"Newmark Parameters", *newmarkPL);
604 template<
class Scalar>
605 Teuchos::RCP<StepperNewmarkImplicitAForm<Scalar> >
608 Teuchos::RCP<Teuchos::ParameterList> pl)
611 stepper->setStepperImplicitValues(pl);
613 if (pl != Teuchos::null) {
614 if (pl->isSublist(
"Newmark Parameters")) {
615 auto newmarkPL = pl->sublist(
"Newmark Parameters",
true);
616 std::string schemeName =
617 newmarkPL.get<std::string>(
"Scheme Name",
"Average Acceleration");
618 stepper->setSchemeName(schemeName);
619 if (schemeName ==
"User Defined") {
620 stepper->setBeta (newmarkPL.get<
double>(
"Beta", 0.25));
621 stepper->setGamma(newmarkPL.get<
double>(
"Gamma", 0.5 ));
624 stepper->setSchemeName(
"Average Acceleration");
628 if (model != Teuchos::null) {
629 stepper->setModel(model);
630 stepper->initialize();
638 #endif // Tempus_StepperNewmarkImplicitAForm_impl_hpp
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver) override
Set solver.
Teuchos::RCP< StepperNewmarkImplicitAForm< Scalar > > createStepperNewmarkImplicitAForm(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
const std::string toString(const Status status)
Convert Status to string.
void initializeNewmark(Teuchos::RCP< const Vector > v_pred, Teuchos::RCP< const Vector > d_pred, Scalar delta_t, Scalar t, Scalar beta, Scalar gamma)
Set values needed in evalModelImpl.
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]...
void setStepperType(std::string s)
Set the stepper type.
void setICConsistency(std::string s)