|
Ifpack2 Templated Preconditioning Package
Version 1.0
|
00001 /*@HEADER 00002 // *********************************************************************** 00003 // 00004 // Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package 00005 // Copyright (2009) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 //@HEADER 00041 */ 00042 00043 #ifndef IFPACK2_OVERLAPPINGROWGRAPH_DEF_HPP 00044 #define IFPACK2_OVERLAPPINGROWGRAPH_DEF_HPP 00045 00046 #include <Ifpack2_Details_OverlappingRowGraph_decl.hpp> 00047 #include <Tpetra_Import.hpp> 00048 #include <Tpetra_Export.hpp> 00049 00050 00051 namespace Ifpack2 { 00052 namespace Details { 00053 00054 template<class GraphType> 00055 OverlappingRowGraph<GraphType>:: 00056 OverlappingRowGraph (const Teuchos::RCP<const row_graph_type>& nonoverlappingGraph, 00057 const Teuchos::RCP<const row_graph_type>& overlappingGraph, 00058 const Teuchos::RCP<const map_type>& rowMap, 00059 const Teuchos::RCP<const map_type>& colMap, 00060 const Tpetra::global_size_t numGlobalRows, 00061 const Tpetra::global_size_t numGlobalCols, 00062 const Tpetra::global_size_t numGlobalNonzeros, 00063 const size_t maxNumEntries, 00064 const Teuchos::RCP<const import_type>& nonoverlappingImporter, 00065 const Teuchos::RCP<const import_type>& overlappingImporter) : 00066 nonoverlappingGraph_ (nonoverlappingGraph), 00067 overlappingGraph_ (overlappingGraph), 00068 rowMap_ (rowMap), 00069 colMap_ (colMap), 00070 numGlobalRows_ (numGlobalRows), 00071 numGlobalCols_ (numGlobalCols), 00072 numGlobalNonzeros_ (numGlobalNonzeros), 00073 maxNumEntries_ (maxNumEntries), 00074 nonoverlappingImporter_ (nonoverlappingImporter), 00075 overlappingImporter_ (overlappingImporter) 00076 {} 00077 00078 00079 template<class GraphType> 00080 OverlappingRowGraph<GraphType>::~OverlappingRowGraph() {} 00081 00082 00083 template<class GraphType> 00084 Teuchos::RCP<const Teuchos::Comm<int> > 00085 OverlappingRowGraph<GraphType>::getComm () const 00086 { 00087 return nonoverlappingGraph_->getComm (); 00088 } 00089 00090 00091 template<class GraphType> 00092 Teuchos::RCP<typename GraphType::node_type> 00093 OverlappingRowGraph<GraphType>::getNode () const 00094 { 00095 return nonoverlappingGraph_->getNode(); 00096 } 00097 00098 00099 template<class GraphType> 00100 Teuchos::RCP<const Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> > 00101 OverlappingRowGraph<GraphType>::getRowMap () const 00102 { 00103 return rowMap_; 00104 } 00105 00106 00107 template<class GraphType> 00108 Teuchos::RCP<const Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> > 00109 OverlappingRowGraph<GraphType>::getColMap () const 00110 { 00111 return colMap_; 00112 } 00113 00114 00115 template<class GraphType> 00116 Teuchos::RCP<const Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> > 00117 OverlappingRowGraph<GraphType>::getDomainMap () const 00118 { 00119 return nonoverlappingGraph_->getDomainMap (); 00120 } 00121 00122 00123 template<class GraphType> 00124 Teuchos::RCP<const Tpetra::Map<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> > 00125 OverlappingRowGraph<GraphType>::getRangeMap () const 00126 { 00127 return nonoverlappingGraph_->getRangeMap (); 00128 } 00129 00130 00131 template<class GraphType> 00132 Teuchos::RCP<const Tpetra::Import<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> > 00133 OverlappingRowGraph<GraphType>::getImporter () const 00134 { 00135 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Not implemented"); 00136 } 00137 00138 00139 template<class GraphType> 00140 Teuchos::RCP<const Tpetra::Export<typename GraphType::local_ordinal_type, typename GraphType::global_ordinal_type, typename GraphType::node_type> > 00141 OverlappingRowGraph<GraphType>::getExporter () const 00142 { 00143 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Not implemented"); 00144 } 00145 00146 00147 template<class GraphType> 00148 global_size_t OverlappingRowGraph<GraphType>::getGlobalNumRows () const 00149 { 00150 return numGlobalRows_; 00151 } 00152 00153 00154 template<class GraphType> 00155 global_size_t OverlappingRowGraph<GraphType>::getGlobalNumCols () const 00156 { 00157 return numGlobalCols_; 00158 } 00159 00160 00161 template<class GraphType> 00162 size_t OverlappingRowGraph<GraphType>::getNodeNumRows () const 00163 { 00164 return nonoverlappingGraph_->getNodeNumRows () + 00165 overlappingGraph_->getNodeNumRows (); 00166 } 00167 00168 00169 template<class GraphType> 00170 size_t OverlappingRowGraph<GraphType>::getNodeNumCols () const 00171 { 00172 return this->getNodeNumRows (); 00173 } 00174 00175 00176 template<class GraphType> 00177 typename GraphType::global_ordinal_type 00178 OverlappingRowGraph<GraphType>::getIndexBase () const 00179 { 00180 return nonoverlappingGraph_->getIndexBase (); 00181 } 00182 00183 00184 template<class GraphType> 00185 Tpetra::global_size_t OverlappingRowGraph<GraphType>::getGlobalNumEntries () const 00186 { 00187 return numGlobalNonzeros_; 00188 } 00189 00190 00191 template<class GraphType> 00192 size_t OverlappingRowGraph<GraphType>::getNodeNumEntries () const 00193 { 00194 return nonoverlappingGraph_->getNodeNumEntries () + 00195 overlappingGraph_->getNodeNumEntries (); 00196 } 00197 00198 00199 template<class GraphType> 00200 size_t 00201 OverlappingRowGraph<GraphType>:: 00202 getNumEntriesInGlobalRow (global_ordinal_type globalRow) const 00203 { 00204 const local_ordinal_type localRow = rowMap_->getLocalElement (globalRow); 00205 if (localRow == Teuchos::OrdinalTraits<local_ordinal_type>::invalid ()) { 00206 return Teuchos::OrdinalTraits<size_t>::invalid(); 00207 } else { 00208 return getNumEntriesInLocalRow (localRow); 00209 } 00210 } 00211 00212 00213 template<class GraphType> 00214 size_t 00215 OverlappingRowGraph<GraphType>:: 00216 getNumEntriesInLocalRow (local_ordinal_type localRow) const 00217 { 00218 using Teuchos::as; 00219 const size_t numMyRowsA = nonoverlappingGraph_->getNodeNumRows (); 00220 if (as<size_t> (localRow) < numMyRowsA) { 00221 return nonoverlappingGraph_->getNumEntriesInLocalRow (localRow); 00222 } else { 00223 return overlappingGraph_->getNumEntriesInLocalRow (as<local_ordinal_type> (localRow - numMyRowsA)); 00224 } 00225 } 00226 00227 00228 template<class GraphType> 00229 global_size_t OverlappingRowGraph<GraphType>::getGlobalNumDiags () const 00230 { 00231 throw std::runtime_error("Ifpack2::OverlappingRowGraph::getGlobalNumDiags() not supported."); 00232 } 00233 00234 00235 template<class GraphType> 00236 size_t OverlappingRowGraph<GraphType>::getNodeNumDiags() const 00237 { 00238 return nonoverlappingGraph_->getNodeNumDiags(); 00239 } 00240 00241 00242 template<class GraphType> 00243 size_t OverlappingRowGraph<GraphType>::getGlobalMaxNumRowEntries () const 00244 { 00245 throw std::runtime_error("Ifpack2::OverlappingRowGraph::getGlobalMaxNumRowEntries() not supported."); 00246 } 00247 00248 00249 template<class GraphType> 00250 size_t OverlappingRowGraph<GraphType>::getNodeMaxNumRowEntries () const 00251 { 00252 return maxNumEntries_; 00253 } 00254 00255 00256 template<class GraphType> 00257 bool OverlappingRowGraph<GraphType>::hasColMap () const 00258 { 00259 return true; 00260 } 00261 00262 00263 template<class GraphType> 00264 bool OverlappingRowGraph<GraphType>::isLowerTriangular () const 00265 { 00266 return nonoverlappingGraph_->isLowerTriangular (); 00267 } 00268 00269 00270 template<class GraphType> 00271 bool OverlappingRowGraph<GraphType>::isUpperTriangular() const 00272 { 00273 return nonoverlappingGraph_->isUpperTriangular (); 00274 } 00275 00276 00277 template<class GraphType> 00278 bool OverlappingRowGraph<GraphType>::isLocallyIndexed () const 00279 { 00280 return true; 00281 } 00282 00283 00284 template<class GraphType> 00285 bool OverlappingRowGraph<GraphType>::isGloballyIndexed () const 00286 { 00287 return false; 00288 } 00289 00290 00291 template<class GraphType> 00292 bool OverlappingRowGraph<GraphType>::isFillComplete () const 00293 { 00294 return true; 00295 } 00296 00297 00298 template<class GraphType> 00299 void 00300 OverlappingRowGraph<GraphType>:: 00301 getGlobalRowCopy (global_ordinal_type globalRow, 00302 const Teuchos::ArrayView<global_ordinal_type>& indices, 00303 size_t& numIndices) const 00304 { 00305 const local_ordinal_type localRow = rowMap_->getLocalElement (globalRow); 00306 if (localRow == Teuchos::OrdinalTraits<local_ordinal_type>::invalid ()) { 00307 numIndices = Teuchos::OrdinalTraits<size_t>::invalid (); 00308 } else { 00309 if (Teuchos::as<size_t> (localRow) < nonoverlappingGraph_->getNodeNumRows ()) { 00310 nonoverlappingGraph_->getGlobalRowCopy (globalRow, indices, numIndices); 00311 } else { 00312 overlappingGraph_->getGlobalRowCopy (globalRow, indices, numIndices); 00313 } 00314 } 00315 } 00316 00317 00318 template<class GraphType> 00319 void 00320 OverlappingRowGraph<GraphType>:: 00321 getLocalRowCopy (local_ordinal_type localRow, 00322 const Teuchos::ArrayView<local_ordinal_type>& indices, 00323 size_t& numIndices) const 00324 { 00325 using Teuchos::as; 00326 const size_t numMyRowsA = nonoverlappingGraph_->getNodeNumRows (); 00327 if (as<size_t> (localRow) < numMyRowsA) { 00328 nonoverlappingGraph_->getLocalRowCopy (localRow, indices, numIndices); 00329 } else { 00330 const local_ordinal_type localRowOffset = 00331 localRow - as<local_ordinal_type> (numMyRowsA); 00332 overlappingGraph_->getLocalRowCopy (localRowOffset, indices, numIndices); 00333 } 00334 } 00335 00336 } // namespace Details 00337 } // namespace Ifpack2 00338 00339 #define IFPACK2_DETAILS_OVERLAPPINGROWGRAPH_INSTANT(LO,GO,N) \ 00340 template class Ifpack2::Details::OverlappingRowGraph<Tpetra::CrsGraph< LO, GO, N > >; \ 00341 template class Ifpack2::Details::OverlappingRowGraph<Tpetra::RowGraph< LO, GO, N > >; 00342 00343 #endif // IFPACK2_OVERLAPPINGROWGRAPH_DEF_HPP
1.7.6.1