aboutsummaryrefslogtreecommitdiff
path: root/src/Domain.c
blob: 75272a045b092eb4529d3122c28cb2a511ad6563 (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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
#include <cctk.h>
#include <cctk_Parameters.h>
#include <util_Table.h>



CCTK_INT CoordBase_GetBoundarySpecification
  (CCTK_INT const size,
   CCTK_INT * const nboundaryzones,
   CCTK_INT * const is_internal,
   CCTK_INT * const is_staggered,
   CCTK_INT * const shiftout)
{
  DECLARE_CCTK_PARAMETERS;
  
  if(! (size>=0))
    CCTK_WARN (0, "size is less than zero");
  if(! (nboundaryzones))
    CCTK_WARN (0, "nboundaryzones is out of bounds");
  if(! (is_internal))
    CCTK_WARN (0, "is_internal is out of bounds");
  if(! (is_staggered))
    CCTK_WARN (0, "is_staggered is out of bounds");
  if(! (shiftout))
    CCTK_WARN (0, "shiftout is out of bounds");
  
  if(! (size == 6))
    CCTK_WARN (0, "size is out of bounds");

  nboundaryzones[0] = boundary_size_x_lower;
  nboundaryzones[1] = boundary_size_x_upper;
  nboundaryzones[2] = boundary_size_y_lower;
  nboundaryzones[3] = boundary_size_y_upper;
  nboundaryzones[4] = boundary_size_z_lower;
  nboundaryzones[5] = boundary_size_z_upper;
  
  is_internal[0] = boundary_internal_x_lower;
  is_internal[1] = boundary_internal_x_upper;
  is_internal[2] = boundary_internal_y_lower;
  is_internal[3] = boundary_internal_y_upper;
  is_internal[4] = boundary_internal_z_lower;
  is_internal[5] = boundary_internal_z_upper;
  
  is_staggered[0] = boundary_staggered_x_lower;
  is_staggered[1] = boundary_staggered_x_upper;
  is_staggered[2] = boundary_staggered_y_lower;
  is_staggered[3] = boundary_staggered_y_upper;
  is_staggered[4] = boundary_staggered_z_lower;
  is_staggered[5] = boundary_staggered_z_upper;
  
  shiftout[0] = boundary_shiftout_x_lower;
  shiftout[1] = boundary_shiftout_x_upper;
  shiftout[2] = boundary_shiftout_y_lower;
  shiftout[3] = boundary_shiftout_y_upper;
  shiftout[4] = boundary_shiftout_z_lower;
  shiftout[5] = boundary_shiftout_z_upper;
  
  return 0;
}



CCTK_INT CoordBase_GetDomainSpecification
  (CCTK_INT const size,
   CCTK_REAL * const physical_min,
   CCTK_REAL * const physical_max,
   CCTK_REAL * const interior_min,
   CCTK_REAL * const interior_max,
   CCTK_REAL * const exterior_min,
   CCTK_REAL * const exterior_max,
   CCTK_REAL * const thespacing)
{
  DECLARE_CCTK_PARAMETERS;
  
  int ierr;
  
  if(! (size>=0))
    CCTK_WARN (0, "size is out of bounds");
  if(! (physical_min))
    CCTK_WARN (0, "physical_min is out of bounds");
  if(! (physical_max))
    CCTK_WARN (0, "physical_max is out of bounds");
  if(! (interior_min))
    CCTK_WARN (0, "interior_min is out of bounds");
  if(! (interior_max))
    CCTK_WARN (0, "interior_max is out of bounds");
  if(! (exterior_min))
    CCTK_WARN (0, "exterior_min is out of bounds");
  if(! (exterior_max))
    CCTK_WARN (0, "exterior_max is out of bounds");
  if(! (thespacing))
    CCTK_WARN (0, "thespacing is out of bounds");

  if(! (size == 3))
    CCTK_WARN (0, "size is out of bounds");  
  
  
  if (CCTK_EQUALS (domainsize, "minmax")) {
    
    physical_min[0] = xmin;
    physical_min[1] = ymin;
    physical_min[2] = zmin;
    physical_max[0] = xmax;
    physical_max[1] = ymax;
    physical_max[2] = zmax;
    if (CCTK_EQUALS (spacing, "gridspacing")) {
      thespacing[0] = dx;
      thespacing[1] = dy;
      thespacing[2] = dz;
    } else if (CCTK_EQUALS (spacing, "numcells")) {
      thespacing[0] = (physical_max[0] - physical_min[0]) / ncells_x;
      thespacing[1] = (physical_max[1] - physical_min[1]) / ncells_y;
      thespacing[2] = (physical_max[2] - physical_min[2]) / ncells_z;
    }
    
  } else if (CCTK_EQUALS (domainsize, "extent")) {
    
    if (zero_origin_x) {
      physical_min[0] = xmin;
      physical_max[0] = xmin + xextent;
    } else {
      physical_min[0] = - xextent / 2;
      physical_max[0] = + xextent / 2;
    }
    if (zero_origin_y) {
      physical_min[1] = ymin;
      physical_max[1] = ymin + yextent;
    } else {
      physical_min[1] = - yextent / 2;
      physical_max[1] = + yextent / 2;
    }
    if (zero_origin_z) {
      physical_min[2] = zmin;
      physical_max[2] = zmin + zextent;
    } else {
      physical_min[2] = - zextent / 2;
      physical_max[2] = + zextent / 2;
    }
    if (CCTK_EQUALS (spacing, "gridspacing")) {
      thespacing[0] = dx;
      thespacing[1] = dy;
      thespacing[2] = dz;
    } else if (CCTK_EQUALS (spacing, "numcells")) {
      thespacing[0] = (physical_max[0] - physical_min[0]) / ncells_x;
      thespacing[1] = (physical_max[1] - physical_min[1]) / ncells_y;
      thespacing[2] = (physical_max[2] - physical_min[2]) / ncells_z;
    }
    
  } else if (CCTK_EQUALS (domainsize, "spacing")) {
    
    if (zero_origin_x) {
      physical_min[0] = xmin;
      physical_max[0] = xmin + dx * ncells_x;
    } else {
      physical_min[0] = - dx * ncells_x / 2;
      physical_max[0] = + dx * ncells_x / 2;
    }
    if (zero_origin_y) {
      physical_min[1] = ymin;
      physical_max[1] = ymin + dy * ncells_y;
    } else {
      physical_min[1] = - dy * ncells_y / 2;
      physical_max[1] = + dy * ncells_y / 2;
    }
    if (zero_origin_z) {
      physical_min[2] = zmin;
      physical_max[2] = zmin + dz * ncells_z;
    } else {
      physical_min[2] = - dz * ncells_z / 2;
      physical_max[2] = + dz * ncells_z / 2;
    }
    thespacing[0] = dx;
    thespacing[1] = dy;
    thespacing[2] = dz;

  } else {
    CCTK_WARN (0, "domainsize is out of bounds");
  }
  
  ierr = ConvertFromPhysicalBoundary
    (size, physical_min, physical_max, interior_min, interior_max,
     exterior_min, exterior_max, thespacing);
  if(ierr)
    CCTK_WARN (0, "Error returned from ConvertFromPhysicalBoundary");  
  
  return 0;
}



CCTK_INT CoordBase_ConvertFromPhysicalBoundary
  (CCTK_INT const size,
   CCTK_REAL const * const physical_min,
   CCTK_REAL const * const physical_max,
   CCTK_REAL * const interior_min,
   CCTK_REAL * const interior_max,
   CCTK_REAL * const exterior_min,
   CCTK_REAL * const exterior_max,
   CCTK_REAL const * const thespacing)
{
  CCTK_INT nboundaryzones[6];
  CCTK_INT is_internal[6];
  CCTK_INT is_staggered[6];
  CCTK_INT shiftout[6];
  
  int d;
  int ierr;
  
  if(! (size>=0))
    CCTK_WARN (0, "size is out of bounds");
  if(! (physical_min))
    CCTK_WARN (0, "physical_min is out of bounds");
  if(! (physical_max))
    CCTK_WARN (0, "physical_max is out of bounds");
  if(! (interior_min))
    CCTK_WARN (0, "interior_min is out of bounds");
  if(! (interior_max))
    CCTK_WARN (0, "interior_max is out of bounds");
  if(! (exterior_min))
    CCTK_WARN (0, "exterior_min is out of bounds");
  if(! (exterior_max))
    CCTK_WARN (0, "exterior_max is out of bounds");
  if(! (thespacing))
    CCTK_WARN (0, "thespacing is out of bounds");

  if(! (size == 3))
    CCTK_WARN (0, "size is out of bounds");  
  
  ierr = CoordBase_GetBoundarySpecification
    (6, nboundaryzones, is_internal, is_staggered, shiftout);
  if (ierr)
    CCTK_WARN (0, "error returned from function CoordBase_GetBoundarySpecification");
  
  for (d=0; d<3; ++d) {
    
    exterior_min[d] = physical_min[d] - thespacing[d] *
      (+ (is_internal[2*d] ? 0 : nboundaryzones[2*d] - 1)
       + (is_staggered[2*d] ? 0.5 : 0.0)
       + shiftout[2*d]);
    exterior_max[d] = physical_max[d] + thespacing[d] *
      (+ (is_internal[2*d+1] ? 0 : nboundaryzones[2*d+1] - 1)
       + (is_staggered[2*d+1] ? 0.5 : 0.0)
       + shiftout[2*d+1]);
  
    interior_min[d] = exterior_min[d] + thespacing[d] * nboundaryzones[2*d];
    interior_max[d] = exterior_max[d] - thespacing[d] * nboundaryzones[2*d+1];

  }
  
  return 0;
}



CCTK_INT CoordBase_ConvertFromInteriorBoundary
  (CCTK_INT const size,
   CCTK_REAL * const physical_min,
   CCTK_REAL * const physical_max,
   CCTK_REAL const * const interior_min,
   CCTK_REAL const * const interior_max,
   CCTK_REAL * const exterior_min,
   CCTK_REAL * const exterior_max,
   CCTK_REAL const * const thespacing)
{
  CCTK_INT nboundaryzones[6];
  CCTK_INT is_internal[6];
  CCTK_INT is_staggered[6];
  CCTK_INT shiftout[6];
  
  int d;
  int ierr;
  
  if(! (size>=0))
    CCTK_WARN (0, "size is out of bounds");
  if(! (physical_min))
    CCTK_WARN (0, "physical_min is out of bounds");
  if(! (physical_max))
    CCTK_WARN (0, "physical_max is out of bounds");
  if(! (interior_min))
    CCTK_WARN (0, "interior_min is out of bounds");
  if(! (interior_max))
    CCTK_WARN (0, "interior_max is out of bounds");
  if(! (exterior_min))
    CCTK_WARN (0, "exterior_min is out of bounds");
  if(! (exterior_max))
    CCTK_WARN (0, "exterior_max is out of bounds");
  if(! (thespacing))
    CCTK_WARN (0, "thespacing is out of bounds");

  if(! (size == 3))
    CCTK_WARN (0, "size is out of bounds");  
  
  ierr = CoordBase_GetBoundarySpecification
    (6, nboundaryzones, is_internal, is_staggered, shiftout);
  if (ierr)
    CCTK_VWarn (0, __LINE__, __FILE__, "CactusBase", "error returned from function CoordBase_GetBoundarySpecification");
  
  for (d=0; d<3; ++d) {
    
    exterior_min[d] = interior_min[d] - thespacing[d] * nboundaryzones[2*d];
    exterior_max[d] = interior_max[d] + thespacing[d] * nboundaryzones[2*d+1];

    physical_min[d] = exterior_min[d] + thespacing[d] *
      (+ (is_internal[2*d] ? 0 : nboundaryzones[2*d] - 1)
       + (is_staggered[2*d] ? 0.5 : 0.0)
       + shiftout[2*d]);
    physical_max[d] = exterior_max[d] - thespacing[d] *
      (+ (is_internal[2*d+1] ? 0 : nboundaryzones[2*d+1] - 1)
       + (is_staggered[2*d+1] ? 0.5 : 0.0)
       + shiftout[2*d+1]);
  
  }
  
  return 0;
}



CCTK_INT CoordBase_ConvertFromExteriorBoundary
  (CCTK_INT const size,
   CCTK_REAL * const physical_min,
   CCTK_REAL * const physical_max,
   CCTK_REAL * const interior_min,
   CCTK_REAL * const interior_max,
   CCTK_REAL const * const exterior_min,
   CCTK_REAL const * const exterior_max,
   CCTK_REAL const * const thespacing)
{
  CCTK_INT nboundaryzones[6];
  CCTK_INT is_internal[6];
  CCTK_INT is_staggered[6];
  CCTK_INT shiftout[6];
  
  int d;
  int ierr;
  
  if(! (size>=0))
    CCTK_WARN (0, "size is out of bounds");
  if(! (physical_min))
    CCTK_WARN (0, "physical_min is out of bounds");
  if(! (physical_max))
    CCTK_WARN (0, "physical_max is out of bounds");
  if(! (interior_min))
    CCTK_WARN (0, "interior_min is out of bounds");
  if(! (interior_max))
    CCTK_WARN (0, "interior_max is out of bounds");
  if(! (exterior_min))
    CCTK_WARN (0, "exterior_min is out of bounds");
  if(! (exterior_max))
    CCTK_WARN (0, "exterior_max is out of bounds");
  if(! (thespacing))
    CCTK_WARN (0, "thespacing is out of bounds");

  if(! (size == 3))
    CCTK_WARN (0, "size is out of bounds");  
  
  ierr = CoordBase_GetBoundarySpecification
    (6, nboundaryzones, is_internal, is_staggered, shiftout);
  if (ierr)
    CCTK_WARN (0, "Error returned from CoordBase_GetBoundarySpecification");  
  
  for (d=0; d<3; ++d) {
    
    physical_min[d] = exterior_min[d] + thespacing[d] *
      (+ (is_internal[2*d] ? 0 : nboundaryzones[2*d] - 1)
       + (is_staggered[2*d] ? 0.5 : 0.0)
       + shiftout[2*d]);
    physical_max[d] = exterior_max[d] - thespacing[d] *
      (+ (is_internal[2*d+1] ? 0 : nboundaryzones[2*d+1] - 1)
       + (is_staggered[2*d+1] ? 0.5 : 0.0)
       + shiftout[2*d+1]);
  
    interior_min[d] = exterior_min[d] + thespacing[d] * nboundaryzones[2*d];
    interior_max[d] = exterior_max[d] - thespacing[d] * nboundaryzones[2*d+1];

  }
  
  return 0;
}



CCTK_INT CoordBase_GetBoundarySizesAndTypes
  (CCTK_POINTER_TO_CONST const cctkGH_,
   CCTK_INT const size,
   CCTK_INT * restrict const bndsize,
   CCTK_INT * restrict const is_ghostbnd,
   CCTK_INT * restrict const is_symbnd, 
   CCTK_INT * restrict const is_physbnd)
{
  cGH const * restrict const cctkGH = cctkGH_;
  
  /* Check arguments */
  int const dim = cctkGH->cctk_dim;
  if (size != 2*dim) {
    CCTK_WARN(CCTK_WARN_ABORT, "Inconsistent size argument");
  }
  
  /* Obtain multi-patch bbox information, specifying which boundaries
     are set by a multi-patch system (bbox=1) and which by a physical
     boundary condition (bbox=0) */
  CCTK_INT mp_bbox[2*dim];
  if (CCTK_IsFunctionAliased("MultiPatch_GetBbox")) {
    int const ierr = MultiPatch_GetBbox(cctkGH, 2*dim, mp_bbox);
    if (ierr != 0) {
      CCTK_WARN(CCTK_WARN_ABORT,
                "Could not obtain multi-patch bbox specification");
    }
  } else {
    for (int d=0; d<2*dim; ++d) {
      mp_bbox[d] = 0;
    }
  }
  
  /* Obtain boundary information */
  CCTK_INT nboundaryzones[2*dim];
  CCTK_INT is_internal[2*dim];
  CCTK_INT is_staggered[2*dim];
  CCTK_INT shiftout[2*dim];
  if (CCTK_IsFunctionAliased("MultiPatch_GetBoundarySpecification")) {
    /* We are using a multi-patch system */
    int const map = MultiPatch_GetMap(cctkGH);
    if (map < 0) {
      CCTK_WARN(CCTK_WARN_ABORT, "Could not determine current map (need to be called in local mode)");
    }
    int const ierr = MultiPatch_GetBoundarySpecification
      (map, 2*dim, nboundaryzones, is_internal, is_staggered, shiftout);
    if (ierr != 0) {
      CCTK_WARN(CCTK_WARN_ABORT, "Could not obtain boundary specification");
    }
  } else if (CCTK_IsFunctionAliased("GetBoundarySpecification")) {
    /* We are not using a multi-patch system */
    int const ierr = GetBoundarySpecification
      (2*dim, nboundaryzones, is_internal, is_staggered, shiftout);
    if (ierr != 0) {
      CCTK_WARN(CCTK_WARN_ABORT, "Could not obtain boundary specification");
    }
  } else {
    CCTK_WARN(CCTK_WARN_ABORT, "Could not obtain boundary specification");
  }
  
  /* Obtain symmetry information */
  int const symtable = SymmetryTableHandleForGrid(cctkGH);
  if (symtable < 0) {
    CCTK_WARN(CCTK_WARN_ABORT, "Could not obtain symmetry table");
  }
  CCTK_INT symbnd[2*dim];
  int const iret =
    Util_TableGetIntArray(symtable, 2*dim, symbnd, "symmetry_handle");
  if (iret != 2*dim) {
    CCTK_WARN(CCTK_WARN_ABORT, "Could not obtain symmetry information");
  }
  
  /* Determine boundary types */
  for (int d=0; d<2*dim; ++d) {
    /* Ghost boundaries (inter-process or mesh refinement boundaries)
       have cctk_bbox=0 */
    is_ghostbnd[d] = !cctkGH->cctk_bbox[d];
    /* Symmetry boundaries are not ghost boundaries, are described as
       symmetry boundaries, and are not multi-patch outer
       boundaries */
    is_symbnd [d] = !is_ghostbnd[d] && symbnd[d]>=0 && !mp_bbox[d];
    /* Physical (outer) boundaries are all other boundaries */
    is_physbnd[d] = !is_ghostbnd[d] && !is_symbnd[d];
  }
  
  /* Determine boundary sizes */
  for (int dir=0; dir<dim; ++dir) {
    for (int face=0; face<2; ++face) {
      
      if (is_ghostbnd[2*dir+face]) {
	/* Ghost boundary */
	bndsize[2*dir+face] = cctkGH->cctk_nghostzones[dir];
      } else  {
	/* Symmetry or physical boundary */
	bndsize[2*dir+face] = nboundaryzones[2*dir+face];
        
	if (is_symbnd[2*dir+face]) {
	  /* Ensure that the number of symmetry zones is the same as
	     the number of ghost zones */
	  if (bndsize[2*dir+face] != cctkGH->cctk_nghostzones[dir]) {
	    CCTK_WARN(CCTK_WARN_ALERT,
                      "The number of symmetry points is different from the number of ghost points; this is probably an error");
	  }
	}
      }
    }
  }
  
  return 0;
}