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>
103 TEUCHOS_TEST_FOR_EXCEPTION(
104 this->appModel_ == Teuchos::null, std::logic_error,
105 "Error - Need to set the model, setModel(), before calling "
106 "StepperNewmarkExplicitAForm::initialize()\n");
109 template<
class Scalar>
117 TEUCHOS_TEST_FOR_EXCEPTION(numStates < 1, std::logic_error,
118 "Error - setInitialConditions() needs at least one SolutionState\n"
119 " to set the initial condition. Number of States = " << numStates);
122 RCP<Teuchos::FancyOStream> out = this->getOStream();
123 Teuchos::OSTab ostab(out,1,
124 "StepperNewmarkExplicitAForm::setInitialConditions()");
125 *out <<
"Warning -- SolutionHistory has more than one state!\n"
126 <<
"Setting the initial conditions on the currentState.\n"<<std::endl;
129 RCP<SolutionState<Scalar> > initialState =
solutionHistory->getCurrentState();
130 RCP<Thyra::VectorBase<Scalar> > x = initialState->getX();
131 RCP<Thyra::VectorBase<Scalar> > xDot = initialState->getXDot();
135 TEUCHOS_TEST_FOR_EXCEPTION(
136 !((initialState->getX() != Teuchos::null &&
137 initialState->getXDot() != Teuchos::null) ||
138 (this->inArgs_.get_x() != Teuchos::null &&
139 this->inArgs_.get_x_dot() != Teuchos::null)), std::logic_error,
140 "Error - We need to set the initial conditions for x and xDot from\n"
141 " either initialState or appModel_->getNominalValues::InArgs\n"
142 " (but not from a mixture of the two).\n");
144 this->inArgs_ = this->appModel_->getNominalValues();
145 using Teuchos::rcp_const_cast;
147 if ( initialState->getX() == Teuchos::null ||
148 initialState->getXDot() == Teuchos::null ) {
149 TEUCHOS_TEST_FOR_EXCEPTION( (this->inArgs_.get_x() == Teuchos::null) ||
150 (this->inArgs_.get_x_dot() == Teuchos::null), std::logic_error,
151 "Error - setInitialConditions() needs the ICs from the SolutionHistory\n"
152 " or getNominalValues()!\n");
153 x =rcp_const_cast<Thyra::VectorBase<Scalar> >(this->inArgs_.get_x());
154 initialState->setX(x);
155 xDot =rcp_const_cast<Thyra::VectorBase<Scalar> >(this->inArgs_.get_x_dot());
156 initialState->setXDot(xDot);
158 this->inArgs_.set_x(x);
159 this->inArgs_.set_x_dot(xDot);
163 if (initialState->getXDotDot() == Teuchos::null)
164 initialState->setXDotDot(initialState->getX()->clone_v());
167 std::string icConsistency = this->getICConsistency();
168 if (icConsistency ==
"None") {
169 if (initialState->getXDotDot() == Teuchos::null) {
170 RCP<Teuchos::FancyOStream> out = this->getOStream();
171 Teuchos::OSTab ostab(out,1,
"StepperForwardEuler::setInitialConditions()");
172 *out <<
"Warning -- Requested IC consistency of 'None' but\n"
173 <<
" initialState does not have an xDotDot.\n"
174 <<
" Setting a 'Consistent' xDotDot!\n" << std::endl;
176 this->evaluateExplicitODE(initialState->getXDotDot(), x, xDot,
177 initialState->getTime(), p);
179 initialState->setIsSynced(
true);
182 else if (icConsistency ==
"Zero")
183 Thyra::assign(initialState->getXDotDot().ptr(), Scalar(0.0));
184 else if (icConsistency ==
"App") {
185 auto xDotDot = Teuchos::rcp_const_cast<Thyra::VectorBase<Scalar> >(
186 this->inArgs_.get_x_dot_dot());
187 TEUCHOS_TEST_FOR_EXCEPTION(xDotDot == Teuchos::null, std::logic_error,
188 "Error - setInitialConditions() requested 'App' for IC consistency,\n"
189 " but 'App' returned a null pointer for xDotDot!\n");
190 Thyra::assign(initialState->getXDotDot().ptr(), *xDotDot);
192 else if (icConsistency ==
"Consistent") {
195 this->evaluateExplicitODE(initialState->getXDotDot(), x, xDot,
196 initialState->getTime(), p);
200 initialState->setIsSynced(
true);
203 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
204 "Error - setInitialConditions() invalid IC consistency, "
205 << icConsistency <<
".\n");
209 if (this->getICConsistencyCheck()) {
210 auto xDotDot = initialState->getXDotDot();
211 auto f = initialState->getX()->clone_v();
213 this->evaluateExplicitODE(f, x, xDot, initialState->getTime(), p);
214 Thyra::Vp_StV(f.ptr(), Scalar(-1.0), *(xDotDot));
215 Scalar reldiff = Thyra::norm(*f);
216 Scalar normxDotDot = Thyra::norm(*xDotDot);
218 Scalar eps = Scalar(100.0)*std::abs(Teuchos::ScalarTraits<Scalar>::eps());
219 if (normxDotDot > eps*reldiff) reldiff /= normxDotDot;
222 RCP<Teuchos::FancyOStream> out = this->getOStream();
223 Teuchos::OSTab ostab(out,1,
"StepperForwardEuler::setInitialConditions()");
224 *out <<
"Warning -- Failed consistency check but continuing!\n"
225 <<
" ||xDotDot-f(x,t)||/||xDotDot|| > eps" << std::endl
226 <<
" ||xDotDot-f(x,t)|| = " << Thyra::norm(*f)
228 <<
" ||xDotDot|| = " << Thyra::norm(*xDotDot)
230 <<
" ||xDotDot-f(x,t)||/||xDotDot|| = " << reldiff << std::endl
231 <<
" eps = " << eps << std::endl;
237 template<
class Scalar>
243 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperNewmarkExplicitAForm::takeStep()");
247 "Error - StepperNewmarkExplicitAForm<Scalar>::takeStep(...)\n"
248 "Need at least two SolutionStates for NewmarkExplicitAForm.\n"
250 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
251 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
253 RCP<SolutionState<Scalar> > currentState=
solutionHistory->getCurrentState();
254 RCP<SolutionState<Scalar> > workingState=
solutionHistory->getWorkingState();
257 RCP<const Thyra::VectorBase<Scalar> > d_old = currentState->getX();
258 RCP<const Thyra::VectorBase<Scalar> > v_old = currentState->getXDot();
259 RCP< Thyra::VectorBase<Scalar> > a_old = currentState->getXDotDot();
262 const Scalar dt = workingState->getTimeStep();
263 const Scalar time_old = currentState->getTime();
266 if ( !(this->getUseFSAL()) ) {
268 this->evaluateExplicitODE(a_old, d_old, v_old, time_old, p);
272 currentState->setIsSynced(
true);
276 RCP<Thyra::VectorBase<Scalar> > d_new = workingState->getX();
277 RCP<Thyra::VectorBase<Scalar> > v_new = workingState->getXDot();
278 RCP<Thyra::VectorBase<Scalar> > a_new = workingState->getXDotDot();
281 predictDisplacement(*d_new, *d_old, *v_old, *a_old, dt);
282 predictVelocity(*v_new, *v_old, *a_old, dt);
285 this->evaluateExplicitODE(a_new, d_new, v_new, time_old, p);
288 correctVelocity(*v_new, *v_new, *a_new, dt);
290 if ( this->getUseFSAL() ) {
292 const Scalar time_new = workingState->getTime();
293 this->evaluateExplicitODE(a_new, d_new, v_new, time_new, p);
297 workingState->setIsSynced(
true);
299 assign(a_new.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
300 workingState->setIsSynced(
false);
304 workingState->setOrder(this->getOrder());
316 template<
class Scalar>
320 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
326 template<
class Scalar>
328 Teuchos::FancyOStream &out,
329 const Teuchos::EVerbosityLevel )
const
331 out << this->getStepperType() <<
"::describe:" << std::endl
332 <<
"appModel_ = " << this->appModel_->description() << std::endl;
336 template<
class Scalar>
337 Teuchos::RCP<const Teuchos::ParameterList>
340 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
342 pl->set<
bool>(
"Use FSAL", this->getUseFSALDefault());
343 pl->set<std::string>(
"Initial Condition Consistency",
344 this->getICConsistencyDefault());
345 pl->sublist(
"Newmark Explicit Parameters",
false,
"");
346 pl->sublist(
"Newmark Explicit Parameters",
false,
"").set(
"Gamma",
347 0.5,
"Newmark Explicit parameter");
353 #endif // Tempus_StepperNewmarkExplicitAForm_impl_hpp
virtual bool getICConsistencyCheckDefault() const
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.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
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)