diff options
author | allen <allen@6a38eb6e-646e-4a02-a296-d141613ad6c4> | 2001-01-17 13:31:29 +0000 |
---|---|---|
committer | allen <allen@6a38eb6e-646e-4a02-a296-d141613ad6c4> | 2001-01-17 13:31:29 +0000 |
commit | 10513f497d685f88995baf6f27d3bd113b010825 (patch) | |
tree | f5948ede555fd429f4795e5eeddc27aa8fd261b6 /src/ScalarBoundary.c | |
parent | 67d025a8986ad4c97825981b98ab6f808ee5539d (diff) |
Added more error checking for Scalar boundaries, and removed debugging statements.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/Boundary/trunk@129 6a38eb6e-646e-4a02-a296-d141613ad6c4
Diffstat (limited to 'src/ScalarBoundary.c')
-rw-r--r-- | src/ScalarBoundary.c | 259 |
1 files changed, 143 insertions, 116 deletions
diff --git a/src/ScalarBoundary.c b/src/ScalarBoundary.c index d39c28b..02098d5 100644 --- a/src/ScalarBoundary.c +++ b/src/ScalarBoundary.c @@ -20,7 +20,7 @@ #include "BoundarySymmetries.h" #include "Boundary.h" -#define DEBUG_BOUNDARY +/*#define DEBUG_BOUNDARY*/ /* Internal routine prototypes */ @@ -471,7 +471,7 @@ static int ApplyBndScalar(cGH *GH, int vi, gi, dim; int coord; int idim; - int berr,ierr; + int berr,ierr,retval=0; int dirloop1,dirloop2; int doBC, count; int *dstag; @@ -492,151 +492,178 @@ static int ApplyBndScalar(cGH *GH, printf("-----------------------------------\n"); #endif - /* See if we have a symmetry array */ - symmetry_handle = CCTK_GHExtensionHandle("Symmetry"); - if (symmetry_handle < 0) - { - sGHex = NULL; - } - else - { - sGHex = (SymmetryGHex*)GH->extensions[symmetry_handle]; - } - /* Get group dimension */ dim = CCTK_GroupDimFromVarI(first_var); - /* Set up stencil width array if needed */ - if (stencil_array) + if (dim<1 || dim>3) { - sw = stencil_array; + CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, + "ApplyBndScalar: Invalid grid function dimension %d", + dim); + retval=-1; } else { - int i; - sw = (int *)malloc(dim*sizeof(int)); - for (i=0;i<dim;i++) + /* See if we have a symmetry array */ + symmetry_handle = CCTK_GHExtensionHandle("Symmetry"); + if (symmetry_handle < 0) { - sw[i] = 0; + sGHex = NULL; } - if (dir > 0) + else { - sw[dir-1] = stencil; - coord = dir-1; + sGHex = (SymmetryGHex*)GH->extensions[symmetry_handle]; + } + + /* Set up stencil width array if needed */ + if (stencil_array && dir == 0) + { + sw = stencil_array; + } + else if (dir==0) + { + CCTK_WARN(0,"ApplyBndScalar: Direction 0 invalid for directional BC"); + } + else if (dir>dim||-dir>dim) + { + CCTK_VWarn(0,__LINE__,__FILE__,CCTK_THORNSTRING, + "ApplyBndScalar: Direction %d greater than dimension %d", + dir,dim); } else { - sw[-dir-1] = stencil; - coord = -dir-1; + int i; + /* Should be single direction */ + sw = (int *)malloc(dim*sizeof(int)); + if (sw) + { + for (i=0;i<dim;i++) + { + sw[i] = 0; + } + if (dir > 0) + { + sw[dir-1] = stencil; + coord = dir-1; + } + else + { + sw[-dir-1] = stencil; + coord = -dir-1; + } + } + else + { + CCTK_WARN(0,"ApplyBndScalar: Malloc sw failed"); + } } - } - /* allocate arrays */ - dstag = (int *)malloc(dim*sizeof(int)); - lssh = (int *)malloc(dim*sizeof(int)); + /* allocate arrays */ + dstag = (int *)malloc(dim*sizeof(int)); + lssh = (int *)malloc(dim*sizeof(int)); - /* get the directional staggering of the group */ - gi = CCTK_GroupIndexFromVarI(first_var); - ierr = CCTK_GroupStaggerDirArrayGI(dstag, dim, gi); + /* get the directional staggering of the group */ + gi = CCTK_GroupIndexFromVarI(first_var); + ierr = CCTK_GroupStaggerDirArrayGI(dstag, dim, gi); - /* get the current timelevel */ - timelevel = CCTK_NumTimeLevelsFromVarI (first_var) - 1; + /* get the current timelevel */ + timelevel = CCTK_NumTimeLevelsFromVarI (first_var) - 1; - /* Treat all boundaries or just one? */ - if (dir>0) - { - dirloop1 = 2*(dir-1)+1; - dirloop2 = dirloop1+1; - } - else if (dir<0) - { - dirloop1 = 2*(-dir-1); - dirloop2 = dirloop1+1; - } - else - { - dirloop1 = 0; - dirloop2 = 2*dim; - } - - for (vi=first_var; vi<first_var+num_vars; vi++) - { - /* Apply condition if: - + boundary is not a symmetry boundary - (no symmetry or unset(=unsed)) - + boundary is a physical boundary - + have enough grid points - */ - - for (idim=0;idim<dim;idim++) + /* Treat all boundaries or just one? */ + if (dir>0) { - lssh[idim] = (int)GH->cctk_lssh[CCTK_LSSH_IDX(dstag[idim],idim)]; + dirloop1 = 2*(dir-1)+1; + dirloop2 = dirloop1+1; } - - for (count=dirloop1;count<dirloop2;count++) + else if (dir<0) { - if (sGHex) - { - doBC = ( - ( (sGHex->GFSym[vi][count]==GFSYM_NOSYM) || - (sGHex->GFSym[vi][count]==GFSYM_UNSET) ) && - GH->cctk_lsh[coord]>1 && GH->cctk_bbox[count]) ? - count : -1; - } - else + dirloop1 = 2*(-dir-1); + dirloop2 = dirloop1+1; + } + else + { + dirloop1 = 0; + dirloop2 = 2*dim; + } + + for (vi=first_var; vi<first_var+num_vars; vi++) + { + /* Apply condition if: + + boundary is not a symmetry boundary + (no symmetry or unset(=unsed)) + + boundary is a physical boundary + + have enough grid points */ + + for (idim=0;idim<dim;idim++) { - doBC = (GH->cctk_lsh[coord]>1 && GH->cctk_bbox[count]) ? - count : -1 ; + lssh[idim] = (int)GH->cctk_lssh[CCTK_LSSH_IDX(dstag[idim],idim)]; } - if (doBC >=0) + for (count=dirloop1;count<dirloop2;count++) { - switch (dim) - { - case 1: - berr = BndApplyScalar1Di(GH, - doBC, - lssh, - sw, - scalar_val, - GH->data[vi][timelevel]); - break; - case 2: - berr = BndApplyScalar2Di(GH, - doBC, - lssh, - sw, - scalar_val, - GH->data[vi][timelevel]); - break; - case 3: - berr = BndApplyScalar3Di(GH, - doBC, - lssh, - sw, - scalar_val, - GH->data[vi][timelevel]); - break; - default : - berr = -1; - CCTK_VWarn(1,__LINE__,__FILE__,"Boundary", - "No scalar boundary for dim>3: grid variable '%s'", - CCTK_VarName(vi)); + if (sGHex) + { + doBC = ( + ( (sGHex->GFSym[vi][count]==GFSYM_NOSYM) || + (sGHex->GFSym[vi][count]==GFSYM_UNSET) ) && + GH->cctk_lsh[coord]>1 && GH->cctk_bbox[count]) ? + count : -1; + } + else + { + doBC = (GH->cctk_lsh[coord]>1 && GH->cctk_bbox[count]) ? + count : -1 ; + } + + if (doBC >=0) + { + switch (dim) + { + case 1: + berr = BndApplyScalar1Di(GH, + doBC, + lssh, + sw, + scalar_val, + GH->data[vi][timelevel]); + break; + case 2: + berr = BndApplyScalar2Di(GH, + doBC, + lssh, + sw, + scalar_val, + GH->data[vi][timelevel]); + break; + case 3: + berr = BndApplyScalar3Di(GH, + doBC, + lssh, + sw, + scalar_val, + GH->data[vi][timelevel]); + break; + default : + berr = -1; + CCTK_VWarn(1,__LINE__,__FILE__,"Boundary", + "No scalar boundary for dim>3: grid variable '%s'", + CCTK_VarName(vi)); + } } } + /* retval = (berr>-1) ? 0 : -1;*/ } - berr = (berr>-1) ? 0 : -1; - } - - free(dstag); - free(lssh); + + free(dstag); + free(lssh); - if (!stencil_array) - { - free(sw); + if (!stencil_array) + { + free(sw); + } } - return ierr; + return retval; } |