10 #ifndef TEMPUS_TEST_VANDERPOL_IMEX_IMPLICITMODEL_IMPL_HPP
11 #define TEMPUS_TEST_VANDERPOL_IMEX_IMPLICITMODEL_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"
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>
66 template <
class Scalar>
73 template <
class Scalar>
78 "Error, setupInOutArgs_ must be called first!\n");
79 return nominalValues_;
82 template <
class Scalar>
88 this->get_W_factory();
106 V_V(multivec->col(0).
ptr(), *vec);
112 V_V(multivec->col(1).
ptr(), *vec);
116 Thyra::linearOpWithSolve<Scalar>(*W_factory, matrix);
121 template <
class Scalar>
126 Thyra::createMembers(x_space_, dim_);
130 template <
class Scalar>
135 Thyra::defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
139 template <
class Scalar>
149 template <
class Scalar>
157 template <
class Scalar>
164 using Teuchos::rcp_dynamic_cast;
166 "Error, setupInOutArgs_ must be called first!\n");
169 inArgs.
get_x().assert_not_null();
174 Scalar
eps = epsilon_;
176 if (acceptModelParams_) {
178 if (p_in != Teuchos::null) {
182 if (inArgs.
get_p(1) != Teuchos::null) {
183 dxdp_in = rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(1),
true)
186 if (inArgs.
get_p(2) != Teuchos::null) {
187 dxdotdp_in = rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(2),
true)
195 if (acceptModelParams_) {
205 f_out_view[1] = (1.0 - x_in_view[0] * x_in_view[0]) * x_in_view[1] / eps;
209 DfDp_out_view(0, 0) = 0.0;
210 DfDp_out_view(1, 0) =
211 -(1.0 - x_in_view[0] * x_in_view[0]) * x_in_view[1] / (eps * eps);
214 if (useDfDpAsTangent_ && !
is_null(dxdp_in)) {
216 DfDp_out_view(1, 0) +=
217 -2.0 * x_in_view[0] * x_in_view[1] / eps * dxdp(0, 0) +
218 (1.0 - x_in_view[0] * x_in_view[0]) / eps * dxdp(1, 0);
229 -2.0 * beta * x_in_view[0] * x_in_view[1] /
eps;
231 beta * (1.0 - x_in_view[0] * x_in_view[0]) / eps;
238 x_dot_in = inArgs.
get_x_dot().assert_not_null();
244 f_out_view[0] = x_dot_in_view[0];
245 f_out_view[1] = x_dot_in_view[1] -
246 (1.0 - x_in_view[0] * x_in_view[0]) * x_in_view[1] / eps;
250 DfDp_out_view(0, 0) = 0.0;
251 DfDp_out_view(1, 0) =
252 (1.0 - x_in_view[0] * x_in_view[0]) * x_in_view[1] / (eps * eps);
255 if (useDfDpAsTangent_ && !
is_null(dxdotdp_in)) {
257 DfDp_out_view(0, 0) += dxdotdp(0, 0);
258 DfDp_out_view(1, 0) += dxdotdp(1, 0);
260 if (useDfDpAsTangent_ && !
is_null(dxdp_in)) {
262 DfDp_out_view(1, 0) +=
263 2.0 * x_in_view[0] * x_in_view[1] / eps * dxdp(0, 0) -
264 (1.0 - x_in_view[0] * x_in_view[0]) / eps * dxdp(1, 0);
272 W_view(0, 0) = alpha;
275 2.0 * beta * x_in_view[0] * x_in_view[1] /
eps;
276 W_view(1, 1) = alpha - beta * (1.0 - x_in_view[0] * x_in_view[0]) /
283 template <
class Scalar>
287 if (!acceptModelParams_) {
288 return Teuchos::null;
293 else if (l == 1 || l == 2)
295 return Teuchos::null;
298 template <
class Scalar>
302 if (!acceptModelParams_) {
303 return Teuchos::null;
308 p_strings->push_back(
"Model Coefficient: epsilon");
310 p_strings->push_back(
"Model Coefficient: epsilon");
312 p_strings->push_back(
"DxDp");
314 p_strings->push_back(
"Dx_dotDp");
318 template <
class Scalar>
326 template <
class Scalar>
329 if (isInitialized_) {
337 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot);
338 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_x);
339 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_t);
340 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_alpha);
341 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_beta);
342 if (acceptModelParams_) {
352 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_f);
353 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_W_op);
354 if (acceptModelParams_) {
356 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_DfDp, 0,
357 Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM);
363 nominalValues_ = inArgs_;
365 nominalValues_.set_t(t0_ic_);
367 createMember(x_space_);
370 x_ic_view[0] = x0_ic_;
371 x_ic_view[1] = x1_ic_;
373 nominalValues_.set_x(x_ic);
374 if (acceptModelParams_) {
376 createMember(p_space_);
379 p_ic_view[0] = epsilon_;
381 nominalValues_.set_p(0, p_ic);
384 createMember(x_space_);
387 x_dot_ic_view[0] = x1_ic_;
388 x_dot_ic_view[1] = ((1.0 - x0_ic_ * x0_ic_) * x1_ic_ - x0_ic_) / epsilon_;
390 nominalValues_.set_x_dot(x_dot_ic);
393 isInitialized_ =
true;
396 template <
class Scalar>
404 if (paramList != Teuchos::null) tmpPL = paramList;
406 this->setMyParamList(tmpPL);
408 bool acceptModelParams = get<bool>(*pl,
"Accept model parameters");
409 bool haveIC = get<bool>(*pl,
"Provide nominal values");
410 bool useDfDpAsTangent = get<bool>(*pl,
"Use DfDp as Tangent");
411 if ((acceptModelParams != acceptModelParams_) || (haveIC != haveIC_)) {
412 isInitialized_ =
false;
414 acceptModelParams_ = acceptModelParams;
416 useDfDpAsTangent_ = useDfDpAsTangent;
417 epsilon_ = get<Scalar>(*pl,
"Coeff epsilon");
418 x0_ic_ = get<Scalar>(*pl,
"IC x0");
419 x1_ic_ = get<Scalar>(*pl,
"IC x1");
420 t0_ic_ = get<Scalar>(*pl,
"IC t0");
424 template <
class Scalar>
431 pl->
set(
"Accept model parameters",
false);
432 pl->
set(
"Provide nominal values",
true);
433 pl->
set(
"Use DfDp as Tangent",
false);
434 Teuchos::setDoubleParameter(
"Coeff epsilon", 1.0e-06,
435 "Coefficient a in model", &*pl);
436 Teuchos::setDoubleParameter(
"IC x0", 2.0,
"Initial Condition for x0", &*pl);
437 Teuchos::setDoubleParameter(
"IC x1", 0.0,
"Initial Condition for x1", &*pl);
438 Teuchos::setDoubleParameter(
"IC t0", 0.0,
"Initial time t0", &*pl);
445 #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)
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
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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