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");
120 this->isInitialized_ =
false;
124 template<
class Scalar>
127 if (schemeName_ !=
"User Defined") {
128 *out_ <<
"\nWARNING: schemeName != 'User Defined' (=" <<schemeName_<<
").\n"
129 <<
" Not setting gamma, and leaving as gamma = " << gamma_ <<
"!\n";
135 TEUCHOS_TEST_FOR_EXCEPTION( (gamma_ > 1.0) || (gamma_ < 0.0),
137 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Gamma ="
138 <<gamma_ <<
". Please select Gamma >= 0 and <= 1. \n");
140 this->isInitialized_ =
false;
144 template<
class Scalar>
146 std::string schemeName)
148 schemeName_ = schemeName;
150 if (schemeName_ ==
"Average Acceleration") {
151 beta_= 0.25; gamma_ = 0.5;
153 else if (schemeName_ ==
"Linear Acceleration") {
154 beta_= 0.25; gamma_ = 1.0/6.0;
156 else if (schemeName_ ==
"Central Difference") {
157 beta_= 0.0; gamma_ = 0.5;
159 else if (schemeName_ ==
"User Defined") {
160 beta_= 0.25; gamma_ = 0.5;
163 TEUCHOS_TEST_FOR_EXCEPTION(
true,
165 "\nError in Tempus::StepperNewmarkImplicitDForm! "
166 <<
"Invalid Scheme Name = " << schemeName_ <<
". \n"
167 <<
"Valid Scheme Names are: 'Average Acceleration', "
168 <<
"'Linear Acceleration', \n"
169 <<
"'Central Difference' and 'User Defined'.\n");
172 this->isInitialized_ =
false;
176 template <
class Scalar>
178 : out_(Teuchos::VerboseObjectBase::getDefaultOStream()) {
179 #ifdef VERBOSE_DEBUG_OUTPUT
180 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
194 template <
class Scalar>
196 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar>>& appModel,
198 const Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
200 std::string ICConsistency,
201 bool ICConsistencyCheck,
202 bool zeroInitialGuess,
203 std::string schemeName,
206 : out_(Teuchos::VerboseObjectBase::getDefaultOStream())
220 if (appModel != Teuchos::null) {
227 template <
class Scalar>
230 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar>>& appModel) {
231 #ifdef VERBOSE_DEBUG_OUTPUT
232 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
235 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
237 appModel,
"Newmark Implicit d-Form"));
238 this->wrapperModel_ = wrapperModel;
240 this->isInitialized_ =
false;
244 template <
class Scalar>
248 #ifdef VERBOSE_DEBUG_OUTPUT
249 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
251 this->checkInitialized();
255 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperNewmarkImplicitDForm::takeStep()");
257 TEUCHOS_TEST_FOR_EXCEPTION(solutionHistory->getNumStates() < 2,
259 "Error - StepperNewmarkImplicitDForm<Scalar>::takeStep(...)\n"
260 "Need at least two SolutionStates for NewmarkImplicitDForm.\n"
261 " Number of States = " << solutionHistory->getNumStates() <<
"\n"
262 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
263 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
265 RCP<SolutionState<Scalar>> workingState =solutionHistory->getWorkingState();
266 RCP<SolutionState<Scalar>> currentState =solutionHistory->getCurrentState();
268 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
270 this->wrapperModel_);
273 RCP<const Thyra::VectorBase<Scalar>> d_old = currentState->getX();
274 RCP<Thyra::VectorBase<Scalar>> v_old = currentState->getXDot();
275 RCP<Thyra::VectorBase<Scalar>> a_old = currentState->getXDotDot();
279 RCP<Thyra::VectorBase<Scalar>> d_new = workingState->getX();
280 RCP<Thyra::VectorBase<Scalar>> v_new = workingState->getXDot();
281 RCP<Thyra::VectorBase<Scalar>> a_new = workingState->getXDotDot();
284 const Scalar time = currentState->getTime();
285 const Scalar dt = workingState->getTimeStep();
287 Scalar t = time + dt;
291 Teuchos::Range1D range;
293 *out_ <<
"\n*** d_old ***\n";
294 RTOpPack::ConstSubVectorView<Scalar> dov;
295 d_old->acquireDetachedView(range, &dov);
296 auto doa = dov.values();
297 for (
auto i = 0; i < doa.size(); ++i) *out_ << doa[i] <<
" ";
298 *out_ <<
"\n*** d_old ***\n";
300 *out_ <<
"\n*** v_old ***\n";
301 RTOpPack::ConstSubVectorView<Scalar> vov;
302 v_old->acquireDetachedView(range, &vov);
303 auto voa = vov.values();
304 for (
auto i = 0; i < voa.size(); ++i) *out_ << voa[i] <<
" ";
305 *out_ <<
"\n*** v_old ***\n";
307 *out_ <<
"\n*** a_old ***\n";
308 RTOpPack::ConstSubVectorView<Scalar> aov;
309 a_old->acquireDetachedView(range, &aov);
310 auto aoa = aov.values();
311 for (
auto i = 0; i < aoa.size(); ++i) *out_ << aoa[i] <<
" ";
312 *out_ <<
"\n*** a_old ***\n";
316 RCP<Thyra::VectorBase<Scalar>> d_pred = Thyra::createMember(d_old->space());
317 RCP<Thyra::VectorBase<Scalar>> v_pred = Thyra::createMember(v_old->space());
320 predictDisplacement(*d_pred, *d_old, *v_old, *a_old, dt);
321 predictVelocity(*v_pred, *v_old, *a_old, dt);
324 *out_ <<
"\n*** d_pred ***\n";
325 RTOpPack::ConstSubVectorView<Scalar> dpv;
326 d_pred->acquireDetachedView(range, &dpv);
327 auto dpa = dpv.values();
328 for (
auto i = 0; i < dpa.size(); ++i) *out_ << dpa[i] <<
" ";
329 *out_ <<
"\n*** d_pred ***\n";
331 *out_ <<
"\n*** v_pred ***\n";
332 RTOpPack::ConstSubVectorView<Scalar> vpv;
333 v_pred->acquireDetachedView(range, &vpv);
334 auto vpa = vpv.values();
335 for (
auto i = 0; i < vpa.size(); ++i) *out_ << vpa[i] <<
" ";
336 *out_ <<
"\n*** v_pred ***\n";
340 wrapperModel->initializeNewmark(v_pred, d_pred, dt, t, beta_, gamma_);
343 RCP<Thyra::VectorBase<Scalar>> initial_guess = Thyra::createMember(d_pred->space());
344 if ((time == solutionHistory->minTime()) && (this->initialGuess_ != Teuchos::null)) {
347 bool is_compatible = (initial_guess->space())->isCompatible(*this->initialGuess_->space());
348 TEUCHOS_TEST_FOR_EXCEPTION(
349 is_compatible !=
true, std::logic_error,
350 "Error in Tempus::NemwarkImplicitDForm takeStep(): user-provided initial guess'!\n"
351 <<
"for Newton is not compatible with solution vector!\n");
352 Thyra::copy(*this->initialGuess_, initial_guess.ptr());
356 Thyra::copy(*d_pred, initial_guess.ptr());
360 const Thyra::SolveStatus<Scalar> sStatus =
361 this->solveImplicitODE(initial_guess);
363 workingState->setSolutionStatus(sStatus);
367 Thyra::copy(*initial_guess, d_new.ptr());
370 correctAcceleration(*a_new, *d_pred, *d_new, dt);
371 correctVelocity(*v_new, *v_pred, *a_new, dt);
374 *out_ <<
"\n*** d_new ***\n";
375 RTOpPack::ConstSubVectorView<Scalar> dnv;
376 d_new->acquireDetachedView(range, &dnv);
377 auto dna = dnv.values();
378 for (
auto i = 0; i < dna.size(); ++i) *out_ << dna[i] <<
" ";
379 *out_ <<
"\n*** d_new ***\n";
381 *out_ <<
"\n*** v_new ***\n";
382 RTOpPack::ConstSubVectorView<Scalar> vnv;
383 v_new->acquireDetachedView(range, &vnv);
384 auto vna = vnv.values();
385 for (
auto i = 0; i < vna.size(); ++i) *out_ << vna[i] <<
" ";
386 *out_ <<
"\n*** v_new ***\n";
388 *out_ <<
"\n*** a_new ***\n";
389 RTOpPack::ConstSubVectorView<Scalar> anv;
390 a_new->acquireDetachedView(range, &anv);
391 auto ana = anv.values();
392 for (
auto i = 0; i < ana.size(); ++i) *out_ << ana[i] <<
" ";
393 *out_ <<
"\n*** a_new ***\n";
396 workingState->setOrder(this->getOrder());
397 workingState->computeNorms(currentState);
408 template <
class Scalar>
409 Teuchos::RCP<Tempus::StepperState<Scalar>>
411 #ifdef VERBOSE_DEBUG_OUTPUT
412 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
414 Teuchos::RCP<Tempus::StepperState<Scalar>> stepperState =
419 template <
class Scalar>
422 Teuchos::FancyOStream& out,
423 const Teuchos::EVerbosityLevel verbLevel)
const {
424 #ifdef VERBOSE_DEBUG_OUTPUT
425 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
432 out <<
"--- StepperNewmarkImplicitDForm ---\n";
433 out <<
" schemeName_ = " << schemeName_ << std::endl;
434 out <<
" beta_ = " << beta_ << std::endl;
435 out <<
" gamma_ = " << gamma_ << std::endl;
436 out <<
"-----------------------------------" << std::endl;
440 template<
class Scalar>
443 bool isValidSetup =
true;
448 if (this->wrapperModel_->getAppModel() == Teuchos::null) {
449 isValidSetup =
false;
450 out <<
"The application ModelEvaluator is not set!\n";
453 if (this->wrapperModel_ == Teuchos::null) {
454 isValidSetup =
false;
455 out <<
"The wrapper ModelEvaluator is not set!\n";
458 if (this->solver_ == Teuchos::null) {
459 isValidSetup =
false;
460 out <<
"The solver is not set!\n";
467 template <
class Scalar>
468 Teuchos::RCP<const Teuchos::ParameterList>
470 #ifdef VERBOSE_DEBUG_OUTPUT
471 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
473 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
475 pl->set<std::string>(
"Scheme Name",
"Average Acceleration");
476 pl->set<
double> (
"Beta" , 0.25);
477 pl->set<
double> (
"Gamma", 0.5 );
478 pl->set<std::string>(
"Solver Name",
"Default Solver");
479 pl->set<
bool> (
"Zero Initial Guess",
false);
481 pl->set(
"Default Solver", *solverPL);
487 #endif // Tempus_StepperNewmarkImplicitDForm_impl_hpp
virtual bool getICConsistencyCheckDefault() const
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
virtual std::string getICConsistencyDefault() const
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.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void setDefaultSolver()
void setICConsistencyCheck(bool c)
StepperObserver class for Stepper class.
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
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) 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)