9 #ifndef Tempus_IntegratorPseudoTransientAdjointSensitivity_impl_hpp
10 #define Tempus_IntegratorPseudoTransientAdjointSensitivity_impl_hpp
12 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
13 #include "Thyra_DefaultMultiVectorProductVector.hpp"
14 #include "Thyra_VectorStdOps.hpp"
15 #include "Thyra_MultiVectorStdOps.hpp"
16 #include "NOX_Thyra.H"
20 template<
class Scalar>
23 Teuchos::RCP<Teuchos::ParameterList> inputPL,
24 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model)
27 state_integrator_ = integratorBasic<Scalar>(inputPL, model_);
28 sens_model_ = createSensitivityModel(model_, inputPL);
29 sens_integrator_ = integratorBasic<Scalar>(inputPL, sens_model_);
32 template<
class Scalar>
35 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
36 std::string stepperType)
39 state_integrator_ = integratorBasic<Scalar>(model_, stepperType);
40 sens_model_ = createSensitivityModel(model, Teuchos::null);
41 sens_integrator_ = integratorBasic<Scalar>(sens_model_, stepperType);
44 template<
class Scalar>
48 state_integrator_ = integratorBasic<Scalar>();
49 sens_integrator_ = integratorBasic<Scalar>();
52 template<
class Scalar>
58 state_integrator_->getTimeStepControl()->getFinalTime();
59 return advanceTime(tfinal);
62 template<
class Scalar>
68 using Thyra::VectorBase;
69 typedef Thyra::ModelEvaluatorBase MEB;
72 bool state_status = state_integrator_->advanceTime(timeFinal);
75 sens_model_->setForwardSolutionHistory(
76 state_integrator_->getSolutionHistory());
79 bool sens_status = sens_integrator_->advanceTime(timeFinal);
83 MEB::InArgs<Scalar> inargs = sens_model_->getNominalValues();
84 MEB::OutArgs<Scalar> outargs = sens_model_->createOutArgs();
85 inargs.set_t(sens_integrator_->getTime());
86 inargs.set_x(sens_integrator_->getX());
87 if (inargs.supports(MEB::IN_ARG_x_dot))
88 inargs.set_x_dot(sens_integrator_->getXdot());
89 if (inargs.supports(MEB::IN_ARG_x_dot_dot))
90 inargs.set_x_dot_dot(sens_integrator_->getXdotdot());
91 RCP<VectorBase<Scalar> > G = dgdp_;
92 if (G == Teuchos::null) {
93 G = Thyra::createMember(sens_model_->get_g_space(0));
94 dgdp_ = Teuchos::rcp_dynamic_cast<
DMVPV>(G);
97 sens_model_->evalModel(inargs, outargs);
99 buildSolutionHistory();
101 return state_status && sens_status;
104 template<
class Scalar>
109 return solutionHistory_->getCurrentTime();
112 template<
class Scalar>
117 return solutionHistory_->getCurrentIndex();
120 template<
class Scalar>
125 Status state_status = state_integrator_->getStatus();
126 Status sens_status = sens_integrator_->getStatus();
134 template<
class Scalar>
135 Teuchos::RCP<Stepper<Scalar> >
139 return state_integrator_->getStepper();
142 template<
class Scalar>
143 Teuchos::RCP<Teuchos::ParameterList>
147 return state_integrator_->getTempusParameterList();
150 template<
class Scalar>
155 state_integrator_->setTempusParameterList(pl);
156 sens_integrator_->setTempusParameterList(pl);
159 template<
class Scalar>
160 Teuchos::RCP<const SolutionHistory<Scalar> >
164 return solutionHistory_;
167 template<
class Scalar>
168 Teuchos::RCP<const TimeStepControl<Scalar> >
172 return state_integrator_->getTimeStepControl();
175 template<
class Scalar>
176 Teuchos::RCP<TimeStepControl<Scalar> >
180 return state_integrator_->getNonConstTimeStepControl();
183 template<
class Scalar>
186 Teuchos::RCP<
const Thyra::VectorBase<Scalar> > x0,
187 Teuchos::RCP<
const Thyra::VectorBase<Scalar> > xdot0,
188 Teuchos::RCP<
const Thyra::VectorBase<Scalar> > xdotdot0,
189 Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > y0,
190 Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > ydot0,
191 Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > ydotdot0)
194 using Teuchos::rcp_dynamic_cast;
195 using Thyra::VectorSpaceBase;
197 using Thyra::createMember;
202 RCP< const VectorSpaceBase<Scalar> > space = sens_model_->get_x_space();
203 RCP<DMVPV> Y = rcp_dynamic_cast<
DMVPV>(createMember(space));
204 RCP<DMVPV> Ydot = rcp_dynamic_cast<
DMVPV>(createMember(space));
205 RCP<DMVPV> Ydotdot = rcp_dynamic_cast<
DMVPV>(createMember(space));
206 const Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
209 if (y0 == Teuchos::null)
210 assign(Y->getNonconstMultiVector().ptr(), zero);
212 assign(Y->getNonconstMultiVector().ptr(), *y0);
215 if (ydot0 == Teuchos::null)
216 assign(Ydot->getNonconstMultiVector().ptr(), zero);
218 assign(Ydot->getNonconstMultiVector().ptr(), *ydot0);
221 if (ydotdot0 == Teuchos::null)
222 assign(Ydotdot->getNonconstMultiVector().ptr(), zero);
224 assign(Ydotdot->getNonconstMultiVector().ptr(), *ydotdot0);
226 state_integrator_->initializeSolutionHistory(t0, x0, xdot0, xdotdot0);
227 sens_integrator_->initializeSolutionHistory(t0, Y, Ydot, Ydotdot);
230 template<
class Scalar>
231 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
235 return state_integrator_->getX();
238 template<
class Scalar>
239 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
243 return state_integrator_->getXdot();
246 template<
class Scalar>
247 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
251 return state_integrator_->getXdotdot();
254 template<
class Scalar>
255 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
259 return dgdp_->getMultiVector();
262 template<
class Scalar>
267 std::string name =
"Tempus::IntegratorPseudoTransientAdjointSensitivity";
271 template<
class Scalar>
275 Teuchos::FancyOStream &out,
276 const Teuchos::EVerbosityLevel verbLevel)
const
278 out << description() <<
"::describe" << std::endl;
279 state_integrator_->describe(out, verbLevel);
280 sens_integrator_->describe(out, verbLevel);
283 template<
class Scalar>
288 state_integrator_->setParameterList(inputPL);
289 sens_integrator_->setParameterList(inputPL);
292 template<
class Scalar>
293 Teuchos::RCP<Teuchos::ParameterList>
297 state_integrator_->unsetParameterList();
298 return sens_integrator_->unsetParameterList();
301 template<
class Scalar>
302 Teuchos::RCP<const Teuchos::ParameterList>
306 Teuchos::RCP<Teuchos::ParameterList> pl =
307 Teuchos::rcp(
new Teuchos::ParameterList);
308 Teuchos::RCP<const Teuchos::ParameterList> integrator_pl =
309 state_integrator_->getValidParameters();
310 Teuchos::RCP<const Teuchos::ParameterList> sensitivity_pl =
312 pl->setParameters(*integrator_pl);
313 pl->sublist(
"Sensitivities").setParameters(*sensitivity_pl);
318 template<
class Scalar>
319 Teuchos::RCP<Teuchos::ParameterList>
323 return state_integrator_->getNonconstParameterList();
326 template <
class Scalar>
327 Teuchos::RCP<AdjointSensitivityModelEvaluator<Scalar> >
330 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
331 const Teuchos::RCP<Teuchos::ParameterList>& inputPL)
335 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
336 if (inputPL != Teuchos::null) {
337 *pl = inputPL->sublist(
"Sensitivities");
339 const Scalar tfinal = state_integrator_->getTimeStepControl()->getFinalTime();
341 model, tfinal,
true, pl));
344 template<
class Scalar>
351 using Teuchos::rcp_dynamic_cast;
352 using Teuchos::ParameterList;
353 using Thyra::VectorBase;
354 using Thyra::VectorSpaceBase;
356 using Thyra::defaultProductVector;
357 typedef Thyra::DefaultProductVector<Scalar> DPV;
358 typedef Thyra::DefaultProductVectorSpace<Scalar> DPVS;
362 RCP<ParameterList> shPL =
363 Teuchos::sublist(state_integrator_->getIntegratorParameterList(),
364 "Solution History",
true);
367 RCP<const VectorSpaceBase<Scalar> > x_space =
368 model_->get_x_space();
369 RCP<const VectorSpaceBase<Scalar> > adjoint_space =
370 sens_model_->get_x_space();
371 Teuchos::Array< RCP<const VectorSpaceBase<Scalar> > > spaces(2);
373 spaces[1] = adjoint_space;
374 RCP<const DPVS > prod_space = Thyra::productVectorSpace(spaces());
375 const Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
377 RCP<const SolutionHistory<Scalar> > state_solution_history =
378 state_integrator_->getSolutionHistory();
379 int num_states = state_solution_history->getNumStates();
380 for (
int i=0; i<num_states; ++i) {
381 RCP<const SolutionState<Scalar> > state = (*state_solution_history)[i];
384 RCP<DPV> x = defaultProductVector(prod_space);
385 assign(x->getNonconstVectorBlock(0).ptr(), *(state->getX()));
386 assign(x->getNonconstVectorBlock(1).ptr(), zero);
387 RCP<VectorBase<Scalar> > x_b = x;
390 RCP<VectorBase<Scalar> > x_dot_b;
391 if (state->getXDot() != Teuchos::null) {
392 RCP<DPV> x_dot = defaultProductVector(prod_space);
393 assign(x_dot->getNonconstVectorBlock(0).ptr(), *(state->getXDot()));
394 assign(x_dot->getNonconstVectorBlock(1).ptr(), zero);
399 RCP<VectorBase<Scalar> > x_dot_dot_b;
400 if (state->getXDotDot() != Teuchos::null) {
401 RCP<DPV> x_dot_dot = defaultProductVector(prod_space);
402 assign(x_dot_dot->getNonconstVectorBlock(0).ptr(),*(state->getXDotDot()));
403 assign(x_dot_dot->getNonconstVectorBlock(1).ptr(), zero);
404 x_dot_dot_b = x_dot_dot;
407 RCP<SolutionState<Scalar> > prod_state = state->clone();
408 prod_state->setX(x_b);
409 prod_state->setXDot(x_dot_b);
410 prod_state->setXDotDot(x_dot_dot_b);
411 solutionHistory_->addState(prod_state);
414 RCP<const VectorBase<Scalar> > frozen_x =
415 state_solution_history->getCurrentState()->getX();
416 RCP<const VectorBase<Scalar> > frozen_x_dot =
417 state_solution_history->getCurrentState()->getXDot();
418 RCP<const VectorBase<Scalar> > frozen_x_dot_dot =
419 state_solution_history->getCurrentState()->getXDotDot();
420 RCP<const SolutionHistory<Scalar> > sens_solution_history =
421 sens_integrator_->getSolutionHistory();
422 num_states = sens_solution_history->getNumStates();
423 for (
int i=0; i<num_states; ++i) {
424 RCP<const SolutionState<Scalar> > state = (*sens_solution_history)[i];
427 RCP<DPV> x = defaultProductVector(prod_space);
428 assign(x->getNonconstVectorBlock(0).ptr(), *frozen_x);
429 assign(x->getNonconstVectorBlock(1).ptr(), *(state->getX()));
430 RCP<VectorBase<Scalar> > x_b = x;
433 RCP<VectorBase<Scalar> > x_dot_b;
434 if (state->getXDot() != Teuchos::null) {
435 RCP<DPV> x_dot = defaultProductVector(prod_space);
436 assign(x_dot->getNonconstVectorBlock(0).ptr(), *frozen_x_dot);
437 assign(x_dot->getNonconstVectorBlock(1).ptr(), *(state->getXDot()));
442 RCP<VectorBase<Scalar> > x_dot_dot_b;
443 if (state->getXDotDot() != Teuchos::null) {
444 RCP<DPV> x_dot_dot = defaultProductVector(prod_space);
445 assign(x_dot_dot->getNonconstVectorBlock(0).ptr(), *frozen_x_dot_dot);
446 assign(x_dot_dot->getNonconstVectorBlock(1).ptr(),*(state->getXDotDot()));
447 x_dot_dot_b = x_dot_dot;
450 RCP<SolutionState<Scalar> > prod_state = state->clone();
451 prod_state->setX(x_b);
452 prod_state->setXDot(x_dot_b);
453 prod_state->setXDotDot(x_dot_dot_b);
454 solutionHistory_->addState(prod_state);
459 template<
class Scalar>
460 Teuchos::RCP<IntegratorPseudoTransientAdjointSensitivity<Scalar> >
462 Teuchos::RCP<Teuchos::ParameterList> pList,
463 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model)
465 Teuchos::RCP<IntegratorPseudoTransientAdjointSensitivity<Scalar> > integrator =
471 template<
class Scalar>
472 Teuchos::RCP<IntegratorPseudoTransientAdjointSensitivity<Scalar> >
474 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
475 std::string stepperType)
477 Teuchos::RCP<IntegratorPseudoTransientAdjointSensitivity<Scalar> > integrator =
483 template<
class Scalar>
484 Teuchos::RCP<IntegratorPseudoTransientAdjointSensitivity<Scalar> >
487 Teuchos::RCP<IntegratorPseudoTransientAdjointSensitivity<Scalar> > integrator =
493 #endif // Tempus_IntegratorPseudoTransientAdjointSensitivity_impl_hpp
static Teuchos::RCP< const Teuchos::ParameterList > getValidParameters()
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl) override
virtual Scalar getTime() const override
Get current time.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
virtual void setTempusParameterList(Teuchos::RCP< Teuchos::ParameterList > pl) override
Teuchos::RCP< Tempus::IntegratorPseudoTransientAdjointSensitivity< Scalar > > integratorPseudoTransientAdjointSensitivity(Teuchos::RCP< Teuchos::ParameterList > pList, const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model)
Non-member constructor.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList() override
std::string description() const override
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDgDp() const
Return adjoint sensitivity stored in gradient format.
Time integrator suitable for pseudotransient adjoint sensitivity analysis.
virtual Teuchos::RCP< TimeStepControl< Scalar > > getNonConstTimeStepControl() override
Status
Status for the Integrator, the Stepper and the SolutionState.
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXdot() const
Get current the time derivative of the solution, xdot.
virtual void initializeSolutionHistory(Scalar t0, Teuchos::RCP< const Thyra::VectorBase< Scalar > > x0, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xdot0=Teuchos::null, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xdotdot0=Teuchos::null, Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > y0=Teuchos::null, Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > ydot0=Teuchos::null, Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > ydotdot0=Teuchos::null)
Set the initial state from Thyra::VectorBase(s)
IntegratorPseudoTransientAdjointSensitivity()
Destructor.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXdotdot() const
Get current the second time derivative of the solution, xdotdot.
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList() override
Teuchos::RCP< AdjointSensitivityModelEvaluator< Scalar > > createSensitivityModel(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model, const Teuchos::RCP< Teuchos::ParameterList > &inputPL)
virtual Teuchos::RCP< Teuchos::ParameterList > getTempusParameterList() override
Return a copy of the Tempus ParameterList.
virtual int getIndex() const override
Get current index.
virtual Teuchos::RCP< Stepper< Scalar > > getStepper() const override
Get the Stepper.
virtual Teuchos::RCP< const SolutionHistory< Scalar > > getSolutionHistory() const override
Get the SolutionHistory.
virtual Teuchos::RCP< const TimeStepControl< Scalar > > getTimeStepControl() const override
Get the TimeStepControl.
ModelEvaluator for forming adjoint sensitivity equations.
virtual bool advanceTime()
Advance the solution to timeMax, and return true if successful.
void buildSolutionHistory()
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getX() const
Get current the solution, x.
Thyra::DefaultMultiVectorProductVector< Scalar > DMVPV
virtual Status getStatus() const override
Get Status.