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 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Ray Tuminaro (rstumin@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 #include <Tpetra_RowMatrix.hpp>
46 
47 namespace MueLu {
48 
49 template <class Scalar = Tpetra::Operator<>::scalar_type,
53 class TpetraOperatorAsRowMatrix : public Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
54  public:
57 
60 
62  using mag_type = typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
63 
65  typename row_matrix_type::local_inds_device_view_type;
67  typename row_matrix_type::local_inds_host_view_type;
69  typename row_matrix_type::nonconst_local_inds_host_view_type;
70 
72  typename row_matrix_type::global_inds_device_view_type;
74  typename row_matrix_type::global_inds_host_view_type;
76  typename row_matrix_type::nonconst_global_inds_host_view_type;
77 
79  typename row_matrix_type::values_device_view_type;
80  using values_host_view_type =
81  typename row_matrix_type::values_host_view_type;
83  typename row_matrix_type::nonconst_values_host_view_type;
84 
86 
87 
90  : op_(op)
91  , diag_(Teuchos::null) {}
92 
94  const RCP<vec_type>& diag)
95  : op_(op)
96  , diag_(diag) {}
97 
100  return op_->getDomainMap();
101  }
102 
105  return op_->getRangeMap();
106  }
107 
109 
118  op_->apply(X, Y, mode, alpha, beta);
119  }
120 
121  // Fake RowMatrix interface
123  return op_->getRangeMap();
124  }
125 
127  throw MueLu::Exceptions::RuntimeError("Not implemented.");
128  }
129 
131  throw MueLu::Exceptions::RuntimeError("Not implemented.");
132  }
133 
135  return op_->getDomainMap()->getComm();
136  }
137 
139  throw MueLu::Exceptions::RuntimeError("Not implemented.");
140  }
141 
143  return getRowMap()->getGlobalNumElements();
144  }
145 
147  return getDomainMap()->getGlobalNumElements();
148  }
149 
150  size_t getLocalNumRows() const {
151  return getRowMap()->getLocalNumElements();
152  }
153 
154  size_t getLocalNumCols() const {
155  throw MueLu::Exceptions::RuntimeError("Not implemented.");
156  }
157 
159  throw MueLu::Exceptions::RuntimeError("Not implemented.");
160  }
161 
163  return 0;
164  }
165 
166  size_t getLocalNumEntries() const {
167  throw MueLu::Exceptions::RuntimeError("Not implemented.");
168  }
169 
170  size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const {
171  throw MueLu::Exceptions::RuntimeError("Not implemented.");
172  }
173 
174  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const {
175  throw MueLu::Exceptions::RuntimeError("Not implemented.");
176  }
177 
178  size_t getGlobalMaxNumRowEntries() const {
179  throw MueLu::Exceptions::RuntimeError("Not implemented.");
180  }
181 
182  size_t getLocalMaxNumRowEntries() const {
183  throw MueLu::Exceptions::RuntimeError("Not implemented.");
184  }
185 
186  bool hasColMap() const {
187  return false;
188  }
189 
190  bool isLocallyIndexed() const {
191  return true;
192  }
193 
194  bool isGloballyIndexed() const {
195  return true;
196  }
197 
198  bool isFillComplete() const {
199  return true;
200  }
201 
202  bool supportsRowViews() const {
203  return false;
204  }
205 
206  void
210  size_t& NumEntries) const {
211  throw MueLu::Exceptions::RuntimeError("Not implemented.");
212  }
213 
214  void
218  size_t& NumEntries) const {
219  throw MueLu::Exceptions::RuntimeError("Not implemented.");
220  }
221 
222  void
225  values_host_view_type& values) const {
226  throw MueLu::Exceptions::RuntimeError("Not implemented.");
227  }
228 
229  void
231  local_inds_host_view_type& indices,
232  values_host_view_type& values) const {
233  throw MueLu::Exceptions::RuntimeError("Not implemented.");
234  }
235 
237  if (diag_.is_null())
238  throw MueLu::Exceptions::RuntimeError("No diagonal available.");
239  else
240  diag = *diag_;
241  }
242 
244  throw MueLu::Exceptions::RuntimeError("Not implemented.");
245  }
246 
248  throw MueLu::Exceptions::RuntimeError("Not implemented.");
249  }
250 
252  return 0.;
253  }
254 
255  // void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel) const {
256  // using std::setw;
257  // using std::endl;
258  // const size_t numRows = nearField_->getRowMap()->getGlobalNumElements();
259  // const size_t nnzNearField = nearField_->getGlobalNumEntries();
260  // const double nnzNearPerRow = Teuchos::as<double>(nnzNearField)/numRows;
261  // const size_t nnzKernelApprox = kernelApproximations_->pointA_->getGlobalNumEntries();
262  // const size_t numClusterPairs = kernelApproximations_->blockA_->getGlobalNumEntries();
263  // const size_t nnzBasis = basisMatrix_->getGlobalNumEntries();
264  // size_t nnzTransfer = 0;
265  // for (size_t i = 0; i<transferMatrices_.size(); i++)
266  // nnzTransfer += transferMatrices_[i]->pointA_->getGlobalNumEntries();
267  // const size_t nnzTotal = nnzNearField+nnzKernelApprox+nnzBasis+nnzTransfer;
268  // const double nnzTotalPerRow = Teuchos::as<double>(nnzTotal)/numRows;
269  // std::ostringstream oss;
270  // oss << std::left;
271  // 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;
272  // 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;
273  // out << oss.str();
274  // }
275 
276  private:
279 };
280 
281 } // namespace MueLu
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