EpetraExt  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EpetraExt_BlockCrsMatrix.h
Go to the documentation of this file.
1 //@HEADER
2 // ***********************************************************************
3 //
4 // EpetraExt: Epetra Extended - Linear Algebra Services Package
5 // Copyright (2011) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
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 #ifndef EPETRAEXT_BLOCKCRSMATRIX_H
43 #define EPETRAEXT_BLOCKCRSMATRIX_H
44 
45 #if defined(EpetraExt_SHOW_DEPRECATED_WARNINGS)
46 #ifdef __GNUC__
47 #warning "The EpetraExt package is deprecated"
48 #endif
49 #endif
50 
51 #include <vector>
52 
53 #include "Epetra_ConfigDefs.h"
54 #include "Epetra_CrsMatrix.h"
55 
57 
64 namespace EpetraExt {
65 
67  public:
68 
70 
80 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
81  BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const std::vector<int> & RowStencil, int RowIndex, const Epetra_Comm & GlobalComm );
82 #endif
83 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
84  BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const std::vector<long long> & RowStencil, long long RowIndex, const Epetra_Comm & GlobalComm );
85 #endif
86 
88 
97 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
98  BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const std::vector< std::vector<int> > & RowStencil, const std::vector<int> & RowIndices, const Epetra_Comm & GlobalComm );
99 #endif
100 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
101  BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const std::vector< std::vector<long long> > & RowStencil, const std::vector<long long> & RowIndices, const Epetra_Comm & GlobalComm );
102 #endif
103 
105  BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const Epetra_CrsGraph& LocalBlockGraph, const Epetra_Comm & GlobalComm );
106 
107 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
108  BlockCrsMatrix( const Epetra_RowMatrix & BaseMatrix, const std::vector< std::vector<int> > & RowStencil, const std::vector<int> & RowIndices, const Epetra_Comm & GlobalComm );
109 #endif
110 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
111  BlockCrsMatrix( const Epetra_RowMatrix & BaseMatrix, const std::vector< std::vector<long long> > & RowStencil, const std::vector<long long> & RowIndices, const Epetra_Comm & GlobalComm );
112 #endif
113 
115  BlockCrsMatrix( const BlockCrsMatrix & Matrix );
116 
118  virtual ~BlockCrsMatrix();
120 
121 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
122  const std::vector<int> & Stencil( int i = 0 ) {
125  return RowStencil_int_[i];
126  else
127  throw "EpetraExt::BlockCrsMatrix::Stencil: Global Indices not int";
128  }
129 
131  int RowIndex( int i = 0 ) {
133  return RowIndices_int_[i];
134  else
135  throw "EpetraExt::BlockCrsMatrix::RowIndex: Global Indices not int";
136  }
137 #endif
138 
139 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
140  const std::vector<long long> & Stencil64( int i = 0 ) {
143  return RowStencil_LL_[i];
144  else
145  throw "EpetraExt::BlockCrsMatrix::Stencil: Global Indices not long long";
146  }
147 
149  long long RowIndex64( int i = 0 ) {
151  return RowIndices_LL_[i];
152  else
153  throw "EpetraExt::BlockCrsMatrix::RowIndex: Global Indices not long long";
154  }
155 #endif
156 
159 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
160  void LoadBlock(const Epetra_RowMatrix & BaseMatrix, const int Row, const int Col);
161 #endif
162 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
163  void LoadBlock(const Epetra_RowMatrix & BaseMatrix, const long long Row, const long long Col);
164 #endif
165 
168 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
169  void SumIntoBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const int Row, const int Col);
170 #endif
171 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
172  void SumIntoBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const long long Row, const long long Col);
173 #endif
174 
177 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
178  void SumIntoGlobalBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const int Row, const int Col);
179 #endif
180 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
181  void SumIntoGlobalBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const long long Row, const long long Col);
182 #endif
183 
186 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
187  void BlockSumIntoGlobalValues(const int BaseRow, int NumIndices,
188  double* Values, const int* Indices, const int Row, const int Col);
189 #endif
190 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
191  void BlockSumIntoGlobalValues(const long long BaseRow, int NumIndices,
192  double* Values, const long long* Indices, const long long Row, const long long Col);
193 #endif
194 
195 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
196  void BlockReplaceGlobalValues(const int BaseRow, int NumIndices,
197  double* Values, const int* Indices, const int Row, const int Col);
198 #endif
199 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
200  void BlockReplaceGlobalValues(const long long BaseRow, int NumIndices,
201  double* Values, const long long* Indices, const long long Row, const long long Col);
202 #endif
203 
204 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
205  void BlockExtractGlobalRowView(const int BaseRow, int& NumEntries,
206  double*& Values, const int Row, const int Col);
207 #endif
208 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
209  void BlockExtractGlobalRowView(const long long BaseRow, int& NumEntries,
210  double*& Values, const long long Row, const long long Col);
211 #endif
212 
213 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
214  void ExtractBlock(Epetra_CrsMatrix & BaseMatrix, const int Row, const int Col);
215 #endif
216 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
217  void ExtractBlock(Epetra_CrsMatrix & BaseMatrix, const long long Row, const long long Col);
218 #endif
219 
220  protected:
221 
223 
224 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
225  std::vector< std::vector<int> > RowStencil_int_;
226 
227  std::vector<int> RowIndices_int_;
228 #endif
229 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
230  std::vector< std::vector<long long> > RowStencil_LL_;
231 
232  std::vector<long long> RowIndices_LL_;
233 #endif
234 
235  long long ROffset_;
236  long long COffset_;
237 
238 private:
239  template<typename int_type>
240  void TLoadBlock(const Epetra_RowMatrix & BaseMatrix, const int_type Row, const int_type Col);
241 
242  template<typename int_type>
243  void TSumIntoBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const int_type Row, const int_type Col);
244 
245  template<typename int_type>
246  void TSumIntoGlobalBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const int_type Row, const int_type Col);
247 
248  template<typename int_type>
249  void TBlockSumIntoGlobalValues(const int_type BaseRow, int NumIndices,
250  double* Values, const int_type* Indices, const int_type Row, const int_type Col);
251 
252  template<typename int_type>
253  void TBlockReplaceGlobalValues(const int_type BaseRow, int NumIndices,
254  double* Values, const int_type* Indices, const int_type Row, const int_type Col);
255 
256  template<typename int_type>
257  void TBlockExtractGlobalRowView(const int_type BaseRow, int& NumEntries,
258  double*& Values, const int_type Row, const int_type Col);
259 
260  template<typename int_type>
261  void TExtractBlock(Epetra_CrsMatrix & BaseMatrix, const int_type Row, const int_type Col);
262 
263  template<typename int_type>
264  std::vector< std::vector<int_type> >& TRowStencil();
265 
266  template<typename int_type>
267  std::vector<int_type>& TRowIndices();
268 };
269 
270 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
271 template<> inline std::vector<int>& BlockCrsMatrix::TRowIndices() { return RowIndices_int_; }
272 template<> inline std::vector< std::vector<int> >& BlockCrsMatrix::TRowStencil() { return RowStencil_int_; }
273 #endif
274 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
275 template<> inline std::vector<long long>& BlockCrsMatrix::TRowIndices() { return RowIndices_LL_; }
276 template<> inline std::vector< std::vector<long long> >& BlockCrsMatrix::TRowStencil() { return RowStencil_LL_; }
277 #endif
278 
279 } //namespace EpetraExt
280 
281 #endif /* EPETRA_CRSMATRIX_H */
void LoadBlock(const Epetra_RowMatrix &BaseMatrix, const int Row, const int Col)
Routine for loading a base matrices values into the large Block Matrix The Row and Col arguments are ...
bool GlobalIndicesLongLong() const
std::vector< std::vector< int > > RowStencil_int_
void BlockReplaceGlobalValues(const int BaseRow, int NumIndices, double *Values, const int *Indices, const int Row, const int Col)
std::vector< long long > RowIndices_LL_
void ExtractBlock(Epetra_CrsMatrix &BaseMatrix, const int Row, const int Col)
bool GlobalIndicesInt() const
void BlockExtractGlobalRowView(const int BaseRow, int &NumEntries, double *&Values, const int Row, const int Col)
std::vector< std::vector< long long > > RowStencil_LL_
const std::vector< int > & Stencil(int i=0)
Local Stencil Info.
void SumIntoGlobalBlock(double alpha, const Epetra_RowMatrix &BaseMatrix, const int Row, const int Col)
Routine for summing base matrices values into the large Block Matrix The Row and Col arguments are gl...
const Epetra_BlockMap & RowMap() const
BlockCrsMatrix(const Epetra_CrsGraph &BaseGraph, const std::vector< int > &RowStencil, int RowIndex, const Epetra_Comm &GlobalComm)
BlockCrsMatrix constuctor with one block row per processor.
const std::vector< long long > & Stencil64(int i=0)
Local Stencil Info.
void SumIntoBlock(double alpha, const Epetra_RowMatrix &BaseMatrix, const int Row, const int Col)
Routine for summing base matrices values into the large Block Matrix The Row and Col arguments are in...
void BlockSumIntoGlobalValues(const int BaseRow, int NumIndices, double *Values, const int *Indices, const int Row, const int Col)
Sum Entries into Block matrix using base-matrix numbering plus block Row and Col The Row and Col argu...
long long RowIndex64(int i=0)
RowIndex.