9 #ifndef Tempus_StepperNewmarkImplicitDForm_impl_hpp
10 #define Tempus_StepperNewmarkImplicitDForm_impl_hpp
12 #include "NOX_Thyra.H"
14 #include "Tempus_config.hpp"
15 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
23 template <
class Scalar>
26 template <
class Scalar>
29 Thyra::VectorBase<Scalar>& vPred,
const Thyra::VectorBase<Scalar>& v,
30 const Thyra::VectorBase<Scalar>& a,
const Scalar dt)
const {
31 #ifdef VERBOSE_DEBUG_OUTPUT
32 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
35 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0, v, dt * (1.0 - gamma_), a);
38 template <
class Scalar>
41 Thyra::VectorBase<Scalar>& dPred,
const Thyra::VectorBase<Scalar>& d,
42 const Thyra::VectorBase<Scalar>& v,
const Thyra::VectorBase<Scalar>& a,
43 const Scalar dt)
const {
44 #ifdef VERBOSE_DEBUG_OUTPUT
45 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
47 Teuchos::RCP<const Thyra::VectorBase<Scalar>> tmp =
48 Thyra::createMember<Scalar>(dPred.space());
50 Scalar aConst = dt * dt / 2.0 * (1.0 - 2.0 * beta_);
51 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), dt, v, aConst, a);
53 Thyra::Vp_V(Teuchos::ptrFromRef(dPred), d, 1.0);
56 template <
class Scalar>
59 Thyra::VectorBase<Scalar>& v,
const Thyra::VectorBase<Scalar>& vPred,
60 const Thyra::VectorBase<Scalar>& a,
const Scalar dt)
const {
61 #ifdef VERBOSE_DEBUG_OUTPUT
62 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
65 Thyra::V_StVpStV(Teuchos::ptrFromRef(v), 1.0, vPred, dt * gamma_, a);
68 template <
class Scalar>
71 Thyra::VectorBase<Scalar>& d,
const Thyra::VectorBase<Scalar>& dPred,
72 const Thyra::VectorBase<Scalar>& a,
const Scalar dt)
const {
73 #ifdef VERBOSE_DEBUG_OUTPUT
74 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
77 Thyra::V_StVpStV(Teuchos::ptrFromRef(d), 1.0, dPred, beta_ * dt * dt, a);
80 template <
class Scalar>
83 Thyra::VectorBase<Scalar>& a,
const Thyra::VectorBase<Scalar>& dPred,
84 const Thyra::VectorBase<Scalar>& d,
const Scalar dt)
const {
85 #ifdef VERBOSE_DEBUG_OUTPUT
86 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
89 Scalar
const c = 1.0 / beta_ / dt / dt;
90 Thyra::V_StVpStV(Teuchos::ptrFromRef(a), c, d, -c, dPred);
93 template <
class Scalar>
95 : out_(Teuchos::VerboseObjectBase::getDefaultOStream()) {
96 #ifdef VERBOSE_DEBUG_OUTPUT
97 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
104 template <
class Scalar>
106 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar>>& appModel,
107 Teuchos::RCP<Teuchos::ParameterList> pList)
108 : out_(Teuchos::VerboseObjectBase::getDefaultOStream()) {
109 #ifdef VERBOSE_DEBUG_OUTPUT
110 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
115 if (appModel == Teuchos::null) {
124 template <
class Scalar>
127 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar>>& appModel) {
128 #ifdef VERBOSE_DEBUG_OUTPUT
129 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
131 this->validSecondOrderODE_DAE(appModel);
132 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
134 appModel,
"Newmark Implicit d-Form"));
135 this->wrapperModel_ = wrapperModel;
136 inArgs_ = this->wrapperModel_->getNominalValues();
137 outArgs_ = this->wrapperModel_->createOutArgs();
140 template <
class Scalar>
144 TEUCHOS_TEST_FOR_EXCEPTION( this->wrapperModel_ == Teuchos::null,
146 "Error - Need to set the model, setModel(), before calling "
147 "StepperNewmarkImplicitDForm::initialize()\n");
149 #ifdef VERBOSE_DEBUG_OUTPUT
150 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
152 this->setParameterList(this->stepperPL_);
156 template <
class Scalar>
160 #ifdef VERBOSE_DEBUG_OUTPUT
161 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
165 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperNewmarkImplicitDForm::takeStep()");
169 "Error - StepperNewmarkImplicitDForm<Scalar>::takeStep(...)\n"
170 "Need at least two SolutionStates for NewmarkImplicitDForm.\n"
172 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
173 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
175 RCP<SolutionState<Scalar>> workingState =
solutionHistory->getWorkingState();
176 RCP<SolutionState<Scalar>> currentState =
solutionHistory->getCurrentState();
178 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
180 this->wrapperModel_);
183 RCP<const Thyra::VectorBase<Scalar>> d_old = currentState->getX();
184 RCP<Thyra::VectorBase<Scalar>> v_old = currentState->getXDot();
185 RCP<Thyra::VectorBase<Scalar>> a_old = currentState->getXDotDot();
189 RCP<Thyra::VectorBase<Scalar>> d_new = workingState->getX();
190 RCP<Thyra::VectorBase<Scalar>> v_new = workingState->getXDot();
191 RCP<Thyra::VectorBase<Scalar>> a_new = workingState->getXDotDot();
194 const Scalar time = currentState->getTime();
195 const Scalar dt = workingState->getTimeStep();
197 Scalar t = time + dt;
201 Teuchos::Range1D range;
203 *out_ <<
"\n*** d_old ***\n";
204 RTOpPack::ConstSubVectorView<Scalar> dov;
205 d_old->acquireDetachedView(range, &dov);
206 auto doa = dov.values();
207 for (
auto i = 0; i < doa.size(); ++i) *out_ << doa[i] <<
" ";
208 *out_ <<
"\n*** d_old ***\n";
210 *out_ <<
"\n*** v_old ***\n";
211 RTOpPack::ConstSubVectorView<Scalar> vov;
212 v_old->acquireDetachedView(range, &vov);
213 auto voa = vov.values();
214 for (
auto i = 0; i < voa.size(); ++i) *out_ << voa[i] <<
" ";
215 *out_ <<
"\n*** v_old ***\n";
217 *out_ <<
"\n*** a_old ***\n";
218 RTOpPack::ConstSubVectorView<Scalar> aov;
219 a_old->acquireDetachedView(range, &aov);
220 auto aoa = aov.values();
221 for (
auto i = 0; i < aoa.size(); ++i) *out_ << aoa[i] <<
" ";
222 *out_ <<
"\n*** a_old ***\n";
226 RCP<Thyra::VectorBase<Scalar>> d_pred = Thyra::createMember(d_old->space());
227 RCP<Thyra::VectorBase<Scalar>> v_pred = Thyra::createMember(v_old->space());
230 predictDisplacement(*d_pred, *d_old, *v_old, *a_old, dt);
231 predictVelocity(*v_pred, *v_old, *a_old, dt);
234 *out_ <<
"\n*** d_pred ***\n";
235 RTOpPack::ConstSubVectorView<Scalar> dpv;
236 d_pred->acquireDetachedView(range, &dpv);
237 auto dpa = dpv.values();
238 for (
auto i = 0; i < dpa.size(); ++i) *out_ << dpa[i] <<
" ";
239 *out_ <<
"\n*** d_pred ***\n";
241 *out_ <<
"\n*** v_pred ***\n";
242 RTOpPack::ConstSubVectorView<Scalar> vpv;
243 v_pred->acquireDetachedView(range, &vpv);
244 auto vpa = vpv.values();
245 for (
auto i = 0; i < vpa.size(); ++i) *out_ << vpa[i] <<
" ";
246 *out_ <<
"\n*** v_pred ***\n";
250 wrapperModel->initializeNewmark(v_pred, d_pred, dt, t, beta_, gamma_);
253 RCP<Thyra::VectorBase<Scalar>> initial_guess = Thyra::createMember(d_pred->space());
254 if ((time ==
solutionHistory->minTime()) && (this->initial_guess_ != Teuchos::null)) {
257 bool is_compatible = (initial_guess->space())->isCompatible(*this->initial_guess_->space());
258 TEUCHOS_TEST_FOR_EXCEPTION(
259 is_compatible !=
true, std::logic_error,
260 "Error in Tempus::NemwarkImplicitDForm takeStep(): user-provided initial guess'!\n"
261 <<
"for Newton is not compatible with solution vector!\n");
262 Thyra::copy(*this->initial_guess_, initial_guess.ptr());
266 Thyra::copy(*d_pred, initial_guess.ptr());
270 const Thyra::SolveStatus<Scalar> sStatus =
271 this->solveImplicitODE(initial_guess);
273 workingState->setSolutionStatus(sStatus);
277 Thyra::copy(*initial_guess, d_new.ptr());
280 correctAcceleration(*a_new, *d_pred, *d_new, dt);
281 correctVelocity(*v_new, *v_pred, *a_new, dt);
284 *out_ <<
"\n*** d_new ***\n";
285 RTOpPack::ConstSubVectorView<Scalar> dnv;
286 d_new->acquireDetachedView(range, &dnv);
287 auto dna = dnv.values();
288 for (
auto i = 0; i < dna.size(); ++i) *out_ << dna[i] <<
" ";
289 *out_ <<
"\n*** d_new ***\n";
291 *out_ <<
"\n*** v_new ***\n";
292 RTOpPack::ConstSubVectorView<Scalar> vnv;
293 v_new->acquireDetachedView(range, &vnv);
294 auto vna = vnv.values();
295 for (
auto i = 0; i < vna.size(); ++i) *out_ << vna[i] <<
" ";
296 *out_ <<
"\n*** v_new ***\n";
298 *out_ <<
"\n*** a_new ***\n";
299 RTOpPack::ConstSubVectorView<Scalar> anv;
300 a_new->acquireDetachedView(range, &anv);
301 auto ana = anv.values();
302 for (
auto i = 0; i < ana.size(); ++i) *out_ << ana[i] <<
" ";
303 *out_ <<
"\n*** a_new ***\n";
306 workingState->setOrder(this->getOrder());
317 template <
class Scalar>
318 Teuchos::RCP<Tempus::StepperState<Scalar>>
320 #ifdef VERBOSE_DEBUG_OUTPUT
321 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
323 Teuchos::RCP<Tempus::StepperState<Scalar>> stepperState =
328 template <
class Scalar>
331 #ifdef VERBOSE_DEBUG_OUTPUT
332 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
334 std::string name =
"Newmark Implicit d-Form";
338 template <
class Scalar>
341 Teuchos::FancyOStream& out,
342 const Teuchos::EVerbosityLevel )
const {
343 #ifdef VERBOSE_DEBUG_OUTPUT
344 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
346 out << description() <<
"::describe:" << std::endl
347 <<
"wrapperModel_ = " << this->wrapperModel_->
description() << std::endl;
350 template <
class Scalar>
353 Teuchos::RCP<Teuchos::ParameterList>
const& pList) {
354 #ifdef VERBOSE_DEBUG_OUTPUT
355 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
357 if (pList == Teuchos::null) {
359 if (this->stepperPL_ == Teuchos::null) this->stepperPL_ = this->getDefaultParameters();
361 this->stepperPL_ = pList;
369 Teuchos::RCP<Teuchos::ParameterList> stepperPL = this->stepperPL_;
370 std::string stepperType = stepperPL->get<std::string>(
"Stepper Type");
371 TEUCHOS_TEST_FOR_EXCEPTION(
372 stepperType !=
"Newmark Implicit d-Form", std::logic_error,
373 "Error - Stepper Type is not 'Newmark Implicit d-Form'!\n"
374 <<
" Stepper Type = " << stepperPL->get<std::string>(
"Stepper Type")
378 Teuchos::VerboseObjectBase::getDefaultOStream();
379 if (this->stepperPL_->isSublist(
"Newmark Parameters")) {
380 Teuchos::ParameterList& newmarkPL =
381 this->stepperPL_->sublist(
"Newmark Parameters",
true);
382 std::string scheme_name = newmarkPL.get(
"Scheme Name",
"Not Specified");
383 if (scheme_name ==
"Not Specified") {
384 beta_ = newmarkPL.get(
"Beta", 0.25);
385 gamma_ = newmarkPL.get(
"Gamma", 0.5);
386 TEUCHOS_TEST_FOR_EXCEPTION(
387 (beta_ > 1.0) || (beta_ < 0.0), std::logic_error,
388 "\nError in 'Newmark Implicit d-Form' stepper: invalid value of Beta = "
389 << beta_ <<
". Please select Beta >= 0 and <= 1. \n");
390 TEUCHOS_TEST_FOR_EXCEPTION(
391 (gamma_ > 1.0) || (gamma_ < 0.0), std::logic_error,
392 "\nError in 'Newmark Implicit d-Form' stepper: invalid value of Gamma = "
393 << gamma_ <<
". Please select Gamma >= 0 and <= 1. \n");
394 *out_ <<
"\nSetting Beta = " << beta_ <<
" and Gamma = " << gamma_
395 <<
" from Newmark Parameters in input file.\n";
397 *out_ <<
"\nScheme Name = " << scheme_name <<
". Using values \n"
398 <<
"of Beta and Gamma for this scheme (ignoring values of Beta and "
400 <<
"in input file, if provided).\n";
401 if (scheme_name ==
"Average Acceleration") {
404 }
else if (scheme_name ==
"Linear Acceleration") {
407 }
else if (scheme_name ==
"Central Difference") {
411 TEUCHOS_TEST_FOR_EXCEPTION(
412 true, std::logic_error,
413 "\nError in Tempus::StepperNewmarkImplicitDForm! Invalid Scheme Name = "
414 << scheme_name <<
". \n"
415 <<
"Valid Scheme Names are: 'Average Acceleration', 'Linear "
417 <<
"'Central Difference' and 'Not Specified'.\n");
419 *out_ <<
"===> Beta = " << beta_ <<
", Gamma = " << gamma_ <<
"\n";
423 TEUCHOS_TEST_FOR_EXCEPTION(
424 true, std::logic_error,
425 "Error - d-Form of Newmark scheme is not defined for explicit (Beta = 0).\n");
428 *out_ <<
"\nNo Newmark Parameters sublist found in input file; using "
429 "default values of Beta = "
430 << beta_ <<
" and Gamma = " << gamma_ <<
".\n";
434 template <
class Scalar>
435 Teuchos::RCP<const Teuchos::ParameterList>
437 #ifdef VERBOSE_DEBUG_OUTPUT
438 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
440 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
441 pl->setName(
"Default Stepper - " + this->description());
442 pl->set<std::string>(
"Stepper Type", this->description());
443 this->getValidParametersBasic(pl);
444 pl->set<
bool> (
"Zero Initial Guess",
false);
445 pl->set<std::string>(
"Solver Name",
"",
446 "Name of ParameterList containing the solver specifications.");
450 template <
class Scalar>
451 Teuchos::RCP<Teuchos::ParameterList>
453 #ifdef VERBOSE_DEBUG_OUTPUT
454 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
457 using Teuchos::ParameterList;
458 using Teuchos::rcp_const_cast;
460 RCP<ParameterList> pl =
461 rcp_const_cast<ParameterList>(this->getValidParameters());
463 pl->set<std::string>(
"Solver Name",
"Default Solver");
464 RCP<ParameterList> solverPL = this->defaultSolverParameters();
465 pl->set(
"Default Solver", *solverPL);
470 template <
class Scalar>
471 Teuchos::RCP<Teuchos::ParameterList>
473 #ifdef VERBOSE_DEBUG_OUTPUT
474 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
476 return (this->stepperPL_);
479 template <
class Scalar>
480 Teuchos::RCP<Teuchos::ParameterList>
482 #ifdef VERBOSE_DEBUG_OUTPUT
483 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
485 Teuchos::RCP<Teuchos::ParameterList> temp_plist = this->stepperPL_;
486 this->stepperPL_ = Teuchos::null;
491 #endif // Tempus_StepperNewmarkImplicitDForm_impl_hpp
virtual void modelWarning() const
A ModelEvaluator for residual evaluations given a state. This ModelEvaluator takes a state...
StepperState is a simple class to hold state information about the stepper.
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...