10 #ifndef TEMPUS_TEST_VANDERPOL_MODEL_IMPL_HPP
11 #define TEMPUS_TEST_VANDERPOL_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_VectorStdOps.hpp"
25 namespace Tempus_Test {
27 template <
class Scalar>
31 isInitialized_ =
false;
37 acceptModelParams_ =
false;
45 x_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
46 f_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
48 p_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(np_);
49 g_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(ng_);
51 setParameterList(pList_);
54 template <
class Scalar>
59 true, std::logic_error,
60 "Error - No exact solution for van der Pol problem!\n");
64 template <
class Scalar>
69 !isInitialized_, std::logic_error,
70 "Error - No exact sensitivities for van der Pol problem!\n");
74 template <
class Scalar>
81 template <
class Scalar>
88 template <
class Scalar>
93 "Error, setupInOutArgs_ must be called first!\n");
94 return nominalValues_;
97 template <
class Scalar>
103 this->get_W_factory();
121 V_V(multivec->col(0).
ptr(), *vec);
127 V_V(multivec->col(1).
ptr(), *vec);
131 Thyra::linearOpWithSolve<Scalar>(*W_factory, matrix);
136 template <
class Scalar>
141 Thyra::createMembers(x_space_, dim_);
145 template <
class Scalar>
150 Thyra::defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
154 template <
class Scalar>
164 template <
class Scalar>
172 template <
class Scalar>
179 "Error, setupInOutArgs_ must be called first!\n");
182 inArgs.
get_x().assert_not_null();
186 Scalar epsilon = epsilon_;
187 if (acceptModelParams_) {
189 inArgs.
get_p(0).assert_not_null();
191 epsilon = p_in_view[0];
199 if (acceptModelParams_) {
208 f_out_view[0] = x_in_view[1];
210 ((1.0 - x_in_view[0] * x_in_view[0]) * x_in_view[1] - x_in_view[0]) /
218 matrix_view(0, 0) = 0.0;
219 matrix_view(0, 1) = +beta;
220 matrix_view(1, 0) = -beta * (2.0 * x_in_view[0] * x_in_view[1] + 1.0) /
222 matrix_view(1, 1) = beta * (1.0 - x_in_view[0] * x_in_view[0]) /
228 DfDp_out_view(0, 0) = 0.0;
229 DfDp_out_view(1, 0) =
230 -((1.0 - x_in_view[0] * x_in_view[0]) * x_in_view[1] - x_in_view[0]) /
237 x_dot_in = inArgs.
get_x_dot().assert_not_null();
242 f_out_view[0] = x_dot_in_view[0] - x_in_view[1];
245 ((1.0 - x_in_view[0] * x_in_view[0]) * x_in_view[1] - x_in_view[0]) /
253 matrix_view(0, 0) = alpha;
254 matrix_view(0, 1) = -beta;
255 matrix_view(1, 0) = beta * (2.0 * x_in_view[0] * x_in_view[1] + 1.0) /
257 matrix_view(1, 1) = alpha - beta * (1.0 - x_in_view[0] * x_in_view[0]) /
263 DfDp_out_view(0, 0) = 0.0;
264 DfDp_out_view(1, 0) =
265 ((1.0 - x_in_view[0] * x_in_view[0]) * x_in_view[1] - x_in_view[0]) /
271 template <
class Scalar>
275 if (!acceptModelParams_) {
276 return Teuchos::null;
282 template <
class Scalar>
286 if (!acceptModelParams_) {
287 return Teuchos::null;
292 p_strings->push_back(
"Model Coefficient: epsilon");
296 template <
class Scalar>
306 template <
class Scalar>
309 if (isInitialized_) {
317 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_t);
318 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_x);
319 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_beta);
320 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot);
321 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_alpha);
322 if (acceptModelParams_) {
332 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_f);
333 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_W_op);
334 if (acceptModelParams_) {
336 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_DfDp, 0,
337 Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM);
343 nominalValues_ = inArgs_;
346 nominalValues_.set_t(t0_ic_);
350 x_ic_view[0] = x0_ic_;
351 x_ic_view[1] = x1_ic_;
353 nominalValues_.set_x(x_ic);
354 if (acceptModelParams_) {
358 p_ic_view[0] = epsilon_;
360 nominalValues_.set_p(0, p_ic);
365 x_dot_ic_view[0] = x1_ic_;
366 x_dot_ic_view[1] = ((1.0 - x0_ic_ * x0_ic_) * x1_ic_ - x0_ic_) / epsilon_;
368 nominalValues_.set_x_dot(x_dot_ic);
371 isInitialized_ =
true;
374 template <
class Scalar>
382 if (paramList != Teuchos::null) tmpPL = paramList;
384 this->setMyParamList(tmpPL);
386 bool acceptModelParams = get<bool>(*pl,
"Accept model parameters");
387 bool haveIC = get<bool>(*pl,
"Provide nominal values");
388 if ((acceptModelParams != acceptModelParams_) || (haveIC != haveIC_)) {
389 isInitialized_ =
false;
391 acceptModelParams_ = acceptModelParams;
393 epsilon_ = get<Scalar>(*pl,
"Coeff epsilon");
394 x0_ic_ = get<Scalar>(*pl,
"IC x0");
395 x1_ic_ = get<Scalar>(*pl,
"IC x1");
396 t0_ic_ = get<Scalar>(*pl,
"IC t0");
400 template <
class Scalar>
407 pl->
set(
"Accept model parameters",
false);
408 pl->
set(
"Provide nominal values",
true);
409 Teuchos::setDoubleParameter(
"Coeff epsilon", 1.0e-06,
410 "Coefficient a in model", &*pl);
411 Teuchos::setDoubleParameter(
"IC x0", 2.0,
"Initial Condition for x0", &*pl);
412 Teuchos::setDoubleParameter(
"IC x1", 0.0,
"Initial Condition for x1", &*pl);
413 Teuchos::setDoubleParameter(
"IC t0", 0.0,
"Initial time t0", &*pl);
414 Teuchos::setIntParameter(
"Number of Time Step Sizes", 1,
415 "Number time step sizes for convergence study",
423 #endif // TEMPUS_TEST_VANDERPOL_MODEL_IMPL_HPP
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
bool is_null(const boost::shared_ptr< T > &p)
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)
Evaluation< VectorBase< Scalar > > get_f() const
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Thyra::ModelEvaluatorBase::InArgs< Scalar > getExactSolution(double t) const
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
VanDerPolModel(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
void setSupports(EInArgsMembers arg, bool supports=true)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > create_W() const
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs_bar, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs_bar) const
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int j) const
void setSupports(EOutArgsMembers arg, bool supports=true)
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Thyra::ModelEvaluatorBase::InArgs< Scalar > getExactSensSolution(int j, double t) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int l) const
void setupInOutArgs_() const
void setModelEvalDescription(const std::string &modelEvalDescription)
RCP< LinearOpBase< Scalar > > get_W_op() const
RCP< const VectorBase< Scalar > > get_x() const
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
RCP< const VectorBase< Scalar > > get_p(int l) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
RCP< MultiVectorBase< Scalar > > getMultiVector() const