// @HEADER // ***************************************************************************** // MueLu: A package for multigrid based preconditioning // // Copyright 2012 NTESS and the MueLu contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef XPETRA_HIERARCHICALOPERATOR_DECL_HPP #define XPETRA_HIERARCHICALOPERATOR_DECL_HPP #include #include #include #include #include #include #include #include "Xpetra_OperatorWithDiagonal.hpp" #include "Xpetra_RowMatrix.hpp" namespace Xpetra { template class HierarchicalOperator : public OperatorWithDiagonal { public: using tHOp = Tpetra::HierarchicalOperator; using map_type = Xpetra::Map; using mv_type = Xpetra::MultiVector; using matrix_type = Xpetra::Matrix; using blocked_matrix_type = Xpetra::TpetraBlockedMatrix; //! @name Constructor/Destructor //@{ //! Constructor HierarchicalOperator(const RCP& op) : op_(op) { this->setTpetra_RowMatrix(op); } HierarchicalOperator(const RCP& nearField, const RCP& kernelApproximations, const RCP& basisMatrix, std::vector >& transferMatrices, const Teuchos::RCP& params = Teuchos::null); //! Returns the Tpetra::Map object associated with the domain of this operator. const Teuchos::RCP getDomainMap() const { return toXpetra(op_->getDomainMap()); } //! Returns the Tpetra::Map object associated with the range of this operator. const Teuchos::RCP getRangeMap() const { return toXpetra(op_->getRangeMap()); } //! \brief Computes the operator-multivector application. /*! Loosely, performs \f$Y = \alpha \cdot A^{\textrm{mode}} \cdot X + \beta \cdot Y\f$. However, the details of operation vary according to the values of \c alpha and \c beta. Specifically - if beta == 0, apply() must overwrite \c Y, so that any values in \c Y (including NaNs) are ignored. - if alpha == 0, apply() may short-circuit the operator, so that any values in \c X (including NaNs) are ignored. */ void apply(const mv_type& X, mv_type& Y, Teuchos::ETransp mode = Teuchos::NO_TRANS, Scalar alpha = Teuchos::ScalarTraits::one(), Scalar beta = Teuchos::ScalarTraits::zero()) const { op_->apply(Xpetra::toTpetra(X), Xpetra::toTpetra(Y), mode, alpha, beta); } //! Compute a residual R = B - (*this) * X void residual(const mv_type& X, const mv_type& B, mv_type& R) const { Tpetra::Details::residual(*op_, toTpetra(X), toTpetra(B), toTpetra(R)); } RCP > restrict(const RCP& P) { using TpCrs = TpetraCrsMatrix; using CrsWrap = CrsMatrixWrap; return Teuchos::rcp(new HierarchicalOperator(op_->restrict(Teuchos::rcp_dynamic_cast(Teuchos::rcp_dynamic_cast(P)->getCrsMatrix(), true)->getTpetra_CrsMatrixNonConst()))); } RCP toMatrix() { using TpCrs = TpetraCrsMatrix; using CrsWrap = CrsMatrixWrap; auto tpMat = Teuchos::rcp(new TpCrs(op_->toMatrix())); return Teuchos::rcp(new CrsWrap(Teuchos::rcp_dynamic_cast >(tpMat))); } double getCompression() { return op_->getCompression(); } void setDebugOutput(const bool debugOutput) { op_->setDebugOutput(debugOutput); } RCP nearFieldMatrix() { auto tpMat = Teuchos::rcp(new TpetraCrsMatrix(op_->nearFieldMatrix())); return Teuchos::rcp(new CrsMatrixWrap(Teuchos::rcp_dynamic_cast >(tpMat))); } //! Gets the operator out // RCP > getTpetra_RowMatrix() const override { return op_; } // RCP > getTpetra_RowMatrixNonConst() const override { return op_; } void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel) const { describe(out, verbLevel, true); } void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel, const bool printHeader) const { op_->describe(out, verbLevel, printHeader); } bool hasFarField() const { return op_->hasFarField(); } bool denserThanDenseMatrix() const { return op_->denserThanDenseMatrix(); } private: RCP op_; }; } // namespace Xpetra #endif // XPETRA_HIERARCHICALOPERATOR_DECL_HPP