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>
96 if (schemeName_ !=
"User Defined") {
97 *out_ <<
"\nWARNING: schemeName != 'User Defined' (=" <<schemeName_<<
").\n"
98 <<
" Not setting beta, and leaving as beta = " << beta_ <<
"!\n";
105 *out_ <<
"\nWARNING: Running (implicit implementation of) Newmark "
106 <<
"Implicit a-Form Stepper with Beta = 0.0, which \n"
107 <<
"specifies an explicit scheme. Mass lumping is not possible, "
108 <<
"so this will be slow! To run explicit \n"
109 <<
"implementation of Newmark Implicit a-Form Stepper, please "
110 <<
"re-run with 'Stepper Type' = 'Newmark Explicit a-Form'.\n"
111 <<
"This stepper allows for mass lumping when called through "
112 <<
"Piro::TempusSolver.\n";
115 TEUCHOS_TEST_FOR_EXCEPTION( (beta_ > 1.0) || (beta_ < 0.0),
117 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Beta = "
118 << beta_ <<
". Please select Beta >= 0 and <= 1. \n");
122 template<
class Scalar>
125 if (schemeName_ !=
"User Defined") {
126 *out_ <<
"\nWARNING: schemeName != 'User Defined' (=" <<schemeName_<<
").\n"
127 <<
" Not setting gamma, and leaving as gamma = " << gamma_ <<
"!\n";
133 TEUCHOS_TEST_FOR_EXCEPTION( (gamma_ > 1.0) || (gamma_ < 0.0),
135 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Gamma ="
136 <<gamma_ <<
". Please select Gamma >= 0 and <= 1. \n");
140 template<
class Scalar>
142 std::string schemeName)
144 schemeName_ = schemeName;
146 if (schemeName_ ==
"Average Acceleration") {
147 beta_= 0.25; gamma_ = 0.5;
149 else if (schemeName_ ==
"Linear Acceleration") {
150 beta_= 0.25; gamma_ = 1.0/6.0;
152 else if (schemeName_ ==
"Central Difference") {
153 beta_= 0.0; gamma_ = 0.5;
155 else if (schemeName_ ==
"User Defined") {
156 beta_= 0.25; gamma_ = 0.5;
159 TEUCHOS_TEST_FOR_EXCEPTION(
true,
161 "\nError in Tempus::StepperNewmarkImplicitDForm! "
162 <<
"Invalid Scheme Name = " << schemeName_ <<
". \n"
163 <<
"Valid Scheme Names are: 'Average Acceleration', "
164 <<
"'Linear Acceleration', \n"
165 <<
"'Central Difference' and 'User Defined'.\n");
170 template <
class Scalar>
172 : out_(Teuchos::VerboseObjectBase::getDefaultOStream()) {
173 #ifdef VERBOSE_DEBUG_OUTPUT
174 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
187 template <
class Scalar>
189 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar>>& appModel,
191 const Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
193 std::string ICConsistency,
194 bool ICConsistencyCheck,
195 bool zeroInitialGuess,
196 std::string schemeName,
199 : out_(Teuchos::VerboseObjectBase::getDefaultOStream())
212 if (appModel != Teuchos::null) {
221 template <
class Scalar>
224 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar>>& appModel) {
225 #ifdef VERBOSE_DEBUG_OUTPUT
226 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
229 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
231 appModel,
"Newmark Implicit d-Form"));
232 this->wrapperModel_ = wrapperModel;
233 inArgs_ = this->wrapperModel_->getNominalValues();
234 outArgs_ = this->wrapperModel_->createOutArgs();
237 template <
class Scalar>
241 TEUCHOS_TEST_FOR_EXCEPTION( this->wrapperModel_ == Teuchos::null,
243 "Error - Need to set the model, setModel(), before calling "
244 "StepperNewmarkImplicitDForm::initialize()\n");
246 #ifdef VERBOSE_DEBUG_OUTPUT
247 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
251 template <
class Scalar>
255 #ifdef VERBOSE_DEBUG_OUTPUT
256 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
260 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperNewmarkImplicitDForm::takeStep()");
264 "Error - StepperNewmarkImplicitDForm<Scalar>::takeStep(...)\n"
265 "Need at least two SolutionStates for NewmarkImplicitDForm.\n"
267 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
268 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
270 RCP<SolutionState<Scalar>> workingState =
solutionHistory->getWorkingState();
271 RCP<SolutionState<Scalar>> currentState =
solutionHistory->getCurrentState();
273 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
275 this->wrapperModel_);
278 RCP<const Thyra::VectorBase<Scalar>> d_old = currentState->getX();
279 RCP<Thyra::VectorBase<Scalar>> v_old = currentState->getXDot();
280 RCP<Thyra::VectorBase<Scalar>> a_old = currentState->getXDotDot();
284 RCP<Thyra::VectorBase<Scalar>> d_new = workingState->getX();
285 RCP<Thyra::VectorBase<Scalar>> v_new = workingState->getXDot();
286 RCP<Thyra::VectorBase<Scalar>> a_new = workingState->getXDotDot();
289 const Scalar time = currentState->getTime();
290 const Scalar dt = workingState->getTimeStep();
292 Scalar t = time + dt;
296 Teuchos::Range1D range;
298 *out_ <<
"\n*** d_old ***\n";
299 RTOpPack::ConstSubVectorView<Scalar> dov;
300 d_old->acquireDetachedView(range, &dov);
301 auto doa = dov.values();
302 for (
auto i = 0; i < doa.size(); ++i) *out_ << doa[i] <<
" ";
303 *out_ <<
"\n*** d_old ***\n";
305 *out_ <<
"\n*** v_old ***\n";
306 RTOpPack::ConstSubVectorView<Scalar> vov;
307 v_old->acquireDetachedView(range, &vov);
308 auto voa = vov.values();
309 for (
auto i = 0; i < voa.size(); ++i) *out_ << voa[i] <<
" ";
310 *out_ <<
"\n*** v_old ***\n";
312 *out_ <<
"\n*** a_old ***\n";
313 RTOpPack::ConstSubVectorView<Scalar> aov;
314 a_old->acquireDetachedView(range, &aov);
315 auto aoa = aov.values();
316 for (
auto i = 0; i < aoa.size(); ++i) *out_ << aoa[i] <<
" ";
317 *out_ <<
"\n*** a_old ***\n";
321 RCP<Thyra::VectorBase<Scalar>> d_pred = Thyra::createMember(d_old->space());
322 RCP<Thyra::VectorBase<Scalar>> v_pred = Thyra::createMember(v_old->space());
325 predictDisplacement(*d_pred, *d_old, *v_old, *a_old, dt);
326 predictVelocity(*v_pred, *v_old, *a_old, dt);
329 *out_ <<
"\n*** d_pred ***\n";
330 RTOpPack::ConstSubVectorView<Scalar> dpv;
331 d_pred->acquireDetachedView(range, &dpv);
332 auto dpa = dpv.values();
333 for (
auto i = 0; i < dpa.size(); ++i) *out_ << dpa[i] <<
" ";
334 *out_ <<
"\n*** d_pred ***\n";
336 *out_ <<
"\n*** v_pred ***\n";
337 RTOpPack::ConstSubVectorView<Scalar> vpv;
338 v_pred->acquireDetachedView(range, &vpv);
339 auto vpa = vpv.values();
340 for (
auto i = 0; i < vpa.size(); ++i) *out_ << vpa[i] <<
" ";
341 *out_ <<
"\n*** v_pred ***\n";
345 wrapperModel->initializeNewmark(v_pred, d_pred, dt, t, beta_, gamma_);
348 RCP<Thyra::VectorBase<Scalar>> initial_guess = Thyra::createMember(d_pred->space());
349 if ((time ==
solutionHistory->minTime()) && (this->initial_guess_ != Teuchos::null)) {
352 bool is_compatible = (initial_guess->space())->isCompatible(*this->initial_guess_->space());
353 TEUCHOS_TEST_FOR_EXCEPTION(
354 is_compatible !=
true, std::logic_error,
355 "Error in Tempus::NemwarkImplicitDForm takeStep(): user-provided initial guess'!\n"
356 <<
"for Newton is not compatible with solution vector!\n");
357 Thyra::copy(*this->initial_guess_, initial_guess.ptr());
361 Thyra::copy(*d_pred, initial_guess.ptr());
365 const Thyra::SolveStatus<Scalar> sStatus =
366 this->solveImplicitODE(initial_guess);
368 workingState->setSolutionStatus(sStatus);
372 Thyra::copy(*initial_guess, d_new.ptr());
375 correctAcceleration(*a_new, *d_pred, *d_new, dt);
376 correctVelocity(*v_new, *v_pred, *a_new, dt);
379 *out_ <<
"\n*** d_new ***\n";
380 RTOpPack::ConstSubVectorView<Scalar> dnv;
381 d_new->acquireDetachedView(range, &dnv);
382 auto dna = dnv.values();
383 for (
auto i = 0; i < dna.size(); ++i) *out_ << dna[i] <<
" ";
384 *out_ <<
"\n*** d_new ***\n";
386 *out_ <<
"\n*** v_new ***\n";
387 RTOpPack::ConstSubVectorView<Scalar> vnv;
388 v_new->acquireDetachedView(range, &vnv);
389 auto vna = vnv.values();
390 for (
auto i = 0; i < vna.size(); ++i) *out_ << vna[i] <<
" ";
391 *out_ <<
"\n*** v_new ***\n";
393 *out_ <<
"\n*** a_new ***\n";
394 RTOpPack::ConstSubVectorView<Scalar> anv;
395 a_new->acquireDetachedView(range, &anv);
396 auto ana = anv.values();
397 for (
auto i = 0; i < ana.size(); ++i) *out_ << ana[i] <<
" ";
398 *out_ <<
"\n*** a_new ***\n";
401 workingState->setOrder(this->getOrder());
412 template <
class Scalar>
413 Teuchos::RCP<Tempus::StepperState<Scalar>>
415 #ifdef VERBOSE_DEBUG_OUTPUT
416 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
418 Teuchos::RCP<Tempus::StepperState<Scalar>> stepperState =
423 template <
class Scalar>
426 Teuchos::FancyOStream& out,
427 const Teuchos::EVerbosityLevel )
const {
428 #ifdef VERBOSE_DEBUG_OUTPUT
429 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
431 out << this->getStepperType() <<
"::describe:" << std::endl
432 <<
"wrapperModel_ = " << this->wrapperModel_->description() << std::endl;
435 template <
class Scalar>
436 Teuchos::RCP<const Teuchos::ParameterList>
438 #ifdef VERBOSE_DEBUG_OUTPUT
439 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
441 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
443 pl->set<std::string>(
"Scheme Name",
"Average Acceleration");
444 pl->set<
double> (
"Beta" , 0.25);
445 pl->set<
double> (
"Gamma", 0.5 );
446 pl->set<std::string>(
"Solver Name",
"Default Solver");
447 pl->set<
bool> (
"Zero Initial Guess",
false);
449 pl->set(
"Default Solver", *solverPL);
455 #endif // Tempus_StepperNewmarkImplicitDForm_impl_hpp
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver=Teuchos::null)
Set solver.
virtual bool getICConsistencyCheckDefault() const
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
virtual std::string getICConsistencyDefault() 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.
void setICConsistencyCheck(bool c)
StepperObserver class for Stepper class.
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
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]...
virtual bool getUseFSALDefault() const
void getValidParametersBasic(Teuchos::RCP< Teuchos::ParameterList > pl, std::string stepperType)
Provide basic parameters to Steppers.
void setStepperType(std::string s)
void setICConsistency(std::string s)