diff options
Diffstat (limited to 'src/StaticBoundary.c')
-rw-r--r-- | src/StaticBoundary.c | 228 |
1 files changed, 173 insertions, 55 deletions
diff --git a/src/StaticBoundary.c b/src/StaticBoundary.c index 79027c5..e88415e 100644 --- a/src/StaticBoundary.c +++ b/src/StaticBoundary.c @@ -30,7 +30,12 @@ static int ApplyBndStatic (const cGH *GH, int dir, int first_var, int num_vars); - +static int OldApplyBndStatic (const cGH *GH, + int stencil_dir, + const int *stencil_alldirs, + int dir, + int first_var, + int num_vars); /******************************************************************** ******************** External Routines ************************ @@ -65,6 +70,11 @@ static int ApplyBndStatic (const cGH *GH, @vtype int @vio in @endvar + @var widths + @vdesc array of boundary widths for each variable + @vtype int + @vio in + @endvar @var table_handles @vdesc array of table handles which hold extra arguments @vtype int @@ -72,32 +82,38 @@ static int ApplyBndStatic (const cGH *GH, @endvar @returntype int @returndesc - return code of @seeroutine ApplyBndStatic <BR> + return code of @seeroutine ApplyBndStatic + -21 error reading boundary width array from table + -22 wrong size boundary width array in table @endreturndesc @@*/ -int BndStatic(const cGH *GH, int num_vars, int *vars, int *faces, int *tables) +int BndStatic(const cGH *GH, int num_vars, int *vars, int *faces, int *widths, + int *tables) { - int i, j, k, err, gdim, max_gdim, retval; + int i, j, k, gi, err, gdim, max_gdim, retval; /* variables to pass to ApplyBndStatic */ - /*int stencil_dir;*/ /* width of stencil in direction dir, not needed */ - int *stencil; /* width of stencil in all directions */ - int dir; /* direction in which to apply bc */ + int *width_alldirs; /* width of boundary in all directions */ + int dir; /* direction in which to apply bc */ #ifdef DEBUG printf("BndStatic(): got passed GH=%p, num_vars=%d, var_indices[0]=%d, table_handles[0]=%d\n", (const void *) GH, num_vars, var_indices[0], table_handles[0]); #endif - retval = 0; stencil = NULL; max_gdim = 0; + retval = 0; width_alldirs = NULL; max_gdim = 0; /* loop through variables, j at a time */ for (i=0; i<num_vars; i+=j) { - /* find other adjacent vars which are selected for identical bcs */ j=1; - while (i+j<num_vars && vars[i+j]==vars[i]+j && tables[i+j]==tables[i] && - faces[i+j]==faces[i]) + /* Since GFs are allowed to have different staggering, the best we + can do is find variables of the same group which are selected + for identical bcs. If all GFs had the same staggering then we + could groups many GFs together. */ + gi = CCTK_GroupIndexFromVarI (vars[i]); + while (i+j<num_vars && CCTK_GroupIndexFromVarI(vars[i+j])==gi && + tables[i+j]==tables[i] && faces[i+j]==faces[i] && widths[i+j]==widths[i]) { ++j; } @@ -108,43 +124,54 @@ int BndStatic(const cGH *GH, int num_vars, int *vars, int *faces, int *tables) CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING, "Faces specification %d for Static boundary conditions on " "%s is not implemented yet. " - "Applying radiative bcs to all (external) faces.", faces[i], + "Applying Static bcs to all (external) faces.", faces[i], CCTK_VarName(vars[i])); } dir = 0; - /* Set up default arguments for ApplyBndStatic */ - /* Allocate memory and populate stencil width array */ - gdim = CCTK_GroupDimFromVarI(vars[i]); - if (!stencil) + /* Determine boundary width on all faces */ + /* allocate memory for buffer */ + gdim = CCTK_GroupDimI(gi); + if (!width_alldirs) { - stencil = (int *) malloc(gdim*sizeof(int)); + width_alldirs = (int *) malloc(2*gdim*sizeof(int)); max_gdim = gdim; } else if (gdim > max_gdim) { - realloc(stencil, gdim*sizeof(int)); + width_alldirs = realloc(width_alldirs, gdim*sizeof(int)); max_gdim = gdim; } - for (k=0; k<gdim; ++k) - { - stencil[k] = 1; - } - /* Look on table for possible non-default arguments - * (If any of these table look-ups fail, the value will be unchanged - * from its default value) - */ - /* Stencil width array */ - err = Util_TableGetIntArray(tables[i], gdim, stencil, "STENCIL WIDTH"); - if (err == UTIL_ERROR_BAD_HANDLE) + /* fill it with values, either from table or the boundary_width + parameter */ + if (widths[i]<0) { - CCTK_VWarn(5, __LINE__, __FILE__, CCTK_THORNSTRING, - "Invalid table handle passed for Static boundary " - "conditions for %s. Using all default values.", - CCTK_VarName(vars[i])); + err = Util_TableGetIntArray(tables[i], gdim, width_alldirs, + "BOUNDARY WIDTH"); + if (err<0) + { + CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Error %d when reading boundary width array from table " + "for %s", + err, CCTK_VarName(vars[i])); + return -21; + } else if (err!=2*gdim) + { + CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Boundary width array for %s has %d elements, but %d " + "expected", CCTK_VarName(vars[i]), err, 2*gdim); + return -22; + } + } else + { + for (k=0; k<2*gdim; ++k) + { + width_alldirs[k] = widths[i]; + } } - if ((retval = ApplyBndStatic(GH, 0, stencil, dir, vars[i], j)) < 0) + /* Apply the boundary condition */ + if ((retval = ApplyBndStatic(GH, 0, width_alldirs, dir, vars[i], j)) < 0) { CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING, "ApplyBndStatic() returned %d", retval); @@ -153,7 +180,7 @@ int BndStatic(const cGH *GH, int num_vars, int *vars, int *faces, int *tables) #ifdef DEBUG printf("BndStatic(): returning %d\n",retval); #endif - free(stencil); + free(width_alldirs); return retval; } @@ -323,7 +350,7 @@ int BndStaticVI (const cGH *GH, num_vars = CCTK_NumVars (); if (vi >= 0 && vi < num_vars) { - retval = ApplyBndStatic (GH, -1, stencil, 0, vi, 1); + retval = OldApplyBndStatic (GH, -1, stencil, 0, vi, 1); } else { @@ -461,7 +488,7 @@ int BndStaticGI (const cGH *GH, first_vi = CCTK_FirstVarIndexI (gi); if (first_vi >= 0) { - retval = ApplyBndStatic (GH, -1, stencil, 0, first_vi, + retval = OldApplyBndStatic (GH, -1, stencil, 0, first_vi, CCTK_NumVarsInGroupI (gi)); } else @@ -854,13 +881,13 @@ void CCTK_FCALL CCTK_FNAME (BndStaticVN) @vtype const cGH * @vio in @endvar - @var stencil_dir - @vdesc stencil width in direction dir + @var width_dir + @vdesc boundary width in direction dir @vtype int @vio in @endvar - @var stencil_alldirs - @vdesc stencil widths for all directions + @var in_widths + @vdesc boundary widths for all directions @vtype int [ dimension of variable(s) ] @vio in @endvar @@ -902,8 +929,8 @@ void CCTK_FCALL CCTK_FNAME (BndStaticVN) @endreturndesc @@*/ static int ApplyBndStatic (const cGH *GH, - int stencil_dir, - const int *stencil_alldirs, + int width_dir, + const int *in_widths, int dir, int first_var, int num_vars) @@ -912,7 +939,8 @@ static int ApplyBndStatic (const cGH *GH, int timelvl_to, timelvl_from; int gindex, gdim; int var, vtypesize; - int doBC[2*MAXDIM], dstag[MAXDIM], lsh[MAXDIM], lssh[MAXDIM], stencil[MAXDIM]; + int doBC[2*MAXDIM], dstag[MAXDIM], lsh[MAXDIM], lssh[MAXDIM], + widths[2*MAXDIM]; SymmetryGHex *sGHex; /* Only apply boundary condition if more than one timelevel */ @@ -945,18 +973,20 @@ static int ApplyBndStatic (const cGH *GH, return (-2); } - /* set up stencil width array */ + /* set up boundary width array */ if (dir) { - stencil[abs (dir) - 1] = stencil_dir; + widths[2*(abs(dir)-1)] = width_dir; + widths[2*(abs(dir)-1)+1] = width_dir; } - else if (stencil_alldirs) + else if (in_widths) { - memcpy (stencil, stencil_alldirs, gdim * sizeof (int)); + memcpy (widths, in_widths, 2* gdim * sizeof (int)); } else { - CCTK_WARN (1, "ApplyBndStatic: NULL pointer passed for stencil width array"); + CCTK_WARN (1, "ApplyBndStatic: NULL pointer passed for boundary width " + "array"); return (-3); } @@ -1014,25 +1044,113 @@ static int ApplyBndStatic (const cGH *GH, if (gdim > 0) { /* lower x */ - STATIC_BOUNDARY (doBC[0], stencil[0], lssh[1], lssh[2], i, j, k); + STATIC_BOUNDARY (doBC[0], widths[0], lssh[1], lssh[2], i, j, k); /* upper x */ - STATIC_BOUNDARY (doBC[1], stencil[0], lssh[1], lssh[2], lssh[0]-i-1, j, k); + STATIC_BOUNDARY (doBC[1], widths[1], lssh[1], lssh[2], lssh[0]-i-1, j, + k); } if (gdim > 1) { /* lower y */ - STATIC_BOUNDARY (doBC[2], lssh[0], stencil[1], lssh[2], i, j, k); + STATIC_BOUNDARY (doBC[2], lssh[0], widths[2], lssh[2], i, j, k); /* upper y */ - STATIC_BOUNDARY (doBC[3], lssh[0], stencil[1], lssh[2], i, lssh[1]-j-1, k); + STATIC_BOUNDARY (doBC[3], lssh[0], widths[3], lssh[2], i, lssh[1]-j-1, + k); } if (gdim > 2) { /* lower z */ - STATIC_BOUNDARY (doBC[4], lssh[0], lssh[1], stencil[2], i, j, k); + STATIC_BOUNDARY (doBC[4], lssh[0], lssh[1], widths[4], i, j, k); /* upper z */ - STATIC_BOUNDARY (doBC[5], lssh[0], lssh[1], stencil[2], i, j, lssh[2]-k-1); + STATIC_BOUNDARY (doBC[5], lssh[0], lssh[1], widths[5], i, j, + lssh[2]-k-1); } } return(0); } + + +/*@@ + @routine OldApplyBndStatic + @date 5 May 2003 + @author David Rideout + @desc + The new boundary API expects a 2d-element array for the + boundary_widths (d=dimension of grid variable), while + the old API expects a d-element array. This function + converts the old array to the new format. + @enddesc + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var stencil_dir + @vdesc boundary width in direction dir + @vtype int + @vio in + @endvar + @var stencil_alldirs + @vdesc boundary widths for all directions + @vtype int [ dimension of variable(s) ] + @vio in + @endvar + @var dir + @vdesc direction for static boundaries (0 for copying all directions) + @vtype int + @vio in + @endvar + @var first_var + @vdesc index of first variable to apply static boundaries to + @vtype int + @vio in + @endvar + @var num_vars + @vdesc number of variables + @vtype int + @vio in + @endvar + + @calls CCTK_GroupIndexFromVarI + ApplyBndScalar + @returntype int + @returndesc + returncode from @seeroutine ApplyBndScalar + @endreturndesc +@@*/ + +static int OldApplyBndStatic (const cGH *GH, + int stencil_dir, + const int *stencil_alldirs, + int dir, + int first_var, + int num_vars) +{ + int retval, *boundary_widths, dim, i; + static int warned; + + /* Convert stencil_alldirs to new format */ + dim = CCTK_GroupDimFromVarI (first_var); + boundary_widths = (int *) malloc(2*dim*sizeof(int)); + for (i=0; i<2*dim; ++i) + { + boundary_widths[i] = stencil_alldirs[i/2]; + } + + /* Bug people for using the old interface */ + if (!warned) + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Copied older d-element array of boundary widths into the " + "newer 2d-element format. Please use the new boundary " + "interface to avoid this."); + warned = 1; + } + + /* Call ApplyBnd... with new boundary width array */ + retval = ApplyBndStatic(GH, stencil_dir, boundary_widths, dir, first_var, num_vars); + + return retval; +} |