43 #include "Epetra_Map.h" 44 #include "Epetra_Comm.h" 52 const Epetra_BlockMap & BaseMap,
53 const int * RowIndices,
55 const Epetra_Comm & GlobalComm,
58 int BaseIndex = BaseMap.IndexBase();
63 int Size = BaseMap.NumMyElements();
64 int TotalSize = NumBlockRows * Size;
65 vector<int> GIDs(Size);
66 BaseMap.MyGlobalElements( &GIDs[0] );
68 vector<int> GlobalGIDs( TotalSize );
69 for(
int i = 0; i < NumBlockRows; ++i )
71 for(
int j = 0; j < Size; ++j )
72 GlobalGIDs[i*Size+j] = GIDs[j] + RowIndices[i] * Offset;
76 GlobalComm.SumAll( &TotalSize, &GlobalSize, 1 );
78 Epetra_Map *GlobalMap =
79 new Epetra_Map( GlobalSize, TotalSize, &GlobalGIDs[0], BaseIndex,
87 const Epetra_BlockMap & BaseMap,
88 const std::vector<int>& RowIndices,
89 const Epetra_Comm & GlobalComm,
98 const Epetra_BlockMap & BaseMap,
99 const Epetra_BlockMap& BlockMap,
100 const Epetra_Comm & GlobalComm,
104 BlockMap.MyGlobalElements(),
105 BlockMap.NumMyElements(),
112 const Epetra_CrsGraph & BaseGraph,
113 const vector< vector<int> > & RowStencil,
114 const vector<int> & RowIndices,
115 const Epetra_Comm & GlobalComm )
118 const Epetra_BlockMap & BaseMap = BaseGraph.RowMap();
119 int BaseIndex = BaseMap.IndexBase();
123 int NumBlockRows = RowIndices.size();
124 int Size = BaseMap.NumMyElements();
125 int TotalSize = NumBlockRows * Size;
126 vector<int> GIDs(Size);
127 BaseMap.MyGlobalElements( &GIDs[0] );
129 vector<int> GlobalGIDs( TotalSize );
130 for(
int i = 0; i < NumBlockRows; ++i )
132 for(
int j = 0; j < Size; ++j )
133 GlobalGIDs[i*Size+j] = GIDs[j] + RowIndices[i] * Offset;
137 GlobalComm.SumAll( &TotalSize, &GlobalSize, 1 );
139 Epetra_Map GlobalMap( GlobalSize, TotalSize, &GlobalGIDs[0], BaseIndex, GlobalComm );
141 int MaxIndices = BaseGraph.MaxNumIndices();
142 vector<int> Indices(MaxIndices);
145 Epetra_CrsGraph * GlobalGraph =
new Epetra_CrsGraph( Copy,
146 dynamic_cast<Epetra_BlockMap&>(GlobalMap),
149 for(
int i = 0; i < NumBlockRows; ++i )
151 int StencilSize = RowStencil[i].size();
152 for(
int j = 0; j < Size; ++j )
154 int BaseRow = BaseMap.GID(j);
155 int GlobalRow = GlobalMap.GID(j+i*Size);
157 BaseGraph.ExtractGlobalRowCopy( BaseRow, MaxIndices, NumIndices, &Indices[0] );
158 for(
int k = 0; k < StencilSize; ++k )
160 int ColOffset = (RowIndices[i]+RowStencil[i][k]) * Offset;
161 if( k > 0 ) ColOffset -= (RowIndices[i]+RowStencil[i][k-1]) * Offset;
163 for(
int l = 0; l < NumIndices; ++l )
164 Indices[l] += ColOffset;
166 GlobalGraph->InsertGlobalIndices( GlobalRow, NumIndices, &Indices[0] );
171 GlobalGraph->FillComplete();
178 const Epetra_RowMatrix & BaseMatrix,
179 const vector< vector<int> > & RowStencil,
180 const vector<int> & RowIndices,
181 const Epetra_Comm & GlobalComm )
184 const Epetra_BlockMap & BaseMap = BaseMatrix.RowMatrixRowMap();
185 const Epetra_BlockMap & BaseColMap = BaseMatrix.RowMatrixColMap();
186 int BaseIndex = BaseMap.IndexBase();
190 int NumBlockRows = RowIndices.size();
191 int Size = BaseMap.NumMyElements();
192 int TotalSize = NumBlockRows * Size;
193 vector<int> GIDs(Size);
194 BaseMap.MyGlobalElements( &GIDs[0] );
196 vector<int> GlobalGIDs( TotalSize );
197 for(
int i = 0; i < NumBlockRows; ++i )
199 for(
int j = 0; j < Size; ++j )
200 GlobalGIDs[i*Size+j] = GIDs[j] + RowIndices[i] * Offset;
204 GlobalComm.SumAll( &TotalSize, &GlobalSize, 1 );
206 Epetra_Map GlobalMap( GlobalSize, TotalSize, &GlobalGIDs[0], BaseIndex, GlobalComm );
208 int MaxIndices = BaseMatrix.MaxNumEntries();
209 vector<int> Indices(MaxIndices);
210 vector<double> Values(MaxIndices);
213 Epetra_CrsGraph * GlobalGraph =
new Epetra_CrsGraph( Copy,
214 dynamic_cast<Epetra_BlockMap&>(GlobalMap),
217 for(
int i = 0; i < NumBlockRows; ++i )
219 int StencilSize = RowStencil[i].size();
220 for(
int j = 0; j < Size; ++j )
222 int GlobalRow = GlobalMap.GID(j+i*Size);
224 BaseMatrix.ExtractMyRowCopy( j, MaxIndices, NumIndices, &Values[0], &Indices[0] );
225 for(
int l = 0; l < NumIndices; ++l ) Indices[l] = BaseColMap.GID(Indices[l]);
227 for(
int k = 0; k < StencilSize; ++k )
229 int ColOffset = (RowIndices[i]+RowStencil[i][k]) * Offset;
230 if( k > 0 ) ColOffset -= (RowIndices[i]+RowStencil[i][k-1]) * Offset;
232 for(
int l = 0; l < NumIndices; ++l )
233 Indices[l] += ColOffset;
235 GlobalGraph->InsertGlobalIndices( GlobalRow, NumIndices, &Indices[0] );
240 GlobalGraph->FillComplete();
247 const Epetra_CrsGraph & BaseGraph,
248 const Epetra_CrsGraph & LocalBlockGraph,
249 const Epetra_Comm & GlobalComm )
251 const Epetra_BlockMap & BaseRowMap = BaseGraph.RowMap();
252 const Epetra_BlockMap & BaseColMap = BaseGraph.ColMap();
258 const Epetra_BlockMap & BlockRowMap = LocalBlockGraph.RowMap();
259 const Epetra_BlockMap & BlockColMap = LocalBlockGraph.ColMap();
261 int NumBlockRows = BlockRowMap.NumMyElements();
262 vector<int> RowIndices(NumBlockRows);
263 BlockRowMap.MyGlobalElements(&RowIndices[0]);
265 int Size = BaseRowMap.NumMyElements();
267 Epetra_Map *GlobalRowMap =
271 int MaxIndices = BaseGraph.MaxNumIndices();
272 vector<int> Indices(MaxIndices);
274 Epetra_CrsGraph * GlobalGraph =
new Epetra_CrsGraph( Copy,
275 dynamic_cast<Epetra_BlockMap&>(*GlobalRowMap),
278 int NumBlockIndices, NumBaseIndices;
279 int *BlockIndices, *BaseIndices;
280 for(
int i = 0; i < NumBlockRows; ++i )
282 LocalBlockGraph.ExtractMyRowView(i, NumBlockIndices, BlockIndices);
284 for(
int j = 0; j < Size; ++j )
286 int GlobalRow = GlobalRowMap->GID(j+i*Size);
288 BaseGraph.ExtractMyRowView( j, NumBaseIndices, BaseIndices );
289 for(
int k = 0; k < NumBlockIndices; ++k )
291 int ColOffset = BlockColMap.GID(BlockIndices[k]) * COffset;
293 for(
int l = 0; l < NumBaseIndices; ++l )
294 Indices[l] = BaseGraph.GCID(BaseIndices[l]) + ColOffset;
296 GlobalGraph->InsertGlobalIndices( GlobalRow, NumBaseIndices, &Indices[0] );
301 const Epetra_BlockMap & BaseDomainMap = BaseGraph.DomainMap();
302 const Epetra_BlockMap & BaseRangeMap = BaseGraph.RangeMap();
303 const Epetra_BlockMap & BlockDomainMap = LocalBlockGraph.DomainMap();
304 const Epetra_BlockMap & BlockRangeMap = LocalBlockGraph.RangeMap();
306 Epetra_Map *GlobalDomainMap =
308 Epetra_Map *GlobalRangeMap =
311 GlobalGraph->FillComplete(*GlobalDomainMap, *GlobalRangeMap);
313 delete GlobalDomainMap;
314 delete GlobalRangeMap;
322 std::vector<int> RowIndices,
323 std::vector< std::vector<int> >& RowStencil)
326 int NumMyRows = LocalBlockGraph.NumMyRows();
327 RowIndices.resize(NumMyRows);
328 const Epetra_BlockMap& RowMap = LocalBlockGraph.RowMap();
329 RowMap.MyGlobalElements(&RowIndices[0]);
332 RowStencil.resize(NumMyRows);
333 if (LocalBlockGraph.IndicesAreGlobal()) {
334 for (
int i=0; i<NumMyRows; i++) {
335 int Row = RowIndices[i];
336 int NumCols = LocalBlockGraph.NumGlobalIndices(Row);
337 RowStencil[i].resize(NumCols);
338 LocalBlockGraph.ExtractGlobalRowCopy(Row, NumCols, NumCols,
340 for (
int k=0; k<NumCols; k++)
341 RowStencil[i][k] -= Row;
345 for (
int i=0; i<NumMyRows; i++) {
346 int NumCols = LocalBlockGraph.NumMyIndices(i);
347 RowStencil[i].resize(NumCols);
348 LocalBlockGraph.ExtractMyRowCopy(i, NumCols, NumCols,
350 for (
int k=0; k<NumCols; k++)
351 RowStencil[i][k] = LocalBlockGraph.GCID(RowStencil[i][k]) -
360 int MaxGID = BaseMap.MaxAllGID();
static void GenerateRowStencil(const Epetra_CrsGraph &LocalBlockGraph, std::vector< int > RowIndices, std::vector< std::vector< int > > &RowStencil)
Generate stencil arrays from a local block graph.
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.
static int CalculateOffset(const Epetra_BlockMap &BaseMap)
Routine for calculating Offset for creating unique global IDs for Block representation.
static Epetra_Map * GenerateBlockMap(const Epetra_BlockMap &BaseMap, const int *RowIndices, int num_indices, const Epetra_Comm &GlobalComm, int Offset=0)
static Epetra_CrsGraph * GenerateBlockGraph(const Epetra_CrsGraph &BaseGraph, const std::vector< std::vector< int > > &RowStencil, const std::vector< int > &RowIndices, const Epetra_Comm &GlobalComm)
BlockCrsMatrix constuctor.