9 #ifndef TEMPUS_TEST_VANDERPOL_IMEXPart_IMPLICITMODEL_IMPL_HPP
10 #define TEMPUS_TEST_VANDERPOL_IMEXPart_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;
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>
70 template<
class Scalar>
78 template<
class Scalar>
84 "Error, setupInOutArgs_ must be called first!\n");
85 return nominalValues_;
88 template<
class Scalar>
95 this->get_W_factory();
111 V_V(multivec->col(0).
ptr(),*vec);
115 Thyra::linearOpWithSolve<Scalar>(*W_factory, matrix);
121 template<
class Scalar>
127 Thyra::createMembers(x_space_, dim_);
132 template<
class Scalar>
138 Thyra::defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
143 template<
class Scalar>
156 template<
class Scalar>
166 template<
class Scalar>
176 using Teuchos::rcp_dynamic_cast;
178 "Error, setupInOutArgs_ must be called first!\n");
181 inArgs.
get_x().assert_not_null();
183 Scalar x1 = x_in_view[0];
187 Scalar eps = epsilon_;
190 if (p_in != Teuchos::null) {
196 if (inArgs.
get_p(1) != Teuchos::null) {
198 rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(1),
true)->getMultiVector();
200 if (inArgs.
get_p(2) != Teuchos::null) {
202 rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(2),
true)->getMultiVector();
204 if (inArgs.
get_p(3) != Teuchos::null) {
206 rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(3),
true)->getMultiVector();
210 inArgs.
get_p(4).assert_not_null();
212 Scalar x0 = y_in_view[0];
217 outArgs.
get_DfDp(0).getMultiVector();
219 outArgs.
get_DfDp(4).getMultiVector();
226 f_out_view[0] = (1.0-x0*x0)*x1/eps;
230 DfDp_out_view(0,0) = -(1.0-x0*x0)*x1/(eps*eps);
233 if (useDfDpAsTangent_ && !
is_null(dxdp_in)) {
235 DfDp_out_view(0,0) += (1.0 - x0*x0)/eps * dxdp(0,0);
237 if (useDfDpAsTangent_ && !
is_null(dydp_in)) {
239 DfDp_out_view(0,0) += -2.0*x0*x1/eps * dydp(0,0);
244 DfDx0_out_view(0,0) = -2.0*x0*x1/eps;
250 W_view(0,0) = beta*(1.0 - x0*x0)/eps;
257 x_dot_in = inArgs.
get_x_dot().assert_not_null();
261 f_out_view[0] = x_dot_in_view[0] - (1.0-x0*x0)*x1/eps;
265 DfDp_out_view(0,0) = (1.0-x0*x0)*x1/(eps*eps);
268 if (useDfDpAsTangent_ && !
is_null(dxdotdp_in)) {
270 DfDp_out_view(0,0) += dxdotdp(0,0);
272 if (useDfDpAsTangent_ && !
is_null(dxdp_in)) {
274 DfDp_out_view(0,0) += -(1.0 - x0*x0)/eps * dxdp(0,0);
276 if (useDfDpAsTangent_ && !
is_null(dydp_in)) {
278 DfDp_out_view(0,0) += 2.0*x0*x1/eps * dydp(0,0);
283 DfDx0_out_view(0,0) = 2.0*x0*x1/eps;
290 W_view(0,0) = alpha - beta*(1.0 - x0*x0)/eps;
296 template<
class Scalar>
304 else if (l == 1 || l == 2)
310 return Teuchos::null;
313 template<
class Scalar>
322 p_strings->push_back(
"Model Coefficient: epsilon");
324 p_strings->push_back(
"DxDp");
326 p_strings->push_back(
"Dx_dotDp");
328 p_strings->push_back(
"DyDp");
330 p_strings->push_back(
"EXPLICIT_ONLY_VECTOR");
334 template<
class Scalar>
343 template<
class Scalar>
348 if (isInitialized_)
return;
354 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_x_dot );
355 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_x );
356 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_t );
357 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_alpha );
358 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_beta );
367 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_f );
368 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_W_op );
370 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_DfDp,0,
371 Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM );
372 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_DfDp,4,
373 Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM );
378 nominalValues_ = inArgs_;
382 nominalValues_.set_t(t0_ic_);
386 x_ic_view[0] = x1_ic_;
388 nominalValues_.set_x(x_ic);
395 p_ic_view[0] = epsilon_;
396 y_ic_view[0] = x0_ic_;
398 nominalValues_.set_p(0,p_ic);
399 nominalValues_.set_p(4,y_ic);
404 x_dot_ic_view[0] = ((1.0-x0_ic_*x0_ic_)*x1_ic_-x0_ic_)/epsilon_;
406 nominalValues_.set_x_dot(x_dot_ic);
409 isInitialized_ =
true;
413 template<
class Scalar>
422 if (paramList != Teuchos::null) tmpPL = paramList;
424 this->setMyParamList(tmpPL);
426 bool haveIC = get<bool>(*pl,
"Provide nominal values");
427 bool useDfDpAsTangent = get<bool>(*pl,
"Use DfDp as Tangent");
428 if (haveIC != haveIC_) isInitialized_ =
false;
430 useDfDpAsTangent_ = useDfDpAsTangent;
431 epsilon_ = get<Scalar>(*pl,
"Coeff epsilon");
432 x0_ic_ = get<Scalar>(*pl,
"IC x0");
433 x1_ic_ = get<Scalar>(*pl,
"IC x1");
434 t0_ic_ = get<Scalar>(*pl,
"IC t0");
438 template<
class Scalar>
446 pl->
set(
"Accept model parameters",
false);
447 pl->
set(
"Provide nominal values",
true);
448 pl->
set(
"Use DfDp as Tangent",
false);
449 Teuchos::setDoubleParameter(
450 "Coeff epsilon", 1.0e-06,
"Coefficient a in model", &*pl);
451 Teuchos::setDoubleParameter(
452 "IC x0", 2.0,
"Initial Condition for x0", &*pl);
453 Teuchos::setDoubleParameter(
454 "IC x1", 0.0,
"Initial Condition for x1", &*pl);
455 Teuchos::setDoubleParameter(
456 "IC t0", 0.0,
"Initial time t0", &*pl);
463 #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
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)
VanDerPol_IMEXPart_ImplicitModel(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
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)
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