9 #ifndef Tempus_IntegratorPseudoTransientForwardSensitivity_impl_hpp
10 #define Tempus_IntegratorPseudoTransientForwardSensitivity_impl_hpp
13 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
14 #include "Thyra_DefaultMultiVectorProductVector.hpp"
15 #include "Thyra_VectorStdOps.hpp"
16 #include "Thyra_MultiVectorStdOps.hpp"
20 template<
class Scalar>
23 Teuchos::RCP<Teuchos::ParameterList> inputPL,
24 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model) :
33 template<
class Scalar>
36 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
37 std::string stepperType) :
39 force_W_update_(false)
47 template<
class Scalar>
51 force_W_update_(false)
57 template<
class Scalar>
63 using Thyra::VectorBase;
66 bool state_status = state_integrator_->advanceTime();
69 sens_model_->setForwardSolutionState(state_integrator_->getCurrentState());
73 state_integrator_->getStepper()->getSolver() != Teuchos::null) {
74 sens_model_->setSolver(state_integrator_->getStepper()->getSolver(),
79 bool sens_status = sens_integrator_->advanceTime();
81 buildSolutionHistory();
83 return state_status && sens_status;
86 template<
class Scalar>
92 using Thyra::VectorBase;
95 bool state_status = state_integrator_->advanceTime(timeFinal);
98 sens_model_->setForwardSolutionState(state_integrator_->getCurrentState());
102 state_integrator_->getStepper()->getSolver() != Teuchos::null) {
103 sens_model_->setSolver(state_integrator_->getStepper()->getSolver(),
108 bool sens_status = sens_integrator_->advanceTime(timeFinal);
110 buildSolutionHistory();
112 return state_status && sens_status;
115 template<
class Scalar>
120 return solutionHistory_->getCurrentTime();
123 template<
class Scalar>
128 return solutionHistory_->getCurrentIndex();
131 template<
class Scalar>
136 Status state_status = state_integrator_->getStatus();
137 Status sens_status = sens_integrator_->getStatus();
145 template<
class Scalar>
146 Teuchos::RCP<Stepper<Scalar> >
150 return state_integrator_->getStepper();
153 template<
class Scalar>
154 Teuchos::RCP<Teuchos::ParameterList>
158 return state_integrator_->getTempusParameterList();
161 template<
class Scalar>
166 state_integrator_->setTempusParameterList(pl);
167 sens_integrator_->setTempusParameterList(pl);
170 template<
class Scalar>
171 Teuchos::RCP<const SolutionHistory<Scalar> >
175 return solutionHistory_;
178 template<
class Scalar>
179 Teuchos::RCP<const TimeStepControl<Scalar> >
183 return state_integrator_->getTimeStepControl();
186 template<
class Scalar>
189 Teuchos::RCP<
const Thyra::VectorBase<Scalar> > x0,
190 Teuchos::RCP<
const Thyra::VectorBase<Scalar> > xdot0,
191 Teuchos::RCP<
const Thyra::VectorBase<Scalar> > xdotdot0,
192 Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > DxDp0,
193 Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > DxdotDp0,
194 Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > DxdotdotDp0)
197 using Teuchos::rcp_dynamic_cast;
198 using Thyra::VectorSpaceBase;
200 using Thyra::createMember;
201 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
206 RCP< const VectorSpaceBase<Scalar> > space = sens_model_->get_x_space();
207 RCP<DMVPV> X = rcp_dynamic_cast<DMVPV>(createMember(space));
208 RCP<DMVPV> Xdot = rcp_dynamic_cast<DMVPV>(createMember(space));
209 RCP<DMVPV> Xdotdot = rcp_dynamic_cast<DMVPV>(createMember(space));
210 const Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
213 if (DxDp0 == Teuchos::null)
214 assign(X->getNonconstMultiVector().ptr(), zero);
216 assign(X->getNonconstMultiVector().ptr(), *DxDp0);
219 if (DxdotDp0 == Teuchos::null)
220 assign(Xdot->getNonconstMultiVector().ptr(), zero);
222 assign(Xdot->getNonconstMultiVector().ptr(), *DxdotDp0);
225 if (DxdotDp0 == Teuchos::null)
226 assign(Xdotdot->getNonconstMultiVector().ptr(), zero);
228 assign(Xdotdot->getNonconstMultiVector().ptr(), *DxdotdotDp0);
230 state_integrator_->initializeSolutionHistory(t0, x0, xdot0, xdotdot0);
231 sens_integrator_->initializeSolutionHistory(t0, X, Xdot, Xdotdot);
234 template<
class Scalar>
235 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
240 using Teuchos::rcp_dynamic_cast;
241 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
244 rcp_dynamic_cast<
const DMVPV>(solutionHistory_->getCurrentState()->getX());
245 return X->getMultiVector()->col(0);
248 template<
class Scalar>
249 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
254 using Teuchos::rcp_dynamic_cast;
255 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
258 rcp_dynamic_cast<
const DMVPV>(solutionHistory_->getCurrentState()->getX());
259 const int num_param = X->getMultiVector()->domain()->dim()-1;
260 const Teuchos::Range1D rng(1,num_param);
261 return X->getMultiVector()->subView(rng);
264 template<
class Scalar>
265 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
270 using Teuchos::rcp_dynamic_cast;
271 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
273 RCP<const DMVPV> Xdot =
274 rcp_dynamic_cast<
const DMVPV>(solutionHistory_->getCurrentState()->getXDot());
275 return Xdot->getMultiVector()->col(0);
278 template<
class Scalar>
279 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
284 using Teuchos::rcp_dynamic_cast;
285 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
287 RCP<const DMVPV> Xdot =
288 rcp_dynamic_cast<
const DMVPV>(solutionHistory_->getCurrentState()->getXDot());
289 const int num_param = Xdot->getMultiVector()->domain()->dim()-1;
290 const Teuchos::Range1D rng(1,num_param);
291 return Xdot->getMultiVector()->subView(rng);
294 template<
class Scalar>
295 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
300 using Teuchos::rcp_dynamic_cast;
301 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
303 RCP<const DMVPV> Xdotdot =
304 rcp_dynamic_cast<
const DMVPV>(solutionHistory_->getCurrentState()->getXDotDot());
305 return Xdotdot->getMultiVector()->col(0);
308 template<
class Scalar>
309 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
314 using Teuchos::rcp_dynamic_cast;
315 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
317 RCP<const DMVPV> Xdotdot =
318 rcp_dynamic_cast<
const DMVPV>(solutionHistory_->getCurrentState()->getXDotDot());
319 const int num_param = Xdotdot->getMultiVector()->domain()->dim()-1;
320 const Teuchos::Range1D rng(1,num_param);
321 return Xdotdot->getMultiVector()->subView(rng);
324 template<
class Scalar>
329 std::string name =
"Tempus::IntegratorPseudoTransientForwardSensitivity";
333 template<
class Scalar>
337 Teuchos::FancyOStream &out,
338 const Teuchos::EVerbosityLevel verbLevel)
const
340 out << description() <<
"::describe" << std::endl;
341 state_integrator_->describe(out, verbLevel);
342 sens_integrator_->describe(out, verbLevel);
345 template<
class Scalar>
350 state_integrator_->setParameterList(inputPL);
351 sens_integrator_->setParameterList(inputPL);
353 inputPL->sublist(
"Sensitivities").get(
"Reuse State Linear Solver",
false);
355 inputPL->sublist(
"Sensitivities").get(
"Force W Update",
false);
358 template<
class Scalar>
359 Teuchos::RCP<Teuchos::ParameterList>
363 state_integrator_->unsetParameterList();
364 return sens_integrator_->unsetParameterList();
367 template<
class Scalar>
368 Teuchos::RCP<const Teuchos::ParameterList>
372 Teuchos::RCP<Teuchos::ParameterList> pl =
373 Teuchos::rcp(
new Teuchos::ParameterList);
374 Teuchos::RCP<const Teuchos::ParameterList> integrator_pl =
375 state_integrator_->getValidParameters();
376 Teuchos::RCP<const Teuchos::ParameterList> sensitivity_pl =
378 pl->setParameters(*integrator_pl);
379 pl->sublist(
"Sensitivities").setParameters(*sensitivity_pl);
380 pl->sublist(
"Sensitivities").set(
"Reuse State Linear Solver",
false);
381 pl->sublist(
"Sensitivities").set(
"Force W Update",
false);
386 template<
class Scalar>
387 Teuchos::RCP<Teuchos::ParameterList>
391 return state_integrator_->getNonconstParameterList();
394 template <
class Scalar>
395 Teuchos::RCP<SensitivityModelEvaluatorBase<Scalar> >
398 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
399 const Teuchos::RCP<Teuchos::ParameterList>& inputPL)
403 Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
404 if (inputPL != Teuchos::null) {
405 *pl = inputPL->sublist(
"Sensitivities");
407 reuse_solver_ = pl->get(
"Reuse State Linear Solver",
false);
408 force_W_update_ = pl->get(
"Force W Update",
true);
409 pl->remove(
"Reuse State Linear Solver");
410 pl->remove(
"Force W Update");
414 template<
class Scalar>
421 using Teuchos::rcp_dynamic_cast;
422 using Teuchos::ParameterList;
423 using Thyra::VectorBase;
424 using Thyra::MultiVectorBase;
425 using Thyra::VectorSpaceBase;
426 using Thyra::createMembers;
427 using Thyra::multiVectorProductVector;
429 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
433 RCP<ParameterList> shPL =
434 Teuchos::sublist(state_integrator_->getIntegratorParameterList(),
435 "Solution History",
true);
438 const int num_param =
439 rcp_dynamic_cast<
const DMVPV>(sens_integrator_->getX())->getMultiVector()->domain()->dim();
440 RCP<const VectorSpaceBase<Scalar> > x_space = model_->get_x_space();
441 RCP<const Thyra::DefaultMultiVectorProductVectorSpace<Scalar> > prod_space =
442 Thyra::multiVectorProductVectorSpace(x_space, num_param+1);
443 const Teuchos::Range1D rng(1,num_param);
444 const Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
446 RCP<const SolutionHistory<Scalar> > state_solution_history =
447 state_integrator_->getSolutionHistory();
448 int num_states = state_solution_history->getNumStates();
449 for (
int i=0; i<num_states; ++i) {
450 RCP<const SolutionState<Scalar> > state = (*state_solution_history)[i];
453 RCP< MultiVectorBase<Scalar> > x_mv =
454 createMembers(x_space, num_param+1);
455 assign(x_mv->col(0).ptr(), *(state->getX()));
456 assign(x_mv->subView(rng).ptr(), zero);
457 RCP<VectorBase<Scalar> > x = multiVectorProductVector(prod_space, x_mv);
460 RCP<VectorBase<Scalar> > x_dot;
461 if (state->getXDot() != Teuchos::null) {
462 RCP< MultiVectorBase<Scalar> > x_dot_mv =
463 createMembers(x_space, num_param+1);
464 assign(x_dot_mv->col(0).ptr(), *(state->getXDot()));
465 assign(x_dot_mv->subView(rng).ptr(), zero);
466 x_dot = multiVectorProductVector(prod_space, x_dot_mv);
470 RCP<VectorBase<Scalar> > x_dot_dot;
471 if (state->getXDotDot() != Teuchos::null) {
472 RCP< MultiVectorBase<Scalar> > x_dot_dot_mv =
473 createMembers(x_space, num_param+1);
474 assign(x_dot_dot_mv->col(0).ptr(), *(state->getXDotDot()));
475 assign(x_dot_dot_mv->subView(rng).ptr(), zero);
476 x_dot_dot = multiVectorProductVector(prod_space, x_dot_dot_mv);
479 RCP<SolutionState<Scalar> > prod_state =
482 state->getStepperState()->clone()));
483 solutionHistory_->addState(prod_state);
486 RCP<const VectorBase<Scalar> > frozen_x =
487 state_solution_history->getCurrentState()->getX();
488 RCP<const VectorBase<Scalar> > frozen_x_dot =
489 state_solution_history->getCurrentState()->getXDot();
490 RCP<const VectorBase<Scalar> > frozen_x_dot_dot =
491 state_solution_history->getCurrentState()->getXDotDot();
492 RCP<const SolutionHistory<Scalar> > sens_solution_history =
493 sens_integrator_->getSolutionHistory();
494 num_states = sens_solution_history->getNumStates();
495 for (
int i=0; i<num_states; ++i) {
496 RCP<const SolutionState<Scalar> > state = (*sens_solution_history)[i];
499 RCP< MultiVectorBase<Scalar> > x_mv =
500 createMembers(x_space, num_param+1);
501 RCP<const MultiVectorBase<Scalar> > dxdp =
502 rcp_dynamic_cast<
const DMVPV>(state->getX())->getMultiVector();
503 assign(x_mv->col(0).ptr(), *(frozen_x));
504 assign(x_mv->subView(rng).ptr(), *dxdp);
505 RCP<VectorBase<Scalar> > x = multiVectorProductVector(prod_space, x_mv);
508 RCP<VectorBase<Scalar> > x_dot;
509 if (state->getXDot() != Teuchos::null) {
510 RCP< MultiVectorBase<Scalar> > x_dot_mv =
511 createMembers(x_space, num_param+1);
512 RCP<const MultiVectorBase<Scalar> > dxdotdp =
513 rcp_dynamic_cast<
const DMVPV>(state->getXDot())->getMultiVector();
514 assign(x_dot_mv->col(0).ptr(), *(frozen_x_dot));
515 assign(x_dot_mv->subView(rng).ptr(), *dxdotdp);
516 x_dot = multiVectorProductVector(prod_space, x_dot_mv);
520 RCP<VectorBase<Scalar> > x_dot_dot;
521 if (state->getXDotDot() != Teuchos::null) {
522 RCP< MultiVectorBase<Scalar> > x_dot_dot_mv =
523 createMembers(x_space, num_param+1);
524 RCP<const MultiVectorBase<Scalar> > dxdotdotdp =
525 rcp_dynamic_cast<
const DMVPV>(state->getXDotDot())->getMultiVector();
526 assign(x_dot_dot_mv->col(0).ptr(), *(frozen_x_dot_dot));
527 assign(x_dot_dot_mv->subView(rng).ptr(), *dxdotdotdp);
528 x_dot_dot = multiVectorProductVector(prod_space, x_dot_dot_mv);
531 RCP<SolutionState<Scalar> > prod_state =
534 state->getStepperState()->clone()));
535 solutionHistory_->addState(prod_state);
540 template<
class Scalar>
541 Teuchos::RCP<Tempus::IntegratorPseudoTransientForwardSensitivity<Scalar> >
543 Teuchos::RCP<Teuchos::ParameterList> pList,
544 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model)
546 Teuchos::RCP<Tempus::IntegratorPseudoTransientForwardSensitivity<Scalar> > integrator =
552 template<
class Scalar>
553 Teuchos::RCP<Tempus::IntegratorPseudoTransientForwardSensitivity<Scalar> >
555 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
556 std::string stepperType)
558 Teuchos::RCP<Tempus::IntegratorPseudoTransientForwardSensitivity<Scalar> > integrator =
564 template<
class Scalar>
565 Teuchos::RCP<Tempus::IntegratorPseudoTransientForwardSensitivity<Scalar> >
568 Teuchos::RCP<Tempus::IntegratorPseudoTransientForwardSensitivity<Scalar> > integrator =
574 #endif // Tempus_IntegratorPseudoTransientForwardSensitivity_impl_hpp
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDxdotDp() const
virtual Teuchos::RCP< Stepper< Scalar > > getStepper() const override
Get the Stepper.
virtual Status getStatus() const override
Get Status.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl) override
virtual Teuchos::RCP< const SolutionHistory< Scalar > > getSolutionHistory() const override
Get the SolutionHistory.
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDxDp() const
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDxdotdotDp() const
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList() override
Teuchos::RCP< SensitivityModelEvaluatorBase< Scalar > > wrapStaggeredFSAModelEvaluator(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, const Teuchos::RCP< const Teuchos::ParameterList > &pList=Teuchos::null)
static Teuchos::RCP< const Teuchos::ParameterList > getValidParameters()
Teuchos::RCP< Tempus::IntegratorPseudoTransientForwardSensitivity< Scalar > > integratorPseudoTransientForwardSensitivity(Teuchos::RCP< Teuchos::ParameterList > pList, const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model)
Non-member constructor.
Teuchos::RCP< IntegratorBasic< Scalar > > state_integrator_
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 > > DxDp0=Teuchos::null, Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > DxdotDp0=Teuchos::null, Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > DxdotdotDp0=Teuchos::null)
Set the initial state from Thyra::VectorBase(s)
virtual bool advanceTime()
Advance the solution to timeMax, and return true if successful.
Status
Status for the Integrator, the Stepper and the SolutionState.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
std::string description() const override
virtual Teuchos::RCP< Teuchos::ParameterList > getTempusParameterList() override
Return a copy of the Tempus ParameterList.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Teuchos::RCP< SensitivityModelEvaluatorBase< Scalar > > sens_model_
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXdot() const
Get current the time derivative of the solution, xdot.
virtual Scalar getIndex() const override
Get current index.
virtual Scalar getTime() const override
Get current time.
Teuchos::RCP< SensitivityModelEvaluatorBase< Scalar > > createSensitivityModel(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model, const Teuchos::RCP< Teuchos::ParameterList > &inputPL)
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXdotdot() const
Get current the second time derivative of the solution, xdotdot.
IntegratorPseudoTransientForwardSensitivity()
Destructor.
Time integrator suitable for pseudotransient forward sensitivity analysis.
virtual void setTempusParameterList(Teuchos::RCP< Teuchos::ParameterList > pl) override
void buildSolutionHistory()
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList() override
virtual Teuchos::RCP< const TimeStepControl< Scalar > > getTimeStepControl() const override
Get the TimeStepControl.
Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > model_
Teuchos::RCP< IntegratorBasic< Scalar > > sens_integrator_
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getX() const
Get current the solution, x.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...