aboutsummaryrefslogtreecommitdiff
path: root/src/Startup.c
blob: 69be43601657577f28b9b1d02a047fd7dc1a3391 (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
 /*@@
   @file      Startup.c
   @date      Sun Jul 04 1999
   @author    Thomas Radke
   @desc
              Startup routines for PUGHInterp
   @enddesc
   @version   $Id$
 @@*/

#include <stdlib.h>

#include "cctk.h"
#include "util_Table.h"
#include "cctk_Interp.h"
#include "pughInterpGH.h"

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


/********************************************************************
 ********************    External Routines   ************************
 ********************************************************************/
void PUGHInterp_Startup (void);


/********************************************************************
 ********************    Internal Routines   ************************
 ********************************************************************/
#ifdef CCTK_MPI
static void *SetupGH (tFleshConfig *config, int convergence_level, cGH *GH);
#endif
static int InterpGV_1stOrder (cGH *GH,
                              const char *coord_system,
                              int num_points,
                              int num_in_array_indices,
                              int num_out_arrays,
                              const void *const interp_coord_arrays[],
                              const int interp_coord_array_types[],
                              const int in_array_indices[],
                              void *const out_arrays[],
                              const int out_array_types[]);
static int InterpGV_2ndOrder (cGH *GH,
                              const char *coord_system,
                              int num_points,
                              int num_in_array_indices,
                              int num_out_arrays,
                              const void *const interp_coord_arrays[],
                              const int interp_coord_array_types[],
                              const int in_array_indices[],
                              void *const out_arrays[],
                              const int out_array_types[]);
static int InterpGV_3rdOrder (cGH *GH,
                              const char *coord_system,
                              int num_points,
                              int num_in_array_indices,
                              int num_out_arrays,
                              const void *const interp_coord_arrays[],
                              const int interp_coord_array_types[],
                              const int in_array_indices[],
                              void *const out_arrays[],
                              const int out_array_types[]);
static int PUGHInterp_InterpGV (cGH *GH,
                                int order,
                                const char *local_interpolator,
                                const char *coord_system_name,
                                int N_points,
                                int N_input_arrays,
                                int N_output_arrays,
                                const void *const interp_coord_arrays[],
                                const int interp_coord_array_types[],
                                const int input_array_indices[],
                                void *const output_arrays[],
                                const int output_array_types[]);


 /*@@
   @routine   PUGHInterp_Startup
   @date      Sun Jul 04 1999
   @author    Thomas Radke
   @desc
              The startup registration routine for PUGHInterp.
              Registers the PUGHInterp GH extensions setup routine
              and the interpolation operators with the flesh.
   @enddesc
   @calls     CCTK_OverloadInterpGridArrays
              CCTK_RegisterGHExtensionSetupGH
              CCTK_InterpRegisterOperatorGV
@@*/
void PUGHInterp_Startup (void)
{
  CCTK_OverloadInterpGridArrays (PUGHInterp_InterpGridArrays);

#ifdef CCTK_MPI
  CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("PUGHInterp"),
                                   SetupGH);
#endif

  CCTK_InterpRegisterOperatorGV (InterpGV_1stOrder,
                                 "first-order uniform cartesian");
  CCTK_InterpRegisterOperatorGV (InterpGV_2ndOrder,
                                 "second-order uniform cartesian");
  CCTK_InterpRegisterOperatorGV (InterpGV_3rdOrder,
                                 "third-order uniform cartesian");
}


/********************************************************************
 ********************    Internal Routines   ************************
 ********************************************************************/
