EpetraExt Package Browser (Single Doxygen Collection) Development
Loading...
Searching...
No Matches
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#include <vector>
46
47#include "Epetra_ConfigDefs.h"
48#include "Epetra_CrsMatrix.h"
49
51
58namespace EpetraExt {
59
61 public:
62
64
74#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
75 BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const std::vector<int> & RowStencil, int RowIndex, const Epetra_Comm & GlobalComm );
76#endif
77#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
78 BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const std::vector<long long> & RowStencil, long long RowIndex, const Epetra_Comm & GlobalComm );
79#endif
80
82
91#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
92 BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const std::vector< std::vector<int> > & RowStencil, const std::vector<int> & RowIndices, const Epetra_Comm & GlobalComm );
93#endif
94#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
95 BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const std::vector< std::vector<long long> > & RowStencil, const std::vector<long long> & RowIndices, const Epetra_Comm & GlobalComm );
96#endif
97
99 BlockCrsMatrix( const Epetra_CrsGraph & BaseGraph, const Epetra_CrsGraph& LocalBlockGraph, const Epetra_Comm & GlobalComm );
100
101#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
102 BlockCrsMatrix( const Epetra_RowMatrix & BaseMatrix, const std::vector< std::vector<int> > & RowStencil, const std::vector<int> & RowIndices, const Epetra_Comm & GlobalComm );
103#endif
104#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
105 BlockCrsMatrix( const Epetra_RowMatrix & BaseMatrix, const std::vector< std::vector<long long> > & RowStencil, const std::vector<long long> & RowIndices, const Epetra_Comm & GlobalComm );
106#endif
107
109 BlockCrsMatrix( const BlockCrsMatrix & Matrix );
110
112 virtual ~BlockCrsMatrix();
114
115#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
117 const std::vector<int> & Stencil( int i = 0 ) {
118 if(BaseGraph_.RowMap().GlobalIndicesInt())
119 return RowStencil_int_[i];
120 else
121 throw "EpetraExt::BlockCrsMatrix::Stencil: Global Indices not int";
122 }
123
125 int RowIndex( int i = 0 ) {
126 if(BaseGraph_.RowMap().GlobalIndicesInt())
127 return RowIndices_int_[i];
128 else
129 throw "EpetraExt::BlockCrsMatrix::RowIndex: Global Indices not int";
130 }
131#endif
132
133#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
135 const std::vector<long long> & Stencil64( int i = 0 ) {
136 if(BaseGraph_.RowMap().GlobalIndicesLongLong())
137 return RowStencil_LL_[i];
138 else
139 throw "EpetraExt::BlockCrsMatrix::Stencil: Global Indices not long long";
140 }
141
143 long long RowIndex64( int i = 0 ) {
144 if(BaseGraph_.RowMap().GlobalIndicesLongLong())
145 return RowIndices_LL_[i];
146 else
147 throw "EpetraExt::BlockCrsMatrix::RowIndex: Global Indices not long long";
148 }
149#endif
150
153#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
154 void LoadBlock(const Epetra_RowMatrix & BaseMatrix, const int Row, const int Col);
155#endif
156#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
157 void LoadBlock(const Epetra_RowMatrix & BaseMatrix, const long long Row, const long long Col);
158#endif
159
162#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
163 void SumIntoBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const int Row, const int Col);
164#endif
165#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
166 void SumIntoBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const long long Row, const long long Col);
167#endif
168
171#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
172 void SumIntoGlobalBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const int Row, const int Col);
173#endif
174#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
175 void SumIntoGlobalBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const long long Row, const long long Col);
176#endif
177
180#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
181 void BlockSumIntoGlobalValues(const int BaseRow, int NumIndices,
182 double* Values, const int* Indices, const int Row, const int Col);
183#endif
184#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
185 void BlockSumIntoGlobalValues(const long long BaseRow, int NumIndices,
186 double* Values, const long long* Indices, const long long Row, const long long Col);
187#endif
188
189#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
190 void BlockReplaceGlobalValues(const int BaseRow, int NumIndices,
191 double* Values, const int* Indices, const int Row, const int Col);
192#endif
193#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
194 void BlockReplaceGlobalValues(const long long BaseRow, int NumIndices,
195 double* Values, const long long* Indices, const long long Row, const long long Col);
196#endif
197
198#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
199 void BlockExtractGlobalRowView(const int BaseRow, int& NumEntries,
200 double*& Values, const int Row, const int Col);
201#endif
202#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
203 void BlockExtractGlobalRowView(const long long BaseRow, int& NumEntries,
204 double*& Values, const long long Row, const long long Col);
205#endif
206
207#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
208 void ExtractBlock(Epetra_CrsMatrix & BaseMatrix, const int Row, const int Col);
209#endif
210#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
211 void ExtractBlock(Epetra_CrsMatrix & BaseMatrix, const long long Row, const long long Col);
212#endif
213
214 protected:
215
217
218#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
219 std::vector< std::vector<int> > RowStencil_int_;
220
221 std::vector<int> RowIndices_int_;
222#endif
223#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
224 std::vector< std::vector<long long> > RowStencil_LL_;
225
226 std::vector<long long> RowIndices_LL_;
227#endif
228
229 long long ROffset_;
230 long long COffset_;
231
232private:
233 template<typename int_type>
234 void TLoadBlock(const Epetra_RowMatrix & BaseMatrix, const int_type Row, const int_type Col);
235
236 template<typename int_type>
237 void TSumIntoBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const int_type Row, const int_type Col);
238
239 template<typename int_type>
240 void TSumIntoGlobalBlock(double alpha, const Epetra_RowMatrix & BaseMatrix, const int_type Row, const int_type Col);
241
242 template<typename int_type>
243 void TBlockSumIntoGlobalValues(const int_type BaseRow, int NumIndices,
244 double* Values, const int_type* Indices, const int_type Row, const int_type Col);
245
246 template<typename int_type>
247 void TBlockReplaceGlobalValues(const int_type BaseRow, int NumIndices,
248 double* Values, const int_type* Indices, const int_type Row, const int_type Col);
249
250 template<typename int_type>
251 void TBlockExtractGlobalRowView(const int_type BaseRow, int& NumEntries,
252 double*& Values, const int_type Row, const int_type Col);
253
254 template<typename int_type>
255 void TExtractBlock(Epetra_CrsMatrix & BaseMatrix, const int_type Row, const int_type Col);
256
257 template<typename int_type>
258 std::vector< std::vector<int_type> >& TRowStencil();
259
260 template<typename int_type>
261 std::vector<int_type>& TRowIndices();
262};
263
264#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
265template<> inline std::vector<int>& BlockCrsMatrix::TRowIndices() { return RowIndices_int_; }
266template<> inline std::vector< std::vector<int> >& BlockCrsMatrix::TRowStencil() { return RowStencil_int_; }
267#endif
268#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
269template<> inline std::vector<long long>& BlockCrsMatrix::TRowIndices() { return RowIndices_LL_; }
270template<> inline std::vector< std::vector<long long> >& BlockCrsMatrix::TRowStencil() { return RowStencil_LL_; }
271#endif
272
273} //namespace EpetraExt
274
275#endif /* EPETRA_CRSMATRIX_H */
const std::vector< long long > & Stencil64(int i=0)
Local Stencil Info.
BlockCrsMatrix(const Epetra_RowMatrix &BaseMatrix, const std::vector< std::vector< int > > &RowStencil, const std::vector< int > &RowIndices, const Epetra_Comm &GlobalComm)
void TBlockSumIntoGlobalValues(const int_type BaseRow, int NumIndices, double *Values, const int_type *Indices, const int_type Row, const int_type Col)
void TBlockExtractGlobalRowView(const int_type BaseRow, int &NumEntries, double *&Values, const int_type Row, const int_type Col)
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...
std::vector< std::vector< int > > RowStencil_int_
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...
std::vector< std::vector< int_type > > & TRowStencil()
void BlockExtractGlobalRowView(const int BaseRow, int &NumEntries, double *&Values, const int Row, const int Col)
std::vector< int_type > & TRowIndices()
void TBlockReplaceGlobalValues(const int_type BaseRow, int NumIndices, double *Values, const int_type *Indices, const int_type Row, const int_type Col)
void TSumIntoGlobalBlock(double alpha, const Epetra_RowMatrix &BaseMatrix, const int_type Row, const int_type Col)
BlockCrsMatrix(const Epetra_RowMatrix &BaseMatrix, const std::vector< std::vector< long long > > &RowStencil, const std::vector< long long > &RowIndices, const Epetra_Comm &GlobalComm)
void ExtractBlock(Epetra_CrsMatrix &BaseMatrix, const int Row, const int Col)
std::vector< std::vector< long long > > RowStencil_LL_
BlockCrsMatrix(const Epetra_CrsGraph &BaseGraph, const std::vector< long long > &RowStencil, long long RowIndex, const Epetra_Comm &GlobalComm)
void TLoadBlock(const Epetra_RowMatrix &BaseMatrix, const int_type Row, const int_type Col)
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.
void BlockReplaceGlobalValues(const int BaseRow, int NumIndices, double *Values, const int *Indices, const int Row, const int Col)
const std::vector< int > & Stencil(int i=0)
Local Stencil Info.
void TExtractBlock(Epetra_CrsMatrix &BaseMatrix, const int_type Row, const int_type Col)
std::vector< long long > RowIndices_LL_
BlockCrsMatrix(const Epetra_CrsGraph &BaseGraph, const std::vector< std::vector< long long > > &RowStencil, const std::vector< long long > &RowIndices, const Epetra_Comm &GlobalComm)
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 ...
BlockCrsMatrix(const Epetra_CrsGraph &BaseGraph, const std::vector< std::vector< int > > &RowStencil, const std::vector< int > &RowIndices, const Epetra_Comm &GlobalComm)
BlockCrsMatrix constuctor with multiple block rows per processor.
void TSumIntoBlock(double alpha, const Epetra_RowMatrix &BaseMatrix, const int_type Row, const int_type Col)
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 Epetra_BlockMap & RowMap() const
double ** Values() const
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.