9 #ifndef Tempus_IntegratorForwardSensitivity_impl_hpp
10 #define Tempus_IntegratorForwardSensitivity_impl_hpp
12 #include "Thyra_DefaultMultiVectorProductVector.hpp"
13 #include "Thyra_VectorStdOps.hpp"
14 #include "Thyra_MultiVectorStdOps.hpp"
16 #include "Tempus_CombinedForwardSensitivityModelEvaluator.hpp"
22 template<
class Scalar>
29 integrator_ = integratorBasic<Scalar>();
30 this->setParameterList(inputPL);
31 createSensitivityModelAndStepper(model);
32 if (use_combined_method_)
33 integrator_ = integratorBasic<Scalar>(tempus_pl_, sens_model_);
35 integrator_ = integratorBasic<Scalar>();
36 integrator_->setTempusParameterList(tempus_pl_);
37 integrator_->setStepperWStepper(sens_stepper_);
38 integrator_->initialize();
42 template<
class Scalar>
46 std::string stepperType)
49 integrator_ = integratorBasic<Scalar>();
50 this->setParameterList(Teuchos::null);
51 createSensitivityModelAndStepper(model);
52 if (use_combined_method_)
53 integrator_ = integratorBasic<Scalar>(sens_model_, stepperType);
55 integrator_ = integratorBasic<Scalar>();
56 integrator_->setParameterList(tempus_pl_);
57 integrator_->setStepperWStepper(sens_stepper_);
58 integrator_->initialize();
63 template<
class Scalar>
67 integrator_ = integratorBasic<Scalar>();
68 this->setParameterList(Teuchos::null);
71 template<
class Scalar>
76 createSensitivityModelAndStepper(model);
77 if (use_combined_method_)
78 integrator_->setStepper(sens_model_);
80 integrator_->setStepperWStepper(sens_stepper_);
83 template<
class Scalar>
94 using Teuchos::rcp_dynamic_cast;
97 using Thyra::createMember;
103 RCP< const VectorSpaceBase<Scalar> > space;
104 if (use_combined_method_)
105 space = sens_model_->get_x_space();
107 space = sens_stepper_->get_x_space();
108 RCP<DMVPV> X = rcp_dynamic_cast<DMVPV>(createMember(space));
109 RCP<DMVPV> Xdot = rcp_dynamic_cast<DMVPV>(createMember(space));
110 RCP<DMVPV> Xdotdot = rcp_dynamic_cast<DMVPV>(createMember(space));
117 assign(X->getNonconstMultiVector()->col(0).ptr(), *x0);
118 if (DxDp0 == Teuchos::null)
119 assign(X->getNonconstMultiVector()->subView(rng).ptr(), zero);
121 assign(X->getNonconstMultiVector()->subView(rng).ptr(), *DxDp0);
124 if (xdot0 == Teuchos::null)
125 assign(Xdot->getNonconstMultiVector()->col(0).ptr(), zero);
127 assign(Xdot->getNonconstMultiVector()->col(0).ptr(), *xdot0);
128 if (DxdotDp0 == Teuchos::null)
129 assign(Xdot->getNonconstMultiVector()->subView(rng).ptr(), zero);
131 assign(Xdot->getNonconstMultiVector()->subView(rng).ptr(), *DxdotDp0);
134 if (xdotdot0 == Teuchos::null)
135 assign(Xdotdot->getNonconstMultiVector()->col(0).ptr(), zero);
137 assign(Xdotdot->getNonconstMultiVector()->col(0).ptr(), *xdotdot0);
138 if (DxdotDp0 == Teuchos::null)
139 assign(Xdotdot->getNonconstMultiVector()->subView(rng).ptr(), zero);
141 assign(Xdotdot->getNonconstMultiVector()->subView(rng).ptr(), *DxdotdotDp0);
143 integrator_->initializeSolutionHistory(t0, X, Xdot, Xdotdot);
146 template<
class Scalar>
152 using Teuchos::rcp_dynamic_cast;
155 RCP<const DMVPV> X = rcp_dynamic_cast<
const DMVPV>(integrator_->getX());
159 template<
class Scalar>
165 using Teuchos::rcp_dynamic_cast;
168 RCP<const DMVPV> X = rcp_dynamic_cast<
const DMVPV>(integrator_->getX());
171 return X->getMultiVector()->subView(rng);
174 template<
class Scalar>
180 using Teuchos::rcp_dynamic_cast;
183 RCP<const DMVPV> Xdot = rcp_dynamic_cast<
const DMVPV>(integrator_->getXDot());
187 template<
class Scalar>
193 using Teuchos::rcp_dynamic_cast;
196 RCP<const DMVPV> Xdot = rcp_dynamic_cast<
const DMVPV>(integrator_->getXDot());
199 return Xdot->getMultiVector()->subView(rng);
202 template<
class Scalar>
208 using Teuchos::rcp_dynamic_cast;
211 RCP<const DMVPV> Xdotdot =
212 rcp_dynamic_cast<
const DMVPV>(integrator_->getXDotDot());
216 template<
class Scalar>
222 using Teuchos::rcp_dynamic_cast;
225 RCP<const DMVPV> Xdotdot =
226 rcp_dynamic_cast<
const DMVPV>(integrator_->getXDotDot());
227 const int num_param = Xdotdot->
getMultiVector()->domain()->dim()-1;
229 return Xdotdot->getMultiVector()->subView(rng);
232 template<
class Scalar>
237 std::string name =
"Tempus::IntegratorForwardSensitivity";
241 template<
class Scalar>
248 auto out = Teuchos::fancyOStream( in_out.
getOStream() );
249 out->setOutputToRootOnly(0);
250 *out << description() <<
"::describe" << std::endl;
251 integrator_->describe(in_out, verbLevel);
254 template<
class Scalar>
259 tempus_pl_ = Teuchos::parameterList();
260 if (inputPL != Teuchos::null)
261 *tempus_pl_ = *inputPL;
263 sens_pl_ = Teuchos::sublist(tempus_pl_,
"Sensitivities",
false);
264 std::string integratorName =
265 tempus_pl_->get<std::string>(
"Integrator Name",
"Default Integrator");
266 std::string stepperName =
267 tempus_pl_->sublist(integratorName).get<std::string>(
"Stepper Name");
268 stepper_pl_ = Teuchos::sublist(tempus_pl_, stepperName,
true);
269 use_combined_method_ =
270 sens_pl_->get<std::string>(
"Sensitivity Method") ==
"Combined";
273 template<
class Scalar>
279 tempus_pl_ = Teuchos::null;
280 sens_pl_ = Teuchos::null;
281 stepper_pl_ = Teuchos::null;
282 integrator_->unsetParameterList();
283 return temp_param_list;
286 template<
class Scalar>
294 integrator_->getValidParameters();
300 spl.
set(
"Sensitivity Method",
"Combined");
301 spl.
set(
"Reuse State Linear Solver",
false);
306 template <
class Scalar>
316 spl->
remove(
"Sensitivity Method");
318 if (use_combined_method_) {
319 spl->
remove(
"Reuse State Linear Solver");
326 model_, stepper_pl_, spl));
331 template<
class Scalar>
343 template<
class Scalar>
347 std::string stepperType)
355 template<
class Scalar>
365 #endif // Tempus_IntegratorForwardSensitivity_impl_hpp
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXDotDot() const
Get current the second time derivative of the solution, xdotdot.
std::string description() const override
virtual void initializeSolutionHistory(Teuchos::RCP< SolutionState< Scalar > > state=Teuchos::null)
Set the initial state which has the initial conditions.
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDXDotDp() const
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDXDotDotDp() const
static Teuchos::RCP< const Teuchos::ParameterList > getValidParameters()
A stepper implementing staggered forward sensitivity analysis.
virtual void setStepper(Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > model)
Set the Stepper.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList() override
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)
Nonmember constructor.
bool remove(std::string const &name, bool throwIfNotExists=true)
IntegratorForwardSensitivity()
Destructor.
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDxDp() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl) override
RCP< const MultiVectorBase< Scalar > > getMultiVector() const
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
ParameterList & setParameters(const ParameterList &source)
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getX() const
Get current the solution, x.
RCP< std::basic_ostream< char_type, traits_type > > getOStream()
ParameterList & setParametersNotAlreadySet(const ParameterList &source)
Teuchos::RCP< SensitivityModelEvaluatorBase< Scalar > > wrapCombinedFSAModelEvaluator(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, const Teuchos::RCP< const Teuchos::ParameterList > &pList=Teuchos::null)
RCP< MultiVectorBase< Scalar > > getNonconstMultiVector()
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXDot() const
Get current the time derivative of the solution, xdot.
Time integrator implementing forward sensitivity analysis.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override