// @HEADER // ***************************************************************************** // Belos: Block Linear Solvers Package // // Copyright 2004-2016 NTESS and the Belos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef BELOS_XPETRA_ADAPTER_OPERATOR_HPP #define BELOS_XPETRA_ADAPTER_OPERATOR_HPP //Note: using MACRO HAVE_XPETRA_ instead of HAVE_MUELU_ because this file will eventually be moved to Xpetra #include "Xpetra_ConfigDefs.hpp" #ifdef HAVE_XPETRA_EPETRA #include #include #endif #include namespace Belos { using Teuchos::RCP; using Teuchos::rcpFromRef; // //! @name MueLu Adapter Exceptions //@{ /** \brief XpetraOpFailure is thrown when a return value from an MueLu * call on an Xpetra::Operator or MueLu::Hierarchy is non-zero. */ class XpetraOpFailure : public BelosError {public: XpetraOpFailure(const std::string& what_arg) : BelosError(what_arg) {}}; //@} //! @name Belos operator for Xpetra //@{ /*! @class XpetraOp * * @brief Implementation of the Belos::XpetraOp. It derives from the Belos::OperatorT templated on * the Xpetra::MultiVector and the Tpetra::MultiVector (if Teptra is enabled) * Note, in contrast to Belos::MueLuOp this operator administrates an Xpetra::Matrix<> object * and implements the effect of a vector applied to the stored matrix. * * The Belos::OperatorT class is a generalization of the Belos::Operator<> class, which * deals with any kind of vector (not only Belos::MultiVec as the Belos::Operator<> interface does). * * This is the general implementation for Tpetra only. */ template class XpetraOp : public OperatorT > #ifdef HAVE_XPETRA_TPETRA , public OperatorT > #endif { public: //! @name Constructor/Destructor //@{ //! Default constructor XpetraOp (const RCP > & Op) : Op_(Op) {} //! Destructor. virtual ~XpetraOp() {}; //@} //! @name Operator application method //@{ /*! \brief This routine takes the Xpetra::MultiVector \c x and applies the operator to it resulting in the Xpetra::MultiVector \c y, which is returned. \note It is expected that any problem with applying this operator to \c x will be indicated by an std::exception being thrown. */ void Apply ( const Xpetra::MultiVector& x, Xpetra::MultiVector& y, ETrans trans=NOTRANS ) const { TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, "Belos::XpetraOp::Apply, transpose mode != NOTRANS not supported."); //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). y.putScalar(0.0); Op_->apply(x,y); } #ifdef HAVE_XPETRA_TPETRA // TO SKIP THE TRAIT IMPLEMENTATION OF XPETRA::MULTIVECTOR /*! \brief This routine takes the Tpetra::MultiVector \c x and applies the operator to it resulting in the Tpetra::MultiVector \c y, which is returned. \note It is expected that any problem with applying this operator to \c x will be indicated by an std::exception being thrown. */ void Apply ( const Tpetra::MultiVector& x, Tpetra::MultiVector& y, ETrans trans=NOTRANS ) const { TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, "Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported."); Tpetra::MultiVector & temp_x = const_cast &>(x); const Xpetra::TpetraMultiVector tX(rcpFromRef(temp_x)); Xpetra::TpetraMultiVector tY(rcpFromRef(y)); //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). tY.putScalar(0.0); Op_->apply(tX,tY); } #endif RCP > getOperator() const { return Op_; } private: RCP > Op_; }; #ifdef HAVE_XPETRA_EPETRA #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES /*! @class XpetraOp * * @brief Implementation of the Belos::XpetraOp. It derives from the Belos::OperatorT templated on * the Xpetra::MultiVector and/or the Tpetra::MultiVector (if Teptra is enabled) and/or the * EpetraMultiVector (if Epetra is enabled) * * This is the specialization for */ template <> class XpetraOp : public OperatorT > #ifdef HAVE_XPETRA_TPETRA #if !((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) , public OperatorT > #endif #endif #ifdef HAVE_XPETRA_EPETRA , public OperatorT #endif { typedef double Scalar; typedef int LocalOrdinal; typedef int GlobalOrdinal; typedef Xpetra::EpetraNode Node; public: XpetraOp(const RCP > & Op) : Op_(Op) {} virtual ~XpetraOp() {}; void Apply ( const Xpetra::MultiVector& x, Xpetra::MultiVector& y, ETrans trans=NOTRANS ) const { TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, "Belos::XpetraOp::Apply, transpose mode != NOTRANS not supported."); //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). y.putScalar(0.0); Op_->apply(x,y); } #ifdef HAVE_XPETRA_TPETRA #if !((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) void Apply ( const Tpetra::MultiVector& x, Tpetra::MultiVector& y, ETrans trans=NOTRANS ) const { TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, "Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported."); Tpetra::MultiVector & temp_x = const_cast &>(x); const Xpetra::TpetraMultiVector tX(rcpFromRef(temp_x)); Xpetra::TpetraMultiVector tY(rcpFromRef(y)); //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). tY.putScalar(0.0); Op_->apply(tX,tY); } #endif #endif #ifdef HAVE_XPETRA_EPETRA // TO SKIP THE TRAIT IMPLEMENTATION OF XPETRA::MULTIVECTOR /*! \brief This routine takes the Epetra_MultiVector \c x and applies the operator to it resulting in the Epetra_MultiVector \c y, which is returned. \note It is expected that any problem with applying this operator to \c x will be indicated by an std::exception being thrown. */ void Apply ( const Epetra_MultiVector& x, Epetra_MultiVector& y, ETrans trans=NOTRANS ) const { TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, "Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported."); Epetra_MultiVector & temp_x = const_cast(x); const Xpetra::EpetraMultiVectorT tX(rcpFromRef(temp_x)); Xpetra::EpetraMultiVectorT tY(rcpFromRef(y)); //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). tY.putScalar(0.0); Op_->apply(tX,tY); } #endif RCP > getOperator() const { return Op_; } private: RCP > Op_; }; #endif // !EPETRA_NO_32BIT_GLOBAL_INDICES #endif // HAVE_XPETRA_EPETRA #ifdef HAVE_XPETRA_EPETRA #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES /*! @class XpetraOp * * @brief Implementation of the Belos::XpetraOp. It derives from the Belos::OperatorT templated on * the Xpetra::MultiVector and/or the Tpetra::MultiVector (if Teptra is enabled) and/or the * EpetraMultiVector (if Epetra64 is enabled). Please be aware that Epetra64 is not supported * by MueLu. Don't expect it to work or produce reasonable results. * * This is the specialization for */ template <> class XpetraOp : public OperatorT > #ifdef HAVE_XPETRA_TPETRA #if !((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \ (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG)))) , public OperatorT > #endif #endif #ifdef HAVE_XPETRA_EPETRA , public OperatorT #endif { typedef double Scalar; typedef int LocalOrdinal; typedef long long GlobalOrdinal; typedef Xpetra::EpetraNode Node; public: XpetraOp(const RCP > & Op) : Op_(Op) {} virtual ~XpetraOp() {}; void Apply ( const Xpetra::MultiVector& x, Xpetra::MultiVector& y, ETrans trans=NOTRANS ) const { TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, "Belos::XpetraOp::Apply, transpose mode != NOTRANS not supported."); //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). y.putScalar(0.0); Op_->apply(x,y); } #ifdef HAVE_XPETRA_TPETRA #if !((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \ (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG)))) void Apply ( const Tpetra::MultiVector& x, Tpetra::MultiVector& y, ETrans trans=NOTRANS ) const { TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, "Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported."); Tpetra::MultiVector & temp_x = const_cast &>(x); const Xpetra::TpetraMultiVector tX(rcpFromRef(temp_x)); Xpetra::TpetraMultiVector tY(rcpFromRef(y)); //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). tY.putScalar(0.0); Op_->apply(tX,tY); } #endif #endif #ifdef HAVE_XPETRA_EPETRA // TO SKIP THE TRAIT IMPLEMENTATION OF XPETRA::MULTIVECTOR /*! \brief This routine takes the Epetra_MultiVector \c x and applies the operator to it resulting in the Epetra_MultiVector \c y, which is returned. \note It is expected that any problem with applying this operator to \c x will be indicated by an std::exception being thrown. */ void Apply ( const Epetra_MultiVector& x, Epetra_MultiVector& y, ETrans trans=NOTRANS ) const { TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, "Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported."); Epetra_MultiVector & temp_x = const_cast(x); const Xpetra::EpetraMultiVectorT tX(rcpFromRef(temp_x)); Xpetra::EpetraMultiVectorT tY(rcpFromRef(y)); //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). tY.putScalar(0.0); Op_->apply(tX,tY); } #endif RCP > getOperator() const { return Op_; } private: RCP > Op_; }; #endif // !EPETRA_NO_64BIT_GLOBAL_INDICES #endif // HAVE_XPETRA_EPETRA //@} } // namespace Belos #endif // BELOS_XPETRA_ADAPTER_OPERATOR_HPP