aboutsummaryrefslogtreecommitdiff
path: root/src/CopyBoundary.c
diff options
context:
space:
mode:
authorrideout <rideout@6a38eb6e-646e-4a02-a296-d141613ad6c4>2003-05-05 22:31:49 +0000
committerrideout <rideout@6a38eb6e-646e-4a02-a296-d141613ad6c4>2003-05-05 22:31:49 +0000
commitdcdc72dd6f10779d1d4294a4b2afb2dab218369d (patch)
treea7358592f27853517e42592fdf1f4ae36876eae2 /src/CopyBoundary.c
parenta1d9093aa44cec3768244a2ac8b1e62d264e9136 (diff)
Support for new boundary API, which places an integer boundary_width
argument on calls to Select*ForBC*. If a negative value is given then the boundary condition will look into the table for a 2d element integer array specifying the width of each boundary face. A number bug fixes, including the restriction to only execute a boundary condition on a single group at a time. (consider that the next group may have different staggering) Improvements of debugging code. Wrapper functions OldApplyBnd<BC> added, which support the old d-element 'stencil width' array API. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/Boundary/trunk@221 6a38eb6e-646e-4a02-a296-d141613ad6c4
Diffstat (limited to 'src/CopyBoundary.c')
-rw-r--r--src/CopyBoundary.c240
1 files changed, 156 insertions, 84 deletions
diff --git a/src/CopyBoundary.c b/src/CopyBoundary.c
index 8b3f85c..3b91eb5 100644
--- a/src/CopyBoundary.c
+++ b/src/CopyBoundary.c
@@ -41,7 +41,6 @@ static int ApplyBndCopy (const cGH *GH,
/********************************************************************
******************** External Routines ************************
********************************************************************/
-
/*@@
@routine BndCopy
@date 13 Feb 2003
@@ -51,6 +50,14 @@ static int ApplyBndCopy (const cGH *GH,
the Copy boundary condition
@enddesc
@calls ApplyBndCopy
+ CCTK_GroupDimFromVarI
+ Util_TableGetIntArray
+ Util_TableQueryValueInfo
+ CCTK_VWarn
+ Util_TableGetString
+ CCTK_VarIndex
+ Util_TableGetInt
+
@var GH
@vdesc Pointer to CCTK grid hierarchy
@vtype const cGH *
@@ -72,6 +79,11 @@ static int ApplyBndCopy (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
@@ -79,32 +91,40 @@ static int ApplyBndCopy (const cGH *GH,
@endvar
@returntype int
@returndesc
- return code of @seeroutine ApplyBndScalar
+ return code of @seeroutine ApplyBndCopy
-11 invalid table handle
-12 no "COPY FROM" key in table
+ -21 error reading boundary width array from table
+ -22 wrong size boundary width array in table
@endreturndesc
@@*/
-int BndCopy(const cGH *GH, int num_vars, int *vars, int *faces, int *tables)
+int BndCopy(const cGH *GH, int num_vars, int *vars, int *faces, int *widths,
+ int *tables)
{
- int i, j, k, gdim, max_gdim, err, value_type, value_size, retval;
+ int i, j, k, gi, gdim, max_gdim, err, value_type, value_size, retval;
char *copy_from_name;
/* variables to pass to ApplyBndCopy */
- /*int stencil_dir;*/ /* width of stencil in direction dir, not needed */
- int *stencil_alldirs; /* width of stencil in all directions */
- int dir; /* direction in which to apply bc */
- int copy_from; /* variable (index) from which to copy the boundary data */
+ int *width_alldirs; /* width of boundary on each face */
+ int dir; /* direction in which to apply bc */
+ int copy_from; /* variable (index) from which to copy the boundary
+ data */
- retval = 0; stencil_alldirs = 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;
}
@@ -115,33 +135,14 @@ int BndCopy(const cGH *GH, int num_vars, int *vars, int *faces, int *tables)
CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
"Faces specification %d for Copy boundary conditions on "
"%s is not implemented yet. "
- "Applying radiative bcs to all (external) faces.", faces[i],
+ "Applying Copy bcs to all (external) faces.", faces[i],
CCTK_VarName(vars[i]));
}
dir = 0; /* apply bc to all faces */
- /* Set up default arguments for ApplyBndCopy */
- /* Allocate memory and populate stencil width array */
- gdim = CCTK_GroupDimFromVarI(vars[i]);
- if (!stencil_alldirs)
- {
- stencil_alldirs = (int *) malloc(gdim*sizeof(int));
- max_gdim = gdim;
- } else if (gdim > max_gdim)
- {
- realloc(stencil_alldirs, gdim*sizeof(int));
- max_gdim = gdim;
- }
- for (k=0; k<gdim; ++k)
- {
- stencil_alldirs[k] = 1;
- }
-
- /* Look on table for copy-from variable and possible non-default arguments
- */
- /* Stencil width array */
- err = Util_TableGetIntArray(tables[i], gdim, stencil_alldirs,
- "STENCIL WIDTH");
+ /* Look on table for copy-from variable */
+ err = Util_TableQueryValueInfo(tables[i], &value_type, &value_size,
+ "COPY FROM");
if (err == UTIL_ERROR_BAD_HANDLE)
{
CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
@@ -150,47 +151,84 @@ int BndCopy(const cGH *GH, int num_vars, int *vars, int *faces, int *tables)
"must be provided via key \"COPY FROM\". Aborting.",
CCTK_VarName(vars[i]));
return -11;
- } else
+ } else if (err==1)
{
- if (Util_TableQueryValueInfo(tables[i], &value_type, &value_size,
- "COPY FROM"))
+ if (value_type==CCTK_VARIABLE_STRING)
{
- if (value_type==CCTK_VARIABLE_STRING)
- {
- copy_from_name = (char *) malloc(value_size*sizeof(char));
- Util_TableGetString(tables[i], value_size, copy_from_name,
- "COPY FROM");
- copy_from = CCTK_VarIndex(copy_from_name);
- free(copy_from_name);
- } else if (value_type==CCTK_VARIABLE_INT)
- {
- Util_TableGetInt(tables[i], &copy_from,
- "COPY FROM");
- } else
- {
- CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Invalid data type for key \"COPY FROM\" "
- "Please use CCTK_STRING for the variable name, "
- "or CCTK_INT for the variable index.");
- }
+ copy_from_name = (char *) malloc(value_size*sizeof(char));
+ Util_TableGetString(tables[i], value_size, copy_from_name,
+ "COPY FROM");
+ copy_from = CCTK_VarIndex(copy_from_name);
+ free(copy_from_name);
+ } else if (value_type==CCTK_VARIABLE_INT)
+ {
+ Util_TableGetInt(tables[i], &copy_from,
+ "COPY FROM");
} else
{
CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "No key \"COPY FROM\" provided in table. Please enter the "
- "name or index of variable to copy from into the table "
- "under this key. Aborting.");
- return -12;
+ "Invalid data type for key \"COPY FROM\" "
+ "Please use CCTK_STRING for the variable name, "
+ "or CCTK_INT for the variable index.");
+ }
+ } else
+ {
+ CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "No key \"COPY FROM\" provided in table. Please enter the "
+ "name or index of variable to copy from into the table "
+ "under this key. Aborting.");
+ return -12;
+ }
+
+ /* Determine boundary width on all faces */
+ /* allocate memory for buffer */
+ gdim = CCTK_GroupDimI(gi);
+ if (!width_alldirs)
+ {
+ width_alldirs = (int *) malloc(2*gdim*sizeof(int));
+ max_gdim = gdim;
+ } else if (gdim > max_gdim)
+ {
+ width_alldirs = realloc(width_alldirs, gdim*sizeof(int));
+ max_gdim = gdim;
+ }
+
+ /* fill it with values, either from table or the boundary_width
+ parameter */
+ if (widths[i]<0)
+ {
+ 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 && (retval = ApplyBndCopy(GH, 0, stencil_alldirs, dir,
+ /* Apply the boundary condition */
+ if (!retval && (retval = ApplyBndCopy(GH, 0, width_alldirs, dir,
vars[i], copy_from, j)) < 0)
{
CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
"ApplyBndCopy() returned %d", retval);
}
}
- free(stencil_alldirs);
+ free(width_alldirs);
return retval;
}
@@ -371,13 +409,21 @@ int BndCopyVI (const cGH *GH,
int vi_to,
int vi_from)
{
- int retval, num_vars;
+ int retval, num_vars, dim, i;
+ int *boundary_widths; /* boundary widths as expected by ApplyBndCopy */
+ /* Set up boundary_widths array */
+ dim = CCTK_GroupDimFromVarI (vi_to);
+ boundary_widths = (int *) malloc(2*dim*sizeof(int));
+ for (i=0; i<2*dim; i+=2)
+ {
+ boundary_widths[i] = stencil[i/2];
+ }
num_vars = CCTK_NumVars ();
if (vi_to >= 0 && vi_to < num_vars && vi_from >= 0 && vi_from < num_vars)
{
- retval = ApplyBndCopy (GH, -1, stencil, 0, vi_to, vi_from, 1);
+ retval = ApplyBndCopy (GH, -1, boundary_widths, 0, vi_to, vi_from, 1);
}
else
{
@@ -525,14 +571,22 @@ int BndCopyGI (const cGH *GH,
int gi_from)
{
int first_vi_to, first_vi_from, retval;
+ int i, dim, *boundary_widths;
+ /* Set up boundary_widths array */
+ dim = CCTK_GroupDimI (gi_to);
+ boundary_widths = (int *) malloc(2*dim*sizeof(int));
+ for (i=0; i<2*dim; i+=2)
+ {
+ boundary_widths[i] = stencil[i/2];
+ }
first_vi_to = CCTK_FirstVarIndexI (gi_to);
first_vi_from = CCTK_FirstVarIndexI (gi_from);
if (first_vi_to >= 0 && first_vi_from >= 0)
{
- retval = ApplyBndCopy (GH, -1, stencil, 0, first_vi_to, first_vi_from,
- CCTK_NumVarsInGroupI (gi_to));
+ retval = ApplyBndCopy (GH, -1, boundary_widths, 0, first_vi_to,
+ first_vi_from, CCTK_NumVarsInGroupI (gi_to));
}
else
{
@@ -683,15 +737,23 @@ int BndCopyGN (const cGH *GH,
const char *gname_from)
{
int gi_to, gi_from, num_groups, retval;
-
+ int i, dim, *boundary_widths;
gi_to = CCTK_GroupIndex (gname_to);
gi_from = CCTK_GroupIndex (gname_from);
num_groups = CCTK_NumGroups ();
+ /* Set up boundary_widths array */
+ dim = CCTK_GroupDimI (gi_to);
+ boundary_widths = (int *) malloc(2*dim*sizeof(int));
+ for (i=0; i<2*dim; i+=2)
+ {
+ boundary_widths[i] = stencil[i/2];
+ }
+
if (gi_to >= 0 && gi_to < num_groups && gi_from >= 0 && gi_from < num_groups)
{
- retval = BndCopyGI (GH, stencil, gi_to, gi_from);
+ retval = BndCopyGI (GH, boundary_widths, gi_to, gi_from);
}
else
{
@@ -844,15 +906,23 @@ int BndCopyVN (const cGH *GH,
const char *vname_from)
{
int vi_to, vi_from, num_vars, retval;
-
+ int i, dim, *boundary_widths;
vi_to = CCTK_VarIndex (vname_to);
vi_from = CCTK_VarIndex (vname_from);
num_vars = CCTK_NumVars ();
+ /* Set up boundary_widths array */
+ dim = CCTK_GroupDimFromVarI(vi_to);
+ boundary_widths = (int *) malloc(2*dim*sizeof(int));
+ for (i=0; i<2*dim; i+=2)
+ {
+ boundary_widths[i] = stencil[i/2];
+ }
+
if (vi_to >= 0 && vi_to < num_vars && vi_from >= 0 && vi_from < num_vars)
{
- retval = BndCopyVI (GH, stencil, vi_to, vi_from);
+ retval = BndCopyVI (GH, boundary_widths, vi_to, vi_from);
}
else
{
@@ -1006,12 +1076,12 @@ void CCTK_FCALL CCTK_FNAME (BndCopyVN)
0 for success
-1 if dimension is not supported
-2 if direction parameter is invalid
- -3 if stencil width array parameter is NULL
+ -3 if boundary width array parameter is NULL
@endreturndesc
@@*/
static int ApplyBndCopy (const cGH *GH,
- int stencil_dir,
- const int *stencil_alldirs,
+ int width_dir,
+ const int *in_widths,
int dir,
int first_var_to,
int first_var_from,
@@ -1021,7 +1091,7 @@ static int ApplyBndCopy (const cGH *GH,
int timelvl_to, timelvl_from;
int gindex, gdim;
int var_to, var_from, 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;
@@ -1052,15 +1122,17 @@ static int ApplyBndCopy (const cGH *GH,
/* set up stencil 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, "ApplyBndCopy: NULL pointer passed for stencil width array");
+ CCTK_WARN (1, "ApplyBndCopy: NULL pointer passed for boundary width "
+ "array");
return (-3);
}
@@ -1118,23 +1190,23 @@ static int ApplyBndCopy (const cGH *GH,
if (gdim > 0)
{
/* lower x */
- COPY_BOUNDARY (doBC[0], stencil[0], lssh[1], lssh[2], i, j, k);
+ COPY_BOUNDARY (doBC[0], widths[0], lssh[1], lssh[2], i, j, k);
/* upper x */
- COPY_BOUNDARY (doBC[1], stencil[0], lssh[1], lssh[2], lssh[0]-i-1, j, k);
+ COPY_BOUNDARY (doBC[1], widths[1], lssh[1], lssh[2], lssh[0]-i-1, j, k);
}
if (gdim > 1)
{
/* lower y */
- COPY_BOUNDARY (doBC[2], lssh[0], stencil[1], lssh[2], i, j, k);
+ COPY_BOUNDARY (doBC[2], lssh[0], widths[2], lssh[2], i, j, k);
/* upper y */
- COPY_BOUNDARY (doBC[3], lssh[0], stencil[1], lssh[2], i, lssh[1]-j-1, k);
+ COPY_BOUNDARY (doBC[3], lssh[0], widths[3], lssh[2], i, lssh[1]-j-1, k);
}
if (gdim > 2)
{
/* lower z */
- COPY_BOUNDARY (doBC[4], lssh[0], lssh[1], stencil[2], i, j, k);
+ COPY_BOUNDARY (doBC[4], lssh[0], lssh[1], widths[4], i, j, k);
/* upper z */
- COPY_BOUNDARY (doBC[5], lssh[0], lssh[1], stencil[2], i, j, lssh[2]-k-1);
+ COPY_BOUNDARY (doBC[5], lssh[0], lssh[1], widths[5], i, j, lssh[2]-k-1);
}
}