aboutsummaryrefslogtreecommitdiff
path: root/src/GHExtension.c
blob: 1d5edea598038ab722765ffc227f182967a4183f (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
 /*@@
   @file      GHExtension.c
   @date      Sun Sept 22 2002
   @author    Gabrielle Allen and David Rideout
   @desc 
              CoordBase GHExtension setup
   @enddesc 
   @version   $Header$
 @@*/

#include <stdlib.h>

#include "cctk.h"
#include "coordbaseGH.h"
#include "util_Hash.h"

static const char *rcsid = "$Header$";

CCTK_FILEVERSION(CactusBase_CoordBase_GHExtension_c);

/********************************************************************
 *********************  Scheduled Routine Prototypes  ***************
 ********************************************************************/

void CoordBase_Startup (void);

/********************************************************************
 ********************* Local Routine Prototypes *********************
 ********************************************************************/

static void *CoordBase_SetupGH (tFleshConfig *config, int conv_level, cGH *GH);
static int CoordBase_InitGH (cGH *GH);

/********************************************************************
 *********************     External Routines   **********************
 ********************************************************************/

 /*@@
   @routine   CoordBase_Startup
   @date      Sunday Sept 22 2002
   @author    Gabrielle Allen
   @desc 
              The startup registration routine for CoordBase.
              Registers the GH extension needed for CoordBase.
   @enddesc 
   @calls     CCTK_RegisterGHExtension
              CCTK_RegisterGHExtensionSetupGH
	      CCTK_RegisterGHExtensionInitGH
@@*/
void CoordBase_Startup (void)
{
  int GHex_handle;

  GHex_handle = CCTK_RegisterGHExtension ("CoordBase");
  CCTK_RegisterGHExtensionSetupGH (GHex_handle, CoordBase_SetupGH);
  CCTK_RegisterGHExtensionInitGH  (GHex_handle, CoordBase_InitGH);
}


/********************************************************************
 ********************    Internal Routines   ************************
 ********************************************************************/

 /*@@
   @routine   CoordBase_SetupGH
   @date      Sun Sept 22 2002
   @author    Gabrielle Allen
   @desc 
              Allocates CoordBase's GH extension structure
   @enddesc 

   @calls     Util_HashCreate

   @var       config
   @vdesc     the CCTK configuration as provided by the flesh
   @vtype     tFleshConfig *
   @vio       unused
   @endvar
   @var       conv_level
   @vdesc     the convergence level
   @vtype     int
   @vio       unused
   @endvar
   @var       GH
   @vdesc     Pointer to CCTK grid hierarchy
   @vtype     cGH *
   @vio       in
   @endvar

   @returntype void *
   @returndesc
               pointer to the allocated GH extension structure
   @endreturndesc
@@*/

static void *CoordBase_SetupGH (tFleshConfig *config, int conv_level, cGH *GH)
{
  coordbaseGH *myGH;

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

  /* allocate the GH extension and its components */
  myGH = (coordbaseGH *) malloc (sizeof (coordbaseGH));

  if (! myGH)
  {
    CCTK_WARN (0, "CoordBase_SetupGH: Unable to allocate memory for GH "
	       "extension");
  }

  myGH->coordsystems = Util_HashCreate(8);

  myGH->default_coord_systems = (int *) malloc(CCTK_MaxDim()*sizeof(int));

  if (! myGH->default_coord_systems)
  {
    CCTK_WARN (0, "CoordBase_SetupGH: Unable to allocate memory for GH "
	       "extension");
  }

  return (myGH);
}

 /*@@
   @routine   CoordBase_InitGH
   @date      28 July 2003
   @author    David Rideout
   @desc 
              Initializes CoordBase's GH extension structure
   @enddesc 

   @calls     CCTK_GHExtension, CCTK_MaxDim

   @var       GH
   @vdesc     Pointer to CCTK grid hierarchy
   @vtype     cGH *
   @vio       in
   @endvar

   @returntype int
   @returndesc
               pointer to the initialized GH extension structure
   @endreturndesc
@@*/

int CoordBase_InitGH (cGH *GH)
{
  const coordbaseGH *GHex;
  int i;

  /* Get the GH extension pointer again... */
  GHex = (const coordbaseGH *) CCTK_GHExtension(GH,"CoordBase");

  /* Initialize default_coord_systems to invalid table handles */
  for (i=0; i<CCTK_MaxDim(); ++i)
  {
    GHex->default_coord_systems[i] = -1;
  }

  return 0;
}