Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Details_OverlappingRowGraph_def.hpp
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef IFPACK2_OVERLAPPINGROWGRAPH_DEF_HPP
44 #define IFPACK2_OVERLAPPINGROWGRAPH_DEF_HPP
45 
46 #include <Ifpack2_Details_OverlappingRowGraph_decl.hpp>
47 #include <Tpetra_Import.hpp>
48 #include <Tpetra_Export.hpp>
49 
50 
51 namespace Ifpack2 {
52 namespace Details {
53 
54 template<class GraphType>
56 OverlappingRowGraph (const Teuchos::RCP<const row_graph_type>& nonoverlappingGraph,
57  const Teuchos::RCP<const row_graph_type>& overlappingGraph,
58  const Teuchos::RCP<const map_type>& rowMap,
59  const Teuchos::RCP<const map_type>& colMap,
60  const Tpetra::global_size_t numGlobalRows,
61  const Tpetra::global_size_t numGlobalCols,
62  const Tpetra::global_size_t numGlobalNonzeros,
63  const size_t maxNumEntries,
64  const Teuchos::RCP<const import_type>& nonoverlappingImporter,
65  const Teuchos::RCP<const import_type>& overlappingImporter) :
66  nonoverlappingGraph_ (nonoverlappingGraph),
67  overlappingGraph_ (overlappingGraph),
68  rowMap_ (rowMap),
69  colMap_ (colMap),
70  numGlobalRows_ (numGlobalRows),
71  numGlobalCols_ (numGlobalCols),
72  numGlobalNonzeros_ (numGlobalNonzeros),
73  maxNumEntries_ (maxNumEntries),
74  nonoverlappingImporter_ (nonoverlappingImporter),
75  overlappingImporter_ (overlappingImporter)
76 {}
77 
78 
79 template<class GraphType>
81 
82 
83 template<class GraphType>
84 Teuchos::RCP<const Teuchos::Comm<int> >
86 {
87  return nonoverlappingGraph_->getComm ();
88 }
89 
90 
91 template<class GraphType>
92 Teuchos::RCP<typename GraphType::node_type>
94 {
95  return nonoverlappingGraph_->getNode();
96 }
97 
98 
99 template<class GraphType>
100 Teuchos::RCP<const Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> >
102 {
103  return rowMap_;
104 }
105 
106 
107 template<class GraphType>
108 Teuchos::RCP<const Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> >
110 {
111  return colMap_;
112 }
113 
114 
115 template<class GraphType>
116 Teuchos::RCP<const Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> >
118 {
119  return nonoverlappingGraph_->getDomainMap ();
120 }
121 
122 
123 template<class GraphType>
124 Teuchos::RCP<const Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> >
126 {
127  return nonoverlappingGraph_->getRangeMap ();
128 }
129 
130 
131 template<class GraphType>
132 Teuchos::RCP<const Tpetra::Import<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> >
134 {
135  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Not implemented");
136 }
137 
138 
139 template<class GraphType>
140 Teuchos::RCP<const Tpetra::Export<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> >
142 {
143  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Not implemented");
144 }
145 
146 
147 template<class GraphType>
149 {
150  return numGlobalRows_;
151 }
152 
153 
154 template<class GraphType>
156 {
157  return numGlobalCols_;
158 }
159 
160 
161 template<class GraphType>
163 {
164  return nonoverlappingGraph_->getNodeNumRows () +
165  overlappingGraph_->getNodeNumRows ();
166 }
167 
168 
169 template<class GraphType>
171 {
172  return this->getNodeNumRows ();
173 }
174 
175 
176 template<class GraphType>
177 typename GraphType::global_ordinal_type
179 {
180  return nonoverlappingGraph_->getIndexBase ();
181 }
182 
183 
184 template<class GraphType>
186 {
187  return numGlobalNonzeros_;
188 }
189 
190 
191 template<class GraphType>
193 {
194  return nonoverlappingGraph_->getNodeNumEntries () +
195  overlappingGraph_->getNodeNumEntries ();
196 }
197 
198 
199 template<class GraphType>
200 size_t
202 getNumEntriesInGlobalRow (global_ordinal_type globalRow) const
203 {
204  const local_ordinal_type localRow = rowMap_->getLocalElement (globalRow);
205  if (localRow == Teuchos::OrdinalTraits<local_ordinal_type>::invalid ()) {
206  return Teuchos::OrdinalTraits<size_t>::invalid();
207  } else {
208  return getNumEntriesInLocalRow (localRow);
209  }
210 }
211 
212 
213 template<class GraphType>
214 size_t
216 getNumEntriesInLocalRow (local_ordinal_type localRow) const
217 {
218  using Teuchos::as;
219  const size_t numMyRowsA = nonoverlappingGraph_->getNodeNumRows ();
220  if (as<size_t> (localRow) < numMyRowsA) {
221  return nonoverlappingGraph_->getNumEntriesInLocalRow (localRow);
222  } else {
223  return overlappingGraph_->getNumEntriesInLocalRow (as<local_ordinal_type> (localRow - numMyRowsA));
224  }
225 }
226 
227 
228 template<class GraphType>
230 {
231  throw std::runtime_error("Ifpack2::OverlappingRowGraph::getGlobalNumDiags() not supported.");
232 }
233 
234 
235 template<class GraphType>
237 {
238  return nonoverlappingGraph_->getNodeNumDiags();
239 }
240 
241 
242 template<class GraphType>
244 {
245  throw std::runtime_error("Ifpack2::OverlappingRowGraph::getGlobalMaxNumRowEntries() not supported.");
246 }
247 
248 
249 template<class GraphType>
251 {
252  return maxNumEntries_;
253 }
254 
255 
256 template<class GraphType>
258 {
259  return true;
260 }
261 
262 
263 template<class GraphType>
265 {
266  return nonoverlappingGraph_->isLowerTriangular ();
267 }
268 
269 
270 template<class GraphType>
272 {
273  return nonoverlappingGraph_->isUpperTriangular ();
274 }
275 
276 
277 template<class GraphType>
279 {
280  return true;
281 }
282 
283 
284 template<class GraphType>
286 {
287  return false;
288 }
289 
290 
291 template<class GraphType>
293 {
294  return true;
295 }
296 
297 
298 template<class GraphType>
299 void
301 getGlobalRowCopy (global_ordinal_type globalRow,
302  const Teuchos::ArrayView<global_ordinal_type>& indices,
303  size_t& numIndices) const
304 {
305  const local_ordinal_type localRow = rowMap_->getLocalElement (globalRow);
306  if (localRow == Teuchos::OrdinalTraits<local_ordinal_type>::invalid ()) {
307  numIndices = Teuchos::OrdinalTraits<size_t>::invalid ();
308  } else {
309  if (Teuchos::as<size_t> (localRow) < nonoverlappingGraph_->getNodeNumRows ()) {
310  nonoverlappingGraph_->getGlobalRowCopy (globalRow, indices, numIndices);
311  } else {
312  overlappingGraph_->getGlobalRowCopy (globalRow, indices, numIndices);
313  }
314  }
315 }
316 
317 
318 template<class GraphType>
319 void
321 getLocalRowCopy (local_ordinal_type localRow,
322  const Teuchos::ArrayView<local_ordinal_type>& indices,
323  size_t& numIndices) const
324 {
325  using Teuchos::as;
326  const size_t numMyRowsA = nonoverlappingGraph_->getNodeNumRows ();
327  if (as<size_t> (localRow) < numMyRowsA) {
328  nonoverlappingGraph_->getLocalRowCopy (localRow, indices, numIndices);
329  } else {
330  const local_ordinal_type localRowOffset =
331  localRow - as<local_ordinal_type> (numMyRowsA);
332  overlappingGraph_->getLocalRowCopy (localRowOffset, indices, numIndices);
333  }
334 }
335 
336 } // namespace Details
337 } // namespace Ifpack2
338 
339 #define IFPACK2_DETAILS_OVERLAPPINGROWGRAPH_INSTANT(LO,GO,N) \
340  template class Ifpack2::Details::OverlappingRowGraph<Tpetra::CrsGraph< LO, GO, N > >; \
341  template class Ifpack2::Details::OverlappingRowGraph<Tpetra::RowGraph< LO, GO, N > >;
342 
343 #endif // IFPACK2_OVERLAPPINGROWGRAPH_DEF_HPP
virtual size_t getNodeNumCols() const
The number of columns owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:170
virtual bool isGloballyIndexed() const
Whether this graph is globally indexed.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:285
virtual size_t getNodeNumEntries() const
The number of entries in this graph owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:192
virtual bool isLowerTriangular() const
Whether this graph is lower triangular.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:264
OverlappingRowGraph(const Teuchos::RCP< const row_graph_type > &nonoverlappingGraph, const Teuchos::RCP< const row_graph_type > &overlappingGraph, const Teuchos::RCP< const map_type > &rowMap, const Teuchos::RCP< const map_type > &colMap, const Tpetra::global_size_t numGlobalRows, const Tpetra::global_size_t numGlobalCols, const Tpetra::global_size_t numGlobalNonzeros, const size_t maxNumEntries, const Teuchos::RCP< const import_type > &nonoverlappingImporter, const Teuchos::RCP< const import_type > &overlappingImporter)
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:56
virtual bool isLocallyIndexed() const
Whether this graph is locally indexed.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:278
virtual size_t getNodeNumRows() const
The number of rows owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:162
virtual global_ordinal_type getIndexBase() const
The index base for global indices for this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:178
virtual void getLocalRowCopy(local_ordinal_type localRow, const Teuchos::ArrayView< local_ordinal_type > &indices, size_t &numIndices) const
Copy out a list of local column indices in the given local row that are owned by the calling process...
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:321
virtual Teuchos::RCP< node_type > getNode() const
The graph&#39;s Node instance.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:93
virtual Teuchos::RCP< const map_type > getRangeMap() const
The Map that describes the range of this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:125
virtual Teuchos::RCP< const import_type > getImporter() const
Import object (from domain Map to column Map).
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:133
virtual bool hasColMap() const
Whether this graph has a column Map.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:257
Ifpack2 implementation details.
virtual global_size_t getGlobalNumDiags() const
The global number of diagonal entries.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:229
virtual bool isFillComplete() const
true if fillComplete() has been called, else false.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:292
virtual Teuchos::RCP< const map_type > getRowMap() const
The Map that describes the distribution of rows over processes.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:101
virtual size_t getNodeNumDiags() const
The number of diagonal entries owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:236
virtual void getGlobalRowCopy(global_ordinal_type globalRow, const Teuchos::ArrayView< global_ordinal_type > &indices, size_t &numIndices) const
Copy out a list of column indices in the given global row that are owned by the calling process...
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:301
virtual size_t getNumEntriesInLocalRow(local_ordinal_type localRow) const
The number of entries in the given local row that are owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:216
virtual Teuchos::RCP< const map_type > getColMap() const
The Map that describes the distribution of columns over processes.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:109
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
The communicator over which the graph is distributed.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:85
virtual global_size_t getGlobalNumEntries() const
The global number of entries in this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:185
virtual ~OverlappingRowGraph()
Destructor.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:80
virtual Teuchos::RCP< const export_type > getExporter() const
Export object (from row Map to range Map).
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:141
virtual global_size_t getGlobalNumCols() const
The global number of columns in this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:155
virtual Teuchos::RCP< const map_type > getDomainMap() const
The Map that describes the domain of this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:117
virtual global_size_t getGlobalNumRows() const
The global number of rows in this graph.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:148
virtual size_t getNumEntriesInGlobalRow(global_ordinal_type globalRow) const
The number of entries in the given global row that are owned by the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:202
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:72
virtual size_t getGlobalMaxNumRowEntries() const
The maximum number of entries in any row on any process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:243
virtual bool isUpperTriangular() const
Whether this graph is upper triangular.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:271
virtual size_t getNodeMaxNumRowEntries() const
The maximum number of entries in any row on the calling process.
Definition: Ifpack2_Details_OverlappingRowGraph_def.hpp:250