|
Tpetra Matrix/Vector Services
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Tpetra: Templated Linear Algebra Services Package 00005 // Copyright (2008) Sandia Corporation 00006 // 00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00008 // the U.S. Government retains certain rights in this software. 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 TPETRA_MMHELPERS_DECL_HPP 00044 #define TPETRA_MMHELPERS_DECL_HPP 00045 00046 #include <Tpetra_CrsMatrix.hpp> 00047 #include <Teuchos_Array.hpp> 00048 #include <map> 00049 #include <set> 00050 00056 00057 namespace Tpetra { 00058 00064 template <class Scalar = CrsMatrix<>::scalar_type, 00065 class LocalOrdinal = typename CrsMatrix<Scalar>::local_ordinal_type, 00066 class GlobalOrdinal = typename CrsMatrix<Scalar, LocalOrdinal>::global_ordinal_type, 00067 class Node = typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal>::node_type> 00068 class CrsMatrixStruct { 00069 public: 00070 typedef Map<LocalOrdinal, GlobalOrdinal, Node> map_type; 00071 typedef CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> crs_matrix_type; 00072 00073 CrsMatrixStruct (); 00074 00075 virtual ~CrsMatrixStruct (); 00076 00077 void deleteContents (); 00078 00080 Teuchos::RCP<const map_type > origRowMap; 00082 Teuchos::RCP<const map_type > rowMap; 00084 Teuchos::RCP<const map_type > colMap; 00086 Teuchos::RCP<const map_type > domainMap; 00088 Teuchos::RCP<const map_type > importColMap; 00090 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > importMatrix; 00092 Teuchos::RCP<const CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > origMatrix; 00093 00094 }; 00095 00096 00097 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> 00098 int 00099 dumpCrsMatrixStruct (const CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node >& M); 00100 00101 00102 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> 00103 class CrsWrapper { 00104 public: 00105 typedef Map<LocalOrdinal, GlobalOrdinal, Node> map_type; 00106 00107 virtual ~CrsWrapper () {} 00108 virtual Teuchos::RCP<const map_type> getRowMap () const = 0; 00109 virtual bool isFillComplete () = 0; 00110 00111 virtual void 00112 insertGlobalValues (GlobalOrdinal globalRow, 00113 const Teuchos::ArrayView<const GlobalOrdinal> &indices, 00114 const Teuchos::ArrayView<const Scalar> &values) = 0; 00115 virtual void 00116 sumIntoGlobalValues (GlobalOrdinal globalRow, 00117 const Teuchos::ArrayView<const GlobalOrdinal> &indices, 00118 const Teuchos::ArrayView<const Scalar> &values) = 0; 00119 }; 00120 00121 template <class Scalar = CrsMatrix<>::scalar_type, 00122 class LocalOrdinal = typename CrsMatrix<Scalar>::local_ordinal_type, 00123 class GlobalOrdinal = typename CrsMatrix<Scalar, LocalOrdinal>::global_ordinal_type, 00124 class Node = typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal>::node_type> 00125 class CrsWrapper_CrsMatrix : 00126 public CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node> { 00127 public: 00128 typedef Map<LocalOrdinal, GlobalOrdinal, Node> map_type; 00129 typedef CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> crs_matrix_type; 00130 00131 CrsWrapper_CrsMatrix (crs_matrix_type& crsmatrix); 00132 virtual ~CrsWrapper_CrsMatrix (); 00133 Teuchos::RCP<const map_type> getRowMap () const; 00134 00135 bool isFillComplete (); 00136 00137 void 00138 insertGlobalValues (GlobalOrdinal globalRow, 00139 const Teuchos::ArrayView<const GlobalOrdinal> &indices, 00140 const Teuchos::ArrayView<const Scalar> &values); 00141 void 00142 sumIntoGlobalValues (GlobalOrdinal globalRow, 00143 const Teuchos::ArrayView<const GlobalOrdinal> &indices, 00144 const Teuchos::ArrayView<const Scalar> &values); 00145 private: 00146 crs_matrix_type& crsmat_; 00147 }; 00148 00149 00150 template <class Scalar = CrsMatrix<>::scalar_type, 00151 class LocalOrdinal = typename CrsMatrix<Scalar>::local_ordinal_type, 00152 class GlobalOrdinal = 00153 typename CrsMatrix<Scalar, LocalOrdinal>::global_ordinal_type, 00154 class Node = 00155 typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal>::node_type> 00156 class CrsWrapper_GraphBuilder : 00157 public CrsWrapper<Scalar, LocalOrdinal, GlobalOrdinal, Node> { 00158 public: 00159 typedef Map<LocalOrdinal, GlobalOrdinal, Node> map_type; 00160 00161 CrsWrapper_GraphBuilder (const Teuchos::RCP<const map_type>& map); 00162 virtual ~CrsWrapper_GraphBuilder (); 00163 00164 Teuchos::RCP<const map_type> getRowMap () const { 00165 return rowmap_; 00166 } 00167 00168 bool isFillComplete (); 00169 void 00170 insertGlobalValues (GlobalOrdinal globalRow, 00171 const Teuchos::ArrayView<const GlobalOrdinal> &indices, 00172 const Teuchos::ArrayView<const Scalar> &values); 00173 void 00174 sumIntoGlobalValues (GlobalOrdinal globalRow, 00175 const Teuchos::ArrayView<const GlobalOrdinal> &indices, 00176 const Teuchos::ArrayView<const Scalar> &values); 00177 00178 std::map<GlobalOrdinal, std::set<GlobalOrdinal>*>& get_graph (); 00179 00180 size_t get_max_row_length () { 00181 return max_row_length_; 00182 } 00183 00184 private: 00185 std::map<GlobalOrdinal, std::set<GlobalOrdinal>*> graph_; 00186 const Teuchos::RCP<const map_type>& rowmap_; 00187 global_size_t max_row_length_; 00188 }; 00189 00190 template<class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> 00191 void 00192 insert_matrix_locations (CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>& graphbuilder, 00193 CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>& C); 00194 00195 } // namespace Tpetra 00196 #endif // TPETRA_MMHELPERS_DECL_HPP 00197
1.7.6.1