HYPRE_Int hypre_PFMGRelax( void *pfmg_relax_vdata, hypre_StructMatrix *A, hypre_StructVector *b, hypre_StructVector *x ) { hypre_PFMGRelaxData *pfmg_relax_data = pfmg_relax_vdata; HYPRE_Int relax_type = (pfmg_relax_data -> relax_type); HYPRE_Int constant_coefficient= hypre_StructMatrixConstantCoefficient(A); switch(relax_type) { case 0: case 1: hypre_PointRelax((pfmg_relax_data -> relax_data), A, b, x); break; case 2: case 3: if (constant_coefficient) { hypre_RedBlackConstantCoefGS((pfmg_relax_data -> rb_relax_data), A, b, x); } else { hypre_RedBlackGS((pfmg_relax_data -> rb_relax_data), A, b, x); } break; } return hypre_error_flag; }
HYPRE_Int hypre_SemiInterp( void *interp_vdata, hypre_StructMatrix *P, hypre_StructVector *xc, hypre_StructVector *e ) { hypre_SemiInterpData *interp_data = interp_vdata; HYPRE_Int P_stored_as_transpose; hypre_ComputePkg *compute_pkg; hypre_IndexRef cindex; hypre_IndexRef findex; hypre_IndexRef stride; hypre_StructGrid *fgrid; HYPRE_Int *fgrid_ids; hypre_StructGrid *cgrid; hypre_BoxArray *cgrid_boxes; HYPRE_Int *cgrid_ids; hypre_CommHandle *comm_handle; hypre_BoxArrayArray *compute_box_aa; hypre_BoxArray *compute_box_a; hypre_Box *compute_box; hypre_Box *P_dbox; hypre_Box *xc_dbox; hypre_Box *e_dbox; HYPRE_Int Pi; HYPRE_Int xci; HYPRE_Int ei; HYPRE_Int constant_coefficient; HYPRE_Real *Pp0, *Pp1; HYPRE_Real *xcp; HYPRE_Real *ep, *ep0, *ep1; hypre_Index loop_size; hypre_Index start; hypre_Index startc; hypre_Index stridec; hypre_StructStencil *stencil; hypre_Index *stencil_shape; HYPRE_Int compute_i, fi, ci, j; /*----------------------------------------------------------------------- * Initialize some things *-----------------------------------------------------------------------*/ hypre_BeginTiming(interp_data -> time_index); P_stored_as_transpose = (interp_data -> P_stored_as_transpose); compute_pkg = (interp_data -> compute_pkg); cindex = (interp_data -> cindex); findex = (interp_data -> findex); stride = (interp_data -> stride); stencil = hypre_StructMatrixStencil(P); stencil_shape = hypre_StructStencilShape(stencil); constant_coefficient = hypre_StructMatrixConstantCoefficient(P); hypre_assert( constant_coefficient==0 || constant_coefficient==1 ); /* ... constant_coefficient==2 for P shouldn't happen, see hypre_PFMGCreateInterpOp in pfmg_setup_interp.c */ if (constant_coefficient) hypre_StructVectorClearBoundGhostValues(e, 0); hypre_SetIndex3(stridec, 1, 1, 1); /*----------------------------------------------------------------------- * Compute e at coarse points (injection) *-----------------------------------------------------------------------*/ fgrid = hypre_StructVectorGrid(e); fgrid_ids = hypre_StructGridIDs(fgrid); cgrid = hypre_StructVectorGrid(xc); cgrid_boxes = hypre_StructGridBoxes(cgrid); cgrid_ids = hypre_StructGridIDs(cgrid); fi = 0; hypre_ForBoxI(ci, cgrid_boxes) { while (fgrid_ids[fi] != cgrid_ids[ci]) { fi++; } compute_box = hypre_BoxArrayBox(cgrid_boxes, ci); hypre_CopyIndex(hypre_BoxIMin(compute_box), startc); hypre_StructMapCoarseToFine(startc, cindex, stride, start); e_dbox = hypre_BoxArrayBox(hypre_StructVectorDataSpace(e), fi); xc_dbox = hypre_BoxArrayBox(hypre_StructVectorDataSpace(xc), ci); ep = hypre_StructVectorBoxData(e, fi); xcp = hypre_StructVectorBoxData(xc, ci); hypre_BoxGetSize(compute_box, loop_size); hypre_BoxLoop2Begin(hypre_StructMatrixNDim(P), loop_size, e_dbox, start, stride, ei, xc_dbox, startc, stridec, xci); #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(HYPRE_BOX_PRIVATE,ei,xci) HYPRE_SMP_SCHEDULE #endif hypre_BoxLoop2For(ei, xci) { ep[ei] = xcp[xci]; } hypre_BoxLoop2End(ei, xci); } /*----------------------------------------------------------------------- * Compute e at fine points *-----------------------------------------------------------------------*/ for (compute_i = 0; compute_i < 2; compute_i++) { switch(compute_i) { case 0: { ep = hypre_StructVectorData(e); hypre_InitializeIndtComputations(compute_pkg, ep, &comm_handle); compute_box_aa = hypre_ComputePkgIndtBoxes(compute_pkg); } break; case 1: { hypre_FinalizeIndtComputations(comm_handle); compute_box_aa = hypre_ComputePkgDeptBoxes(compute_pkg); } break; } hypre_ForBoxArrayI(fi, compute_box_aa) { compute_box_a = hypre_BoxArrayArrayBoxArray(compute_box_aa, fi); P_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(P), fi); e_dbox = hypre_BoxArrayBox(hypre_StructVectorDataSpace(e), fi); if (P_stored_as_transpose) { if ( constant_coefficient ) { Pp0 = hypre_StructMatrixBoxData(P, fi, 1); Pp1 = hypre_StructMatrixBoxData(P, fi, 0) - hypre_CCBoxOffsetDistance(P_dbox, stencil_shape[0]); } else { Pp0 = hypre_StructMatrixBoxData(P, fi, 1); Pp1 = hypre_StructMatrixBoxData(P, fi, 0) - hypre_BoxOffsetDistance(P_dbox, stencil_shape[0]); } } else { Pp0 = hypre_StructMatrixBoxData(P, fi, 0); Pp1 = hypre_StructMatrixBoxData(P, fi, 1); } ep = hypre_StructVectorBoxData(e, fi); ep0 = ep + hypre_BoxOffsetDistance(e_dbox, stencil_shape[0]); ep1 = ep + hypre_BoxOffsetDistance(e_dbox, stencil_shape[1]); hypre_ForBoxI(j, compute_box_a) { compute_box = hypre_BoxArrayBox(compute_box_a, j); hypre_CopyIndex(hypre_BoxIMin(compute_box), start); hypre_StructMapFineToCoarse(start, findex, stride, startc); hypre_BoxGetStrideSize(compute_box, stride, loop_size); if ( constant_coefficient ) { Pi = hypre_CCBoxIndexRank( P_dbox, startc ); hypre_BoxLoop1Begin(hypre_StructMatrixNDim(P), loop_size, e_dbox, start, stride, ei); #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(HYPRE_BOX_PRIVATE,ei) HYPRE_SMP_SCHEDULE #endif hypre_BoxLoop1For(ei) { ep[ei] = (Pp0[Pi] * ep0[ei] + Pp1[Pi] * ep1[ei]); } hypre_BoxLoop1End(ei); } else { hypre_BoxLoop2Begin(hypre_StructMatrixNDim(P), loop_size, P_dbox, startc, stridec, Pi, e_dbox, start, stride, ei); #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(HYPRE_BOX_PRIVATE,Pi,ei) HYPRE_SMP_SCHEDULE #endif hypre_BoxLoop2For(Pi, ei) { ep[ei] = (Pp0[Pi] * ep0[ei] + Pp1[Pi] * ep1[ei]); } hypre_BoxLoop2End(Pi, ei); } }
HYPRE_Int hypre_PFMGBuildCoarseOp5( hypre_StructMatrix *A, hypre_StructMatrix *P, hypre_StructMatrix *R, HYPRE_Int cdir, hypre_Index cindex, hypre_Index cstride, hypre_StructMatrix *RAP ) { hypre_Index index; hypre_Index index_temp; hypre_StructGrid *fgrid; hypre_BoxArray *fgrid_boxes; hypre_Box *fgrid_box; HYPRE_Int *fgrid_ids; hypre_StructGrid *cgrid; hypre_BoxArray *cgrid_boxes; hypre_Box *cgrid_box; HYPRE_Int *cgrid_ids; hypre_IndexRef cstart, bfstart, stridef; hypre_Index fstart, bcstart, stridec; hypre_Index loop_size; HYPRE_Int constant_coefficient; HYPRE_Int fi, ci, fbi; HYPRE_Int loopi, loopj, loopk; hypre_Box *A_dbox; hypre_Box *P_dbox; hypre_Box *RAP_dbox; hypre_BoxArray *bdy_boxes, *tmp_boxes; hypre_Box *bdy_box, *fcbox; double *pb, *pa; double *a_cc, *a_cw, *a_ce, *a_cb, *a_ca; double *rap_cc, *rap_cw, *rap_ce; double *rap_cb, *rap_ca; double west, east; double center_int, center_bdy; HYPRE_Int iA, iAm1, iAp1; HYPRE_Int iAc; HYPRE_Int iP, iPm1, iPp1; HYPRE_Int OffsetA; HYPRE_Int OffsetP; stridef = cstride; hypre_SetIndex(stridec, 1, 1, 1); fgrid = hypre_StructMatrixGrid(A); fgrid_boxes = hypre_StructGridBoxes(fgrid); fgrid_ids = hypre_StructGridIDs(fgrid); cgrid = hypre_StructMatrixGrid(RAP); cgrid_boxes = hypre_StructGridBoxes(cgrid); cgrid_ids = hypre_StructGridIDs(cgrid); constant_coefficient = hypre_StructMatrixConstantCoefficient(RAP); hypre_assert( hypre_StructMatrixConstantCoefficient(A) == constant_coefficient ); if ( constant_coefficient==0 ) { hypre_assert( hypre_StructMatrixConstantCoefficient(R) == 0 ); hypre_assert( hypre_StructMatrixConstantCoefficient(P) == 0 ); } else /* 1 or 2 */ { hypre_assert( hypre_StructMatrixConstantCoefficient(R) == 1 ); hypre_assert( hypre_StructMatrixConstantCoefficient(P) == 1 ); } fcbox = hypre_BoxCreate(); bdy_boxes = hypre_BoxArrayCreate(0); tmp_boxes = hypre_BoxArrayCreate(0); fi = 0; hypre_ForBoxI(ci, cgrid_boxes) { while (fgrid_ids[fi] != cgrid_ids[ci]) { fi++; } cgrid_box = hypre_BoxArrayBox(cgrid_boxes, ci); fgrid_box = hypre_BoxArrayBox(fgrid_boxes, fi); cstart = hypre_BoxIMin(cgrid_box); hypre_StructMapCoarseToFine(cstart, cindex, cstride, fstart); A_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(A), fi); P_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(P), fi); RAP_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(RAP), ci); /*----------------------------------------------------------------- * Extract pointers for interpolation operator: * pb is pointer for weight for f-point below c-point * pa is pointer for weight for f-point above c-point *-----------------------------------------------------------------*/ hypre_SetIndex(index_temp,0,-1,0); MapIndex(index_temp, cdir, index); pa = hypre_StructMatrixExtractPointerByIndex(P, fi, index); hypre_SetIndex(index_temp,0,1,0); MapIndex(index_temp, cdir, index); pb = hypre_StructMatrixExtractPointerByIndex(P, fi, index) - hypre_BoxOffsetDistance(P_dbox, index); /*----------------------------------------------------------------- * Extract pointers for 5-point fine grid operator: * * a_cc is pointer for center coefficient * a_cw is pointer for west coefficient * a_ce is pointer for east coefficient * a_cb is pointer for below coefficient * a_ca is pointer for above coefficient *-----------------------------------------------------------------*/ hypre_SetIndex(index_temp,0,0,0); MapIndex(index_temp, cdir, index); a_cc = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index_temp,-1,0,0); MapIndex(index_temp, cdir, index); a_cw = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index_temp,1,0,0); MapIndex(index_temp, cdir, index); a_ce = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index_temp,0,-1,0); MapIndex(index_temp, cdir, index); a_cb = hypre_StructMatrixExtractPointerByIndex(A, fi, index); hypre_SetIndex(index_temp,0,1,0); MapIndex(index_temp, cdir, index); a_ca = hypre_StructMatrixExtractPointerByIndex(A, fi, index); /*----------------------------------------------------------------- * Extract pointers for coarse grid operator * rap_cc is pointer for center coefficient (etc.) *-----------------------------------------------------------------*/ hypre_SetIndex(index_temp,0,0,0); MapIndex(index_temp, cdir, index); rap_cc = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); hypre_SetIndex(index_temp,-1,0,0); MapIndex(index_temp, cdir, index); rap_cw = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); hypre_SetIndex(index_temp,1,0,0); MapIndex(index_temp, cdir, index); rap_ce = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); hypre_SetIndex(index_temp,0,-1,0); MapIndex(index_temp, cdir, index); rap_cb = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); hypre_SetIndex(index_temp,0,1,0); MapIndex(index_temp, cdir, index); rap_ca = hypre_StructMatrixExtractPointerByIndex(RAP, ci, index); /*----------------------------------------------------------------- * Define offsets for fine grid stencil and interpolation * * In the BoxLoop below I assume iA and iP refer to data associated * with the point which we are building the stencil for. The below * Offsets are used in refering to data associated with other points. *-----------------------------------------------------------------*/ hypre_SetIndex(index_temp,0,1,0); MapIndex(index_temp, cdir, index); OffsetP = hypre_BoxOffsetDistance(P_dbox,index); OffsetA = hypre_BoxOffsetDistance(A_dbox,index); /*-------------------------------------------------------------- * Loop for symmetric 5-point fine grid operator; produces a * symmetric 5-point coarse grid operator. *--------------------------------------------------------------*/ if ( constant_coefficient==0 ) { hypre_BoxGetSize(cgrid_box, loop_size); hypre_BoxLoop3Begin(loop_size, P_dbox, cstart, stridec, iP, A_dbox, fstart, stridef, iA, RAP_dbox, cstart, stridec, iAc); #define HYPRE_BOX_SMP_PRIVATE loopk,loopi,loopj,iP,iA,iAc,iAm1,iAp1,iPm1,iPp1,west,east #include "hypre_box_smp_forloop.h" hypre_BoxLoop3For(loopi, loopj, loopk, iP, iA, iAc) { iAm1 = iA - OffsetA; iAp1 = iA + OffsetA; iPm1 = iP - OffsetP; iPp1 = iP + OffsetP; rap_cb[iAc] = a_cb[iA] * pa[iPm1]; rap_ca[iAc] = a_ca[iA] * pb[iPp1]; west = a_cw[iA] + 0.5 * a_cw[iAm1] + 0.5 * a_cw[iAp1]; east = a_ce[iA] + 0.5 * a_ce[iAm1] + 0.5 * a_ce[iAp1]; /*----------------------------------------------------- * Prevent non-zero entries reaching off grid *-----------------------------------------------------*/ if(a_cw[iA] == 0.0) west = 0.0; if(a_ce[iA] == 0.0) east = 0.0; rap_cw[iAc] = west; rap_ce[iAc] = east; rap_cc[iAc] = a_cc[iA] + a_cw[iA] + a_ce[iA] + a_cb[iA] * pb[iP] + a_ca[iA] * pa[iP] - west - east; } hypre_BoxLoop3End(iP, iA, iAc); }
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; }
HYPRE_Int hypre_PFMGSolve( void *pfmg_vdata, hypre_StructMatrix *A, hypre_StructVector *b, hypre_StructVector *x ) { hypre_PFMGData *pfmg_data = pfmg_vdata; HYPRE_Real tol = (pfmg_data -> tol); HYPRE_Int max_iter = (pfmg_data -> max_iter); HYPRE_Int rel_change = (pfmg_data -> rel_change); HYPRE_Int zero_guess = (pfmg_data -> zero_guess); HYPRE_Int num_pre_relax = (pfmg_data -> num_pre_relax); HYPRE_Int num_post_relax = (pfmg_data -> num_post_relax); HYPRE_Int num_levels = (pfmg_data -> num_levels); hypre_StructMatrix **A_l = (pfmg_data -> A_l); hypre_StructMatrix **P_l = (pfmg_data -> P_l); hypre_StructMatrix **RT_l = (pfmg_data -> RT_l); hypre_StructVector **b_l = (pfmg_data -> b_l); hypre_StructVector **x_l = (pfmg_data -> x_l); hypre_StructVector **r_l = (pfmg_data -> r_l); hypre_StructVector **e_l = (pfmg_data -> e_l); void **relax_data_l = (pfmg_data -> relax_data_l); void **matvec_data_l = (pfmg_data -> matvec_data_l); void **restrict_data_l = (pfmg_data -> restrict_data_l); void **interp_data_l = (pfmg_data -> interp_data_l); HYPRE_Int logging = (pfmg_data -> logging); HYPRE_Real *norms = (pfmg_data -> norms); HYPRE_Real *rel_norms = (pfmg_data -> rel_norms); HYPRE_Int *active_l = (pfmg_data -> active_l); HYPRE_Real b_dot_b = 0, r_dot_r, eps = 0; HYPRE_Real e_dot_e, x_dot_x; HYPRE_Int i, l; HYPRE_Int constant_coefficient; #if DEBUG char filename[255]; #endif /*----------------------------------------------------- * Initialize some things and deal with special cases *-----------------------------------------------------*/ hypre_BeginTiming(pfmg_data -> time_index); constant_coefficient = hypre_StructMatrixConstantCoefficient(A); hypre_StructMatrixDestroy(A_l[0]); hypre_StructVectorDestroy(b_l[0]); hypre_StructVectorDestroy(x_l[0]); A_l[0] = hypre_StructMatrixRef(A); b_l[0] = hypre_StructVectorRef(b); x_l[0] = hypre_StructVectorRef(x); (pfmg_data -> num_iterations) = 0; /* if max_iter is zero, return */ if (max_iter == 0) { /* if using a zero initial guess, return zero */ if (zero_guess) { hypre_StructVectorSetConstantValues(x, 0.0); } hypre_EndTiming(pfmg_data -> time_index); return hypre_error_flag; } /* part of convergence check */ if (tol > 0.0) { /* eps = (tol^2) */ b_dot_b = hypre_StructInnerProd(b_l[0], b_l[0]); eps = tol*tol; /* if rhs is zero, return a zero solution */ if (b_dot_b == 0.0) { hypre_StructVectorSetConstantValues(x, 0.0); if (logging > 0) { norms[0] = 0.0; rel_norms[0] = 0.0; } hypre_EndTiming(pfmg_data -> time_index); return hypre_error_flag; } } /*----------------------------------------------------- * Do V-cycles: * For each index l, "fine" = l, "coarse" = (l+1) *-----------------------------------------------------*/ for (i = 0; i < max_iter; i++) { /*-------------------------------------------------- * Down cycle *--------------------------------------------------*/ if (constant_coefficient) { hypre_StructVectorClearAllValues(r_l[0]); } /* fine grid pre-relaxation */ hypre_PFMGRelaxSetPreRelax(relax_data_l[0]); hypre_PFMGRelaxSetMaxIter(relax_data_l[0], num_pre_relax); hypre_PFMGRelaxSetZeroGuess(relax_data_l[0], zero_guess); hypre_PFMGRelax(relax_data_l[0], A_l[0], b_l[0], x_l[0]); zero_guess = 0; /* compute fine grid residual (b - Ax) */ hypre_StructCopy(b_l[0], r_l[0]); hypre_StructMatvecCompute(matvec_data_l[0], -1.0, A_l[0], x_l[0], 1.0, r_l[0]); /* convergence check */ if (tol > 0.0) { r_dot_r = hypre_StructInnerProd(r_l[0], r_l[0]); if (logging > 0) { norms[i] = sqrt(r_dot_r); if (b_dot_b > 0) rel_norms[i] = sqrt(r_dot_r/b_dot_b); else rel_norms[i] = 0.0; } /* always do at least 1 V-cycle */ if ((r_dot_r/b_dot_b < eps) && (i > 0)) { if (rel_change) { if ((e_dot_e/x_dot_x) < eps) break; } else { break; } } } if (num_levels > 1) { /* restrict fine grid residual */ hypre_SemiRestrict(restrict_data_l[0], RT_l[0], r_l[0], b_l[1]); #if DEBUG hypre_sprintf(filename, "zout_xdown.%02d", 0); hypre_StructVectorPrint(filename, x_l[0], 0); hypre_sprintf(filename, "zout_rdown.%02d", 0); hypre_StructVectorPrint(filename, r_l[0], 0); hypre_sprintf(filename, "zout_b.%02d", 1); hypre_StructVectorPrint(filename, b_l[1], 0); #endif for (l = 1; l <= (num_levels - 2); l++) { if (constant_coefficient) { hypre_StructVectorClearAllValues(r_l[l]); } if (active_l[l]) { /* pre-relaxation */ hypre_PFMGRelaxSetPreRelax(relax_data_l[l]); hypre_PFMGRelaxSetMaxIter(relax_data_l[l], num_pre_relax); hypre_PFMGRelaxSetZeroGuess(relax_data_l[l], 1); hypre_PFMGRelax(relax_data_l[l], A_l[l], b_l[l], x_l[l]); /* compute residual (b - Ax) */ hypre_StructCopy(b_l[l], r_l[l]); hypre_StructMatvecCompute(matvec_data_l[l], -1.0, A_l[l], x_l[l], 1.0, r_l[l]); } else { /* inactive level, set x=0, so r=(b-Ax)=b */ hypre_StructVectorSetConstantValues(x_l[l], 0.0); hypre_StructCopy(b_l[l], r_l[l]); } /* restrict residual */ hypre_SemiRestrict(restrict_data_l[l], RT_l[l], r_l[l], b_l[l+1]); #if DEBUG hypre_sprintf(filename, "zout_xdown.%02d", l); hypre_StructVectorPrint(filename, x_l[l], 0); hypre_sprintf(filename, "zout_rdown.%02d", l); hypre_StructVectorPrint(filename, r_l[l], 0); hypre_sprintf(filename, "zout_b.%02d", l+1); hypre_StructVectorPrint(filename, b_l[l+1], 0); #endif } /*-------------------------------------------------- * Bottom *--------------------------------------------------*/ if (active_l[l]) { hypre_PFMGRelaxSetZeroGuess(relax_data_l[l], 1); hypre_PFMGRelax(relax_data_l[l], A_l[l], b_l[l], x_l[l]); } else { hypre_StructVectorSetConstantValues(x_l[l], 0.0); } #if DEBUG hypre_sprintf(filename, "zout_xbottom.%02d", l); hypre_StructVectorPrint(filename, x_l[l], 0); #endif /*-------------------------------------------------- * Up cycle *--------------------------------------------------*/ for (l = (num_levels - 2); l >= 1; l--) { if (constant_coefficient) { hypre_StructVectorClearAllValues(e_l[l]); } /* interpolate error and correct (x = x + Pe_c) */ hypre_SemiInterp(interp_data_l[l], P_l[l], x_l[l+1], e_l[l]); hypre_StructAxpy(1.0, e_l[l], x_l[l]); #if DEBUG hypre_sprintf(filename, "zout_eup.%02d", l); hypre_StructVectorPrint(filename, e_l[l], 0); hypre_sprintf(filename, "zout_xup.%02d", l); hypre_StructVectorPrint(filename, x_l[l], 0); #endif if (active_l[l]) { /* post-relaxation */ hypre_PFMGRelaxSetPostRelax(relax_data_l[l]); hypre_PFMGRelaxSetMaxIter(relax_data_l[l], num_post_relax); hypre_PFMGRelaxSetZeroGuess(relax_data_l[l], 0); hypre_PFMGRelax(relax_data_l[l], A_l[l], b_l[l], x_l[l]); } } if (constant_coefficient) { hypre_StructVectorClearAllValues(e_l[0]); } /* interpolate error and correct on fine grid (x = x + Pe_c) */ hypre_SemiInterp(interp_data_l[0], P_l[0], x_l[1], e_l[0]); hypre_StructAxpy(1.0, e_l[0], x_l[0]); #if DEBUG hypre_sprintf(filename, "zout_eup.%02d", 0); hypre_StructVectorPrint(filename, e_l[0], 0); hypre_sprintf(filename, "zout_xup.%02d", 0); hypre_StructVectorPrint(filename, x_l[0], 0); #endif } /* part of convergence check */ if ((tol > 0.0) && (rel_change)) { if (num_levels > 1) { e_dot_e = hypre_StructInnerProd(e_l[0], e_l[0]); x_dot_x = hypre_StructInnerProd(x_l[0], x_l[0]); } else { e_dot_e = 0.0; x_dot_x = 1.0; } } /* fine grid post-relaxation */ hypre_PFMGRelaxSetPostRelax(relax_data_l[0]); hypre_PFMGRelaxSetMaxIter(relax_data_l[0], num_post_relax); hypre_PFMGRelaxSetZeroGuess(relax_data_l[0], 0); hypre_PFMGRelax(relax_data_l[0], A_l[0], b_l[0], x_l[0]); (pfmg_data -> num_iterations) = (i + 1); } hypre_EndTiming(pfmg_data -> time_index); return hypre_error_flag; }
HYPRE_Int hypre_StructInterpAssemble( hypre_StructMatrix *A, hypre_StructMatrix *P, HYPRE_Int P_stored_as_transpose, HYPRE_Int cdir, hypre_Index index, hypre_Index stride ) { hypre_StructGrid *grid = hypre_StructMatrixGrid(A); hypre_BoxArrayArray *box_aa; hypre_BoxArray *box_a; hypre_Box *box; hypre_CommInfo *comm_info; hypre_CommPkg *comm_pkg; hypre_CommHandle *comm_handle; HYPRE_Int num_ghost[] = {0, 0, 0, 0, 0, 0}; HYPRE_Int i, j, s, dim; if (hypre_StructMatrixConstantCoefficient(P) != 0) { return hypre_error_flag; } /* set num_ghost */ dim = hypre_StructGridDim(grid); for (j = 0; j < dim; j++) { num_ghost[2*j] = 1; num_ghost[2*j+1] = 1; } if (P_stored_as_transpose) { num_ghost[2*cdir] = 2; num_ghost[2*cdir+1] = 2; } /* comm_info <-- From fine grid grown by num_ghost */ hypre_CreateCommInfoFromNumGhost(grid, num_ghost, &comm_info); /* Project and map comm_info onto coarsened index space */ hypre_CommInfoProjectSend(comm_info, index, stride); hypre_CommInfoProjectRecv(comm_info, index, stride); for (s = 0; s < 3; s++) { switch(s) { case 0: box_aa = hypre_CommInfoSendBoxes(comm_info); hypre_SetIndex(hypre_CommInfoSendStride(comm_info), 1, 1, 1); break; case 1: box_aa = hypre_CommInfoRecvBoxes(comm_info); hypre_SetIndex(hypre_CommInfoRecvStride(comm_info), 1, 1, 1); break; case 2: box_aa = hypre_CommInfoSendRBoxes(comm_info); break; } hypre_ForBoxArrayI(j, box_aa) { box_a = hypre_BoxArrayArrayBoxArray(box_aa, j); hypre_ForBoxI(i, box_a) { box = hypre_BoxArrayBox(box_a, i); hypre_StructMapFineToCoarse(hypre_BoxIMin(box), index, stride, hypre_BoxIMin(box)); hypre_StructMapFineToCoarse(hypre_BoxIMax(box), index, stride, hypre_BoxIMax(box)); } }