diff options
author | allen <allen@b9286e40-80fe-41ab-903a-d6b447012e1e> | 2002-06-29 18:37:18 +0000 |
---|---|---|
committer | allen <allen@b9286e40-80fe-41ab-903a-d6b447012e1e> | 2002-06-29 18:37:18 +0000 |
commit | aceb267979362c8f7de476c61a269a5424df1c69 (patch) | |
tree | 18b1e9b9747a12d80f6c41a72959211e7f78b575 /src | |
parent | 1b8525cc2558334fc8093ca4ce036a226e597a87 (diff) |
Included style suggestions from Erik Schnetter (Cactus/1104)
Used a more accurate representation of pi (hence new testsuite files)
Wrote some minimal documentation
git-svn-id: http://svn.cactuscode.org/arrangements/CactusWave/WaveBinarySource/trunk@36 b9286e40-80fe-41ab-903a-d6b447012e1e
Diffstat (limited to 'src')
-rw-r--r-- | src/CoordinateStuff.c | 152 | ||||
-rw-r--r-- | src/WaveBinary.c | 51 |
2 files changed, 130 insertions, 73 deletions
diff --git a/src/CoordinateStuff.c b/src/CoordinateStuff.c index e9a2b9e..025fc01 100644 --- a/src/CoordinateStuff.c +++ b/src/CoordinateStuff.c @@ -1,3 +1,13 @@ + /*@@ + @file CoordinateStuff.c + @date + @author Cactus Maintainers + @desc + Extra functions for coordinate information + @enddesc + @version $Header$ + @@*/ + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -9,12 +19,36 @@ static const char *rcsid = "$Header$"; CCTK_FILEVERSION(CactusWave_WaveBinarySource_CoordinateStuff_c) -int IndexFloorC(cGH *GH, CCTK_REAL coord_value, int d); +/******************************************************************** + ********************* Local Data Types *********************** + ********************************************************************/ + + +/******************************************************************** + ********************* Local Routine Prototypes ********************* + ********************************************************************/ + + +/******************************************************************** + ********************* Local Data ***************************** + ********************************************************************/ + + +/******************************************************************** + ***************** External Routines Prototype ******************** + ********************************************************************/ + int IndexCeilC(cGH *GH, CCTK_REAL coord_value, int d); +int IndexFloorC(cGH *GH, CCTK_REAL coord_value, int d); + + +/******************************************************************** + ********************** External Routines ************************ + ********************************************************************/ /*@@ - @routine IndexFloor + @routine IndexFloorC @date Fri Jan 7 10:34:29 2000 @author Gerd Lanfermann @desc @@ -24,6 +58,8 @@ int IndexCeilC(cGH *GH, CCTK_REAL coord_value, int d); Other return values: -1 : gridindex not on this gridpatch + -2 : illegal dimension + -3 : coordinate value outside grid @enddesc @calls @calledby @@ -35,51 +71,43 @@ int IndexCeilC(cGH *GH, CCTK_REAL coord_value, int d); int IndexFloorC(cGH *GH, CCTK_REAL coord_value, int d) { - int index_low,idummy; + int index_low; CCTK_REAL cmin,cmax; - if (d==0) - { - CCTK_CoordRange(GH,&cmin,&cmax, 1, "x", "cart3d"); - } - else if (d==1) - { - CCTK_CoordRange(GH,&cmin,&cmax, 2, "y", "cart3d"); - } - else if (d==2) + if (d>=0 || d<3) { - CCTK_CoordRange(GH,&cmin,&cmax, 3, "z", "cart3d"); + CCTK_CoordRange(GH,&cmin,&cmax, d+1, NULL, "cart3d"); + + if ((coord_value<cmin)||(coord_value>cmax)) + { + CCTK_VWarn(2,__LINE__,__FILE__,CCTK_THORNSTRING, + "IndexFloor: coordinate value outside grid [%f,%f]: %f \n", + cmin, cmax, coord_value); + index_low = -3; + } + else + { + index_low = floor((coord_value-cmin)/ GH->cctk_delta_space[d]) + - GH->cctk_lbnd[d]; + + if (index_low<0 || index_low>=GH->cctk_lsh[d]) + { + index_low = -1; + } + } } else { - CCTK_WARN(0,"IndexFloor: dimension is not valid. Fortran:1..3 C:0..2"); + CCTK_WARN(1,"IndexFloorC: dimension is not valid"); + index_low = -2; } - if ((coord_value<cmin)||(coord_value>cmax)) - { - CCTK_VWarn(2,__LINE__,__FILE__,CCTK_THORNSTRING, - "IndexFloor: coordinate value outside grid [%f,%f]: %f \n", - cmin, cmax, coord_value); - return(-3); - } - - idummy = floor((coord_value-cmin)/ GH->cctk_delta_space[d]); - index_low = idummy-GH->cctk_lbnd[d]; - - if (index_low<0) - { - index_low = -1; - } - if (index_low>=GH->cctk_lsh[d]) - { - index_low = -1; - } return(index_low); } /*@@ - @routine IndexCeil + @routine IndexCeilC @date Fri Jan 7 10:34:29 2000 @author Gerd Lanfermann @desc @@ -88,6 +116,8 @@ int IndexFloorC(cGH *GH, CCTK_REAL coord_value, int d) including ghostzones. Other return values: -1 : grid index not on this gridpatch + -2 : illegal dimension + -3 : coordinate value outside grid @enddesc @calls @calledby @@ -100,44 +130,36 @@ int IndexFloorC(cGH *GH, CCTK_REAL coord_value, int d) int IndexCeilC(cGH *GH, CCTK_REAL coord_value, int d) { - int index_up,idummy; + int index_up; CCTK_REAL cmin,cmax; - if (d==0) - { - CCTK_CoordRange(GH,&cmin,&cmax, -1, "x", "cart3d"); - } - else if (d==1) + if (d>=0 || d<3) { - CCTK_CoordRange(GH,&cmin,&cmax, -1, "y", "cart3d"); - } - else if (d==2) - { - CCTK_CoordRange(GH,&cmin,&cmax, -1, "z", "cart3d"); + CCTK_CoordRange(GH,&cmin,&cmax, d+1, NULL, "cart3d"); + + if ((coord_value<cmin)||(coord_value>cmax)) + { + CCTK_VWarn(2,__LINE__,__FILE__,CCTK_THORNSTRING, + "IndexCeil: coordinate value outside grid [%f,%f]: %f \n", + cmin, cmax, coord_value); + index_up = -3; + } + else + { + index_up = ceil((coord_value-cmin)/ GH->cctk_delta_space[d]) + -GH->cctk_lbnd[d]; + + if (index_up<0 || index_up>=GH->cctk_lsh[d]) + { + index_up = -1; + } + } } else { - CCTK_WARN(0,"IndexCeilC: dimension is not valid. Fortran:1..3 C:0..2"); + CCTK_WARN(1,"IndexCeilC: dimension is not valid"); + index_up = -2; } - if ((coord_value<cmin)||(coord_value>cmax)) - { - CCTK_VWarn(2,__LINE__,__FILE__,CCTK_THORNSTRING, - "IndexCeil: coordinate value outside grid [%f,%f]: %f \n", - cmin,cmax, coord_value); - return(-3); - } - - idummy = ceil((coord_value-cmin)/ GH->cctk_delta_space[d]); - index_up = idummy-GH->cctk_lbnd[d]; - - if (index_up<0) - { - index_up = -1; - } - if (index_up>=GH->cctk_lsh[d]) - { - index_up = -1; - } return(index_up); } diff --git a/src/WaveBinary.c b/src/WaveBinary.c index 269a024..ab8f3ec 100644 --- a/src/WaveBinary.c +++ b/src/WaveBinary.c @@ -1,8 +1,17 @@ + /*@@ + @file WaveBinary.c + @date + @author Cactus Maintainers + @desc + Add a binary source term to the 3D scalar wave equation + @enddesc + @version $Header$ + @@*/ + #include <stdio.h> #include <stdlib.h> #include <math.h> -/* Using Cactus infrastructure */ #include "cctk.h" #include "cctk_Parameters.h" #include "cctk_Arguments.h" @@ -11,11 +20,35 @@ static const char *rcsid = "$Header$"; CCTK_FILEVERSION(CactusWave_WaveBinarySource_WaveBinary_c) +/******************************************************************** + ********************* Local Data Types *********************** + ********************************************************************/ + + +/******************************************************************** + ********************* Local Routine Prototypes ********************* + ********************************************************************/ -void WaveBinaryC(CCTK_ARGUMENTS); int IndexCeilC(cGH *GH, CCTK_REAL coord_value, int d); int IndexFloorC(cGH *GH, CCTK_REAL coord_value, int d); + +/******************************************************************** + ********************* Local Data ***************************** + ********************************************************************/ + + +/******************************************************************** + ***************** External Routines Prototype ******************** + ********************************************************************/ + +void WaveBinaryC(CCTK_ARGUMENTS); + + +/******************************************************************** + ********************** External Routines ************************ + ********************************************************************/ + void WaveBinaryC(CCTK_ARGUMENTS) { @@ -38,16 +71,18 @@ void WaveBinaryC(CCTK_ARGUMENTS) /* some flags */ int onthisproc, xproc, sign; static int firstcall; - + CCTK_REAL xs,ys,zs,rad; CCTK_REAL zmin,zmax,charge_factor; + const CCTK_REAL binary_pi=3.141592653589793; /* Because binary_charge and binary_size are a steerable parameters now, charge_factor needs to be recomputed at every iteration. */ charge_factor = 3.0*binary_charge/ - (4.0*3.1415*binary_size*binary_size*binary_size); + (4.0*binary_pi*binary_size*binary_size*binary_size); /* Initialize the range arrays */ + for (d=0;d<3;d++) { mingp[d] = 0; @@ -68,7 +103,7 @@ void WaveBinaryC(CCTK_ARGUMENTS) /* we have two charges opposite, origin is the center - sign mulitplies the charge xy-positions by +1 and -1 */ + sign multiplies the charge xy-positions by +1 and -1 */ for (sign=1; sign>=-1; sign-=2) { @@ -96,8 +131,8 @@ void WaveBinaryC(CCTK_ARGUMENTS) for (d=0;d<3;d++) { - /* check where our binaries are: - - the can be on our grid chunk completly + /* check where our binary sources are: + - they can be on our grid chunk completly - we have a lower part of the source on our grid chunk - we have a upper part - the source covers a grid chunk completetly @@ -157,7 +192,7 @@ void WaveBinaryC(CCTK_ARGUMENTS) maxc[0],maxc[1],maxc[2]); } - /* we have the source, no loop over the vindex boudary */ + /* we have the source, now loop over the vindex boundary */ if (onthisproc==3) { for (k=lowerloc[2];k<=upperloc[2];k++) |