45 #ifndef THYRA_SIMPLE_2D_MODEL_EVALUATOR_DEF_HPP
46 #define THYRA_SIMPLE_2D_MODEL_EVALUATOR_DEF_HPP
49 #include "Thyra_Simple2DModelEvaluator_decl.hpp"
50 #include "Thyra_SimpleDenseLinearOp.hpp"
51 #include "Thyra_DefaultSpmdVectorSpace.hpp"
52 #include "Thyra_DefaultSerialDenseLinearOpWithSolveFactory.hpp"
53 #include "Thyra_DefaultPreconditioner.hpp"
54 #include "Thyra_DetachedMultiVectorView.hpp"
55 #include "Thyra_DetachedVectorView.hpp"
56 #include "Thyra_MultiVectorStdOps.hpp"
57 #include "Thyra_VectorStdOps.hpp"
66 template<
class Scalar>
68 simple2DModelEvaluator()
77 template<
class Scalar>
84 template<
class Scalar>
94 template<
class Scalar>
101 x0.sv().values()().assign(x0_in);
105 template<
class Scalar>
108 showGetInvalidArg_ = showGetInvalidArg;
115 template<
class Scalar>
123 template<
class Scalar>
131 template<
class Scalar>
135 return nominalValues_;
139 template<
class Scalar>
143 return createNonconstSimpleDenseLinearOp<Scalar>(
144 createMembers<Scalar>(f_space_, x_space_->dim())
149 template<
class Scalar>
153 return nonconstUnspecifiedPrec<Scalar>(
154 createNonconstSimpleDenseLinearOp<Scalar>(
155 createMembers<Scalar>(f_space_, x_space_->dim())
161 template<
class Scalar>
169 template<
class Scalar>
173 return prototypeInArgs_;
180 template<
class Scalar>
184 return prototypeOutArgs_;
188 template<
class Scalar>
189 void Simple2DModelEvaluator<Scalar>::evalModelImpl(
194 using Teuchos::rcp_dynamic_cast;
195 const Scalar one = 1.0, two = 2.0, zero = 0.0;
197 const ConstDetachedVectorView<Scalar> x(inArgs.
get_x());
199 const RCP<Thyra::VectorBase<Scalar> > f_out = outArgs.
get_f();
200 const RCP<Thyra::LinearOpBase< Scalar > > W_op_out = outArgs.
get_W_op();
201 const RCP<Thyra::PreconditionerBase< Scalar > > W_prec_out = outArgs.
get_W_prec();
204 const DetachedVectorView<Scalar> f(f_out);
205 f[0] = x[0] + x[1] * x[1] - p_[0];
206 f[1] = d_ * (x[0] * x[0] - x[1] - p_[1]);
210 const RCP<SimpleDenseLinearOp<Scalar> > W =
211 rcp_dynamic_cast<SimpleDenseLinearOp<Scalar> >(W_op_out,
true);
212 const RCP<MultiVectorBase<Scalar> > W_mv = W->getNonconstMultiVector();
215 W_dmvv(0, 1) = two * x[1];
216 W_dmvv(1, 0) = d_ * two * x[0];
221 const RCP<SimpleDenseLinearOp<Scalar> > W_prec_op =
222 rcp_dynamic_cast<SimpleDenseLinearOp<Scalar> >(
223 W_prec_out->getNonconstUnspecifiedPrecOp(),
true);
224 const RCP<MultiVectorBase<Scalar> > W_prec_mv = W_prec_op->getNonconstMultiVector();
227 W_prec_dmvv(0, 0) = one;
228 W_prec_dmvv(0, 1) = zero;
229 W_prec_dmvv(1, 0) = zero;
230 W_prec_dmvv(1, 1) = -one/d_;
239 template<
class Scalar>
240 Simple2DModelEvaluator<Scalar>::Simple2DModelEvaluator()
241 : x_space_(Thyra::defaultSpmdVectorSpace<Scalar>(2)),
243 W_factory_(Thyra::defaultSerialDenseLinearOpWithSolveFactory<Scalar>()),
245 p_(x_space_->dim(), Teuchos::ScalarTraits<Scalar>::zero()),
246 showGetInvalidArg_(false)
251 using Thyra::createMember;
255 MEB::InArgsSetup<Scalar> inArgs;
256 inArgs.setModelEvalDescription(this->
description());
257 inArgs.setSupports(MEB::IN_ARG_x);
258 prototypeInArgs_ = inArgs;
260 MEB::OutArgsSetup<Scalar> outArgs;
261 outArgs.setModelEvalDescription(this->
description());
262 outArgs.setSupports(MEB::OUT_ARG_f);
263 outArgs.setSupports(MEB::OUT_ARG_W_op);
264 outArgs.setSupports(MEB::OUT_ARG_W_prec);
265 prototypeOutArgs_ = outArgs;
267 nominalValues_ = inArgs;
268 x0_ = createMember(x_space_);
269 V_S(x0_.
ptr(), ST::zero());
270 nominalValues_.set_x(x0_);
273 set_p(Teuchos::tuple<Scalar>(2.0, 0.0)());
274 set_x0(Teuchos::tuple<Scalar>(1.0, 1.0)());
288 #define SIMPLE_2D_MODEL_EVALUATOR_INSTANT(SCALAR) \
290 template class Simple2DModelEvaluator<SCALAR >; \
292 template Teuchos::RCP<Simple2DModelEvaluator<SCALAR > > \
293 simple2DModelEvaluator(); \
296 #endif // THYRA_SIMPLE_2D_MODEL_EVALUATOR_DEF_HPP
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
Teuchos::RCP< Thyra::PreconditionerBase< Scalar > > create_W_prec() const
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
Evaluation< VectorBase< Scalar > > get_f() const
Precondition: supports(OUT_ARG_f)==true.
void set_p(const Teuchos::ArrayView< const Scalar > &p)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
Create an explicit mutable (non-const) view of a MultiVectorBase object.
void set_d(const Scalar &d)
void set_x0(const Teuchos::ArrayView< const Scalar > &x0)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Create an explicit mutable (non-const) view of a VectorBase object.
void setShowGetInvalidArgs(bool showGetInvalidArg)
virtual std::string description() const
Abstract interface for finite-dimensional dense vectors.
Simple 2d simulation only ModelEvaluator for f(x) = 0.
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
Base subclass for ModelEvaluator that defines some basic types.
bool nonnull(const boost::shared_ptr< T > &p)
RCP< PreconditionerBase< Scalar > > get_W_prec() const
Precondition: supports(OUT_ARG_W_op)==true.
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
RCP< LinearOpBase< Scalar > > get_W_op() const
Precondition: supports(OUT_ARG_W_op)==true.
RCP< const VectorBase< Scalar > > get_x() const
Precondition: supports(IN_ARG_x)==true.
Concrete aggregate class for all input arguments computable by a ModelEvaluator subclass object...