diff options
author | tradke <tradke@c78560ca-4b45-4335-b268-5f3340f3cb52> | 2002-11-03 23:18:07 +0000 |
---|---|---|
committer | tradke <tradke@c78560ca-4b45-4335-b268-5f3340f3cb52> | 2002-11-03 23:18:07 +0000 |
commit | 1ad057c7403c47f4ce904e908d6c39df53f23559 (patch) | |
tree | f06a9428b2f47e0da91468febfb6ef10b52ed23b | |
parent | ea3a2774881627e701e4961605822e0372a5c6c9 (diff) |
Generalized set symmetry BC routines for arbitrary CCTK datatypes.
Some formatting, completed grdoc.
This closes PR CactusBase/1030.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/CartGrid3D/trunk@174 c78560ca-4b45-4335-b268-5f3340f3cb52
-rw-r--r-- | src/GHExtension.c | 94 | ||||
-rw-r--r-- | src/SetSymmetry.c | 244 | ||||
-rw-r--r-- | src/Startup.c | 155 | ||||
-rw-r--r-- | src/Symmetry.c | 897 | ||||
-rw-r--r-- | src/Symmetry.h | 52 | ||||
-rw-r--r-- | src/SymmetryWrappers.c | 445 | ||||
-rw-r--r-- | src/make.code.defn | 4 |
7 files changed, 822 insertions, 1069 deletions
diff --git a/src/GHExtension.c b/src/GHExtension.c deleted file mode 100644 index 700efa5..0000000 --- a/src/GHExtension.c +++ /dev/null @@ -1,94 +0,0 @@ - /*@@ - @file GHExtension.c - @date Mon Mar 15 15:48:42 1999 - @author Gerd Lanfermann - @desc - Set up the symmetry GH extension. This should really be done - with StoredData - @enddesc - @version $Id$ - @@*/ - -#include <stdlib.h> - -#include "cctk.h" -#include "Symmetry.h" - -static const char *rcsid = "$Header$"; - -CCTK_FILEVERSION(CactusBase_CartGrid3D_GHExtension_c) - -int Symmetry_InitGHex(cGH *GH); -void *Symmetry_AllocGHex(tFleshConfig *config, int convlevel, cGH *GH); -int Symmetry_InitFGHex(cGH *GH); - -void *Symmetry_AllocGHex(tFleshConfig *config, int convlevel, cGH *GH) -{ - - int gf,grid_dim,NumVars; /* Number of dimensions, grid functions */ - SymmetryGHex *newGHex; /* Type of GHextension is EinsteinBoundGHex */ - - - /* avoid compiler warnings about unused arguments */ - config = config; - convlevel = convlevel; - GH = GH; - - NumVars = CCTK_NumVars(); /* Get number of grid functions */ - grid_dim = CCTK_MaxDim(); /* Get maximal dimension of the grid */ - - /* allocate the GHextension */ - newGHex = (SymmetryGHex*)malloc(sizeof(SymmetryGHex)); - - /* allocation for the number of grid functions*/ - newGHex->GFSym = (int **)malloc(NumVars*sizeof(int *)); - - /* allocation for the number of dimensions*/ - for (gf=0;gf<NumVars;gf++) - { - newGHex->GFSym[gf] = (int *)malloc(2*grid_dim*sizeof(int)); - } - - /* Now we have something, that looks like [0..NumVars-1][0..grid_dim-1] - and we return that: This will be merged into - the GH and can be referenced in the following manner: - int handle = CCTK_GHExtensionHandle("Symmetry"); - ..... which returns a pointer the GHextension - BoundGHex = ((pGH *)GH->extensions[handle]); - ..... BoundGHex can now be used as: - BoundGHex->GFSym[3][2] = 1 ; - */ - - return newGHex; - -} - -int Symmetry_InitGHex(cGH *GH) -{ - int retval = 0; - SymmetryGHex *newGHex; - int handle; - int gf,d; - int NumVars =CCTK_NumVars(); - int grid_dim; - - grid_dim = CCTK_MaxDim(); - handle = CCTK_GHExtensionHandle("Symmetry"); - newGHex = (SymmetryGHex*) GH->extensions[handle]; - - /* ... and initialize them: */ - for (gf=0;gf<NumVars;gf++) - { - for(d=0;d<2*grid_dim;d++) - { - newGHex->GFSym[gf][d] = GFSYM_UNSET; /* not set */ - } - } - - return retval; -} - - - - - diff --git a/src/SetSymmetry.c b/src/SetSymmetry.c index afefea2..c10c55b 100644 --- a/src/SetSymmetry.c +++ b/src/SetSymmetry.c @@ -3,10 +3,10 @@ @file Symmetry.c @date Mon Mar 15 15:09:00 1999 @author Gerd Lanfermann - @desc - This file contains the routines for registering and applying symmetry + @desc + This file contains the routines for registering and applying symmetry boundary conditions - @enddesc + @enddesc @@*/ #include <stdlib.h> @@ -14,99 +14,85 @@ #include "cctk.h" #include "cctk_Parameters.h" #include "cctk_FortranString.h" -#include "Symmetry.h" +#include "Symmetry.h" static const char *rcsid = "$Header$"; CCTK_FILEVERSION(CactusBase_CartGrid3D_SetSymmetry_c) -/******************************************************************** - ********************* Local Data Types *********************** - ********************************************************************/ /******************************************************************** - ********************* Local Routine Prototypes ********************* + ********************* External Routines ********************** ********************************************************************/ - void DecodeSymParameters3D(int sym[6]); - void CCTK_FCALL CCTK_FNAME(SetCartSymVI) - (int *ierr, cGH *GH, int *sym, int *vi); + (int *ierr, const cGH *GH, const int *sym, const int *vi); void CCTK_FCALL CCTK_FNAME(SetCartSymVN) - (int *ierr, cGH *GH, int *sym, ONE_FORTSTRING_ARG); + (int *ierr, const cGH *GH, const int *sym, ONE_FORTSTRING_ARG); void CCTK_FCALL CCTK_FNAME(SetCartSymGI) - (int *ierr, cGH *GH, int *sym, int *gi); + (int *ierr, const cGH *GH, const int *sym, const int *gi); void CCTK_FCALL CCTK_FNAME(SetCartSymGN) - (int *ierr, cGH *GH, int *sym, ONE_FORTSTRING_ARG); - + (int *ierr, const cGH *GH, const int *sym, ONE_FORTSTRING_ARG); -/******************************************************************** - ********************* External Routines ********************** - ********************************************************************/ - /*@@ @routine SetCartSymmetry @date Mon Mar 15 15:10:58 1999 @author Gerd Lanfermann - @desc - This routine sets the GH extension (EinsteinBoundGHex *bGHex), - which describes the symmetry boundary type of each GF. Takes - the name of the GF ("implementation::gfname") and the symmetry operators - sx,sy,sz and inserts them in the array bGHex. - These values will looked up by the application routines SymmetryWrappers - @enddesc - @calls - @calledby - @history enhanced by E.Schnetter - - @endhistory - + @desc + This routine sets the GH extension (EinsteinBoundGHex *bGHex), + which describes the symmetry boundary type of each GF. Takes + the name of the GF ("implementation::gfname") and the + symmetry operators sx,sy,sz and inserts them in the array bGHex. + These values will looked up by the application routines + SymmetryWrappers + @enddesc + @history + enhanced by E.Schnetter + @endhistory @@*/ - -int SetCartSymVI(cGH *GH, int *sym, int vi) +int SetCartSymVI (const cGH *GH, const int *sym, int vi) { - - DECLARE_CCTK_PARAMETERS - int domainsym[MAX_FACE]; SymmetryGHex *sGHex; int dir; - + DECLARE_CCTK_PARAMETERS + + /* Pointer to the SymmetryGHextension */ - sGHex = (SymmetryGHex *)GH->extensions[CCTK_GHExtensionHandle("Symmetry")]; + sGHex = (SymmetryGHex *) CCTK_GHExtension (GH, "Symmetry"); /* Reference the hash table in the GHex and tell it what kind of - symmetry is being applied - (depending on sym and the grid layout) + symmetry is being applied + (depending on sym and the grid layout) If there is no symmetry necessary,set ESYM_NOSYM - When we apply a symmetry and find ESYM_UNSET, something went wrong! + When we apply a symmetry and find ESYM_UNSET, something went wrong! */ #ifdef SYM_DEBUG printf("SetSymmetry: %s [%d,%d,%d]\n",CCTK_VarName(vi), sym[0],sym[1],sym[2]); #endif - + DecodeSymParameters3D(domainsym); - for (dir=0; dir<MAX_FACE; ++dir) + for (dir=0; dir<MAX_FACE; ++dir) { - if (domainsym[dir] == GFSYM_REFLECTION) + if (domainsym[dir] == GFSYM_REFLECTION) { sGHex->GFSym[vi][dir] = sym[dir/2]; } - else if (domainsym[dir] == GFSYM_ROTATION_X) + else if (domainsym[dir] == GFSYM_ROTATION_X) { sGHex->GFSym[vi][dir] = sym[1]*sym[2]; } - else if (domainsym[dir] == GFSYM_ROTATION_Y) + else if (domainsym[dir] == GFSYM_ROTATION_Y) { sGHex->GFSym[vi][dir] = sym[0]*sym[2]; } - else if (domainsym[dir] == GFSYM_ROTATION_Z) + else if (domainsym[dir] == GFSYM_ROTATION_Z) { sGHex->GFSym[vi][dir] = sym[0]*sym[1]; } - else + else { sGHex->GFSym[vi][dir] = GFSYM_NOSYM; } @@ -114,53 +100,50 @@ int SetCartSymVI(cGH *GH, int *sym, int vi) #ifdef SYM_DEBUG printf("SetSymmetry: %s [%d,%d,%d]\n\n", CCTK_VarName(vi), - sGHex->GFSym[vi][0], - sGHex->GFSym[vi][2], - sGHex->GFSym[vi][4]); + sGHex->GFSym[vi][0], sGHex->GFSym[vi][2], sGHex->GFSym[vi][4]); #endif - return 0; + + return (0); } void CCTK_FCALL CCTK_FNAME(SetCartSymVI) - (int *ierr, cGH *GH, int *sym, int *vi) + (int *ierr, const cGH *GH, const int *sym, const int *vi) { - *ierr = SetCartSymVI(GH, sym, *vi); + *ierr = SetCartSymVI (GH, sym, *vi); } + /*@@ @routine SetCartSymVN @date Thu May 11 13:32:55 2000 @author Gerd Lanfermann - @desc + @desc Applies symmetry boundary conditions from variable index - @enddesc - @calls - @calledby - @history - - @endhistory - + @enddesc @@*/ +int SetCartSymVN(const cGH *GH, const int *sym, const char *vn) +{ + int vi, retval; + -int SetCartSymVN(cGH *GH, int *sym, const char *vn) { - int vi; vi = CCTK_VarIndex(vn); - - if (vi>-1) + if (vi >= 0) { - return(SetCartSymVI(GH, sym, vi)); + retval = SetCartSymVI (GH, sym, vi); } else { CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, - "Cannot find variable %s in SetCartSymVN",vn); - return(-1); + "Unknown variable '%s' in SetCartSymVN", vn); + retval = -1; } + + return (retval); } void CCTK_FCALL CCTK_FNAME(SetCartSymVN) - (int *ierr, cGH *GH, int *sym, ONE_FORTSTRING_ARG) + (int *ierr, const cGH *GH, const int *sym, ONE_FORTSTRING_ARG) { ONE_FORTSTRING_CREATE(vn) *ierr = SetCartSymVN(GH, sym, vn); @@ -168,34 +151,25 @@ void CCTK_FCALL CCTK_FNAME(SetCartSymVN) } - /*@@ @routine SetCartSymGI - @date - @author Gerd Lanfermann - @desc + @date + @author Gerd Lanfermann + @desc Applies symmetry boundary conditions from Group index - @enddesc - @calls - @calledby - @history - - @endhistory - + @enddesc @@*/ - -int SetCartSymGI(cGH *GH, int *sym, int gi) +int SetCartSymGI(const cGH *GH, const int *sym, int gi) { - - DECLARE_CCTK_PARAMETERS - int domainsym[MAX_FACE]; - SymmetryGHex *sGHex; + SymmetryGHex *sGHex; int first_vari,numvars,vi; int dir; - - sGHex = (SymmetryGHex *)GH->extensions[CCTK_GHExtensionHandle("Symmetry")]; + DECLARE_CCTK_PARAMETERS + + + sGHex = (SymmetryGHex *) CCTK_GHExtension (GH, "Symmetry"); first_vari = CCTK_FirstVarIndexI(gi); numvars = CCTK_NumVarsInGroupI(gi); @@ -203,106 +177,100 @@ int SetCartSymGI(cGH *GH, int *sym, int gi) if (first_vari<0) { CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, - "Cannot find group %s (grp.index: %d) in SetCartSymGI", - CCTK_GroupName(gi),first_vari); + "Cannot find group %s (grp.index: %d) in SetCartSymGI", + CCTK_GroupName(gi),first_vari); return(-1); } /* Reference the hash table in the GHex and tell it what kind of - symmetry is being applied - (depending on sym and the grid layout) + symmetry is being applied + (depending on sym and the grid layout) If there is no symmetry necessary,set ESYM_NOSYM - When we apply a symmetry and find ESYM_UNSET, something went wrong! + When we apply a symmetry and find ESYM_UNSET, something went wrong! */ - for (vi=first_vari; vi<first_vari+numvars; vi++) + for (vi=first_vari; vi<first_vari+numvars; vi++) { #ifdef SYM_DEBUG - printf("SetSymmetry: %s [%d,%d,%d]\n",CCTK_VarName(vi), - sym[0],sym[1],sym[2]); + printf("SetSymmetry: %s [%d,%d,%d]\n",CCTK_VarName(vi), + sym[0],sym[1],sym[2]); #endif - + DecodeSymParameters3D (domainsym); - for (dir=0; dir<MAX_FACE; dir++) + for (dir=0; dir<MAX_FACE; dir++) { - if (domainsym[dir] == GFSYM_REFLECTION) + if (domainsym[dir] == GFSYM_REFLECTION) { - sGHex->GFSym[vi][dir] = sym[dir/2]; + sGHex->GFSym[vi][dir] = sym[dir/2]; } - else if (domainsym[dir] == GFSYM_ROTATION_X) + else if (domainsym[dir] == GFSYM_ROTATION_X) { - sGHex->GFSym[vi][dir] = sym[1]*sym[2]; + sGHex->GFSym[vi][dir] = sym[1]*sym[2]; } - else if (domainsym[dir] == GFSYM_ROTATION_Y) + else if (domainsym[dir] == GFSYM_ROTATION_Y) { - sGHex->GFSym[vi][dir] = sym[0]*sym[2]; + sGHex->GFSym[vi][dir] = sym[0]*sym[2]; } - else if (domainsym[dir] == GFSYM_ROTATION_Z) + else if (domainsym[dir] == GFSYM_ROTATION_Z) { - sGHex->GFSym[vi][dir] = sym[0]*sym[1]; + sGHex->GFSym[vi][dir] = sym[0]*sym[1]; } - else + else { - sGHex->GFSym[vi][dir] = GFSYM_NOSYM; + sGHex->GFSym[vi][dir] = GFSYM_NOSYM; } } #ifdef SYM_DEBUG - printf("SetSymmetry: %s [%d,%d,%d]\n\n", CCTK_VarName(vi), - sGHex->GFSym[vi][0], - sGHex->GFSym[vi][2], - sGHex->GFSym[vi][4]); + printf("SetSymmetry: %s [%d,%d,%d]\n\n", CCTK_VarName(vi), + sGHex->GFSym[vi][0], + sGHex->GFSym[vi][2], + sGHex->GFSym[vi][4]); #endif } return(0); } void CCTK_FCALL CCTK_FNAME(SetCartSymGI) - (int *ierr, cGH *GH, int *sym, int *gi) + (int *ierr, const cGH *GH, const int *sym, const int *gi) { *ierr = SetCartSymGI(GH, sym, *gi); } - /*@@ - @routine - @date - @author - @desc + @routine + @date + @author + @desc Applies symmetry boundary conditions from "Implementation::Groupname" - @enddesc - @calls - @calledby - @history - - @endhistory - + @enddesc @@*/ - -int SetCartSymGN(cGH *GH, int *sym, const char *gn) +int SetCartSymGN(const cGH *GH, const int *sym, const char *gn) { - int gi = CCTK_GroupIndex(gn); - - if (gi>-1) + int gi, retval; + + + gi = CCTK_GroupIndex(gn); + if (gi >= 0) { - return(SetCartSymGI(GH, sym, gi)); + retval = SetCartSymGI (GH, sym, gi); } else { CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, - "Cannot find group %s in SetCartSymGN",gn); - return(-1); + "Unknown group '%s' in SetCartSymGN", gn); + retval = -1; } + + return (retval); } void CCTK_FCALL CCTK_FNAME(SetCartSymGN) - (int *ierr, cGH *GH, int *sym, ONE_FORTSTRING_ARG) + (int *ierr, const cGH *GH, const int *sym, ONE_FORTSTRING_ARG) { ONE_FORTSTRING_CREATE(gn) *ierr = SetCartSymGN(GH, sym, gn); free(gn); } - - diff --git a/src/Startup.c b/src/Startup.c index c094bb1..6ec32df 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -2,106 +2,137 @@ @file Startup.c @date Mon Mar 15 15:48:42 1999 @author Gerd Lanfermann - @desc - Startup file to register the GHextension and coordinates - @enddesc + @desc + Startup file to register the GHextension and coordinates + @enddesc + @version $Id$ @@*/ +#include <stdlib.h> + #include "cctk.h" +#include "Symmetry.h" +/* the rcs ID and its dummy function to use it */ static const char *rcsid = "$Header$"; - CCTK_FILEVERSION(CactusBase_CartGrid3D_Startup_c) -void *Symmetry_AllocGHex(tFleshConfig *config, int convlevel, cGH *GH); -int Symmetry_InitGHex(cGH *GH); -int SymmetryStartup(void); -int RegisterCartGrid3DCoords(void); + +/******************************************************************** + ******************** External Routines ************************ + ********************************************************************/ +void SymmetryStartup (void); +int RegisterCartGrid3DCoords (void); + + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static void *SetupGH (tFleshConfig *config, int convlevel, cGH *GH); + /*@@ @routine SymmetryStartup @date Mon Mar 15 15:49:16 1999 @author Gerd Lanfermann - @desc - Routine registers the Setup and Initialation routines for the - GHExtension, which holds the symmetry BCs. We name the - GHextension "Symmetry" and get an integer ("handle") - identifying the GHex. - @enddesc - @calls - @calledby - @history - - @endhistory - + @desc + Routine registers the GH extension for CartGrid3D + along with its setup routine. + @enddesc + @calls CCTK_RegisterGHExtension + CCTK_RegisterGHExtensionSetupGH @@*/ - -/* Store the handle in a global variable for the moment. */ -int Symmetry_handle; - - -int SymmetryStartup(void) +void SymmetryStartup (void) { - Symmetry_handle = CCTK_RegisterGHExtension("Symmetry"); - - /* Register the allocation and init routine */ - CCTK_RegisterGHExtensionSetupGH(Symmetry_handle,Symmetry_AllocGHex); - CCTK_RegisterGHExtensionInitGH(Symmetry_handle,Symmetry_InitGHex); - - return 0; + CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("Symmetry"), + SetupGH); } /*@@ @routine RegisterCartGrid3DCoords - @date + @date @author Gabrielle Allen - @desc - Routine registers the coordinates provided by CartGrid3D - @enddesc - @calls - @calledby - @history - - @endhistory - + @desc + Routine registers the coordinates provided by CartGrid3D + @enddesc + @calls CCTK_CoordRegisterSystem + CCTK_CoordRegisterData + + @returntype int + @returndesc + 0 for success, or negative in case of errors + @endreturndesc @@*/ - -int RegisterCartGrid3DCoords(void) +int RegisterCartGrid3DCoords (void) { + int nerrors; - int ierr; - int nerrors=0; - ierr=CCTK_CoordRegisterSystem(3,"cart3d"); - ierr=CCTK_CoordRegisterSystem(3,"spher3d"); + nerrors = 0; + CCTK_CoordRegisterSystem (3, "cart3d"); + CCTK_CoordRegisterSystem (3, "spher3d"); - ierr=CCTK_CoordRegisterData(1,"grid::x","x","cart3d"); - if (ierr<0) + if (CCTK_CoordRegisterData (1, "grid::x", "x", "cart3d") < 0) { - CCTK_WARN(1,"Problem with registering coordinate x"); + CCTK_WARN (1, "Problem with registering coordinate x"); nerrors--; } - ierr=CCTK_CoordRegisterData(2,"grid::y","y","cart3d"); - if (ierr<0) + if (CCTK_CoordRegisterData (2, "grid::y", "y", "cart3d") < 0) { - CCTK_WARN(1,"Problem with registering coordinate y"); + CCTK_WARN (1, "Problem with registering coordinate y"); nerrors--; } - ierr=CCTK_CoordRegisterData(3,"grid::z","z","cart3d"); - if (ierr<0) + if (CCTK_CoordRegisterData (3, "grid::z", "z", "cart3d") < 0) { - CCTK_WARN(1,"Problem with registering coordinate z"); + CCTK_WARN (1, "Problem with registering coordinate z"); nerrors--; } - ierr=CCTK_CoordRegisterData(1,"grid::r","r","spher3d"); - if (ierr<0) + if (CCTK_CoordRegisterData (1, "grid::r", "r", "spher3d") < 0) { - CCTK_WARN(1,"Problem with registering coordinate r"); + CCTK_WARN (1, "Problem with registering coordinate r"); nerrors--; } - return nerrors; + return (nerrors); } +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static void *SetupGH (tFleshConfig *config, int convlevel, cGH *GH) +{ + int i, j, maxdim, numvars; + SymmetryGHex *myGH; + + + /* avoid compiler warnings about unused arguments */ + (void) (config + 0); + (void) (convlevel + 0); + (void) (GH + 0); + + maxdim = CCTK_MaxDim (); + numvars = CCTK_NumVars (); + + /* allocate the GH extension */ + myGH = (SymmetryGHex *) malloc (sizeof (SymmetryGHex)); + if (myGH) + { + /* allocation for the number of grid functions */ + myGH->GFSym = (int **) malloc (numvars * sizeof (int *)); + + /* allocation for the number of dimensions*/ + for (i = 0; i < numvars; i++) + { + myGH->GFSym[i] = (int *) malloc (2 * maxdim * sizeof (int)); + + for (j = 0; j < 2 * maxdim; j++) + { + myGH->GFSym[i][j] = GFSYM_UNSET; /* not set */ + } + } + } + + return (myGH); +} diff --git a/src/Symmetry.c b/src/Symmetry.c index f245600..387573b 100644 --- a/src/Symmetry.c +++ b/src/Symmetry.c @@ -1,375 +1,668 @@ - /*@@ - @file Symmetry.c - @date Tue Apr 18 14:14:16 2000 + @file SymmetryWrappers.c + @date April 2000 @author Gerd Lanfermann @desc - Routines to apply the 1/2/3D Symmetries for - all symmetry domains (octant/bitant/quadrant). + Routines to apply the 1/2/3D Symmetries for + all symmetry domains (octant/bitant/quadrant). @enddesc + @history + @hdate Sat 02 Nov 2002 + @hauthor Thomas Radke + @hdesc routines generalized for applying to arbitrary CCTK data types + @endhistory + @version $Id$ @@*/ -#include <stdio.h> -#include <assert.h> #include <stdlib.h> -#include <string.h> #include "cctk.h" +#include "cctk_Parameters.h" +#include "cctk_FortranString.h" #include "Symmetry.h" +/* the rcs ID and its dummy function to use it */ static const char *rcsid = "$Header$"; - CCTK_FILEVERSION(CactusBase_CartGrid3D_Symmetry_c) -/*#define SYM_DEBUG*/ -int CartApplySym3Di(cGH *GH, int *doSym, int *cntstag, - int *lssh, int *ghostz, int *sym, CCTK_REAL *var); -int CartApplySym2Di(cGH *GH, int *doSym, int *cntstag, - int *lssh, int *ghostz, int *sym, CCTK_REAL *var); -int CartApplySym1Di(cGH *GH, int *doSym, int *cntstag, - int *lssh, int *ghostz, int *sym, CCTK_REAL *var); +/******************************************************************** + ********************* Local Routine Prototypes ********************* + ********************************************************************/ +static int ApplySymmetry (const cGH *GH, int gindex, int first_vindex, + int numvars); -/*@@ - @routine CartApplySym3Di - @date Tue Apr 18 14:17:23 2000 - @author Gerd Lanfermann - @desc Apply Symmetry BC to 3D variables - - Variables passed through: - cGH *GH pointer to cGH - int *doSym flags whether to apply a symmetries on a given face - size 2*dim, here we only check for lower faces:0,2,4 - int *cntstag value used when the gridpoints are staggered - around the origin - int *lssh size of the domain, - int *ghostz size of the ghostzone - int *sym symmetry values - CCTK_REAL *var pointer to variable - - index convention: - i ~ x ~ 0 - j ~ y ~ 1 - k ~ z ~ 2 - - @enddesc - @calls - @calledby - @history - - @endhistory +/******************************************************************** + ******************* Fortran Wrapper Prototypes ********************* + ********************************************************************/ +void CCTK_FCALL CCTK_FNAME (CartSymGI) (int *ierr, const cGH *GH, int *gindex); +void CCTK_FCALL CCTK_FNAME (CartSymGN) + (int *ierr, const cGH *GH, ONE_FORTSTRING_ARG); +void CCTK_FCALL CCTK_FNAME (CartSymVI) (int *ierr, const cGH *GH, int *vindex); +void CCTK_FCALL CCTK_FNAME (CartSymVN) + (int *ierr, const cGH *GH, ONE_FORTSTRING_ARG); -@@*/ +/******************************************************************** + ****************** External Routine Prototypes ********************* + ********************************************************************/ +void DecodeSymParameters3D (int sym[6]); -int CartApplySym3Di(cGH *GH, int *doSym, int *cntstag, - int *lssh, int *ghostz, int *sym, CCTK_REAL *var) -{ - int i, j, k; - -#ifdef SYM_DEBUG - printf(" doSym: %d %d / %d %d / %d %d \n", - doSym[0],doSym[1], - doSym[2],doSym[3], - doSym[4],doSym[5]); - printf(" lssh: %d %d %d sym: %d %d %d \n", - lssh[0],lssh[1],lssh[2], sym[0], sym[2], sym[4] ); - printf(" ghostz %d %d %d \n",ghostz[0],ghostz[1],ghostz[2]); - printf(" cntstag: %d %d %d\n",cntstag[0],cntstag[1],cntstag[2]); -#endif +/*@@ + @routine CartSymGI + @date April 2000 + @author Gerd Lanfermann + @desc + Apply symmetry boundary routines by group index + @enddesc + @calls ApplySymmetry + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var gindex + @vdesc index of group to apply symmetry BC + @vtype int + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine ApplySymmetry <BR> + -1 if invalid group index was given + @endreturndesc +@@*/ +int CartSymGI (const cGH *GH, int gindex) +{ + int numvars, first_vindex, retval; - /* - * Apply symmetry to the lower x face. - */ - if (doSym[0] == GFSYM_REFLECTION) - { - for(k=0; k < lssh[2]; k++) - { - for(j=0; j < lssh[1]; j++) - { - for(i=0; i < ghostz[0]; i++) - { - var[CCTK_GFINDEX3D(GH,i,j,k)] = sym[0] * - var[CCTK_GFINDEX3D(GH, 2*ghostz[0]-cntstag[0]-i, j, k)]; - } - } - } - } - else if (doSym[0] == GFSYM_ROTATION_Y) + + numvars = CCTK_NumVarsInGroupI (gindex); + first_vindex = CCTK_FirstVarIndexI (gindex); + if (numvars > 0 && first_vindex >= 0) { - /* - * FIXME: The following loop is local, but global indices are - * FIXME: needed for this to work on multiple processors. - */ - for(k=0; k < lssh[2]; k++) - { - for(j=0; j < lssh[1]; j++) - { - for(i=0; i < ghostz[0]; i++) - { - var[CCTK_GFINDEX3D(GH,i,j,k)] = sym[0] * - var[CCTK_GFINDEX3D(GH, 2*ghostz[0]-cntstag[0]-i, j, lssh[2]-k-1)]; - } - } - } + retval = ApplySymmetry (GH, gindex, first_vindex, numvars); } - else if (doSym[0] == GFSYM_ROTATION_Z) + else { - /* - * FIXME: The following loop is local, but global indices are - * FIXME: needed for this to work on multiple processors. - */ - for(k=0; k < lssh[2]; k++) - { - for(j=0; j < lssh[1]; j++) - { - for(i=0; i < ghostz[0]; i++) - { - var[CCTK_GFINDEX3D(GH,i,j,k)] = sym[0] * - var[CCTK_GFINDEX3D(GH, 2*ghostz[0]-cntstag[0]-i, lssh[1]-j-1, k)]; - } - } - } + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid group index %d in CartSymGI", gindex); + retval = -1; } - /* - * Apply symmetry to the lower y face. - */ - if (doSym[2] == GFSYM_REFLECTION) - { - for(i=0; i < lssh[0]; i++) - { - for(k=0; k < lssh[2]; k++) - { - for(j=0; j < ghostz[1]; j++) - { - var[CCTK_GFINDEX3D(GH,i,j,k)] = sym[2] * - var[CCTK_GFINDEX3D(GH, i, 2*ghostz[1]-cntstag[1]-j, k)]; - } - } - } - } - else if (doSym[2] == GFSYM_ROTATION_X) + return (retval); +} + +void CCTK_FCALL CCTK_FNAME (CartSymGI) (int *ierr, const cGH *GH, int *gindex) +{ + *ierr = CartSymGI (GH, *gindex); +} + + +/*@@ + @routine CartSymGN + @date April 2000 + @author Gerd Lanfermann + @desc + Apply symmetry boundary routines by group name + @enddesc + @calls ApplySymmetry + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var gname + @vdesc name of group to apply symmetry BC + @vtype const char * + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine ApplySymmetry <BR> + -1 if invalid group name was given + @endreturndesc +@@*/ +int CartSymGN (const cGH *GH, const char *gname) +{ + int gindex, retval; + + + gindex = CCTK_GroupIndex (gname); + if (gindex >= 0) { - /* - * FIXME: The following loop is local, but global indices are - * FIXME: needed for this to work on multiple processors. - */ - for(i=0; i < lssh[0]; i++) - { - for(k=0; k < lssh[2]; k++) - { - for(j=0; j < ghostz[1]; j++) - { - var[CCTK_GFINDEX3D(GH,i,j,k)] = sym[2] * - var[CCTK_GFINDEX3D(GH, i, 2*ghostz[1]-cntstag[1]-j, lssh[2]-k-1)]; - } - } - } + retval = CartSymGI (GH, gindex); } - else if (doSym[2] == GFSYM_ROTATION_Z) + else { - /* - * FIXME: The following loop is local, but global indices are - * FIXME: needed for this to work on multiple processors. - */ - for(i=0; i < lssh[0]; i++) - { - for(k=0; k < lssh[2]; k++) - { - for(j=0; j < ghostz[1]; j++) - { - var[CCTK_GFINDEX3D(GH,i,j,k)] = sym[2] * - var[CCTK_GFINDEX3D(GH, lssh[0]-i-1, 2*ghostz[1]-cntstag[1]-j, k)]; - } - } - } + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid group name '%s' in CartSymGN", gname); + retval = -1; } - /* - * Apply symmetry to the lower z face. - */ - if (doSym[4] == GFSYM_REFLECTION) + return (retval); +} + +void CCTK_FCALL CCTK_FNAME (CartSymGN) + (int *ierr, const cGH *GH, ONE_FORTSTRING_ARG) +{ + ONE_FORTSTRING_CREATE (gname) + *ierr = CartSymGN (GH, gname); + free (gname); +} + + +/*@@ + @routine CartSymVI + @date April 2000 + @author Gerd Lanfermann + @desc + Apply symmetry boundary routines by variable index + @enddesc + @calls ApplySymmetry + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var gindex + @vdesc index of variable to apply symmetry BC + @vtype int + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine ApplySymmetry <BR> + -1 if invalid variable index was given + @endreturndesc +@@*/ +int CartSymVI (const cGH *GH, int vindex) +{ + int retval, gindex; + + + gindex = CCTK_GroupIndexFromVarI (vindex); + if (gindex >= 0) { - for(i=0; i < lssh[0]; i++) - { - for(j=0; j < lssh[1]; j++) - { - for(k=0; k < ghostz[2]; k++) - { - var[CCTK_GFINDEX3D(GH,i,j,k)] = sym[4] * - var[CCTK_GFINDEX3D(GH, i, j, 2*ghostz[2]-cntstag[2]-k)]; - } - } - } + retval = ApplySymmetry (GH, gindex, vindex, 1); } - else if (doSym[4] == GFSYM_ROTATION_X) + else { - /* - * FIXME: The following loop is local, but global indices are - * FIXME: needed for this to work on multiple processors. - */ - for(i=0; i < lssh[0]; i++) - { - for(j=0; j < lssh[1]; j++) - { - for(k=0; k < ghostz[2]; k++) - { - var[CCTK_GFINDEX3D(GH,i,j,k)] = sym[4] * - var[CCTK_GFINDEX3D(GH, i, lssh[1]-j-1, 2*ghostz[2]-cntstag[2]-k)]; - } - } - } - } - else if (doSym[4] == GFSYM_ROTATION_Y) - { - /* - * FIXME: The following loop is local, but global indices are - * FIXME: needed for this to work on multiple processors. - */ - for(i=0; i < lssh[0]; i++) - { - for(j=0; j < lssh[1]; j++) - { - for(k=0; k < ghostz[2]; k++) - { - var[CCTK_GFINDEX3D(GH,i,j,k)] = sym[4] * - var[CCTK_GFINDEX3D(GH, lssh[0]-i-1, j, 2*ghostz[2]-cntstag[2]-k)]; - } - } - } + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid variable index %d in CartSymVI", vindex); + retval = -1; } - return(0); + return (retval); +} + +void CCTK_FCALL CCTK_FNAME (CartSymVI) (int *ierr, const cGH *GH, int *vindex) +{ + *ierr = CartSymVI (GH, *vindex); } /*@@ - @routine CartApplySym2Di - @date Tue Apr 18 14:17:23 2000 + @routine CartSymVN + @date April 2000 @author Gerd Lanfermann - @desc Apply Symmetry BC to 2D variables + @desc + Apply symmetry boundary routines by variable name + @enddesc + @calls ApplySymmetry + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var gname + @vdesc name of variable to apply symmetry BC + @vtype const char * + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine ApplySymmetry <BR> + -1 if invalid variable name was given + @endreturndesc +@@*/ +int CartSymVN (const cGH *GH, const char *vname) +{ + int vindex, retval; - index convention: - i ~ x ~ 0 - j ~ y ~ 1 - k ~ z ~ 2 - - @enddesc - @calls - @calledby - @history - - @endhistory + vindex = CCTK_VarIndex (vname); + if (vindex >= 0) + { + retval = CartSymVI (GH, vindex); + } + else + { + CCTK_VWarn (1,__LINE__,__FILE__,CCTK_THORNSTRING, + "Invalid variable name '%s' in CartSymVN", vname); + retval = -1; + } -@@*/ - -int CartApplySym2Di(cGH *GH, int *doSym, int *cntstag, - int *lssh, int *ghostz, int *sym, CCTK_REAL *var) + return (retval); +} + +void CCTK_FCALL CCTK_FNAME (CartSymVN) + (int *ierr, const cGH *GH, ONE_FORTSTRING_ARG) { - int i, j; + ONE_FORTSTRING_CREATE (vname) + *ierr = CartSymVN (GH, vname); + free (vname); +} + + +/******************************************************************** + ********************* Local Routines ************************* + ********************************************************************/ +/* 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 SYMMETRY_BOUNDARY + @date Sat 02 Nov 2002 + @author Thomas Radke + @desc + Macro to apply symmetry boundary conditions to a variable + of given datatype + Currently it is limited up to 3D variables only. + @enddesc + + @var cctk_type + @vdesc CCTK datatype of the variable + @vtype <cctk_type> + @vio in + @endvar +@@*/ +#define SYMMETRY_BOUNDARY(cctk_type) \ +{ \ + cctk_type *_var = (cctk_type *) GH->data[vindex][0]; \ + \ + \ + /* apply symmetry to the lower x face */ \ + if (doSym[0] == GFSYM_REFLECTION) \ + { \ + for (k = 0; k < lssh[2]; k++) \ + { \ + for (j = 0; j < lssh[1]; j++) \ + { \ + for (i = 0; i < group_dynamic_data.nghostzones[0]; i++) \ + { \ + _var[INDEX_3D (lsh, i, j, k)] NUMBER_PART = GFSym[vindex][0] * \ + _var[INDEX_3D (lsh, offset[0]-i, j, k)] NUMBER_PART; \ + } \ + } \ + } \ + } \ + else if (group_static_data.dim > 1) \ + { \ + if (doSym[0] == GFSYM_ROTATION_Z) \ + { \ + for (k = 0; k < lssh[2]; k++) \ + { \ + for (j = 0; j < lssh[1]; j++) \ + { \ + for (i = 0; i < group_dynamic_data.nghostzones[0]; i++) \ + { \ + _var[INDEX_3D (lsh, i, j, k)] NUMBER_PART = GFSym[vindex][0] * \ + _var[INDEX_3D (lsh, offset[0]-i, lssh[1]-j-1, k)] NUMBER_PART; \ + } \ + } \ + } \ + } \ + else if (group_static_data.dim > 2 && doSym[0] == GFSYM_ROTATION_Y) \ + { \ + for (k = 0; k < lssh[2]; k++) \ + { \ + for (j = 0; j < lssh[1]; j++) \ + { \ + for (i = 0; i < group_dynamic_data.nghostzones[0]; i++) \ + { \ + _var[INDEX_3D (lsh, i, j, k)] NUMBER_PART = GFSym[vindex][0] * \ + _var[INDEX_3D (lsh, offset[0]-i, j, lssh[2]-k-1)] NUMBER_PART; \ + } \ + } \ + } \ + } \ + } \ + \ + if (group_static_data.dim == 1) \ + { \ + break; \ + } \ + \ + /* apply symmetry to the lower y face */ \ + if (doSym[2] == GFSYM_REFLECTION) \ + { \ + for (i = 0; i < lssh[0]; i++) \ + { \ + for (k = 0; k < lssh[2]; k++) \ + { \ + for (j = 0; j < group_dynamic_data.nghostzones[1]; j++) \ + { \ + _var[INDEX_3D (lsh, i, j, k)] NUMBER_PART = GFSym[vindex][2] * \ + _var[INDEX_3D (lsh, i, offset[1]-j, k)] NUMBER_PART; \ + } \ + } \ + } \ + } \ + else if (doSym[2] == GFSYM_ROTATION_Z) \ + { \ + for (i = 0; i < lssh[0]; i++) \ + { \ + for (k = 0; k < lssh[2]; k++) \ + { \ + for (j = 0; j < group_dynamic_data.nghostzones[1]; j++) \ + { \ + _var[INDEX_3D (lsh, i, j, k)] NUMBER_PART = GFSym[vindex][2] * \ + _var[INDEX_3D (lsh, lssh[0]-i-1, offset[1]-j, k)] NUMBER_PART; \ + } \ + } \ + } \ + } \ + else if (group_static_data.dim > 2 && doSym[2] == GFSYM_ROTATION_X) \ + { \ + for (i = 0; i < lssh[0]; i++) \ + { \ + for (k = 0; k < lssh[2]; k++) \ + { \ + for (j = 0; j < group_dynamic_data.nghostzones[1]; j++) \ + { \ + _var[INDEX_3D (lsh, i, j, k)] NUMBER_PART = GFSym[vindex][2] * \ + _var[INDEX_3D (lsh, i, offset[1]-j, lssh[2]-k-1)] NUMBER_PART; \ + } \ + } \ + } \ + } \ + \ + if (group_static_data.dim == 2) \ + { \ + break; \ + } \ + \ + /* apply symmetry to the lower z face */ \ + if (doSym[4] == GFSYM_REFLECTION) \ + { \ + for (i = 0; i < lssh[0]; i++) \ + { \ + for (j = 0; j < lssh[1]; j++) \ + { \ + for (k = 0; k < group_dynamic_data.nghostzones[2]; k++) \ + { \ + _var[INDEX_3D (lsh, i, j, k)] NUMBER_PART = GFSym[vindex][4] * \ + _var[INDEX_3D (lsh, i, j, offset[2]-k)] NUMBER_PART; \ + } \ + } \ + } \ + } \ + else if (doSym[4] == GFSYM_ROTATION_X) \ + { \ + for (i = 0; i < lssh[0]; i++) \ + { \ + for (j = 0; j < lssh[1]; j++) \ + { \ + for (k = 0; k < group_dynamic_data.nghostzones[2]; k++) \ + { \ + _var[INDEX_3D (lsh, i, j, k)] NUMBER_PART = GFSym[vindex][4] * \ + _var[INDEX_3D (lsh, i, lssh[1]-j-1, offset[2]-k)] NUMBER_PART; \ + } \ + } \ + } \ + } \ + else if (doSym[4] == GFSYM_ROTATION_Y) \ + { \ + for (i = 0; i < lssh[0]; i++) \ + { \ + for (j = 0; j < lssh[1]; j++) \ + { \ + for (k = 0; k < group_dynamic_data.nghostzones[2]; k++) \ + { \ + _var[INDEX_3D (lsh, i, j, k)] NUMBER_PART = GFSym[vindex][4] * \ + _var[INDEX_3D (lsh, lssh[0]-i-1, j, offset[2]-k)] NUMBER_PART; \ + } \ + } \ + } \ + } \ +} - if (doSym[0] == GFSYM_REFLECTION) + +/*@@ + @routine ApplySymmetry + @date Thu Mar 2 11:02:10 2000 + @author Gerd Lanfermann + @desc + Apply symmetry boundary conditions to a group of grid variables + This routine is called by the various CartSymXXX wrappers. + @enddesc + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var gindex + @vdesc group index of the variables to apply symmetry BCs + @vtype int + @vio in + @endvar + @var first_var + @vdesc index of first variable to apply symmetry BCs + @vtype int + @vio in + @endvar + @var num_vars + @vdesc number of variables + @vtype int + @vio in + @endvar + + @calls CCTK_GroupData + CCTK_GroupDynamicData + CCTK_StaggerDirArray + SYMMETRY_BOUNDARY + @history + @hdate Sat 02 Nov 2002 + @hauthor Thomas Radke + @hdesc Merged separate routines for 1D, 2D, and 3D + into a single generic routine + @endhistory + + @returntype int + @returndesc + 0 for success, or<BR> + -1 if group dimension is not supported<BR> + -2 if group datatype is not supported + @endreturndesc +@@*/ +static int ApplySymmetry (const cGH *GH, int gindex, int first_vindex, + int numvars) +{ + int i, j, k, dim, vindex, retval; + int **GFSym; + int domainsym[MAX_FACE], doSym[MAX_FACE]; + int dstag[MAX_DIM], lsh[MAX_DIM], lssh[MAX_DIM], + cntstag[MAX_DIM], offset[MAX_DIM]; + cGroup group_static_data; + cGroupDynamicData group_dynamic_data; + DECLARE_CCTK_PARAMETERS + + + /* get out if we are sure no symmetries should be applied */ + /* FIXME: There has to be a better way early bailout! */ + if (CCTK_Equals (domain, "full")) { - for(j=0; j < lssh[1]; j++) - { - for(i=0; i < ghostz[0]; i++) - { - var[CCTK_GFINDEX2D(GH,i,j)] = sym[0] * - var[CCTK_GFINDEX2D(GH, 2*ghostz[0]-cntstag[0]-i, j)]; - } - } + return (0); } - else if (doSym[0] == GFSYM_ROTATION_Z) + + /* get the group's static and dynamic data structure */ + CCTK_GroupData (gindex, &group_static_data); + CCTK_GroupDynamicData (GH, gindex, &group_dynamic_data); + if (group_static_data.dim <= 0 || group_static_data.dim > MAX_DIM) { - /* - * FIXME: The following loop is local, but global indices are - * FIXME: needed for this to work on multiple processors. - */ - for(j=0; j < lssh[1]; j++) - { - for(i=0; i < ghostz[0]; i++) - { - var[CCTK_GFINDEX2D(GH,i,j)] = sym[0] * - var[CCTK_GFINDEX2D(GH, 2*ghostz[0]-cntstag[0]-i, lssh[1]-j-1)]; - } - } + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "ApplySymmetry: group dimension must 1, 2, or 3"); + return (-1); } + + /* Avoid origin? Default is yes */ + cntstag[0] = no_origin && no_originx && avoid_origin && avoid_originx; + cntstag[1] = no_origin && no_originy && avoid_origin && avoid_originy; + cntstag[2] = no_origin && no_originz && avoid_origin && avoid_originz; + + /* get the directional staggering of the group */ + CCTK_StaggerDirArray (dstag, group_static_data.dim, + group_static_data.stagtype); - if (doSym[2] == GFSYM_REFLECTION) + /* initialize array for variables with less dimensions than MAX_DIM + so that we can use the INDEX_3D macro later on */ + for (i = 0; i < MAX_DIM; i++) { - for(i=0; i < lssh[0]; i++) + if (i < group_static_data.dim) { - for(j=0; j < ghostz[1]; j++) - { - var[CCTK_GFINDEX2D(GH,i,j)] = sym[2] * - var[CCTK_GFINDEX2D(GH, i, 2*ghostz[1]-cntstag[1]-j)]; - } + lsh[i] = group_dynamic_data.lsh[i]; + lssh[i] = GH->cctk_lssh[CCTK_LSSH_IDX (dstag[i], i)]; } + else + { + lsh[i] = lssh[i] = 1; + } + offset[i] = 2*group_dynamic_data.nghostzones[i] - cntstag[i]; } - else if (doSym[2] == GFSYM_ROTATION_Z) + + DecodeSymParameters3D (domainsym); + + GFSym = ((SymmetryGHex *) CCTK_GHExtension (GH, "Symmetry"))->GFSym; + + /* Apply Symmetries to lower sides [0,2,4] if: + + if the Symmetry is activated (== NOT NOSYM) + + if the Symmetry is set (== NOT UNSET) + + if the length in the direction is more than 1 grid point + + if the processor has a lower physical boundary. + Whether a grid allows a symmetry along a direction (e.g. octant=all) + is part if the Symmetry Setup process. + + No Symmetries for "upper" sides : [1,3,5] + */ + retval = 0; + for (vindex = first_vindex; vindex < first_vindex + numvars; vindex++) { - /* - * FIXME: The following loop is local, but global indices are - * FIXME: needed for this to work on multiple processors. - */ - for(i=0; i < lssh[0]; i++) + for (dim = 0; dim < group_static_data.dim; dim++) { - for(j=0; j < ghostz[1]; j++) + if (GFSym[vindex][2*dim] == GFSYM_UNSET) { - var[CCTK_GFINDEX2D(GH,i,j)] = sym[2] * - var[CCTK_GFINDEX2D(GH, lssh[0]-i-1, 2*ghostz[1]-cntstag[1]-j)]; + CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Symmetries unspecified for '%s'", CCTK_VarName (vindex)); } - } - } - - return(0); -} + doSym[2*dim] = (GFSym[vindex][2*dim] != GFSYM_NOSYM && + GFSym[vindex][2*dim] != GFSYM_UNSET && + lssh[dim] > 1 && GH->cctk_bbox[2*dim]) ? + domainsym[2*dim+0] : 0; + } -/*@@ - @routine CartApplySym1Di - @date Tue Apr 18 14:17:23 2000 - @author Gerd Lanfermann - @desc Apply Symmetry BC to 1D variables +#define NUMBER_PART + switch (group_static_data.vartype) + { + case CCTK_VARIABLE_CHAR: + SYMMETRY_BOUNDARY (CCTK_CHAR); break; + + case CCTK_VARIABLE_INT: + SYMMETRY_BOUNDARY (CCTK_INT); break; + + case CCTK_VARIABLE_REAL: + SYMMETRY_BOUNDARY (CCTK_REAL); break; + + case CCTK_VARIABLE_COMPLEX: +#undef NUMBER_PART +#define NUMBER_PART .Re + SYMMETRY_BOUNDARY (CCTK_COMPLEX); +#undef NUMBER_PART +#define NUMBER_PART .Im + SYMMETRY_BOUNDARY (CCTK_COMPLEX); break; +#undef NUMBER_PART +#define NUMBER_PART + +#ifdef CCTK_INT2 + case CCTK_VARIABLE_INT2: + SYMMETRY_BOUNDARY (CCTK_INT2); break; +#endif - index convention: - i ~ x ~ 0 - j ~ y ~ 1 - k ~ z ~ 2 - - @enddesc - @calls - @calledby - @history - - @endhistory +#ifdef CCTK_INT4 + case CCTK_VARIABLE_INT4: + SYMMETRY_BOUNDARY (CCTK_INT4); break; +#endif -@@*/ +#ifdef CCTK_INT8 + case CCTK_VARIABLE_INT8: + SYMMETRY_BOUNDARY (CCTK_INT8); break; +#endif -int CartApplySym1Di(cGH *GH, int *doSym, int *cntstag, - int *lssh, int *ghostz, int *sym, CCTK_REAL *var) -{ - int i; +#ifdef CCTK_REAL4 + case CCTK_VARIABLE_REAL4: + SYMMETRY_BOUNDARY (CCTK_REAL4); break; + + case CCTK_VARIABLE_COMPLEX8: +#undef NUMBER_PART +#define NUMBER_PART .Re + SYMMETRY_BOUNDARY (CCTK_COMPLEX8); +#undef NUMBER_PART +#define NUMBER_PART .Im + SYMMETRY_BOUNDARY (CCTK_COMPLEX8); break; +#undef NUMBER_PART +#define NUMBER_PART +#endif +#ifdef CCTK_REAL8 + case CCTK_VARIABLE_REAL8: + SYMMETRY_BOUNDARY (CCTK_REAL8); break; + + case CCTK_VARIABLE_COMPLEX16: +#undef NUMBER_PART +#define NUMBER_PART .Re + SYMMETRY_BOUNDARY (CCTK_COMPLEX16); +#undef NUMBER_PART +#define NUMBER_PART .Im + SYMMETRY_BOUNDARY (CCTK_COMPLEX16); break; +#undef NUMBER_PART +#define NUMBER_PART +#endif - /* avoid compiler warnings about unused parameters */ - GH = GH; - lssh = lssh; +#ifdef CCTK_REAL16 + case CCTK_VARIABLE_REAL16: + SYMMETRY_BOUNDARY (CCTK_REAL16); break; + + case CCTK_VARIABLE_COMPLEX32: +#undef NUMBER_PART +#define NUMBER_PART .Re + SYMMETRY_BOUNDARY (CCTK_COMPLEX32); +#undef NUMBER_PART +#define NUMBER_PART .Im + SYMMETRY_BOUNDARY (CCTK_COMPLEX32); break; +#undef NUMBER_PART +#endif - if (doSym[0] == GFSYM_REFLECTION) - { - for(i=0; i < ghostz[0]; i++) - { - var[CCTK_GFINDEX1D(GH,i)] = - sym[0]*var[CCTK_GFINDEX1D(GH,2*ghostz[0]-cntstag[0]-i)]; + default: + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Unsupported variable type %d for variable '%s'", + CCTK_VarTypeI (vindex), CCTK_VarName (vindex)); + retval = -2; } } - return(0); + return (retval); } - diff --git a/src/Symmetry.h b/src/Symmetry.h index ca21967..bb72e3a 100644 --- a/src/Symmetry.h +++ b/src/Symmetry.h @@ -2,22 +2,24 @@ @header Symmetry.h @date Sun 7th Mar 1999 @author Gerd Lanfermann - @desc - The extensions to the GH structure for 3D grid symmetry Treatment - We'll have six int array for every GF, which holds a flag for which symmetry or - (physical) bnd-condition to apply at the grid faces. + @desc + The extensions to the GH structure for 3D grid symmetry treatment. - * These tables are set by SetSymmetry(GF,int,int,int) - during initialization. - * Default values ? - * The information is used during evolution by Einstein_DoBound(GF), - Einstein_DoSym(GF) + We'll have six int array for every GF, which holds a flag + for which symmetry or (physical) bnd-condition to apply + at the grid faces. + + * These tables are set by SetSymmetry(GF,int,int,int) + during initialization. + * Default values ? + * The information is used during evolution + by Einstein_DoBound(GF), Einstein_DoSym(GF). @enddesc - @version $Header$ + @version $Header$ @@*/ #ifndef _SYMMETRY_H_ -#define _SYMMETRY_H_ +#define _SYMMETRY_H_ 1 #define GFSYM_UNSET -41 #define GFSYM_NOSYM -42 @@ -30,34 +32,32 @@ #define MAX_DIM 3 #define MAX_FACE 6 -typedef struct Symmetry +typedef struct Symmetry { - /* Symmetry[0..GF-1][0..dim-1] */ - /* in each direction [0,..dim-1], this will hold the symmetry + /* in each direction [0,..dim-1], this will hold the symmetry operation across that plane, iff the grid layout requires this. this compares to the {sx,sy,sz} of Cactus3.2 */ int **GFSym; - } SymmetryGHex; #ifdef __cplusplus -extern "C" +extern "C" { #endif -int GetCartSymVI(const cGH *GH, int *sym, int vi); -int GetCartSymVN(const cGH *GH, int *sym, const char *vn); +int GetCartSymVI (const cGH *GH, int *sym, int varindexi); +int GetCartSymVN (const cGH *GH, int *sym, const char *varname); -int SetCartSymVI(cGH *GH, int *sym, int vi); -int SetCartSymGI(cGH *GH, int *sym, int vi); -int SetCartSymVN(cGH *GH, int *sym, const char *vn); -int SetCartSymGN(cGH *GH, int *sym, const char *vn); +int SetCartSymVI (const cGH *GH, const int *sym, int varindex); +int SetCartSymGI (const cGH *GH, const int *sym, int groupindex); +int SetCartSymVN (const cGH *GH, const int *sym, const char *varname); +int SetCartSymGN (const cGH *GH, const int *sym, const char *groupname); -int CartSymVI(cGH *GH, int vi); -int CartSymGI(cGH *GH, int gi); -int CartSymVN(cGH *GH, const char *vn); -int CartSymGN(cGH *GH, const char *gn); +int CartSymVI (const cGH *GH, int varindex); +int CartSymGI (const cGH *GH, int groupindexi); +int CartSymVN (const cGH *GH, const char *varname); +int CartSymGN (const cGH *GH, const char *groupname); #ifdef __cplusplus } diff --git a/src/SymmetryWrappers.c b/src/SymmetryWrappers.c deleted file mode 100644 index 548c149..0000000 --- a/src/SymmetryWrappers.c +++ /dev/null @@ -1,445 +0,0 @@ - /*@@ - @file SymmetryWrappers.c - @date April 2000 - @author Gerd Lanfermann - @desc - Apply symmetry boundary conditions - @enddesc - @@*/ - -#include <stdlib.h> - -#include "cctk.h" -#include "cctk_Parameters.h" -#include "cctk_FortranString.h" -#include "Symmetry.h" - -void DecodeSymParameters3D(int sym[6]); - -void CCTK_FCALL CCTK_FNAME(CartSymGI)(int *ierr, cGH *GH, int *gi); -void CCTK_FCALL CCTK_FNAME(CartSymGN) - (int *ierr, cGH *GH, ONE_FORTSTRING_ARG); -void CCTK_FCALL CCTK_FNAME(CartSymVI)(int *ierr, cGH *GH, int *vi); -void CCTK_FCALL CCTK_FNAME(CartSymVN) - (int *ierr, cGH *GH, ONE_FORTSTRING_ARG); - -int CartApplySym3Di(cGH *GH, - int *doSym, - int *cntstag, - int *lssh, - int *ghostz, - int *sym, - CCTK_REAL *var); - -int CartApplySym2Di(cGH *GH, - int *doSym, - int *cntstag, - int *lssh, - int *ghostz, - int *sym, - CCTK_REAL *var); - -int CartApplySym1Di(cGH *GH, - int *doSym, - int *cntstag, - int *lssh, - int *ghostz, - int *sym, - CCTK_REAL *var); - - -static const char *rcsid = "$Header$"; - -CCTK_FILEVERSION(CactusBase_CartGrid3D_SymmetryWrappers_c) - -/*#define SYM_DEBUG*/ - - - /*@@ - @routine - @date - @author - @desc - - @enddesc - @calls - @calledby - @history - - @endhistory - -@@*/ - -int CartSymGI(cGH *GH, int gi) -{ - DECLARE_CCTK_PARAMETERS - - int numvars, vi, first_vi; - int idim, gdim; - int berr=-1,ierr=-1; - int time; - int *doSym, *dstag, *lssh, *cntstag; - int domainsym[MAX_FACE]; - SymmetryGHex *sGHex; - - /* Get out if we are sure no symmetries should be applied */ - /* FIXME: There has to be a better way early bailout! */ - /*$if (CCTK_Equals(domain,"full")) return 0;$*/ - - first_vi = CCTK_FirstVarIndexI(gi); - if (first_vi<0) - { - CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, - "CartSymGI: Cannot find group %d (%s)",gi,CCTK_GroupName(gi)); - return(-1); - } - - numvars = CCTK_NumVarsInGroupI(gi); - gdim = CCTK_GroupDimI(gi); - - - sGHex = (SymmetryGHex*)GH->extensions[CCTK_GHExtensionHandle("Symmetry")]; - doSym = (int *)malloc((2*gdim)*sizeof(int)); - dstag = (int *)malloc(gdim*sizeof(int)); - lssh = (int *)malloc(gdim*sizeof(int)); - cntstag= (int *)malloc(gdim*sizeof(int)); - - /* get the directional staggering of the group */ - ierr = CCTK_GroupStaggerDirArrayGI(dstag, gdim, gi); - - /* Set value to one if grid is staggered around the center */ - - /* Avoid origin? Default is yes */ - cntstag[0] = no_origin && no_originx && avoid_origin && avoid_originx; - cntstag[1] = no_origin && no_originy && avoid_origin && avoid_originy; - cntstag[2] = no_origin && no_originz && avoid_origin && avoid_originz; - - /* Use next time level, if present */ - time = 0; - /*if (time < 0) - { - time = 0; - }*/ - - DecodeSymParameters3D(domainsym); - - for (vi=first_vi; vi<first_vi+numvars; vi++) - { - /* Apply Symmetries to lower sides [0,2,4,...] if: - + if the Symmetry is activated (== NOT NOSYM) - + if the Symmetry is set (== NOT UNSET) - + if the length in the direction is more than 1 grid point - + if the processor has a lower physical boundary. - Whether a grid allows a symmetry along a direction (e.g. octant=all) - is part if the Symmetry Setup process. - - No Symmetries for "upper" sides : [1,3,5,...] - */ - for (idim=0; idim<gdim; idim++) - { - if ((sGHex->GFSym[vi][idim*2] == GFSYM_UNSET)) - { - CCTK_VWarn(0,__LINE__,__FILE__,CCTK_THORNSTRING, - "Symmetries unspecified for %s",CCTK_FullName(vi)); - } - - lssh[idim] = GH->cctk_lssh[CCTK_LSSH_IDX(dstag[idim],idim)]; - - if (((sGHex->GFSym[vi][idim*2] != GFSYM_NOSYM) && - (sGHex->GFSym[vi][idim*2] != GFSYM_UNSET)) && - lssh[idim]>1 && GH->cctk_bbox[idim*2]==1) - { - doSym[idim*2] = domainsym[idim*2]; - } - else - { - doSym[idim*2] = 0; - } - - doSym[idim*2+1] = 0; - - } - -#ifdef SYM_DEBUG - printf(" DOSYM: %s [%d,%d] [%d,%d] [%d,%d] --- %d %d %d\n", - CCTK_VarName(vi), - doSym[0],doSym[1], - doSym[2],doSym[3], - doSym[4],doSym[5], - sGHex->GFSym[vi][0], - sGHex->GFSym[vi][2], - sGHex->GFSym[vi][4]); -#endif - - switch (gdim) - { - case 1: berr = CartApplySym1Di(GH, - doSym, - cntstag, - lssh, - GH->cctk_nghostzones, - sGHex->GFSym[vi], - GH->data[vi][time]); break; - case 2: berr = CartApplySym2Di(GH, - doSym, - cntstag, - lssh, - GH->cctk_nghostzones, - sGHex->GFSym[vi], - GH->data[vi][time]); break; - case 3: berr = CartApplySym3Di(GH, - doSym, - cntstag, - lssh, - GH->cctk_nghostzones, - sGHex->GFSym[vi], - GH->data[vi][time]); break; - default: berr = -1; CCTK_WARN(1, "No Symmetries for GF of dim>3"); - } - berr=(berr>-1)?0:-1; - } - - free(dstag); - free(doSym); - free(lssh); - free(cntstag); - - return(ierr); -} - -void CCTK_FCALL CCTK_FNAME(CartSymGI)(int *ierr, cGH *GH, int *gi) -{ - *ierr = CartSymGI(GH,*gi); - return; -} - - - - /*@@ - @routine - @date - @author - @desc - - @enddesc - @calls - @calledby - @history - - @endhistory - -@@*/ - -int CartSymGN(cGH *GH, const char *gn) -{ - int gi=CCTK_GroupIndex(gn); - int retval=-1; - if (gi>-1) - { - retval = CartSymGI(GH,gi); - } - else - { - CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, - "CartSymGN: Cannot find group %s",gn); - } - return retval; -} - -void CCTK_FCALL CCTK_FNAME(CartSymGN) - (int *ierr, cGH *GH, ONE_FORTSTRING_ARG) -{ - ONE_FORTSTRING_CREATE(gn) - *ierr = CartSymGN(GH,gn); - free(gn); - return; -} - - - /*@@ - @routine - @date - @author - @desc - - @enddesc - @calls - @calledby - @history - - @endhistory - -@@*/ - -int CartSymVI(cGH *GH, int vi) -{ - DECLARE_CCTK_PARAMETERS - - int gi; - int idim, gdim; - int berr=-1; - int time; - int *doSym, *dstag, *lssh, *cntstag; - SymmetryGHex *sGHex; - - /* Get out if we are sure no symmetries should be applied */ - /* FIXME: There has to be a better way early bailout! */ - if (CCTK_Equals(domain,"full")) return 0; - - /* get the dimension/directional staggering of the - group that vi belongs to */ - gi = CCTK_GroupIndexFromVarI(vi); - if (gi<0) - { - CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, - "Cannot find variable index %d (%s) in CartSymVI", - vi,CCTK_FullName(vi)); - return(-1); - } - - gdim = CCTK_GroupDimI(gi); - - sGHex = (SymmetryGHex*)GH->extensions[CCTK_GHExtensionHandle("Symmetry")]; - doSym = (int *)malloc((2*gdim)*sizeof(int)); - dstag = (int *)malloc(gdim*sizeof(int)); - lssh = (int *)malloc(gdim*sizeof(int)); - cntstag= (int *)malloc(gdim*sizeof(int)); - - /* get the directional staggering of the group */ - berr = CCTK_GroupStaggerDirArrayGI(dstag, gdim, gi); - - /* Avoid origin? Default is yes */ - cntstag[0] = no_origin && no_originx && avoid_origin && avoid_originx; - cntstag[1] = no_origin && no_originy && avoid_origin && avoid_originy; - cntstag[2] = no_origin && no_originz && avoid_origin && avoid_originz; - - /* Use next time level, if present */ - time = 0; - /* if (time < 0) - { - time = 0; - }*/ - - - /* Apply Symmetries to lower sides [0,2,4] if: - + if the Symmetry is activated (== NOT NOSYM) - + if the Symmetry is set (== NOT UNSET) - + if the length in the direction is more than 1 grid point - + if the processor has a lower physical boundary. - Whether a grid allows a symmetry along a direction (e.g. octant=all) - is part if the Symmetry Setup process. - - No Symmetries for "upper" sides : [1,3,5] - */ - for (idim=0; idim<gdim; idim++) - { - if (sGHex->GFSym[vi][idim*2]==GFSYM_UNSET) - { - CCTK_VWarn(0,__LINE__,__FILE__,CCTK_THORNSTRING, - "Symmetries unspecified for %s", CCTK_FullName(vi)); - } - - lssh[idim] = GH->cctk_lssh[CCTK_LSSH_IDX(dstag[idim],idim)]; - - doSym[idim*2] = (((sGHex->GFSym[vi][idim*2]!=GFSYM_NOSYM) && - (sGHex->GFSym[vi][idim*2]!=GFSYM_UNSET)) && - lssh[idim]>1 && GH->cctk_bbox[idim*2]); - doSym[idim*2+1] = 0; - } - -#ifdef SYM_DEBUG - printf(" DOSYM: %s [%d,%d] [%d,%d] [%d,%d] --- %d %d %d\n", - CCTK_VarName(vi), - doSym[0],doSym[1], - doSym[2],doSym[3], - doSym[4],doSym[5], - sGHex->GFSym[vi][0], - sGHex->GFSym[vi][2], - sGHex->GFSym[vi][4]); -#endif - - - - switch (gdim) - { - case 1: berr = CartApplySym1Di(GH, - doSym, - cntstag, - lssh, - GH->cctk_nghostzones, - sGHex->GFSym[vi], - GH->data[vi][time]); break; - case 2: berr = CartApplySym2Di(GH, - doSym, - cntstag, - lssh, - GH->cctk_nghostzones, - sGHex->GFSym[vi], - GH->data[vi][time]); break; - case 3: berr = CartApplySym3Di(GH, - doSym, - cntstag, - lssh, - GH->cctk_nghostzones, - sGHex->GFSym[vi], - GH->data[vi][time]); break; - default: berr = -1; CCTK_WARN(1, "No Symmetries for GF dim>3"); - } - - free(lssh); - free(dstag); - free(doSym); - free(cntstag); - - return(berr); -} - -void CCTK_FCALL CCTK_FNAME(CartSymVI)(int *ierr, cGH *GH, int *vi) -{ - *ierr = CartSymVI(GH, *vi); - return; -} - - - - /*@@ - @routine - @date - @author - @desc - - @enddesc - @calls - @calledby - @history - - @endhistory - -@@*/ - -int CartSymVN(cGH *GH, const char *vn) -{ - int retval=-1; - int vi=CCTK_VarIndex(vn); - - if (vi>-1) - { - retval = CartSymVI(GH, vi); - } - else - { - CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING, - "Cannot find variable %s in CartSymVN",vn); - } - return retval; -} - -void CCTK_FCALL CCTK_FNAME(CartSymVN) - (int *ierr, cGH *GH, ONE_FORTSTRING_ARG) -{ - ONE_FORTSTRING_CREATE(vn) - *ierr = CartSymVN(GH,vn); - free(vn); - return; -} - diff --git a/src/make.code.defn b/src/make.code.defn index ec04fdc..bf17dd1 100644 --- a/src/make.code.defn +++ b/src/make.code.defn @@ -2,5 +2,5 @@ # $Header$ # Source files in this directory -SRCS = DecodeSymParameters.c CartGrid3D.c GHExtension.c GetSymmetry.c \ - ParamCheck.c Startup.c SetSymmetry.c Symmetry.c SymmetryWrappers.c +SRCS = Startup.c ParamCheck.c DecodeSymParameters.c CartGrid3D.c \ + GetSymmetry.c SetSymmetry.c Symmetry.c |