42 #ifndef THYRA_TPETRA_LINEAR_OP_HPP
43 #define THYRA_TPETRA_LINEAR_OP_HPP
50 #include "Tpetra_CrsMatrix.hpp"
52 #ifdef HAVE_THYRA_TPETRA_EPETRA
59 #ifdef HAVE_THYRA_TPETRA_EPETRA
65 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal>
66 class GetTpetraEpetraRowMatrixWrapper {
68 template<
class TpetraMatrixType>
70 RCP<Tpetra::EpetraRowMatrix<TpetraMatrixType> >
71 get(
const RCP<TpetraMatrixType> &tpetraMatrix)
81 class GetTpetraEpetraRowMatrixWrapper<double, int, int> {
83 template<
class TpetraMatrixType>
85 RCP<Tpetra::EpetraRowMatrix<TpetraMatrixType> >
86 get(
const RCP<TpetraMatrixType> &tpetraMatrix)
89 new Tpetra::EpetraRowMatrix<TpetraMatrixType>(tpetraMatrix,
99 #endif // HAVE_THYRA_TPETRA_EPETRA
102 template <
class Scalar>
109 Exceptions::OpNotSupported,
111 ", Tpetra does not support conjugation without transposition."
117 template <
class Scalar>
124 case CONJ:
return convertConjNoTransToTeuchosTransMode<Scalar>();
137 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
142 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
144 const RCP<
const VectorSpaceBase<Scalar> > &rangeSpace,
145 const RCP<
const VectorSpaceBase<Scalar> > &domainSpace,
146 const RCP<Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraOperator
149 initializeImpl(rangeSpace, domainSpace, tpetraOperator);
153 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
155 const RCP<
const VectorSpaceBase<Scalar> > &rangeSpace,
156 const RCP<
const VectorSpaceBase<Scalar> > &domainSpace,
157 const RCP<
const Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> > &tpetraOperator
160 initializeImpl(rangeSpace, domainSpace, tpetraOperator);
164 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
168 return tpetraOperator_.getNonconstObj();
172 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
176 return tpetraOperator_;
183 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
191 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
202 #ifdef HAVE_THYRA_TPETRA_EPETRA
205 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
208 const Ptr<EOpTransp> &epetraOpTransp,
209 const Ptr<EApplyEpetraOpAs> &epetraOpApplyAs,
210 const Ptr<EAdjointEpetraOp> &epetraOpAdjointSupport
217 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
218 void TpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getEpetraOpView(
219 const Ptr<RCP<const Epetra_Operator> > &epetraOp,
220 const Ptr<EOpTransp> &epetraOpTransp,
221 const Ptr<EApplyEpetraOpAs> &epetraOpApplyAs,
222 const Ptr<EAdjointEpetraOp> &epetraOpAdjointSupport
225 using Teuchos::rcp_dynamic_cast;
226 typedef Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> TpetraRowMatrix_t;
227 if (
nonnull(tpetraOperator_)) {
229 epetraOp_ = GetTpetraEpetraRowMatrixWrapper<Scalar,LocalOrdinal,GlobalOrdinal>::get(
230 rcp_dynamic_cast<const TpetraRowMatrix_t>(tpetraOperator_.getConstObj(),
true));
232 *epetraOp = epetraOp_;
235 *epetraOpAdjointSupport = ( tpetraOperator_->hasTransposeApply()
244 #endif // HAVE_THYRA_TPETRA_EPETRA
250 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
252 Thyra::EOpTransp M_trans)
const
260 if (M_trans == CONJ) {
266 return tpetraOperator_->hasTransposeApply();
270 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
272 const Thyra::EOpTransp M_trans,
273 const Thyra::MultiVectorBase<Scalar> &X_in,
274 const Teuchos::Ptr<Thyra::MultiVectorBase<Scalar> > &Y_inout,
279 using Teuchos::rcpFromRef;
280 using Teuchos::rcpFromPtr;
283 typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>
289 ConverterT::getConstTpetraMultiVector(rcpFromRef(X_in));
292 ConverterT::getTpetraMultiVector(rcpFromPtr(Y_inout));
294 const Teuchos::ETransp tTransp = convertToTeuchosTransMode<Scalar>(M_trans);
298 tpetraOperator_->apply(*tX, *tY, tTransp, alpha, beta);
305 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
312 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
319 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
324 using Teuchos::rcpFromRef;
330 Teuchos::rcp_dynamic_cast<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(tpetraOperator_.getNonconstObj(),
true);
332 rowMatrix->leftScale(*row_scaling);
336 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
341 using Teuchos::rcpFromRef;
347 Teuchos::rcp_dynamic_cast<Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(tpetraOperator_.getNonconstObj(),
true);
349 rowMatrix->rightScale(*col_scaling);
355 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
358 const RowStatLinearOpBaseUtils::ERowStat rowStat)
const
364 case RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM:
365 case RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM:
375 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
377 const RowStatLinearOpBaseUtils::ERowStat rowStat,
378 const Ptr<VectorBase<Scalar> > &rowStatVec_in
381 typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>
384 typedef typename STS::magnitudeType MT;
387 if ( (rowStat == RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM) ||
388 (rowStat == RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM) ) {
404 Teuchos::rcp_dynamic_cast<
const Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >(tpetraOperator_.getConstObj(),
true);
409 TEUCHOS_ASSERT(tCrsMatrix->getRowMap()->isSameAs(*tCrsMatrix->getRangeMap()));
410 TEUCHOS_ASSERT(tCrsMatrix->getRowMap()->isSameAs(*tRowSumVec->getMap()));
412 size_t numMyRows = tCrsMatrix->getNodeNumRows();
417 for (
size_t row=0; row < numMyRows; ++row) {
418 MT sum = STM::zero ();
419 tCrsMatrix->getLocalRowView (row, indices, values);
421 for (
int col = 0; col < values.
size(); ++col) {
422 sum += STS::magnitude (values[col]);
425 if (rowStat == RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM) {
426 if (sum < STM::sfmin ()) {
428 "Error - Thyra::TpetraLinearOp::getRowStatImpl() - Inverse row sum "
429 <<
"requested for a matrix where one of the rows has a zero row sum!");
430 sum = STM::one () / STM::sfmin ();
433 sum = STM::one () / sum;
437 tRowSumVec->replaceLocalValue (row, Scalar (sum));
443 "Error - Thyra::TpetraLinearOp::getRowStatImpl() - Column sum support not implemented!");
451 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
452 template<
class TpetraOperator_t>
454 const RCP<
const VectorSpaceBase<Scalar> > &rangeSpace,
455 const RCP<
const VectorSpaceBase<Scalar> > &domainSpace,
465 rangeSpace_ = rangeSpace;
466 domainSpace_ = domainSpace;
467 tpetraOperator_ = tpetraOperator;
474 #endif // THYRA_TPETRA_LINEAR_OP_HPP
bool is_null(const boost::shared_ptr< T > &p)
void initializeImpl(const RCP< const VectorSpaceBase< Scalar > > &rangeSpace, const RCP< const VectorSpaceBase< Scalar > > &domainSpace, const RCP< TpetraOperator_t > &tpetraOperator)
void constInitialize(const RCP< const VectorSpaceBase< Scalar > > &rangeSpace, const RCP< const VectorSpaceBase< Scalar > > &domainSpace, const RCP< const Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraOperator)
Initialize.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void getRowStatImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat, const Ptr< VectorBase< Scalar > > &rowStatVec) const
bool opSupportedImpl(Thyra::EOpTransp M_trans) const
RCP< const Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getConstTpetraOperator() const
Get embedded const Tpetra::Operator.
void applyImpl(const Thyra::EOpTransp M_trans, const Thyra::MultiVectorBase< Scalar > &X_in, const Teuchos::Ptr< Thyra::MultiVectorBase< Scalar > > &Y_inout, const Scalar alpha, const Scalar beta) const
virtual bool rowStatIsSupportedImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual bool supportsScaleLeftImpl() const
RCP< const Thyra::VectorSpaceBase< Scalar > > range() const
RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetraOperator()
Get embedded non-const Tpetra::Operator.
Teuchos::ETransp convertConjNoTransToTeuchosTransMode()
TpetraLinearOp()
Construct to uninitialized.
Teuchos::ETransp convertToTeuchosTransMode(const Thyra::EOpTransp transp)
RCP< const Epetra_Comm > get_Epetra_Comm(const Teuchos::Comm< Ordinal > &comm)
Get (or create) and Epetra_Comm given a Teuchos::Comm object.
virtual void scaleLeftImpl(const VectorBase< Scalar > &row_scaling)
bool nonnull(const boost::shared_ptr< T > &p)
virtual void scaleRightImpl(const VectorBase< Scalar > &col_scaling)
virtual bool supportsScaleRightImpl() const
void initialize(const RCP< const VectorSpaceBase< Scalar > > &rangeSpace, const RCP< const VectorSpaceBase< Scalar > > &domainSpace, const RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraOperator)
Initialize.
RCP< const Teuchos::Comm< Ordinal > > convertTpetraToThyraComm(const RCP< const Teuchos::Comm< int > > &tpetraComm)
Given an Tpetra Teuchos::Comm<int> object, return an equivalent Teuchos::Comm<Ordinal> object...
#define TEUCHOS_ASSERT(assertion_test)
RCP< const Thyra::VectorSpaceBase< Scalar > > domain() const
Concrete Thyra::LinearOpBase subclass for Tpetra::Operator.
Apply using Epetra_Operator::Apply(...)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)