MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_TpetraOperatorAsRowMatrix.hpp
Go to the documentation of this file.
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#ifndef MUELU_TPETRAOPERATORASROWMATRIX_HPP
10#define MUELU_TPETRAOPERATORASROWMATRIX_HPP
11
12#include <Teuchos_RCP.hpp>
13#include <Tpetra_RowMatrix.hpp>
14#include <MueLu_Exceptions.hpp>
15
16namespace MueLu {
17
18template <class Scalar = Tpetra::Operator<>::scalar_type,
19 class LocalOrdinal = typename Tpetra::Operator<Scalar>::local_ordinal_type,
20 class GlobalOrdinal = typename Tpetra::Operator<Scalar, LocalOrdinal>::global_ordinal_type,
21 class Node = typename Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal>::node_type>
22class TpetraOperatorAsRowMatrix : public Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
23 public:
24 using op_type = Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
25 using vec_type = Tpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
26
28 using row_matrix_type = Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
29
30 using impl_scalar_type = typename row_matrix_type::impl_scalar_type;
31 using mag_type = typename KokkosKernels::ArithTraits<impl_scalar_type>::mag_type;
32
34 typename row_matrix_type::local_inds_device_view_type;
36 typename row_matrix_type::local_inds_host_view_type;
38 typename row_matrix_type::nonconst_local_inds_host_view_type;
39
41 typename row_matrix_type::global_inds_device_view_type;
43 typename row_matrix_type::global_inds_host_view_type;
45 typename row_matrix_type::nonconst_global_inds_host_view_type;
46
48 typename row_matrix_type::values_device_view_type;
50 typename row_matrix_type::values_host_view_type;
52 typename row_matrix_type::nonconst_values_host_view_type;
53
55
56
58 TpetraOperatorAsRowMatrix(const RCP<op_type>& op)
59 : op_(op)
60 , diag_(Teuchos::null) {}
61
62 TpetraOperatorAsRowMatrix(const RCP<op_type>& op,
63 const RCP<vec_type>& diag)
64 : op_(op)
65 , diag_(diag) {}
66
68 Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
69 return op_->getDomainMap();
70 }
71
73 Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
74 return op_->getRangeMap();
75 }
76
78
82 void apply(const Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& X,
83 Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Y,
84 Teuchos::ETransp mode = Teuchos::NO_TRANS,
85 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
86 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const {
87 op_->apply(X, Y, mode, alpha, beta);
88 }
89
90 // Fake RowMatrix interface
91 Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const {
92 return op_->getRangeMap();
93 }
94
95 Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const {
96 throw MueLu::Exceptions::RuntimeError("Not implemented.");
97 }
98
99 typename row_matrix_type::local_ordinal_type getBlockSize() const {
100 throw MueLu::Exceptions::RuntimeError("Not implemented.");
101 }
102
103 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const {
104 return op_->getDomainMap()->getComm();
105 }
106
107 Teuchos::RCP<const Tpetra::RowGraph<LocalOrdinal, GlobalOrdinal, Node> > getGraph() const {
108 throw MueLu::Exceptions::RuntimeError("Not implemented.");
109 }
110
111 Tpetra::global_size_t getGlobalNumRows() const {
112 return getRowMap()->getGlobalNumElements();
113 }
114
115 Tpetra::global_size_t getGlobalNumCols() const {
116 return getDomainMap()->getGlobalNumElements();
117 }
118
119 size_t getLocalNumRows() const {
120 return getRowMap()->getLocalNumElements();
121 }
122
123 size_t getLocalNumCols() const {
124 throw MueLu::Exceptions::RuntimeError("Not implemented.");
125 }
126
128 throw MueLu::Exceptions::RuntimeError("Not implemented.");
129 }
130
131 Tpetra::global_size_t getGlobalNumEntries() const {
132 return 0;
133 }
134
135 size_t getLocalNumEntries() const {
136 throw MueLu::Exceptions::RuntimeError("Not implemented.");
137 }
138
139 size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const {
140 throw MueLu::Exceptions::RuntimeError("Not implemented.");
141 }
142
143 size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const {
144 throw MueLu::Exceptions::RuntimeError("Not implemented.");
145 }
146
148 throw MueLu::Exceptions::RuntimeError("Not implemented.");
149 }
150
152 throw MueLu::Exceptions::RuntimeError("Not implemented.");
153 }
154
155 bool hasColMap() const {
156 return false;
157 }
158
159 bool isLocallyIndexed() const {
160 return true;
161 }
162
163 bool isGloballyIndexed() const {
164 return true;
165 }
166
167 bool isFillComplete() const {
168 return true;
169 }
170
171 bool supportsRowViews() const {
172 return false;
173 }
174
175 void
179 size_t& NumEntries) const {
180 throw MueLu::Exceptions::RuntimeError("Not implemented.");
181 }
182
183 void
187 size_t& NumEntries) const {
188 throw MueLu::Exceptions::RuntimeError("Not implemented.");
189 }
190
191 void
194 values_host_view_type& values) const {
195 throw MueLu::Exceptions::RuntimeError("Not implemented.");
196 }
197
198 void
201 values_host_view_type& values) const {
202 throw MueLu::Exceptions::RuntimeError("Not implemented.");
203 }
204
205 void getLocalDiagCopy(Tpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& diag) const {
206 if (diag_.is_null())
207 throw MueLu::Exceptions::RuntimeError("No diagonal available.");
208 else
209 diag = *diag_;
210 }
211
212 void leftScale(const Tpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x) {
213 throw MueLu::Exceptions::RuntimeError("Not implemented.");
214 }
215
216 void rightScale(const Tpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x) {
217 throw MueLu::Exceptions::RuntimeError("Not implemented.");
218 }
219
221 return 0.;
222 }
223
224 // void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel) const {
225 // using std::setw;
226 // using std::endl;
227 // const size_t numRows = nearField_->getRowMap()->getGlobalNumElements();
228 // const size_t nnzNearField = nearField_->getGlobalNumEntries();
229 // const double nnzNearPerRow = Teuchos::as<double>(nnzNearField)/numRows;
230 // const size_t nnzKernelApprox = kernelApproximations_->pointA_->getGlobalNumEntries();
231 // const size_t numClusterPairs = kernelApproximations_->blockA_->getGlobalNumEntries();
232 // const size_t nnzBasis = basisMatrix_->getGlobalNumEntries();
233 // size_t nnzTransfer = 0;
234 // for (size_t i = 0; i<transferMatrices_.size(); i++)
235 // nnzTransfer += transferMatrices_[i]->pointA_->getGlobalNumEntries();
236 // const size_t nnzTotal = nnzNearField+nnzKernelApprox+nnzBasis+nnzTransfer;
237 // const double nnzTotalPerRow = Teuchos::as<double>(nnzTotal)/numRows;
238 // std::ostringstream oss;
239 // oss << std::left;
240 // oss << setw(9) << "rows" << setw(12) << "nnz(near)" << setw(14) << "nnz(near)/row" << setw(12) << "nnz(basis)" << setw(15) << "#cluster pairs" << setw(12)<< "nnz(kernel)" << setw(14) << "nnz(transfer)" << setw(12) << "nnz(total)" << setw(14) << "nnz(total)/row" << endl;
241 // oss << setw(9) << numRows << setw(12) << nnzNearField << setw(14) << nnzNearPerRow << setw(12) << nnzBasis << setw(15) << numClusterPairs << setw(12) << nnzKernelApprox << setw(14) << nnzTransfer << setw(12) << nnzTotal << setw(14) << nnzTotalPerRow << endl;
242 // out << oss.str();
243 // }
244
245 private:
246 RCP<op_type> op_;
247 RCP<vec_type> diag_;
248};
249
250} // namespace MueLu
251
252#endif
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
MueLu::DefaultNode Node
Exception throws to report errors in the internal logical of the program.
Teuchos::RCP< const Tpetra::RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
void getGlobalRowCopy(GlobalOrdinal GlobalRow, nonconst_global_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const
typename row_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type
void getLocalRowView(LocalOrdinal LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
typename row_matrix_type::local_inds_host_view_type local_inds_host_view_type
typename row_matrix_type::values_host_view_type values_host_view_type
typename row_matrix_type::global_inds_host_view_type global_inds_host_view_type
void apply(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Returns in Y the result of a Tpetra::Operator applied to a Tpetra::MultiVector X.
typename row_matrix_type::local_inds_device_view_type local_inds_device_view_type
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
typename row_matrix_type::global_inds_device_view_type global_inds_device_view_type
Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > vec_type
void rightScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
typename row_matrix_type::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type
typename row_matrix_type::impl_scalar_type impl_scalar_type
Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > op_type
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
typename row_matrix_type::values_device_view_type values_device_view_type
typename row_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type
void getLocalRowCopy(LocalOrdinal LocalRow, nonconst_local_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const
Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > row_matrix_type
The RowMatrix representing the base class of CrsMatrix.
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
TpetraOperatorAsRowMatrix(const RCP< op_type > &op, const RCP< vec_type > &diag)
void getGlobalRowView(GlobalOrdinal GlobalRow, global_inds_host_view_type &indices, values_host_view_type &values) const
TpetraOperatorAsRowMatrix(const RCP< op_type > &op)
Constructor.
typename KokkosKernels::ArithTraits< impl_scalar_type >::mag_type mag_type
void leftScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
row_matrix_type::local_ordinal_type getBlockSize() const
void getLocalDiagCopy(Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Namespace for MueLu classes and methods.