10 #ifndef Tempus_StepperNewmarkImplicitDForm_impl_hpp
11 #define Tempus_StepperNewmarkImplicitDForm_impl_hpp
20 template <
class Scalar>
25 #ifdef VERBOSE_DEBUG_OUTPUT
26 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
29 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0, v, dt * (1.0 - gamma_), a);
32 template <
class Scalar>
36 const Scalar dt)
const
38 #ifdef VERBOSE_DEBUG_OUTPUT
39 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
42 Thyra::createMember<Scalar>(dPred.
space());
44 Scalar aConst = dt * dt / 2.0 * (1.0 - 2.0 * beta_);
45 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), dt, v, aConst, a);
47 Thyra::Vp_V(Teuchos::ptrFromRef(dPred), d, 1.0);
50 template <
class Scalar>
55 #ifdef VERBOSE_DEBUG_OUTPUT
56 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
59 Thyra::V_StVpStV(Teuchos::ptrFromRef(v), 1.0, vPred, dt * gamma_, a);
62 template <
class Scalar>
67 #ifdef VERBOSE_DEBUG_OUTPUT
68 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
71 Thyra::V_StVpStV(Teuchos::ptrFromRef(d), 1.0, dPred, beta_ * dt * dt, a);
74 template <
class Scalar>
79 #ifdef VERBOSE_DEBUG_OUTPUT
80 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
83 Scalar
const c = 1.0 / beta_ / dt / dt;
84 Thyra::V_StVpStV(Teuchos::ptrFromRef(a), c, d, -c, dPred);
87 template <
class Scalar>
90 if (schemeName_ !=
"User Defined") {
91 *out_ <<
"\nWARNING: schemeName != 'User Defined' (=" << schemeName_
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";
111 (beta_ > 1.0) || (beta_ < 0.0), std::logic_error,
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;
118 template <
class Scalar>
121 if (schemeName_ !=
"User Defined") {
122 *out_ <<
"\nWARNING: schemeName != 'User Defined' (=" << schemeName_
124 <<
" Not setting gamma, and leaving as gamma = " << gamma_ <<
"!\n";
131 (gamma_ > 1.0) || (gamma_ < 0.0), std::logic_error,
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;
138 template <
class Scalar>
141 schemeName_ = schemeName;
143 if (schemeName_ ==
"Average Acceleration") {
147 else if (schemeName_ ==
"Linear Acceleration") {
151 else if (schemeName_ ==
"Central Difference") {
155 else if (schemeName_ ==
"User Defined") {
161 true, std::logic_error,
162 "\nError in Tempus::StepperNewmarkImplicitDForm! "
163 <<
"Invalid Scheme Name = " << schemeName_ <<
". \n"
164 <<
"Valid Scheme Names are: 'Average Acceleration', "
165 <<
"'Linear Acceleration', \n"
166 <<
"'Central Difference' and 'User Defined'.\n");
169 this->isInitialized_ =
false;
172 template <
class Scalar>
174 : out_(Teuchos::VerboseObjectBase::getDefaultOStream())
176 #ifdef VERBOSE_DEBUG_OUTPUT
177 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
192 template <
class Scalar>
196 bool useFSAL, std::string ICConsistency,
bool ICConsistencyCheck,
197 bool zeroInitialGuess, std::string schemeName, Scalar beta, Scalar gamma,
200 : out_(Teuchos::VerboseObjectBase::getDefaultOStream())
214 if (appModel != Teuchos::null) {
220 template <
class Scalar>
224 #ifdef VERBOSE_DEBUG_OUTPUT
225 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
228 this->wrapperModel_ =
230 appModel,
"Newmark Implicit d-Form"));
233 std::logic_error,
"Error - Solver is not set!\n");
234 this->getSolver()->setModel(this->wrapperModel_);
236 this->isInitialized_ =
false;
239 template <
class Scalar>
243 if (appAction == Teuchos::null) {
245 stepperNewmarkImpAppAction_ =
249 stepperNewmarkImpAppAction_ = appAction;
252 this->isInitialized_ =
false;
255 template <
class Scalar>
259 #ifdef VERBOSE_DEBUG_OUTPUT
260 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
262 this->checkInitialized();
266 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperNewmarkImplicitDForm::takeStep()");
269 solutionHistory->getNumStates() < 2, std::logic_error,
270 "Error - StepperNewmarkImplicitDForm<Scalar>::takeStep(...)\n"
271 <<
"Need at least two SolutionStates for NewmarkImplicitDForm.\n"
272 <<
" Number of States = " << solutionHistory->getNumStates()
273 <<
"\nTry setting in \"Solution History\" \"Storage Type\" = "
275 <<
" or \"Storage Type\" = \"Static\" and \"Storage Limit\" = "
278 auto thisStepper = Teuchos::rcpFromRef(*
this);
279 stepperNewmarkImpAppAction_->execute(
280 solutionHistory, thisStepper,
282 Scalar>::ACTION_LOCATION::BEGIN_STEP);
284 RCP<SolutionState<Scalar>> workingState =
285 solutionHistory->getWorkingState();
286 RCP<SolutionState<Scalar>> currentState =
287 solutionHistory->getCurrentState();
291 this->wrapperModel_);
294 RCP<const Thyra::VectorBase<Scalar>> d_old = currentState->getX();
295 RCP<Thyra::VectorBase<Scalar>> v_old = currentState->getXDot();
296 RCP<Thyra::VectorBase<Scalar>> a_old = currentState->getXDotDot();
300 RCP<Thyra::VectorBase<Scalar>> d_new = workingState->getX();
301 RCP<Thyra::VectorBase<Scalar>> v_new = workingState->getXDot();
302 RCP<Thyra::VectorBase<Scalar>> a_new = workingState->getXDotDot();
305 const Scalar time = currentState->getTime();
306 const Scalar dt = workingState->getTimeStep();
308 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 =
364 Thyra::createMember(d_pred->space());
365 if ((time == solutionHistory->minTime()) &&
366 (this->initialGuess_ != Teuchos::null)) {
371 (initial_guess->space())->isCompatible(*this->initialGuess_->space());
373 is_compatible !=
true, std::logic_error,
374 "Error in Tempus::NemwarkImplicitDForm takeStep(): user-provided "
376 <<
"for Newton is not compatible with solution vector!\n");
377 Thyra::copy(*this->initialGuess_, initial_guess.ptr());
381 Thyra::copy(*d_pred, initial_guess.ptr());
384 stepperNewmarkImpAppAction_->execute(
385 solutionHistory, thisStepper,
387 Scalar>::ACTION_LOCATION::BEFORE_SOLVE);
391 (*(this->solver_)).solve(&*initial_guess);
393 workingState->setSolutionStatus(sStatus);
395 stepperNewmarkImpAppAction_->execute(
396 solutionHistory, thisStepper,
398 Scalar>::ACTION_LOCATION::AFTER_SOLVE);
402 Thyra::copy(*initial_guess, d_new.ptr());
405 correctAcceleration(*a_new, *d_pred, *d_new, dt);
406 correctVelocity(*v_new, *v_pred, *a_new, dt);
409 *out_ <<
"\n*** d_new ***\n";
410 RTOpPack::ConstSubVectorView<Scalar> dnv;
411 d_new->acquireDetachedView(range, &dnv);
412 auto dna = dnv.values();
413 for (
auto i = 0; i < dna.size(); ++i) *out_ << dna[i] <<
" ";
414 *out_ <<
"\n*** d_new ***\n";
416 *out_ <<
"\n*** v_new ***\n";
417 RTOpPack::ConstSubVectorView<Scalar> vnv;
418 v_new->acquireDetachedView(range, &vnv);
419 auto vna = vnv.values();
420 for (
auto i = 0; i < vna.size(); ++i) *out_ << vna[i] <<
" ";
421 *out_ <<
"\n*** v_new ***\n";
423 *out_ <<
"\n*** a_new ***\n";
424 RTOpPack::ConstSubVectorView<Scalar> anv;
425 a_new->acquireDetachedView(range, &anv);
426 auto ana = anv.values();
427 for (
auto i = 0; i < ana.size(); ++i) *out_ << ana[i] <<
" ";
428 *out_ <<
"\n*** a_new ***\n";
431 workingState->setOrder(this->getOrder());
432 workingState->computeNorms(currentState);
434 stepperNewmarkImpAppAction_->execute(
435 solutionHistory, thisStepper,
437 Scalar>::ACTION_LOCATION::END_STEP);
448 template <
class Scalar>
452 #ifdef VERBOSE_DEBUG_OUTPUT
453 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
460 template <
class Scalar>
464 #ifdef VERBOSE_DEBUG_OUTPUT
465 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
473 out <<
"--- StepperNewmarkImplicitDForm ---\n";
474 out <<
" schemeName_ = " << schemeName_ << std::endl;
475 out <<
" beta_ = " << beta_ << std::endl;
476 out <<
" gamma_ = " << gamma_ << std::endl;
477 out <<
"-----------------------------------" << std::endl;
480 template <
class Scalar>
485 bool isValidSetup =
true;
490 if (this->wrapperModel_->getAppModel() == Teuchos::null) {
491 isValidSetup =
false;
492 out <<
"The application ModelEvaluator is not set!\n";
495 if (this->wrapperModel_ == Teuchos::null) {
496 isValidSetup =
false;
497 out <<
"The wrapper ModelEvaluator is not set!\n";
500 if (this->solver_ == Teuchos::null) {
501 isValidSetup =
false;
502 out <<
"The solver is not set!\n";
508 template <
class Scalar>
512 #ifdef VERBOSE_DEBUG_OUTPUT
513 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
515 auto pl = this->getValidParametersBasicImplicit();
517 auto newmarkPL = Teuchos::parameterList(
"Newmark Parameters");
518 newmarkPL->set<std::string>(
"Scheme Name", schemeName_);
519 newmarkPL->set<
double>(
"Beta", beta_);
520 newmarkPL->set<
double>(
"Gamma", gamma_);
521 pl->set(
"Newmark Parameters", *newmarkPL);
528 template <
class Scalar>
535 stepper->setStepperImplicitValues(pl);
537 if (pl != Teuchos::null) {
538 if (pl->
isSublist(
"Newmark Parameters")) {
539 auto newmarkPL = pl->
sublist(
"Newmark Parameters",
true);
540 std::string schemeName =
541 newmarkPL.
get<std::string>(
"Scheme Name",
"Average Acceleration");
542 stepper->setSchemeName(schemeName);
543 if (schemeName ==
"User Defined") {
544 stepper->setBeta(newmarkPL.get<
double>(
"Beta", 0.25));
545 stepper->setGamma(newmarkPL.get<
double>(
"Gamma", 0.5));
549 stepper->setSchemeName(
"Average Acceleration");
553 if (model != Teuchos::null) {
554 stepper->setModel(model);
555 stepper->initialize();
562 #endif // Tempus_StepperNewmarkImplicitDForm_impl_hpp
virtual RCP< const VectorSpaceBase< Scalar > > space() const =0
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver) override
Set solver.
T & get(const std::string &name, T def_value)
Teuchos::RCP< StepperNewmarkImplicitDForm< Scalar > > createStepperNewmarkImplicitDForm(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar >> &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
#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.
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.
StepperState is a simple class to hold state information about the stepper.
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)
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)
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
virtual void setUseFSAL(bool a)
void setStepperType(std::string s)
Set the stepper type.
void setICConsistency(std::string s)