int hypre_SStructGraphFindBoxEndpt(hypre_SStructGraph *graph, int part, int var, int proc, int endpt, int boxi) { hypre_SStructGrid *grid = hypre_SStructGraphGrid(graph); int type = hypre_SStructGraphObjectType(graph); hypre_BoxMap *map; hypre_BoxMapEntry *map_entry; hypre_StructGrid *sgrid; hypre_Box *box; int rank; HYPRE_BigInt big_rank; map= hypre_SStructGridMap(grid, part, var); hypre_BoxMapFindBoxProcEntry(map, boxi, proc, &map_entry); sgrid= hypre_SStructPGridSGrid(hypre_SStructGridPGrid(grid, part), var); box = hypre_StructGridBox(sgrid, boxi); /* get the global rank of the endpt corner of box boxi */ if (endpt < 1) { hypre_SStructMapEntryGetGlobalRank(map_entry, hypre_BoxIMin(box), &big_rank, type); } else { hypre_SStructMapEntryGetGlobalRank(map_entry, hypre_BoxIMax(box), &big_rank, type); } if (type == HYPRE_SSTRUCT || type == HYPRE_STRUCT) { rank = (int)(big_rank - hypre_SStructGridGhstartRank(grid)); } if (type == HYPRE_PARCSR) { rank = (int)(big_rank - hypre_SStructGridStartRank(grid)); } return rank; }
/*-------------------------------------------------------------------------- * hypre_SStructPMatrixInitialize *--------------------------------------------------------------------------*/ int hypre_SStructPMatrixInitialize( hypre_SStructPMatrix *pmatrix ) { int nvars = hypre_SStructPMatrixNVars(pmatrix); int **symmetric = hypre_SStructPMatrixSymmetric(pmatrix); hypre_SStructPGrid *pgrid = hypre_SStructPMatrixPGrid(pmatrix); HYPRE_SStructVariable *vartypes = hypre_SStructPGridVarTypes(pgrid); int ndim = hypre_SStructPGridNDim(pgrid); int num_ghost[6]= {1, 1, 1, 1, 1, 1}; hypre_StructMatrix *smatrix; hypre_StructGrid *sgrid; hypre_Index varoffset; int vi, vj, d; for (vi = 0; vi < nvars; vi++) { /* use variable vi add_numghost */ sgrid= hypre_SStructPGridSGrid(pgrid, vi); hypre_SStructVariableGetOffset(vartypes[vi], ndim, varoffset); for (vj = 0; vj < nvars; vj++) { smatrix = hypre_SStructPMatrixSMatrix(pmatrix, vi, vj); if (smatrix != NULL) { HYPRE_StructMatrixSetSymmetric(smatrix, symmetric[vi][vj]); hypre_StructMatrixSetNumGhost(smatrix, num_ghost); for (d = 0; d < 3; d++) { hypre_StructMatrixAddNumGhost(smatrix)[2*d]= hypre_IndexD(varoffset, d); hypre_StructMatrixAddNumGhost(smatrix)[2*d+1]= hypre_IndexD(varoffset, d); } hypre_StructMatrixInitialize(smatrix); } } } return hypre_error_flag; }
int hypre_SStructGraphFindSGridEndpts(hypre_SStructGraph *graph, int part, int var, int proc, int endpt, int *endpts) { hypre_SStructGrid *grid = hypre_SStructGraphGrid(graph); hypre_StructGrid *sgrid; hypre_BoxArray *boxes; int i; sgrid= hypre_SStructPGridSGrid(hypre_SStructGridPGrid(grid, part), var); boxes= hypre_StructGridBoxes(sgrid); /* get the endpts using hypre_SStructGraphFindBoxEndpt */ for (i= 0; i< hypre_BoxArraySize(boxes); i++) { endpts[i]= hypre_SStructGraphFindBoxEndpt(graph, part, var, proc, endpt, i); } return 0; }
HYPRE_Int hypre_AMR_CFCoarsen( hypre_SStructMatrix * A, hypre_SStructMatrix * fac_A, hypre_Index refine_factors, HYPRE_Int level ) { MPI_Comm comm = hypre_SStructMatrixComm(A); hypre_SStructGraph *graph = hypre_SStructMatrixGraph(A); HYPRE_Int graph_type = hypre_SStructGraphObjectType(graph); hypre_SStructGrid *grid = hypre_SStructGraphGrid(graph); HYPRE_Int nUventries = hypre_SStructGraphNUVEntries(graph); HYPRE_IJMatrix ij_A = hypre_SStructMatrixIJMatrix(A); HYPRE_Int matrix_type= hypre_SStructMatrixObjectType(A); HYPRE_Int ndim = hypre_SStructMatrixNDim(A); hypre_SStructPMatrix *A_pmatrix; hypre_StructMatrix *smatrix_var; hypre_StructStencil *stencils; HYPRE_Int stencil_size; hypre_Index stencil_shape_i; hypre_Index loop_size; hypre_Box refined_box; double **a_ptrs; hypre_Box *A_dbox; HYPRE_Int part_crse= level-1; HYPRE_Int part_fine= level; hypre_BoxManager *fboxman; hypre_BoxManEntry **boxman_entries, *boxman_entry; HYPRE_Int nboxman_entries; hypre_Box boxman_entry_box; hypre_BoxArrayArray ***fgrid_cinterface_extents; hypre_StructGrid *cgrid; hypre_BoxArray *cgrid_boxes; hypre_Box *cgrid_box; hypre_Index node_extents; hypre_Index stridec, stridef; hypre_BoxArrayArray *cinterface_arrays; hypre_BoxArray *cinterface_array; hypre_Box *fgrid_cinterface; HYPRE_Int centre; HYPRE_Int ci, fi, boxi; HYPRE_Int max_stencil_size= 27; HYPRE_Int false= 0; HYPRE_Int true = 1; HYPRE_Int found; HYPRE_Int *stencil_ranks, *rank_stencils; HYPRE_Int rank, startrank; double *vals; HYPRE_Int i, j, iA; HYPRE_Int nvars, var1; hypre_Index lindex, zero_index; hypre_Index index1, index2; hypre_Index index_temp; hypre_SStructUVEntry *Uventry; HYPRE_Int nUentries, cnt1; HYPRE_Int box_array_size; HYPRE_Int *ncols, *rows, *cols; HYPRE_Int *temp1, *temp2; HYPRE_Int myid; hypre_MPI_Comm_rank(comm, &myid); hypre_SetIndex(zero_index, 0, 0, 0); /*-------------------------------------------------------------------------- * Task: Coarsen the CF interface connections of A into fac_A so that * fac_A will have the stencil coefficients extending into a coarsened * fbox. The centre coefficient is constructed to preserve the row sum. *--------------------------------------------------------------------------*/ if (graph_type == HYPRE_SSTRUCT) { startrank = hypre_SStructGridGhstartRank(grid); } if (graph_type == HYPRE_PARCSR) { startrank = hypre_SStructGridStartRank(grid); } /*-------------------------------------------------------------------------- * Fine grid strides by the refinement factors. *--------------------------------------------------------------------------*/ hypre_SetIndex(stridec, 1, 1, 1); for (i= 0; i< ndim; i++) { stridef[i]= refine_factors[i]; } for (i= ndim; i< 3; i++) { stridef[i]= 1; } /*-------------------------------------------------------------------------- * Determine the c/f interface index boxes: fgrid_cinterface_extents. * These are between fpart= level and cpart= (level-1). The * fgrid_cinterface_extents are indexed by cboxes, but fboxes that * abutt a given cbox must be considered. Moreover, for each fbox, * we can have a c/f interface from a number of different stencil * directions- i.e., we have a boxarrayarray for each cbox, each * fbox leading to a boxarray. * * Algo.: For each cbox: * 1) refine & stretch by a unit in each dimension. * 2) boxman_intersect with the fgrid boxman to get all fboxes contained * or abutting this cbox. * 3) get the fgrid_cinterface_extents for each of these fboxes. * * fgrid_cinterface_extents[var1][ci] *--------------------------------------------------------------------------*/ A_pmatrix= hypre_SStructMatrixPMatrix(fac_A, part_crse); nvars = hypre_SStructPMatrixNVars(A_pmatrix); fgrid_cinterface_extents= hypre_TAlloc(hypre_BoxArrayArray **, nvars); for (var1= 0; var1< nvars; var1++) { fboxman= hypre_SStructGridBoxManager(grid, part_fine, var1); stencils= hypre_SStructPMatrixSStencil(A_pmatrix, var1, var1); cgrid= hypre_SStructPGridSGrid(hypre_SStructPMatrixPGrid(A_pmatrix), var1); cgrid_boxes= hypre_StructGridBoxes(cgrid); fgrid_cinterface_extents[var1]= hypre_TAlloc(hypre_BoxArrayArray *, hypre_BoxArraySize(cgrid_boxes)); hypre_ForBoxI(ci, cgrid_boxes) { cgrid_box= hypre_BoxArrayBox(cgrid_boxes, ci); hypre_StructMapCoarseToFine(hypre_BoxIMin(cgrid_box), zero_index, refine_factors, hypre_BoxIMin(&refined_box)); hypre_SetIndex(index1, refine_factors[0]-1, refine_factors[1]-1, refine_factors[2]-1); hypre_StructMapCoarseToFine(hypre_BoxIMax(cgrid_box), index1, refine_factors, hypre_BoxIMax(&refined_box)); /*------------------------------------------------------------------------ * Stretch the refined_box so that a BoxManIntersect will get abutting * fboxes. *------------------------------------------------------------------------*/ for (i= 0; i< ndim; i++) { hypre_BoxIMin(&refined_box)[i]-= 1; hypre_BoxIMax(&refined_box)[i]+= 1; } hypre_BoxManIntersect(fboxman, hypre_BoxIMin(&refined_box), hypre_BoxIMax(&refined_box), &boxman_entries, &nboxman_entries); fgrid_cinterface_extents[var1][ci]= hypre_BoxArrayArrayCreate(nboxman_entries); /*------------------------------------------------------------------------ * Get the fgrid_cinterface_extents using var1-var1 stencil (only like- * variables couple). *------------------------------------------------------------------------*/ if (stencils != NULL) { for (i= 0; i< nboxman_entries; i++) { hypre_BoxManEntryGetExtents(boxman_entries[i], hypre_BoxIMin(&boxman_entry_box), hypre_BoxIMax(&boxman_entry_box)); hypre_CFInterfaceExtents2(&boxman_entry_box, cgrid_box, stencils, refine_factors, hypre_BoxArrayArrayBoxArray(fgrid_cinterface_extents[var1][ci], i) ); } } hypre_TFree(boxman_entries); } /* hypre_ForBoxI(ci, cgrid_boxes) */ } /* for (var1= 0; var1< nvars; var1++) */
HYPRE_Int hypre_FacSemiRestrictSetup2( void *fac_restrict_vdata, hypre_SStructVector *r, HYPRE_Int part_crse, HYPRE_Int part_fine, hypre_SStructPVector *rc, hypre_Index rfactors ) { HYPRE_Int ierr = 0; hypre_FacSemiRestrictData2 *fac_restrict_data = fac_restrict_vdata; MPI_Comm comm= hypre_SStructPVectorComm(rc); hypre_CommInfo *comm_info; hypre_CommPkg **interlevel_comm; hypre_SStructPVector *rf= hypre_SStructVectorPVector(r, part_fine); hypre_StructVector *s_rc, *s_cvector; hypre_SStructPGrid *pgrid; hypre_SStructPVector *fgrid_cvectors; hypre_SStructPGrid *fgrid_coarsen; hypre_BoxArrayArray **identity_arrayboxes; hypre_BoxArrayArray **fullwgt_ownboxes; hypre_BoxArrayArray **fullwgt_sendboxes; hypre_BoxArray *boxarray; hypre_BoxArray *tmp_boxarray, *intersect_boxes; HYPRE_Int ***own_cboxnums; hypre_BoxArrayArray **send_boxes, *send_rboxes; HYPRE_Int ***send_processes; HYPRE_Int ***send_remote_boxnums; hypre_BoxArrayArray **recv_boxes, *recv_rboxes; HYPRE_Int ***recv_processes; HYPRE_Int ***recv_remote_boxnums; hypre_BoxManager *boxman; hypre_BoxManEntry **boxman_entries; HYPRE_Int nboxman_entries; hypre_Box box, scaled_box; hypre_Index zero_index, index, ilower, iupper; HYPRE_Int ndim= hypre_SStructVectorNDim(r); HYPRE_Int myproc, proc; HYPRE_Int nvars, vars; HYPRE_Int num_values; HYPRE_Int i, cnt1, cnt2; HYPRE_Int fi, ci; hypre_MPI_Comm_rank(comm, &myproc); hypre_ClearIndex(zero_index); nvars= hypre_SStructPVectorNVars(rc); (fac_restrict_data -> nvars)= nvars; hypre_CopyIndex(rfactors, (fac_restrict_data -> stride)); for (i= ndim; i< 3; i++) { rfactors[i]= 1; } /* work vector for storing the fullweighted fgrid boxes */ hypre_SStructPGridCreate(hypre_SStructPVectorComm(rf), ndim, &fgrid_coarsen); pgrid= hypre_SStructPVectorPGrid(rf); for (vars= 0; vars< nvars; vars++) { boxarray= hypre_StructGridBoxes(hypre_SStructPGridSGrid(pgrid, vars)); hypre_ForBoxI(fi, boxarray) { hypre_CopyBox(hypre_BoxArrayBox(boxarray, fi), &box); hypre_StructMapFineToCoarse(hypre_BoxIMin(&box), zero_index, rfactors, hypre_BoxIMin(&box)); hypre_StructMapFineToCoarse(hypre_BoxIMax(&box), zero_index, rfactors, hypre_BoxIMax(&box)); hypre_SStructPGridSetExtents(fgrid_coarsen, hypre_BoxIMin(&box), hypre_BoxIMax(&box)); } }
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; }
int hypre_SStructPMatrixCreate( MPI_Comm comm, hypre_SStructPGrid *pgrid, hypre_SStructStencil **stencils, hypre_SStructPMatrix **pmatrix_ptr ) { hypre_SStructPMatrix *pmatrix; int nvars; int **smaps; hypre_StructStencil ***sstencils; hypre_StructMatrix ***smatrices; int **symmetric; hypre_StructStencil *sstencil; int *vars; hypre_Index *sstencil_shape; int sstencil_size; int new_dim; int *new_sizes; hypre_Index **new_shapes; int size; hypre_StructGrid *sgrid; int vi, vj; int i, j, k; pmatrix = hypre_TAlloc(hypre_SStructPMatrix, 1); hypre_SStructPMatrixComm(pmatrix) = comm; hypre_SStructPMatrixPGrid(pmatrix) = pgrid; hypre_SStructPMatrixStencils(pmatrix) = stencils; nvars = hypre_SStructPGridNVars(pgrid); hypre_SStructPMatrixNVars(pmatrix) = nvars; /* create sstencils */ smaps = hypre_TAlloc(int *, nvars); sstencils = hypre_TAlloc(hypre_StructStencil **, nvars); new_sizes = hypre_TAlloc(int, nvars); new_shapes = hypre_TAlloc(hypre_Index *, nvars); size = 0; for (vi = 0; vi < nvars; vi++) { sstencils[vi] = hypre_TAlloc(hypre_StructStencil *, nvars); for (vj = 0; vj < nvars; vj++) { sstencils[vi][vj] = NULL; new_sizes[vj] = 0; } sstencil = hypre_SStructStencilSStencil(stencils[vi]); vars = hypre_SStructStencilVars(stencils[vi]); sstencil_shape = hypre_StructStencilShape(sstencil); sstencil_size = hypre_StructStencilSize(sstencil); smaps[vi] = hypre_TAlloc(int, sstencil_size); for (i = 0; i < sstencil_size; i++) { j = vars[i]; new_sizes[j]++; } for (vj = 0; vj < nvars; vj++) { if (new_sizes[vj]) { new_shapes[vj] = hypre_TAlloc(hypre_Index, new_sizes[vj]); new_sizes[vj] = 0; } } for (i = 0; i < sstencil_size; i++) { j = vars[i]; k = new_sizes[j]; hypre_CopyIndex(sstencil_shape[i], new_shapes[j][k]); smaps[vi][i] = k; new_sizes[j]++; } new_dim = hypre_StructStencilDim(sstencil); for (vj = 0; vj < nvars; vj++) { if (new_sizes[vj]) { sstencils[vi][vj] = hypre_StructStencilCreate(new_dim, new_sizes[vj], new_shapes[vj]); } size = hypre_max(size, new_sizes[vj]); } } hypre_SStructPMatrixSMaps(pmatrix) = smaps; hypre_SStructPMatrixSStencils(pmatrix) = sstencils; hypre_TFree(new_sizes); hypre_TFree(new_shapes); /* create smatrices */ smatrices = hypre_TAlloc(hypre_StructMatrix **, nvars); for (vi = 0; vi < nvars; vi++) { smatrices[vi] = hypre_TAlloc(hypre_StructMatrix *, nvars); for (vj = 0; vj < nvars; vj++) { smatrices[vi][vj] = NULL; if (sstencils[vi][vj] != NULL) { sgrid = hypre_SStructPGridSGrid(pgrid, vi); smatrices[vi][vj] = hypre_StructMatrixCreate(comm, sgrid, sstencils[vi][vj]); } } } hypre_SStructPMatrixSMatrices(pmatrix) = smatrices; /* create symmetric */ symmetric = hypre_TAlloc(int *, nvars); for (vi = 0; vi < nvars; vi++) { symmetric[vi] = hypre_TAlloc(int, nvars); for (vj = 0; vj < nvars; vj++) { symmetric[vi][vj] = 0; } } hypre_SStructPMatrixSymmetric(pmatrix) = symmetric; hypre_SStructPMatrixSEntriesSize(pmatrix) = size; hypre_SStructPMatrixSEntries(pmatrix) = hypre_TAlloc(int, size); hypre_SStructPMatrixRefCount(pmatrix) = 1; *pmatrix_ptr = pmatrix; return hypre_error_flag; }
/*-------------------------------------------------------------------------- * hypre_FacZeroCFSten: Zeroes the coarse stencil coefficients that reach * into an underlying coarsened refinement box. * Algo: For each cbox * { * 1) refine cbox and expand by one in each direction * 2) boxman_intersect with the fboxman * 3) loop over intersection boxes to see if stencil * reaches over. * } *--------------------------------------------------------------------------*/ HYPRE_Int hypre_FacZeroCFSten( hypre_SStructPMatrix *Af, hypre_SStructPMatrix *Ac, hypre_SStructGrid *grid, HYPRE_Int fine_part, hypre_Index rfactors ) { hypre_BoxManager *fboxman; hypre_BoxManEntry **boxman_entries; HYPRE_Int nboxman_entries; hypre_SStructPGrid *p_cgrid; hypre_Box fgrid_box; hypre_StructGrid *cgrid; hypre_BoxArray *cgrid_boxes; hypre_Box *cgrid_box; hypre_Box scaled_box; hypre_Box *shift_ibox; hypre_StructMatrix *smatrix; hypre_StructStencil *stencils; HYPRE_Int stencil_size; hypre_Index refine_factors, upper_shift; hypre_Index stride; hypre_Index stencil_shape; hypre_Index zero_index, ilower, iupper; HYPRE_Int nvars, var1, var2; HYPRE_Int ndim; hypre_Box *ac_dbox; HYPRE_Real *ac_ptr; hypre_Index loop_size; HYPRE_Int iac; HYPRE_Int ci, i, j; HYPRE_Int abs_shape; HYPRE_Int ierr = 0; p_cgrid = hypre_SStructPMatrixPGrid(Ac); nvars = hypre_SStructPMatrixNVars(Ac); ndim = hypre_SStructPGridNDim(p_cgrid); hypre_BoxInit(&fgrid_box, ndim); hypre_BoxInit(&scaled_box, ndim); hypre_ClearIndex(zero_index); hypre_ClearIndex(stride); hypre_ClearIndex(upper_shift); for (i= 0; i< ndim; i++) { stride[i]= 1; upper_shift[i]= rfactors[i]-1; } hypre_CopyIndex(rfactors, refine_factors); if (ndim < 3) { for (i= ndim; i< 3; i++) { refine_factors[i]= 1; } } for (var1= 0; var1< nvars; var1++) { cgrid= hypre_SStructPGridSGrid(hypre_SStructPMatrixPGrid(Ac), var1); cgrid_boxes= hypre_StructGridBoxes(cgrid); fboxman= hypre_SStructGridBoxManager(grid, fine_part, var1); /*------------------------------------------------------------------ * For each parent coarse box find all fboxes that may be connected * through a stencil entry- refine this box, expand it by one * in each direction, and boxman_intersect with fboxman *------------------------------------------------------------------*/ hypre_ForBoxI(ci, cgrid_boxes) { cgrid_box= hypre_BoxArrayBox(cgrid_boxes, ci); hypre_StructMapCoarseToFine(hypre_BoxIMin(cgrid_box), zero_index, refine_factors, hypre_BoxIMin(&scaled_box)); hypre_StructMapCoarseToFine(hypre_BoxIMax(cgrid_box), upper_shift, refine_factors, hypre_BoxIMax(&scaled_box)); hypre_SubtractIndexes(hypre_BoxIMin(&scaled_box), stride, 3, hypre_BoxIMin(&scaled_box)); hypre_AddIndexes(hypre_BoxIMax(&scaled_box), stride, 3, hypre_BoxIMax(&scaled_box)); hypre_BoxManIntersect(fboxman, hypre_BoxIMin(&scaled_box), hypre_BoxIMax(&scaled_box), &boxman_entries, &nboxman_entries); for (var2= 0; var2< nvars; var2++) { stencils= hypre_SStructPMatrixSStencil(Ac, var1, var2); if (stencils != NULL) { stencil_size= hypre_StructStencilSize(stencils); smatrix = hypre_SStructPMatrixSMatrix(Ac, var1, var2); ac_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(smatrix), ci); /*--------------------------------------------------------- * Find the stencil coefficients that must be zeroed off. * Loop over all possible boxes. *---------------------------------------------------------*/ for (i= 0; i< stencil_size; i++) { hypre_CopyIndex(hypre_StructStencilElement(stencils, i), stencil_shape); AbsStencilShape(stencil_shape, abs_shape); if (abs_shape) /* non-centre stencils are zeroed */ { /* look for connecting fboxes that must be zeroed. */ for (j= 0; j< nboxman_entries; j++) { hypre_BoxManEntryGetExtents(boxman_entries[j], ilower, iupper); hypre_BoxSetExtents(&fgrid_box, ilower, iupper); shift_ibox= hypre_CF_StenBox(&fgrid_box, cgrid_box, stencil_shape, refine_factors, ndim); if ( hypre_BoxVolume(shift_ibox) ) { ac_ptr= hypre_StructMatrixExtractPointerByIndex(smatrix, ci, stencil_shape); hypre_BoxGetSize(shift_ibox, loop_size); hypre_BoxLoop1Begin(ndim, loop_size, ac_dbox, hypre_BoxIMin(shift_ibox), stride, iac); #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(HYPRE_BOX_PRIVATE,iac) HYPRE_SMP_SCHEDULE #endif hypre_BoxLoop1For(iac) { ac_ptr[iac] = 0.0; } hypre_BoxLoop1End(iac); } /* if ( hypre_BoxVolume(shift_ibox) ) */ hypre_BoxDestroy(shift_ibox); } /* for (j= 0; j< nboxman_entries; j++) */ } /* if (abs_shape) */ } /* for (i= 0; i< stencil_size; i++) */ } /* if (stencils != NULL) */ } /* for (var2= 0; var2< nvars; var2++) */ hypre_TFree(boxman_entries); } /* hypre_ForBoxI ci */
HYPRE_Int hypre_FacZeroCData( void *fac_vdata, hypre_SStructMatrix *A ) { hypre_FACData *fac_data = fac_vdata; hypre_SStructGrid *grid; hypre_SStructPGrid *p_cgrid; hypre_StructGrid *cgrid; hypre_BoxArray *cgrid_boxes; hypre_Box *cgrid_box; hypre_BoxManager *fboxman; hypre_BoxManEntry **boxman_entries; HYPRE_Int nboxman_entries; hypre_Box scaled_box; hypre_Box intersect_box; hypre_SStructPMatrix *level_pmatrix; hypre_StructStencil *stencils; HYPRE_Int stencil_size; hypre_Index *refine_factors; hypre_Index temp_index; hypre_Index ilower, iupper; HYPRE_Int max_level = fac_data -> max_levels; HYPRE_Int *level_to_part = fac_data -> level_to_part; HYPRE_Int ndim = hypre_SStructMatrixNDim(A); HYPRE_Int part_crse = 0; HYPRE_Int part_fine = 1; HYPRE_Int level; HYPRE_Int nvars, var; HYPRE_Int ci, i, j, rem, intersect_size; double *values; HYPRE_Int ierr = 0; for (level= max_level; level> 0; level--) { level_pmatrix = hypre_SStructMatrixPMatrix(fac_data -> A_level[level], part_crse); grid = (fac_data -> grid_level[level]); refine_factors= &(fac_data -> refine_factors[level]); p_cgrid= hypre_SStructGridPGrid(grid, part_crse); nvars = hypre_SStructPGridNVars(p_cgrid); for (var= 0; var< nvars; var++) { stencils = hypre_SStructPMatrixSStencil(level_pmatrix, var, var); stencil_size= hypre_StructStencilSize(stencils); /*--------------------------------------------------------------------- * For each variable, find the underlying boxes for each coarse box. *---------------------------------------------------------------------*/ cgrid = hypre_SStructPGridSGrid(p_cgrid, var); cgrid_boxes = hypre_StructGridBoxes(cgrid); fboxman = hypre_SStructGridBoxManager(grid, part_fine, var); hypre_ForBoxI(ci, cgrid_boxes) { cgrid_box= hypre_BoxArrayBox(cgrid_boxes, ci); hypre_ClearIndex(temp_index); hypre_StructMapCoarseToFine(hypre_BoxIMin(cgrid_box), temp_index, *refine_factors, hypre_BoxIMin(&scaled_box)); for (i= 0; i< ndim; i++) { temp_index[i]= (*refine_factors)[i]-1; } hypre_StructMapCoarseToFine(hypre_BoxIMax(cgrid_box), temp_index, *refine_factors, hypre_BoxIMax(&scaled_box)); hypre_BoxManIntersect(fboxman, hypre_BoxIMin(&scaled_box), hypre_BoxIMax(&scaled_box), &boxman_entries, &nboxman_entries); for (i= 0; i< nboxman_entries; i++) { hypre_BoxManEntryGetExtents(boxman_entries[i], ilower, iupper); hypre_BoxSetExtents(&intersect_box, ilower, iupper); hypre_IntersectBoxes(&intersect_box, &scaled_box, &intersect_box); /* adjust the box so that it is divisible by refine_factors */ for (j= 0; j< ndim; j++) { rem= hypre_BoxIMin(&intersect_box)[j]%(*refine_factors)[j]; if (rem) { hypre_BoxIMin(&intersect_box)[j]+=(*refine_factors)[j] - rem; } } hypre_ClearIndex(temp_index); hypre_StructMapFineToCoarse(hypre_BoxIMin(&intersect_box), temp_index, *refine_factors, hypre_BoxIMin(&intersect_box)); hypre_StructMapFineToCoarse(hypre_BoxIMax(&intersect_box), temp_index, *refine_factors, hypre_BoxIMax(&intersect_box)); intersect_size= hypre_BoxVolume(&intersect_box); if (intersect_size > 0) { /*------------------------------------------------------------ * Coarse underlying box found. Now zero off. *------------------------------------------------------------*/ values= hypre_CTAlloc(double, intersect_size); for (j= 0; j< stencil_size; j++) { HYPRE_SStructMatrixSetBoxValues(fac_data -> A_level[level], part_crse, hypre_BoxIMin(&intersect_box), hypre_BoxIMax(&intersect_box), var, 1, &j, values); HYPRE_SStructMatrixSetBoxValues(A, level_to_part[level-1], hypre_BoxIMin(&intersect_box), hypre_BoxIMax(&intersect_box), var, 1, &j, values); } hypre_TFree(values); } /* if (intersect_size > 0) */ } /* for (i= 0; i< nboxman_entries; i++) */ hypre_TFree(boxman_entries); } /* hypre_ForBoxI(ci, cgrid_boxes) */ } /* for (var= 0; var< nvars; var++) */
HYPRE_SStructGridAssemble(node_grid); HYPRE_SStructGridAssemble(edge_grid); /* CREATE IJ_MATRICES- need to find the size of each one. Notice that the row and col ranks of these matrices can be created using only grid information. Grab the first part, first variable, first box, and lower index (lower rank); Grab the last part, last variable, last box, and upper index (upper rank). */ /* Grad: node(col) -> edge(row). Same for 2-d and 3-d */ /* lower rank */ part= 0; i = 0; hypre_SStructGridBoxProcFindBoxManEntry(edge_grid, part, 0, i, myproc, &entry); pgrid = hypre_SStructGridPGrid(edge_grid, part); var_grid= hypre_SStructPGridSGrid(pgrid, 0); boxes = hypre_StructGridBoxes(var_grid); box = hypre_BoxArrayBox(boxes, 0); hypre_SStructBoxManEntryGetGlobalCSRank(entry, hypre_BoxIMin(box), &ilower); hypre_SStructGridBoxProcFindBoxManEntry(node_grid, part, 0, i, myproc, &entry); pgrid = hypre_SStructGridPGrid(node_grid, part); var_grid= hypre_SStructPGridSGrid(pgrid, 0); boxes = hypre_StructGridBoxes(var_grid); box = hypre_BoxArrayBox(boxes, 0); hypre_SStructBoxManEntryGetGlobalCSRank(entry, hypre_BoxIMin(box), &jlower); /* upper rank */ part= nparts-1; pgrid = hypre_SStructGridPGrid(edge_grid, part);
HYPRE_Int hypre_Maxwell_PhysBdy( hypre_SStructGrid **grid_l, HYPRE_Int num_levels, hypre_Index rfactors, HYPRE_Int ***BdryRanksl_ptr, HYPRE_Int **BdryRanksCntsl_ptr ) { MPI_Comm comm= (grid_l[0]-> comm); HYPRE_Int **BdryRanks_l; HYPRE_Int *BdryRanksCnts_l; HYPRE_Int *npts; HYPRE_Int *ranks, *upper_rank, *lower_rank; hypre_BoxManEntry *boxman_entry; hypre_SStructGrid *grid; hypre_SStructPGrid *pgrid; hypre_StructGrid *cell_fgrid, *cell_cgrid, *sgrid; hypre_BoxArrayArray ****bdry; hypre_BoxArrayArray *fbdry; hypre_BoxArrayArray *cbdry; hypre_BoxArray *box_array; hypre_BoxArray *fboxes, *cboxes; hypre_Box *fbox, *cbox; hypre_Box *box, *contract_fbox, rbox; hypre_Box intersect; HYPRE_Int **cbox_mapping, **fbox_mapping; HYPRE_Int **boxes_with_bdry; HYPRE_Int ndim, nvars; HYPRE_Int nboxes, nfboxes; HYPRE_Int boxi; hypre_Index zero_shift, upper_shift, lower_shift; hypre_Index loop_size, start, index, lindex; HYPRE_Int i, j, k, l, m, n, p; HYPRE_Int d; HYPRE_Int cnt; HYPRE_Int part= 0; /* NOTE, ASSUMING ONE PART */ HYPRE_Int matrix_type= HYPRE_PARCSR; HYPRE_Int myproc; HYPRE_Int ierr= 0; hypre_MPI_Comm_rank(comm, &myproc); ndim= hypre_SStructGridNDim(grid_l[0]); hypre_SetIndex3(zero_shift, 0, 0, 0); hypre_BoxInit(&intersect, ndim); /* bounding global ranks of this processor & allocate boundary box markers. */ upper_rank= hypre_CTAlloc(HYPRE_Int, num_levels); lower_rank= hypre_CTAlloc(HYPRE_Int, num_levels); boxes_with_bdry= hypre_TAlloc(HYPRE_Int *, num_levels); for (i= 0; i< num_levels; i++) { grid = grid_l[i]; lower_rank[i]= hypre_SStructGridStartRank(grid); /* note we are assuming only one part */ pgrid= hypre_SStructGridPGrid(grid, part); nvars= hypre_SStructPGridNVars(pgrid); sgrid= hypre_SStructPGridSGrid(pgrid, nvars-1); box_array= hypre_StructGridBoxes(sgrid); box = hypre_BoxArrayBox(box_array, hypre_BoxArraySize(box_array)-1); hypre_SStructGridBoxProcFindBoxManEntry(grid, part, nvars-1, hypre_BoxArraySize(box_array)-1, myproc, &boxman_entry); hypre_SStructBoxManEntryGetGlobalCSRank(boxman_entry, hypre_BoxIMax(box), &upper_rank[i]); sgrid= hypre_SStructPGridCellSGrid(pgrid); box_array= hypre_StructGridBoxes(sgrid); boxes_with_bdry[i]= hypre_CTAlloc(HYPRE_Int, hypre_BoxArraySize(box_array)); } /*----------------------------------------------------------------------------- * construct box_number mapping between levels, and offset strides because of * projection coarsening. Note: from the way the coarse boxes are created and * numbered, to determine the coarse box that matches the fbox, we need to * only check the tail end of the list of cboxes. In fact, given fbox_i, * if it's coarsened extents do not interesect with the first coarse box of the * tail end, then this fbox vanishes in the coarsening. * c/fbox_mapping gives the fine/coarse box mapping between two consecutive levels * of the multilevel hierarchy. *-----------------------------------------------------------------------------*/ if (num_levels > 1) { cbox_mapping= hypre_CTAlloc(HYPRE_Int *, num_levels); fbox_mapping= hypre_CTAlloc(HYPRE_Int *, num_levels); }