hypre_StructMatrix * hypre_SMGCreateRAPOp( hypre_StructMatrix *R, hypre_StructMatrix *A, hypre_StructMatrix *PT, hypre_StructGrid *coarse_grid ) { hypre_StructMatrix *RAP; hypre_StructStencil *stencil; #if NEWRAP HYPRE_Int cdir; HYPRE_Int P_stored_as_transpose = 1; #endif stencil = hypre_StructMatrixStencil(A); #if OLDRAP switch (hypre_StructStencilDim(stencil)) { case 2: RAP = hypre_SMG2CreateRAPOp(R ,A, PT, coarse_grid); break; case 3: RAP = hypre_SMG3CreateRAPOp(R ,A, PT, coarse_grid); break; } #endif #if NEWRAP switch (hypre_StructStencilDim(stencil)) { case 2: cdir = 1; RAP = hypre_SemiCreateRAPOp(R ,A, PT, coarse_grid, cdir, P_stored_as_transpose); break; case 3: cdir = 2; RAP = hypre_SemiCreateRAPOp(R ,A, PT, coarse_grid, cdir, P_stored_as_transpose); break; } #endif return RAP; }
hypre_SStructPMatrix * hypre_SysPFMGCreateRAPOp( hypre_SStructPMatrix *R, hypre_SStructPMatrix *A, hypre_SStructPMatrix *P, hypre_SStructPGrid *coarse_grid, HYPRE_Int cdir ) { hypre_SStructPMatrix *RAP; HYPRE_Int ndim; HYPRE_Int nvars; hypre_SStructVariable vartype; hypre_SStructStencil **RAP_stencils; hypre_StructMatrix *RAP_s; hypre_StructMatrix *R_s; hypre_StructMatrix *A_s; hypre_StructMatrix *P_s; hypre_Index **RAP_shapes; hypre_StructStencil *sstencil; hypre_Index *shape; HYPRE_Int s; HYPRE_Int *sstencil_sizes; HYPRE_Int stencil_size; hypre_StructGrid *cgrid; HYPRE_Int vi,vj; HYPRE_Int sten_cntr; HYPRE_Int P_stored_as_transpose = 0; ndim = hypre_StructStencilDim(hypre_SStructPMatrixSStencil(A, 0, 0)); nvars = hypre_SStructPMatrixNVars(A); vartype = hypre_SStructPGridVarType(coarse_grid, 0); cgrid = hypre_SStructPGridVTSGrid(coarse_grid, vartype); RAP_stencils = hypre_CTAlloc(hypre_SStructStencil *, nvars); RAP_shapes = hypre_CTAlloc(hypre_Index *, nvars); sstencil_sizes = hypre_CTAlloc(HYPRE_Int, nvars); /*-------------------------------------------------------------------------- * Symmetry within a block is exploited, but not symmetry of the form * A_{vi,vj} = A_{vj,vi}^T. *--------------------------------------------------------------------------*/ for (vi = 0; vi < nvars; vi++) { R_s = hypre_SStructPMatrixSMatrix(R, vi, vi); stencil_size = 0; for (vj = 0; vj < nvars; vj++) { A_s = hypre_SStructPMatrixSMatrix(A, vi, vj); P_s = hypre_SStructPMatrixSMatrix(P, vj, vj); sstencil_sizes[vj] = 0; if (A_s != NULL) { RAP_s = hypre_SemiCreateRAPOp(R_s, A_s, P_s, cgrid, cdir, P_stored_as_transpose); /* Just want stencil for RAP */ hypre_StructMatrixInitializeShell(RAP_s); sstencil = hypre_StructMatrixStencil(RAP_s); shape = hypre_StructStencilShape(sstencil); sstencil_sizes[vj] = hypre_StructStencilSize(sstencil); stencil_size += sstencil_sizes[vj]; RAP_shapes[vj] = hypre_CTAlloc(hypre_Index, sstencil_sizes[vj]); for (s = 0; s < sstencil_sizes[vj]; s++) { hypre_CopyIndex(shape[s],RAP_shapes[vj][s]); } hypre_StructMatrixDestroy(RAP_s); } } HYPRE_SStructStencilCreate(ndim, stencil_size, &RAP_stencils[vi]); sten_cntr = 0; for (vj = 0; vj < nvars; vj++) { if (sstencil_sizes[vj] > 0) { for (s = 0; s < sstencil_sizes[vj]; s++) { HYPRE_SStructStencilSetEntry(RAP_stencils[vi], sten_cntr, RAP_shapes[vj][s], vj); sten_cntr++; } hypre_TFree(RAP_shapes[vj]); } } } /* create RAP Pmatrix */ hypre_SStructPMatrixCreate(hypre_SStructPMatrixComm(A), coarse_grid, RAP_stencils, &RAP); hypre_TFree(RAP_shapes); hypre_TFree(sstencil_sizes); return RAP; }
hypre_StructMatrix * hypre_PFMGCreateRAPOp( hypre_StructMatrix *R, hypre_StructMatrix *A, hypre_StructMatrix *P, hypre_StructGrid *coarse_grid, HYPRE_Int cdir, HYPRE_Int rap_type ) { hypre_StructMatrix *RAP=NULL; hypre_StructStencil *stencil; HYPRE_Int P_stored_as_transpose = 0; HYPRE_Int constant_coefficient; stencil = hypre_StructMatrixStencil(A); if (rap_type == 0) { switch (hypre_StructStencilNDim(stencil)) { case 2: RAP = hypre_PFMG2CreateRAPOp(R ,A, P, coarse_grid, cdir); break; case 3: RAP = hypre_PFMG3CreateRAPOp(R ,A, P, coarse_grid, cdir); break; } } else if (rap_type == 1) { switch (hypre_StructStencilNDim(stencil)) { case 2: RAP = hypre_PFMGCreateCoarseOp5(R ,A, P, coarse_grid, cdir); break; case 3: RAP = hypre_PFMGCreateCoarseOp7(R ,A, P, coarse_grid, cdir); break; } } else if (rap_type == 2) { RAP = hypre_SemiCreateRAPOp(R ,A, P, coarse_grid, cdir, P_stored_as_transpose); } constant_coefficient = hypre_StructMatrixConstantCoefficient(A); if ( constant_coefficient==2 && rap_type==0 ) { /* A has variable diagonal, so, in the Galerkin case, P (and R) is entirely variable coefficient. Thus RAP will be variable coefficient */ hypre_StructMatrixSetConstantCoefficient( RAP, 0 ); } else { hypre_StructMatrixSetConstantCoefficient( RAP, constant_coefficient ); } return RAP; }