Debian Codegraph @

packages/muelu/research/caglusa/Xpetra_HierarchicalOperator_decl.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #ifndef XPETRA_HIERARCHICALOPERATOR_DECL_HPP
11 #define XPETRA_HIERARCHICALOPERATOR_DECL_HPP
12
13 #include <Tpetra_HierarchicalOperator_decl.hpp>
14 #include <Tpetra_HierarchicalOperator_def.hpp>
15 #include <Xpetra_TpetraOperator.hpp>
16 #include <Xpetra_Map.hpp>
17 #include <Xpetra_MultiVector.hpp>
18 #include <Xpetra_Matrix.hpp>
19 #include <Xpetra_TpetraBlockedMatrix.hpp>
20 #include "Xpetra_OperatorWithDiagonal.hpp"
21 #include "Xpetra_RowMatrix.hpp"
22
23 namespace Xpetra {
24
25 template <class Scalar,
26 class LocalOrdinal,
27 class GlobalOrdinal,
28 class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
29 class HierarchicalOperator : public OperatorWithDiagonal<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
30 public:
31 using tHOp = Tpetra::HierarchicalOperator<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
32 using map_type = Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>;
33 using mv_type = Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
34 using matrix_type = Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
35 using blocked_matrix_type = Xpetra::TpetraBlockedMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
36
37 //! @name Constructor/Destructor
38 //@{
39
40 //! Constructor
41 HierarchicalOperator(const RCP<tHOp>& op)
42 : op_(op) {
43 this->setTpetra_RowMatrix(op);
44 }
45
46 HierarchicalOperator(const RCP<matrix_type>& nearField,
47 const RCP<blocked_matrix_type>& kernelApproximations,
48 const RCP<matrix_type>& basisMatrix,
49 std::vector<RCP<blocked_matrix_type> >& transferMatrices,
50 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
51
52 //! Returns the Tpetra::Map object associated with the domain of this operator.
53 const Teuchos::RCP<const map_type> getDomainMap() const {
54 return toXpetra(op_->getDomainMap());
55 }
56
57 //! Returns the Tpetra::Map object associated with the range of this operator.
58 const Teuchos::RCP<const map_type> getRangeMap() const {
59 return toXpetra(op_->getRangeMap());
60 }
61
62 //! \brief Computes the operator-multivector application.
63 /*! Loosely, performs \f$Y = \alpha \cdot A^{\textrm{mode}} \cdot X + \beta \cdot Y\f$. However, the details of operation
64 vary according to the values of \c alpha and \c beta. Specifically
65 - if <tt>beta == 0</tt>, apply() <b>must</b> overwrite \c Y, so that any values in \c Y (including NaNs) are ignored.
66 - if <tt>alpha == 0</tt>, apply() <b>may</b> short-circuit the operator, so that any values in \c X (including NaNs) are ignored.
67 */
68 void apply(const mv_type& X, mv_type& Y,
69 Teuchos::ETransp mode = Teuchos::NO_TRANS,
70 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
71 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const {
72 op_->apply(Xpetra::toTpetra(X), Xpetra::toTpetra(Y), mode, alpha, beta);
73 }
74
75 //! Compute a residual R = B - (*this) * X
76 void residual(const mv_type& X,
77 const mv_type& B,
78 mv_type& R) const {
79 Tpetra::Details::residual(*op_, toTpetra(X), toTpetra(B), toTpetra(R));
80 }
81
82 RCP<HierarchicalOperator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > restrict(const RCP<matrix_type>& P) {
83 using TpCrs = TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
84 using CrsWrap = CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
85 return Teuchos::rcp(new HierarchicalOperator<Scalar, LocalOrdinal, GlobalOrdinal, Node>(op_->restrict(Teuchos::rcp_dynamic_cast<TpCrs>(Teuchos::rcp_dynamic_cast<CrsWrap>(P)->getCrsMatrix(), true)->getTpetra_CrsMatrixNonConst())));
86 }
87
88 RCP<matrix_type> toMatrix() {
89 using TpCrs = TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
90 using CrsWrap = CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
91 auto tpMat = Teuchos::rcp(new TpCrs(op_->toMatrix()));
92 return Teuchos::rcp(new CrsWrap(Teuchos::rcp_dynamic_cast<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpMat)));
93 }
94
95 double getCompression() {
96 return op_->getCompression();
97 }
98
99 void setDebugOutput(const bool debugOutput) {
100 op_->setDebugOutput(debugOutput);
101 }
102
103 RCP<matrix_type> nearFieldMatrix() {
104 auto tpMat = Teuchos::rcp(new TpetraCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>(op_->nearFieldMatrix()));
105 return Teuchos::rcp(new CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Node>(Teuchos::rcp_dynamic_cast<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >(tpMat)));
106 }
107
108 //! Gets the operator out
109 // RCP<const Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getTpetra_RowMatrix() const override { return op_; }
110
111 // RCP<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getTpetra_RowMatrixNonConst() const override { return op_; }
112
113 void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel) const {
114 describe(out, verbLevel, true);
115 }
116
117 void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel, const bool printHeader) const {
118 op_->describe(out, verbLevel, printHeader);
119 }
120
121 bool hasFarField() const {
122 return op_->hasFarField();
123 }
124
125 bool denserThanDenseMatrix() const {
126 return op_->denserThanDenseMatrix();
127 }
128
129 private:
130 RCP<tHOp> op_;
131 };
132
133 } // namespace Xpetra
134
135 #endif // XPETRA_HIERARCHICALOPERATOR_DECL_HPP