10 #ifndef THYRA_TPETRA_LINEAR_OP_HPP
11 #define THYRA_TPETRA_LINEAR_OP_HPP
13 #include "Thyra_TpetraLinearOp_decl.hpp"
14 #include "Thyra_TpetraVectorSpace.hpp"
15 #include "Teuchos_ScalarTraits.hpp"
16 #include "Teuchos_TypeNameTraits.hpp"
18 #include "Tpetra_CrsMatrix.hpp"
20 #ifdef HAVE_THYRA_TPETRA_EPETRA
27 #ifdef HAVE_THYRA_TPETRA_EPETRA
33 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal>
34 class GetTpetraEpetraRowMatrixWrapper {
36 template<
class TpetraMatrixType>
38 RCP<Tpetra::EpetraRowMatrix<TpetraMatrixType> >
39 get(
const RCP<TpetraMatrixType> &tpetraMatrix)
49 class GetTpetraEpetraRowMatrixWrapper<double, int, int> {
51 template<
class TpetraMatrixType>
53 RCP<Tpetra::EpetraRowMatrix<TpetraMatrixType> >
54 get(
const RCP<TpetraMatrixType> &tpetraMatrix)
57 new Tpetra::EpetraRowMatrix<TpetraMatrixType>(tpetraMatrix,
67 #endif // HAVE_THYRA_TPETRA_EPETRA
70 template <
class Scalar>
73 convertConjNoTransToTeuchosTransMode()
77 Exceptions::OpNotSupported,
79 ", Tpetra does not support conjugation without transposition."
85 template <
class Scalar>
92 case CONJ:
return convertConjNoTransToTeuchosTransMode<Scalar>();
105 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
110 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
117 initializeImpl(rangeSpace, domainSpace, tpetraOperator);
121 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
128 initializeImpl(rangeSpace, domainSpace, tpetraOperator);
132 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
136 return tpetraOperator_.getNonconstObj();
140 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
144 return tpetraOperator_;
151 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
159 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
170 #ifdef HAVE_THYRA_TPETRA_EPETRA
173 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
185 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
186 void TpetraLinearOp<Scalar,LocalOrdinal,GlobalOrdinal,Node>::getEpetraOpView(
187 const Ptr<RCP<const Epetra_Operator> > &epetraOp,
188 const Ptr<EOpTransp> &epetraOpTransp,
189 const Ptr<EApplyEpetraOpAs> &epetraOpApplyAs,
190 const Ptr<EAdjointEpetraOp> &epetraOpAdjointSupport
193 using Teuchos::rcp_dynamic_cast;
195 if (
nonnull(tpetraOperator_)) {
197 epetraOp_ = GetTpetraEpetraRowMatrixWrapper<Scalar,LocalOrdinal,GlobalOrdinal>::get(
198 rcp_dynamic_cast<const TpetraRowMatrix_t>(tpetraOperator_.getConstObj(),
true));
200 *epetraOp = epetraOp_;
203 *epetraOpAdjointSupport = ( tpetraOperator_->hasTransposeApply()
207 *epetraOp = Teuchos::null;
212 #endif // HAVE_THYRA_TPETRA_EPETRA
218 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
228 if (M_trans ==
CONJ) {
234 return tpetraOperator_->hasTransposeApply();
238 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
247 using Teuchos::rcpFromRef;
248 using Teuchos::rcpFromPtr;
257 ConverterT::getConstTpetraMultiVector(rcpFromRef(X_in));
260 ConverterT::getTpetraMultiVector(rcpFromPtr(Y_inout));
262 const Teuchos::ETransp tTransp = convertToTeuchosTransMode<Scalar>(M_trans);
266 tpetraOperator_->apply(*tX, *tY, tTransp, alpha, beta);
273 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
280 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
287 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
292 using Teuchos::rcpFromRef;
300 rowMatrix->leftScale(*row_scaling);
305 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
310 using Teuchos::rcpFromRef;
318 rowMatrix->rightScale(*col_scaling);
325 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
328 const RowStatLinearOpBaseUtils::ERowStat rowStat)
const
334 case RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM:
335 case RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM:
344 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
346 const RowStatLinearOpBaseUtils::ERowStat rowStat,
353 typedef typename STS::magnitudeType MT;
356 if ( (rowStat == RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM) ||
357 (rowStat == RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM) ) {
378 TEUCHOS_ASSERT(tCrsMatrix->getRowMap()->isSameAs(*tCrsMatrix->getRangeMap()));
379 TEUCHOS_ASSERT(tCrsMatrix->getRowMap()->isSameAs(*tRowSumVec->getMap()));
381 size_t numMyRows = tCrsMatrix->getLocalNumRows();
384 typename crs_t::local_inds_host_view_type indices;
385 typename crs_t::values_host_view_type values;
388 for (
size_t row=0; row < numMyRows; ++row) {
389 MT sum = STM::zero ();
390 tCrsMatrix->getLocalRowView (row, indices, values);
392 for (
int col = 0; col < (int) values.size(); ++col) {
393 sum += STS::magnitude (values[col]);
396 if (rowStat == RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM) {
397 if (sum < STM::sfmin ()) {
399 "Error - Thyra::TpetraLinearOp::getRowStatImpl() - Inverse row sum "
400 <<
"requested for a matrix where one of the rows has a zero row sum!");
401 sum = STM::one () / STM::sfmin ();
404 sum = STM::one () / sum;
408 tRowSumVec->replaceLocalValue (row, Scalar (sum));
414 "Error - Thyra::TpetraLinearOp::getRowStatImpl() - Column sum support not implemented!");
423 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
424 template<
class TpetraOperator_t>
437 rangeSpace_ = rangeSpace;
438 domainSpace_ = domainSpace;
439 tpetraOperator_ = tpetraOperator;
446 #endif // THYRA_TPETRA_LINEAR_OP_HPP
bool is_null(const boost::shared_ptr< T > &p)
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
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)
Use the non-transposed operator.
virtual void getRowStatImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat, const Ptr< VectorBase< Scalar > > &rowStatVec) const
bool opSupportedImpl(Thyra::EOpTransp M_trans) const
Use the transposed operator with complex-conjugate clements (same as TRANS for real scalar types)...
Abstract interface for objects that represent a space for vectors.
Use the non-transposed operator with complex-conjugate elements (same as NOTRANS for real scalar type...
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
Use the transposed operator.
virtual bool rowStatIsSupportedImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Interface for a collection of column vectors called a multi-vector.
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.
Abstract interface for finite-dimensional dense vectors.
TpetraLinearOp()
Construct to uninitialized.
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...
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.
#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)