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

#include <stdlib.h>

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

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

CCTK_FILEVERSION(CactusBase_CoordBase_GHExtension_c);

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

int CoordBase_Startup (void);

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

static void *CoordBase_SetupGH (tFleshConfig *config, int conv_level, 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
@@*/
int CoordBase_Startup (void)
{
  int GHex_handle;

  GHex_handle = CCTK_RegisterGHExtension ("CoordBase");
  CCTK_RegisterGHExtensionSetupGH (GHex_handle, CoordBase_SetupGH);

  return 0;
}


/********************************************************************
 ********************    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)
{
  int maxdim;
  int *default_coord_systems;
  coordbaseGH *myGH;

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

  maxdim = CCTK_MaxDim();

  /* allocate the GH extension and its components */
  myGH = malloc (sizeof (coordbaseGH));
  default_coord_systems = malloc(maxdim * sizeof(int));
  if (myGH && default_coord_systems)
  {
    myGH->default_coord_systems = default_coord_systems;
    while (--maxdim >= 0)
    {
      myGH->default_coord_systems[maxdim] = COORDERROR_NOSYSTEM;
    }

    myGH->coordsystems = Util_HashCreate(8);
  }
  else
  {
    CCTK_WARN (0, "CoordBase_SetupGH: Unable to allocate memory for GH "
                  "extension");
    free (default_coord_systems);
    myGH = NULL;
  }

  return (myGH);
}