aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Utils.c')
-rw-r--r--src/Utils.c263
1 files changed, 263 insertions, 0 deletions
diff --git a/src/Utils.c b/src/Utils.c
new file mode 100644
index 0000000..d38b1c6
--- /dev/null
+++ b/src/Utils.c
@@ -0,0 +1,263 @@
+ /*@@
+ @file Utils.c
+ @date Tue 4th July 2000
+ @author Gabrielle Allen
+ @desc
+ Utility routines which may be called by other IO thorns
+ @enddesc
+ @history
+ @endhistory
+ @@*/
+
+/*#define DEBUG_IOUTIL*/
+
+#include "cctk.h"
+#include "cctk_Parameters.h"
+
+ /*@@
+ @routine IOUtil_1DLines
+ @date July 4 2000
+ @author Gabrielle Allen, Gerd Lanfermann, Thomas Radke
+ @desc
+ Fills out an array determining where to position 1D lines for output
+ on a multidimensional regular Cartesian unigrid.
+ The first slot of the array specifies the 1D line direction, the
+ second slot fixes the indices of the starting point of that line on the
+ grid.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+
+int IOUtil_1DLines (cGH *GH,
+ int dimension,
+ int **index,
+ CCTK_REAL **coord,
+ int **spxyz)
+{
+ DECLARE_CCTK_PARAMETERS
+
+ int ierr=0;
+ int dim, dir;
+ CCTK_REAL lower,upper;
+ const char *name=NULL;
+ CCTK_REAL lowercoords[3]={0,0,0};
+ CCTK_REAL uppercoords[3]={0,0,0};
+
+ /* Get the appropriate coordinate system */
+ switch (dimension)
+ {
+ case 1:
+ name = "cart1d";
+ ierr = CCTK_CoordRange(GH, &lower, &upper, 1, NULL, name);
+ if (ierr>-1)
+ {
+ lowercoords[0] = lower;
+ uppercoords[0] = upper;
+ }
+ break;
+ case 2:
+ name = "cart2d";
+ ierr = CCTK_CoordRange(GH, &lower, &upper, 1, NULL, name);
+ if (ierr>-1)
+ {
+ lowercoords[0] = lower;
+ uppercoords[0] = upper;
+ }
+ ierr = CCTK_CoordRange(GH, &lower, &upper, 2, NULL, name);
+ if (ierr>-1)
+ {
+ lowercoords[1] = lower;
+ uppercoords[1] = upper;
+ }
+ break;
+ case 3:
+ name = "cart3d";
+ ierr = CCTK_CoordRange(GH, &lower, &upper, 1, NULL, name);
+ if (ierr>-1)
+ {
+ lowercoords[0] = lower;
+ uppercoords[0] = upper;
+ }
+ ierr = CCTK_CoordRange(GH, &lower, &upper, 2, NULL, name);
+ if (ierr>-1)
+ {
+ lowercoords[1] = lower;
+ uppercoords[1] = upper;
+ }
+ ierr = CCTK_CoordRange(GH, &lower, &upper, 3, NULL, name);
+ if (ierr>-1)
+ {
+ lowercoords[2] = lower;
+ uppercoords[2] = upper;
+ }
+ break;
+ default:
+ CCTK_VWarn(4,__LINE__,__FILE__,"IOASCII",
+ "IOUtil_1DLines: Support only for dim<=3");
+ ierr = -1;
+ break;
+ }
+
+ for (dir = 0; dir < dimension; dir++)
+ {
+ for (dim = 0; dim < dimension; dim++)
+ {
+ if (dim == dir)
+ {
+ spxyz[dir][dim] = 0;
+ }
+ else if (index && index[dir][dim]>-1)
+ {
+ spxyz[dir][dim] = index[dir][dim];
+ }
+ else if (ierr < 0)
+ {
+ CCTK_VWarn(4, __LINE__,__FILE__,"IOASCII",
+ "IOUtil_1DLines: Cartesian coordinate system %s not found",
+ name);
+ spxyz[dir][dim] = 0;
+ }
+ else if (lowercoords[dim]>coord[dir][dim] ||
+ uppercoords[dim]<coord[dir][dim])
+ {
+ CCTK_VWarn(2,__LINE__,__FILE__,"IOUtil",
+ "IOUtil_1DLines: Coordinate in direction %d (%f,%f)"
+ " doesn't contain %f",
+ dim,lowercoords[dim],uppercoords[dim],coord[dir][dim]);
+ spxyz[dir][dim] = 0;
+ }
+ else
+ {
+ /* Find index for first point above the chosen coordinate */
+ spxyz[dir][dim] = 0.5-(lowercoords[dim]-coord[dir][dim])/
+ (GH->cctk_delta_space[dim]);
+
+#ifdef DEBUG_IOUTIL
+ printf("spxyz for %d-coord of lines in %d-direction is %d\n",
+ dim,dir,spxyz[dir][dim]);
+#endif
+ }
+ }
+ }
+
+ return 0;
+}
+
+
+
+int IOUtil_2DPlanes (cGH *GH,
+ int dimension,
+ int *index,
+ CCTK_REAL *coord,
+ int *sp2xyz)
+{
+ DECLARE_CCTK_PARAMETERS
+
+ int ierr=0;
+ int dir;
+ CCTK_REAL lower,upper;
+ const char *name=NULL;
+ CCTK_REAL lowercoords[3]={0,0,0};
+ CCTK_REAL uppercoords[3]={0,0,0};
+
+ /* Get the appropriate coordinate system */
+ /* Get the appropriate coordinate system */
+ switch (dimension)
+ {
+ case 1:
+ name = "cart1d";
+ ierr = CCTK_CoordRange(GH, &lower, &upper, 1, NULL, name);
+ if (ierr>-1)
+ {
+ lowercoords[0] = lower;
+ uppercoords[0] = upper;
+ }
+ break;
+ case 2:
+ name = "cart2d";
+ ierr = CCTK_CoordRange(GH, &lower, &upper, 1, NULL, name);
+ if (ierr>-1)
+ {
+ lowercoords[0] = lower;
+ uppercoords[0] = upper;
+ }
+ ierr = CCTK_CoordRange(GH, &lower, &upper, 2, NULL, name);
+ if (ierr>-1)
+ {
+ lowercoords[1] = lower;
+ uppercoords[1] = upper;
+ }
+ break;
+ case 3:
+ name = "cart3d";
+ ierr = CCTK_CoordRange(GH, &lower, &upper, 1, NULL, name);
+ if (ierr>-1)
+ {
+ lowercoords[0] = lower;
+ uppercoords[0] = upper;
+ }
+ ierr = CCTK_CoordRange(GH, &lower, &upper, 2, NULL, name);
+ if (ierr>-1)
+ {
+ lowercoords[1] = lower;
+ uppercoords[1] = upper;
+ }
+ ierr = CCTK_CoordRange(GH, &lower, &upper, 3, NULL, name);
+ if (ierr>-1)
+ {
+ lowercoords[2] = lower;
+ uppercoords[2] = upper;
+ }
+ break;
+ default:
+ CCTK_VWarn(4,__LINE__,__FILE__,"IOASCII",
+ "IOUtil_2DPlanes: Support only for dim<=3");
+ ierr = -1;
+ break;
+ }
+
+
+ for (dir = 0; dir < dimension; dir++)
+ {
+ if (index && index[dir]>-1)
+ {
+ sp2xyz[dir] = index[dir];
+ }
+ else if (ierr < 0)
+ {
+ CCTK_VWarn(4, __LINE__,__FILE__,"IOUtil",
+ "IOUtil_2DPlanes: Cartesian coordinate system %s not found",
+ name);
+ sp2xyz[dir] = 0;
+ }
+ else if (lowercoords[dir]>coord[dir] ||
+ uppercoords[dir]<coord[dir])
+ {
+ CCTK_VWarn(2,__LINE__,__FILE__,"IOUtil",
+ "IOUtil_2DPlanes: Coordinate in direction %d (%lf,%lf)"
+ " doesn't contain %f",
+ dir,lowercoords[dir],uppercoords[dir],coord[dir]);
+ sp2xyz[dir] = 0;
+ }
+ else
+ {
+ /* Find index for first point above the chosen coordinate */
+ sp2xyz[dir] = 0.5-(lowercoords[dir]-coord[dir])/
+ (GH->cctk_delta_space[dir]);
+
+#ifdef DEBUG_IOUTIL
+ printf("sp2xyz for planes perpendicular to"
+ " %d-direction is %d\n",
+ dir,sp2xyz[dir]);
+#endif
+ }
+ }
+
+ return 0;
+
+}