10#ifndef Tempus_IntegratorAdjointSensitivity_impl_hpp
11#define Tempus_IntegratorAdjointSensitivity_impl_hpp
16#include "Teuchos_ParameterList.hpp"
17#include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
18#include "Thyra_DefaultMultiVectorProductVector.hpp"
19#include "Thyra_DefaultProductVectorSpace.hpp"
20#include "Thyra_DefaultProductVector.hpp"
21#include "Thyra_VectorStdOps.hpp"
22#include "Thyra_MultiVectorStdOps.hpp"
24#include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
30template <
class Scalar>
39 const int p_index,
const int g_index,
const bool g_depends_on_p,
40 const bool f_depends_on_p,
const bool ic_depends_on_p,
42 const std::vector<Scalar>& response_times,
44 const Teuchos::RCP<const Teuchos::ParameterList>& dae_jump_solver_pl)
63 TEUCHOS_TEST_FOR_EXCEPTION(
67 "Error - IntegratorAdjointSensitivity(): the \"Sum Over Times\" "
68 "response requires a non-empty \"Response Time List\".\n");
69 TEUCHOS_TEST_FOR_EXCEPTION(
72 "Error - IntegratorAdjointSensitivity(): \""
74 <<
"\" cannot be used with \"Mass Matrix Is Identity\" = true.\n");
77 TEUCHOS_TEST_FOR_EXCEPTION(
79 "Error - IntegratorAdjointSensitivity(): Cannot use FSAL with\n"
80 " IntegratorAdjointSensitivity, because the state and adjoint\n"
81 " integrators require ModelEvaluator evaluation in the\n"
82 " constructor to make the initial conditions consistent.\n"
83 " For the adjoint integrator, this requires special construction\n"
84 " which has not been implemented yet.\n");
87template <
class Scalar>
96template <
class Scalar>
103template <
class Scalar>
106 TEMPUS_FUNC_TIME_MONITOR_DIFF(
107 "Tempus::IntegratorAdjointSensitivity::advanceTime()", TEMPUS_AS_AT);
110 using Teuchos::rcp_dynamic_cast;
112 using Thyra::createMember;
113 using Thyra::createMembers;
121 using Thyra::VectorSpaceBase;
122 typedef Thyra::ModelEvaluatorBase MEB;
123 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
124 typedef Thyra::DefaultProductVector<Scalar> DPV;
127 RCP<const SolutionHistory<Scalar>> state_solution_history =
129 RCP<const SolutionState<Scalar>> initial_state = (*state_solution_history)[0];
132 bool state_status =
true;
134 TEMPUS_FUNC_TIME_MONITOR_DIFF(
135 "Tempus::IntegratorAdjointSensitivity::advanceTime::state",
143 dgdp_ = Teuchos::null;
156 RCP<const VectorSpaceBase<Scalar>> g_space =
model_->get_g_space(
g_index_);
157 RCP<const VectorSpaceBase<Scalar>> x_space =
model_->get_x_space();
158 RCP<const VectorSpaceBase<Scalar>> p_space =
model_->get_p_space(
p_index_);
159 const int num_g = g_space->dim();
160 MEB::InArgs<Scalar> inargs =
model_->getNominalValues();
161 MEB::OutArgs<Scalar> adj_outargs =
adjoint_model_->createOutArgs();
167 const Scalar time_tol =
168 Scalar(1.0e-9) * std::max(std::abs(t_final - t_init), std::abs(t_final) + Scalar(1.0e-6));
175 std::vector<Scalar> jump_times;
177 jump_times.push_back(t_final);
179 TEUCHOS_TEST_FOR_EXCEPTION(
182 "Error - IntegratorAdjointSensitivity::advanceTime(): the response "
185 <<
"] must be in the time interval [" << t_init <<
", " << t_final
193 RCP<const SolutionState<Scalar>> final_state = state_solution_history->getCurrentState();
194 MEB::InArgs<Scalar> check_inargs =
model_->getNominalValues();
195 check_inargs.set_t(final_state->getTime());
196 check_inargs.set_x(final_state->getX());
197 if (check_inargs.supports(MEB::IN_ARG_x_dot))
198 check_inargs.set_x_dot(final_state->getXDot());
199 dae_structure_->checkMassMatrix(*
model_, check_inargs,
"Tempus::IntegratorAdjointSensitivity::advanceTime");
203 RCP<DPV> adjoint_state = rcp_dynamic_cast<DPV>(Thyra::createMember(
adjoint_aux_model_->get_x_space()));
204 assign(Teuchos::ptr_implicit_cast<VectorBase<Scalar>>(adjoint_state.ptr()), Teuchos::ScalarTraits<Scalar>::zero());
205 RCP<MultiVectorBase<Scalar>> adjoint_y_mv =
206 rcp_dynamic_cast<DMVPV>(adjoint_state->getNonconstVectorBlock(0))->getNonconstMultiVector();
209 dgdp_ = createMembers(p_space, num_g);
210 assign(
dgdp_.ptr(), Scalar(0.0));
212 RCP<MultiVectorBase<Scalar>> dgdx = createMembers(x_space, num_g);
213 RCP<MultiVectorBase<Scalar>> dgdp_k;
214 RCP<MultiVectorBase<Scalar>> jump;
215 RCP<MultiVectorBase<Scalar>> dae_jump;
216 RCP<MultiVectorBase<Scalar>> algebraic_jump;
217 RCP<LinearOpWithSolveBase<Scalar>> W;
220 const bool restart_at_jumps =
223 bool sens_status =
true;
225 TEMPUS_FUNC_TIME_MONITOR_DIFF(
226 "Tempus::IntegratorAdjointSensitivity::advanceTime::adjoint",
229 const Scalar tau_init =
231 Scalar tau = tau_init;
232 int num_segments = 0;
233 int adjoint_index = -1;
234 for (std::size_t k = 0; sens_status && k < jump_times.size(); ++k) {
235 const Scalar t_k = jump_times[k];
236 const Scalar tau_k = t_final + t_init - t_k;
237 if (tau_k > tau + time_tol) {
238 if (restart_at_jumps && num_segments > 0)
244 if (!sens_status)
break;
248 RCP<const SolutionState<Scalar>> state;
250 state = state_solution_history->getCurrentState();
256 inargs.set_x(state->getX());
257 if (inargs.supports(MEB::IN_ARG_x_dot)) inargs.set_x_dot(state->getXDot());
266 "Tempus::IntegratorAdjointSensitivity::advanceTime");
268 Thyra::update(Scalar(1.0), *dgdx, adjoint_y_mv.ptr());
273 if (jump == Teuchos::null) jump = createMembers(x_space, num_g);
276 assign(jump.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
277 W->solve(Thyra::NOTRANS, *dgdx, jump.ptr());
278 Thyra::update(Scalar(1.0), *jump, adjoint_y_mv.ptr());
283 if (dae_jump == Teuchos::null)
284 dae_jump = createMembers(
model_->get_f_space(), num_g);
291 if (algebraic_jump == Teuchos::null)
292 algebraic_jump = createMembers(
model_->get_f_space(), num_g);
293 assign(algebraic_jump.ptr(), *dae_jump);
302 Thyra::update(Scalar(1.0), *dae_jump, adjoint_y_mv.ptr());
307 if (dgdp_k == Teuchos::null) dgdp_k = createMembers(p_space, num_g);
309 Thyra::update(Scalar(1.0), *dgdp_k,
dgdp_.ptr());
313 if (num_segments > 0)
320 if (sens_status && (num_segments == 0 || tau < timeFinal - time_tol)) {
321 if (restart_at_jumps && num_segments > 0)
327 if (restart_at_jumps && num_segments > 0)
335 RCP<const MultiVectorBase<Scalar>> adjoint_mv = adjoint_y_mv;
337 dxdp_init_->apply(Thyra::CONJTRANS, *adjoint_mv,
dgdp_.ptr(), Scalar(1.0),
340 inargs.set_t(initial_state->getTime());
341 inargs.set_x(initial_state->getX());
342 if (inargs.supports(MEB::IN_ARG_x_dot))
343 inargs.set_x_dot(initial_state->getXDot());
344 inargs.set_alpha(1.0);
345 inargs.set_beta(0.0);
347 adj_outargs.set_W_op(W_op);
349 adj_outargs.set_W_op(Teuchos::null);
350 RCP<MultiVectorBase<Scalar>> tmp = createMembers(x_space, num_g);
351 W_op->apply(Thyra::NOTRANS, *adjoint_mv, tmp.ptr(), Scalar(1.0),
363 RCP<const MultiVectorBase<Scalar>> z_mv =
364 rcp_dynamic_cast<const DMVPV>(adjoint_state->getVectorBlock(1))
371 return state_status && sens_status;
374template <
class Scalar>
375Teuchos::RCP<Thyra::LinearOpWithSolveBase<Scalar>>
377 const Thyra::ModelEvaluatorBase::InArgs<Scalar>& inArgs)
const
383template <
class Scalar>
384Teuchos::RCP<const SolutionState<Scalar>>
388 Teuchos::RCP<const SolutionState<Scalar>> closest;
389 for (
int i = 0; i < state_solution_history.
getNumStates(); ++i) {
390 Teuchos::RCP<const SolutionState<Scalar>> state = state_solution_history[i];
391 if (closest == Teuchos::null || std::abs(state->getTime() - t) < std::abs(closest->getTime() - t))
394 TEUCHOS_TEST_FOR_EXCEPTION(
395 closest == Teuchos::null || std::abs(closest->getTime() - t) > tol,
397 "Error - IntegratorAdjointSensitivity: no stored time step of the "
398 "forward integration ends at the response time "
399 << t <<
" (closest stored time = "
400 << (closest == Teuchos::null ? t : closest->getTime())
402 " With \"Step Type\" = \"Variable\", the time steps land on the "
403 "response times. With \"Step Type\" = \"Constant\", the response "
404 "times must be on the time grid. The forward solution history must "
405 "store all time steps (\"Storage Type\" = \"Unlimited\").\n");
409template <
class Scalar>
411 const Scalar tau_begin,
const Scalar tau_end,
420 Teuchos::RCP<TimeStepControl<Scalar>> tsc =
adjoint_integrator_->getNonConstTimeStepControl();
421 if (tau_end > tsc->getFinalTime()) tsc->setFinalTime(tau_end);
428template <
class Scalar>
432 Teuchos::RCP<const SolutionHistory<Scalar>> sh =
adjoint_integrator_->getSolutionHistory();
438 for (
int i = 0; i < sh->getNumStates(); ++i) {
439 Teuchos::RCP<const SolutionState<Scalar>> state = (*sh)[i];
448template <
class Scalar>
457template <
class Scalar>
465template <
class Scalar>
475template <
class Scalar>
482template <
class Scalar>
489template <
class Scalar>
490Teuchos::RCP<const SolutionHistory<Scalar>>
496template <
class Scalar>
497Teuchos::RCP<const SolutionHistory<Scalar>>
503template <
class Scalar>
504Teuchos::RCP<const SolutionHistory<Scalar>>
515template <
class Scalar>
516Teuchos::RCP<SolutionHistory<Scalar>>
522template <
class Scalar>
523Teuchos::RCP<const TimeStepControl<Scalar>>
529template <
class Scalar>
530Teuchos::RCP<TimeStepControl<Scalar>>
536template <
class Scalar>
537Teuchos::RCP<TimeStepControl<Scalar>>
543template <
class Scalar>
544Teuchos::RCP<TimeStepControl<Scalar>>
550template <
class Scalar>
563template <
class Scalar>
564Teuchos::RCP<IntegratorObserver<Scalar>>
570template <
class Scalar>
580template <
class Scalar>
587template <
class Scalar>
588Teuchos::RCP<const Thyra::VectorBase<Scalar>>
594template <
class Scalar>
595Teuchos::RCP<const Thyra::VectorBase<Scalar>>
601template <
class Scalar>
602Teuchos::RCP<const Thyra::VectorBase<Scalar>>
608template <
class Scalar>
609Teuchos::RCP<const Thyra::MultiVectorBase<Scalar>>
613 using Teuchos::rcp_dynamic_cast;
614 typedef Thyra::DefaultProductVector<Scalar> DPV;
615 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
617 RCP<const DMVPV> mvpv = rcp_dynamic_cast<const DMVPV>(pv->getVectorBlock(0));
618 return mvpv->getMultiVector();
621template <
class Scalar>
622Teuchos::RCP<const Thyra::MultiVectorBase<Scalar>>
626 using Teuchos::rcp_dynamic_cast;
627 typedef Thyra::DefaultProductVector<Scalar> DPV;
628 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
631 RCP<const DMVPV> mvpv = rcp_dynamic_cast<const DMVPV>(pv->getVectorBlock(0));
632 return mvpv->getMultiVector();
635template <
class Scalar>
636Teuchos::RCP<const Thyra::MultiVectorBase<Scalar>>
640 using Teuchos::rcp_dynamic_cast;
641 typedef Thyra::DefaultProductVector<Scalar> DPV;
642 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
645 RCP<const DMVPV> mvpv = rcp_dynamic_cast<const DMVPV>(pv->getVectorBlock(0));
646 return mvpv->getMultiVector();
649template <
class Scalar>
650Teuchos::RCP<const Thyra::MultiVectorBase<Scalar>>
656template <
class Scalar>
659 std::string name =
"Tempus::IntegratorAdjointSensitivity";
663template <
class Scalar>
665 Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel)
const
667 auto l_out = Teuchos::fancyOStream(out.getOStream());
668 Teuchos::OSTab ostab(*l_out, 2, this->
description());
669 l_out->setOutputToRootOnly(0);
671 *l_out <<
description() <<
"::describe" << std::endl;
676template <
class Scalar>
682template <
class Scalar>
683Teuchos::RCP<AdjointAuxSensitivityModelEvaluator<Scalar>>
687 const Teuchos::RCP<Teuchos::ParameterList>& inputPL)
689 using Teuchos::ParameterList;
693 RCP<ParameterList> spl = Teuchos::parameterList();
694 if (inputPL != Teuchos::null) {
695 *spl = inputPL->sublist(
"Sensitivities");
697 if (spl->isParameter(
"IC Depends on Parameters"))
698 spl->remove(
"IC Depends on Parameters");
705 model, adjoint_model, tinit, tfinal, spl));
708template <
class Scalar>
713 using Teuchos::ParameterList;
716 using Teuchos::rcp_dynamic_cast;
718 using Thyra::createMembers;
720 using Thyra::multiVectorProductVector;
722 using Thyra::VectorSpaceBase;
723 typedef Thyra::DefaultProductVectorSpace<Scalar> DPVS;
724 typedef Thyra::DefaultProductVector<Scalar> DPV;
726 RCP<const VectorSpaceBase<Scalar>> x_space =
model_->get_x_space();
727 RCP<const VectorSpaceBase<Scalar>> adjoint_space =
730 Teuchos::Array<RCP<const VectorSpaceBase<Scalar>>> spaces(2);
732 spaces[1] = adjoint_space;
733 RCP<const DPVS> prod_space = Thyra::productVectorSpace(spaces());
735 int num_states = state_solution_history->getNumStates();
738 const Scalar time_tol =
739 Scalar(1.0e-9) * std::max(std::abs(t_final - t_init), std::abs(t_final) + Scalar(1.0e-6));
740 for (
int i = 0; i < num_states; ++i) {
741 RCP<const SolutionState<Scalar>> forward_state =
742 (*state_solution_history)[i];
746 const Scalar adjoint_time = t_final + t_init - forward_state->getTime();
747 RCP<const SolutionState<Scalar>> adjoint_state;
750 int lo = 0, hi = adjoint_solution_history->getNumStates();
752 const int mid = (lo + hi) / 2;
753 if ((*adjoint_solution_history)[mid]->
getTime() <
754 adjoint_time - time_tol)
759 if (lo < adjoint_solution_history->getNumStates() &&
760 std::abs((*adjoint_solution_history)[lo]->
getTime() -
761 adjoint_time) <= time_tol)
762 adjoint_state = (*adjoint_solution_history)[lo];
764 if (adjoint_state == Teuchos::null)
765 adjoint_state = adjoint_solution_history->interpolateState(adjoint_time);
768 RCP<DPV> x = Thyra::defaultProductVector(prod_space);
769 RCP<const VectorBase<Scalar>> adjoint_x =
770 rcp_dynamic_cast<const DPV>(adjoint_state->getX())->getVectorBlock(0);
771 assign(x->getNonconstVectorBlock(0).ptr(), *(forward_state->getX()));
772 assign(x->getNonconstVectorBlock(1).ptr(), *(adjoint_x));
773 RCP<VectorBase<Scalar>> x_b = x;
776 RCP<DPV> x_dot = Thyra::defaultProductVector(prod_space);
777 RCP<const VectorBase<Scalar>> adjoint_x_dot =
778 rcp_dynamic_cast<const DPV>(adjoint_state->getXDot())
780 assign(x_dot->getNonconstVectorBlock(0).ptr(), *(forward_state->getXDot()));
781 assign(x_dot->getNonconstVectorBlock(1).ptr(), *(adjoint_x_dot));
782 RCP<VectorBase<Scalar>> x_dot_b = x_dot;
786 if (forward_state->getXDotDot() != Teuchos::null) {
787 x_dot_dot = Thyra::defaultProductVector(prod_space);
788 RCP<const VectorBase<Scalar>> adjoint_x_dot_dot =
789 rcp_dynamic_cast<const DPV>(adjoint_state->getXDotDot())
791 assign(x_dot_dot->getNonconstVectorBlock(0).ptr(),
792 *(forward_state->getXDotDot()));
793 assign(x_dot_dot->getNonconstVectorBlock(1).ptr(), *(adjoint_x_dot_dot));
795 RCP<VectorBase<Scalar>> x_dot_dot_b = x_dot_dot;
797 RCP<SolutionState<Scalar>> prod_state = forward_state->clone();
798 prod_state->setX(x_b);
799 prod_state->setXDot(x_dot_b);
800 prod_state->setXDotDot(x_dot_dot_b);
801 prod_state->setPhysicsState(Teuchos::null);
807template <
class Scalar>
808Teuchos::RCP<IntegratorAdjointSensitivity<Scalar>>
810 Teuchos::RCP<Teuchos::ParameterList> inputPL,
815 Teuchos::RCP<Teuchos::ParameterList> spl = Teuchos::parameterList();
816 if (inputPL != Teuchos::null) *spl = inputPL->sublist(
"Sensitivities");
818 int p_index = spl->get<
int>(
"Sensitivity Parameter Index", 0);
819 int g_index = spl->get<
int>(
"Response Function Index", 0);
820 bool g_depends_on_p = spl->get<
bool>(
"Response Depends on Parameters",
true);
821 bool f_depends_on_p = spl->get<
bool>(
"Residual Depends on Parameters",
true);
822 bool ic_depends_on_p = spl->get<
bool>(
"IC Depends on Parameters",
true);
823 bool mass_matrix_is_identity =
824 spl->get<
bool>(
"Mass Matrix Is Identity",
false);
826 Teuchos::RCP<const Teuchos::ParameterList> dae_jump_solver_pl;
831 spl->get<std::string>(
"Response Type",
"Final Time"));
832 const std::vector<Scalar> response_times =
834 spl->get<std::string>(
"Response Time List",
""));
835 TEUCHOS_TEST_FOR_EXCEPTION(
837 response_times.empty(),
839 "Error - createIntegratorAdjointSensitivity(): the \"Sum Over Times\" "
840 "response requires a non-empty \"Response Time List\".\n");
847 *state_integrator->getNonConstTimeStepControl(), response_times);
850 if (spl->isParameter(
"IC Depends on Parameters"))
851 spl->remove(
"IC Depends on Parameters");
856 const Scalar tinit = state_integrator->getTimeStepControl()->getInitTime();
857 const Scalar tfinal = state_integrator->getTimeStepControl()->getFinalTime();
862 Teuchos::RCP<Thyra::ModelEvaluator<Scalar>> adjt_model = adjoint_model;
863 if (adjoint_model == Teuchos::null)
866 auto adjoint_aux_model =
868 model, adjt_model, tinit, tfinal, spl));
872 auto integrator_name = inputPL->get<std::string>(
"Integrator Name");
873 auto integratorPL = Teuchos::sublist(inputPL, integrator_name,
true);
874 auto shPL = Teuchos::sublist(integratorPL,
"Solution History",
true);
881 auto adjointPL = Teuchos::rcp(
new Teuchos::ParameterList(*inputPL));
883 auto adjoint_integrator =
886 Teuchos::RCP<IntegratorAdjointSensitivity<Scalar>> integrator =
888 model, state_integrator, adjt_model, adjoint_aux_model,
889 adjoint_integrator, combined_solution_History, p_index, g_index,
890 g_depends_on_p, f_depends_on_p, ic_depends_on_p,
891 mass_matrix_is_identity, response_type, response_times,
892 dae_structure, dae_jump_solver_pl));
898template <
class Scalar>
899Teuchos::RCP<IntegratorAdjointSensitivity<Scalar>>
902 Teuchos::RCP<IntegratorAdjointSensitivity<Scalar>> integrator =
ModelEvaluator for forming adjoint sensitivity equations.
Solver for the adjoint jumps of an index-1 DAE.
static const std::string & sublistName()
Name of the "Sensitivities" sublist with the options of this solver.
Structure of an index-1 differential-algebraic system.
static const std::string & algebraicMaskName()
Name of the parameter giving the mask of the algebraic equations.
Time integrator suitable for adjoint sensitivity analysis.
Teuchos::RCP< const SolutionHistory< Scalar > > getSensSolutionHistory() const
virtual Teuchos::RCP< SolutionHistory< Scalar > > getNonConstSolutionHistory() override
Get the SolutionHistory.
AdjointResponseType response_type_
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getYDot() const
Get the current time derivative of the adjoint solution, ydot.
virtual void setObserver(Teuchos::RCP< IntegratorObserver< Scalar > > obs=Teuchos::null)
Set the Observer.
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXDotDot() const
Get the current second time derivative of the solution, xdotdot.
virtual Scalar getTime() const override
Get current time.
virtual int getIndex() const override
Get current index.
virtual Status getStatus() const override
Get Status.
virtual Teuchos::RCP< const SolutionHistory< Scalar > > getSolutionHistory() const override
Get the SolutionHistory.
void appendAdjointSolutionHistory(const Scalar tol)
void buildSolutionHistory(const Teuchos::RCP< const SolutionHistory< Scalar > > &state_solution_history, const Teuchos::RCP< const SolutionHistory< Scalar > > &adjoint_solution_history)
Teuchos::RCP< TimeStepControl< Scalar > > getSensNonConstTimeStepControl()
bool mass_matrix_is_identity_
virtual void initialize()
Initializes the Integrator after set* function calls.
IntegratorAdjointSensitivity()
Constructor that requires a subsequent setParameterList, setStepper, and initialize calls.
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > createAdjointMassMatrixSolver(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs) const
Solver for df/dx_dot^T, computed with the adjoint model at inArgs.
std::string description() const override
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > dfdp_op_
df/dp work objects for the algebraic contributions of the jumps
std::vector< Scalar > response_times_
Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > model_
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getX() const
Get the current solution, x.
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getYDotDot() const
Get the current second time derivative of the adjoint solution, ydotdot.
Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > dxdp_init_
virtual bool advanceTime()
Advance the solution to timeMax, and return true if successful.
Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > adjoint_model_
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXDot() const
Get the current time derivative of the solution, xdot.
Teuchos::RCP< const AdjointDAEJumpSolver< Scalar > > dae_jump_solver_
Solver of the adjoint jumps of the index-1 DAE (null for an ODE).
virtual void setStatus(const Status st) override
Set Status.
Teuchos::RCP< const SolutionState< Scalar > > findForwardState(const SolutionHistory< Scalar > &state_solution_history, const Scalar t, const Scalar tol) const
Forward state at time t, which must be the time of a stored time step.
SensitivityStepMode getStepMode() const
What mode the current time integration step is in.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
virtual Teuchos::RCP< const TimeStepControl< Scalar > > getTimeStepControl() const override
Get the TimeStepControl.
virtual Teuchos::RCP< TimeStepControl< Scalar > > getNonConstTimeStepControl() override
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).
bool integrateAdjoint(const Scalar tau_begin, const Scalar tau_end, Thyra::VectorBase< Scalar > &adjoint_state, int &index)
virtual Teuchos::RCP< Stepper< Scalar > > getStepper() const override
Get the Stepper.
Teuchos::RCP< Thyra::MultiVectorBase< Scalar > > dgdp_
SensitivityStepMode stepMode_
Teuchos::RCP< const SolutionHistory< Scalar > > getStateSolutionHistory() const
Teuchos::RCP< IntegratorBasic< Scalar > > adjoint_integrator_
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDgDp() const
Return adjoint sensitivity stored in gradient format.
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getY() const
Get the current adjoint solution, y.
Teuchos::RCP< SolutionHistory< Scalar > > adjoint_solution_history_
virtual Teuchos::RCP< IntegratorObserver< Scalar > > getObserver()
Get the Observer.
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory_
Teuchos::RCP< IntegratorBasic< Scalar > > state_integrator_
Teuchos::RCP< TimeStepControl< Scalar > > getStateNonConstTimeStepControl()
Teuchos::RCP< AdjointAuxSensitivityModelEvaluator< Scalar > > createAdjointModel(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model, const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &adjoint_model, const Teuchos::RCP< Teuchos::ParameterList > &inputPL)
Teuchos::RCP< const DAEStructure< Scalar > > dae_structure_
Structure of the index-1 DAE (null for an ODE).
Teuchos::RCP< AdjointAuxSensitivityModelEvaluator< Scalar > > adjoint_aux_model_
Teuchos::RCP< Thyra::MultiVectorBase< Scalar > > dfdp_mv_
IntegratorObserver class for time integrators.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
int getNumStates() const
Get the number of states.
std::vector< Scalar > parseTimeList(const std::string &str)
void evalResponseGradientX(const Thyra::ModelEvaluator< Scalar > &model, const int g_index, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs, Thyra::MultiVectorBase< Scalar > &dgdx, const bool dgdx_dot_check, const std::string &caller)
Evaluate dg/dx^T (gradient form, x_space x num_g) of response g_index at the given inArgs.
void addResponseTimeEvents(TimeStepControl< Scalar > &tsc, const std::vector< Scalar > ×)
Add the response times to the time step control as time events on which the time steps land exactly.
AdjointResponseType parseResponseType(const std::string &name)
Convert the "Response Type" parameter value to the enum.
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > createAdjointLinearOpWithSolve(const Thyra::ModelEvaluator< Scalar > &adjoint_model, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs, const Scalar alpha, const Scalar beta)
Create a solver for the adjoint model's W = (alpha*df/dx_dot + beta*df/dx)^T at inArgs.
void applyDfDpTranspose(const Thyra::ModelEvaluator< Scalar > &model, const int p_index, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs, const Thyra::MultiVectorBase< Scalar > &v, Thyra::MultiVectorBase< Scalar > &y, const Scalar alpha, const Scalar beta, Teuchos::RCP< Thyra::LinearOpBase< Scalar > > &dfdp_op, Teuchos::RCP< Thyra::MultiVectorBase< Scalar > > &dfdp_mv)
Compute y = alpha * df/dp^T * v + beta * y.
void evalResponseGradientP(const Thyra::ModelEvaluator< Scalar > &model, const int g_index, const int p_index, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs, Thyra::MultiVectorBase< Scalar > &dgdp)
Evaluate dg/dp^T (gradient form, p_space x num_g) of response g_index with respect to parameter p_ind...
@ STORAGE_TYPE_UNLIMITED
Grow the history as needed.
Status
Status for the Integrator, the Stepper and the SolutionState.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryPL(Teuchos::RCP< Teuchos::ParameterList > pList)
Nonmember constructor from a ParameterList.
AdjointResponseType
Type of response for transient adjoint sensitivities.
Teuchos::RCP< IntegratorBasic< Scalar > > createIntegratorBasic()
Nonmember constructor.
void removeIntegratorSolverObjects(Teuchos::ParameterList &tempusPL)
Same as removeStepperSolverObjects, for the stepper of the integrator selected by Tempus parameters (...
Teuchos::RCP< const DAEStructure< Scalar > > getDAEStructure(const Teuchos::ParameterList &pl)
The DAE structure given by the "Algebraic Equations Mask" parameter of pl, or null if the parameter i...
Teuchos::RCP< IntegratorAdjointSensitivity< Scalar > > createIntegratorAdjointSensitivity()
Nonmember constructor.
RCP< ImplicitAdjointModelEvaluator< Scalar > > implicitAdjointModelEvaluator(const RCP< const ModelEvaluator< Scalar > > &model)