Chombo + EB  3.0
EBInterface.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 /* Serial programming interface to Chombo EB HDF5 file format*/
12 
13 #ifndef _EBINTERFACE_H_
14 #define _EBINTERFACE_H_
15 
16 #include <hdf5.h>
17 #include <math.h>
18 #include "NamespaceHeader.H"
19 
20 struct
21 {
22  int i;
23  int j;
24 } typedef intvect2d ;
25 
26 struct
27 {
28  int i;
29  int j;
30  int k;
31 } typedef intvect3d ;
32 
33 struct
34 {
37 } typedef box2d ;
38 
39 struct
40 {
43 } typedef box3d;
44 
45 union
46 {
49 } typedef box;
50 
51 struct
52 {
54  double volfrac;
55  double areafrac[6];
56 } typedef regvof ; /* regular volume-of-fluid */
57 
58 struct
59 {
60  double areafrac;
62  int nindex;
63 } typedef irregface;
64 
65 struct
66 {
68  double volfrac;
69  int numfaces;
71 } typedef irregvof; /* irregular volume-of-fluid */
72 
73 /* gives values to *_id objects */
74 /* must be called, and called only once, before other functions in this
75  header will function properly */
77 
78 /* domain is broken up into many non-overlapping boxes that completely cover
79  the domain.
80 
81  for each box, 'i', there is a regoffset, and an irregoffset:
82 
83  if regoffset[i] = -1 the box is completely REGULAR
84  if regoffset[i] = -2 the box is completely COVERED
85 
86  otherwise regoffset contains an index into regvof* array where reading
87  is to begin of regular volume-of-fluids,
88  regvof[ regoffset [i]] to regvof[ regoffset [i+1]]
89 
90  irregular volumes are then written for each box,
91  irregvof[ irregoffset [i]] to irregvof[ irregoffset [i+1]]
92 
93  both indexings do not include the endpoint [...) , so that emtpy
94  sets can be given with both indexes being the same.
95 
96  return codes;
97 
98  0 : success
99  -1: error opening file
100  -2: error writing attributes to header
101  -4: error writing boxes to data file
102  -20: error closing file on exit
103 */
104 
105 int writeEBChomboFile(const char* filename,
106  box3d domain,
107  int length,
108  box3d* boxes,
109  long* regoffset,
110  long* irregoffset,
111  long numreg,
112  long numirreg,
113  regvof* regularVofs,
114  irregvof* irregularVofs);
115 
116 /*================================*/
117 /* END OF USER INTERFACE SECTION */
118 /*================================*/
119 
120 /* these functions prototypes are used by EBInterface.c */
121 
122 int isEmpty(const box2d*);
123 int numPnts2(const box2d*);
124 int numPnts3(const box3d*);
125 
126 void grow2(box2d*, intvect2d*);
127 void grow3(box3d*, intvect3d*);
128 
129 void refine2(box2d*, int refinement);
130 void refine3(box3d*, int refinement);
131 int cut(const box3d* box, int dir, int index);
132 box2d* crossSection(const box3d* box, int dir, box2d* box2);
133 
135 
136 enum
137 {
140 } typedef ChPrecision;
141 
142 struct
143 {
144  hid_t file_ID;
145  hid_t group_ID;
146  int dim;
148 }typedef HDF5Handle;
149 
150 /* three next functions return 0 on success */
151 
152 /* returns negative number if file open failed
153  1 if 'Chombo_global' couldn't be found and ChDim and ChPrecision not set
154  accessMode is one of H5F_ACC_RDWR, H5F_ACC_RDONLY, H5F_ACC_CREATE
155  */
156 int Handleopen(HDF5Handle* handle, const char* filename, hid_t accessMode);
157 int HandlesetGroup(HDF5Handle* handle, const char* group);/* ie. "/level_0" */
158 int Handleclose(HDF5Handle handle);
159 int HandleCreateGroup(HDF5Handle* handle, const char* group);/* ie. "/level_0" */
160 
161 #define ChTYPES 8
162 enum
163 {
172 } typedef ChattributeType;
173 static const char* TYPE_NAMES[ChTYPES];
174 
175 struct
176 {
177  void* data;
178  char* name;
180  void* next;
181 } typedef Attribute;
182 
183 /* struct that holds all the attributes of an HDF5 group.
184 
185  each entry in the accessByType array is the head of a linked
186  list of members terminated with a null.
187 
188  to access directly by type you can use code like this:
189 
190  HDF5attributes a;
191  readHDF5attributes(&a, handle);
192  int numChar = a.numByType(CHAR);
193  Attribute* at = a.accessByType[CHAR];
194  while (at != NULL)
195  {
196  printf("char attribute %s = %s",
197  at->name,
198  (char*)(at->data));
199  at = at->next;
200  }
201  */
202 struct
203 {
204  int numByType[ChTYPES];
205  Attribute* accessByType[ChTYPES];
206  int dim;
208 } typedef HDF5attributes;
209 
210 void freeHDF5attributes(HDF5attributes* attributes);
211 void printAttributes(HDF5attributes* attributes);
212 
213 /* utility functions for appending attributes to an HDF5attributes struct
214  attrib: HDF5atributes struct */
215 extern Attribute* ADD_tmp;
216 extern Attribute* ADD_at;
217 #define ADD_ATTRIBUTE(attrib, Ttype, ChType, Sname, value) \
218 ADD_tmp = attrib.accessByType[ChType] ; \
219 ADD_at = (Attribute*) malloc(sizeof(Attribute)); \
220 attrib.accessByType[ChType] = ADD_at; \
221 ADD_at->name = malloc(strlen(Sname)+1); \
222 sprintf(ADD_at->name, Sname); \
223 ADD_at->data = malloc(sizeof(Ttype)); \
224 ADD_at->attributeType = ChType; \
225 *((Ttype *)ADD_at->data) = value; \
226  ADD_at->next = ADD_tmp; \
227 attrib.numByType[ChType]++; \
228 
229 #define ADD_CHAR_ATTRIBUTE(attrib, Sname, value) \
230 ADD_tmp = attrib.accessByType[CHAR] ; \
231 ADD_at = (Attribute*) malloc(sizeof(Attribute)); \
232 attrib.accessByType[CHAR] = ADD_at; \
233 ADD_at->name = malloc(strlen(Sname)); \
234 sprintf(ADD_at->name, Sname); \
235 ADD_at->data = malloc(strlen(value)); \
236 ADD_at->attributeType = CHAR; \
237 sprintf((char*)ADD_at->data, value); \
238  ADD_at->next = ADD_tmp; \
239 attrib.numByType[CHAR]++; \
240 
241 /* next eight functions return 0 on success */
242 
243 /* - users responsibility to make sure HDF5Handle is pointing at a valid group
244  in an open file.
245  - User must use freeHDF5attributes when finished.
246  - User must pass in a pointer to a valid HDF5attributes struct.*/
247 int readHDF5attributes(HDF5attributes* attr, HDF5Handle handle);
248 
249 /* input: HDF5Handle
250  users responsibility to cast *(boxes) to either box2d*
251  or box3d* and free it */
252 int readBoxes(box** boxes, int* length, HDF5Handle handle);
253 
254 /* - users responsibility to make sure HDF5Handle is pointing at a valid group
255  in an open file.
256  - User must use freeHDF5attributes when finished.
257  - User must pass in a pointer to a valid HDF5attributes struct.
258 
259  returns 0 on success
260 
261  -1 attribute creation problems */
263 
264 int writeBoxes(box* boxes, int length, HDF5Handle handle);
265 
266 /** create our own platform independent form that spans
267  a lot of IEEE goofiness. */
268 #define CFINITE(X) !isnan(X) && (X) < HUGE_VAL && (X) > -HUGE_VAL
269 
270 #include "NamespaceFooter.H"
271 #endif
int numPnts2(const box2d *)
box2d b2
Definition: EBInterface.H:47
void * next
Definition: EBInterface.H:180
void grow2(box2d *, intvect2d *)
ChattributeType
Definition: EBInterface.H:162
int HandleCreateGroup(HDF5Handle *handle, const char *group)
void initializeHDF5datatypes()
int attributeType
Definition: EBInterface.H:179
static hid_t box2d_id
Definition: EBInterface.H:134
void refine2(box2d *, int refinement)
double volfrac
Definition: EBInterface.H:54
static hid_t box3d_id
Definition: EBInterface.H:134
void printAttributes(HDF5attributes *attributes)
Definition: EBInterface.H:164
Definition: EBInterface.H:138
struct @17 HDF5Handle
Definition: Box.H:1631
static hid_t intvect3d_id
Definition: EBInterface.H:134
int j
Definition: EBInterface.H:29
intvect3d hi
Definition: EBInterface.H:42
void grow3(box3d *, intvect3d *)
static const char * TYPE_NAMES[ChTYPES]
Definition: EBInterface.H:173
int nindex
Definition: EBInterface.H:62
Attribute * ADD_tmp
int Handleopen(HDF5Handle *handle, const char *filename, hid_t accessMode)
Definition: EBInterface.H:175
Definition: EBInterface.H:33
intvect2d lo
Definition: EBInterface.H:35
Definition: EBInterface.H:139
int isEmpty(const box2d *)
ChPrecision
Definition: EBInterface.H:136
Definition: EBInterface.H:45
int HandlesetGroup(HDF5Handle *handle, const char *group)
Definition: EBInterface.H:26
void * data
Definition: EBInterface.H:177
hid_t file_ID
Definition: EBInterface.H:144
int i
Definition: EBInterface.H:22
Definition: EBInterface.H:169
ChPrecision precision
Definition: EBInterface.H:207
hid_t group_ID
Definition: EBInterface.H:145
#define ChTYPES
Definition: EBInterface.H:161
int writeBoxes(box *boxes, int length, HDF5Handle handle)
box3d b3
Definition: EBInterface.H:48
int writeEBChomboFile(const char *filename, box3d domain, int length, box3d *boxes, long *regoffset, long *irregoffset, long numreg, long numirreg, regvof *regularVofs, irregvof *irregularVofs)
char * name
Definition: EBInterface.H:178
irregface * faces
Definition: EBInterface.H:70
int Handleclose(HDF5Handle handle)
Definition: EBInterface.H:165
int dim
Definition: EBInterface.H:206
void refine3(box3d *, int refinement)
box2d * crossSection(const box3d *box, int dir, box2d *box2)
intvect3d neighbour
Definition: EBInterface.H:61
int k
Definition: EBInterface.H:30
Definition: EBInterface.H:58
Definition: EBInterface.H:168
Definition: EBInterface.H:171
Definition: EBInterface.H:39
Handle to a particular group in an HDF file.
Definition: CH_HDF5.H:267
Definition: EBInterface.H:202
Definition: EBInterface.H:65
intvect3d index
Definition: EBInterface.H:67
intvect2d hi
Definition: EBInterface.H:36
intvect3d index
Definition: EBInterface.H:53
int readHDF5attributes(HDF5attributes *attr, HDF5Handle handle)
Attribute * ADD_at
int numfaces
Definition: EBInterface.H:69
Definition: EBInterface.H:167
void freeHDF5attributes(HDF5attributes *attributes)
Definition: EBInterface.H:51
int i
Definition: EBInterface.H:28
static hid_t intvect2d_id
Definition: EBInterface.H:134
Definition: EBInterface.H:20
int cut(const box3d *box, int dir, int index)
int dim
Definition: EBInterface.H:146
double volfrac
Definition: EBInterface.H:68
int readBoxes(box **boxes, int *length, HDF5Handle handle)
int writeHDF5attributes(HDF5attributes *attr, HDF5Handle handle)
ChPrecision precision
Definition: EBInterface.H:147
double areafrac
Definition: EBInterface.H:60
Definition: EBInterface.H:166
int numPnts3(const box3d *)
intvect3d lo
Definition: EBInterface.H:41
Definition: EBInterface.H:170
int j
Definition: EBInterface.H:23