10 #ifndef TEMPUS_TEST_VANDERPOL_IMEX_EXPLICITMODEL_IMPL_HPP
11 #define TEMPUS_TEST_VANDERPOL_IMEX_EXPLICITMODEL_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"
22 #include "Thyra_MultiVectorStdOps.hpp"
23 #include "Thyra_DefaultMultiVectorProductVector.hpp"
24 #include "Thyra_DefaultBlockedLinearOp.hpp"
28 namespace Tempus_Test {
30 template <
class Scalar>
34 useProductVector_ = useProductVector;
35 isInitialized_ =
false;
41 acceptModelParams_ =
false;
48 if (useProductVector_ ==
false) {
49 x_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
50 f_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
56 xSpace_ = Thyra::defaultSpmdVectorSpace<Scalar>(1);
57 for (
int i = 0; i < dim_; ++i) yxSpaceArray.
push_back(xSpace_);
58 x_space_ = Thyra::productVectorSpace<Scalar>(yxSpaceArray);
59 f_space_ = Thyra::productVectorSpace<Scalar>(yxSpaceArray);
63 p_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(np_);
64 g_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(ng_);
65 dxdp_space_ = Thyra::multiVectorProductVectorSpace(x_space_, np_);
67 setParameterList(pList_);
70 template <
class Scalar>
77 template <
class Scalar>
84 template <
class Scalar>
89 "Error, setupInOutArgs_ must be called first!\n");
90 return nominalValues_;
93 template <
class Scalar>
98 if (useProductVector_ ==
false)
99 W_op = Thyra::createMembers(x_space_, dim_);
104 Thyra::createMembers(xSpace_, 1);
106 Thyra::createMembers(xSpace_, 1);
108 Thyra::createMembers(xSpace_, 1);
110 Thyra::createMembers(xSpace_, 1);
111 W_op = Thyra::nonconstBlock2x2(A00, A01, A10, A11);
116 template <
class Scalar>
124 template <
class Scalar>
132 template <
class Scalar>
135 if (isInitialized_) {
143 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot);
144 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_x);
145 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_t);
146 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_alpha);
147 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_beta);
148 if (acceptModelParams_) {
158 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_f);
159 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_W_op);
160 if (acceptModelParams_) {
162 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_DfDp, 0,
163 Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM);
169 nominalValues_ = inArgs_;
173 nominalValues_.set_t(t0_ic_);
177 x_ic_view[0] = x0_ic_;
178 x_ic_view[1] = x1_ic_;
180 nominalValues_.set_x(x_ic);
182 if (acceptModelParams_) {
186 p_ic_view[0] = epsilon_;
188 nominalValues_.set_p(0, p_ic);
193 x_dot_ic_view[0] = x1_ic_;
194 x_dot_ic_view[1] = ((1.0 - x0_ic_ * x0_ic_) * x1_ic_ - x0_ic_) / epsilon_;
196 nominalValues_.set_x_dot(x_dot_ic);
199 isInitialized_ =
true;
202 template <
class Scalar>
210 if (paramList != Teuchos::null) tmpPL = paramList;
212 this->setMyParamList(tmpPL);
214 bool acceptModelParams = get<bool>(*pl,
"Accept model parameters");
215 bool haveIC = get<bool>(*pl,
"Provide nominal values");
216 bool useDfDpAsTangent = get<bool>(*pl,
"Use DfDp as Tangent");
217 if ((acceptModelParams != acceptModelParams_) || (haveIC != haveIC_)) {
218 isInitialized_ =
false;
220 acceptModelParams_ = acceptModelParams;
222 useDfDpAsTangent_ = useDfDpAsTangent;
223 epsilon_ = get<Scalar>(*pl,
"Coeff epsilon");
224 x0_ic_ = get<Scalar>(*pl,
"IC x0");
225 x1_ic_ = get<Scalar>(*pl,
"IC x1");
226 t0_ic_ = get<Scalar>(*pl,
"IC t0");
230 template <
class Scalar>
237 pl->
set(
"Accept model parameters",
false);
238 pl->
set(
"Provide nominal values",
true);
239 pl->
set(
"Use DfDp as Tangent",
false);
240 Teuchos::setDoubleParameter(
"Coeff epsilon", 1.0e-06,
241 "Coefficient a in model", &*pl);
242 Teuchos::setDoubleParameter(
"IC x0", 2.0,
"Initial Condition for x0", &*pl);
243 Teuchos::setDoubleParameter(
"IC x1", 0.0,
"Initial Condition for x1", &*pl);
244 Teuchos::setDoubleParameter(
"IC t0", 0.0,
"Initial time t0", &*pl);
250 template <
class Scalar>
254 if (!acceptModelParams_) {
255 return Teuchos::null;
260 else if (l == 1 || l == 2)
262 return Teuchos::null;
265 template <
class Scalar>
269 if (!acceptModelParams_) {
270 return Teuchos::null;
276 p_strings->push_back(
"Model Coefficient: epsilon");
278 p_strings->push_back(
"DxDp");
280 p_strings->push_back(
"Dx_dotDp");
284 template <
class Scalar>
292 template <
class Scalar>
299 using Teuchos::rcp_dynamic_cast;
301 "Error, setupInOutArgs_ must be called first!\n");
304 inArgs.
get_x().assert_not_null();
309 Scalar
eps = epsilon_;
311 if (acceptModelParams_) {
313 if (p_in != Teuchos::null) {
317 if (inArgs.
get_p(1) != Teuchos::null) {
318 dxdp_in = rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(1),
true)
321 if (inArgs.
get_p(2) != Teuchos::null) {
322 dxdotdp_in = rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(2),
true)
330 if (acceptModelParams_) {
339 f_out_view[0] = x_in_view[1];
340 f_out_view[1] = -x_in_view[0] /
eps;
344 DfDp_out_view(0, 0) = 0.0;
345 DfDp_out_view(1, 0) = x_in_view[0] / (eps *
eps);
348 if (useDfDpAsTangent_ && !
is_null(dxdp_in)) {
350 DfDp_out_view(0, 0) += dxdp(1, 0);
351 DfDp_out_view(1, 0) += -dxdp(0, 0) /
eps;
355 if (useProductVector_ ==
false) {
362 W_view(1, 0) = -beta /
eps;
372 W_block->getNonconstBlock(0, 0),
true);
375 W_block->getNonconstBlock(0, 1),
true);
378 W_block->getNonconstBlock(1, 0),
true);
381 W_block->getNonconstBlock(1, 1),
true);
386 W00_view(0, 0) = 0.0;
387 W01_view(0, 0) = beta;
388 W10_view(0, 0) = -beta /
eps;
389 W11_view(0, 0) = 0.0;
397 x_dot_in = inArgs.
get_x_dot().assert_not_null();
403 f_out_view[0] = x_dot_in_view[0] - x_in_view[1];
404 f_out_view[1] = x_dot_in_view[1] + x_in_view[0] /
eps;
408 DfDp_out_view(0, 0) = 0.0;
409 DfDp_out_view(1, 0) = -x_in_view[0] / (eps *
eps);
412 if (useDfDpAsTangent_ && !
is_null(dxdotdp_in)) {
414 DfDp_out_view(0, 0) += dxdotdp(0, 0);
415 DfDp_out_view(1, 0) += dxdotdp(1, 0);
417 if (useDfDpAsTangent_ && !
is_null(dxdp_in)) {
419 DfDp_out_view(0, 0) += -dxdp(1, 0);
420 DfDp_out_view(1, 0) += dxdp(0, 0) /
eps;
424 if (useProductVector_ ==
false) {
429 W_view(0, 0) = alpha;
430 W_view(0, 1) = -beta;
431 W_view(1, 0) = beta /
eps;
432 W_view(1, 1) = alpha;
441 W_block->getNonconstBlock(0, 0),
true);
444 W_block->getNonconstBlock(0, 1),
true);
447 W_block->getNonconstBlock(1, 0),
true);
450 W_block->getNonconstBlock(1, 1),
true);
455 W00_view(0, 0) = alpha;
456 W01_view(0, 0) = -beta;
457 W10_view(0, 0) = beta /
eps;
458 W11_view(0, 0) = alpha;
466 #endif // TEMPUS_TEST_VANDERPOL_IMEX_EXPLICITMODEL_IMPL_HPP
bool is_null(const boost::shared_ptr< T > &p)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Derivative< Scalar > get_DfDp(int l) const
RCP< const VectorBase< Scalar > > get_x_dot() const
void setModelEvalDescription(const std::string &modelEvalDescription)
void setupInOutArgs_() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
void set_Np_Ng(int Np, int Ng)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
#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_f() const
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
void setSupports(EInArgsMembers arg, bool supports=true)
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
void push_back(const value_type &x)
void setSupports(EOutArgsMembers arg, bool supports=true)
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
VanDerPol_IMEX_ExplicitModel(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null, bool useProductVector=false)
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 setModelEvalDescription(const std::string &modelEvalDescription)
RCP< LinearOpBase< Scalar > > get_W_op() const
RCP< const VectorBase< Scalar > > get_x() const
RCP< const VectorBase< Scalar > > get_p(int l) const
RCP< MultiVectorBase< Scalar > > getMultiVector() const