HYPRE_Int HYPRE_SStructGridDestroy( HYPRE_SStructGrid grid ) { HYPRE_Int nparts; hypre_SStructPGrid **pgrids; HYPRE_Int *nneighbors; hypre_SStructNeighbor **neighbors; hypre_Index **nbor_offsets; HYPRE_Int **nvneighbors; hypre_SStructNeighbor ***vneighbors; hypre_SStructCommInfo **vnbor_comm_info; HYPRE_Int vnbor_ncomms; HYPRE_Int *fem_nvars; HYPRE_Int **fem_vars; hypre_Index **fem_offsets; hypre_BoxManager ***managers; hypre_BoxManager ***nbor_managers; HYPRE_Int nvars; HYPRE_Int part, var, i; if (grid) { hypre_SStructGridRefCount(grid) --; if (hypre_SStructGridRefCount(grid) == 0) { nparts = hypre_SStructGridNParts(grid); pgrids = hypre_SStructGridPGrids(grid); nneighbors = hypre_SStructGridNNeighbors(grid); neighbors = hypre_SStructGridNeighbors(grid); nbor_offsets = hypre_SStructGridNborOffsets(grid); nvneighbors = hypre_SStructGridNVNeighbors(grid); vneighbors = hypre_SStructGridVNeighbors(grid); vnbor_comm_info = hypre_SStructGridVNborCommInfo(grid); vnbor_ncomms = hypre_SStructGridVNborNComms(grid); fem_nvars = hypre_SStructGridFEMNVars(grid); fem_vars = hypre_SStructGridFEMVars(grid); fem_offsets = hypre_SStructGridFEMOffsets(grid); managers = hypre_SStructGridBoxManagers(grid); nbor_managers = hypre_SStructGridNborBoxManagers(grid); for (part = 0; part < nparts; part++) { nvars = hypre_SStructPGridNVars(pgrids[part]); for (var = 0; var < nvars; var++) { hypre_TFree(vneighbors[part][var]); hypre_BoxManDestroy(managers[part][var]); hypre_BoxManDestroy(nbor_managers[part][var]); } hypre_TFree(neighbors[part]); hypre_TFree(nbor_offsets[part]); hypre_TFree(nvneighbors[part]); hypre_TFree(vneighbors[part]); hypre_SStructPGridDestroy(pgrids[part]); hypre_TFree(fem_vars[part]); hypre_TFree(fem_offsets[part]); hypre_TFree(managers[part]); hypre_TFree(nbor_managers[part]); } for (i = 0; i < vnbor_ncomms; i++) { hypre_CommInfoDestroy( hypre_SStructCommInfoCommInfo(vnbor_comm_info[i])); hypre_TFree(vnbor_comm_info[i]); } hypre_TFree(vnbor_comm_info); hypre_TFree(pgrids); hypre_TFree(nneighbors); hypre_TFree(neighbors); hypre_TFree(nbor_offsets); hypre_TFree(fem_nvars); hypre_TFree(fem_vars); hypre_TFree(fem_offsets); hypre_TFree(nvneighbors); hypre_TFree(vneighbors); hypre_TFree(vnbor_comm_info); hypre_TFree(managers); hypre_TFree(nbor_managers); hypre_TFree(grid); } } return hypre_error_flag; }
int hypre_SStructUMatrixInitialize( hypre_SStructMatrix *matrix ) { HYPRE_IJMatrix ijmatrix = hypre_SStructMatrixIJMatrix(matrix); hypre_SStructGraph *graph = hypre_SStructMatrixGraph(matrix); hypre_SStructGrid *grid = hypre_SStructGraphGrid(graph); int nparts = hypre_SStructGraphNParts(graph); hypre_SStructPGrid **pgrids = hypre_SStructGraphPGrids(graph); hypre_SStructStencil ***stencils = hypre_SStructGraphStencils(graph); int nUventries = hypre_SStructGraphNUVEntries(graph); int *iUventries = hypre_SStructGraphIUVEntries(graph); hypre_SStructUVEntry **Uventries = hypre_SStructGraphUVEntries(graph); int **nvneighbors = hypre_SStructGridNVNeighbors(grid); hypre_StructGrid *sgrid; hypre_SStructStencil *stencil; int *split; int nvars; int nrows, nnzs ; int part, var, entry, i, j, k,m,b; int *row_sizes; int max_row_size; int matrix_type = hypre_SStructMatrixObjectType(matrix); hypre_Box *gridbox; hypre_Box *loopbox; hypre_Box *ghostbox; hypre_BoxArray *boxes; int *num_ghost; HYPRE_IJMatrixSetObjectType(ijmatrix, HYPRE_PARCSR); /* GEC1002 the ghlocalsize is used to set the number of rows */ if (matrix_type == HYPRE_PARCSR) { nrows = hypre_SStructGridLocalSize(grid); } if (matrix_type == HYPRE_SSTRUCT || matrix_type == HYPRE_STRUCT) { nrows = hypre_SStructGridGhlocalSize(grid) ; } /* set row sizes */ m = 0; row_sizes = hypre_CTAlloc(int, nrows); max_row_size = 0; for (part = 0; part < nparts; part++) { nvars = hypre_SStructPGridNVars(pgrids[part]); for (var = 0; var < nvars; var++) { sgrid = hypre_SStructPGridSGrid(pgrids[part], var); stencil = stencils[part][var]; split = hypre_SStructMatrixSplit(matrix, part, var); nnzs = 0; for (entry = 0; entry < hypre_SStructStencilSize(stencil); entry++) { if (split[entry] == -1) { nnzs++; } } #if 0 /* TODO: For now, assume stencil is full/complete */ if (hypre_SStructMatrixSymmetric(matrix)) { nnzs = 2*nnzs - 1; } #endif /**************/ boxes = hypre_StructGridBoxes(sgrid) ; num_ghost = hypre_StructGridNumGhost(sgrid); for (b = 0; b < hypre_BoxArraySize(boxes); b++) { gridbox = hypre_BoxArrayBox(boxes, b); ghostbox = hypre_BoxCreate(); loopbox = hypre_BoxCreate(); hypre_CopyBox(gridbox,ghostbox); hypre_BoxExpand(ghostbox,num_ghost); if (matrix_type == HYPRE_SSTRUCT || matrix_type == HYPRE_STRUCT) { hypre_CopyBox(ghostbox,loopbox); } if (matrix_type == HYPRE_PARCSR) { hypre_CopyBox(gridbox,loopbox); } for (k = hypre_BoxIMinZ(loopbox); k <= hypre_BoxIMaxZ(loopbox); k++) { for (j = hypre_BoxIMinY(loopbox); j <= hypre_BoxIMaxY(loopbox); j++) { for (i = hypre_BoxIMinX(loopbox); i <= hypre_BoxIMaxX(loopbox); i++) { if ( ( ( i>=hypre_BoxIMinX(gridbox) ) && ( j>=hypre_BoxIMinY(gridbox) ) ) && ( k>=hypre_BoxIMinZ(gridbox) ) ) { if ( ( ( i<=hypre_BoxIMaxX(gridbox) ) && ( j<=hypre_BoxIMaxY(gridbox) ) ) && ( k<=hypre_BoxIMaxZ(gridbox) ) ) { row_sizes[m] = nnzs; max_row_size = hypre_max(max_row_size, row_sizes[m]); } } m++; } } } hypre_BoxDestroy(ghostbox); hypre_BoxDestroy(loopbox); } if (nvneighbors[part][var]) { max_row_size = hypre_max(max_row_size, hypre_SStructStencilSize(stencil)); } /*********************/ } } /* GEC0902 essentially for each UVentry we figure out how many extra columns * we need to add to the rowsizes */ for (entry = 0; entry < nUventries; entry++) { i = iUventries[entry]; row_sizes[i] += hypre_SStructUVEntryNUEntries(Uventries[i]); max_row_size = hypre_max(max_row_size, row_sizes[i]); } /* ZTODO: Update row_sizes based on neighbor off-part couplings */ HYPRE_IJMatrixSetRowSizes (ijmatrix, (const int *) row_sizes); hypre_TFree(row_sizes); hypre_SStructMatrixTmpColCoords(matrix) = hypre_CTAlloc(HYPRE_BigInt, max_row_size); hypre_SStructMatrixTmpCoeffs(matrix) = hypre_CTAlloc(double, max_row_size); /* GEC1002 at this point the processor has the partitioning (creation of ij) */ HYPRE_IJMatrixInitialize(ijmatrix); return hypre_error_flag; }