9 #ifndef TEMPUS_TEST_VANDERPOL_IMEX_IMPLICITMODEL_IMPL_HPP
10 #define TEMPUS_TEST_VANDERPOL_IMEX_IMPLICITMODEL_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"
21 #include "Thyra_MultiVectorStdOps.hpp"
22 #include "Thyra_DefaultMultiVectorProductVector.hpp"
27 namespace Tempus_Test {
29 template<
class Scalar>
33 isInitialized_ =
false;
39 acceptModelParams_ =
false;
40 useDfDpAsTangent_ =
false;
48 x_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
49 f_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
51 p_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(np_);
52 dxdp_space_ = Thyra::multiVectorProductVectorSpace(x_space_, np_);
56 setParameterList(pList_);
59 template<
class Scalar>
67 template<
class Scalar>
75 template<
class Scalar>
81 "Error, setupInOutArgs_ must be called first!\n");
82 return nominalValues_;
85 template<
class Scalar>
107 V_V(multivec->col(0).
ptr(),*vec);
113 V_V(multivec->col(1).
ptr(),*vec);
117 Thyra::linearOpWithSolve<Scalar>(*W_factory, matrix);
123 template<
class Scalar>
133 template<
class Scalar>
139 Thyra::defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
144 template<
class Scalar>
157 template<
class Scalar>
167 template<
class Scalar>
177 using Teuchos::rcp_dynamic_cast;
179 "Error, setupInOutArgs_ must be called first!\n");
182 inArgs.
get_x().assert_not_null();
187 Scalar eps = epsilon_;
189 if (acceptModelParams_) {
191 if (p_in != Teuchos::null) {
195 if (inArgs.
get_p(1) != Teuchos::null) {
197 rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(1),
true)->getMultiVector();
199 if (inArgs.
get_p(2) != Teuchos::null) {
201 rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(2),
true)->getMultiVector();
208 if (acceptModelParams_) {
219 f_out_view[1] = (1.0-x_in_view[0]*x_in_view[0])*x_in_view[1]/eps;
223 DfDp_out_view(0,0) = 0.0;
224 DfDp_out_view(1,0) = -(1.0-x_in_view[0]*x_in_view[0])*x_in_view[1]/(eps*eps);
227 if (useDfDpAsTangent_ && !
is_null(dxdp_in)) {
229 DfDp_out_view(1,0) +=
230 -2.0*x_in_view[0]*x_in_view[1]/eps * dxdp(0,0) +
231 (1.0 - x_in_view[0]*x_in_view[0])/eps * dxdp(1,0);
241 -2.0*beta*x_in_view[0]*x_in_view[1]/eps;
243 beta*(1.0 - x_in_view[0]*x_in_view[0])/eps;
250 x_dot_in = inArgs.
get_x_dot().assert_not_null();
256 f_out_view[0] = x_dot_in_view[0];
257 f_out_view[1] = x_dot_in_view[1]
258 - (1.0-x_in_view[0]*x_in_view[0])*x_in_view[1]/eps;;
262 DfDp_out_view(0,0) = 0.0;
263 DfDp_out_view(1,0) = (1.0-x_in_view[0]*x_in_view[0])*x_in_view[1]/(eps*eps);
266 if (useDfDpAsTangent_ && !
is_null(dxdotdp_in)) {
268 DfDp_out_view(0,0) += dxdotdp(0,0);
269 DfDp_out_view(1,0) += dxdotdp(1,0);
271 if (useDfDpAsTangent_ && !
is_null(dxdp_in)) {
273 DfDp_out_view(1,0) +=
274 2.0*x_in_view[0]*x_in_view[1]/eps * dxdp(0,0) -
275 (1.0 - x_in_view[0]*x_in_view[0])/eps * dxdp(1,0);
285 2.0*beta*x_in_view[0]*x_in_view[1]/eps;
287 - beta*(1.0 - x_in_view[0]*x_in_view[0])/eps;
293 template<
class Scalar>
298 if (!acceptModelParams_) {
299 return Teuchos::null;
304 else if (l == 1 || l == 2)
306 return Teuchos::null;
309 template<
class Scalar>
314 if (!acceptModelParams_) {
315 return Teuchos::null;
320 p_strings->push_back(
"Model Coefficient: epsilon");
322 p_strings->push_back(
"Model Coefficient: epsilon");
324 p_strings->push_back(
"DxDp");
326 p_strings->push_back(
"Dx_dotDp");
330 template<
class Scalar>
339 template<
class Scalar>
344 if (isInitialized_) {
352 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_x_dot );
353 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_x );
354 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_t );
355 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_alpha );
356 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_beta );
357 if (acceptModelParams_) {
367 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_f );
368 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_W_op );
369 if (acceptModelParams_) {
371 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_DfDp,0,
372 Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM );
378 nominalValues_ = inArgs_;
381 nominalValues_.set_t(t0_ic_);
385 x_ic_view[0] = x0_ic_;
386 x_ic_view[1] = x1_ic_;
388 nominalValues_.set_x(x_ic);
389 if (acceptModelParams_) {
393 p_ic_view[0] = epsilon_;
395 nominalValues_.set_p(0,p_ic);
400 x_dot_ic_view[0] = x1_ic_;
401 x_dot_ic_view[1] = ((1.0-x0_ic_*x0_ic_)*x1_ic_-x0_ic_)/epsilon_;
403 nominalValues_.set_x_dot(x_dot_ic);
406 isInitialized_ =
true;
410 template<
class Scalar>
419 if (paramList != Teuchos::null) tmpPL = paramList;
421 this->setMyParamList(tmpPL);
423 bool acceptModelParams = get<bool>(*pl,
"Accept model parameters");
424 bool haveIC = get<bool>(*pl,
"Provide nominal values");
425 bool useDfDpAsTangent = get<bool>(*pl,
"Use DfDp as Tangent");
426 if ( (acceptModelParams != acceptModelParams_) ||
429 isInitialized_ =
false;
431 acceptModelParams_ = acceptModelParams;
433 useDfDpAsTangent_ = useDfDpAsTangent;
434 epsilon_ = get<Scalar>(*pl,
"Coeff epsilon");
435 x0_ic_ = get<Scalar>(*pl,
"IC x0");
436 x1_ic_ = get<Scalar>(*pl,
"IC x1");
437 t0_ic_ = get<Scalar>(*pl,
"IC t0");
441 template<
class Scalar>
449 pl->
set(
"Accept model parameters",
false);
450 pl->
set(
"Provide nominal values",
true);
451 pl->
set(
"Use DfDp as Tangent",
false);
452 Teuchos::setDoubleParameter(
453 "Coeff epsilon", 1.0e-06,
"Coefficient a in model", &*pl);
454 Teuchos::setDoubleParameter(
455 "IC x0", 2.0,
"Initial Condition for x0", &*pl);
456 Teuchos::setDoubleParameter(
457 "IC x1", 0.0,
"Initial Condition for x1", &*pl);
458 Teuchos::setDoubleParameter(
459 "IC t0", 0.0,
"Initial time t0", &*pl);
466 #endif // TEMPUS_TEST_VANDERPOL_IMEX_IMPLICITMODEL_IMPL_HPP
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int l) const
void setupInOutArgs_() const
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > create_W() const
bool is_null(const boost::shared_ptr< T > &p)
Derivative< Scalar > get_DfDp(int l) const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() 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)
VanDerPol_IMEX_ImplicitModel(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
void set_Np_Ng(int Np, int Ng)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
Evaluation< VectorBase< Scalar > > get_f() 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)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
void setSupports(EInArgsMembers arg, bool supports=true)
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs_bar, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs_bar) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
void setSupports(EOutArgsMembers arg, bool supports=true)
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
void setModelEvalDescription(const std::string &modelEvalDescription)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
RCP< LinearOpBase< Scalar > > get_W_op() const
RCP< const VectorBase< Scalar > > get_x() const
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
RCP< const VectorBase< Scalar > > get_p(int l) const
RCP< MultiVectorBase< Scalar > > getMultiVector() const