Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
mhdf_public.h
Go to the documentation of this file.
00001 #ifndef MHDF_PUBLIC_H
00002 #define MHDF_PUBLIC_H
00003 
00004 #include <H5Tpublic.h>
00005 
00006 #ifdef __cplusplus
00007 extern "C" {
00008 #endif
00009 
00010 #define MHDF_MESSAGE_BUFFER_LEN 160
00011 
00012 /** \brief Struct used to return error status. */
00013 typedef struct struct_mhdf_Status
00014 {
00015     char message[MHDF_MESSAGE_BUFFER_LEN];
00016 } mhdf_Status;
00017 /* another name/alias/typedef for mhdf_Status*/
00018 typedef mhdf_Status MHDF_Status;
00019 
00020 /** \brief Return 1 if passed status object indicates an error.  Zero otherwise. */
00021 int mhdf_isError( mhdf_Status const* );
00022 
00023 /** \brief Get the error message given a status object.  */
00024 const char* mhdf_message( mhdf_Status const* );
00025 
00026 /*@}*/
00027 
00028 /**
00029  *\defgroup mhdf_type Common element type names.
00030  */
00031 /*@{*/
00032 
00033 /** \brief Name to use for edge element */
00034 #define mhdf_EDGE_TYPE_NAME "Edge"
00035 /** \brief Name to use for triangle element */
00036 #define mhdf_TRI_TYPE_NAME "Tri"
00037 /** \brief Name to use for quadrilateral element */
00038 #define mhdf_QUAD_TYPE_NAME "Quad"
00039 /** \brief Name to use for general polygon element */
00040 #define mhdf_POLYGON_TYPE_NAME "Polygon"
00041 /** \brief Name to use for tetrahedral element */
00042 #define mhdf_TET_TYPE_NAME "Tet"
00043 /** \brief Name to use for quad-based pyramid element */
00044 #define mhdf_PYRAMID_TYPE_NAME "Pyramid"
00045 /** \brief Name to use for triangular prism element */
00046 #define mhdf_PRISM_TYPE_NAME "Prism"
00047 /** \brief Name to use for knife element */
00048 #define mdhf_KNIFE_TYPE_NAME "Knife"
00049 /** \brief Name to use for quad-sided hexahedral element */
00050 #define mdhf_HEX_TYPE_NAME "Hex"
00051 /** \brief Name to use for general polyhedron specified as a arbitrary-length list of faces */
00052 #define mhdf_POLYHEDRON_TYPE_NAME "Polyhedron"
00053 /** \brief Name to use for hexagonal-based pyramid */
00054 #define mhdf_SEPTAHEDRON_TYPE_NAME "Septahedron"
00055 
00056 /*@}*/
00057 
00058 /** \brief Enum for tag data type class
00059  *
00060  * Enumerates known types for tag data
00061  */
00062 typedef enum mhdf_TagDataType
00063 {
00064     mhdf_OPAQUE = 0, /**< Opaque/unknown type */
00065     mhdf_INTEGER,    /**< Integer type */
00066     mhdf_FLOAT,      /**< Floating point value */
00067     mhdf_BITFIELD,   /**< Bit field */
00068     mhdf_BOOLEAN,    /**< Boolean values stored as one byte each */
00069     mhdf_ENTITY_ID   /**< Global ID referencing another entity in file */
00070 } MHDF_TagDataType;
00071 
00072 /**\brief Type used when creating index tables
00073  *
00074  * The data type used by mhdf_create* functions that create tables
00075  * if indices (e.g. mhdf_createSetMeta, mhdf_createVarLenTag, etc.).
00076  */
00077 typedef long mhdf_index_t;
00078 
00079 /*@}*/
00080 
00081 /**
00082  *\defgroup mhdf_file File operations
00083  */
00084 /*@{*/
00085 
00086 /** \brief Opaque handle to an open file */
00087 typedef void* mhdf_FileHandle;
00088 /* another name/alias/typedef for mhdf_FileHandle*/
00089 typedef mhdf_FileHandle MHDF_FileHandle;
00090 
00091 /* Top level file operations */
00092 
00093 /** \brief Create a new file.
00094  *
00095  * Create a new HDF mesh file.  This handle must be closed with
00096  * <code>mhdf_closeFile</code> to avoid resource loss.
00097  *
00098  * \param filename   The path and name of the file to create
00099  * \param overwrite  If zero, will fail if the specified file
00100  *                   already exists.  If non-zero, will overwrite
00101  *                   an existing file.
00102  * \param elem_type_list The list of element types that will be stored
00103  *                   in the file.  If the element name exits as a pre-
00104  *                   defined constant (\ref mhdf_type), that constant
00105  *                   should be used.  If a constant does not exist for
00106  *                   the type, a similar naming pattern should be used
00107  *                   (accepted name for type, first character uppercase,
00108  *                   subsequent characters lowercase.)  The element type
00109  *                   index passed to \ref mhdf_addElement is then an
00110  *                   index into this list.  The array may contain
00111  *                   null entries to allow the caller some control over
00112  *                   the assigned indices without creating dummy types
00113  *                   which may confuse readers.
00114  * \param elem_type_list_len The length of <code>elem_type_list</code>.
00115  * \param id_type    Type to use when creating datasets containing file IDs
00116  * \param status     Passed back status of API call.
00117  * \return An opaque handle to the file.
00118  */
00119 mhdf_FileHandle mhdf_createFile( const char* filename,
00120                                  int overwrite,
00121                                  const char** elem_type_list,
00122                                  size_t elem_type_list_len,
00123                                  hid_t id_type,
00124                                  mhdf_Status* status );
00125 
00126 /** \brief Open an existing file.
00127  *
00128  * Open an existing HDF mesh file.  This handle must be closed with
00129  * <code>mhdf_closeFile</code> to avoid resource loss.
00130  *
00131  * \param filename   The path and name of the file to open
00132  * \param writable  If non-zero, open read-write.  Otherwise read-only.
00133  * \param status     Passed back status of API call.
00134  * \param max_id     Used to pass back the maximum global ID used in the
00135  *                   file.  Provided as an indication to the caller of the
00136  *                   size of the mesh.  This parameter is optional.  NULL
00137  *                   may be passed.
00138  * \param id_type    Type to use when creating datasets containing file IDs
00139  * \return An opaque handle to the file.
00140  */
00141 mhdf_FileHandle mhdf_openFile( const char* filename,
00142                                int writable,
00143                                unsigned long* max_id,
00144                                hid_t id_type,
00145                                mhdf_Status* status );
00146 
00147 /** \brief Open an existing file with options.
00148  *
00149  * Open an existing HDF mesh file.  This handle must be closed with
00150  * <code>mhdf_closeFile</code> to avoid resource loss.  This function
00151  * allows the calling application to specify the HDF5 access property
00152  * list that is passed to the HDF5 H5Fopen API.  If this is passed as
00153  * H5P_DEFAULT, the behavior is the same as \ref mhdf_openFile .
00154  * This argument is typically used to specify a parallel context for
00155  * for writing the file in parallel.
00156  *
00157  * \param filename   The path and name of the file to open
00158  * \param writable  If non-zero, open read-write.  Otherwise read-only.
00159  * \param status     Passed back status of API call.
00160  * \param max_id     Used to pass back the maximum global ID used in the
00161  *                   file.  Provided as an indication to the caller of the
00162  *                   size of the mesh.  This parameter is optional.  NULL
00163  *                   may be passed.
00164  * \param options    The HDF5 access property list to use when opening
00165  *                   the file.  See the HDF5 documentation for H5Fopen.
00166  * \param id_type    Type to use when creating datasets containing file IDs
00167  * \return An opaque handle to the file.
00168  */
00169 mhdf_FileHandle mhdf_openFileWithOpt( const char* filename,
00170                                       int writable,
00171                                       unsigned long* max_id,
00172                                       hid_t id_type,
00173                                       hid_t options,
00174                                       mhdf_Status* status );
00175 
00176 /**\brief Get number of open HDF5 objects from file */
00177 int mhdf_countOpenHandles( mhdf_FileHandle h );
00178 
00179 /** Data common to sets, nodes, and each element type */
00180 typedef struct mhdf_EntDesc
00181 {
00182     long start_id; /**< First file ID for table of data */
00183     long count;    /**< Number of entities in table */
00184     int vals_per_ent; /**< Connectivity length for elems, dimension for verts, unused for sets, -1 for variable length poly* data */
00185     int*
00186         dense_tag_indices; /**< Indices into mhdf_FileDesc::tags for each tag for which dense data is present for these entities */
00187     int num_dense_tags; /**< Length of dense_tag_indices */
00188 } MHDF_EntDesc;
00189 /** Struct describing a tag */
00190 typedef struct mhdf_TagDesc
00191 {
00192     const char* name;           /**< Tag name */
00193     enum mhdf_TagDataType type; /**< Data type */
00194     int size;                   /**< Tag size (num of data type) */
00195     int bytes;                  /**< Tag size (number of bytes) */
00196     int storage;                /**< MOAB tag type (dense or sparse) */
00197     int have_sparse;            /**< Have sparse id/data pairs in file */
00198     void* default_value;        /**< Default value, NULL if none. */
00199     int default_value_size;
00200     void* global_value; /**< Global value, NULL if none. */
00201     int global_value_size;
00202     int* dense_elem_indices; /**< Array of indices indicating element types for which dense
00203                                    data is stored.  -2 for sets, -1 for nodes. */
00204     int num_dense_indices;
00205 } MHDF_TagDesc;
00206 typedef struct mhdf_ElemDesc
00207 {
00208     const char* handle; /**< String table identifier */
00209     const char* type;   /**< String type designator */
00210     int have_adj;       /**< File contains adjacency data for this element group */
00211     struct mhdf_EntDesc desc;
00212 } MHDF_ElemDesc;
00213 typedef struct mhdf_FileDesc
00214 {
00215     struct mhdf_EntDesc nodes;
00216     struct mhdf_EntDesc sets;
00217     int have_set_contents;
00218     int have_set_children;
00219     int have_set_parents;
00220     struct mhdf_ElemDesc* elems; /**< Array of element table descriptions */
00221     int num_elem_desc;
00222     struct mhdf_TagDesc* tags; /**< Array of tag descriptions */
00223     int num_tag_desc;
00224     int* numEntSets; /* used to be [4] */
00225     /*int num_parts; will look specifically for number of sets with PARALLEL_PARTITION tags*/
00226     /* int num_mats; will look specifically for number of sets with MATERIAL_SET tags*/
00227     /*int num_neumann; will look specifically for number of sets with NEUMANN_SET tags*/
00228     /*int num_diri; will look specifically for number of sets with DIRICHLET_SET tags*/
00229     int** defTagsEntSets; /* we may need to add geometry_dimension tags */
00230     int** defTagsVals;
00231     size_t total_size;     /**< Size of memory block containing all struct data */
00232     unsigned char* offset; /**< Unused, may be used by application */
00233 } MHDF_FileDesc;
00234 
00235 /** \brief Get summary of data tables contained within file.
00236  *
00237  * Returned struct, including all pointed-to data, is allocated in a
00238  * single contiguous block of memory with a size equal to 'total_size'.
00239  * Caller is responsible for freeing the returned struct FileDesc pointer
00240  * (and *only* that pointer, not pointers nexted within the struct!).
00241  * Caller may copy (e.g. MPI_BCast) entire struct as one contiguous block,
00242  * assuming all nested pointers in the copy are updated to the correct
00243  * relative offset from the beginning of the struct.
00244  */
00245 MHDF_FileDesc* mhdf_getFileSummary( mhdf_FileHandle file_handle,
00246                                     hid_t file_id_type,
00247                                     mhdf_Status* status,
00248                                     int extraSetInfo );
00249 
00250 /**\brief Fix nested pointers for copied/moved FileDesc struct
00251  *
00252  * This is a utility method to facility copying/moving/communicating
00253  * struct FileDesc instances.  The structure and all data it references
00254  * are allocated in a single contiguous block of memory of size
00255  * FileDesc::total_size.  As such, the struct can be copied with a single
00256  * memcpy, packed into a single network packet, communicated with a single
00257  * MPI call, etc.  However, the pointers contained within the struct will
00258  * not be valid in the copied instance (they will still point into the
00259  * original instance.)  Given a pointer to the copied struct and the address
00260  * of the original struct, this function will updated all contained pointers.
00261  */
00262 void mhdf_fixFileDesc( struct mhdf_FileDesc* copy_ptr, const struct mhdf_FileDesc* orig_addr );
00263 
00264 /** \brief Close the file
00265  * \param handle     The file to close.
00266  * \param status     Passed back status of API call.
00267  */
00268 void mhdf_closeFile( mhdf_FileHandle handle, mhdf_Status* status );
00269 
00270 /**\brief Check for open handles in file
00271  **/
00272 
00273 #ifdef __cplusplus
00274 } /* extern "C" */
00275 #endif
00276 
00277 #endif /* MHDF_PUBLIC_H*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines