00001 /*
00002 ** _______ __
00003 ** / ___/ / ___ __ _ / / ___
00004 ** / /__/ _ \/ _ \/ ' \/ _ \/ _ \
00005 ** \___/_//_/\___/_/_/_/_.__/\___/
00006 **
00007 ** EBInterface.h
00008 **
00009 ** This software is copyright (C) by the Lawrence Berkeley
00010 ** National Laboratory. Permission is granted to reproduce
00011 ** this software for non-commercial purposes provided that
00012 ** this notice is left intact.
00013 **
00014 ** It is acknowledged that the U.S. Government has rights to
00015 ** this software under Contract DE-AC03-765F00098 between
00016 ** the U.S. Department of Energy and the University of
00017 ** California.
00018 **
00019 ** This software is provided as a professional and academic
00020 ** contribution for joint exchange. Thus it is experimental,
00021 ** is provided ``as is'', with no warranties of any kind
00022 ** whatsoever, no support, no promise of updates, or printed
00023 ** documentation. By using this software, you acknowledge
00024 ** that the Lawrence Berkeley National Laboratory and
00025 ** Regents of the University of California shall have no
00026 ** liability with respect to the infringement of other
00027 ** copyrights by any part of this software.
00028 **
00029 */
00030
00031 /* Serial programming interface to Chombo EB HDF5 file format*/
00032 #ifndef __EBINTERFACE_H_
00033 #define __EBINTERFACE_H_
00034
00035 #include <hdf5.h>
00036 #include <math.h>
00037
00038 struct {
00039 int i;
00040 int j;
00041 }typedef intvect2d ;
00042
00043 struct {
00044 int i;
00045 int j;
00046 int k;
00047 }typedef intvect3d ;
00048
00049 struct {
00050 intvect2d lo;
00051 intvect2d hi;
00052 }typedef box2d ;
00053
00054 struct{
00055 intvect3d lo;
00056 intvect3d hi;
00057 } typedef box3d;
00058
00059 union
00060 {
00061 box2d b2;
00062 box3d b3;
00063 } typedef box;
00064
00065
00066 struct {
00067 intvect3d index;
00068 double volfrac;
00069 double areafrac[6];
00070
00071 } typedef regvof ; /* regular volume-of-fluid */
00072
00073
00074 struct {
00075 double areafrac;
00076 intvect3d neighbour;
00077 int nindex;
00078 } typedef irregface;
00079
00080 struct {
00081 intvect3d index;
00082 double volfrac;
00083 int numfaces;
00084 irregface* faces;
00085 } typedef irregvof; /* irregular volume-of-fluid */
00086
00087
00088 /* gives values to *_id objects */
00089 /* must be called, and called only once, before other functions in this
00090 header will function properly */
00091 void initializeHDF5datatypes();
00092
00093
00094
00095 /* domain is broken up into many non-overlapping boxes that completely cover
00096 the domain.
00097
00098 for each box, 'i', there is a regoffset, and an irregoffset:
00099
00100 if regoffset[i] = -1 the box is completely REGULAR
00101 if regoffset[i] = -2 the box is completely COVERED
00102
00103 otherwise regoffset contains an index into regvof* array where reading
00104 is to begin of regular volume-of-fluids,
00105 regvof[ regoffset [i]] to regvof[ regoffset [i+1]]
00106
00107 irregular volumes are then written for each box,
00108 irregvof[ irregoffset [i]] to irregvof[ irregoffset [i+1]]
00109
00110 both indexings do not include the endpoint [...) , so that emtpy
00111 sets can be given with both indexes being the same.
00112
00113
00114 return codes;
00115
00116 0 : success
00117 -1: error opening file
00118 -2: error writing attributes to header
00119 -4: error writing boxes to data file
00120 -20: error closing file on exit
00121 */
00122
00123 int writeEBChomboFile(const char* filename,
00124 box3d domain,
00125 int length,
00126 box3d* boxes,
00127 long* regoffset,
00128 long* irregoffset,
00129 long numreg,
00130 long numirreg,
00131 regvof* regularVofs,
00132 irregvof* irregularVofs);
00133
00134
00135
00136
00137 /*================================*/
00138 /* END OF USER INTERFACE SECTION */
00139 /*================================*/
00140
00141
00142 /* these functions prototypes are used by EBInterface.c */
00143
00144 int isEmpty(const box2d*);
00145 int numPnts2(const box2d*);
00146 int numPnts3(const box3d*);
00147
00148 void grow2(box2d*, intvect2d*);
00149 void grow3(box3d*, intvect3d*);
00150
00151 void refine2(box2d*, int refinement);
00152 void refine3(box3d*, int refinement);
00153 int cut(const box3d* box, int dir, int index);
00154 box2d* crossSection(const box3d* box, int dir, box2d* box2);
00155
00156 static hid_t intvect2d_id, intvect3d_id, box2d_id, box3d_id ;
00157
00158
00159
00160
00161
00162
00163
00164 enum{Float, Double} typedef ChPrecision;
00165
00166 struct
00167 {
00168 hid_t file_ID;
00169 hid_t group_ID;
00170 int dim;
00171 ChPrecision precision;
00172 }typedef HDF5Handle;
00173
00174 /* three next functions return 0 on success */
00175
00176 /* returns negative number if file open failed
00177 1 if 'Chombo_global' couldn't be found and ChDim and ChPrecision not set
00178 accessMode is one of H5F_ACC_RDWR, H5F_ACC_RDONLY, H5F_ACC_CREATE
00179 */
00180 int Handleopen(HDF5Handle* handle, const char* filename, hid_t accessMode);
00181 int HandlesetGroup(HDF5Handle* handle, const char* group);/* ie. "/level_0" */
00182 int Handleclose(HDF5Handle handle);
00183 int HandleCreateGroup(HDF5Handle* handle, const char* group);/* ie. "/level_0" */
00184
00185
00186 #define ChTYPES 8
00187 enum{INTEGER, FLOAT, DOUBLE, CHAR, INTVECT2D, INTVECT3D, BOX2D, BOX3D}typedef ChattributeType;
00188 static const char* TYPE_NAMES[ChTYPES];
00189
00190 struct
00191 {
00192 void* data;
00193 char* name;
00194 int attributeType;
00195 void* next;
00196 } typedef Attribute;
00197
00198 /* struct that holds all the attributes of an HDF5 group.
00199
00200 each entry in the accessByType array is the head of a linked
00201 list of members terminated with a null.
00202
00203 to access directly by type you can use code like this:
00204
00205 HDF5attributes a;
00206 readHDF5attributes(&a, handle);
00207 int numChar = a.numByType(CHAR);
00208 Attribute* at = a.accessByType[CHAR];
00209 while(at != NULL)
00210 {
00211 printf("char attribute %s = %s",
00212 at->name,
00213 (char*)(at->data));
00214 at = at->next;
00215 }
00216 */
00217 struct
00218 {
00219 int numByType[ChTYPES];
00220 Attribute* accessByType[ChTYPES];
00221 int dim;
00222 ChPrecision precision;
00223 } typedef HDF5attributes;
00224
00225 void freeHDF5attributes(HDF5attributes* attributes);
00226 void printAttributes(HDF5attributes* attributes);
00227
00228
00229 /* utility functions for appending attributes to an HDF5attributes struct
00230 attrib: HDF5atributes struct */
00231 extern Attribute* ADD_tmp;
00232 extern Attribute* ADD_at;
00233 #define ADD_ATTRIBUTE(attrib, Ttype, ChType, Sname, value) \
00234 ADD_tmp = attrib.accessByType[ChType] ; \
00235 ADD_at = (Attribute*) malloc(sizeof(Attribute)); \
00236 attrib.accessByType[ChType] = ADD_at; \
00237 ADD_at->name = malloc(strlen(Sname)+1); \
00238 sprintf(ADD_at->name, Sname); \
00239 ADD_at->data = malloc(sizeof(Ttype)); \
00240 ADD_at->attributeType = ChType; \
00241 *((Ttype *)ADD_at->data) = value; \
00242 ADD_at->next = ADD_tmp; \
00243 attrib.numByType[ChType]++; \
00244
00245 #define ADD_CHAR_ATTRIBUTE(attrib, Sname, value) \
00246 ADD_tmp = attrib.accessByType[CHAR] ; \
00247 ADD_at = (Attribute*) malloc(sizeof(Attribute)); \
00248 attrib.accessByType[CHAR] = ADD_at; \
00249 ADD_at->name = malloc(strlen(Sname)); \
00250 sprintf(ADD_at->name, Sname); \
00251 ADD_at->data = malloc(strlen(value)); \
00252 ADD_at->attributeType = CHAR; \
00253 sprintf((char*)ADD_at->data, value); \
00254 ADD_at->next = ADD_tmp; \
00255 attrib.numByType[CHAR]++; \
00256
00257 /* next eight functions return 0 on success */
00258
00259 /* - users responsibility to make sure HDF5Handle is pointing at a valid group
00260 in an open file.
00261 - User must use freeHDF5attributes when finished.
00262 - User must pass in a pointer to a valid HDF5attributes struct.*/
00263 int readHDF5attributes(HDF5attributes* attr, HDF5Handle handle);
00264
00265 /* input: HDF5Handle
00266 users responsibility to cast *(boxes) to either box2d*
00267 or box3d* and free it */
00268 int readBoxes(box** boxes, int* length, HDF5Handle handle);
00269
00270
00271
00272 /* - users responsibility to make sure HDF5Handle is pointing at a valid group
00273 in an open file.
00274 - User must use freeHDF5attributes when finished.
00275 - User must pass in a pointer to a valid HDF5attributes struct.
00276
00277 returns 0 on success
00278
00279 -1 attribute creation problems */
00280 int writeHDF5attributes(HDF5attributes* attr, HDF5Handle handle);
00281
00282 int writeBoxes(box* boxes, int length, HDF5Handle handle);
00283
00284
00285
00286
00289 #define CFINITE(X) !isnan(X) && (X) < HUGE_VAL && (X) > -HUGE_VAL
00290
00291 #endif
1.2.16