MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
16 namespace MueLu {
17 
18 template <class Scalar = Tpetra::Operator<>::scalar_type,
22 class TpetraOperatorAsRowMatrix : public Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
23  public:
26 
29 
31  using mag_type = typename Kokkos::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;
49  using values_host_view_type =
50  typename row_matrix_type::values_host_view_type;
52  typename row_matrix_type::nonconst_values_host_view_type;
53 
55 
56 
59  : op_(op)
60  , diag_(Teuchos::null) {}
61 
63  const RCP<vec_type>& diag)
64  : op_(op)
65  , diag_(diag) {}
66 
69  return op_->getDomainMap();
70  }
71 
74  return op_->getRangeMap();
75  }
76 
78 
87  op_->apply(X, Y, mode, alpha, beta);
88  }
89 
90  // Fake RowMatrix interface
92  return op_->getRangeMap();
93  }
94 
96  throw MueLu::Exceptions::RuntimeError("Not implemented.");
97  }
98 
100  throw MueLu::Exceptions::RuntimeError("Not implemented.");
101  }
102 
104  return op_->getDomainMap()->getComm();
105  }
106 
108  throw MueLu::Exceptions::RuntimeError("Not implemented.");
109  }
110 
112  return getRowMap()->getGlobalNumElements();
113  }
114 
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 
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 
147  size_t getGlobalMaxNumRowEntries() const {
148  throw MueLu::Exceptions::RuntimeError("Not implemented.");
149  }
150 
151  size_t getLocalMaxNumRowEntries() const {
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
200  local_inds_host_view_type& indices,
201  values_host_view_type& values) const {
202  throw MueLu::Exceptions::RuntimeError("Not implemented.");
203  }
204 
206  if (diag_.is_null())
207  throw MueLu::Exceptions::RuntimeError("No diagonal available.");
208  else
209  diag = *diag_;
210  }
211 
213  throw MueLu::Exceptions::RuntimeError("Not implemented.");
214  }
215 
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:
248 };
249 
250 } // namespace MueLu
251 
252 #endif
void leftScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
MueLu::DefaultLocalOrdinal LocalOrdinal
TpetraOperatorAsRowMatrix(const RCP< op_type > &op, const RCP< vec_type > &diag)
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, nonconst_global_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const
row_matrix_type::local_ordinal_type getBlockSize() const
typename row_matrix_type::values_device_view_type values_device_view_type
LocalOrdinal local_ordinal_type
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
void rightScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
typename row_matrix_type::local_inds_host_view_type local_inds_host_view_type
MueLu::DefaultNode Node
void getLocalRowCopy(LocalOrdinal LocalRow, nonconst_local_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const
void getLocalDiagCopy(Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
size_t global_size_t
typename row_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_type
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
typename Kokkos::ArithTraits< Scalar >::mag_type mag_type
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
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::values_host_view_type values_host_view_type
Tpetra::global_size_t getGlobalNumEntries() const
typename row_matrix_type::nonconst_global_inds_host_view_type nonconst_global_inds_host_view_type
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Teuchos::RCP< const Tpetra::RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
typename row_matrix_type::local_inds_device_view_type local_inds_device_view_type
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
typename row_matrix_type::global_inds_host_view_type global_inds_host_view_type
typename row_matrix_type::global_inds_device_view_type global_inds_device_view_type
typename row_matrix_type::nonconst_values_host_view_type nonconst_values_host_view_type
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
Exception throws to report errors in the internal logical of the program.
void getLocalRowView(LocalOrdinal LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const
TpetraOperatorAsRowMatrix(const RCP< op_type > &op)
Constructor.
void getGlobalRowView(GlobalOrdinal GlobalRow, global_inds_host_view_type &indices, values_host_view_type &values) const
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
bool is_null() const