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";
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";
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";
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;
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>
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"));
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();
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();
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;
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);
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());
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) {
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_);
359 "Error - Solver failed while determining the initial conditions.\n"
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);
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);
400 if (normx > eps*reldiff) reldiff /= normx;
403 RCP<Teuchos::FancyOStream> out = this->getOStream();
404 out->setOutputToRootOnly(0);
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);
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()");
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,
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>
518 #ifdef VERBOSE_DEBUG_OUTPUT
519 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
527 template<
class Scalar>
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 bool isValidSetup =
true;
558 if (this->wrapperModel_->getAppModel() == Teuchos::null) {
559 isValidSetup =
false;
560 out <<
"The application ModelEvaluator is not set!\n";
563 if (this->wrapperModel_ == Teuchos::null) {
564 isValidSetup =
false;
565 out <<
"The wrapper ModelEvaluator is not set!\n";
568 if (this->solver_ == Teuchos::null) {
569 isValidSetup =
false;
570 out <<
"The solver is not set!\n";
573 if (this->stepperNewmarkImpAppAction_ == Teuchos::null){
574 isValidSetup =
false;
575 out <<
"The Newmark Implicit A-Form AppAction is not set!\n";
582 template<
class Scalar>
586 #ifdef VERBOSE_DEBUG_OUTPUT
587 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
589 auto pl = this->getValidParametersBasicImplicit();
591 auto newmarkPL = Teuchos::parameterList(
"Newmark Parameters");
592 newmarkPL->set<std::string>(
"Scheme Name", schemeName_);
593 newmarkPL->set<
double> (
"Beta", beta_);
594 newmarkPL->set<
double> (
"Gamma", gamma_ );
595 pl->set(
"Newmark Parameters", *newmarkPL);
603 template<
class Scalar>
610 stepper->setStepperImplicitValues(pl);
612 if (pl != Teuchos::null) {
613 if (pl->
isSublist(
"Newmark Parameters")) {
614 auto newmarkPL = pl->
sublist(
"Newmark Parameters",
true);
615 std::string schemeName =
616 newmarkPL.
get<std::string>(
"Scheme Name",
"Average Acceleration");
617 stepper->setSchemeName(schemeName);
618 if (schemeName ==
"User Defined") {
619 stepper->setBeta (newmarkPL.get<
double>(
"Beta", 0.25));
620 stepper->setGamma(newmarkPL.get<
double>(
"Gamma", 0.5 ));
623 stepper->setSchemeName(
"Average Acceleration");
627 if (model != Teuchos::null) {
628 stepper->setModel(model);
629 stepper->initialize();
637 #endif // Tempus_StepperNewmarkImplicitAForm_impl_hpp
virtual RCP< const VectorSpaceBase< Scalar > > space() const =0
Teuchos::RCP< StepperNewmarkImplicitAForm< Scalar > > createStepperNewmarkImplicitAForm(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
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.
T & get(const std::string &name, T def_value)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void setStepperName(std::string s)
Set the stepper name.
virtual void initialize()
Initialize after construction and changing input parameters.
A ModelEvaluator for residual evaluations given a state. This ModelEvaluator takes a state...
Thyra Base interface for time steppers.
StepperState is a simple class to hold state information about the stepper.
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver)
Set solver.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
bool isSublist(const std::string &name) const
virtual void setDefaultSolver()
void setICConsistencyCheck(bool c)
TEUCHOSCORE_LIB_DLL_EXPORT std::string toString(const EVerbosityLevel verbLevel)
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...
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
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]...
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void setStepperType(std::string s)
Set the stepper type.
void setICConsistency(std::string s)