9 #ifndef TEMPUS_TEST_VANDERPOL_IMEX_EXPLICITMODEL_IMPL_HPP
10 #define TEMPUS_TEST_VANDERPOL_IMEX_EXPLICITMODEL_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"
23 #include "Thyra_DefaultBlockedLinearOp.hpp"
28 namespace Tempus_Test {
30 template<
class Scalar>
35 useProductVector_ = useProductVector;
36 isInitialized_ =
false;
42 acceptModelParams_ =
false;
49 if (useProductVector_ ==
false) {
50 x_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
51 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>
79 template<
class Scalar>
88 template<
class Scalar>
94 "Error, setupInOutArgs_ must be called first!\n");
95 return nominalValues_;
99 template<
class Scalar>
105 if (useProductVector_ ==
false)
106 W_op = Thyra::createMembers(x_space_, dim_);
111 Thyra::createMembers(xSpace_, 1);
113 Thyra::createMembers(xSpace_, 1);
115 Thyra::createMembers(xSpace_, 1);
117 Thyra::createMembers(xSpace_, 1);
118 W_op = Thyra::nonconstBlock2x2(A00, A01, A10, A11);
124 template<
class Scalar>
134 template<
class Scalar>
144 template<
class Scalar>
149 if (isInitialized_) {
157 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_x_dot );
158 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_x );
159 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_t );
160 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_alpha );
161 inArgs.
setSupports( Thyra::ModelEvaluatorBase::IN_ARG_beta );
162 if (acceptModelParams_) {
172 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_f );
173 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_W_op );
174 if (acceptModelParams_) {
176 outArgs.
setSupports( Thyra::ModelEvaluatorBase::OUT_ARG_DfDp,0,
177 Thyra::ModelEvaluatorBase::DERIV_MV_JACOBIAN_FORM );
183 nominalValues_ = inArgs_;
188 nominalValues_.set_t(t0_ic_);
192 x_ic_view[0] = x0_ic_;
193 x_ic_view[1] = x1_ic_;
195 nominalValues_.set_x(x_ic);
197 if (acceptModelParams_) {
201 p_ic_view[0] = epsilon_;
203 nominalValues_.set_p(0,p_ic);
208 x_dot_ic_view[0] = x1_ic_;
209 x_dot_ic_view[1] = ((1.0-x0_ic_*x0_ic_)*x1_ic_-x0_ic_)/epsilon_;
211 nominalValues_.set_x_dot(x_dot_ic);
214 isInitialized_ =
true;
217 template<
class Scalar>
225 if (paramList != Teuchos::null) tmpPL = paramList;
227 this->setMyParamList(tmpPL);
229 bool acceptModelParams = get<bool>(*pl,
"Accept model parameters");
230 bool haveIC = get<bool>(*pl,
"Provide nominal values");
231 bool useDfDpAsTangent = get<bool>(*pl,
"Use DfDp as Tangent");
232 if ( (acceptModelParams != acceptModelParams_) ||
235 isInitialized_ =
false;
237 acceptModelParams_ = acceptModelParams;
239 useDfDpAsTangent_ = useDfDpAsTangent;
240 epsilon_ = get<Scalar>(*pl,
"Coeff epsilon");
241 x0_ic_ = get<Scalar>(*pl,
"IC x0");
242 x1_ic_ = get<Scalar>(*pl,
"IC x1");
243 t0_ic_ = get<Scalar>(*pl,
"IC t0");
247 template<
class Scalar>
255 pl->
set(
"Accept model parameters",
false);
256 pl->
set(
"Provide nominal values",
true);
257 pl->
set(
"Use DfDp as Tangent",
false);
258 Teuchos::setDoubleParameter(
259 "Coeff epsilon", 1.0e-06,
"Coefficient a in model", &*pl);
260 Teuchos::setDoubleParameter(
261 "IC x0", 2.0,
"Initial Condition for x0", &*pl);
262 Teuchos::setDoubleParameter(
263 "IC x1", 0.0,
"Initial Condition for x1", &*pl);
264 Teuchos::setDoubleParameter(
265 "IC t0", 0.0,
"Initial time t0", &*pl);
271 template<
class Scalar>
276 if (!acceptModelParams_) {
277 return Teuchos::null;
282 else if (l == 1 || l == 2)
284 return Teuchos::null;
287 template<
class Scalar>
292 if (!acceptModelParams_) {
293 return Teuchos::null;
299 p_strings->push_back(
"Model Coefficient: epsilon");
301 p_strings->push_back(
"DxDp");
303 p_strings->push_back(
"Dx_dotDp");
307 template<
class Scalar>
316 template<
class Scalar>
324 using Teuchos::rcp_dynamic_cast;
326 "Error, setupInOutArgs_ must be called first!\n");
329 inArgs.
get_x().assert_not_null();
334 Scalar eps = epsilon_;
336 if (acceptModelParams_) {
339 if (p_in != Teuchos::null) {
343 if (inArgs.
get_p(1) != Teuchos::null) {
345 rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(1),
true)->getMultiVector();
347 if (inArgs.
get_p(2) != Teuchos::null) {
349 rcp_dynamic_cast<
const DMVPV>(inArgs.
get_p(2),
true)->getMultiVector();
356 if (acceptModelParams_) {
366 f_out_view[0] = x_in_view[1];
367 f_out_view[1] = -x_in_view[0]/eps;
371 DfDp_out_view(0,0) = 0.0;
372 DfDp_out_view(1,0) = x_in_view[0]/(eps*eps);
375 if (useDfDpAsTangent_ && !
is_null(dxdp_in)) {
377 DfDp_out_view(0,0) += dxdp(1,0);
378 DfDp_out_view(1,0) += -dxdp(0,0)/eps;
382 if (useProductVector_ ==
false) {
388 W_view(1,0) = -beta/eps;
408 W01_view(0,0) = beta;
409 W10_view(0,0) = -beta/eps;
418 x_dot_in = inArgs.
get_x_dot().assert_not_null();
424 f_out_view[0] = x_dot_in_view[0] - x_in_view[1];
425 f_out_view[1] = x_dot_in_view[1] + x_in_view[0]/eps;
429 DfDp_out_view(0,0) = 0.0;
430 DfDp_out_view(1,0) = -x_in_view[0]/(eps*eps);
433 if (useDfDpAsTangent_ && !
is_null(dxdotdp_in)) {
435 DfDp_out_view(0,0) += dxdotdp(0,0);
436 DfDp_out_view(1,0) += dxdotdp(1,0);
438 if (useDfDpAsTangent_ && !
is_null(dxdp_in)) {
440 DfDp_out_view(0,0) += -dxdp(1,0);
441 DfDp_out_view(1,0) += dxdp(0,0)/eps;
445 if (useProductVector_ ==
false) {
451 W_view(1,0) = beta/eps;
470 W00_view(0,0) = alpha;
471 W01_view(0,0) = -beta;
472 W10_view(0,0) = beta/eps;
473 W11_view(0,0) = alpha;
482 #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
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)
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
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