aboutsummaryrefslogtreecommitdiff
path: root/src/Startup.c
blob: 722f4bb25c48c1c2844b1b939c89785a3f853d41 (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
 /*@@
   @file      Startup.c
   @date      Mon Mar 15 15:48:42 1999
   @author    Gerd Lanfermann
   @desc
              Startup file to register the GHextension and coordinates
   @enddesc
   @version   $Id$
 @@*/

#include <stdlib.h>

#include "cctk.h"
#include "cctk_Arguments.h"
#include "cctk_Parameters.h"
#include "util_Table.h"

#include "CoordBase.h"
#include "Symmetry.h"

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


/********************************************************************
 ********************    External Prototypes   **********************
 ********************************************************************/
void SymmetryStartup (void);
int RegisterCartGrid3DCoords (CCTK_ARGUMENTS);

/********************************************************************
 ********************    Internal Prototypes   **********************
 ********************************************************************/
static void *SetupGH (tFleshConfig *config, int convlevel, cGH *GH);

/********************************************************************
 ********************    External Routines   ************************
 ********************************************************************/
 /*@@
   @routine    SymmetryStartup
   @date       Mon Mar 15 15:49:16 1999
   @author     Gerd Lanfermann
   @desc
               Routine registers the GH extension for CartGrid3D
               along with its setup routine.
   @enddesc
   @calls      CCTK_RegisterGHExtension
               CCTK_RegisterGHExtensionSetupGH
   @history
   @endhistory

   @returntype void
@@*/
void SymmetryStartup (void)
{
  CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("Symmetry"),
                                   SetupGH);
}


 /*@@
   @routine    RegisterCartGrid3DCoords
   @date
   @author     Gabrielle Allen
   @desc 
               Routine registers the coordinates provided by
               CartGrid3D, using both the new and old APIs.  The old
               CCTK_ API is deprecated.
   @enddesc
   @calls      CCTK_CoordRegisterSystem
               CCTK_CoordRegisterData

   @returntype int
   @returndesc
               0 for success, or negative in case of errors
   @endreturndesc
@@*/
int RegisterCartGrid3DCoords (CCTK_ARGUMENTS)
{
  DECLARE_CCTK_ARGUMENTS;
  DECLARE_CCTK_PARAMETERS;

  int ierr, coord_system_handle, retval;

  retval = 0;

  /* Register coordinate systems */
  ierr =   Coord_SystemRegister(cctkGH, 3, "cart3d");
  ierr +=  Coord_SystemRegister(cctkGH, 2, "cart2d");
  ierr +=  Coord_SystemRegister(cctkGH, 1, "cart1d");
  if (ierr < 0)
  {
    CCTK_WARN(0, "Error registering cartnd coordinate systems");
    retval = ierr;
  }
  else
  {

    /* Register coordinates for cart3d */
    coord_system_handle = Coord_SystemHandle(cctkGH, "cart3d");
    if (coord_system_handle<0)
    {
      CCTK_VWarn(0,__LINE__,__FILE__,CCTK_THORNSTRING,
		 "Error obtaining system handle for cart3d");
    }
    ierr =  Coord_CoordRegister(cctkGH, coord_system_handle, 1, "x");
    ierr += Coord_CoordRegister(cctkGH, coord_system_handle, 2, "y");
    ierr += Coord_CoordRegister(cctkGH, coord_system_handle, 3, "z");
    if (ierr < 0)
    {
      CCTK_WARN(0, "Error registering cart3d coordinates");
      retval += ierr;
    }

    /* Fill out rest of coordinate system table for cart3d */
    ierr = Util_TableSetString(coord_system_handle, "uniform", "TYPE");
    if (ierr < 0)
    {
      CCTK_WARN(1, "Error registering cart3d type");
      retval += ierr;
    }    

    /* Register coordinates for cart2d */
    coord_system_handle = Coord_SystemHandle(cctkGH, "cart2d");
    if (coord_system_handle<0)
    {
      CCTK_VWarn(0,__LINE__,__FILE__,CCTK_THORNSTRING,
		 "Error obtaining system handle for cart2d");
    }
    ierr =  Coord_CoordRegister(cctkGH, coord_system_handle, 1, "x");
    ierr += Coord_CoordRegister(cctkGH, coord_system_handle, 2, "y");
    if (ierr < 0)
    {
      CCTK_WARN(0, "Error registering cart2d coordinates");
      retval += ierr;
    }

    /* Fill out rest of coordinate system table for cart2d */
    ierr = Util_TableSetString(coord_system_handle, "uniform", "TYPE");
    if (ierr < 0)
    {
      CCTK_WARN(1, "Error registering cart2d type");
      retval += ierr;
    }    

    /* Register coordinate for cart1d */
    coord_system_handle = Coord_SystemHandle(cctkGH, "cart1d");
    if (coord_system_handle<0)
    {
      CCTK_VWarn(0,__LINE__,__FILE__,CCTK_THORNSTRING,
		 "Error obtaining system handle for cart1d");
    }
    ierr =  Coord_CoordRegister(cctkGH, coord_system_handle, 1, "x");
    if (ierr < 0)
    {
      CCTK_WARN(0, "Error registering cart1d coordinate");
      retval += ierr;
    }

    /* Fill out rest of coordinate system table for cart1d */
    ierr = Util_TableSetString(coord_system_handle, "uniform", "TYPE");
    if (ierr < 0)
    {
      CCTK_WARN(1, "Error registering cart1d type");
      retval += ierr;
    }

    /* Register cartnd as the default coordinate systems */
    if (register_default_coordinate_systems)
    {
      ierr =  Coord_SetDefaultSystem(cctkGH, "cart3d");
      ierr += Coord_SetDefaultSystem(cctkGH, "cart2d");
      ierr += Coord_SetDefaultSystem(cctkGH, "cart1d");
      if (ierr < 0)
      {
	CCTK_WARN(1, "Error registering cartnd as default coordinate systems");
	retval += ierr;
      }
    }
  }

  /* Register coordinates under the old API */
  retval += CCTK_CoordRegisterSystem(3,"cart3d");
  retval += CCTK_CoordRegisterSystem(3,"spher3d");

  if (CCTK_CoordRegisterData (1, "grid::x", "x", "cart3d") < 0)
  {
    CCTK_WARN (1, "Problem with registering coordinate x");
    retval--;
  }
  if (CCTK_CoordRegisterData (2, "grid::y", "y", "cart3d") < 0)
  {
    CCTK_WARN (1, "Problem with registering coordinate y");
    retval--;
  }
  if (CCTK_CoordRegisterData (3, "grid::z", "z", "cart3d") < 0)
  {
    CCTK_WARN (1, "Problem with registering coordinate z");
    retval--;
  }
  if (CCTK_CoordRegisterData (1, "grid::r", "r", "spher3d") < 0)
  {
    CCTK_WARN (1, "Problem with registering coordinate r");
    retval--;
  }

  return retval;
}


/********************************************************************
 ********************    Internal Routines   ************************
 ********************************************************************/
static void *SetupGH (tFleshConfig *config, int convlevel, cGH *GH)
{
  int i, j, maxdim, numvars;
  SymmetryGHex *myGH;


  /* avoid compiler warnings about unused arguments */
  (void) (config + 0);
  (void) (convlevel + 0);
  (void) (GH + 0);

  maxdim = CCTK_MaxDim ();
  numvars = CCTK_NumVars ();

  /* allocate the GH extension */
  myGH = (SymmetryGHex *) malloc (sizeof (SymmetryGHex));
  if (myGH)
  {
    /* allocation for the number of grid functions */
    myGH->GFSym = (int **) malloc (numvars * sizeof (int *));

    /* allocation for the number of dimensions*/
    for (i = 0; i < numvars; i++)
    {
      myGH->GFSym[i] = (int *) malloc (2 * maxdim * sizeof (int));

      for (j = 0; j < 2 * maxdim; j++)
      {
        myGH->GFSym[i][j] = GFSYM_UNSET;  /* not set */
      }
    }
  }

  return (myGH);
}