9 #ifndef Tempus_StepperStaggeredForwardSensitivity_impl_hpp
10 #define Tempus_StepperStaggeredForwardSensitivity_impl_hpp
12 #include "Thyra_VectorStdOps.hpp"
13 #include "Thyra_MultiVectorStdOps.hpp"
14 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
15 #include "Thyra_DefaultMultiVectorProductVector.hpp"
17 #include "Tempus_StepperFactory.hpp"
23 template <
class Scalar>
29 this->
setParams(Teuchos::null, Teuchos::null);
32 template <
class Scalar>
46 this->
setModel(appModel, sens_residual_model, sens_solve_model);
50 template <
class Scalar>
64 spl->
remove(
"Reuse State Linear Solver");
65 spl->
remove(
"Force W Update");
67 sens_solve_model,
false, spl);
74 appModel, sens_residual_model, sens_solve_model, spl);
78 if (stateStepper_ == Teuchos::null)
79 stateStepper_ = sf->createStepper(stepperPL_, appModel);
81 stateStepper_->setModel(appModel);
83 if (sensitivityStepper_ == Teuchos::null)
84 sensitivityStepper_ = sf->createStepper(stepperPL_, fsa_model_);
86 sensitivityStepper_->setModel(fsa_model_);
88 this->isInitialized_ =
false;
91 template <
class Scalar>
95 return combined_fsa_model_;
98 template <
class Scalar>
102 stateStepper_->setSolver(solver);
103 sensitivityStepper_->setSolver(solver);
105 this->isInitialized_ =
false;
108 template <
class Scalar>
112 this->checkInitialized();
116 using Teuchos::rcp_dynamic_cast;
118 using Thyra::createMember;
120 using Thyra::multiVectorProductVector;
121 using Thyra::multiVectorProductVectorSpace;
130 if (stateSolutionHistory_ == Teuchos::null) {
131 RCP<Teuchos::ParameterList> shPL =
132 solutionHistory->getNonconstParameterList();
135 RCP<SolutionState<Scalar> > state = solutionHistory->getCurrentState();
136 RCP<DMVPV> X, XDot, XDotDot;
137 X = rcp_dynamic_cast<DMVPV>(state->getX(),
true);
139 XDot = rcp_dynamic_cast<DMVPV>(state->getXDot(),
true);
140 if (state->getXDotDot() != Teuchos::null)
141 XDotDot = rcp_dynamic_cast<DMVPV>(state->getXDotDot(),
true);
145 RCP<VectorBase<Scalar> > x, xdot, xdotdot;
146 x = X->getNonconstMultiVector()->col(0);
147 xdot = XDot->getNonconstMultiVector()->col(0);
148 if (XDotDot != Teuchos::null)
149 xdotdot = XDotDot->getNonconstMultiVector()->col(0);
152 RCP<SolutionState<Scalar> > state_state = state->
clone();
153 state_state->setX(x);
154 state_state->setXDot(xdot);
155 state_state->setXDotDot(xdotdot);
156 stateSolutionHistory_ = createSolutionHistoryPL<Scalar>(shPL);
157 stateSolutionHistory_->addState(state_state);
159 const int num_param = X->getMultiVector()->domain()->dim() - 1;
164 RCP<MultiVectorBase<Scalar> > dxdp, dxdotdp, dxdotdotdp;
165 dxdp = X->getNonconstMultiVector()->subView(rng);
166 dxdotdp = XDot->getNonconstMultiVector()->subView(rng);
167 if (XDotDot != Teuchos::null)
168 dxdotdotdp = XDotDot->getNonconstMultiVector()->subView(rng);
171 RCP<VectorBase<Scalar> > dxdp_vec, dxdotdp_vec, dxdotdotdp_vec;
172 RCP<const DMVPVS> prod_space =
173 multiVectorProductVectorSpace(X->getMultiVector()->range(), num_param);
174 dxdp_vec = multiVectorProductVector(prod_space, dxdp);
175 dxdotdp_vec = multiVectorProductVector(prod_space, dxdotdp);
176 if (XDotDot != Teuchos::null)
177 dxdotdotdp_vec = multiVectorProductVector(prod_space, dxdotdotdp);
180 RCP<SolutionState<Scalar> > sens_state = state->clone();
181 sens_state->setX(dxdp_vec);
182 sens_state->setXDot(dxdotdp_vec);
183 sens_state->setXDotDot(dxdotdotdp_vec);
184 sensSolutionHistory_ = createSolutionHistoryPL<Scalar>(shPL);
185 sensSolutionHistory_->addState(sens_state);
189 RCP<SolutionState<Scalar> > prod_state = solutionHistory->getWorkingState();
190 RCP<DMVPV> X, XDot, XDotDot;
191 X = rcp_dynamic_cast<DMVPV>(prod_state->getX(),
true);
192 XDot = rcp_dynamic_cast<DMVPV>(prod_state->getXDot(),
true);
193 if (prod_state->getXDotDot() != Teuchos::null)
194 XDotDot = rcp_dynamic_cast<DMVPV>(prod_state->getXDotDot(),
true);
198 stateSolutionHistory_->initWorkingState();
199 RCP<SolutionState<Scalar> > state = stateSolutionHistory_->getWorkingState();
200 state->getMetaData()->copy(prod_state->getMetaData());
201 stateStepper_->takeStep(stateSolutionHistory_);
204 assign(X->getNonconstMultiVector()->col(0).ptr(), *(state->getX()));
205 assign(XDot->getNonconstMultiVector()->col(0).ptr(), *(state->getXDot()));
206 if (XDotDot != Teuchos::null)
207 assign(XDotDot->getNonconstMultiVector()->col(0).ptr(),
208 *(state->getXDotDot()));
209 prod_state->setOrder(state->getOrder());
216 stateSolutionHistory_->promoteWorkingState();
219 fsa_model_->setForwardSolutionHistory(stateSolutionHistory_);
220 if (reuse_solver_ && stateStepper_->getSolver() != Teuchos::null)
221 fsa_model_->setSolver(stateStepper_->getSolver(), force_W_update_);
225 sensSolutionHistory_->initWorkingState();
226 RCP<SolutionState<Scalar> > sens_state =
227 sensSolutionHistory_->getWorkingState();
228 sens_state->getMetaData()->copy(prod_state->getMetaData());
229 sensitivityStepper_->takeStep(sensSolutionHistory_);
232 RCP<const MultiVectorBase<Scalar> > dxdp =
233 rcp_dynamic_cast<
const DMVPV>(sens_state->getX(),
true)->getMultiVector();
234 const int num_param = dxdp->domain()->dim();
236 assign(X->getNonconstMultiVector()->subView(rng).ptr(), *dxdp);
237 RCP<const MultiVectorBase<Scalar> > dxdotdp =
238 rcp_dynamic_cast<
const DMVPV>(sens_state->getXDot(),
true)
240 assign(XDot->getNonconstMultiVector()->subView(rng).ptr(), *dxdotdp);
241 if (sens_state->getXDotDot() != Teuchos::null) {
242 RCP<const MultiVectorBase<Scalar> > dxdotdotdp =
243 rcp_dynamic_cast<
const DMVPV>(sens_state->getXDotDot(),
true)
245 assign(XDotDot->getNonconstMultiVector()->subView(rng).ptr(), *dxdotdotdp);
247 prod_state->setOrder(std::min(state->getOrder(), sens_state->getOrder()));
254 sensSolutionHistory_->promoteWorkingState();
259 template <
class Scalar>
270 template <
class Scalar>
278 out <<
"--- StepperStaggeredForwardSensitivity ---\n";
279 out <<
" stateStepper_ = " << stateStepper_ << std::endl;
280 out <<
" sensitivityStepper_ = " << sensitivityStepper_ << std::endl;
281 out <<
" combined_fsa_model_ = " << combined_fsa_model_ << std::endl;
282 out <<
" fsa_model_ = " << fsa_model_ << std::endl;
283 out <<
" stateSolutionHistory_ = " << stateSolutionHistory_ << std::endl;
284 out <<
" sensSolutionHistory_ = " << sensSolutionHistory_ << std::endl;
285 out <<
"------------------------------------------" << std::endl;
287 out << description() <<
"::describe:" << std::endl;
288 stateStepper_->describe(out, verbLevel);
290 sensitivityStepper_->describe(out, verbLevel);
293 template <
class Scalar>
298 bool isValidSetup =
true;
302 if (stateStepper_ == Teuchos::null) {
303 isValidSetup =
false;
304 out <<
"The state stepper is not set!\n";
307 if (sensitivityStepper_ == Teuchos::null) {
308 isValidSetup =
false;
309 out <<
"The sensitivity stepper is not set!\n";
312 if (combined_fsa_model_ == Teuchos::null) {
313 isValidSetup =
false;
314 out <<
"The combined FSA model is not set!\n";
317 if (fsa_model_ == Teuchos::null) {
318 isValidSetup =
false;
319 out <<
"The FSA model is not set!\n";
325 template <
class Scalar>
329 if (pList == Teuchos::null) {
331 if (this->stepperPL_ == Teuchos::null)
333 this->getValidParameters());
336 this->stepperPL_ = pList;
342 template <
class Scalar>
346 return stateStepper_->getValidParameters();
349 template <
class Scalar>
356 template <
class Scalar>
361 stepperPL_ = Teuchos::null;
365 template <
class Scalar>
370 if (pList == Teuchos::null)
372 this->getValidParameters());
376 if (spList == Teuchos::null)
377 sensPL_ = Teuchos::parameterList();
381 reuse_solver_ = sensPL_->
get(
"Reuse State Linear Solver",
false);
382 force_W_update_ = sensPL_->get(
"Force W Update",
true);
388 template <
class Scalar>
393 using Teuchos::rcp_dynamic_cast;
396 RCP<const Thyra::VectorSpaceBase<Scalar> > x_space =
397 stateStepper_->getModel()->get_x_space();
398 RCP<const DMVPVS> dxdp_space = rcp_dynamic_cast<
const DMVPVS>(
399 sensitivityStepper_->getModel()->get_x_space(),
true);
400 const int num_param = dxdp_space->
numBlocks();
401 RCP<const Thyra::VectorSpaceBase<Scalar> > prod_space =
402 multiVectorProductVectorSpace(x_space, num_param + 1);
408 #endif // Tempus_StepperStaggeredForwardSensitivity_impl_hpp
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
RCP< const VectorSpaceBase< Scalar > > clone() const
T & get(const std::string &name, T def_value)
Teuchos::RCP< SensitivityModelEvaluatorBase< Scalar > > wrapStaggeredFSAModelEvaluator(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &sens_residual_model, const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &sens_solve_model, const bool is_pseudotransient, const Teuchos::RCP< const Teuchos::ParameterList > &pList=Teuchos::null)
void setStepperName(std::string s)
Set the stepper name.
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
StepperStaggeredForwardSensitivity()
Default constructor.
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
virtual void initialize()
Initialize after construction and changing input parameters.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
Thyra Base interface for time steppers.
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
bool remove(std::string const &name, bool throwIfNotExists=true)
StepperState is a simple class to hold state information about the stepper.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Teuchos::RCP< SensitivityModelEvaluatorBase< Scalar > > wrapCombinedFSAModelEvaluator(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &sens_residual_model, const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &sens_solve_model, const Teuchos::RCP< const Teuchos::ParameterList > &pList=Teuchos::null)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
#define TEUCHOS_ASSERT(assertion_test)
void setParams(const Teuchos::RCP< Teuchos::ParameterList > &pl, const Teuchos::RCP< Teuchos::ParameterList > &spl)
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver=Teuchos::null)
Set solver.
void setStepperType(std::string s)
Set the stepper type.
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getModel() const
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const