Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_TpetraRowMatrix.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
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 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef XPETRA_TPETRAROWMATRIX_HPP
47 #define XPETRA_TPETRAROWMATRIX_HPP
48 
49 /* this file is automatically generated - do not edit (see script/tpetra.py) */
50 
51 // WARNING: This code is experimental. Backwards compatibility should not be expected.
52 
53 #include <Teuchos_Describable.hpp>
54 #include "Xpetra_ConfigDefs.hpp"
55 #include "Xpetra_Map.hpp"
56 #include "Xpetra_Vector.hpp"
57 
58 #include "Xpetra_TpetraMap.hpp"
59 
60 #include "Tpetra_RowMatrix.hpp"
61 
62 #include "Xpetra_RowMatrix.hpp"
63 #include "Xpetra_Exceptions.hpp"
64 
65 namespace Xpetra {
66 
67 template <class Scalar,
68  class LocalOrdinal,
69  class GlobalOrdinal,
70  class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
72  : virtual public RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> {
73  public:
75 
76 
78  virtual ~TpetraRowMatrix() = default;
79 
81 
83 
84 
86  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRowMap() const {
87  XPETRA_MONITOR("TpetraRowMatrix::getRowMap");
88  return toXpetra(mtx_->getRowMap());
89  }
90 
92  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getColMap() const {
93  XPETRA_MONITOR("TpetraRowMatrix::getColMap");
94  return toXpetra(mtx_->getColMap());
95  }
96 
99  XPETRA_MONITOR("TpetraRowMatrix::getGlobalNumRows");
100  return mtx_->getGlobalNumRows();
101  }
102 
105  XPETRA_MONITOR("TpetraRowMatrix::getGlobalNumCols");
106  return mtx_->getGlobalNumCols();
107  }
108 
110  size_t getLocalNumRows() const {
111  XPETRA_MONITOR("TpetraRowMatrix::getLocalNumRows");
112  return mtx_->getLocalNumRows();
113  }
114 
116  size_t getLocalNumCols() const {
117  XPETRA_MONITOR("TpetraRowMatrix::getLocalNumCols");
118  return mtx_->getLocalNumCols();
119  }
120 
123  XPETRA_MONITOR("TpetraRowMatrix::getGlobalNumEntries");
124  return mtx_->getGlobalNumEntries();
125  }
126 
128  size_t getNodeNumEntries() const {
129  XPETRA_MONITOR("TpetraRowMatrix::getNodeNumEntries");
130  return mtx_->getNodeNumEntries();
131  }
132 
134  size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const {
135  XPETRA_MONITOR("TpetraRowMatrix::getNumEntriesInLocalRow");
136  return mtx_->getNumEntriesInLocalRow(localRow);
137  }
138 
140  size_t getGlobalMaxNumRowEntries() const {
141  XPETRA_MONITOR("TpetraRowMatrix::getGlobalMaxNumRowEntries");
142  return mtx_->getGlobalMaxNumRowEntries();
143  }
144 
146  size_t getLocalMaxNumRowEntries() const {
147  XPETRA_MONITOR("TpetraRowMatrix::getLocalMaxNumRowEntries");
148  return mtx_->getLocalMaxNumRowEntries();
149  }
150 
152  bool isLocallyIndexed() const {
153  XPETRA_MONITOR("TpetraRowMatrix::isLocallyIndexed");
154  return mtx_->isLocallyIndexed();
155  }
156 
158  bool isGloballyIndexed() const {
159  XPETRA_MONITOR("TpetraRowMatrix::isGloballyIndexed");
160  return mtx_->isGloballyIndexed();
161  }
162 
164  bool isFillComplete() const {
165  XPETRA_MONITOR("TpetraRowMatrix::isFillComplete");
166  return mtx_->isFillComplete();
167  }
168 
170  bool supportsRowViews() const {
171  XPETRA_MONITOR("TpetraRowMatrix::supportsRowViews");
172  return mtx_->supportsRowViews();
173  }
174 
176 
178 
179 
181  void getLocalRowCopy(LocalOrdinal LocalRow, const Teuchos::ArrayView<LocalOrdinal> &Indices, const Teuchos::ArrayView<Scalar> &Values, size_t &NumEntries) const {
182  XPETRA_MONITOR("TpetraRowMatrix::getLocalRowCopy");
183  typename Tpetra::RowGraph<LocalOrdinal, GlobalOrdinal, Node>::nonconst_local_inds_host_view_type indices("indices", Indices.size());
184  typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::nonconst_values_host_view_type values("values", Values.size());
185 
186  mtx_->getLocalRowCopy(LocalRow, indices, values, NumEntries);
187  for (size_t i = 0; i < NumEntries; ++i) {
188  Indices[i] = indices(i);
189  Values[i] = values(i);
190  }
191  }
192 
194  void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values) const {
195  XPETRA_MONITOR("TpetraRowMatrix::getGlobalRowView");
196  typename Tpetra::RowGraph<LocalOrdinal, GlobalOrdinal, Node>::global_inds_host_view_type k_indices;
197  typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::values_host_view_type k_values;
198 
199  mtx_->getGlobalRowView(GlobalRow, k_indices, k_values);
200  indices = ArrayView<const GlobalOrdinal>(k_indices.data(), k_indices.extent(0));
201  values = ArrayView<const Scalar>(reinterpret_cast<const Scalar *>(k_values.data()), k_values.extent(0));
202  }
203 
205  void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values) const {
206  XPETRA_MONITOR("TpetraRowMatrix::getLocalRowView");
207  typename Tpetra::RowGraph<LocalOrdinal, GlobalOrdinal, Node>::local_inds_host_view_type k_indices;
208  typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::values_host_view_type k_values;
209 
210  mtx_->getLocalRowView(LocalRow, k_indices, k_values);
211  indices = ArrayView<const LocalOrdinal>(k_indices.data(), k_indices.extent(0));
212  values = ArrayView<const Scalar>(reinterpret_cast<const Scalar *>(k_values.data()), k_values.extent(0));
213  }
214 
217  //{ XPETRA_MONITOR("TpetraRowMatrix::getLocalDiagCopy"); mtx_->getLocalDiagCopy(diag); }
218 
220 
222 
223 
225  typename ScalarTraits<Scalar>::magnitudeType getFrobeniusNorm() const {
226  XPETRA_MONITOR("TpetraRowMatrix::getFrobeniusNorm");
227  return mtx_->getFrobeniusNorm();
228  }
229 
231 
233 
234 
236  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getDomainMap() const {
237  XPETRA_MONITOR("TpetraRowMatrix::getDomainMap");
238  return toXpetra(mtx_->getDomainMap());
239  }
240 
242  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > getRangeMap() const {
243  XPETRA_MONITOR("TpetraRowMatrix::getRangeMap");
244  return toXpetra(mtx_->getRangeMap());
245  }
246 
248  void apply(const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &X, 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 { TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::NotImplemented, "TODO"); }
249  //{ XPETRA_MONITOR("TpetraRowMatrix::apply"); mtx_->apply(X, Y, mode, alpha, beta); }
250 
252 
254 
255 
256  TpetraRowMatrix() = default;
257 
259  TpetraRowMatrix(const Teuchos::RCP<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > &mtx)
260  : mtx_(mtx) {}
261 
263  void setTpetra_RowMatrix(const Teuchos::RCP<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > &mtx) { mtx_ = mtx; }
264 
266  RCP<const Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getTpetra_RowMatrix() const { return mtx_; }
267 
269  RCP<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getTpetra_RowMatrixNonConst() const { return mtx_; } // TODO: remove
270 
272 
273  private:
274  RCP<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > mtx_;
275 
276 }; // TpetraRowMatrix class
277 
278 } // namespace Xpetra
279 
280 #define XPETRA_TPETRAROWMATRIX_SHORT
281 #endif // XPETRA_TPETRAROWMATRIX_HPP
Tpetra::global_size_t getGlobalNumCols() const
Returns the number of global columns in this matrix.
RCP< Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > mtx_
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Map associated with the range of this operator, which must be compatible with Y...
void setTpetra_RowMatrix(const Teuchos::RCP< Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &mtx)
Set the underlying Tpetra matrix.
Tpetra::global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
size_t getLocalNumRows() const
Returns the number of rows owned on the calling node.
virtual ~TpetraRowMatrix()=default
Destructor.
bool isFillComplete() const
Returns true if fillComplete() has been called.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const
Returns the Map that describes the column distribution in this matrix.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
Returns the Map that describes the row distribution in this matrix.
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, 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
Computes the operator-multivector application.
Exception throws when you call an unimplemented method of Xpetra.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
size_t global_size_t
Global size_t object.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Map associated with the domain of this operator, which must be compatible with X...
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
Tpetra::global_size_t getGlobalNumRows() const
Returns the number of global rows in this matrix.
TpetraRowMatrix(const Teuchos::RCP< Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &mtx)
TpetraCrsMatrix constructor to wrap a Tpetra::CrsMatrix object.
size_t getLocalNumCols() const
Returns the number of columns needed to apply the forward operator on this node, i.e., the number of elements listed in the column map.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
RCP< const Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_RowMatrix() const
Get the underlying Tpetra matrix.
#define XPETRA_MONITOR(funcName)
RCP< Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_RowMatrixNonConst() const
Get the underlying Tpetra matrix.
bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
size_t getLocalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
void getLocalRowCopy(LocalOrdinal LocalRow, const Teuchos::ArrayView< LocalOrdinal > &Indices, const Teuchos::ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the graph. Put into storage allocated by callin...
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)