10 #ifndef Thyra_TpetraExplicitAdjointModelEvaluator_hpp
11 #define Thyra_TpetraExplicitAdjointModelEvaluator_hpp
13 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
15 #include "Tpetra_RowMatrixTransposer.hpp"
29 template <
typename Scalar,
typename LocalOrdinal,
typename GlobalOrdinal=LocalOrdinal,
typename Node=Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
31 public ModelEvaluatorDelegatorBase<Scalar>{
36 const RCP<
const ModelEvaluator<Scalar> >& model) :
37 ModelEvaluatorDelegatorBase<Scalar>(model) {}
41 const RCP<ModelEvaluator<Scalar> >& model) :
42 ModelEvaluatorDelegatorBase<Scalar>(model) {}
54 ModelEvaluatorBase::InArgsSetup<Scalar> inArgs =
55 this->getUnderlyingModel()->createInArgs();
56 inArgs.setModelEvalDescription(this->description());
62 typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> TO;
63 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> TCM;
64 typedef Tpetra::RowMatrixTransposer<Scalar,LocalOrdinal,GlobalOrdinal,Node> TRMT;
66 thyra_fwd_op = this->getUnderlyingModel()->create_W_op();
69 RCP<TO> tpetra_fwd_op = thyra_tpetra_fwd_op->getTpetraOperator();
71 Teuchos::rcp_dynamic_cast<TCM>(tpetra_fwd_op,
true);
72 TRMT transposer(tpetra_fwd_mat);
73 RCP<TCM> tpetra_trans_mat = transposer.createTranspose();
74 return tpetraLinearOp(thyra_op->range(), thyra_op->domain(),
84 typedef ModelEvaluatorBase MEB;
85 MEB::OutArgs<Scalar> model_outArgs =
86 this->getUnderlyingModel()->createOutArgs();
87 MEB::OutArgsSetup<Scalar> outArgs;
88 outArgs.setModelEvalDescription(this->description());
89 outArgs.setSupports(MEB::OUT_ARG_f);
90 outArgs.setSupports(MEB::OUT_ARG_W_op);
96 const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
97 const ModelEvaluatorBase::OutArgs<Scalar> &outArgs)
const
99 typedef ModelEvaluatorBase MEB;
101 typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> TO;
102 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> TCM;
103 typedef Tpetra::RowMatrixTransposer<Scalar,LocalOrdinal,GlobalOrdinal,Node> TRMT;
105 MEB::OutArgs<Scalar> model_outArgs =
106 this->getUnderlyingModel()->createOutArgs();
108 if (model_outArgs.supports(MEB::OUT_ARG_W_op) &&
112 thyra_fwd_op = this->getUnderlyingModel()->create_W_op();
114 this->getUnderlyingModel()->evalModel(inArgs, model_outArgs);
121 RCP<TO> tpetra_fwd_op = thyra_tpetra_fwd_op->getTpetraOperator();
123 Teuchos::rcp_dynamic_cast<TCM>(tpetra_fwd_op,
true);
124 TRMT transposer(tpetra_fwd_mat);
125 RCP<TCM> tpetra_trans_mat = transposer.createTranspose();
128 RCP<LOB> thyra_adj_op = outArgs.get_W_op();
130 Teuchos::rcp_dynamic_cast<TLO>(thyra_adj_op,
true);
131 RCP<TO> tpetra_adj_op = thyra_tpetra_adj_op->getTpetraOperator();
133 Teuchos::rcp_dynamic_cast<TCM>(tpetra_adj_op,
true);
134 *tpetra_adj_mat = *tpetra_trans_mat;
140 template <
typename Scalar>
141 RCP<TpetraExplicitAdjointModelEvaluator<Scalar> >
143 const RCP<
const ModelEvaluator<Scalar> >& model)
148 template <
typename Scalar>
149 RCP<TpetraExplicitAdjointModelEvaluator<Scalar> >
151 const RCP<ModelEvaluator<Scalar> >& model)
void evalModelImpl(const ModelEvaluatorBase::InArgs< Scalar > &inArgs, const ModelEvaluatorBase::OutArgs< Scalar > &outArgs) const
RCP< Thyra::LinearOpBase< Scalar > > thyra_fwd_op
ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
RCP< LinearOpBase< Scalar > > create_W_op() const
virtual ~TpetraExplicitAdjointModelEvaluator()=default
Destructor.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
A model evaluator decorator for computing an explicit adjoint.
ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
#define TEUCHOS_ASSERT(assertion_test)
Concrete Thyra::LinearOpBase subclass for Tpetra::Operator.
TpetraExplicitAdjointModelEvaluator(const RCP< const ModelEvaluator< Scalar > > &model)
Constructor.
TpetraExplicitAdjointModelEvaluator(const RCP< ModelEvaluator< Scalar > > &model)
Constructor.
RCP< TpetraExplicitAdjointModelEvaluator< Scalar > > tpetraExplicitAdjointModelEvaluator(const RCP< const ModelEvaluator< Scalar > > &model)