/*-------------------------------------------------------------------------- * 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; }
/*-------------------------------------------------------------------------- * hypre_Maxwell_Grad.c * Forms a node-to-edge gradient operator. Looping over the * edge grid so that each processor fills up only its own rows. Each * processor will have its processor interface nodal ranks. * Loops over two types of boxes, interior of grid boxes and boundary * of boxes. Algo: * find all nodal and edge physical boundary points and set * the appropriate flag to be 0 at a boundary dof. * set -1's in value array * for each edge box, * for interior * { * connect edge ijk (row) to nodes (col) connected to this edge * and change -1 to 1 if needed; * } * for boundary layers * { * if edge not on the physical boundary connect only the nodes * that are not on the physical boundary * } * set parcsr matrix with values; * * Note that the nodes that are on the processor interface can be * on the physical boundary. But the off-proc edges connected to this * type of node will be a physical boundary edge. * *--------------------------------------------------------------------------*/ hypre_ParCSRMatrix * hypre_Maxwell_Grad(hypre_SStructGrid *grid) { MPI_Comm comm = (grid -> comm); HYPRE_IJMatrix T_grad; hypre_ParCSRMatrix *parcsr_grad; HYPRE_Int matrix_type= HYPRE_PARCSR; hypre_SStructGrid *node_grid, *edge_grid; hypre_SStructPGrid *pgrid; hypre_StructGrid *var_grid; hypre_BoxArray *boxes, *tmp_box_array1, *tmp_box_array2; hypre_BoxArray *node_boxes, *edge_boxes, *cell_boxes; hypre_Box *box, *cell_box; hypre_Box layer, interior_box; hypre_Box *box_piece; hypre_BoxManager *boxman; hypre_BoxManEntry *entry; HYPRE_Int *inode, *jedge; HYPRE_Int nrows, nnodes, *nflag, *eflag, *ncols; HYPRE_Real *vals; hypre_Index index; hypre_Index loop_size, start, lindex; hypre_Index shift, shift2; hypre_Index *offsets, *varoffsets; HYPRE_Int nparts= hypre_SStructGridNParts(grid); HYPRE_Int ndim = hypre_SStructGridNDim(grid); HYPRE_SStructVariable vartype_node, *vartype_edges; HYPRE_SStructVariable *vartypes; HYPRE_Int nvars, part; HYPRE_Int i, j, k, m, n, d; HYPRE_Int *direction, ndirection; HYPRE_Int ilower, iupper; HYPRE_Int jlower, jupper; HYPRE_Int start_rank1, start_rank2, rank; HYPRE_Int myproc; HYPRE_Int ierr=0; hypre_BoxInit(&layer, ndim); hypre_BoxInit(&interior_box, ndim); hypre_MPI_Comm_rank(comm, &myproc); hypre_ClearIndex(shift); for (i= 0; i< ndim; i++) { hypre_IndexD(shift, i)= -1; } /* To get the correct ranks, separate node & edge grids must be formed. Note that the edge vars must be ordered the same way as is in grid.*/ HYPRE_SStructGridCreate(comm, ndim, nparts, &node_grid); HYPRE_SStructGridCreate(comm, ndim, nparts, &edge_grid); vartype_node = HYPRE_SSTRUCT_VARIABLE_NODE; vartype_edges= hypre_TAlloc(HYPRE_SStructVariable, ndim); /* Assuming the same edge variable types on all parts */ pgrid = hypre_SStructGridPGrid(grid, 0); vartypes= hypre_SStructPGridVarTypes(pgrid); nvars = hypre_SStructPGridNVars(pgrid); k= 0; for (i= 0; i< nvars; i++) { j= vartypes[i]; switch(j) { case 2: { vartype_edges[k]= HYPRE_SSTRUCT_VARIABLE_XFACE; k++; break; } case 3: { vartype_edges[k]= HYPRE_SSTRUCT_VARIABLE_YFACE; k++; break; } case 5: { vartype_edges[k]= HYPRE_SSTRUCT_VARIABLE_XEDGE; k++; break; } case 6: { vartype_edges[k]= HYPRE_SSTRUCT_VARIABLE_YEDGE; k++; break; } case 7: { vartype_edges[k]= HYPRE_SSTRUCT_VARIABLE_ZEDGE; k++; break; } } /* switch(j) */ } /* for (i= 0; i< nvars; i++) */ for (part= 0; part< nparts; part++) { pgrid= hypre_SStructGridPGrid(grid, part); var_grid= hypre_SStructPGridCellSGrid(pgrid) ; boxes= hypre_StructGridBoxes(var_grid); hypre_ForBoxI(j, boxes) { box= hypre_BoxArrayBox(boxes, j); HYPRE_SStructGridSetExtents(node_grid, part, hypre_BoxIMin(box), hypre_BoxIMax(box)); HYPRE_SStructGridSetExtents(edge_grid, part, hypre_BoxIMin(box), hypre_BoxIMax(box)); } HYPRE_SStructGridSetVariables(node_grid, part, 1, &vartype_node); HYPRE_SStructGridSetVariables(edge_grid, part, ndim, vartype_edges); }