diff options
author | allen <allen@6a38eb6e-646e-4a02-a296-d141613ad6c4> | 2002-03-16 17:19:34 +0000 |
---|---|---|
committer | allen <allen@6a38eb6e-646e-4a02-a296-d141613ad6c4> | 2002-03-16 17:19:34 +0000 |
commit | 3b7a96fe84f852789164d98a0edfe807c96b24e4 (patch) | |
tree | e9007dc453dbbc10a77161b80e61968e89ba18b6 | |
parent | b636bbee7c31984989db6e0f0865805b9b3dfa07 (diff) |
Adding new static boundary condition (consider this experimental till
it gets added to the documentation)
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/Boundary/trunk@169 6a38eb6e-646e-4a02-a296-d141613ad6c4
-rw-r--r-- | src/StaticBoundary.c | 910 | ||||
-rw-r--r-- | src/make.code.defn | 1 |
2 files changed, 911 insertions, 0 deletions
diff --git a/src/StaticBoundary.c b/src/StaticBoundary.c new file mode 100644 index 0000000..b6a139c --- /dev/null +++ b/src/StaticBoundary.c @@ -0,0 +1,910 @@ + /*@@ + @file StaticBoundary.c + @date Sat Mar 16 15:09:00 2001 + @author Gabrielle Allen + @desc + Routines for applying static-boundary conditions + @enddesc + @version $Id$ + @@*/ + +#include <stdlib.h> +#include <string.h> + +#include "cctk.h" +#include "cctk_FortranString.h" + +#include "Symmetry.h" +#include "Boundary.h" + +/* the rcs ID and its dummy function to use it */ +static const char *rcsid = "$Header$"; +CCTK_FILEVERSION(CactusBase_Boundary_StaticBoundary_c) + + +/******************************************************************** + ******************** External Routines ************************ + ********************************************************************/ +/* prototypes for external C routines are declared in header Boundary.h + here only follow the fortran wrapper prototypes */ +void CCTK_FCALL CCTK_FNAME (BndStaticDirVI) + (int *ierr, + const cGH *GH, + const int *stencil_size, + const int *dir, + const int *vi); +void CCTK_FCALL CCTK_FNAME (BndStaticVI) + (int *ierr, + const cGH *GH, + const int *stencil, + const int *vi); +void CCTK_FCALL CCTK_FNAME (BndStaticDirGI) + (int *ierr, + const cGH *GH, + const int *stencil_size, + const int *dir, + const int *gi); +void CCTK_FCALL CCTK_FNAME (BndStaticGI) + (int *ierr, + const cGH *GH, + const int *stencil, + const int *gi); +void CCTK_FCALL CCTK_FNAME (BndStaticDirVN) + (int *ierr, + const cGH *GH, + const int *stencil_size, + const int *dir, + ONE_FORTSTRING_ARG); +void CCTK_FCALL CCTK_FNAME (BndStaticVN) + (int *ierr, + const cGH *GH, + const int *stencil, + ONE_FORTSTRING_ARG); +void CCTK_FCALL CCTK_FNAME (BndStaticDirGN) + (int *ierr, + const cGH *GH, + const int *stencil_size, + const int *dir, + ONE_FORTSTRING_ARG); +void CCTK_FCALL CCTK_FNAME (BndStaticGN) + (int *ierr, + const cGH *GH, + const int *stencil, + ONE_FORTSTRING_ARG); + + +/******************************************************************** + ******************** 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 + @date Sat Jan 20 2001 + @author Gabrielle Allen + @desc + Apply static boundary routines by var index in given direction + @enddesc + @calls ApplyBndStatic + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var stencil_size + @vdesc stencil size in this direction + @vtype int + @vio in + @endvar + @var dir + @vdesc direction to apply boundary + @vtype int + @vio in + @endvar + @var vi + @vdesc index of variable to apply static boundaries + @vtype int + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine ApplyBndStatic <BR> + -1 if invalid variable indices are given + @endreturndesc +@@*/ +int BndStaticDirVI (const cGH *GH, + int stencil_size, + int dir, + int vi) +{ + int retval, num_vars; + + + num_vars = CCTK_NumVars (); + if (vi >= 0 && vi < num_vars) + { + retval = ApplyBndStatic (GH, stencil_size, NULL, dir, vi, 1); + } + else + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid variable index %d in BndStaticDirVI", + vi); + retval = -1; + } + + return (retval); +} + +void CCTK_FCALL CCTK_FNAME (BndStaticDirVI) + (int *ierr, + const cGH *GH, + const int *stencil_size, + const int *dir, + const int *vi) +{ + *ierr = BndStaticDirVI (GH, *stencil_size, *dir, *vi); +} + + +/*@@ + @routine BndStaticVI + @date Thu Mar 2 11:02:10 2000 + @author Gerd Lanfermann + @desc + Apply static boundary routines by var index + @enddesc + @calls ApplyBndStatic + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var stencil + @vdesc stencil width + @vtype int [ dimension of variable ] + @vio in + @endvar + @var vi + @vdesc index of variable to apply static boundaries to + @vtype int + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine ApplyBndStatic <BR> + -1 if invalid variable indices are given + @endreturndesc +@@*/ +int BndStaticVI (const cGH *GH, + const int *stencil, + int vi) +{ + int retval, num_vars; + + + num_vars = CCTK_NumVars (); + if (vi >= 0 && vi < num_vars) + { + retval = ApplyBndStatic (GH, -1, stencil, 0, vi, 1); + } + else + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid variable index %d in BndStaticVI", + vi); + retval = -1; + } + + return (retval); +} + +void CCTK_FCALL CCTK_FNAME (BndStaticVI) + (int *ierr, + const cGH *GH, + const int *stencil, + const int *vi) +{ + *ierr = BndStaticVI (GH, stencil, *vi); +} + + +/* ====================================================== */ + + /*@@ + @routine BndStaticDirGI + @date Sat Jan 20 2001 + @author Gabrielle Allen + @desc + Apply static boundaries by group index in given direction + @enddesc + @calls ApplyBndStatic + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var stencil_size + @vdesc stencil size in this direction + @vtype int + @vio in + @endvar + @var dir + @vdesc direction to apply static boundaries + @vtype int + @vio in + @endvar + @var gi + @vdesc index of group to apply static boundaries to + @vtype int + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine ApplyBndStatic <BR> + -1 if invalid group indices are given + @endreturndesc +@@*/ +int BndStaticDirGI (const cGH *GH, + int stencil_size, + int dir, + int gi) +{ + int first_vi, retval; + + + first_vi = CCTK_FirstVarIndexI (gi); + if (first_vi >= 0) + { + retval = ApplyBndStatic (GH, stencil_size, NULL, dir, first_vi, + CCTK_NumVarsInGroupI (gi)); + } + else + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid group indices %d in BndStaticDirGI", + gi); + retval = -1; + } + + return (retval); +} + +void CCTK_FCALL CCTK_FNAME (BndStaticDirGI) + (int *ierr, + const cGH *GH, + const int *stencil_size, + const int *dir, + const int *gi) +{ + *ierr = BndStaticDirGI (GH, *stencil_size, *dir, *gi); +} + + + /*@@ + @routine BndStaticGI + @date Thu Mar 2 11:07:11 2000 + @author Gerd Lanfermann + @desc + Apply static boundaries by group index + @enddesc + @calls ApplyBndStatic + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var stencil + @vdesc stencil width + @vtype int [ dimension of group ] + @vio in + @endvar + @var gi + @vdesc index of group to apply static boundaries to + @vtype int + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine ApplyBndStatic <BR> + -1 if invalid group indices are given + @endreturndesc +@@*/ +int BndStaticGI (const cGH *GH, + const int *stencil, + int gi) +{ + int first_vi, retval; + + + first_vi = CCTK_FirstVarIndexI (gi); + if (first_vi >= 0) + { + retval = ApplyBndStatic (GH, -1, stencil, 0, first_vi, + CCTK_NumVarsInGroupI (gi)); + } + else + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid group index %d in BndStaticGI", + gi); + retval = -1; + } + + return (retval); +} + +void CCTK_FCALL CCTK_FNAME (BndStaticGI) + (int *ierr, + const cGH *GH, + const int *stencil, + const int *gi) +{ + *ierr = BndStaticGI (GH, stencil, *gi); +} + + +/* ======================================================= */ + +/*@@ + @routine BndStaticDirGN + @date Sat Jan 20 2001 + @author Gabrielle Allen + @desc + Apply static boundary routines by group name in given direction + @enddesc + @calls BndStaticDirGI + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var stencil_size + @vdesc stencil size in this direction + @vtype int + @vio in + @endvar + @var dir + @vdesc direction to apply static boundaries + @vtype int + @vio in + @endvar + @var gname + @vdesc name of group to apply static boundaries to + @vtype const char * + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine BndStaticDirGI <BR> + -1 if invalid group names are given + @endreturndesc +@@*/ +int BndStaticDirGN (const cGH *GH, + int stencil_size, + int dir, + const char *gname) +{ + int gi, num_groups, retval; + + + gi = CCTK_GroupIndex (gname); + num_groups = CCTK_NumGroups (); + + if (gi >= 0 && gi < num_groups) + { + retval = BndStaticDirGI (GH, stencil_size, dir, gi); + } + else + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid group name '%s' in BndStaticDirGN", + gname); + retval = -1; + } + + return (retval); +} + +void CCTK_FCALL CCTK_FNAME (BndStaticDirGN) + (int *ierr, + const cGH *GH, + const int *stencil_size, + const int *dir, + ONE_FORTSTRING_ARG) +{ + ONE_FORTSTRING_CREATE (gname) + *ierr = BndStaticDirGN (GH, *stencil_size, *dir, gname); + free (gname); +} + + +/*@@ + @routine BndStaticGN + @date Thu Mar 2 11:02:10 2000 + @author Gerd Lanfermann + @desc + Apply static boundary routines by group name + @enddesc + @calls BndStaticGI + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var stencil + @vdesc stencil width + @vtype int [ dimension of group ] + @vio in + @endvar + @var gname + @vdesc name of group to apply static boundaries to + @vtype const char * + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine BndStaticGI <BR> + -1 if invalid group names are given + @endreturndesc +@@*/ +int BndStaticGN (const cGH *GH, + const int *stencil, + const char *gname) +{ + int gi, num_groups, retval; + + + gi = CCTK_GroupIndex (gname); + num_groups = CCTK_NumGroups (); + + if (gi >= 0 && gi < num_groups) + { + retval = BndStaticGI (GH, stencil, gi); + } + else + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid group name '%s' in BndStaticGN", + gname); + retval = -1; + } + + return (retval); +} + +void CCTK_FCALL CCTK_FNAME (BndStaticGN) + (int *ierr, + const cGH *GH, + const int *stencil, + ONE_FORTSTRING_ARG) +{ + ONE_FORTSTRING_CREATE (gname) + *ierr = BndStaticGN (GH, stencil, gname); + free (gname); +} + + +/* ======================================================= */ + +/*@@ + @routine BndStaticDirVN + @date Sat Jan 20 2001 + @author Gabrielle Allen + @desc + Apply static boundary routines by group name in given direction + @enddesc + @calls BndStaticDirVI + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var stencil_size + @vdesc stencil size in this direction + @vtype int + @vio in + @endvar + @var dir + @vdesc direction to apply static boundaries + @vtype int + @vio in + @endvar + @var vname + @vdesc name of variable to apply static boundaries to + @vtype const char * + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine BndStaticDirVI <BR> + -1 if invalid variable names are given + @endreturndesc +@@*/ +int BndStaticDirVN (const cGH *GH, + int stencil_size, + int dir, + const char *vname) +{ + int vi, num_vars, retval; + + + vi = CCTK_VarIndex (vname); + num_vars = CCTK_NumVars (); + + if (vi >= 0 && vi < num_vars) + { + retval = BndStaticDirVI (GH, stencil_size, dir, vi); + } + else + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid variable name '%s' in BndStaticDirVN", + vname); + retval = -1; + } + + return (retval); +} + +void CCTK_FCALL CCTK_FNAME (BndStaticDirVN) + (int *ierr, + const cGH *GH, + const int *stencil_size, + const int *dir, + ONE_FORTSTRING_ARG) +{ + ONE_FORTSTRING_CREATE (vname) + *ierr = BndStaticDirVN (GH, *stencil_size, *dir, vname); + free (vname); +} + + +/*@@ + @routine BndStaticVN + @date Thu Mar 2 11:02:10 2000 + @author Gerd Lanfermann + @desc + Apply static boundary routines by variable name + @enddesc + @calls BndStaticVI + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var stencil + @vdesc stencil width + @vtype int [ dimension of variable ] + @vio in + @endvar + @var vname + @vdesc name of variable to apply static boundaries to + @vtype const char * + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine BndStaticVI <BR> + -1 if invalid variable names are given + @endreturndesc +@@*/ +int BndStaticVN (const cGH *GH, + const int *stencil, + const char *vname) +{ + int vi, num_vars, retval; + + vi = CCTK_VarIndex (vname); + num_vars = CCTK_NumVars (); + + if (vi >= 0 && vi < num_vars) + { + retval = BndStaticVI (GH, stencil, vi); + } + else + { + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid variable name '%s' in BndStaticVN", + vname); + retval = -1; + } + + return (retval); +} + +void CCTK_FCALL CCTK_FNAME (BndStaticVN) + (int *ierr, + const cGH *GH, + const int *stencil, + ONE_FORTSTRING_ARG) +{ + ONE_FORTSTRING_CREATE (vname) + *ierr = BndStaticVN (GH, stencil, vname); + free (vname); +} + + +/******************************************************************** + ********************* Local Routines ************************* + ********************************************************************/ + +/* maximum dimension we can deal with */ +#define MAXDIM 3 + +/* macro to compute the linear index of a 3D point */ +#define INDEX_3D(lsh, i, j, k) ((i) + (lsh)[0]*((j) + (lsh)[1]*(k))) + +/*@@ + @routine STATIC_BOUNDARY + @date Sat 20 Jan 2001 + @author Thomas Radke + @desc + Macro to apply static boundary conditions to a variable + Currently it is limited up to 3D variables only. + @enddesc + + @var doBC + @vdesc flag telling whether to apply boundary conditions or not + @vtype int + @vio in + @endvar + @var iend, jend, kend + @vdesc upper ranges for the loopers + @vtype int + @vio in + @endvar + @var ii, jj, kk + @vdesc indices of the current grid point + @vtype int + @vio in + @endvar +@@*/ +#define STATIC_BOUNDARY(doBC, \ + iend, jend, kend, \ + ii, jj, kk) \ +{ \ + if (doBC) \ + { \ + for (k = 0; k < kend; k++) \ + { \ + for (j = 0; j < jend; j++) \ + { \ + for (i = 0; i < iend; i++) \ + { \ + int _index; \ + \ + \ + _index = INDEX_3D (lsh, ii, jj, kk) * vtypesize; \ + memcpy ((char *) GH->data[var][timelvl_to] + _index, \ + (char *) GH->data[var][timelvl_from] + _index, \ + vtypesize); \ + } \ + } \ + } \ + } \ +} + + +/*@@ + @routine ApplyBndStatic + @date Thu Mar 2 11:02:10 2000 + @author Gerd Lanfermann + @desc + Apply static boundary conditions to a group of grid functions + given by their indices + This routine is called by the various BndStaticXXX wrappers. + + Although it is currently limited to handle 1D, 2D, or 3D + variables only it can easily be extended for higher dimensions + by adapting the appropriate macros. + @enddesc + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var stencil_dir + @vdesc stencil width in direction dir + @vtype int + @vio in + @endvar + @var stencil_alldirs + @vdesc stencil 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 + CCTK_GroupDimI + CCTK_VarTypeI + CCTK_GroupStaggerDirArrayGI + STATIC_BOUNDARY + @history + @hdate Sat 20 Jan 2001 + @hauthor Thomas Radke + @hdesc Merged separate routines for 1D, 2D, and 3D + into a single generic routine + @endhistory + + @returntype int + @returndesc + 0 for success + -1 if dimension is not supported + -2 if direction parameter is invalid + -3 if stencil width array parameter is NULL + @endreturndesc +@@*/ +static int ApplyBndStatic (const cGH *GH, + int stencil_dir, + const int *stencil_alldirs, + int dir, + int first_var, + int num_vars) +{ + int i, j, k; + int timelvl_to, timelvl_from; + int gindex, gdim; + int var, vtypesize; + int doBC[2*MAXDIM], dstag[MAXDIM], lsh[MAXDIM], lssh[MAXDIM], stencil[MAXDIM]; + SymmetryGHex *sGHex; + + /* Only apply boundary condition if more than one timelevel */ + if (CCTK_NumTimeLevelsFromVarI(first_var) == 1) + { + return; + } + + /* get the group index of the target variable */ + gindex = CCTK_GroupIndexFromVarI (first_var); + + /* get the number of dimensions and the size of the variable's type */ + gdim = CCTK_GroupDimI (gindex); + vtypesize = CCTK_VarTypeSize (CCTK_VarTypeI (first_var)); + + /* make sure we can deal with this number of dimensions */ + if (gdim > MAXDIM) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Variable dimension of %d not supported", gdim); + return (-1); + } + + /* check the direction parameter */ + if (abs (dir) > gdim) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "ApplyBndStatic: direction %d greater than dimension %d", + dir, gdim); + return (-2); + } + + /* set up stencil width array */ + if (dir) + { + stencil[abs (dir) - 1] = stencil_dir; + } + else if (stencil_alldirs) + { + memcpy (stencil, stencil_alldirs, gdim * sizeof (int)); + } + else + { + CCTK_WARN (1, "ApplyBndStatic: NULL pointer passed for stencil width array"); + return (-3); + } + + /* initialize arrays for variables with less dimensions than MAXDIM + so that we can use the INDEX_3D macro later on */ + for (i = gdim; i < MAXDIM; i++) + { + lssh[i] = 1; + lsh[i] = 0; + } + + /* get the directional staggering of the group */ + CCTK_GroupStaggerDirArrayGI (dstag, gdim, gindex); + + /* get the current timelevel */ + timelvl_to = 0; + timelvl_from = 1; + + /* see if we have a symmetry array */ + sGHex = (SymmetryGHex *) CCTK_GHExtension (GH, "Symmetry"); + + /* now loop over all variables */ + for (var = first_var; + var < first_var + num_vars; + var++) + { + /* Apply condition if: + + boundary is not a symmetry boundary (no symmetry or unset(=unsed)) + + boundary is a physical boundary + + have enough grid points + */ + memset (doBC, 1, sizeof (doBC)); + if (sGHex) + { + for (i = 0; i < 2 * gdim; i++) + { + doBC[i] = sGHex->GFSym[var][i] == GFSYM_NOSYM || + sGHex->GFSym[var][i] == GFSYM_UNSET; + } + } + for (i = 0; i < gdim; i++) + { + lsh[i] = GH->cctk_lsh[i]; + lssh[i] = GH->cctk_lssh[CCTK_LSSH_IDX (dstag[i], i)]; + doBC[i*2] &= GH->cctk_lsh[i] > 1 && GH->cctk_bbox[i*2]; + doBC[i*2+1] &= GH->cctk_lsh[i] > 1 && GH->cctk_bbox[i*2+1]; + if (dir != 0) + { + doBC[i*2] &= (dir < 0 && (i + 1 == abs (dir))); + doBC[i*2+1] &= (dir > 0 && (i + 1 == abs (dir))); + } + } + + /* now copy the boundaries face by face */ + if (gdim > 0) + { + /* lower x */ + STATIC_BOUNDARY (doBC[0], stencil[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); + } + if (gdim > 1) + { + /* lower y */ + STATIC_BOUNDARY (doBC[2], lssh[0], stencil[1], lssh[2], i, j, k); + /* upper y */ + STATIC_BOUNDARY (doBC[3], lssh[0], stencil[1], 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); + /* upper z */ + STATIC_BOUNDARY (doBC[5], lssh[0], lssh[1], stencil[2], i, j, lssh[2]-k-1); + } + } + + return(0); +} diff --git a/src/make.code.defn b/src/make.code.defn index 1a12a7b..7692d77 100644 --- a/src/make.code.defn +++ b/src/make.code.defn @@ -3,6 +3,7 @@ # Source files in this directory SRCS = ScalarBoundary.c\ + StaticBoundary.c\ CopyBoundary.c\ FlatBoundary.c\ RadiationBoundary.c\ |