MueLu Version of the Day
Loading...
Searching...
No Matches
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
47namespace MueLu {
48
49 template <class Scalar = Tpetra::Operator<>::scalar_type,
50 class LocalOrdinal = typename Tpetra::Operator<Scalar>::local_ordinal_type,
51 class GlobalOrdinal = typename Tpetra::Operator<Scalar, LocalOrdinal>::global_ordinal_type,
52 class Node = typename Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal>::node_type>
53 class TpetraOperatorAsRowMatrix : public Tpetra::RowMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
54
55 public:
56 using op_type = Tpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
57 using vec_type = Tpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
58
60 using row_matrix_type = Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
61
62 using impl_scalar_type = typename row_matrix_type::impl_scalar_type;
63 using mag_type = typename Kokkos::ArithTraits<impl_scalar_type>::mag_type;
64
66 typename row_matrix_type::local_inds_device_view_type;
68 typename row_matrix_type::local_inds_host_view_type;
70 typename row_matrix_type::nonconst_local_inds_host_view_type;
71
73 typename row_matrix_type::global_inds_device_view_type;
75 typename row_matrix_type::global_inds_host_view_type;
77 typename row_matrix_type::nonconst_global_inds_host_view_type;
78
80 typename row_matrix_type::values_device_view_type;
82 typename row_matrix_type::values_host_view_type;
84 typename row_matrix_type::nonconst_values_host_view_type;
85
87
88
90 TpetraOperatorAsRowMatrix(const RCP<op_type>& op)
91 :
92 op_(op),
93 diag_(Teuchos::null)
94 { }
95
96 TpetraOperatorAsRowMatrix(const RCP<op_type>& op,
97 const RCP<vec_type>& diag)
98 :
99 op_(op),
100 diag_(diag)
101 { }
102
104 Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > getDomainMap() const {
105 return op_->getDomainMap();
106 }
107
109 Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > getRangeMap() const {
110 return op_->getRangeMap();
111 }
112
114
118 void apply(const Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X,
119 Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y,
120 Teuchos::ETransp mode = Teuchos::NO_TRANS,
121 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
122 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const {
123 op_->apply(X, Y, mode, alpha, beta);
124 }
125
126 // Fake RowMatrix interface
127 Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > getRowMap() const {
128 return op_->getRangeMap();
129 }
130
131 Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > getColMap() const {
132 throw MueLu::Exceptions::RuntimeError("Not implemented.");
133 }
134
135 Teuchos::RCP<const Teuchos::Comm<int> > getComm() const {
136 return op_->getDomainMap()->getComm();
137 }
138
139 Teuchos::RCP<const Tpetra::RowGraph<LocalOrdinal,GlobalOrdinal,Node> > getGraph() const {
140 throw MueLu::Exceptions::RuntimeError("Not implemented.");
141 }
142
143 Tpetra::global_size_t getGlobalNumRows() const {
144 return getRowMap()->getGlobalNumElements();
145 }
146
147 Tpetra::global_size_t getGlobalNumCols() const {
148 return getDomainMap()->getGlobalNumElements();
149 }
150
151 size_t getLocalNumRows() const {
152 return getRowMap()->getLocalNumElements();
153 }
154
155 size_t getLocalNumCols() const {
156 throw MueLu::Exceptions::RuntimeError("Not implemented.");
157 }
158
160 throw MueLu::Exceptions::RuntimeError("Not implemented.");
161 }
162
163 Tpetra::global_size_t getGlobalNumEntries() const {
164 return 0;
165 }
166
167 size_t getLocalNumEntries() const {
168 throw MueLu::Exceptions::RuntimeError("Not implemented.");
169 }
170
171 size_t getNumEntriesInGlobalRow (GlobalOrdinal globalRow) const {
172 throw MueLu::Exceptions::RuntimeError("Not implemented.");
173 }
174
175 size_t getNumEntriesInLocalRow (LocalOrdinal localRow) const {
176 throw MueLu::Exceptions::RuntimeError("Not implemented.");
177 }
178
180 throw MueLu::Exceptions::RuntimeError("Not implemented.");
181 }
182
183 size_t getLocalMaxNumRowEntries () const {
184 throw MueLu::Exceptions::RuntimeError("Not implemented.");
185 }
186
187 bool hasColMap () const {
188 return false;
189 }
190
191 bool isLocallyIndexed() const {
192 return true;
193 }
194
195 bool isGloballyIndexed() const {
196 return true;
197 }
198
199 bool isFillComplete() const {
200 return true;
201 }
202
203 bool supportsRowViews() const {
204 return false;
205 }
206
207 void
211 size_t& NumEntries) const {
212 throw MueLu::Exceptions::RuntimeError("Not implemented.");
213 }
214
215 void
219 size_t& NumEntries) const {
220 throw MueLu::Exceptions::RuntimeError("Not implemented.");
221 }
222
223 void
226 values_host_view_type &values) const {
227 throw MueLu::Exceptions::RuntimeError("Not implemented.");
228 }
229
230 void
233 values_host_view_type & values) const {
234 throw MueLu::Exceptions::RuntimeError("Not implemented.");
235 }
236
237 void getLocalDiagCopy (Tpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &diag) const {
238 if (diag_.is_null())
239 throw MueLu::Exceptions::RuntimeError("No diagonal available.");
240 else
241 diag = *diag_;
242 }
243
244 void leftScale (const Tpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x) {
245 throw MueLu::Exceptions::RuntimeError("Not implemented.");
246 }
247
248 void rightScale (const Tpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x) {
249 throw MueLu::Exceptions::RuntimeError("Not implemented.");
250 }
251
253 return 0.;
254 }
255
256 // void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel) const {
257 // using std::setw;
258 // using std::endl;
259 // const size_t numRows = nearField_->getRowMap()->getGlobalNumElements();
260 // const size_t nnzNearField = nearField_->getGlobalNumEntries();
261 // const double nnzNearPerRow = Teuchos::as<double>(nnzNearField)/numRows;
262 // const size_t nnzKernelApprox = kernelApproximations_->pointA_->getGlobalNumEntries();
263 // const size_t numClusterPairs = kernelApproximations_->blockA_->getGlobalNumEntries();
264 // const size_t nnzBasis = basisMatrix_->getGlobalNumEntries();
265 // size_t nnzTransfer = 0;
266 // for (size_t i = 0; i<transferMatrices_.size(); i++)
267 // nnzTransfer += transferMatrices_[i]->pointA_->getGlobalNumEntries();
268 // const size_t nnzTotal = nnzNearField+nnzKernelApprox+nnzBasis+nnzTransfer;
269 // const double nnzTotalPerRow = Teuchos::as<double>(nnzTotal)/numRows;
270 // std::ostringstream oss;
271 // oss << std::left;
272 // 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;
273 // 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;
274 // out << oss.str();
275 // }
276
277 private:
278
279 RCP<op_type> op_;
280 RCP<vec_type> diag_;
281 };
282
283}
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
typename row_matrix_type::local_inds_device_view_type local_inds_device_view_type
typename row_matrix_type::values_device_view_type values_device_view_type
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::values_host_view_type values_host_view_type
void getLocalRowView(LocalOrdinal LocalRow, local_inds_host_view_type &indices, values_host_view_type &values) const
typename row_matrix_type::global_inds_host_view_type global_inds_host_view_type
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
typename row_matrix_type::nonconst_values_host_view_type nonconst_values_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.
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
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
typename row_matrix_type::nonconst_local_inds_host_view_type nonconst_local_inds_host_view_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.
typename Kokkos::ArithTraits< impl_scalar_type >::mag_type mag_type
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
void getLocalRowCopy(LocalOrdinal LocalRow, nonconst_local_inds_host_view_type &Indices, nonconst_values_host_view_type &Values, size_t &NumEntries) const
typename row_matrix_type::local_inds_host_view_type local_inds_host_view_type
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
typename row_matrix_type::global_inds_device_view_type global_inds_device_view_type
TpetraOperatorAsRowMatrix(const RCP< op_type > &op)
Constructor.
void leftScale(const Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void getLocalDiagCopy(Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Namespace for MueLu classes and methods.