9 #ifndef Tempus_StepperExplicit_impl_hpp
10 #define Tempus_StepperExplicit_impl_hpp
12 #include "Thyra_VectorStdOps.hpp"
18 template<
class Scalar>
25 inArgs_ = appModel_->getNominalValues();
26 outArgs_ = appModel_->createOutArgs();
30 template<
class Scalar>
36 int numStates = solutionHistory->getNumStates();
39 "Error - setInitialConditions() needs at least one SolutionState\n"
40 " to set the initial condition. Number of States = " << numStates);
43 RCP<Teuchos::FancyOStream> out = this->getOStream();
44 Teuchos::OSTab ostab(out,1,
"StepperExplicit::setInitialConditions()");
45 *out <<
"Warning -- SolutionHistory has more than one state!\n"
46 <<
"Setting the initial conditions on the currentState.\n"<<std::endl;
49 RCP<SolutionState<Scalar> > initialState = solutionHistory->getCurrentState();
50 RCP<Thyra::VectorBase<Scalar> > x = initialState->getX();
51 RCP<Thyra::VectorBase<Scalar> > xDot = initialState->getXDot();
52 if (xDot == Teuchos::null) xDot = this->getStepperXDot();
55 inArgs_ = appModel_->getNominalValues();
57 RCP<Thyra::VectorBase<Scalar> > initialXDot = initialState->getXDot();
61 !((x != Teuchos::null && initialXDot != Teuchos::null) ||
62 (inArgs_.get_x() != Teuchos::null &&
63 inArgs_.get_x_dot() != Teuchos::null)), std::logic_error,
64 "Error - We need to set the initial conditions for x and xDot from\n"
65 " either initialState or appModel_->getNominalValues::InArgs\n"
66 " (but not from a mixture of the two).\n");
70 if (x == Teuchos::null) {
73 (inArgs_.get_x() == Teuchos::null), std::logic_error,
74 "Error - setInitialConditions needs the ICs from the SolutionHistory\n"
75 " or getNominalValues()!\n");
78 initialState->setX(x);
82 using Teuchos::rcp_const_cast;
84 if ( initialState->getX() == Teuchos::null ||
85 initialState->getXDot() == Teuchos::null ) {
87 (inArgs_.get_x_dot() == Teuchos::null), std::logic_error,
88 "Error - setInitialConditions() needs the ICs from the initialState\n"
89 " or getNominalValues()!\n");
91 initialState->setX(x);
92 RCP<Thyra::VectorBase<Scalar> > x_dot
94 initialState->setXDot(x_dot);
99 std::string icConsistency = this->getICConsistency();
100 if (icConsistency ==
"None") {
102 if (initialState->getXDot() == Teuchos::null) {
103 RCP<Teuchos::FancyOStream> out = this->getOStream();
104 Teuchos::OSTab ostab(out,1,
"StepperExplicit::setInitialConditions()");
105 *out <<
"Warning -- Requested IC consistency of 'None' but\n"
106 <<
" initialState does not have an xDot.\n"
107 <<
" Setting a 'Consistent' xDot!\n" << std::endl;
109 evaluateExplicitODE(xDot, x, initialState->getTime(), p);
110 initialState->setIsSynced(
true);
114 if (initialState->getXDotDot() == Teuchos::null) {
115 RCP<Teuchos::FancyOStream> out = this->getOStream();
116 Teuchos::OSTab ostab(out,1,
"StepperExplicit::setInitialConditions()");
117 *out <<
"Warning -- Requested IC consistency of 'None' but\n"
118 <<
" initialState does not have an xDotDot.\n"
119 <<
" Setting a 'Consistent' xDotDot!\n" << std::endl;
121 this->evaluateExplicitODE(this->getStepperXDotDot(initialState), x,
122 initialState->getXDot(),
123 initialState->getTime(), p);
124 initialState->setIsSynced(
true);
128 else if (icConsistency ==
"Zero") {
130 Thyra::assign(xDot.ptr(), Scalar(0.0));
132 Thyra::assign(this->getStepperXDotDot(initialState).ptr(), Scalar(0.0));
134 else if (icConsistency ==
"App") {
137 inArgs_.get_x_dot());
139 "Error - setInitialConditions() requested 'App' for IC consistency,\n"
140 " but 'App' returned a null pointer for xDot!\n");
141 Thyra::assign(xDot.ptr(), *x_dot);
145 inArgs_.get_x_dot_dot());
147 "Error - setInitialConditions() requested 'App' for IC consistency,\n"
148 " but 'App' returned a null pointer for xDotDot!\n");
149 Thyra::assign(this->getStepperXDotDot(initialState).ptr(), *xDotDot);
152 else if (icConsistency ==
"Consistent") {
156 evaluateExplicitODE(xDot, x, initialState->getTime(), p);
161 this->evaluateExplicitODE(initialState->getXDotDot(), x,
162 initialState->getXDot(),
163 initialState->getTime(), p);
168 "Error - setInitialConditions() invalid IC consistency, '"
169 << icConsistency <<
"'.\n");
174 initialState->setIsSynced(
true);
177 if (this->getICConsistencyCheck()) {
179 auto f = initialState->getX()->clone_v();
181 evaluateExplicitODE(f, x, initialState->getTime(), p);
182 Thyra::Vp_StV(f.ptr(), Scalar(-1.0), *(xDot));
183 Scalar normX = Thyra::norm(*x);
184 Scalar reldiff = Scalar(0.0);
185 if (normX == Scalar(0.0)) reldiff = Thyra::norm(*f);
186 else reldiff = Thyra::norm(*f)/normX;
189 RCP<Teuchos::FancyOStream> out = this->getOStream();
190 Teuchos::OSTab ostab(out,1,
"StepperExplicit::setInitialConditions()");
192 *out <<
"\n---------------------------------------------------\n"
193 <<
"Info -- Stepper = " << this->getStepperType() <<
"\n"
194 <<
" Initial condition PASSED consistency check!\n"
195 <<
" (||xDot-f(x,t)||/||x|| = " << reldiff <<
") < "
196 <<
"(eps = " << eps <<
")" << std::endl
197 <<
"---------------------------------------------------\n"<<std::endl;
199 *out <<
"\n---------------------------------------------------\n"
200 <<
"Info -- Stepper = " << this->getStepperType() <<
"\n"
201 <<
" Initial condition FAILED consistency check but continuing!\n"
202 <<
" (||xDot-f(x,t)||/||x|| = " << reldiff <<
") > "
203 <<
"(eps = " << eps <<
")" << std::endl
204 <<
" ||xDot-f(x,t)|| = " << Thyra::norm(*f) << std::endl
205 <<
" ||x|| = " << Thyra::norm(*x) << std::endl
206 <<
"---------------------------------------------------\n"<<std::endl;
210 auto xDotDot = initialState->getXDotDot();
211 auto f = initialState->getX()->clone_v();
213 this->evaluateExplicitODE(f, x, initialState->getXDot(),
214 initialState->getTime(), p);
215 Thyra::Vp_StV(f.ptr(), Scalar(-1.0), *(xDotDot));
216 Scalar normX = Thyra::norm(*x);
217 Scalar reldiff = Scalar(0.0);
218 if (normX == Scalar(0.0)) reldiff = Thyra::norm(*f);
219 else reldiff = Thyra::norm(*f)/normX;
222 RCP<Teuchos::FancyOStream> out = this->getOStream();
223 Teuchos::OSTab ostab(out,1,
"StepperExplicit::setInitialConditions()");
225 *out <<
"\n---------------------------------------------------\n"
226 <<
"Info -- Stepper = " << this->getStepperType() <<
"\n"
227 <<
" Initial condition PASSED consistency check!\n"
228 <<
" (||xDotDot-f(x,xDot,t)||/||x|| = " << reldiff <<
") > "
229 <<
"(eps = " << eps <<
")" << std::endl
230 <<
"---------------------------------------------------\n"<<std::endl;
232 *out <<
"\n---------------------------------------------------\n"
233 <<
"Info -- Stepper = " << this->getStepperType() <<
"\n"
234 <<
"Initial condition FAILED consistency check but continuing!\n"
235 <<
" (||xDotDot-f(x,xDot,t)||/||x|| = " << reldiff <<
") > "
236 <<
"(eps = " << eps <<
")" << std::endl
237 <<
" ||xDotDot-f(x,xDot,t)|| = " << Thyra::norm(*f) << std::endl
238 <<
" ||x|| = " << Thyra::norm(*x) << std::endl
239 <<
"---------------------------------------------------\n"<<std::endl;
245 template<
class Scalar>
251 *out <<
"Warning -- No solver to set for StepperExplicit "
252 <<
"(i.e., explicit method).\n" << std::endl;
255 template<
class Scalar>
266 if (inArgs_.supports(MEB::IN_ARG_t)) inArgs_.set_t(time);
267 if (inArgs_.supports(MEB::IN_ARG_step_size))
268 inArgs_.set_step_size(p->timeStepSize_);
269 if (inArgs_.supports(MEB::IN_ARG_stage_number))
270 inArgs_.set_stage_number(p->stageNumber_);
277 if (inArgs_.supports(MEB::IN_ARG_x_dot)) inArgs_.set_x_dot(Teuchos::null);
279 outArgs_.set_f(xDot);
281 appModel_->evalModel(inArgs_, outArgs_);
284 template<
class Scalar>
296 if (inArgs_.supports(MEB::IN_ARG_x_dot)) inArgs_.set_x_dot(xDot);
297 if (inArgs_.supports(MEB::IN_ARG_t)) inArgs_.set_t(time);
298 if (inArgs_.supports(MEB::IN_ARG_step_size))
299 inArgs_.set_step_size(p->timeStepSize_);
300 if (inArgs_.supports(MEB::IN_ARG_stage_number))
301 inArgs_.set_stage_number(p->stageNumber_);
308 if (inArgs_.supports(MEB::IN_ARG_x_dot_dot))
309 inArgs_.set_x_dot_dot(Teuchos::null);
311 outArgs_.set_f(xDotDot);
313 appModel_->evalModel(inArgs_, outArgs_);
318 template<
class Scalar>
322 out <<
"--- StepperExplicit ---\n";
323 out <<
" appModel_ = " << appModel_ << std::endl;
324 out <<
" inArgs_ = " << inArgs_ << std::endl;
325 out <<
" outArgs_ = " << outArgs_ << std::endl;
329 template<
class Scalar>
332 bool isValidSetup =
true;
334 if (appModel_ == Teuchos::null) {
335 isValidSetup =
false;
336 out <<
"The application ModelEvaluator is not set!\n";
343 template<
class Scalar>
347 if (pl != Teuchos::null) {
349 this->setStepperValues(pl);
355 #endif // Tempus_StepperExplicit_impl_hpp
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void validExplicitODE(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Validate that the model supports explicit ODE evaluation, f(x,t) [=xdot].
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver)
Set solver.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Stepper integrates second-order ODEs.
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions, make them consistent, and set needed memory.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
Stepper integrates first-order ODEs.
virtual void evaluateExplicitODE(Teuchos::RCP< Thyra::VectorBase< Scalar > > xDot, Teuchos::RCP< const Thyra::VectorBase< Scalar > > x, const Scalar time, const Teuchos::RCP< ExplicitODEParameters< Scalar > > &p)
Evaluate xDot = f(x,t).
void setStepperExplicitValues(Teuchos::RCP< Teuchos::ParameterList > pl)
Set StepperExplicit member data from the ParameterList.