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
|
/*@@
@file Interp.c
@date July 07 1999
@author Thomas Radke
@desc
This file contains routines to deal with registering and
using functions providing interpolation operations.
@enddesc
@history
@date July 07 1999
@author Thomas Radke
@hdesc Just copied from Reduction.c
@endhistory
@@*/
/*#define DEBUG_INTERP*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <stdarg.h>
#include "cctk.h"
#include "flesh.h"
#include "FortranString.h"
#include "Groups.h"
#include "StoreHandledData.h"
#include "Interp.h"
#include "WarnLevel.h"
static cHandledData *InterpOperators = NULL;
static int num_interps = 0;
/*@@
@routine CCTK_RegisterInterpOperator
@date July 07 1999
@author Thomas Radke
@desc
Registers "function" as an interpolation operator called "name"
@enddesc
@var function
@vdesc Routine containing interpolation operator
@vtype (int (*))
@vio
@vcomment
@endvar
@var name
@vdesc String containing name of interpolation operator
@vtype const char *
@vio in
@vcomment
@endvar
@@*/
int CCTK_RegisterInterpOperator(int (*function)(REGISTER_INTERP_ARGLIST),
const char *name)
{
int handle;
/* Check that the method hasn't already been registered */
handle = CCTK_GetHandle(InterpOperators, name, NULL);
if(handle < 0)
{
/* Get a handle for it. */
handle = CCTK_NewHandle(&InterpOperators, name, (void *)function);
/* Remember how many interpolation operators there are */
num_interps++;
}
else
{
/* Interpolation operator with this name already exists. */
CCTK_WARN(1,"Interpolation operator with this name already exists");
handle = -1;
}
#ifdef DEBUG_INTERP
CCTK_PRINTSEPARATOR
printf("In CCTK_RegisterInterpOperator\n");
printf("---------------------------------\n");
printf(" Registering %s with handle %d\n",name,handle);
CCTK_PRINTSEPARATOR
#endif
return handle;
}
/*@@
@routine CCTK_GetInterpHandle
@date July 07 1999
@author Thomas Radke
@desc
Returns the handle of a given interpolation operator
@enddesc
@var interp
@vdesc String containing name of interpolation operator
@vtype const char *
@vio in
@vcomment
@endvar
@@*/
int CCTK_GetInterpHandle(const char *interp)
{
int handle;
void **data=NULL; /* isn't used here */
handle = CCTK_GetHandle(InterpOperators, interp, data);
#ifdef DEBUG_INTERP
CCTK_PRINTSEPARATOR
printf("In CCTK_GetInterpHandle\n");
printf("--------------------------\n");
printf(" Got handle %d for %s\n",handle,interp);
CCTK_PRINTSEPARATOR
#endif
if (handle < 0)
CCTK_WARN(1,"No handle found for this interpolation operator");
return handle;
}
void FMODIFIER FORTRAN_NAME(CCTK_GetInterpHandle)(int *handle, ONE_FORTSTRING_ARG)
{
ONE_FORTSTRING_CREATE(interp)
*handle = CCTK_GetInterpHandle(interp);
free(interp);
}
/*@@
@routine CCTK_Interp
@date July 07 1999
@author Thomas Radke
@desc
The CCTK interpolation routine
Just puts the arguments from the variable argument list
into arrays and calls the appropriate interpolation operator.
@enddesc
@var GH
@vdesc pointer to CCTK grid hierarchy
@vtype cGH *
@vio in
@endvar
@var operation_handle
@vdesc handle for the interpolation operator
@vtype int
@vio in
@endvar
@var nPoints
@vdesc number of points to interpolate at
@vtype int
@vio in
@endvar
@var nCoords
@vdesc number of passed coordinate fields
@vtype int
@vio in
@endvar
@var nInFields
@vdesc number of passed input fields
@vtype int
@vio in
@endvar
@var nOutFields
@vdesc number of passed output fields
@vtype int
@vio in
@vcomment end of fixed argument list
@endvar
@var coords
@vdesc coordinates of points to interpolate at
@vtype void * [nCoords]
@vio in
@endvar
@var coordTypes
@vdesc types of passed coordinate fields
@vtype int [nCoords]
@vio in
@endvar
@var inFieldIndices
@vdesc indices of GF to interpolate from
@vtype int [nInfields]
@vio in
@endvar
@var outFields
@vdesc pointer to arrays to hold the interpolation results
@vtype void * [nOutfields]
@vio in
@endvar
@var outFieldTypes
@vdesc types of arrays to hold the interpolation results
@vtype int [nOutfields]
@vio in
@endvar
@@*/
int CCTK_Interp (cGH *GH,
int operation_handle,
int nPoints,
int nCoords,
int nInFields,
int nOutFields,
...)
{
va_list indices;
int i;
void **coords;
int *coordTypes;
int *inFieldIndices;
void **outFields;
int *outFieldTypes;
int (*function)(REGISTER_INTERP_ARGLIST)=NULL;
i = 0;
/* Get the pointer to the interpolation operator */
if (operation_handle < 0)
CCTK_WARN(3,"Invalid handle passed to CCTK_Interp");
else
{
function = (int (*)(REGISTER_INTERP_ARGLIST))
CCTK_GetHandledData(InterpOperators,operation_handle);
if (function)
{
coords = (void **) malloc (nCoords * sizeof (void *));
coordTypes = (int *) malloc (nCoords * sizeof (int));
inFieldIndices = (int *) malloc (nInFields * sizeof (int));
outFields = (void **) malloc (nOutFields * sizeof (void *));
outFieldTypes = (int *) malloc (nOutFields * sizeof (int));
/* Fill in the arrays from the variable argument list */
va_start (indices, nOutFields);
for (i = 0; i < nCoords; i++)
coords [i] = va_arg (indices, void *);
for (i = 0; i < nCoords; i++)
coordTypes [i] = va_arg (indices, int);
for (i = 0; i < nInFields; i++)
inFieldIndices [i] = va_arg (indices, int);
for (i = 0; i < nOutFields; i++)
outFields [i] = va_arg (indices, void *);
for (i = 0; i < nOutFields; i++)
outFieldTypes [i] = va_arg (indices, int);
va_end (indices);
i = function(GH, nPoints, nCoords, nInFields, nOutFields,
coords, coordTypes,inFieldIndices, outFields, outFieldTypes);
free (outFieldTypes);
free (outFields);
free (inFieldIndices);
free (coordTypes);
free (coords);
}
else
CCTK_WARN(3,"Interpolation operation is not registered and cannot be called");
}
return i;
}
void FMODIFIER FORTRAN_NAME(CCTK_Interp)(cGH *GH,
int *fortranreturn,
int *operation_handle,
int *nPoints,
int *nCoords,
int *nInFields,
int *nOutFields,
...)
{
va_list indices;
int i;
void **coords;
int *coordTypes;
int *inFieldIndices;
void **outFields;
int *outFieldTypes;
int (*function)(REGISTER_INTERP_ARGLIST)=NULL;
i = 0;
/* Get the pointer to the interpolation operator */
if (*operation_handle < 0)
CCTK_WARN(3,"Invalid handle passed to CCTK_Interp");
else
{
function = (int (*)(REGISTER_INTERP_ARGLIST))
CCTK_GetHandledData(InterpOperators,*operation_handle);
if (function)
{
coords = (void **) malloc (*nCoords * sizeof (void *));
coordTypes = (int *) malloc (*nCoords * sizeof (int));
inFieldIndices = (int *) malloc (*nInFields * sizeof (int));
outFields = (void **) malloc (*nOutFields * sizeof (void *));
outFieldTypes = (int *) malloc (*nOutFields * sizeof (int));
/* Fill in the arrays from the variable argument list */
va_start (indices, nOutFields);
for (i = 0; i < *nCoords; i++)
coords [i] = va_arg (indices, void *);
for (i = 0; i < *nCoords; i++)
coordTypes [i] = *va_arg (indices, int *);
for (i = 0; i < *nInFields; i++)
inFieldIndices [i] = *va_arg (indices, int *);
for (i = 0; i < *nOutFields; i++)
outFields [i] = va_arg (indices, void *);
for (i = 0; i < *nOutFields; i++)
outFieldTypes [i] = *va_arg (indices, int *);
va_end (indices);
i = function(GH, *nPoints, *nCoords, *nInFields, *nOutFields,
coords, coordTypes,inFieldIndices, outFields, outFieldTypes);
free (outFieldTypes);
free (outFields);
free (inFieldIndices);
free (coordTypes);
free (coords);
}
else
CCTK_WARN(3,"Interpolation operation is not registered and cannot be called");
}
*fortranreturn = i;
}
|