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>
62 : gammaDefault_(Scalar(0.5)), gamma_(Scalar(0.5))
73 template<
class Scalar>
75 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& appModel,
78 std::string ICConsistency,
79 bool ICConsistencyCheck,
81 : gammaDefault_(Scalar(0.5)), gamma_(Scalar(0.5))
92 if (appModel != Teuchos::null) {
100 template<
class Scalar>
106 int numStates = solutionHistory->getNumStates();
108 TEUCHOS_TEST_FOR_EXCEPTION(numStates < 1, std::logic_error,
109 "Error - setInitialConditions() needs at least one SolutionState\n"
110 " to set the initial condition. Number of States = " << numStates);
113 RCP<Teuchos::FancyOStream> out = this->getOStream();
114 Teuchos::OSTab ostab(out,1,
115 "StepperNewmarkExplicitAForm::setInitialConditions()");
116 *out <<
"Warning -- SolutionHistory has more than one state!\n"
117 <<
"Setting the initial conditions on the currentState.\n"<<std::endl;
120 RCP<SolutionState<Scalar> > initialState = solutionHistory->getCurrentState();
121 RCP<Thyra::VectorBase<Scalar> > x = initialState->getX();
122 RCP<Thyra::VectorBase<Scalar> > xDot = initialState->getXDot();
126 TEUCHOS_TEST_FOR_EXCEPTION(
127 !((initialState->getX() != Teuchos::null &&
128 initialState->getXDot() != Teuchos::null) ||
129 (this->inArgs_.get_x() != Teuchos::null &&
130 this->inArgs_.get_x_dot() != Teuchos::null)), std::logic_error,
131 "Error - We need to set the initial conditions for x and xDot from\n"
132 " either initialState or appModel_->getNominalValues::InArgs\n"
133 " (but not from a mixture of the two).\n");
135 this->inArgs_ = this->appModel_->getNominalValues();
136 using Teuchos::rcp_const_cast;
138 if ( initialState->getX() == Teuchos::null ||
139 initialState->getXDot() == Teuchos::null ) {
140 TEUCHOS_TEST_FOR_EXCEPTION( (this->inArgs_.get_x() == Teuchos::null) ||
141 (this->inArgs_.get_x_dot() == Teuchos::null), std::logic_error,
142 "Error - setInitialConditions() needs the ICs from the SolutionHistory\n"
143 " or getNominalValues()!\n");
144 x =rcp_const_cast<Thyra::VectorBase<Scalar> >(this->inArgs_.get_x());
145 initialState->setX(x);
146 xDot =rcp_const_cast<Thyra::VectorBase<Scalar> >(this->inArgs_.get_x_dot());
147 initialState->setXDot(xDot);
149 this->inArgs_.set_x(x);
150 this->inArgs_.set_x_dot(xDot);
154 if (initialState->getXDotDot() == Teuchos::null)
155 initialState->setXDotDot(initialState->getX()->clone_v());
158 std::string icConsistency = this->getICConsistency();
159 if (icConsistency ==
"None") {
160 if (initialState->getXDotDot() == Teuchos::null) {
161 RCP<Teuchos::FancyOStream> out = this->getOStream();
162 Teuchos::OSTab ostab(out,1,
"StepperForwardEuler::setInitialConditions()");
163 *out <<
"Warning -- Requested IC consistency of 'None' but\n"
164 <<
" initialState does not have an xDotDot.\n"
165 <<
" Setting a 'Consistent' xDotDot!\n" << std::endl;
167 this->evaluateExplicitODE(initialState->getXDotDot(), x, xDot,
168 initialState->getTime(), p);
170 initialState->setIsSynced(
true);
173 else if (icConsistency ==
"Zero")
174 Thyra::assign(initialState->getXDotDot().ptr(), Scalar(0.0));
175 else if (icConsistency ==
"App") {
176 auto xDotDot = Teuchos::rcp_const_cast<Thyra::VectorBase<Scalar> >(
177 this->inArgs_.get_x_dot_dot());
178 TEUCHOS_TEST_FOR_EXCEPTION(xDotDot == Teuchos::null, std::logic_error,
179 "Error - setInitialConditions() requested 'App' for IC consistency,\n"
180 " but 'App' returned a null pointer for xDotDot!\n");
181 Thyra::assign(initialState->getXDotDot().ptr(), *xDotDot);
183 else if (icConsistency ==
"Consistent") {
186 this->evaluateExplicitODE(initialState->getXDotDot(), x, xDot,
187 initialState->getTime(), p);
191 initialState->setIsSynced(
true);
194 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
195 "Error - setInitialConditions() invalid IC consistency, "
196 << icConsistency <<
".\n");
200 if (this->getICConsistencyCheck()) {
201 auto xDotDot = initialState->getXDotDot();
202 auto f = initialState->getX()->clone_v();
204 this->evaluateExplicitODE(f, x, xDot, initialState->getTime(), p);
205 Thyra::Vp_StV(f.ptr(), Scalar(-1.0), *(xDotDot));
206 Scalar reldiff = Thyra::norm(*f);
207 Scalar normxDotDot = Thyra::norm(*xDotDot);
209 Scalar eps = Scalar(100.0)*std::abs(Teuchos::ScalarTraits<Scalar>::eps());
210 if (normxDotDot > eps*reldiff) reldiff /= normxDotDot;
213 RCP<Teuchos::FancyOStream> out = this->getOStream();
214 Teuchos::OSTab ostab(out,1,
"StepperForwardEuler::setInitialConditions()");
215 *out <<
"Warning -- Failed consistency check but continuing!\n"
216 <<
" ||xDotDot-f(x,t)||/||xDotDot|| > eps" << std::endl
217 <<
" ||xDotDot-f(x,t)|| = " << Thyra::norm(*f)
219 <<
" ||xDotDot|| = " << Thyra::norm(*xDotDot)
221 <<
" ||xDotDot-f(x,t)||/||xDotDot|| = " << reldiff << std::endl
222 <<
" eps = " << eps << std::endl;
228 template<
class Scalar>
232 this->checkInitialized();
236 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperNewmarkExplicitAForm::takeStep()");
238 TEUCHOS_TEST_FOR_EXCEPTION(solutionHistory->getNumStates() < 2,
240 "Error - StepperNewmarkExplicitAForm<Scalar>::takeStep(...)\n"
241 "Need at least two SolutionStates for NewmarkExplicitAForm.\n"
242 " Number of States = " << solutionHistory->getNumStates() <<
"\n"
243 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
244 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
246 RCP<SolutionState<Scalar> > currentState=solutionHistory->getCurrentState();
247 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
250 RCP<const Thyra::VectorBase<Scalar> > d_old = currentState->getX();
251 RCP<const Thyra::VectorBase<Scalar> > v_old = currentState->getXDot();
252 RCP< Thyra::VectorBase<Scalar> > a_old = currentState->getXDotDot();
255 const Scalar dt = workingState->getTimeStep();
256 const Scalar time_old = currentState->getTime();
259 if ( !(this->getUseFSAL()) ) {
261 this->evaluateExplicitODE(a_old, d_old, v_old, time_old, p);
265 currentState->setIsSynced(
true);
269 RCP<Thyra::VectorBase<Scalar> > d_new = workingState->getX();
270 RCP<Thyra::VectorBase<Scalar> > v_new = workingState->getXDot();
271 RCP<Thyra::VectorBase<Scalar> > a_new = workingState->getXDotDot();
274 predictDisplacement(*d_new, *d_old, *v_old, *a_old, dt);
275 predictVelocity(*v_new, *v_old, *a_old, dt);
278 this->evaluateExplicitODE(a_new, d_new, v_new, time_old, p);
281 correctVelocity(*v_new, *v_new, *a_new, dt);
283 if ( this->getUseFSAL() ) {
285 const Scalar time_new = workingState->getTime();
286 this->evaluateExplicitODE(a_new, d_new, v_new, time_new, p);
290 workingState->setIsSynced(
true);
292 assign(a_new.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
293 workingState->setIsSynced(
false);
297 workingState->setOrder(this->getOrder());
298 workingState->computeNorms(currentState);
310 template<
class Scalar>
314 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
320 template<
class Scalar>
322 Teuchos::FancyOStream &out,
323 const Teuchos::EVerbosityLevel verbLevel)
const
329 out <<
"--- StepperNewmarkExplicitAForm ---\n";
330 out <<
" gamma_ = " << gamma_ << std::endl;
331 out <<
"-----------------------------------" << std::endl;
335 template<
class Scalar>
338 bool isValidSetup =
true;
347 template<
class Scalar>
348 Teuchos::RCP<const Teuchos::ParameterList>
351 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
353 pl->set<
bool>(
"Use FSAL", this->getUseFSALDefault());
354 pl->set<std::string>(
"Initial Condition Consistency",
355 this->getICConsistencyDefault());
356 pl->sublist(
"Newmark Explicit Parameters",
false,
"");
357 pl->sublist(
"Newmark Explicit Parameters",
false,
"").set(
"Gamma",
358 0.5,
"Newmark Explicit parameter");
364 #endif // Tempus_StepperNewmarkExplicitAForm_impl_hpp
virtual bool getICConsistencyCheckDefault() const
virtual void initialize()
Initialize after construction and changing input parameters.
Thyra Base interface for time steppers.
StepperState is a simple class to hold state information about the stepper.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void setICConsistencyCheck(bool c)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
StepperObserver class for Stepper class.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
Thyra Base interface for implicit time steppers.
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)