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";
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";
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";
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;
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>
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"));
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()");
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();
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;
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());
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,
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>
441 #ifdef VERBOSE_DEBUG_OUTPUT
442 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
449 template <
class Scalar>
454 #ifdef VERBOSE_DEBUG_OUTPUT
455 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
462 out <<
"--- StepperNewmarkImplicitDForm ---\n";
463 out <<
" schemeName_ = " << schemeName_ << std::endl;
464 out <<
" beta_ = " << beta_ << std::endl;
465 out <<
" gamma_ = " << gamma_ << std::endl;
466 out <<
"-----------------------------------" << std::endl;
470 template<
class Scalar>
473 bool isValidSetup =
true;
478 if (this->wrapperModel_->getAppModel() == Teuchos::null) {
479 isValidSetup =
false;
480 out <<
"The application ModelEvaluator is not set!\n";
483 if (this->wrapperModel_ == Teuchos::null) {
484 isValidSetup =
false;
485 out <<
"The wrapper ModelEvaluator is not set!\n";
488 if (this->solver_ == Teuchos::null) {
489 isValidSetup =
false;
490 out <<
"The solver is not set!\n";
497 template <
class Scalar>
500 #ifdef VERBOSE_DEBUG_OUTPUT
501 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
503 auto pl = this->getValidParametersBasicImplicit();
505 auto newmarkPL = Teuchos::parameterList(
"Newmark Parameters");
506 newmarkPL->set<std::string>(
"Scheme Name", schemeName_);
507 newmarkPL->set<
double> (
"Beta", beta_);
508 newmarkPL->set<
double> (
"Gamma", gamma_ );
509 pl->set(
"Newmark Parameters", *newmarkPL);
516 template<
class Scalar>
523 stepper->setStepperImplicitValues(pl);
525 if (pl != Teuchos::null) {
526 if (pl->
isSublist(
"Newmark Parameters")) {
527 auto newmarkPL = pl->
sublist(
"Newmark Parameters",
true);
528 std::string schemeName =
529 newmarkPL.
get<std::string>(
"Scheme Name",
"Average Acceleration");
530 stepper->setSchemeName(schemeName);
531 if (schemeName ==
"User Defined") {
532 stepper->setBeta (newmarkPL.get<
double>(
"Beta", 0.25));
533 stepper->setGamma(newmarkPL.get<
double>(
"Gamma", 0.5 ));
536 stepper->setSchemeName(
"Average Acceleration");
540 if (model != Teuchos::null) {
541 stepper->setModel(model);
542 stepper->initialize();
550 #endif // Tempus_StepperNewmarkImplicitDForm_impl_hpp
virtual RCP< const VectorSpaceBase< Scalar > > space() const =0
Teuchos::RCP< StepperNewmarkImplicitDForm< Scalar > > createStepperNewmarkImplicitDForm(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
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)
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]...
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void setUseFSAL(bool a)
void setStepperType(std::string s)
Set the stepper type.
void setICConsistency(std::string s)