diff options
author | schnetter <schnetter@c3c03602-0f4f-0410-b3fa-d2c81c8a7dc5> | 2005-12-07 00:41:06 +0000 |
---|---|---|
committer | schnetter <schnetter@c3c03602-0f4f-0410-b3fa-d2c81c8a7dc5> | 2005-12-07 00:41:06 +0000 |
commit | 9ee6f38cace2f2c4b088d4a4032c91fcdf902e59 (patch) | |
tree | de524e6de3db773aa64dd0934e02e6ca48ef5ba3 | |
parent | 0b7e91ddc636c36bdd695e234eaa604852418851 (diff) |
Clean up the code. Replace the magic number 3 by a constant DIM.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/RotatingSymmetry90/trunk@33 c3c03602-0f4f-0410-b3fa-d2c81c8a7dc5
-rw-r--r-- | src/rotatingsymmetry90.c | 97 |
1 files changed, 50 insertions, 47 deletions
diff --git a/src/rotatingsymmetry90.c b/src/rotatingsymmetry90.c index 728f8c5..cead8a8 100644 --- a/src/rotatingsymmetry90.c +++ b/src/rotatingsymmetry90.c @@ -16,16 +16,22 @@ +/* This is pretty hard coded into all the tensor types and cannot be + changed easily. */ +#define DIM 3 /* spatial dimension */ + + + static int convert_index (int const step, int const index, int const * restrict const alldirs, int * restrict const parity) { int srcindex; - assert (index>=0 && index<3); + assert (index>=0 && index<DIM); assert (alldirs); - assert (alldirs[0]>=0 && alldirs[0]<3); - assert (alldirs[1]>=0 && alldirs[1]<3); + assert (alldirs[0]>=0 && alldirs[0]<DIM); + assert (alldirs[1]>=0 && alldirs[1]<DIM); assert (alldirs[1] != alldirs[0]); assert (parity); assert (abs(*parity) == 1); @@ -78,14 +84,14 @@ int BndRot90VI (cGH const * restrict const cctkGH, void const * restrict * restrict srcptrs; int * restrict parities; - int global_bbox[6]; - int global_lbnd[3], global_ubnd[3]; - int fake_bbox[6]; + int global_bbox[2*DIM]; + int global_lbnd[DIM], global_ubnd[DIM]; + int fake_bbox[2*DIM]; - CCTK_REAL x0[3], dx[3]; - CCTK_REAL origin[3], dorigin[3]; - int avoid_origin[3]; - int offset[3]; /* offset 0..1 due to avoid_origin */ + CCTK_REAL x0[DIM], dx[DIM]; + CCTK_REAL origin[DIM], dorigin[DIM]; + int avoid_origin[DIM]; + int offset[DIM]; /* offset 0..1 due to avoid_origin */ struct xferinfo * restrict xferinfo; @@ -96,8 +102,8 @@ int BndRot90VI (cGH const * restrict const cctkGH, int alldirs[2]; int step; int ndirs; /* 1 for face, 2 for edge */ - int dir[3]; /* current face or edge */ - int otherdir[3]; /* the other direction of the rotation */ + int dir[DIM]; /* current face or edge */ + int otherdir[DIM]; /* the other direction of the rotation */ int q; /* 0..ndirs-1 */ int d; /* 0..group.dim-1 */ int ierr; @@ -158,25 +164,25 @@ int BndRot90VI (cGH const * restrict const cctkGH, { int max_handle; - CCTK_INT local[12], global[12]; + CCTK_INT local[4*DIM], global[4*DIM]; max_handle = CCTK_ReductionArrayHandle ("maximum"); if (max_handle<0) CCTK_WARN (0, "Could not obtain reduction handle"); - for (d=0; d<6; ++d) local[ d] = cctkGH->cctk_bbox[d]; - for (d=0; d<3; ++d) local[6+d] = -cctkGH->cctk_lbnd[d]; - for (d=0; d<3; ++d) local[9+d] = cctkGH->cctk_ubnd[d]; + for (d=0; d<2*DIM; ++d) local[ d] = cctkGH->cctk_bbox[d]; + for (d=0; d< DIM; ++d) local[2*DIM+d] = -cctkGH->cctk_lbnd[d]; + for (d=0; d< DIM; ++d) local[3*DIM+d] = cctkGH->cctk_ubnd[d]; ierr = CCTK_ReduceLocArrayToArray1D - (cctkGH, -1, max_handle, local, global, 12, CCTK_VARIABLE_INT); - for (d=0; d<6; ++d) global_bbox[d] = global[ d]; - for (d=0; d<3; ++d) global_lbnd[d] = -global[6+d]; - for (d=0; d<3; ++d) global_ubnd[d] = global[9+d]; + (cctkGH, -1, max_handle, local, global, 4*DIM, CCTK_VARIABLE_INT); + for (d=0; d<2*DIM; ++d) global_bbox[d] = global[ d]; + for (d=0; d< DIM; ++d) global_lbnd[d] = -global[2*DIM+d]; + for (d=0; d< DIM; ++d) global_ubnd[d] = global[3*DIM+d]; - for (d=0; d<3; ++d) { + for (d=0; d<DIM; ++d) { fake_bbox[2*d ] = data.lbnd[d] == global_lbnd[d]; fake_bbox[2*d+1] = data.ubnd[d] == global_ubnd[d]; } } - + /* directions */ alldirs[0] = 0; alldirs[1] = 1; @@ -282,20 +288,20 @@ int BndRot90VI (cGH const * restrict const cctkGH, || CCTK_EQUALS (tensortypealias, "d")) { /* vector */ - assert (numvars == 3); + assert (numvars == DIM); } else if (CCTK_EQUALS (tensortypealias, "4u") || CCTK_EQUALS (tensortypealias, "4d")) { /* 4-vector */ - assert (numvars == 4); + assert (numvars == DIM+1); } else if (CCTK_EQUALS (tensortypealias, "uu_sym") || CCTK_EQUALS (tensortypealias, "dd_sym")) { /* symmetric tensor */ - assert (numvars == 6); + assert (numvars == DIM*(DIM+1)/2); } else if (CCTK_EQUALS (tensortypealias, "4uu_sym") || CCTK_EQUALS (tensortypealias, "4dd_sym")) { /* symmetric 4-tensor */ - assert (numvars == 10); + assert (numvars == (DIM+1)*(DIM+2)/2); } else { char * groupname = CCTK_GroupName(gis[var]); assert (groupname); @@ -320,14 +326,14 @@ int BndRot90VI (cGH const * restrict const cctkGH, { /* vector */ int srcindex; - assert (index>=0 && index<3); + assert (index>=0 && index<DIM); srcindex = convert_index (step, index, alldirs, &parities[var]); srcvi = firstvar + srcindex; } else if (CCTK_EQUALS (tensortypealias, "4u") || CCTK_EQUALS (tensortypealias, "4d")) { /* 4-vector */ - assert (index>=0 && index<4); + assert (index>=0 && index<DIM+1); if (index==0) { /* temporal component */ srcvi = firstvar; @@ -345,28 +351,28 @@ int BndRot90VI (cGH const * restrict const cctkGH, int index1, index2; int srcindex1, srcindex2; int srcindex; - assert (index>=0 && index<6); + assert (index>=0 && index<DIM*(DIM+1)/2); { - int const expand1[6] = { 0,0,0,1,1,2 }; - int const expand2[6] = { 0,1,2,1,2,2 }; + int const expand1[DIM*(DIM+1)/2] = { 0,0,0,1,1,2 }; + int const expand2[DIM*(DIM+1)/2] = { 0,1,2,1,2,2 }; index1 = expand1[index]; index2 = expand2[index]; } srcindex1 = convert_index (step, index1, alldirs, &parities[var]); srcindex2 = convert_index (step, index2, alldirs, &parities[var]); { - int const compact[3][3] = { { 0,1,2 }, { 1,3,4 }, { 2,4,5 } }; + int const compact[DIM][DIM] = { { 0,1,2 }, { 1,3,4 }, { 2,4,5 } }; srcindex = compact[srcindex1][srcindex2]; } srcvi = firstvar + srcindex; } else if (CCTK_EQUALS (tensortypealias, "4uu_sym") || CCTK_EQUALS (tensortypealias, "4dd_sym")) { /* symmetric 4-tensor */ - assert (index>=0 && index<10); + assert (index>=0 && index<(DIM+1)*(DIM+2)/2); if (index==0) { /* temporal-temporal component */ srcvi = firstvar; - } else if (index<4) { + } else if (index<DIM+1) { /* temporal-spatial components */ int srcindex; int const off = 1; @@ -378,17 +384,17 @@ int BndRot90VI (cGH const * restrict const cctkGH, int index1, index2; int srcindex1, srcindex2; int srcindex; - int const off = 4; + int const off = DIM+1; { - int const expand1[6] = { 0,0,0,1,1,2 }; - int const expand2[6] = { 0,1,2,1,2,2 }; + int const expand1[DIM*(DIM+1)/2] = { 0,0,0,1,1,2 }; + int const expand2[DIM*(DIM+1)/2] = { 0,1,2,1,2,2 }; index1 = expand1[index-off]; index2 = expand2[index-off]; } srcindex1 = convert_index (step, index1, alldirs, &parities[var]); srcindex2 = convert_index (step, index2, alldirs, &parities[var]); { - int const compact[3][3] = { { 0,1,2 }, { 1,3,4 }, { 2,4,5 } }; + int const compact[DIM][DIM] = { { 0,1,2 }, { 1,3,4 }, { 2,4,5 } }; srcindex = off + compact[srcindex1][srcindex2]; } srcvi = firstvar + srcindex; @@ -484,9 +490,6 @@ int BndRot90VI (cGH const * restrict const cctkGH, assert (0); } - for (var=0; var<nvars; ++var) { - } - ierr = Slab_MultiTransfer (cctkGH, group.dim, xferinfo, -1, nvars, vartypes, srcptrs, vartypes, varptrs); @@ -501,9 +504,9 @@ int BndRot90VI (cGH const * restrict const cctkGH, for (var=0; var<nvars; ++var) { assert (abs(parities[var]) == 1); if (parities[var] == -1) { - int imin[3], imax[3]; + int imin[DIM], imax[DIM]; int i, j, k; - for (d=0; d<3; ++d) { + for (d=0; d<DIM; ++d) { imin[d] = xferinfo[d].dst.off; imax[d] = xferinfo[d].dst.off + xferinfo[d].dst.len; imin[d] -= cctk_lbnd[d]; @@ -511,11 +514,11 @@ int BndRot90VI (cGH const * restrict const cctkGH, if (imin[d] < 0) imin[d] = 0; if (imax[d] >= cctk_lsh[d]) imax[d] = cctk_lsh[d]; } - assert (group.dim == 3); + assert (group.dim == DIM); assert (group.vartype == CCTK_VARIABLE_REAL); - for (k=imin[0]; k<imax[2]; ++k) { + for (k=imin[2]; k<imax[2]; ++k) { for (j=imin[1]; j<imax[1]; ++j) { - for (i=imin[2]; i<imax[0]; ++i) { + for (i=imin[0]; i<imax[0]; ++i) { const int ind = CCTK_GFINDEX3D(cctkGH, i, j, k); ((CCTK_REAL *) varptrs[var]) [ind] *= -1; } @@ -575,7 +578,7 @@ void Rot90_ApplyBC (CCTK_ARGUMENTS) for (var=0; var<nvars; ++var) { assert (indices[var]>=0 && indices[var]<CCTK_NumVars()); - assert (widths[var] >= 0); + assert (widths[var]>=0); } ierr = BndRot90VI (cctkGH, nvars, indices); |