9 #ifndef Tempus_StepperNewmarkExplicitAForm_impl_hpp
10 #define Tempus_StepperNewmarkExplicitAForm_impl_hpp
12 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
13 #include "Thyra_VectorStdOps.hpp"
20 template<
class Scalar>
23 const Thyra::VectorBase<Scalar>& v,
24 const Thyra::VectorBase<Scalar>& a,
25 const Scalar dt)
const
28 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0, v, dt*(1.0-gamma_), a);
31 template<
class Scalar>
34 const Thyra::VectorBase<Scalar>& d,
35 const Thyra::VectorBase<Scalar>& v,
36 const Thyra::VectorBase<Scalar>& a,
37 const Scalar dt)
const
39 Teuchos::RCP<const Thyra::VectorBase<Scalar> > tmp =
40 Thyra::createMember<Scalar>(dPred.space());
42 Scalar aConst = dt*dt/2.0;
43 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), dt, v, aConst, a);
45 Thyra::Vp_V(Teuchos::ptrFromRef(dPred), d, 1.0);
48 template<
class Scalar>
51 const Thyra::VectorBase<Scalar>& vPred,
52 const Thyra::VectorBase<Scalar>& a,
53 const Scalar dt)
const
56 Thyra::V_StVpStV(Teuchos::ptrFromRef(v), 1.0, vPred, dt*gamma_, a);
60 template<
class Scalar>
63 this->setParameterList(Teuchos::null);
68 template<
class Scalar>
70 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
71 Teuchos::RCP<Teuchos::ParameterList> pList)
73 this->setParameterList(pList);
75 if (appModel == Teuchos::null) {
79 this->setModel(appModel);
85 template<
class Scalar>
88 TEUCHOS_TEST_FOR_EXCEPTION(
89 this->appModel_ == Teuchos::null, std::logic_error,
90 "Error - Need to set the model, setModel(), before calling "
91 "StepperNewmarkExplicitAForm::initialize()\n");
93 this->setParameterList(this->stepperPL_);
96 template<
class Scalar>
104 TEUCHOS_TEST_FOR_EXCEPTION(numStates < 1, std::logic_error,
105 "Error - setInitialConditions() needs at least one SolutionState\n"
106 " to set the initial condition. Number of States = " << numStates);
109 RCP<Teuchos::FancyOStream> out = this->getOStream();
110 Teuchos::OSTab ostab(out,1,
111 "StepperNewmarkExplicitAForm::setInitialConditions()");
112 *out <<
"Warning -- SolutionHistory has more than one state!\n"
113 <<
"Setting the initial conditions on the currentState.\n"<<std::endl;
116 RCP<SolutionState<Scalar> > initialState =
solutionHistory->getCurrentState();
117 RCP<Thyra::VectorBase<Scalar> > x = initialState->getX();
118 RCP<Thyra::VectorBase<Scalar> > xDot = initialState->getXDot();
122 TEUCHOS_TEST_FOR_EXCEPTION(
123 !((initialState->getX() != Teuchos::null &&
124 initialState->getXDot() != Teuchos::null) ||
125 (this->inArgs_.get_x() != Teuchos::null &&
126 this->inArgs_.get_x_dot() != Teuchos::null)), std::logic_error,
127 "Error - We need to set the initial conditions for x and xDot from\n"
128 " either initialState or appModel_->getNominalValues::InArgs\n"
129 " (but not from a mixture of the two).\n");
131 this->inArgs_ = this->appModel_->getNominalValues();
132 using Teuchos::rcp_const_cast;
134 if ( initialState->getX() == Teuchos::null ||
135 initialState->getXDot() == Teuchos::null ) {
136 TEUCHOS_TEST_FOR_EXCEPTION( (this->inArgs_.get_x() == Teuchos::null) ||
137 (this->inArgs_.get_x_dot() == Teuchos::null), std::logic_error,
138 "Error - setInitialConditions() needs the ICs from the SolutionHistory\n"
139 " or getNominalValues()!\n");
140 x =rcp_const_cast<Thyra::VectorBase<Scalar> >(this->inArgs_.get_x());
141 initialState->setX(x);
142 xDot =rcp_const_cast<Thyra::VectorBase<Scalar> >(this->inArgs_.get_x_dot());
143 initialState->setXDot(xDot);
145 this->inArgs_.set_x(x);
146 this->inArgs_.set_x_dot(xDot);
150 if (initialState->getXDotDot() == Teuchos::null)
151 initialState->setXDotDot(initialState->getX()->clone_v());
154 std::string icConsistency = this->getICConsistency();
155 if (icConsistency ==
"None") {
156 if (initialState->getXDotDot() == Teuchos::null) {
157 RCP<Teuchos::FancyOStream> out = this->getOStream();
158 Teuchos::OSTab ostab(out,1,
"StepperForwardEuler::setInitialConditions()");
159 *out <<
"Warning -- Requested IC consistency of 'None' but\n"
160 <<
" initialState does not have an xDotDot.\n"
161 <<
" Setting a 'Consistent' xDotDot!\n" << std::endl;
162 this->evaluateExplicitODE(initialState->getXDotDot(), x, xDot,
163 initialState->getTime());
165 initialState->setIsSynced(
true);
168 else if (icConsistency ==
"Zero")
169 Thyra::assign(initialState->getXDotDot().ptr(), Scalar(0.0));
170 else if (icConsistency ==
"App") {
171 auto xDotDot = Teuchos::rcp_const_cast<Thyra::VectorBase<Scalar> >(
172 this->inArgs_.get_x_dot_dot());
173 TEUCHOS_TEST_FOR_EXCEPTION(xDotDot == Teuchos::null, std::logic_error,
174 "Error - setInitialConditions() requested 'App' for IC consistency,\n"
175 " but 'App' returned a null pointer for xDotDot!\n");
176 Thyra::assign(initialState->getXDotDot().ptr(), *xDotDot);
178 else if (icConsistency ==
"Consistent") {
180 this->evaluateExplicitODE(initialState->getXDotDot(), x, xDot,
181 initialState->getTime());
185 initialState->setIsSynced(
true);
188 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
189 "Error - setInitialConditions() invalid IC consistency, "
190 << icConsistency <<
".\n");
194 if (this->getICConsistencyCheck()) {
195 auto xDotDot = initialState->getXDotDot();
196 auto f = initialState->getX()->clone_v();
197 this->evaluateExplicitODE(f, x, xDot, initialState->getTime());
198 Thyra::Vp_StV(f.ptr(), Scalar(-1.0), *(xDotDot));
199 Scalar reldiff = Thyra::norm(*f);
200 Scalar normxDotDot = Thyra::norm(*xDotDot);
202 Scalar eps = Scalar(100.0)*std::abs(Teuchos::ScalarTraits<Scalar>::eps());
203 if (normxDotDot > eps*reldiff) reldiff /= normxDotDot;
206 RCP<Teuchos::FancyOStream> out = this->getOStream();
207 Teuchos::OSTab ostab(out,1,
"StepperForwardEuler::setInitialConditions()");
208 *out <<
"Warning -- Failed consistency check but continuing!\n"
209 <<
" ||xDotDot-f(x,t)||/||xDotDot|| > eps" << std::endl
210 <<
" ||xDotDot-f(x,t)|| = " << Thyra::norm(*f)
212 <<
" ||xDotDot|| = " << Thyra::norm(*xDotDot)
214 <<
" ||xDotDot-f(x,t)||/||xDotDot|| = " << reldiff << std::endl
215 <<
" eps = " << eps << std::endl;
221 template<
class Scalar>
227 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperNewmarkExplicitAForm::takeStep()");
231 "Error - StepperNewmarkExplicitAForm<Scalar>::takeStep(...)\n"
232 "Need at least two SolutionStates for NewmarkExplicitAForm.\n"
234 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
235 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
237 RCP<SolutionState<Scalar> > currentState=
solutionHistory->getCurrentState();
238 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
241 RCP<const Thyra::VectorBase<Scalar> > d_old = currentState->getX();
242 RCP<const Thyra::VectorBase<Scalar> > v_old = currentState->getXDot();
243 RCP< Thyra::VectorBase<Scalar> > a_old = currentState->getXDotDot();
246 const Scalar dt = workingState->getTimeStep();
247 const Scalar time_old = currentState->getTime();
249 if ( !(this->getUseFSAL()) ) {
251 this->evaluateExplicitODE(a_old, d_old, v_old, time_old);
255 currentState->setIsSynced(
true);
259 RCP<Thyra::VectorBase<Scalar> > d_new = workingState->getX();
260 RCP<Thyra::VectorBase<Scalar> > v_new = workingState->getXDot();
261 RCP<Thyra::VectorBase<Scalar> > a_new = workingState->getXDotDot();
264 predictDisplacement(*d_new, *d_old, *v_old, *a_old, dt);
265 predictVelocity(*v_new, *v_old, *a_old, dt);
268 this->evaluateExplicitODE(a_new, d_new, v_new, time_old);
271 correctVelocity(*v_new, *v_new, *a_new, dt);
273 if ( this->getUseFSAL() ) {
275 const Scalar time_new = workingState->getTime();
276 this->evaluateExplicitODE(a_new, d_new, v_new, time_new);
280 workingState->setIsSynced(
true);
282 assign(a_new.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
283 workingState->setIsSynced(
false);
287 workingState->setOrder(this->getOrder());
299 template<
class Scalar>
303 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
309 template<
class Scalar>
312 std::string name =
"Newmark Explicit a-Form";
317 template<
class Scalar>
319 Teuchos::FancyOStream &out,
320 const Teuchos::EVerbosityLevel )
const
322 out << description() <<
"::describe:" << std::endl
323 <<
"appModel_ = " << this->appModel_->description() << std::endl;
327 template <
class Scalar>
329 const Teuchos::RCP<Teuchos::ParameterList> & pList)
331 if (pList == Teuchos::null) {
333 if (this->stepperPL_ == Teuchos::null)
334 this->stepperPL_ = this->getDefaultParameters();
336 this->stepperPL_ = pList;
338 this->stepperPL_->validateParametersAndSetDefaults(*this->getValidParameters());
340 std::string stepperType =
341 this->stepperPL_->template get<std::string>(
"Stepper Type");
342 TEUCHOS_TEST_FOR_EXCEPTION( stepperType !=
"Newmark Explicit a-Form",
344 "Error - Stepper Type is not 'Newmark Explicit a-Form'!\n"
345 <<
" Stepper Type = "
346 << this->stepperPL_->template get<std::string>(
"Stepper Type") <<
"\n");
348 gamma_ = this->stepperPL_->sublist(
"Newmark Explicit Parameters")
349 .template get<double>(
"Gamma");
350 TEUCHOS_TEST_FOR_EXCEPTION( (gamma_ > 1.0) || (gamma_ < 0.0),
352 "Error in 'Newmark Explicit a-Form' stepper: invalid value of Gamma = "
353 << gamma_ <<
". Please select 0 <= Gamma <= 1. \n");
358 template<
class Scalar>
359 Teuchos::RCP<const Teuchos::ParameterList>
362 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
363 pl->setName(
"Default Stepper - " + this->description());
364 pl->set<std::string>(
"Stepper Type",
"Newmark Explicit a-Form",
365 "'Stepper Type' must be 'Newmark Explicit a-Form'.");
366 this->getValidParametersBasic(pl);
367 pl->set<
bool>(
"Use FSAL",
true);
368 pl->set<std::string>(
"Initial Condition Consistency",
"Consistent");
369 pl->sublist(
"Newmark Explicit Parameters",
false,
"");
370 pl->sublist(
"Newmark Explicit Parameters",
false,
"").set(
"Gamma",
371 0.5,
"Newmark Explicit parameter");
377 template<
class Scalar>
378 Teuchos::RCP<Teuchos::ParameterList>
382 using Teuchos::ParameterList;
383 using Teuchos::rcp_const_cast;
385 RCP<ParameterList> pl =
386 rcp_const_cast<ParameterList>(this->getValidParameters());
392 template <
class Scalar>
393 Teuchos::RCP<Teuchos::ParameterList>
396 return(this->stepperPL_);
400 template <
class Scalar>
401 Teuchos::RCP<Teuchos::ParameterList>
404 Teuchos::RCP<Teuchos::ParameterList> temp_plist = this->stepperPL_;
405 this->stepperPL_ = Teuchos::null;
411 #endif // Tempus_StepperNewmarkExplicitAForm_impl_hpp
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...