10 #ifndef Tempus_StepperNewmarkExplicitAForm_impl_hpp
11 #define Tempus_StepperNewmarkExplicitAForm_impl_hpp
13 #include "Thyra_VectorStdOps.hpp"
21 template <
class Scalar>
27 Thyra::V_StVpStV(Teuchos::ptrFromRef(vPred), 1.0, v, dt * (1.0 - gamma_), a);
30 template <
class Scalar>
34 const Scalar dt)
const
37 Thyra::createMember<Scalar>(dPred.
space());
39 Scalar aConst = dt * dt / 2.0;
40 Thyra::V_StVpStV(Teuchos::ptrFromRef(dPred), dt, v, aConst, a);
42 Thyra::Vp_V(Teuchos::ptrFromRef(dPred), d, 1.0);
45 template <
class Scalar>
51 Thyra::V_StVpStV(Teuchos::ptrFromRef(v), 1.0, vPred, dt * gamma_, a);
54 template <
class Scalar>
56 : gammaDefault_(Scalar(0.5)), gamma_(Scalar(0.5))
66 template <
class Scalar>
69 bool useFSAL, std::string ICConsistency,
bool ICConsistencyCheck,
73 : gammaDefault_(Scalar(0.5)), gamma_(Scalar(0.5))
84 if (appModel != Teuchos::null) {
90 template <
class Scalar>
96 int numStates = solutionHistory->getNumStates();
99 numStates < 1, std::logic_error,
100 "Error - setInitialConditions() needs at least one SolutionState\n"
101 " to set the initial condition. Number of States = "
105 RCP<Teuchos::FancyOStream> out = this->getOStream();
107 "StepperNewmarkExplicitAForm::setInitialConditions()");
108 *out <<
"Warning -- SolutionHistory has more than one state!\n"
109 <<
"Setting the initial conditions on the currentState.\n"
113 RCP<SolutionState<Scalar> > initialState = solutionHistory->getCurrentState();
114 RCP<Thyra::VectorBase<Scalar> > x = initialState->getX();
115 RCP<Thyra::VectorBase<Scalar> > xDot = initialState->getXDot();
120 !((initialState->getX() != Teuchos::null &&
121 initialState->getXDot() != Teuchos::null) ||
122 (this->inArgs_.get_x() != Teuchos::null &&
123 this->inArgs_.get_x_dot() != Teuchos::null)),
125 "Error - We need to set the initial conditions for x and xDot from\n"
126 " either initialState or appModel_->getNominalValues::InArgs\n"
127 " (but not from a mixture of the two).\n");
129 this->inArgs_ = this->appModel_->getNominalValues();
130 using Teuchos::rcp_const_cast;
132 if (initialState->getX() == Teuchos::null ||
133 initialState->getXDot() == Teuchos::null) {
135 (this->inArgs_.get_x_dot() == Teuchos::null),
137 "Error - setInitialConditions() needs the ICs "
138 "from the SolutionHistory\n"
139 " or getNominalValues()!\n");
141 initialState->setX(x);
144 initialState->setXDot(xDot);
147 this->inArgs_.set_x(x);
148 this->inArgs_.set_x_dot(xDot);
152 if (initialState->getXDotDot() == Teuchos::null)
153 initialState->setXDotDot(initialState->getX()->clone_v());
155 this->setStepperXDotDot(initialState->getXDotDot());
158 std::string icConsistency = this->getICConsistency();
159 if (icConsistency ==
"None") {
160 if (initialState->getXDotDot() == Teuchos::null) {
161 RCP<Teuchos::FancyOStream> out = this->getOStream();
163 "StepperForwardEuler::setInitialConditions()");
164 *out <<
"Warning -- Requested IC consistency of 'None' but\n"
165 <<
" initialState does not have an xDotDot.\n"
166 <<
" Setting a 'Consistent' xDotDot!\n"
169 this->evaluateExplicitODE(initialState->getXDotDot(), x, xDot,
170 initialState->getTime(), p);
172 initialState->setIsSynced(
true);
175 else if (icConsistency ==
"Zero")
176 Thyra::assign(initialState->getXDotDot().ptr(), Scalar(0.0));
177 else if (icConsistency ==
"App") {
179 this->inArgs_.get_x_dot_dot());
181 xDotDot == Teuchos::null, std::logic_error,
182 "Error - setInitialConditions() requested 'App' for IC consistency,\n"
183 " but 'App' returned a null pointer for xDotDot!\n");
184 Thyra::assign(initialState->getXDotDot().ptr(), *xDotDot);
186 else if (icConsistency ==
"Consistent") {
189 this->evaluateExplicitODE(initialState->getXDotDot(), x, xDot,
190 initialState->getTime(), p);
194 initialState->setIsSynced(
true);
198 true, std::logic_error,
199 "Error - setInitialConditions() invalid IC consistency, "
200 << icConsistency <<
".\n");
204 if (this->getICConsistencyCheck()) {
205 auto xDotDot = initialState->getXDotDot();
206 auto f = initialState->getX()->clone_v();
208 this->evaluateExplicitODE(f, x, xDot, initialState->getTime(), p);
209 Thyra::Vp_StV(f.ptr(), Scalar(-1.0), *(xDotDot));
210 Scalar reldiff = Thyra::norm(*f);
211 Scalar normxDotDot = Thyra::norm(*xDotDot);
214 if (normxDotDot > eps * reldiff) reldiff /= normxDotDot;
216 RCP<Teuchos::FancyOStream> out = this->getOStream();
218 "StepperNewmarkExplicitAForm::setInitialConditions()");
220 *out <<
"\n---------------------------------------------------\n"
221 <<
"Info -- Stepper = " << this->getStepperType() <<
"\n"
222 <<
" Initial condition PASSED consistency check!\n"
223 <<
" (||xDotDot-f(x,xDot,t)||/||x|| = " << reldiff <<
") > "
224 <<
"(eps = " << eps <<
")" << std::endl
225 <<
"---------------------------------------------------\n"
229 *out <<
"\n---------------------------------------------------\n"
230 <<
"Info -- Stepper = " << this->getStepperType() <<
"\n"
231 <<
"Initial condition FAILED consistency check but continuing!\n"
232 <<
" (||xDotDot-f(x,xDot,t)||/||x|| = " << reldiff <<
") > "
233 <<
"(eps = " << eps <<
")" << std::endl
234 <<
" ||xDotDot-f(x,xDot,t)|| = " << Thyra::norm(*f) << std::endl
235 <<
" ||x|| = " << Thyra::norm(*x) << std::endl
236 <<
"---------------------------------------------------\n"
242 template <
class Scalar>
246 this->checkInitialized();
250 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperNewmarkExplicitAForm::takeStep()");
253 solutionHistory->getNumStates() < 2, std::logic_error,
254 "Error - StepperNewmarkExplicitAForm<Scalar>::takeStep(...)\n"
255 <<
"Need at least two SolutionStates for NewmarkExplicitAForm.\n"
256 <<
" Number of States = " << solutionHistory->getNumStates()
257 <<
"\nTry setting in \"Solution History\" \"Storage Type\" = "
259 <<
" or \"Storage Type\" = \"Static\" and \"Storage Limit\" = "
262 auto thisStepper = Teuchos::rcpFromRef(*
this);
263 stepperNewmarkExpAppAction_->execute(
264 solutionHistory, thisStepper,
266 Scalar>::ACTION_LOCATION::BEGIN_STEP);
268 RCP<SolutionState<Scalar> > currentState =
269 solutionHistory->getCurrentState();
270 RCP<SolutionState<Scalar> > workingState =
271 solutionHistory->getWorkingState();
274 RCP<const Thyra::VectorBase<Scalar> > d_old = currentState->getX();
275 RCP<const Thyra::VectorBase<Scalar> > v_old = currentState->getXDot();
276 RCP<Thyra::VectorBase<Scalar> > a_old = currentState->getXDotDot();
279 const Scalar dt = workingState->getTimeStep();
280 const Scalar time_old = currentState->getTime();
283 if (!(this->getUseFSAL()) || workingState->getNConsecutiveFailures() != 0) {
285 this->evaluateExplicitODE(a_old, d_old, v_old, time_old, p);
289 currentState->setIsSynced(
true);
293 RCP<Thyra::VectorBase<Scalar> > d_new = workingState->getX();
294 RCP<Thyra::VectorBase<Scalar> > v_new = workingState->getXDot();
295 RCP<Thyra::VectorBase<Scalar> > a_new = workingState->getXDotDot();
298 predictDisplacement(*d_new, *d_old, *v_old, *a_old, dt);
299 predictVelocity(*v_new, *v_old, *a_old, dt);
301 stepperNewmarkExpAppAction_->execute(
302 solutionHistory, thisStepper,
304 Scalar>::ACTION_LOCATION::BEFORE_EXPLICIT_EVAL);
307 this->evaluateExplicitODE(a_new, d_new, v_new, time_old, p);
309 stepperNewmarkExpAppAction_->execute(
310 solutionHistory, thisStepper,
312 Scalar>::ACTION_LOCATION::AFTER_EXPLICIT_EVAL);
315 correctVelocity(*v_new, *v_new, *a_new, dt);
317 if (this->getUseFSAL()) {
319 const Scalar time_new = workingState->getTime();
320 this->evaluateExplicitODE(a_new, d_new, v_new, time_new, p);
324 workingState->setIsSynced(
true);
328 workingState->setIsSynced(
false);
332 workingState->setOrder(this->getOrder());
333 workingState->computeNorms(currentState);
335 stepperNewmarkExpAppAction_->execute(
336 solutionHistory, thisStepper,
338 Scalar>::ACTION_LOCATION::END_STEP);
349 template <
class Scalar>
358 template <
class Scalar>
367 out <<
"--- StepperNewmarkExplicitAForm ---\n";
368 out <<
" gamma_ = " << gamma_ << std::endl;
369 out <<
"-----------------------------------" << std::endl;
372 template <
class Scalar>
377 bool isValidSetup =
true;
385 template <
class Scalar>
389 auto pl = this->getValidParametersBasic();
390 pl->sublist(
"Newmark Explicit Parameters",
false,
"");
391 pl->sublist(
"Newmark Explicit Parameters",
false,
"")
392 .set(
"Gamma", gamma_,
"Newmark Explicit parameter");
396 template <
class Scalar>
400 if (appAction == Teuchos::null) {
402 stepperNewmarkExpAppAction_ =
406 stepperNewmarkExpAppAction_ = appAction;
409 this->isInitialized_ =
false;
414 template <
class Scalar>
421 stepper->setStepperExplicitValues(pl);
423 if (pl != Teuchos::null) {
424 Scalar gamma = pl->
sublist(
"Newmark Explicit Parameters")
425 .template get<double>(
"Gamma", 0.5);
426 stepper->setGamma(gamma);
429 if (model != Teuchos::null) {
430 stepper->setModel(model);
431 stepper->initialize();
438 #endif // Tempus_StepperNewmarkExplicitAForm_impl_hpp
virtual RCP< const VectorSpaceBase< Scalar > > space() const =0
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void setStepperName(std::string s)
Set the stepper name.
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
Set model.
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
Teuchos::RCP< StepperNewmarkExplicitAForm< Scalar > > createStepperNewmarkExplicitAForm(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Thyra Base interface for implicit time steppers.
void setStepperType(std::string s)
Set the stepper type.
void setICConsistency(std::string s)