diff options
Diffstat (limited to 'src/SetGrid.c')
-rw-r--r-- | src/SetGrid.c | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/src/SetGrid.c b/src/SetGrid.c new file mode 100644 index 0000000..dd8a7fe --- /dev/null +++ b/src/SetGrid.c @@ -0,0 +1,228 @@ +/*@@ + @file SetGrid.c + @date April 2002 + @author Denis Pollney + @desc + Reset the grid sizes before they are set by CartGrid3D, so + that they have sensible cartoon-compatible values. + @enddesc + @@*/ + +#include <string.h> + +#include "cctk.h" +#include "cctk_Parameter.h" +#include "cctk_Parameters.h" + +static const char +*rcsid = "$Id$"; + + /*@@ + @routine Cartoon_SetGrid + @date April 2002 + @author Denis Pollney + @desc + Resets the grid dimensions in a cartoon-compatible way if + the user has specified grid::type="byspacing". + + Generally, "byspacing" would put the z-axis in the middle + of the x range. However, for cartoon, it is required to + be at the edge of the range with only some zombie-zones + extending across. This routine ensures that this is the + case, by fixing the x range and re-specifying nx so that + the dx value which was specified by the user is unchanged. + The y range is reset to be a width of 1 plus space for the + zombie points. + + In the process, a couple of other parameters such as + grid::bitant_plane and grid::avoid_originy are also checked + to ensure that they are cartoon-compatible. + + If the grid type is specified to be "byrange", then this + routine does nothing and it is up to the user to choose + appropriate ranges for what they want to do. + + Note that this routine currently needs to be scheduled at + CCTK_RECOVER_PARAMETERS, because this is the only place where + it is still possible to modify non-steerable parameters. + @enddesc + @@*/ +void +Cartoon2D_SetGrid(void) +{ + DECLARE_CCTK_PARAMETERS + + int* s = NULL; + int* p_type = NULL; + int* nx = NULL; + int* ny = NULL; + int* nz = NULL; + int* ghost_z = NULL; + double* dx = NULL; + double* dy = NULL; + double* dz = NULL; + int cartoon_ny; + int ierr; + char p_val[80]; + char* domain; + char* plane; + char* avoid_y0; + double xmin, xmax, ymin, ymax, zmin, zmax; + + + /* + * Determine the y ghostzone size. + */ + s = (int*) CCTK_ParameterGet("ghost_size_y", "pugh", p_type); + if (s == NULL) + CCTK_WARN(0, "pugh::ghost_size_y must be set explicitly"); + + cartoon_ny = 2 * (*s) + 1; + + /* + * Get the x,y,z grid sizes. + */ + nx = (int*) CCTK_ParameterGet("global_nsize", "pugh", p_type); + if ((nx == NULL) || (*nx == -1)) + { + nx = (int*) CCTK_ParameterGet("global_nx", "pugh", p_type); + if ((nx==NULL) || (*nx == -1)) + CCTK_WARN(0, "Couldn't determine global_nx"); + + ny = (int*) CCTK_ParameterGet("global_ny", "pugh", p_type); + if ((ny == NULL) || (*ny == -1)) + CCTK_WARN(0, "Couldn't determine global_nx"); + + nz = (int*) CCTK_ParameterGet("global_nz", "pugh", p_type); + if ((nz == NULL) || (*nz == -1)) + CCTK_WARN(0, "Couldn't determine global_nz"); + } + else + { + ny = nx; + nz = nx; + } + + /* + * Reset the y grid size to be one layer thick, plus twice the ghostzone + * size. + */ + if (*ny != cartoon_ny) + { + CCTK_VInfo(CCTK_THORNSTRING, "Resetting pugh::global_ny to %d\n", + cartoon_ny); + sprintf(p_val, "%d\0", cartoon_ny); + CCTK_ParameterSet("global_ny", "pugh", p_val); + } + + + /* + * Reset the grid sizes if the user has specified a "byspacing" grid. + */ + if (strcmp(CCTK_ParameterValString("type", "cartgrid3d"), "byrange")) + { + /* + * We need to set the grid spacings explicitly, so from now on + * consider the grid to be 'byrange'. + */ + CCTK_ParameterSet("type", "cartgrid3d", "byrange"); + + /* + * Get the x,y,z grid spacing. + */ + dx = (double*) CCTK_ParameterGet("dxyz", "cartgrid3d", p_type); + if (dx == NULL) + { + dx = (double*) CCTK_ParameterGet("dx", "cartgrid3d", p_type); + dy = (double*) CCTK_ParameterGet("dy", "cartgrid3d", p_type); + dz = (double*) CCTK_ParameterGet("dz", "cartgrid3d", p_type); + + if (dx == NULL) + CCTK_WARN(0, "Couldn't determine dx value"); + if (dy == NULL) + CCTK_WARN(0, "Couldn't determine dy value"); + if (dz == NULL) + CCTK_WARN(0, "Couldn't determine dz value"); + } + else + { + dy = dx; + dz = dx; + } + + /* + * Set the x grid dimensions. + */ + *nx += (*s + 1); + xmin = -((*s)-0.5) * (*dx); + xmax = xmin + (*nx-1) * (*dx); + + CCTK_VInfo(CCTK_THORNSTRING, "Setting x-range to [%f, %f]", xmin, xmax); + + sprintf(p_val, "%f\0", xmin); + ierr = CCTK_ParameterSet("xmin", "cartgrid3d", p_val); + sprintf(p_val, "%f\0", xmax); + ierr = CCTK_ParameterSet("xmax", "cartgrid3d", p_val); + + /* + * Set the y grid dimensions. + */ + avoid_y0 = CCTK_ParameterValString("avoid_originy", "cartgrid3d"); + if (strcmp(avoid_y0, "no")) + CCTK_WARN(0, "Cartoon2D requires grid::avoid_originy=\"no\""); + + ymax = (*s) * (*dy); + ymin = -ymax; + + CCTK_VInfo(CCTK_THORNSTRING, "Setting y-range to [%f, %f]", ymin, ymax); + + sprintf(p_val, "%f\0", ymin); + ierr = CCTK_ParameterSet("ymin", "cartgrid3d", p_val); + sprintf(p_val, "%f\0", ymax); + ierr = CCTK_ParameterSet("ymax", "cartgrid3d", p_val); + + /* + * Set the z grid dimensions for bitant mode. + */ + + domain = CCTK_ParameterValString("domain", "cartgrid3d"); + if (!strcmp(domain, "bitant")) + { + plane = CCTK_ParameterValString("bitant_plane", "cartgrid3d"); + if (strcmp(plane, "xy")) + CCTK_WARN(0, "Cartoon2D requires grid::bitant_plane=\"xy\""); + + ghost_z = (int*) CCTK_ParameterGet("ghost_size", "pugh", p_type); + if ((ghost_z == NULL) || (*ghost_z < 0)) + ghost_z = (int*) CCTK_ParameterGet("ghost_size_z", "pugh", p_type); + + (*nz) += 1; + zmax = (*nz-0.5) * (*dz); + zmin = -zmax; + + if ((ghost_z != NULL) && (*ghost_z > 0)) + (*nz) += (*ghost_z); + } + + else if (!strcmp(domain, "full")) + { + (*nz) += 2; + zmax = (*nz-1) * (*dz)/2; + zmin = -zmax; + } + + else + { + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, + "Cartoon2D is unable to handle grid::domain=\"%s\"", + domain); + } + + CCTK_VInfo(CCTK_THORNSTRING, "Setting z-range to [%f,%f]", zmin, zmax); + + sprintf(p_val, "%f\0", zmin); + ierr = CCTK_ParameterSet("zmin", "cartgrid3d", p_val); + sprintf(p_val, "%f\0", zmax); + ierr = CCTK_ParameterSet("zmax", "cartgrid3d", p_val); + } +} |