aboutsummaryrefslogtreecommitdiff
path: root/src/Interpolation.c
blob: 2ae8a2eec96ee04a2a0c645382580ef2ddb1798c (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
/*@@
  @file      Interpolation.c
  @author    Erik Schnetter
  @date      2004-05-11
  @desc
             Apply symmetry conditions during interpolation
  @version   $Header$
  @enddesc
@@*/

#include <stdio.h>

#include "cctk.h"
#include "cctk_Arguments.h"

#include "util_ErrorCodes.h"
#include "util_Table.h"

#include "SymBase.h"



/* the rcs ID and its dummy function to use it */
static const char *const rcsid = "$Header$";
CCTK_FILEVERSION (CactusBase_SymBase_Interpolation_c);



/*@@
  @routine    SymBase_SymmetryInterpolate
  @author     Erik Schnetter
  @date       2004-05-11
  @desc
              Adjust the coordinates of the interpolation points,
              call the driver's interpolation function,
              and then adjust the interpolated tensor components.
              All arguments are equivalent to the CCTK_InterpGridArrays
              function call.
  @enddesc
  @var        cctkGH
  @vtype      CCTK_POINTER_TO_CONST
  @vdesc      Grid hierarchy
  @vio        in
  @endvar
  @var        N_dims
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        local_interp_handle
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        param_table_handle
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        coord_system_handle
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        N_interp_points
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        interp_coords_type
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        interp_coords
  @vtype      CCTK_POINTER_TO_CONST[]
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        N_input_arrays
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        input_array_indices
  @vtype      CCTK_INT[]
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        N_output_arrays
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        output_array_types
  @vtype      CCTK_INT[]
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        output_arrays
  @vtype      CCTK_POINTER[]
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @returntype CCTK_INT
  @returndesc
              status code
              0 for success
              -91 GH is NULL
              -92 N_dims is not equal to cctkGH->cctk_dim
              -93 Input array has illegal group type
              -94 Mixing grid functions and grid arrays
  @endreturndesc
@@*/

CCTK_INT
SymBase_SymmetryInterpolate (CCTK_POINTER_TO_CONST const cctkGH_,
                             CCTK_INT const N_dims,
                             CCTK_INT const local_interp_handle,
                             CCTK_INT const param_table_handle,
                             CCTK_INT const coord_system_handle,
                             CCTK_INT const N_interp_points,
                             CCTK_INT const interp_coords_type,
                             CCTK_POINTER_TO_CONST const interp_coords[],
                             CCTK_INT const N_input_arrays,
                             CCTK_INT const input_array_indices[],
                             CCTK_INT const N_output_arrays,
                             CCTK_INT const output_array_types[],
                             CCTK_POINTER const output_arrays[])
{
  cGH const * restrict const cctkGH = cctkGH_;
  CCTK_INT sym_table;
  CCTK_FPOINTER symmetry_interpolate[100];
  CCTK_INT faces;
  int has_grid_arrays, has_only_grid_arrays;
  int n;
  int f;
  int ierr;
  
  /* Check arguments */
  if (! cctkGH)
  {
    CCTK_WARN (1, "cctkGH is NULL");
    return -91;
  }
  
  /* If this interpolates grid arrays, then do not apply symmetries --
     there are no symmetries registered for grid arrays (yet).  */
  has_grid_arrays = 0;
  has_only_grid_arrays = 1;
  for (n=0; n<N_input_arrays; ++n)
  {
    if (input_array_indices[n] != -1) {
      switch (CCTK_GroupTypeFromVarI (input_array_indices[n]))
      {
      case CCTK_GF:
        has_only_grid_arrays = 0;
        break;
      case CCTK_SCALAR:
      case CCTK_ARRAY:
        has_grid_arrays = 1;
        break;
      default:
        CCTK_WARN (1, "Could not determine group type of input arrays");
        return -93;
      }
    }
  }
  if (has_grid_arrays && ! has_only_grid_arrays)
  {
    CCTK_WARN (1, "The input arrays contain both grid function and grid arrays; this is not possible");
    return -94;
  }
  if (has_grid_arrays)
  {
    /* Call the real interpolator */
    ierr = CCTK_IsFunctionAliased ("DriverInterpolate");
    if (! ierr)
    {
      CCTK_WARN (0, "The aliased function \"DriverInterpolate\" has not been provided");
    }
    return DriverInterpolate
      (cctkGH, N_dims,
       local_interp_handle, param_table_handle, coord_system_handle,
       N_interp_points, interp_coords_type, interp_coords,
       N_input_arrays, input_array_indices,
       N_output_arrays, output_array_types, output_arrays);
  }
  
  /* Check arguments */
  if (N_dims != cctkGH->cctk_dim)
  {
    CCTK_WARN (1, "The number of dimensions is not equal to the GH's number of dimensions");
    return -92;
  }
  
  /* Get table */
  sym_table = SymmetryTableHandleForGrid (cctkGH);
  if (sym_table < 0) CCTK_WARN (0, "internal error");

  /* Get table entries */
  if (2 * cctkGH->cctk_dim > 100)
  {
    CCTK_WARN (0, "internal error");
  }
  ierr = Util_TableGetFPointerArray
    (sym_table, 2 * cctkGH->cctk_dim,
     symmetry_interpolate, "symmetry_interpolate");
  if (ierr != 2 * cctkGH->cctk_dim)
  {
    CCTK_WARN (0, "internal error");
  }
  
  /* Find all faces that need symmetries applied */
  faces = 0;
  for (f=0; f<2*cctkGH->cctk_dim; ++f) {
    if (symmetry_interpolate[f]) {
      faces |= (1 << f);
    }
  }
  
  /* Forward the call */
  return SymBase_SymmetryInterpolateFaces
    (cctkGH, N_dims,
     local_interp_handle, param_table_handle, coord_system_handle,
     N_interp_points, interp_coords_type, interp_coords,
     N_input_arrays, input_array_indices,
     N_output_arrays, output_array_types, output_arrays,
     faces);
}



/*@@
  @routine    SymBase_SymmetryInterpolateFaces
  @author     Erik Schnetter
  @date       2004-05-11
  @desc
              Adjust the coordinates of the interpolation points,
              call the driver's interpolation function,
              and then adjust the interpolated tensor components,
              but only for the selected faces.
              When no faces are selected, forward the call to the
              driver's interpolator throug the aliased function
              "DriverInterpolate".
              All arguments except "faces" are equivalent to the
              CCTK_InterpGridArrays function call.
  @enddesc
  @var        cctkGH
  @vtype      CCTK_POINTER_TO_CONST
  @vdesc      Grid hierarchy
  @vio        in
  @endvar
  @var        N_dims
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        local_interp_handle
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        param_table_handle
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        coord_system_handle
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        N_interp_points
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        interp_coords_type
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        interp_coords
  @vtype      CCTK_POINTER_TO_CONST[]
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        N_input_arrays
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        input_array_indices
  @vtype      CCTK_INT[]
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        N_output_arrays
  @vtype      CCTK_INT
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        output_array_types
  @vtype      CCTK_INT[]
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        output_arrays
  @vtype      CCTK_POINTER[]
  @vdesc      same as for the CCTK_InterpGridArrays call
  @vio        in
  @endvar
  @var        faces
  @vtype      CCTK_INT
  @vdesc      Bit mask selecting which faces' symmetries should be treated.
  @vio        in
  @endvar
  @returntype CCTK_INT
  @returndesc
              status code
              0 for success
              -91 GH is NULL
              -92 N_dims is not equal to cctkGH->cctk_dim
              -93 faces is NULL
              or the return value from DriverInterpolate
  @endreturndesc
@@*/

CCTK_INT
SymBase_SymmetryInterpolateFaces (CCTK_POINTER_TO_CONST const cctkGH_,
                                  CCTK_INT const N_dims,
                                  CCTK_INT const local_interp_handle,
                                  CCTK_INT const param_table_handle,
                                  CCTK_INT const coord_system_handle,
                                  CCTK_INT const N_interp_points,
                                  CCTK_INT const interp_coords_type,
                                  CCTK_POINTER_TO_CONST const interp_coords[],
                                  CCTK_INT const N_input_arrays,
                                  CCTK_INT const input_array_indices[],
                                  CCTK_INT const N_output_arrays,
                                  CCTK_INT const output_array_types[],
                                  CCTK_POINTER const output_arrays[],
                                  CCTK_INT const faces)
{
  cGH const * restrict const cctkGH = cctkGH_;
  CCTK_INT sym_table;
  CCTK_FPOINTER symmetry_interpolate[100];
  int face;
  int ierr;
  
  /* Check arguments */
  
  if (! cctkGH)
  {
    CCTK_WARN (1, "cctkGH is NULL");
    return -91;
  }
  
  if (N_dims != cctkGH->cctk_dim)
  {
    CCTK_WARN (1, "The number of dimensions is not equal to the GH's number of dimensions");
    return -92;
  }
  
  /* Get table */
  sym_table = SymmetryTableHandleForGrid (cctkGH);
  if (sym_table < 0) CCTK_WARN (0, "internal error");

  /* Get table entries */
  if (2 * cctkGH->cctk_dim > 100)
  {
    CCTK_WARN (0, "internal error");
  }
  ierr = Util_TableGetFPointerArray
    (sym_table, 2 * cctkGH->cctk_dim,
     symmetry_interpolate, "symmetry_interpolate");
  if (ierr != 2 * cctkGH->cctk_dim)
  {
    CCTK_WARN (0, "internal error");
  }
  
  /* Find a face that needs a symmetry applied */
  for (face=0; face<2*N_dims; ++face)
  {
    if (faces & (1 << face))
    {
      break;
    }
  }
  
  if (face == 2*N_dims)
  {
    /* All faces are done */
    
    /* Call the real interpolator */
    ierr = CCTK_IsFunctionAliased ("DriverInterpolate");
    if (! ierr)
    {
      CCTK_WARN (0, "The aliased function \"DriverInterpolate\" has not been provided");
    }
    ierr = DriverInterpolate
      (cctkGH, N_dims,
       local_interp_handle, param_table_handle, coord_system_handle,
       N_interp_points, interp_coords_type, interp_coords,
       N_input_arrays, input_array_indices,
       N_output_arrays, output_array_types, output_arrays);
    
  }
  else
  {
    /* Treat the face */
    
    /* Recursive call to a symmetry condition */
    if (! symmetry_interpolate[face])
    {
      CCTK_WARN (0, "internal error");
    }
    ierr = ((SymmetryInterpolateFPointer)symmetry_interpolate[face])
      (cctkGH, N_dims,
       local_interp_handle, param_table_handle, coord_system_handle,
       N_interp_points, interp_coords_type, interp_coords,
       N_input_arrays, input_array_indices,
       N_output_arrays, output_array_types, output_arrays,
       faces);
    
  }
  
  return ierr;
}