96 int numStates = solutionHistory->getNumStates();
98 TEUCHOS_TEST_FOR_EXCEPTION(
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();
106 Teuchos::OSTab ostab(out, 1,
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();
119 TEUCHOS_TEST_FOR_EXCEPTION(
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) {
134 TEUCHOS_TEST_FOR_EXCEPTION((this->inArgs_.get_x() == 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");
140 x = rcp_const_cast<Thyra::VectorBase<Scalar> >(this->inArgs_.get_x());
141 initialState->setX(x);
143 rcp_const_cast<Thyra::VectorBase<Scalar> >(this->inArgs_.get_x_dot());
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();
162 Teuchos::OSTab ostab(out, 1,
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") {
178 auto xDotDot = Teuchos::rcp_const_cast<Thyra::VectorBase<Scalar> >(
179 this->inArgs_.get_x_dot_dot());
180 TEUCHOS_TEST_FOR_EXCEPTION(
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);
197 TEUCHOS_TEST_FOR_EXCEPTION(
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);
213 Scalar eps = Scalar(100.0) * std::abs(Teuchos::ScalarTraits<Scalar>::eps());
214 if (normxDotDot > eps * reldiff) reldiff /= normxDotDot;
216 RCP<Teuchos::FancyOStream> out = this->getOStream();
217 Teuchos::OSTab ostab(out, 1,
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"
246 this->checkInitialized();
250 TEMPUS_FUNC_TIME_MONITOR(
"Tempus::StepperNewmarkExplicitAForm::takeStep()");
252 TEUCHOS_TEST_FOR_EXCEPTION(
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);
327 assign(a_new.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
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);
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...