diff options
Diffstat (limited to 'src/StaticBoundary.c')
-rw-r--r-- | src/StaticBoundary.c | 143 |
1 files changed, 135 insertions, 8 deletions
diff --git a/src/StaticBoundary.c b/src/StaticBoundary.c index 873bbc7..e36f95a 100644 --- a/src/StaticBoundary.c +++ b/src/StaticBoundary.c @@ -12,6 +12,9 @@ #include <string.h> #include "cctk.h" +#include "cctk_Faces.h" +#include "util_Table.h" +#include "util_ErrorCodes.h" #include "cctk_FortranString.h" #include "Symmetry.h" @@ -19,12 +22,143 @@ /* the rcs ID and its dummy function to use it */ static const char *rcsid = "$Header$"; -CCTK_FILEVERSION(CactusBase_Boundary_StaticBoundary_c) +CCTK_FILEVERSION(CactusBase_Boundary_StaticBoundary_c); + +static int ApplyBndStatic (const cGH *GH, + int stencil_dir, + const int *stencil_alldirs, + int dir, + int first_var, + int num_vars); /******************************************************************** ******************** External Routines ************************ ********************************************************************/ +/*@@ + @routine BndStatic + @date 14 Feb 2003 + @author David Rideout + @desc + Top level function which is registered as handling + this boundary condition + @enddesc + @calls ApplyBndStatic + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var num_vars + @vdesc number of variables passed in through var_indices[] + @vtype int + @vio in + @endvar + @var var_indices + @vdesc array of variable indicies to which to apply this boundary + condition + @vtype int * + @vio in + @endvar + @var faces + @vdesc array of set of faces to which to apply the bc + @vtype int + @vio in + @endvar + @var table_handles + @vdesc array of table handles which hold extra arguments + @vtype int + @vio in + @endvar + @returntype int + @returndesc + return code of @seeroutine ApplyBndStatic <BR> + @endreturndesc +@@*/ + +int BndStatic(const cGH *GH, int num_vars, int *vars, int *faces, int *tables) +{ + int i, j, k, 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 */ + +#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; + + /* 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]) + { + ++j; + } + + /* Check to see if faces specification is valid */ + if (faces[i] != CCTK_ALL_FACES) + { + 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], + 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) + { + stencil = (int *) malloc(gdim*sizeof(int)); + max_gdim = gdim; + } else if (gdim > max_gdim) + { + realloc(stencil, 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) + { + CCTK_VWarn(3, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid table handle passed for Static boundary " + "conditions for %s. Using all default values.", + CCTK_VarName(vars[i])); + } + + if ((retval = ApplyBndStatic(GH, 0, stencil, dir, vars[i], j)) < 0) + { + CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING, + "ApplyBndStatic() returned %d", retval); + } + } +#ifdef DEBUG + printf("BndStatic(): returning %d\n",retval); +#endif + free(stencil); + + return retval; +} + + /* prototypes for external C routines are declared in header Boundary.h here only follow the fortran wrapper prototypes */ void CCTK_FCALL CCTK_FNAME (BndStaticDirVI) @@ -76,13 +210,6 @@ void CCTK_FCALL CCTK_FNAME (BndStaticGN) /******************************************************************** ******************** Internal Routines ************************ ********************************************************************/ -static int ApplyBndStatic (const cGH *GH, - int stencil_dir, - const int *stencil_alldirs, - int dir, - int first_var, - int num_vars); - /*@@ @routine BndStaticDirVI |