10 #ifndef TEMPUS_TEST_STEADY_QUADRATIC_MODEL_IMPL_HPP
11 #define TEMPUS_TEST_STEADY_QUADRATIC_MODEL_IMPL_HPP
13 #include "Teuchos_StandardParameterEntryValidators.hpp"
15 #include "Thyra_DefaultSpmdVectorSpace.hpp"
16 #include "Thyra_DetachedVectorView.hpp"
17 #include "Thyra_DetachedMultiVectorView.hpp"
18 #include "Thyra_DefaultSerialDenseLinearOpWithSolveFactory.hpp"
19 #include "Thyra_DefaultMultiVectorLinearOpWithSolve.hpp"
20 #include "Thyra_DefaultLinearOpSource.hpp"
21 #include "Thyra_MultiVectorStdOps.hpp"
22 #include "Thyra_VectorStdOps.hpp"
23 #include "Thyra_DefaultMultiVectorProductVector.hpp"
27 namespace Tempus_Test {
29 template <
class Scalar>
33 isInitialized_ =
false;
39 useDfDpAsTangent_ =
false;
43 x_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
44 f_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
46 p_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(np_);
47 g_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(ng_);
49 setParameterList(pList_);
52 DxDp_space_ = Thyra::multiVectorProductVectorSpace(x_space_, np_);
55 template <
class Scalar>
58 if (b_ < 0.0)
return b_;
62 template <
class Scalar>
65 if (b_ < 0.0)
return 1.0;
69 template <
class Scalar>
76 template <
class Scalar>
83 template <
class Scalar>
88 "Error, setupInOutArgs_ must be called first!\n");
89 return nominalValues_;
92 template <
class Scalar>
98 this->get_W_factory();
115 V_V(multivec->col(0).
ptr(), *vec);
119 Thyra::linearOpWithSolve<Scalar>(*W_factory, matrix);
123 template <
class Scalar>
128 Thyra::createMembers(x_space_, dim_);
132 template <
class Scalar>
137 Thyra::defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
141 template <
class Scalar>
151 template <
class Scalar>
159 template <
class Scalar>
166 using Teuchos::rcp_dynamic_cast;
170 "Error, setupInOutArgs_ must be called first!\n");
177 if (p_in != Teuchos::null) {
183 if (inArgs.
get_p(1) != Teuchos::null)
184 DxDp_in = rcp_dynamic_cast<const DMVPV>(inArgs.
get_p(1))->getMultiVector();
185 if (inArgs.
get_p(2) != Teuchos::null)
187 rcp_dynamic_cast<const DMVPV>(inArgs.
get_p(2))->getMultiVector();
201 f_out_view[0] = x_in_view[0] * x_in_view[0] - b * b;
208 matrix_view(0, 0) = beta * 2.0 * x_in_view[0];
212 DfDp_out_view(0, 0) = -2.0 * b;
215 if (useDfDpAsTangent_ && !
is_null(DxDp_in)) {
217 DfDp_out_view(0, 0) += 2.0 * x_in_view[0] * DxDp(0, 0);
224 x_dot_in = inArgs.
get_x_dot().assert_not_null();
229 f_out_view[0] = x_dot_in_view[0] - (x_in_view[0] * x_in_view[0] - b * b);
236 matrix_view(0, 0) = alpha - beta * 2.0 * x_in_view[0];
240 DfDp_out_view(0, 0) = 2.0 * b;
243 if (useDfDpAsTangent_ && !
is_null(DxdotDp_in)) {
245 DfDp_out_view(0, 0) += DxdotDp(0, 0);
247 if (useDfDpAsTangent_ && !
is_null(DxDp_in)) {
249 DfDp_out_view(0, 0) += -2.0 * x_in_view[0] * DxDp(0, 0);
256 if (g_out != Teuchos::null) Thyra::assign(g_out.
ptr(), *x_in);
259 outArgs.
get_DgDp(0, 0).getMultiVector();
260 if (DgDp_out != Teuchos::null) Thyra::assign(DgDp_out.ptr(), Scalar(0.0));
263 outArgs.
get_DgDx(0).getMultiVector();
264 if (DgDx_out != Teuchos::null) {
266 DgDx_out_view(0, 0) = 1.0;
270 template <
class Scalar>
277 else if (l == 1 || l == 2)
279 return Teuchos::null;
282 template <
class Scalar>
290 p_strings->push_back(
"Model Coefficient: b");
293 p_strings->push_back(
"DxDp");
295 p_strings->push_back(
"Dx_dotDp");
299 template <
class Scalar>
309 template <
class Scalar>
312 if (isInitialized_) {
320 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_t);
321 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_x);
322 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_beta);
323 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot);
324 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_alpha);
333 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_f);
334 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_W_op);
336 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_DfDp, 0,
337 Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM);
338 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_DgDx, 0,
339 Thyra::ModelEvaluatorBase::DERIV_MV_GRADIENT_FORM);
340 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_DgDp, 0, 0,
341 Thyra::ModelEvaluatorBase::DERIV_MV_GRADIENT_FORM);
346 nominalValues_ = inArgs_;
347 nominalValues_.set_t(0.0);
353 nominalValues_.set_x(x_ic);
359 nominalValues_.set_p(0, p_ic);
362 createMember(x_space_);
365 x_dot_ic_view[0] = 0.0;
367 nominalValues_.set_x_dot(x_dot_ic);
369 isInitialized_ =
true;
372 template <
class Scalar>
380 if (paramList != Teuchos::null) tmpPL = paramList;
382 this->setMyParamList(tmpPL);
384 useDfDpAsTangent_ = get<bool>(*pl,
"Use DfDp as Tangent");
385 b_ = get<Scalar>(*pl,
"Coeff b");
386 isInitialized_ =
false;
390 template <
class Scalar>
397 pl->
set(
"Use DfDp as Tangent",
false);
398 Teuchos::setDoubleParameter(
"Coeff b", 1.0,
"Coefficient b in model", &*pl);
405 #endif // TEMPUS_TEST_STEADY_QUADRATIC_MODEL_IMPL_HPP
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs_bar, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs_bar) const
bool is_null(const boost::shared_ptr< T > &p)
Scalar getSteadyStateSolution() const
Derivative< Scalar > get_DfDp(int l) const
RCP< const VectorBase< Scalar > > get_x_dot() const
void setModelEvalDescription(const std::string &modelEvalDescription)
void set_Np_Ng(int Np, int Ng)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int l) const
Evaluation< VectorBase< Scalar > > get_g(int j) const
Evaluation< VectorBase< Scalar > > get_f() const
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
Derivative< Scalar > get_DgDp(int j, int l) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int j) const
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
void setSupports(EInArgsMembers arg, bool supports=true)
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > create_W() const
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
void setSupports(EOutArgsMembers arg, bool supports=true)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
void setModelEvalDescription(const std::string &modelEvalDescription)
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
void setupInOutArgs_() const
RCP< LinearOpBase< Scalar > > get_W_op() const
RCP< const VectorBase< Scalar > > get_x() const
SteadyQuadraticModel(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
RCP< const VectorBase< Scalar > > get_p(int l) const
RCP< MultiVectorBase< Scalar > > getMultiVector() const
Derivative< Scalar > get_DgDx(int j) const
Scalar getSteadyStateSolutionSensitivity() const