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>
178 Teuchos::RCP<
const Thyra::VectorBase<Scalar> > x0,
179 Teuchos::RCP<
const Thyra::VectorBase<Scalar> > xdot0,
180 Teuchos::RCP<
const Thyra::VectorBase<Scalar> > xdotdot0,
181 Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > y0,
182 Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > ydot0,
183 Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > ydotdot0)
186 using Teuchos::rcp_dynamic_cast;
187 using Thyra::VectorSpaceBase;
189 using Thyra::createMember;
194 RCP< const VectorSpaceBase<Scalar> > space = sens_model_->get_x_space();
195 RCP<DMVPV> Y = rcp_dynamic_cast<
DMVPV>(createMember(space));
196 RCP<DMVPV> Ydot = rcp_dynamic_cast<
DMVPV>(createMember(space));
197 RCP<DMVPV> Ydotdot = rcp_dynamic_cast<
DMVPV>(createMember(space));
198 const Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
201 if (y0 == Teuchos::null)
202 assign(Y->getNonconstMultiVector().ptr(), zero);
204 assign(Y->getNonconstMultiVector().ptr(), *y0);
207 if (ydot0 == Teuchos::null)
208 assign(Ydot->getNonconstMultiVector().ptr(), zero);
210 assign(Ydot->getNonconstMultiVector().ptr(), *ydot0);
213 if (ydotdot0 == Teuchos::null)
214 assign(Ydotdot->getNonconstMultiVector().ptr(), zero);
216 assign(Ydotdot->getNonconstMultiVector().ptr(), *ydotdot0);
218 state_integrator_->initializeSolutionHistory(t0, x0, xdot0, xdotdot0);
219 sens_integrator_->initializeSolutionHistory(t0, Y, Ydot, Ydotdot);
222 template<
class Scalar>
223 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
227 return state_integrator_->getX();
230 template<
class Scalar>
231 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
235 return state_integrator_->getXdot();
238 template<
class Scalar>
239 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
243 return state_integrator_->getXdotdot();
246 template<
class Scalar>
247 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
251 return dgdp_->getMultiVector();
254 template<
class Scalar>
259 std::string name =
"Tempus::IntegratorPseudoTransientAdjointSensitivity";
263 template<
class Scalar>
267 Teuchos::FancyOStream &out,
268 const Teuchos::EVerbosityLevel verbLevel)
const
270 out << description() <<
"::describe" << std::endl;
271 state_integrator_->describe(out, verbLevel);
272 sens_integrator_->describe(out, verbLevel);
275 template<
class Scalar>
280 state_integrator_->setParameterList(inputPL);
281 sens_integrator_->setParameterList(inputPL);
284 template<
class Scalar>
285 Teuchos::RCP<Teuchos::ParameterList>
289 state_integrator_->unsetParameterList();
290 return sens_integrator_->unsetParameterList();
293 template<
class Scalar>
294 Teuchos::RCP<const Teuchos::ParameterList>
298 Teuchos::RCP<Teuchos::ParameterList> pl =
299 Teuchos::rcp(
new Teuchos::ParameterList);
300 Teuchos::RCP<const Teuchos::ParameterList> integrator_pl =
301 state_integrator_->getValidParameters();
302 Teuchos::RCP<const Teuchos::ParameterList> sensitivity_pl =
304 pl->setParameters(*integrator_pl);
305 pl->sublist(
"Sensitivities").setParameters(*sensitivity_pl);
310 template<
class Scalar>
311 Teuchos::RCP<Teuchos::ParameterList>
315 return state_integrator_->getNonconstParameterList();
318 template <
class Scalar>
319 Teuchos::RCP<Tempus::AdjointSensitivityModelEvaluator<Scalar> >
322 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
323 const Teuchos::RCP<Teuchos::ParameterList>& inputPL)
327 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
328 if (inputPL != Teuchos::null) {
329 *pl = inputPL->sublist(
"Sensitivities");
331 const Scalar tfinal = state_integrator_->getTimeStepControl()->getFinalTime();
333 model, tfinal,
true, pl));
336 template<
class Scalar>
343 using Teuchos::rcp_dynamic_cast;
344 using Teuchos::ParameterList;
345 using Thyra::VectorBase;
346 using Thyra::VectorSpaceBase;
348 using Thyra::defaultProductVector;
349 typedef Thyra::DefaultProductVector<Scalar> DPV;
350 typedef Thyra::DefaultProductVectorSpace<Scalar> DPVS;
354 RCP<ParameterList> shPL =
355 Teuchos::sublist(state_integrator_->getIntegratorParameterList(),
356 "Solution History",
true);
359 RCP<const VectorSpaceBase<Scalar> > x_space =
360 model_->get_x_space();
361 RCP<const VectorSpaceBase<Scalar> > adjoint_space =
362 sens_model_->get_x_space();
363 Teuchos::Array< RCP<const VectorSpaceBase<Scalar> > > spaces(2);
365 spaces[1] = adjoint_space;
366 RCP<const DPVS > prod_space = Thyra::productVectorSpace(spaces());
367 const Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
369 RCP<const SolutionHistory<Scalar> > state_solution_history =
370 state_integrator_->getSolutionHistory();
371 int num_states = state_solution_history->getNumStates();
372 for (
int i=0; i<num_states; ++i) {
373 RCP<const SolutionState<Scalar> > state = (*state_solution_history)[i];
376 RCP<DPV> x = defaultProductVector(prod_space);
377 assign(x->getNonconstVectorBlock(0).ptr(), *(state->getX()));
378 assign(x->getNonconstVectorBlock(1).ptr(), zero);
379 RCP<VectorBase<Scalar> > x_b = x;
382 RCP<VectorBase<Scalar> > x_dot_b;
383 if (state->getXDot() != Teuchos::null) {
384 RCP<DPV> x_dot = defaultProductVector(prod_space);
385 assign(x_dot->getNonconstVectorBlock(0).ptr(), *(state->getXDot()));
386 assign(x_dot->getNonconstVectorBlock(1).ptr(), zero);
391 RCP<VectorBase<Scalar> > x_dot_dot_b;
392 if (state->getXDotDot() != Teuchos::null) {
393 RCP<DPV> x_dot_dot = defaultProductVector(prod_space);
394 assign(x_dot_dot->getNonconstVectorBlock(0).ptr(),*(state->getXDotDot()));
395 assign(x_dot_dot->getNonconstVectorBlock(1).ptr(), zero);
396 x_dot_dot_b = x_dot_dot;
399 RCP<SolutionState<Scalar> > prod_state =
401 x_b, x_dot_b, x_dot_dot_b,
402 state->getStepperState()->clone()));
403 solutionHistory_->addState(prod_state);
406 RCP<const VectorBase<Scalar> > frozen_x =
407 state_solution_history->getCurrentState()->getX();
408 RCP<const VectorBase<Scalar> > frozen_x_dot =
409 state_solution_history->getCurrentState()->getXDot();
410 RCP<const VectorBase<Scalar> > frozen_x_dot_dot =
411 state_solution_history->getCurrentState()->getXDotDot();
412 RCP<const SolutionHistory<Scalar> > sens_solution_history =
413 sens_integrator_->getSolutionHistory();
414 num_states = sens_solution_history->getNumStates();
415 for (
int i=0; i<num_states; ++i) {
416 RCP<const SolutionState<Scalar> > state = (*sens_solution_history)[i];
419 RCP<DPV> x = defaultProductVector(prod_space);
420 assign(x->getNonconstVectorBlock(0).ptr(), *frozen_x);
421 assign(x->getNonconstVectorBlock(1).ptr(), *(state->getX()));
422 RCP<VectorBase<Scalar> > x_b = x;
425 RCP<VectorBase<Scalar> > x_dot_b;
426 if (state->getXDot() != Teuchos::null) {
427 RCP<DPV> x_dot = defaultProductVector(prod_space);
428 assign(x_dot->getNonconstVectorBlock(0).ptr(), *frozen_x_dot);
429 assign(x_dot->getNonconstVectorBlock(1).ptr(), *(state->getXDot()));
434 RCP<VectorBase<Scalar> > x_dot_dot_b;
435 if (state->getXDotDot() != Teuchos::null) {
436 RCP<DPV> x_dot_dot = defaultProductVector(prod_space);
437 assign(x_dot_dot->getNonconstVectorBlock(0).ptr(), *frozen_x_dot_dot);
438 assign(x_dot_dot->getNonconstVectorBlock(1).ptr(),*(state->getXDotDot()));
439 x_dot_dot_b = x_dot_dot;
442 RCP<SolutionState<Scalar> > prod_state =
444 x_b, x_dot_b, x_dot_dot_b,
445 state->getStepperState()->clone()));
446 solutionHistory_->addState(prod_state);
451 template<
class Scalar>
452 Teuchos::RCP<Tempus::IntegratorPseudoTransientAdjointSensitivity<Scalar> >
454 Teuchos::RCP<Teuchos::ParameterList> pList,
455 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model)
457 Teuchos::RCP<Tempus::IntegratorPseudoTransientAdjointSensitivity<Scalar> > integrator =
463 template<
class Scalar>
464 Teuchos::RCP<Tempus::IntegratorPseudoTransientAdjointSensitivity<Scalar> >
466 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
467 std::string stepperType)
469 Teuchos::RCP<Tempus::IntegratorPseudoTransientAdjointSensitivity<Scalar> > integrator =
475 template<
class Scalar>
476 Teuchos::RCP<Tempus::IntegratorPseudoTransientAdjointSensitivity<Scalar> >
479 Teuchos::RCP<Tempus::IntegratorPseudoTransientAdjointSensitivity<Scalar> > integrator =
485 #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< 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.
Teuchos::RCP< Tempus::IntegratorPseudoTransientAdjointSensitivity< Scalar > > integratorPseudoTransientAdjointSensitivity(Teuchos::RCP< Teuchos::ParameterList > pList, const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model)
Non-member constructor.
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.
Teuchos::RCP< AdjointSensitivityModelEvaluator< Scalar > > createSensitivityModel(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model, const Teuchos::RCP< Teuchos::ParameterList > &inputPL)
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.
virtual Scalar getIndex() const override
Get current index.
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList() override
virtual Teuchos::RCP< Teuchos::ParameterList > getTempusParameterList() override
Return a copy of the Tempus ParameterList.
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.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...