9 #ifndef Tempus_IntegratorForwardSensitivity_impl_hpp
10 #define Tempus_IntegratorForwardSensitivity_impl_hpp
12 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
13 #include "Thyra_DefaultMultiVectorProductVector.hpp"
14 #include "Thyra_VectorStdOps.hpp"
15 #include "Thyra_MultiVectorStdOps.hpp"
16 #include "Tempus_CombinedForwardSensitivityModelEvaluator.hpp"
21 template<
class Scalar>
24 Teuchos::RCP<Teuchos::ParameterList> inputPL,
25 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model)
28 integrator_ = integratorBasic<Scalar>();
29 this->setParameterList(inputPL);
30 createSensitivityModelAndStepper(model);
31 if (use_combined_method_)
32 integrator_ = integratorBasic<Scalar>(tempus_pl_, sens_model_);
34 integrator_ = integratorBasic<Scalar>();
35 integrator_->setTempusParameterList(tempus_pl_);
36 integrator_->setStepperWStepper(sens_stepper_);
37 integrator_->initialize();
41 template<
class Scalar>
44 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
45 std::string stepperType)
48 integrator_ = integratorBasic<Scalar>();
49 this->setParameterList(Teuchos::null);
50 createSensitivityModelAndStepper(model);
51 if (use_combined_method_)
52 integrator_ = integratorBasic<Scalar>(sens_model_, stepperType);
54 integrator_ = integratorBasic<Scalar>();
55 integrator_->setParameterList(tempus_pl_);
56 integrator_->setStepperWStepper(sens_stepper_);
57 integrator_->initialize();
62 template<
class Scalar>
66 integrator_ = integratorBasic<Scalar>();
67 this->setParameterList(Teuchos::null);
70 template<
class Scalar>
73 Teuchos::RCP<Thyra::ModelEvaluator<Scalar> > model)
75 createSensitivityModelAndStepper(model);
76 if (use_combined_method_)
77 integrator_->setStepper(sens_model_);
79 integrator_->setStepperWStepper(sens_stepper_);
82 template<
class Scalar>
85 Teuchos::RCP<
const Thyra::VectorBase<Scalar> > x0,
86 Teuchos::RCP<
const Thyra::VectorBase<Scalar> > xdot0,
87 Teuchos::RCP<
const Thyra::VectorBase<Scalar> > xdotdot0,
88 Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > DxDp0,
89 Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > DxdotDp0,
90 Teuchos::RCP<
const Thyra::MultiVectorBase<Scalar> > DxdotdotDp0)
93 using Teuchos::rcp_dynamic_cast;
94 using Thyra::VectorSpaceBase;
96 using Thyra::createMember;
97 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
102 RCP< const VectorSpaceBase<Scalar> > space;
103 if (use_combined_method_)
104 space = sens_model_->get_x_space();
106 space = sens_stepper_->get_x_space();
107 RCP<DMVPV> X = rcp_dynamic_cast<DMVPV>(createMember(space));
108 RCP<DMVPV> Xdot = rcp_dynamic_cast<DMVPV>(createMember(space));
109 RCP<DMVPV> Xdotdot = rcp_dynamic_cast<DMVPV>(createMember(space));
111 const int num_param = X->getNonconstMultiVector()->domain()->dim()-1;
112 const Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
113 const Teuchos::Range1D rng(1,num_param);
116 assign(X->getNonconstMultiVector()->col(0).ptr(), *x0);
117 if (DxDp0 == Teuchos::null)
118 assign(X->getNonconstMultiVector()->subView(rng).ptr(), zero);
120 assign(X->getNonconstMultiVector()->subView(rng).ptr(), *DxDp0);
123 if (xdot0 == Teuchos::null)
124 assign(Xdot->getNonconstMultiVector()->col(0).ptr(), zero);
126 assign(Xdot->getNonconstMultiVector()->col(0).ptr(), *xdot0);
127 if (DxdotDp0 == Teuchos::null)
128 assign(Xdot->getNonconstMultiVector()->subView(rng).ptr(), zero);
130 assign(Xdot->getNonconstMultiVector()->subView(rng).ptr(), *DxdotDp0);
133 if (xdotdot0 == Teuchos::null)
134 assign(Xdotdot->getNonconstMultiVector()->col(0).ptr(), zero);
136 assign(Xdotdot->getNonconstMultiVector()->col(0).ptr(), *xdotdot0);
137 if (DxdotDp0 == Teuchos::null)
138 assign(Xdotdot->getNonconstMultiVector()->subView(rng).ptr(), zero);
140 assign(Xdotdot->getNonconstMultiVector()->subView(rng).ptr(), *DxdotdotDp0);
142 integrator_->initializeSolutionHistory(t0, X, Xdot, Xdotdot);
145 template<
class Scalar>
146 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
151 using Teuchos::rcp_dynamic_cast;
152 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
154 RCP<const DMVPV> X = rcp_dynamic_cast<
const DMVPV>(integrator_->getX());
155 return X->getMultiVector()->col(0);
158 template<
class Scalar>
159 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
164 using Teuchos::rcp_dynamic_cast;
165 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
167 RCP<const DMVPV> X = rcp_dynamic_cast<
const DMVPV>(integrator_->getX());
168 const int num_param = X->getMultiVector()->domain()->dim()-1;
169 const Teuchos::Range1D rng(1,num_param);
170 return X->getMultiVector()->subView(rng);
173 template<
class Scalar>
174 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
179 using Teuchos::rcp_dynamic_cast;
180 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
182 RCP<const DMVPV> Xdot = rcp_dynamic_cast<
const DMVPV>(integrator_->getXdot());
183 return Xdot->getMultiVector()->col(0);
186 template<
class Scalar>
187 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
192 using Teuchos::rcp_dynamic_cast;
193 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
195 RCP<const DMVPV> Xdot = rcp_dynamic_cast<
const DMVPV>(integrator_->getXdot());
196 const int num_param = Xdot->getMultiVector()->domain()->dim()-1;
197 const Teuchos::Range1D rng(1,num_param);
198 return Xdot->getMultiVector()->subView(rng);
201 template<
class Scalar>
202 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
207 using Teuchos::rcp_dynamic_cast;
208 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
210 RCP<const DMVPV> Xdotdot =
211 rcp_dynamic_cast<
const DMVPV>(integrator_->getXdotdot());
212 return Xdotdot->getMultiVector()->col(0);
215 template<
class Scalar>
216 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
221 using Teuchos::rcp_dynamic_cast;
222 typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
224 RCP<const DMVPV> Xdotdot =
225 rcp_dynamic_cast<
const DMVPV>(integrator_->getXdotdot());
226 const int num_param = Xdotdot->getMultiVector()->domain()->dim()-1;
227 const Teuchos::Range1D rng(1,num_param);
228 return Xdotdot->getMultiVector()->subView(rng);
231 template<
class Scalar>
236 std::string name =
"Tempus::IntegratorForwardSensitivity";
240 template<
class Scalar>
244 Teuchos::FancyOStream &out,
245 const Teuchos::EVerbosityLevel verbLevel)
const
247 out << description() <<
"::describe" << std::endl;
248 integrator_->describe(out, verbLevel);
251 template<
class Scalar>
256 tempus_pl_ = Teuchos::parameterList();
257 if (inputPL != Teuchos::null)
258 *tempus_pl_ = *inputPL;
259 tempus_pl_->setParametersNotAlreadySet(*this->getValidParameters());
260 sens_pl_ = Teuchos::sublist(tempus_pl_,
"Sensitivities",
false);
261 std::string integratorName =
262 tempus_pl_->get<std::string>(
"Integrator Name",
"Default Integrator");
263 std::string stepperName =
264 tempus_pl_->sublist(integratorName).get<std::string>(
"Stepper Name");
265 stepper_pl_ = Teuchos::sublist(tempus_pl_, stepperName,
true);
266 use_combined_method_ =
267 sens_pl_->get<std::string>(
"Sensitivity Method") ==
"Combined";
270 template<
class Scalar>
271 Teuchos::RCP<Teuchos::ParameterList>
275 Teuchos::RCP<Teuchos::ParameterList> temp_param_list = tempus_pl_;
276 tempus_pl_ = Teuchos::null;
277 sens_pl_ = Teuchos::null;
278 stepper_pl_ = Teuchos::null;
279 integrator_->unsetParameterList();
280 return temp_param_list;
283 template<
class Scalar>
284 Teuchos::RCP<const Teuchos::ParameterList>
288 Teuchos::RCP<Teuchos::ParameterList> pl =
289 Teuchos::rcp(
new Teuchos::ParameterList);
290 Teuchos::RCP<const Teuchos::ParameterList> integrator_pl =
291 integrator_->getValidParameters();
292 Teuchos::RCP<const Teuchos::ParameterList> sensitivity_pl =
294 pl->setParameters(*integrator_pl);
295 Teuchos::ParameterList& spl = pl->sublist(
"Sensitivities");
296 spl.setParameters(*sensitivity_pl);
297 spl.set(
"Sensitivity Method",
"Combined");
298 spl.set(
"Reuse State Linear Solver",
false);
303 template <
class Scalar>
307 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& )
311 Teuchos::RCP<Teuchos::ParameterList> spl = Teuchos::parameterList();
313 spl->remove(
"Sensitivity Method");
315 if (use_combined_method_) {
316 spl->remove(
"Reuse State Linear Solver");
323 model_, stepper_pl_, spl));
328 template<
class Scalar>
329 Teuchos::RCP<IntegratorForwardSensitivity<Scalar> >
331 Teuchos::RCP<Teuchos::ParameterList> pList,
332 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model)
334 Teuchos::RCP<IntegratorForwardSensitivity<Scalar> > integrator =
340 template<
class Scalar>
341 Teuchos::RCP<IntegratorForwardSensitivity<Scalar> >
343 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
344 std::string stepperType)
346 Teuchos::RCP<IntegratorForwardSensitivity<Scalar> > integrator =
352 template<
class Scalar>
353 Teuchos::RCP<IntegratorForwardSensitivity<Scalar> >
356 Teuchos::RCP<IntegratorForwardSensitivity<Scalar> > integrator =
362 #endif // Tempus_IntegratorForwardSensitivity_impl_hpp
std::string description() const override
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXdot() const
Get current the time derivative of the solution, xdot.
virtual void initializeSolutionHistory(Teuchos::RCP< SolutionState< Scalar > > state=Teuchos::null)
Set the initial state which has the initial conditions.
static Teuchos::RCP< const Teuchos::ParameterList > getValidParameters()
A stepper implementing staggered forward sensitivity analysis.
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDxdotDp() const
virtual void setStepper(Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > model)
Set the Stepper.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList() override
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDxdotdotDp() const
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXdotdot() const
Get current the second time derivative of the solution, xdotdot.
void createSensitivityModelAndStepper(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model)
Teuchos::RCP< IntegratorForwardSensitivity< Scalar > > integratorForwardSensitivity(Teuchos::RCP< Teuchos::ParameterList > pList, const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model)
Non-member constructor.
IntegratorForwardSensitivity()
Destructor.
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDxDp() const
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl) override
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getX() const
Get current the solution, x.
Teuchos::RCP< SensitivityModelEvaluatorBase< Scalar > > wrapCombinedFSAModelEvaluator(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, const Teuchos::RCP< const Teuchos::ParameterList > &pList=Teuchos::null)
Time integrator implementing forward sensitivity analysis.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override