10 #ifndef TEMPUS_TEST_VANDERPOL_IMEXPart_IMPLICITMODEL_IMPL_HPP
11 #define TEMPUS_TEST_VANDERPOL_IMEXPart_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;
41 useDfDpAsTangent_ =
false;
49 x_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
50 f_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
52 y_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
53 p_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(np_);
54 dxdp_space_ = Thyra::multiVectorProductVectorSpace(x_space_, np_);
55 dydp_space_ = Thyra::multiVectorProductVectorSpace(y_space_, np_);
59 setParameterList(pList_);
62 template <
class Scalar>
69 template <
class Scalar>
76 template <
class Scalar>
81 "Error, setupInOutArgs_ must be called first!\n");
82 return nominalValues_;
85 template <
class Scalar>
91 this->get_W_factory();
108 V_V(multivec->col(0).
ptr(), *vec);
112 Thyra::linearOpWithSolve<Scalar>(*W_factory, matrix);
117 template <
class Scalar>
122 Thyra::createMembers(x_space_, dim_);
126 template <
class Scalar>
131 Thyra::defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
135 template <
class Scalar>
145 template <
class Scalar>
153 template <
class Scalar>
160 using Teuchos::rcp_dynamic_cast;
162 "Error, setupInOutArgs_ must be called first!\n");
165 inArgs.
get_x().assert_not_null();
167 Scalar x1 = x_in_view[0];
171 Scalar
eps = epsilon_;
174 if (p_in != Teuchos::null) {
180 if (inArgs.
get_p(1) != Teuchos::null) {
182 rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(1),
true)->getMultiVector();
184 if (inArgs.
get_p(2) != Teuchos::null) {
186 rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(2),
true)->getMultiVector();
188 if (inArgs.
get_p(3) != Teuchos::null) {
190 rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(3),
true)->getMultiVector();
194 inArgs.
get_p(4).assert_not_null();
196 Scalar x0 = y_in_view[0];
201 outArgs.
get_DfDp(0).getMultiVector();
203 outArgs.
get_DfDp(4).getMultiVector();
209 f_out_view[0] = (1.0 - x0 * x0) * x1 / eps;
213 DfDp_out_view(0, 0) = -(1.0 - x0 * x0) * x1 / (eps * eps);
216 if (useDfDpAsTangent_ && !
is_null(dxdp_in)) {
218 DfDp_out_view(0, 0) += (1.0 - x0 * x0) / eps * dxdp(0, 0);
220 if (useDfDpAsTangent_ && !
is_null(dydp_in)) {
222 DfDp_out_view(0, 0) += -2.0 * x0 * x1 / eps * dydp(0, 0);
227 DfDx0_out_view(0, 0) = -2.0 * x0 * x1 /
eps;
234 W_view(0, 0) = beta * (1.0 - x0 * x0) / eps;
241 x_dot_in = inArgs.
get_x_dot().assert_not_null();
245 f_out_view[0] = x_dot_in_view[0] - (1.0 - x0 * x0) * x1 / eps;
249 DfDp_out_view(0, 0) = (1.0 - x0 * x0) * x1 / (eps * eps);
253 if (useDfDpAsTangent_ && !
is_null(dxdotdp_in)) {
255 DfDp_out_view(0, 0) += dxdotdp(0, 0);
257 if (useDfDpAsTangent_ && !
is_null(dxdp_in)) {
259 DfDp_out_view(0, 0) += -(1.0 - x0 * x0) / eps * dxdp(0, 0);
261 if (useDfDpAsTangent_ && !
is_null(dydp_in)) {
263 DfDp_out_view(0, 0) += 2.0 * x0 * x1 / eps * dydp(0, 0);
268 DfDx0_out_view(0, 0) = 2.0 * x0 * x1 /
eps;
276 W_view(0, 0) = alpha - beta * (1.0 - x0 * x0) / eps;
282 template <
class Scalar>
289 else if (l == 1 || l == 2)
295 return Teuchos::null;
298 template <
class Scalar>
306 p_strings->push_back(
"Model Coefficient: epsilon");
308 p_strings->push_back(
"DxDp");
310 p_strings->push_back(
"Dx_dotDp");
312 p_strings->push_back(
"DyDp");
314 p_strings->push_back(
"EXPLICIT_ONLY_VECTOR");
318 template <
class Scalar>
326 template <
class Scalar>
329 if (isInitialized_)
return;
335 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot);
336 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_x);
337 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_t);
338 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_alpha);
339 inArgs.
setSupports(Thyra::ModelEvaluatorBase::IN_ARG_beta);
348 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_f);
349 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_W_op);
351 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_DfDp, 0,
352 Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM);
353 outArgs.
setSupports(Thyra::ModelEvaluatorBase::OUT_ARG_DfDp, 4,
354 Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM);
359 nominalValues_ = inArgs_;
362 nominalValues_.set_t(t0_ic_);
366 x_ic_view[0] = x1_ic_;
368 nominalValues_.set_x(x_ic);
375 p_ic_view[0] = epsilon_;
376 y_ic_view[0] = x0_ic_;
378 nominalValues_.set_p(0, p_ic);
379 nominalValues_.set_p(4, y_ic);
384 x_dot_ic_view[0] = ((1.0 - x0_ic_ * x0_ic_) * x1_ic_ - x0_ic_) / epsilon_;
386 nominalValues_.set_x_dot(x_dot_ic);
389 isInitialized_ =
true;
392 template <
class Scalar>
400 if (paramList != Teuchos::null) tmpPL = paramList;
402 this->setMyParamList(tmpPL);
404 bool haveIC = get<bool>(*pl,
"Provide nominal values");
405 bool useDfDpAsTangent = get<bool>(*pl,
"Use DfDp as Tangent");
406 if (haveIC != haveIC_) isInitialized_ =
false;
408 useDfDpAsTangent_ = useDfDpAsTangent;
409 epsilon_ = get<Scalar>(*pl,
"Coeff epsilon");
410 x0_ic_ = get<Scalar>(*pl,
"IC x0");
411 x1_ic_ = get<Scalar>(*pl,
"IC x1");
412 t0_ic_ = get<Scalar>(*pl,
"IC t0");
416 template <
class Scalar>
423 pl->
set(
"Accept model parameters",
false);
424 pl->
set(
"Provide nominal values",
true);
425 pl->
set(
"Use DfDp as Tangent",
false);
426 Teuchos::setDoubleParameter(
"Coeff epsilon", 1.0e-06,
427 "Coefficient a in model", &*pl);
428 Teuchos::setDoubleParameter(
"IC x0", 2.0,
"Initial Condition for x0", &*pl);
429 Teuchos::setDoubleParameter(
"IC x1", 0.0,
"Initial Condition for x1", &*pl);
430 Teuchos::setDoubleParameter(
"IC t0", 0.0,
"Initial time t0", &*pl);
437 #endif // TEMPUS_TEST_VANDERPOL_IMEXPart_IMPLICITMODEL_IMPL_HPP
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
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)
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > create_W() const
void set_Np_Ng(int Np, int Ng)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
VanDerPol_IMEXPart_ImplicitModel(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
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)
void setSupports(EInArgsMembers arg, bool supports=true)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
void setupInOutArgs_() const
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int l) const
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
void setSupports(EOutArgsMembers arg, bool supports=true)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
void setModelEvalDescription(const std::string &modelEvalDescription)
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
RCP< LinearOpBase< Scalar > > get_W_op() const
RCP< const VectorBase< Scalar > > get_x() const
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs_bar, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs_bar) const
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
RCP< const VectorBase< Scalar > > get_p(int l) const