本文整理汇总了C++中Epetra_CrsGraph::InsertGlobalIndices方法的典型用法代码示例。如果您正苦于以下问题:C++ Epetra_CrsGraph::InsertGlobalIndices方法的具体用法?C++ Epetra_CrsGraph::InsertGlobalIndices怎么用?C++ Epetra_CrsGraph::InsertGlobalIndices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Epetra_CrsGraph
的用法示例。
在下文中一共展示了Epetra_CrsGraph::InsertGlobalIndices方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: four_quads
int four_quads(const Epetra_Comm& Comm, bool preconstruct_graph, bool verbose)
{
if (verbose) {
cout << "******************* four_quads ***********************"<<endl;
}
//This function assembles a matrix representing a finite-element mesh
//of four 2-D quad elements. There are 9 nodes in the problem. The
//same problem is assembled no matter how many processors are being used
//(within reason). It may not work if more than 9 processors are used.
//
// *------*------*
// 6| 7| 8|
// | E2 | E3 |
// *------*------*
// 3| 4| 5|
// | E0 | E1 |
// *------*------*
// 0 1 2
//
//Nodes are denoted by * with node-numbers below and left of each node.
//E0, E1 and so on are element-numbers.
//
//Each processor will contribute a sub-matrix of size 4x4, filled with 1's,
//for each element. Thus, the coefficient value at position 0,0 should end up
//being 1.0*numProcs, the value at position 4,4 should be 1.0*4*numProcs, etc.
//
//Depending on the number of processors being used, the locations of the
//specific matrix positions (in terms of which processor owns them) will vary.
//
int numProcs = Comm.NumProc();
int numNodes = 9;
int numElems = 4;
int numNodesPerElem = 4;
int blockSize = 1;
int indexBase = 0;
//Create a map using epetra-defined linear distribution.
Epetra_BlockMap map(numNodes, blockSize, indexBase, Comm);
Epetra_CrsGraph* graph = NULL;
int* nodes = new int[numNodesPerElem];
int i, j, k, err = 0;
if (preconstruct_graph) {
graph = new Epetra_CrsGraph(Copy, map, 1);
//we're going to fill the graph with indices, but remember it will only
//accept indices in rows for which map.MyGID(row) is true.
for(i=0; i<numElems; ++i) {
switch(i) {
case 0:
nodes[0] = 0; nodes[1] = 1; nodes[2] = 4; nodes[3] = 3;
break;
case 1:
nodes[0] = 1; nodes[1] = 2; nodes[2] = 5; nodes[3] = 4;
break;
case 2:
nodes[0] = 3; nodes[1] = 4; nodes[2] = 7; nodes[3] = 6;
break;
case 3:
nodes[0] = 4; nodes[1] = 5; nodes[2] = 8; nodes[3] = 7;
break;
}
for(j=0; j<numNodesPerElem; ++j) {
if (map.MyGID(nodes[j])) {
err = graph->InsertGlobalIndices(nodes[j], numNodesPerElem,
nodes);
if (err<0) return(err);
}
}
}
EPETRA_CHK_ERR( graph->FillComplete() );
}
Epetra_FEVbrMatrix* A = NULL;
if (preconstruct_graph) {
A = new Epetra_FEVbrMatrix(Copy, *graph);
}
else {
A = new Epetra_FEVbrMatrix(Copy, map, 1);
}
//EPETRA_CHK_ERR( A->PutScalar(0.0) );
double* values_1d = new double[numNodesPerElem*numNodesPerElem];
double** values_2d = new double*[numNodesPerElem];
for(i=0; i<numNodesPerElem*numNodesPerElem; ++i) values_1d[i] = 1.0;
int offset = 0;
for(i=0; i<numNodesPerElem; ++i) {
//.........这里部分代码省略.........
示例2: GlobalMap
Epetra_CrsGraph * BlockUtility::TGenerateBlockGraph(
const Epetra_RowMatrix & BaseMatrix,
const vector< vector<int_type> > & RowStencil,
const vector<int_type> & RowIndices,
const Epetra_Comm & GlobalComm )
{
const Epetra_BlockMap & BaseMap = BaseMatrix.RowMatrixRowMap();
const Epetra_BlockMap & BaseColMap = BaseMatrix.RowMatrixColMap();
int_type BaseIndex = (int_type) BaseMap.IndexBase64();
int_type Offset = BlockUtility::TCalculateOffset<int_type>(BaseMap);
//Get Base Global IDs
int NumBlockRows = RowIndices.size();
int Size = BaseMap.NumMyElements();
int TotalSize = NumBlockRows * Size;
vector<int_type> GIDs(Size);
BaseMap.MyGlobalElements( &GIDs[0] );
vector<int_type> GlobalGIDs( TotalSize );
for( int i = 0; i < NumBlockRows; ++i )
{
for( int j = 0; j < Size; ++j )
GlobalGIDs[i*Size+j] = GIDs[j] + RowIndices[i] * Offset;
}
int_type GlobalSize;
int_type TotalSize_int_type = TotalSize;
GlobalComm.SumAll( &TotalSize_int_type, &GlobalSize, 1 );
Epetra_Map GlobalMap( GlobalSize, TotalSize, &GlobalGIDs[0], BaseIndex, GlobalComm );
int MaxIndices = BaseMatrix.MaxNumEntries();
vector<int> Indices_local(MaxIndices);
vector<int_type> Indices_global(MaxIndices);
vector<double> Values(MaxIndices);
int NumIndices;
Epetra_CrsGraph * GlobalGraph = new Epetra_CrsGraph( Copy,
dynamic_cast<Epetra_BlockMap&>(GlobalMap),
0 );
for( int i = 0; i < NumBlockRows; ++i )
{
int StencilSize = RowStencil[i].size();
for( int j = 0; j < Size; ++j )
{
int_type GlobalRow = (int_type) GlobalMap.GID64(j+i*Size);
BaseMatrix.ExtractMyRowCopy( j, MaxIndices, NumIndices, &Values[0], &Indices_local[0] );
for( int l = 0; l < NumIndices; ++l ) Indices_global[l] = (int_type) BaseColMap.GID64(Indices_local[l]);
for( int k = 0; k < StencilSize; ++k )
{
int_type ColOffset = (RowIndices[i]+RowStencil[i][k]) * Offset;
if( k > 0 ) ColOffset -= (RowIndices[i]+RowStencil[i][k-1]) * Offset;
for( int l = 0; l < NumIndices; ++l )
Indices_global[l] += ColOffset;
GlobalGraph->InsertGlobalIndices( GlobalRow, NumIndices, &Indices_global[0] );
}
}
}
GlobalGraph->FillComplete();
return GlobalGraph;
}
示例3: RowIndices
Epetra_CrsGraph * BlockUtility::TGenerateBlockGraph(
const Epetra_CrsGraph & BaseGraph,
const Epetra_CrsGraph & LocalBlockGraph,
const Epetra_Comm & GlobalComm )
{
const Epetra_BlockMap & BaseRowMap = BaseGraph.RowMap();
const Epetra_BlockMap & BaseColMap = BaseGraph.ColMap();
int_type ROffset = BlockUtility::TCalculateOffset<int_type>(BaseRowMap);
(void) ROffset; // Silence "unused variable" compiler warning.
int_type COffset = BlockUtility::TCalculateOffset<int_type>(BaseColMap);
//Get Base Global IDs
const Epetra_BlockMap & BlockRowMap = LocalBlockGraph.RowMap();
const Epetra_BlockMap & BlockColMap = LocalBlockGraph.ColMap();
int NumBlockRows = BlockRowMap.NumMyElements();
vector<int_type> RowIndices(NumBlockRows);
BlockRowMap.MyGlobalElements(&RowIndices[0]);
int Size = BaseRowMap.NumMyElements();
Epetra_Map *GlobalRowMap =
GenerateBlockMap(BaseRowMap, BlockRowMap, GlobalComm);
int MaxIndices = BaseGraph.MaxNumIndices();
vector<int_type> Indices(MaxIndices);
Epetra_CrsGraph * GlobalGraph = new Epetra_CrsGraph( Copy,
dynamic_cast<Epetra_BlockMap&>(*GlobalRowMap),
0 );
int NumBlockIndices, NumBaseIndices;
int *BlockIndices, *BaseIndices;
for( int i = 0; i < NumBlockRows; ++i )
{
LocalBlockGraph.ExtractMyRowView(i, NumBlockIndices, BlockIndices);
for( int j = 0; j < Size; ++j )
{
int_type GlobalRow = (int_type) GlobalRowMap->GID64(j+i*Size);
BaseGraph.ExtractMyRowView( j, NumBaseIndices, BaseIndices );
for( int k = 0; k < NumBlockIndices; ++k )
{
int_type ColOffset = (int_type) BlockColMap.GID64(BlockIndices[k]) * COffset;
for( int l = 0; l < NumBaseIndices; ++l )
Indices[l] = (int_type) BaseGraph.GCID64(BaseIndices[l]) + ColOffset;
GlobalGraph->InsertGlobalIndices( GlobalRow, NumBaseIndices, &Indices[0] );
}
}
}
const Epetra_BlockMap & BaseDomainMap = BaseGraph.DomainMap();
const Epetra_BlockMap & BaseRangeMap = BaseGraph.RangeMap();
const Epetra_BlockMap & BlockDomainMap = LocalBlockGraph.DomainMap();
const Epetra_BlockMap & BlockRangeMap = LocalBlockGraph.RangeMap();
Epetra_Map *GlobalDomainMap =
GenerateBlockMap(BaseDomainMap, BlockDomainMap, GlobalComm);
Epetra_Map *GlobalRangeMap =
GenerateBlockMap(BaseRangeMap, BlockRangeMap, GlobalComm);
GlobalGraph->FillComplete(*GlobalDomainMap, *GlobalRangeMap);
delete GlobalDomainMap;
delete GlobalRangeMap;
delete GlobalRowMap;
return GlobalGraph;
}
示例4: four_quads
int four_quads(const Epetra_Comm& Comm, bool preconstruct_graph, bool verbose)
{
if (verbose) {
cout << "******************* four_quads ***********************"<<endl;
}
//This function assembles a matrix representing a finite-element mesh
//of four 2-D quad elements. There are 9 nodes in the problem. The
//same problem is assembled no matter how many processors are being used
//(within reason). It may not work if more than 9 processors are used.
//
// *------*------*
// 6| 7| 8|
// | E2 | E3 |
// *------*------*
// 3| 4| 5|
// | E0 | E1 |
// *------*------*
// 0 1 2
//
//Nodes are denoted by * with node-numbers below and left of each node.
//E0, E1 and so on are element-numbers.
//
//Each processor will contribute a sub-matrix of size 4x4, filled with 1's,
//for each element. Thus, the coefficient value at position 0,0 should end up
//being 1.0*numProcs, the value at position 4,4 should be 1.0*4*numProcs, etc.
//
//Depending on the number of processors being used, the locations of the
//specific matrix positions (in terms of which processor owns them) will vary.
//
int numProcs = Comm.NumProc();
int numNodes = 9;
int numElems = 4;
int numNodesPerElem = 4;
int indexBase = 0;
//Create a map using epetra-defined linear distribution.
Epetra_Map map(numNodes, indexBase, Comm);
Epetra_CrsGraph* graph = NULL;
int* nodes = new int[numNodesPerElem];
int i, j, err = 0;
if (preconstruct_graph) {
graph = new Epetra_CrsGraph(Copy, map, 1);
//we're going to fill the graph with indices, but remember it will only
//accept indices in rows for which map.MyGID(row) is true.
for(i=0; i<numElems; ++i) {
switch(i) {
case 0:
nodes[0] = 0; nodes[1] = 1; nodes[2] = 4; nodes[3] = 3;
break;
case 1:
nodes[0] = 1; nodes[1] = 2; nodes[2] = 5; nodes[3] = 4;
break;
case 2:
nodes[0] = 3; nodes[1] = 4; nodes[2] = 7; nodes[3] = 6;
break;
case 3:
nodes[0] = 4; nodes[1] = 5; nodes[2] = 8; nodes[3] = 7;
break;
}
for(j=0; j<numNodesPerElem; ++j) {
if (map.MyGID(nodes[j])) {
err = graph->InsertGlobalIndices(nodes[j], numNodesPerElem,
nodes);
if (err<0) return(err);
}
}
}
EPETRA_CHK_ERR( graph->FillComplete() );
}
Epetra_FECrsMatrix* A = NULL;
if (preconstruct_graph) {
A = new Epetra_FECrsMatrix(Copy, *graph);
}
else {
A = new Epetra_FECrsMatrix(Copy, map, 1);
}
EPETRA_CHK_ERR( A->PutScalar(0.0) );
double* values_1d = new double[numNodesPerElem*numNodesPerElem];
double** values_2d = new double*[numNodesPerElem];
for(i=0; i<numNodesPerElem*numNodesPerElem; ++i) values_1d[i] = 1.0;
int offset = 0;
for(i=0; i<numNodesPerElem; ++i) {
values_2d[i] = &(values_1d[offset]);
//.........这里部分代码省略.........