aboutsummaryrefslogtreecommitdiff
path: root/src/SpaceMask.h
blob: 2714725e4c71ca30449cfd8b9449e61d6ac457e2 (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
/*@@
  @file      MaskUtils.c
  @date      October 2002
  @author    Denis Pollney
  @desc
             Function prototypes and macros mask utilities.
  @desc
  @version   $Header$
@@*/

#ifndef __CACTUSEINSTEIN_SPACEMASK_H__
#define __CACTUSEINSTEIN_SPACEMASK_H__

#define SPACEMASK_DEBUG 0

/********************************************************************
 *********************  Routine Prototypes  *************************
 ********************************************************************/
#ifdef CCODE

#ifdef __cplusplus
extern "C"
{
#endif 

/* publicly visible routines */
int SpaceMask_RegisterType(const char* type_name, int nstates,
                           const char* const state_list[]);
int SpaceMask_AppendStatesToType(const char* type_name, int nstates,
                                 const char* const state_list[]);
CCTK_INT SpaceMask_GetTypeBits(const char* type_name);
CCTK_INT SpaceMask_GetStateBits(const char* type_name, const char* state_name);
void SpaceMask_SetState(CCTK_INT* mask, int point,
                        const char* type_name, const char* state);
CCTK_INT SpaceMask_CheckState(const CCTK_INT* mask, int point,
                         const char* type_name, const char* state);

#ifdef __cplusplus
}
#endif

#endif

/********************************************************************
 *********************     Local Data Types    **********************
 ********************************************************************/

#ifdef CCODE

typedef struct
{
  const char* name;
  CCTK_INT bitmask;
} SpaceMask_State;

typedef struct
{
  const char* name;
  int nstates;
  CCTK_INT bitmask;
  SpaceMask_State** state_list;
} SpaceMask_Type;

typedef struct
{
  int ntypes;
  SpaceMask_Type** type_list;
} SpaceMask_Registry;

extern SpaceMask_Registry* spacemask_Registry;

#endif

/********************************************************************
 *********************     Macros      ******************************
 ********************************************************************/

/*@@
  @routine    SpaceMask_SetStateBits
  @author     Denis Pollney
  @date       15 October 2002
  @desc 
              Sets the mask at a point to the given state, as specified
              using a bitmask.
  @enddesc 
@@*/

#ifdef FCODE
#define SpaceMask_SetStateBitsF90(mask, i,j,k, type_bits, state_bits) \
  mask(i,j,k) = ior(iand(mask(i,j,k), not(type_bits)), state_bits)
#endif

#ifdef CCODE
#define SpaceMask_SetStateBits(mask, ijk, type_bits, state_bits) \
  ((mask)[ijk] = (((mask)[ijk] & ~(type_bits)) | (state_bits)))
#endif

/*@@
  @routine    SpaceMask_CheckStateBits
  @author     Denis Pollney
  @date       15 October 2002
  @desc 
              Checks that the mask at a point has the specified state,
              in which case return 1, otherwise return 0.
  @enddesc 
@@*/

#ifdef FCODE
#define SpaceMask_CheckStateBitsF90(mask,i,j,k,type_bits,state_bits) \
  (iand(mask((i),(j),(k)),(type_bits)).eq.(state_bits))
#endif

#ifdef CCODE
#define SpaceMask_CheckStateBits(mask, ijk, type_bits, state_bits) \
  (((mask)[ijk] & (type_bits)) == (state_bits))
#endif

#endif /* __CACTUSEINSTEIN_SPACEMASK_H__ */