#ifdef CCTK_MPI
 /*@@
   @routine   SetupGH
   @date      Sun Jul 04 1999
   @author    Thomas Radke
   @desc
              Allocates the GH extension structure and - for the MPI case -
              the count/displacement buffers used in MPI_Alltoall()
              and MPI_Alltoallv()
   @enddesc
   @calls     CCTK_nProcs

   @returntype void *
   @returndesc
               pointer to the allocated GH extension structure
   @endreturndesc
@@*/
static void *SetupGH (tFleshConfig *config, int convergence_level, cGH *GH)
{
  int nprocs;
  pughInterpGH *myGH;


  /* suppress compiler warnings about unused variables */
  (void) (config + 0);
  (void) (convergence_level + 0);

  myGH = malloc (sizeof (pughInterpGH));

  /* allocate once for all fields of same type */
  nprocs = CCTK_nProcs (GH);
  myGH->sendcnt = malloc (4 * nprocs * sizeof (int));
  myGH->senddispl = myGH->sendcnt + nprocs;
  myGH->recvcnt = myGH->senddispl + nprocs;
  myGH->recvdispl = myGH->recvcnt + nprocs;

  myGH->N_points_from = malloc (2 * nprocs * sizeof (CCTK_INT));
  myGH->N_points_to   = myGH->N_points_from + nprocs;

  return (myGH);
}
#endif /* CCTK_MPI */


 /*@@
   @routine   InterpGV_NthOrder
   @date      Wed 14 Feb 2001
   @author    Thomas Radke
   @desc
              Wrappers for the different interpolation operators
              registered for first/second/third order interpolation.
              These wrappers just call the common interpolation routine
              passing all arguments plus the interpolation order.
   @enddesc

   @returntype int
   @returndesc
               the return code of the common interpolation routine
   @endreturndesc
@@*/
static int InterpGV_1stOrder (cGH *GH,
                              const char *coord_system,
                              int num_points,
                              int num_in_array_indices,
                              int num_out_arrays,
                              const void *const interp_coord_arrays[],
                              const int interp_coord_array_types[],
                              const int in_array_indices[],
                              void *const out_arrays[],
                              const int out_array_types[])
{
  return (PUGHInterp_InterpGV (GH, 1, "first-order uniform cartesian",
                               coord_system, num_points,
                               num_in_array_indices, num_out_arrays,
                               interp_coord_arrays, interp_coord_array_types,
                               in_array_indices, out_arrays, out_array_types));
}


static int InterpGV_2ndOrder (cGH *GH,
                              const char *coord_system,
                              int num_points,
                              int num_in_array_indices,
                              int num_out_arrays,
                              const void *const interp_coord_arrays[],
                              const int interp_coord_array_types[],
                              const int in_array_indices[],
                              void *const out_arrays[],
                              const int out_array_types[])
{
  return (PUGHInterp_InterpGV (GH, 2, "second-order uniform cartesian",
                               coord_system, num_points,
                               num_in_array_indices, num_out_arrays,
                               interp_coord_arrays, interp_coord_array_types,
                               in_array_indices, out_arrays, out_array_types));
}


static int InterpGV_3rdOrder (cGH *GH,
                              const char *coord_system,
                              int num_points,
                              int num_in_array_indices,
                              int num_out_arrays,
                              const void *const interp_coord_arrays[],
                              const int interp_coord_array_types[],
                              const int in_array_indices[],
                              void *const out_arrays[],
                              const int out_array_types[])
{
  return (PUGHInterp_InterpGV (GH, 3, "third-order uniform cartesian",
                               coord_system, num_points,
                               num_in_array_indices, num_out_arrays,
                               interp_coord_arrays, interp_coord_array_types,
                               in_array_indices, out_arrays, out_array_types));
}


static int PUGHInterp_InterpGV (cGH *GH,
                                int order,
                                const char *local_interpolator,
                                const char *coord_system_name,
                                int N_points,
                                int N_input_arrays,
                                int N_output_arrays,
                                const void *const interp_coord_arrays[],
                                const int interp_coord_array_types[],
                                const int input_array_indices[],
                                void *const output_arrays[],
                                const int output_array_types[])
{
  int i, N_dims, retval;
  int local_interp_handle, param_table_handle, coord_system_handle;
  char table_string[64];
  CCTK_INT *_input_array_indices, *_output_array_types;
  union
  {
    const cGH *const_GH;
          cGH *non_const_GH;
  } _GH;


  _GH.non_const_GH = GH;

  /* get dimensionality of the coordinate system */
  N_dims = CCTK_CoordSystemDim (coord_system_name);
  if (N_dims <= 0)
  {
    CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
                "Cannot get dimensions of coordinate system '%s'",
                coord_system_name);
    return (-1);
  }
  coord_system_handle = CCTK_CoordSystemHandle (coord_system_name);
  local_interp_handle = CCTK_InterpHandle (local_interpolator);

  /* turn native datatype arrays into CCTK_ datatypes */
  _input_array_indices = malloc (2 * N_dims * sizeof (CCTK_INT));
  _output_array_types = _input_array_indices + N_dims;
  for (i = 0; i < N_dims; i++)
  {
    _input_array_indices[i] = input_array_indices[i];
    _output_array_types[i] = output_array_types[i];
  }

  /* set up the parameter table (only supported option is "order") */
  sprintf (table_string, "order = %d", order);
  param_table_handle = Util_TableCreateFromString (table_string);

  retval = PUGHInterp_InterpGridArrays (_GH.const_GH, N_dims,
                                        local_interp_handle, param_table_handle,
                                        coord_system_handle,
                                        N_points,
                                        interp_coord_array_types[0],
                                        interp_coord_arrays,
                                        N_input_arrays,
                                        _input_array_indices,
                                        N_output_arrays,
                                        _output_array_types,
                                        output_arrays);

  /* release resources */
  Util_TableDestroy (param_table_handle);
  free (_input_array_indices);

  return (retval);
}