aboutsummaryrefslogtreecommitdiff
path: root/src/SetGrid.c
blob: dd8a7fe5d714ef02a040bbf4042f64e01c7d1683 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
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);
    }
}