9 #ifndef TEMPUS_TEST_VANDERPOL_MODEL_IMPL_HPP
10 #define TEMPUS_TEST_VANDERPOL_MODEL_IMPL_HPP
12 #include "Teuchos_StandardParameterEntryValidators.hpp"
14 #include "Thyra_DefaultSpmdVectorSpace.hpp"
15 #include "Thyra_DetachedVectorView.hpp"
16 #include "Thyra_DetachedMultiVectorView.hpp"
17 #include "Thyra_DefaultSerialDenseLinearOpWithSolveFactory.hpp"
18 #include "Thyra_DefaultMultiVectorLinearOpWithSolve.hpp"
19 #include "Thyra_DefaultLinearOpSource.hpp"
20 #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>
60 "Error - No exact solution for van der Pol problem!\n");
64 template<
class Scalar>
70 "Error - No exact sensitivities for van der Pol problem!\n");
74 template<
class Scalar>
83 template<
class Scalar>
92 template<
class Scalar>
98 "Error, setupInOutArgs_ must be called first!\n");
99 return nominalValues_;
103 template<
class Scalar>
125 V_V(multivec->col(0).
ptr(),*vec);
131 V_V(multivec->col(1).
ptr(),*vec);
135 Thyra::linearOpWithSolve<Scalar>(*W_factory, matrix);
141 template<
class Scalar>
151 template<
class Scalar>
157 Thyra::defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
162 template<
class Scalar>
175 template<
class Scalar>
185 template<
class Scalar>
195 "Error, setupInOutArgs_ must be called first!\n");
198 inArgs.
get_x().assert_not_null();
202 Scalar epsilon = epsilon_;
203 if (acceptModelParams_) {
205 inArgs.
get_p(0).assert_not_null();
207 epsilon = p_in_view[0];
215 if (acceptModelParams_) {
225 f_out_view[0] = x_in_view[1];
227 ((1.0-x_in_view[0]*x_in_view[0])*x_in_view[1]-x_in_view[0])/epsilon;
233 matrix_view(0,0) = 0.0;
234 matrix_view(0,1) = +beta;
236 -beta*(2.0*x_in_view[0]*x_in_view[1]+1.0)/epsilon;
238 beta*(1.0 - x_in_view[0]*x_in_view[0])/epsilon;
243 DfDp_out_view(0,0) = 0.0;
245 -((1.0-x_in_view[0]*x_in_view[0])*x_in_view[1]-x_in_view[0])
252 x_dot_in = inArgs.
get_x_dot().assert_not_null();
257 f_out_view[0] = x_dot_in_view[0] - x_in_view[1];
258 f_out_view[1] = x_dot_in_view[1]
259 - ((1.0-x_in_view[0]*x_in_view[0])*x_in_view[1]-x_in_view[0])/epsilon;
265 matrix_view(0,0) = alpha;
266 matrix_view(0,1) = -beta;
268 beta*(2.0*x_in_view[0]*x_in_view[1]+1.0)/epsilon;
269 matrix_view(1,1) = alpha
270 - beta*(1.0 - x_in_view[0]*x_in_view[0])/epsilon;
275 DfDp_out_view(0,0) = 0.0;
277 ((1.0-x_in_view[0]*x_in_view[0])*x_in_view[1]-x_in_view[0])
283 template<
class Scalar>
288 if (!acceptModelParams_) {
289 return Teuchos::null;
295 template<
class Scalar>
300 if (!acceptModelParams_) {
301 return Teuchos::null;
306 p_strings->push_back(
"Model Coefficient: epsilon");
310 template<
class Scalar>
321 template<
class Scalar>
326 if (isInitialized_) {
334 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_t );
335 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_x );
336 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_beta );
337 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_x_dot );
338 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_alpha );
339 if (acceptModelParams_) {
349 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_f );
350 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_W_op );
351 if (acceptModelParams_) {
353 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_DfDp,0,
354 Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM );
360 nominalValues_ = inArgs_;
364 nominalValues_.set_t(t0_ic_);
368 x_ic_view[0] = x0_ic_;
369 x_ic_view[1] = x1_ic_;
371 nominalValues_.set_x(x_ic);
372 if (acceptModelParams_) {
376 p_ic_view[0] = epsilon_;
378 nominalValues_.set_p(0,p_ic);
383 x_dot_ic_view[0] = x1_ic_;
384 x_dot_ic_view[1] = ((1.0-x0_ic_*x0_ic_)*x1_ic_-x0_ic_)/epsilon_;
386 nominalValues_.set_x_dot(x_dot_ic);
389 isInitialized_ =
true;
393 template<
class Scalar>
401 if (paramList != Teuchos::null) tmpPL = paramList;
403 this->setMyParamList(tmpPL);
405 bool acceptModelParams = get<bool>(*pl,
"Accept model parameters");
406 bool haveIC = get<bool>(*pl,
"Provide nominal values");
407 if ( (acceptModelParams != acceptModelParams_) ||
410 isInitialized_ =
false;
412 acceptModelParams_ = acceptModelParams;
414 epsilon_ = get<Scalar>(*pl,
"Coeff epsilon");
415 x0_ic_ = get<Scalar>(*pl,
"IC x0");
416 x1_ic_ = get<Scalar>(*pl,
"IC x1");
417 t0_ic_ = get<Scalar>(*pl,
"IC t0");
421 template<
class Scalar>
429 pl->
set(
"Accept model parameters",
false);
430 pl->
set(
"Provide nominal values",
true);
431 Teuchos::setDoubleParameter(
432 "Coeff epsilon", 1.0e-06,
"Coefficient a in model", &*pl);
433 Teuchos::setDoubleParameter(
434 "IC x0", 2.0,
"Initial Condition for x0", &*pl);
435 Teuchos::setDoubleParameter(
436 "IC x1", 0.0,
"Initial Condition for x1", &*pl);
437 Teuchos::setDoubleParameter(
438 "IC t0", 0.0,
"Initial time t0", &*pl);
439 Teuchos::setIntParameter(
440 "Number of Time Step Sizes", 1,
"Number time step sizes for convergence study", &*pl);
447 #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)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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
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