9 #ifndef Tempus_StepperNewmarkImplicitAForm_impl_hpp
10 #define Tempus_StepperNewmarkImplicitAForm_impl_hpp
12 #include "Tempus_config.hpp"
14 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
15 #include "NOX_Thyra.H"
23 template<
class Scalar>
class StepperFactory;
25 template<
class Scalar>
28 const Thyra::VectorBase<Scalar>& v,
29 const Thyra::VectorBase<Scalar>& a,
30 const Scalar dt)
const
32 #ifdef VERBOSE_DEBUG_OUTPUT
33 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
36 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0, v, dt*(1.0-gamma_), a);
39 template<
class Scalar>
42 const Thyra::VectorBase<Scalar>& d,
43 const Thyra::VectorBase<Scalar>& v,
44 const Thyra::VectorBase<Scalar>& a,
45 const Scalar dt)
const
47 #ifdef VERBOSE_DEBUG_OUTPUT
48 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
50 Teuchos::RCP<const Thyra::VectorBase<Scalar> > tmp =
51 Thyra::createMember<Scalar>(dPred.space());
53 Scalar aConst = dt*dt/2.0*(1.0-2.0*beta_);
54 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), dt, v, aConst, a);
56 Thyra::Vp_V(Teuchos::ptrFromRef(dPred), d, 1.0);
59 template<
class Scalar>
62 const Thyra::VectorBase<Scalar>& vPred,
63 const Thyra::VectorBase<Scalar>& a,
64 const Scalar dt)
const
66 #ifdef VERBOSE_DEBUG_OUTPUT
67 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
70 Thyra::V_StVpStV(Teuchos::ptrFromRef(v), 1.0, vPred, dt*gamma_, a);
73 template<
class Scalar>
76 const Thyra::VectorBase<Scalar>& dPred,
77 const Thyra::VectorBase<Scalar>& a,
78 const Scalar dt)
const
80 #ifdef VERBOSE_DEBUG_OUTPUT
81 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
84 Thyra::V_StVpStV(Teuchos::ptrFromRef(d), 1.0, dPred, beta_*dt*dt, a);
88 template<
class Scalar>
90 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
91 Teuchos::RCP<Teuchos::ParameterList> pList) :
92 out_(
Teuchos::VerboseObjectBase::getDefaultOStream())
94 #ifdef VERBOSE_DEBUG_OUTPUT
95 *
out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
98 using Teuchos::ParameterList;
107 template<
class Scalar>
109 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel)
111 #ifdef VERBOSE_DEBUG_OUTPUT
112 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
114 this->validSecondOrderODE_DAE(appModel);
115 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
117 "Newmark Implicit a-Form"));
118 this->wrapperModel_ = wrapperModel;
119 inArgs_ = this->wrapperModel_->getNominalValues();
120 outArgs_ = this->wrapperModel_->createOutArgs();
124 template<
class Scalar>
127 TEUCHOS_TEST_FOR_EXCEPTION( this->wrapperModel_ == Teuchos::null,
129 "Error - Need to set the model, setModel(), before calling "
130 "StepperNewmarkImplicitAForm::initialize()\n");
132 #ifdef VERBOSE_DEBUG_OUTPUT
133 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
135 this->setParameterList(this->stepperPL_);
140 template<
class Scalar>
144 #ifdef VERBOSE_DEBUG_OUTPUT
145 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
149 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperNewmarkImplicitAForm::takeStep()");
153 "Error - StepperNewmarkImplicitAForm<Scalar>::takeStep(...)\n"
154 "Need at least two SolutionStates for NewmarkImplicitAForm.\n"
156 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
157 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
159 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
160 RCP<SolutionState<Scalar> > currentState=
solutionHistory->getCurrentState();
162 Teuchos::RCP<WrapperModelEvaluatorSecondOrder<Scalar> > wrapperModel =
164 this->wrapperModel_);
167 RCP<const Thyra::VectorBase<Scalar> > d_old = currentState->getX();
168 RCP<const Thyra::VectorBase<Scalar> > v_old = currentState->getXDot();
170 RCP<Thyra::VectorBase<Scalar> > a_old = currentState->getXDotDot();
175 *out_ <<
"IKT d_old = " << Thyra::max(*d_old) <<
"\n";
176 *out_ <<
"IKT v_old = " << Thyra::max(*v_old) <<
"\n";
181 RCP<Thyra::VectorBase<Scalar> > d_new = workingState->getX();
182 RCP<Thyra::VectorBase<Scalar> > v_new = workingState->getXDot();
183 RCP<Thyra::VectorBase<Scalar> > a_new = workingState->getXDotDot();
186 const Scalar time = currentState->getTime();
187 const Scalar dt = workingState->getTimeStep();
194 RCP<Thyra::VectorBase<Scalar> > d_init = Thyra::createMember(d_old->space());
195 RCP<Thyra::VectorBase<Scalar> > v_init = Thyra::createMember(v_old->space());
196 RCP<Thyra::VectorBase<Scalar> > a_init = Thyra::createMember(a_old->space());
197 Thyra::copy(*d_old, d_init.ptr());
198 Thyra::copy(*v_old, v_init.ptr());
199 if (initial_guess_ != Teuchos::null) {
201 bool is_compatible = (a_init->space())->isCompatible(*initial_guess_->space());
202 TEUCHOS_TEST_FOR_EXCEPTION(
203 is_compatible !=
true, std::logic_error,
204 "Error in Tempus::NemwarkImplicitAForm takeStep(): user-provided initial guess'!\n"
205 <<
"for Newton is not compatible with solution vector!\n");
206 Thyra::copy(*initial_guess_, a_init.ptr());
209 Thyra::put_scalar(0.0, a_init.ptr());
211 wrapperModel->initializeNewmark(v_init,d_init,0.0,time,beta_,gamma_);
212 const Thyra::SolveStatus<Scalar> sStatus =
213 this->solveImplicitODE(a_init);
215 if (sStatus.solveStatus == Thyra::SOLVE_STATUS_CONVERGED )
219 Thyra::copy(*a_init, a_old.ptr());
223 *out_ <<
"IKT a_old = " << Thyra::max(*a_old) <<
"\n";
228 RCP<Thyra::VectorBase<Scalar> > d_pred =Thyra::createMember(d_old->space());
229 RCP<Thyra::VectorBase<Scalar> > v_pred =Thyra::createMember(v_old->space());
232 predictDisplacement(*d_pred, *d_old, *v_old, *a_old, dt);
233 predictVelocity(*v_pred, *v_old, *a_old, dt);
236 wrapperModel->initializeNewmark(v_pred,d_pred,dt,t,beta_,gamma_);
239 const Thyra::SolveStatus<Scalar> sStatus = this->solveImplicitODE(a_old);
241 if (sStatus.solveStatus == Thyra::SOLVE_STATUS_CONVERGED )
248 Thyra::copy(*a_old, a_new.ptr());
251 correctVelocity(*v_new, *v_pred, *a_new, dt);
252 correctDisplacement(*d_new, *d_pred, *a_new, dt);
254 workingState->setOrder(this->getOrder());
267 template<
class Scalar>
268 Teuchos::RCP<Tempus::StepperState<Scalar> >
272 #ifdef VERBOSE_DEBUG_OUTPUT
273 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
275 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
281 template<
class Scalar>
284 #ifdef VERBOSE_DEBUG_OUTPUT
285 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
287 std::string name =
"Newmark Implicit a-Form";
292 template<
class Scalar>
294 Teuchos::FancyOStream &out,
295 const Teuchos::EVerbosityLevel verbLevel)
const
297 #ifdef VERBOSE_DEBUG_OUTPUT
298 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
300 out << description() <<
"::describe:" << std::endl
301 <<
"wrapperModel = " << this->wrapperModel_->description() << std::endl;
305 template <
class Scalar>
307 Teuchos::RCP<Teuchos::ParameterList>
const& pList)
309 #ifdef VERBOSE_DEBUG_OUTPUT
310 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
312 if (pList == Teuchos::null) {
314 if (this->stepperPL_ == Teuchos::null) this->stepperPL_ = this->getDefaultParameters();
316 this->stepperPL_ = pList;
323 Teuchos::RCP<Teuchos::ParameterList> stepperPL = this->stepperPL_;
324 std::string stepperType = stepperPL->get<std::string>(
"Stepper Type");
325 TEUCHOS_TEST_FOR_EXCEPTION( stepperType !=
"Newmark Implicit a-Form",
327 "Error - Stepper Type is not 'Newmark Implicit a-Form'!\n"
328 <<
" Stepper Type = "<< stepperPL->get<std::string>(
"Stepper Type")
332 Teuchos::VerboseObjectBase::getDefaultOStream();
333 if (this->stepperPL_->isSublist(
"Newmark Parameters")) {
334 Teuchos::ParameterList &newmarkPL =
335 this->stepperPL_->sublist(
"Newmark Parameters",
true);
336 std::string scheme_name = newmarkPL.get(
"Scheme Name",
"Not Specified");
337 if (scheme_name ==
"Not Specified") {
338 beta_ = newmarkPL.get(
"Beta", 0.25);
339 gamma_ = newmarkPL.get(
"Gamma", 0.5);
340 TEUCHOS_TEST_FOR_EXCEPTION( (beta_ > 1.0) || (beta_ < 0.0),
342 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Beta = "
343 << beta_ <<
". Please select Beta >= 0 and <= 1. \n");
344 TEUCHOS_TEST_FOR_EXCEPTION( (gamma_ > 1.0) || (gamma_ < 0.0),
346 "\nError in 'Newmark Implicit a-Form' stepper: invalid value of Gamma ="
347 <<gamma_ <<
". Please select Gamma >= 0 and <= 1. \n");
348 *out_ <<
"\nSetting Beta = " << beta_ <<
" and Gamma = " << gamma_
349 <<
" from Newmark Parameters in input file.\n";
352 *out_ <<
"\nScheme Name = " << scheme_name <<
". Using values \n"
353 <<
"of Beta and Gamma for this scheme (ignoring values of "
354 <<
"Beta and Gamma \n"
355 <<
"in input file, if provided).\n";
356 if (scheme_name ==
"Average Acceleration") {
357 beta_ = 0.25; gamma_ = 0.5;
359 else if (scheme_name ==
"Linear Acceleration") {
360 beta_ = 0.25; gamma_ = 1.0/6.0;
362 else if (scheme_name ==
"Central Difference") {
363 beta_ = 0.0; gamma_ = 0.5;
366 TEUCHOS_TEST_FOR_EXCEPTION(
true,
368 "\nError in Tempus::StepperNewmarkImplicitAForm! "
369 <<
"Invalid Scheme Name = " << scheme_name <<
". \n"
370 <<
"Valid Scheme Names are: 'Average Acceleration', "
371 <<
"'Linear Acceleration', \n"
372 <<
"'Central Difference' and 'Not Specified'.\n");
374 *out_ <<
"===> Beta = " << beta_ <<
", Gamma = " << gamma_ <<
"\n";
377 *out_ <<
"\nWARNING: Running (implicit implementation of) Newmark "
378 <<
"Implicit a-Form Stepper with Beta = 0.0, which \n"
379 <<
"specifies an explicit scheme. Mass lumping is not possible, "
380 <<
"so this will be slow! To run explicit \n"
381 <<
"implementation of Newmark Implicit a-Form Stepper, please "
382 <<
"re-run with 'Stepper Type' = 'Newmark Explicit a-Form'.\n"
383 <<
"This stepper allows for mass lumping when called through "
384 <<
"Piro::TempusSolver.\n";
388 *out_ <<
"\nNo Newmark Parameters sublist found in input file; using "
389 <<
"default values of Beta = "
390 << beta_ <<
" and Gamma = " << gamma_ <<
".\n";
395 template<
class Scalar>
396 Teuchos::RCP<const Teuchos::ParameterList>
399 #ifdef VERBOSE_DEBUG_OUTPUT
400 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
402 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
403 pl->setName(
"Default Stepper - " + this->description());
404 pl->set(
"Stepper Type", this->description());
405 pl->set(
"Zero Initial Guess",
false);
406 pl->set(
"Solver Name",
"",
407 "Name of ParameterList containing the solver specifications.");
411 template<
class Scalar>
412 Teuchos::RCP<Teuchos::ParameterList>
415 #ifdef VERBOSE_DEBUG_OUTPUT
416 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
419 using Teuchos::ParameterList;
421 RCP<ParameterList> pl = Teuchos::parameterList();
422 pl->setName(
"Default Stepper - " + this->description());
423 pl->set<std::string>(
"Stepper Type", this->description());
424 pl->set<
bool> (
"Zero Initial Guess",
false);
425 pl->set<std::string>(
"Solver Name",
"Default Solver");
427 RCP<ParameterList> solverPL = this->defaultSolverParameters();
428 pl->set(
"Default Solver", *solverPL);
434 template <
class Scalar>
435 Teuchos::RCP<Teuchos::ParameterList>
438 #ifdef VERBOSE_DEBUG_OUTPUT
439 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
441 return(this->stepperPL_);
445 template <
class Scalar>
446 Teuchos::RCP<Teuchos::ParameterList>
449 #ifdef VERBOSE_DEBUG_OUTPUT
450 *out_ <<
"DEBUG: " << __PRETTY_FUNCTION__ <<
"\n";
452 Teuchos::RCP<Teuchos::ParameterList> temp_plist = this->stepperPL_;
453 this->stepperPL_ = Teuchos::null;
459 #endif // Tempus_StepperNewmarkImplicitAForm_impl_hpp