diff options
Diffstat (limited to 'src/RobinBoundary.c')
-rw-r--r-- | src/RobinBoundary.c | 153 |
1 files changed, 144 insertions, 9 deletions
diff --git a/src/RobinBoundary.c b/src/RobinBoundary.c index 9e1c963..3efe8f4 100644 --- a/src/RobinBoundary.c +++ b/src/RobinBoundary.c @@ -18,6 +18,9 @@ #include <string.h> #include "cctk.h" +#include "cctk_Faces.h" +#include "util_Table.h" +#include "util_ErrorCodes.h" #include "cctk_Parameters.h" #include "cctk_FortranString.h" @@ -26,12 +29,151 @@ /* the rcs ID and its dummy function to use it */ static const char *rcsid = "$Header$"; -CCTK_FILEVERSION(CactusBase_Boundary_RobinBoundary_c) +CCTK_FILEVERSION(CactusBase_Boundary_RobinBoundary_c); + +static int ApplyBndRobin (const cGH *GH, + const int *stencil, + CCTK_REAL finf, + int npow, + int first_var, + int num_vars); /******************************************************************** ******************** External Routines ************************ ********************************************************************/ +/*@@ + @routine BndRobin + @date 14 Feb 2003 + @author David Rideout + @desc + Top level function which is registered as handling + this boundary condition + @enddesc + @calls ApplyBndRobin + @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 ApplyBndRobin <BR> + @endreturndesc +@@*/ + +int BndRobin(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 ApplyBndRobin */ + int *stencil; /* width of stencil in all directions */ + CCTK_REAL finf; /* value of function at infinity */ + int npow; /* decay rate */ + +#ifdef DEBUG + printf("BndRobin(): 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 Robin boundary conditions on " + "%s is not implemented yet. " + "Applying radiative bcs to all (external) faces.", faces[i], + CCTK_VarName(vars[i])); + } + + /* Set up default arguments for ApplyBndRobin */ + /* 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; + } + /* Defaults for remainder of arguments */ + finf = 1.; + npow = 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) + */ + /* Asymptotic value of function at infinity */ + err = Util_TableGetReal(tables[i], &finf, "FINF"); + if (err == UTIL_ERROR_BAD_HANDLE) + { + CCTK_VWarn(3, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid table handle passed for Robin boundary " + "conditions for %s. Using all default values.", + CCTK_VarName(vars[i])); + } else + { + /* Stencil width array */ + Util_TableGetIntArray(tables[i], gdim, stencil, "STENCIL WIDTH"); + + /* Decay power */ + Util_TableGetInt(tables[i], &npow, "DECAY POWER"); + } + + if ((retval = ApplyBndRobin(GH, stencil, finf, npow, vars[i], j)) < 0) + { + CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING, + "ApplyBndRobin() returned %d", retval); + } + } +#ifdef DEBUG + printf("BndRobin(): 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 (BndRobinGI) @@ -67,13 +209,6 @@ void CCTK_FCALL CCTK_FNAME (BndRobinVN) /******************************************************************** ******************** Internal Routines ************************ ********************************************************************/ -static int ApplyBndRobin (const cGH *GH, - const int *stencil, - CCTK_REAL finf, - int npow, - int first_var, - int num_vars); - /*@@ @routine BndRobinGI @@ -112,7 +247,7 @@ static int ApplyBndRobin (const cGH *GH, @returntype int @returndesc - return code of @seeroutine ApplyBndRobin <BR> + return code of @seeroutine ApplyBndRobin -1 if invalid group index was given @endreturndesc @@*/ |