moab
Tqdcfr.hpp
Go to the documentation of this file.
00001 
00016 /*
00017  * Tim's Quick 'N Dirty Cub File Reader (Tqdcfr)
00018  *
00019  */
00020 
00021 #ifndef TQDCFR
00022 #define TQDCFR
00023 
00024 #include "moab/Forward.hpp"
00025 #include "moab/ReaderIface.hpp"
00026 #include "MBTagConventions.hpp"
00027 #include "moab/Range.hpp"
00028 
00029 #include <stdio.h>
00030 #include <string>
00031 #include <vector>
00032 #include <map>
00033 
00034 namespace moab {
00035 
00036 class ReadUtilIface;
00037 class FEModelHeader;
00038 class GeomHeader;
00039 class GroupHeader;
00040 class BlockHeader;
00041 class NodesetHeader;
00042 class SidesetHeader;
00043 
00044 
00045 class Tqdcfr : public ReaderIface
00046 {
00047 public:  
00048 
00049   void FSEEK( unsigned offset );        // set cubFile offset to specified value
00050   void FREADI( unsigned num_ents ); // read integers into uint_buf
00051   void FREADD( unsigned num_ents ); // read doubles into dbl_buf
00052   void FREADC( unsigned num_ents ); // read characters into char_buf
00053   void FREADIA( unsigned num_ents,    unsigned int* array ); // read integers
00054   void FREADDA( unsigned num_ents, double* array ); // read doubles
00055   void FREADCA( unsigned num_ents,   char* arrat ); // read bytes
00056   void CONVERT_TO_INTS(unsigned int num_ents); // convert uint_buf to int_buf in-place
00057 
00058     // class for holding the file table of contents
00059   class FileTOC
00060   {
00061   public:
00062     unsigned int fileEndian, fileSchema, numModels, modelTableOffset, 
00063       modelMetaDataOffset, activeFEModel;
00064 
00065     FileTOC();
00066     void print();
00067   };
00068 
00069     // 
00070   class FEModelHeader 
00071   {
00072   public:
00073     unsigned int feEndian, feSchema, feCompressFlag, feLength;
00074 
00075     class ArrayInfo 
00076     {
00077     public:
00078       unsigned numEntities, tableOffset, metaDataOffset;
00079 
00080       ArrayInfo();
00081       
00082       void print();
00083       void init(const std::vector<unsigned int>& uint_buf);
00084     };
00085     
00086     ArrayInfo geomArray, nodeArray, elementArray, groupArray, 
00087       blockArray, nodesetArray, sidesetArray;
00088 
00089     void init(const unsigned int offset, Tqdcfr* instance );
00090         
00091     void print();
00092   };
00093 
00094   class MetaDataContainer
00095   {
00096   public:
00097     unsigned int mdSchema, compressFlag;
00098 
00099     class MetaDataEntry
00100     {
00101     public:
00102       unsigned int mdOwner, mdDataType, mdIntValue;
00103       std::string mdName, mdStringValue;
00104       std::vector<unsigned int> mdIntArrayValue;
00105       double mdDblValue;
00106       std::vector<double> mdDblArrayValue;
00107       
00108       MetaDataEntry();
00109 
00110       void print();
00111     };
00112 
00113     void print();
00114 
00115     int get_md_entry(const unsigned int owner, const std::string &name);
00116     
00117     std::vector<MetaDataEntry> metadataEntries;
00118     MetaDataContainer();
00119   };
00120 
00121   class GeomHeader 
00122   {
00123   public:
00124     unsigned int geomID, nodeCt, nodeOffset, elemCt, elemOffset, 
00125       elemTypeCt, elemLength;
00126 
00127     int maxDim;
00128     
00129     EntityHandle setHandle;
00130 
00131     void print();
00132 
00133     static ErrorCode read_info_header(const unsigned int model_offset, 
00134                                         const FEModelHeader::ArrayInfo &info,
00135                                         Tqdcfr* instance,
00136                                         GeomHeader *&entity_headers);
00137 
00138     GeomHeader();
00139   };
00140   
00141   class GroupHeader 
00142   {
00143   public:
00144     unsigned int grpID, grpType, memCt, memOffset, memTypeCt, grpLength;
00145 
00146     EntityHandle setHandle;
00147 
00148     void print();
00149 
00150     static ErrorCode read_info_header(const unsigned int model_offset, 
00151                                  const FEModelHeader::ArrayInfo &info,
00152                                  Tqdcfr* instance,
00153                                  GroupHeader *&entity_headers);
00154 
00155     GroupHeader();
00156   };
00157   
00158   class BlockHeader 
00159   {
00160   public:
00161     unsigned int blockID, blockElemType, memCt, memOffset, memTypeCt, attribOrder, blockCol,
00162       blockMixElemType, blockPyrType, blockMat, blockLength, blockDim;
00163 
00164     EntityHandle setHandle;
00165 
00166     EntityType blockEntityType;
00167 
00168     int hasMidNodes[4];
00169 
00170     void print();
00171 
00172     static ErrorCode read_info_header(const double data_version,
00173                                         const unsigned int model_offset, 
00174                                         const FEModelHeader::ArrayInfo &info,
00175                                         Tqdcfr* instance,
00176                                         BlockHeader *&block_headers);
00177 
00178     BlockHeader();
00179   };
00180   
00181   class NodesetHeader 
00182   {
00183   public:
00184     unsigned int nsID, memCt, memOffset, memTypeCt, pointSym, nsCol, nsLength;
00185 
00186     EntityHandle setHandle;
00187 
00188     void print();
00189 
00190     static ErrorCode read_info_header(const unsigned int model_offset, 
00191                                  const FEModelHeader::ArrayInfo &info,
00192                                  Tqdcfr* instance,
00193                                  NodesetHeader *&entity_headers);
00194 
00195     NodesetHeader();
00196   };
00197   
00198   class SidesetHeader 
00199   {
00200   public:
00201     unsigned int ssID, memCt, memOffset, memTypeCt, numDF, ssCol, useShell, ssLength;
00202 
00203     EntityHandle setHandle;
00204 
00205     void print();
00206 
00207     static ErrorCode read_info_header(const unsigned int model_offset, 
00208                                  const FEModelHeader::ArrayInfo &info,
00209                                  Tqdcfr* instance,
00210                                  SidesetHeader *&entity_headers);
00211 
00212     SidesetHeader();
00213   };
00214   
00215     // class to hold model entry data for various kinds of models 
00216     // (acis, free mesh, etc.)
00217   class ModelEntry
00218   {
00219   public:
00220     ModelEntry();
00221 
00222     ~ModelEntry();
00223     
00224     unsigned int modelHandle, modelOffset, modelLength, modelType, modelOwner, modelPad;
00225 
00226     FEModelHeader feModelHeader;
00227     GeomHeader *feGeomH;
00228     GroupHeader *feGroupH;
00229     BlockHeader *feBlockH;
00230     NodesetHeader *feNodeSetH;
00231     SidesetHeader *feSideSetH;
00232     
00233     MetaDataContainer geomMD, nodeMD, elementMD, groupMD, blockMD, nodesetMD, sidesetMD;
00234     
00235     void print();
00236 
00237     void print_geom_headers(const char *prefix,
00238                             GeomHeader *header,
00239                             unsigned int num_headers);
00240 
00241     void print_group_headers(const char *prefix,
00242                              GroupHeader *header,
00243                              const unsigned int num_headers);
00244 
00245     void print_block_headers(const char *prefix,
00246                              BlockHeader *header,
00247                              const unsigned int num_headers);
00248 
00249     void print_nodeset_headers(const char *prefix,
00250                                NodesetHeader *header,
00251                                const unsigned int num_headers);
00252 
00253     void print_sideset_headers(const char *prefix,
00254                                SidesetHeader *header,
00255                                const unsigned int num_headers);
00256     
00257     ErrorCode read_header_info( Tqdcfr* instance, const double data_version);
00258     ErrorCode read_metadata_info(Tqdcfr *tqd);
00259   };
00260 
00261   enum {aBODY, LUMP, SHELL, FACE, LOOP, COEDGE, aEDGE, aVERTEX, ATTRIB, UNKNOWN};
00262   
00263   const unsigned int *ACIS_DIMS;
00264   
00265   struct AcisRecord 
00266   {
00267     unsigned int rec_type;
00268     std::string att_string;
00269     bool processed;
00270     int first_attrib;
00271     int att_prev, att_next, att_ent_num;
00272     EntityHandle entity;
00273   };
00274 
00275   ~Tqdcfr();
00276 
00277   ReadUtilIface *readUtilIface;
00278   Interface *mdbImpl;
00279   FILE *cubFile;
00280   FileTOC fileTOC;
00281   std::vector<ModelEntry> modelEntries;
00282   MetaDataContainer modelMetaData;
00283   long currVHandleOffset;
00284   Range beforeEnts;
00285   long currElementIdOffset[MBMAXTYPE];
00286   Tag globalIdTag, cubIdTag, geomTag, uniqueIdTag, blockTag, nsTag, ssTag,
00287     attribVectorTag, entityNameTag, categoryTag, hasMidNodesTag;
00288   std::map<int, EntityHandle> uidSetMap;
00289   std::map<int, EntityHandle> gidSetMap[6];
00290   bool swapForEndianness;
00291 
00292   std::vector<unsigned int> uint_buf;
00293   int *int_buf;
00294   std::vector<double> dbl_buf;
00295   std::vector<char> char_buf;
00296 
00297   static ReaderIface* factory( Interface* );
00298   
00299     // read cub file
00300   ErrorCode load_file( const char* file_name,
00301                        const EntityHandle* file_set,
00302                        const FileOptions& opts,
00303                        const SubsetList* subset_list = 0,
00304                        const Tag* file_id_tag = 0 );
00305 
00306   ErrorCode read_tag_values( const char* file_name,
00307                              const char* tag_name,
00308                              const FileOptions& opts,
00309                              std::vector<int>& tag_values_out,
00310                              const SubsetList* subset_list = 0 );
00311                                
00312   ErrorCode read_nodeset(const unsigned int nsindex,
00313                          ModelEntry *model,
00314                          NodesetHeader *nodeseth);
00315   ErrorCode read_sideset(const unsigned int ssindex,
00316                          const double data_version,
00317                          ModelEntry *model,
00318                          SidesetHeader *sideseth);
00319   ErrorCode read_block(const unsigned int blindex,
00320                        const double data_version,
00321                        ModelEntry *model,
00322                        BlockHeader *blockh);
00323   ErrorCode read_group(const unsigned int gr_index,
00324                          ModelEntry *model,
00325                          GroupHeader *grouph);
00326   ErrorCode read_nodes(const unsigned int gindex,
00327                   ModelEntry *model,
00328                   GeomHeader *entity);
00329   ErrorCode read_elements(ModelEntry *model,
00330                      GeomHeader *entity);
00331   ErrorCode read_file_header();
00332   ErrorCode read_model_entries();
00333   int find_model(const unsigned int model_type);
00334   ErrorCode read_meta_data(const unsigned int metadata_offset, 
00335                       MetaDataContainer &mc);
00336   ErrorCode read_md_string(std::string &name);
00337   
00338   enum {mesh, acist, acisb, facet, exodusmesh};
00339   EntityType type_from_cub_type(const unsigned int cub_type, const unsigned int nodes_per_elem);
00340   void check_contiguous(const unsigned int num_ents, int &contig, 
00341                         unsigned int &min_id, unsigned int &max_id);
00342 
00343   Tqdcfr(Interface *impl);
00344 
00345   ErrorCode create_set( EntityHandle& h, unsigned int flags = MESHSET_SET );
00346 
00347 private:
00348 
00349   EntityHandle mFileSet; // set containing read entities.
00350 
00351   bool printedSeqWarning; // only print acis sequence #'s warning once
00352   
00353   bool printedElemWarning; // only print element #'s warning once
00354   
00355   ErrorCode convert_nodesets_sidesets();
00356 
00357   ErrorCode read_acis_records( const char* sat_file_name = 0 );
00358   
00359   ErrorCode parse_acis_attribs(const unsigned int entity_rec_num,
00360                           std::vector<AcisRecord> &records);
00361   ErrorCode interpret_acis_records(std::vector<AcisRecord> &records);
00362 
00363   ErrorCode reset_record(AcisRecord &this_record);
00364   
00365   ErrorCode process_record(AcisRecord &this_record);
00366   
00367   static const char geom_categories[][CATEGORY_TAG_SIZE];
00368   
00369   FILE* acisDumpFile;
00370 
00371     // map between cub ids and MOAB handles
00372   std::vector<EntityHandle> *cubMOABVertexMap;
00373 
00374     // enum used to identify element/entity type in groups
00375   enum {GROUP = 0, BODY, VOLUME, SURFACE, CURVE, VERTEX, HEX, TET, PYRAMID, QUAD, TRI, EDGE, NODE};
00376   static const EntityType group_type_to_mb_type[];
00377 
00378   enum {SPHERE_EXO=0,
00379         BAR, BAR2, BAR3,
00380         BEAM, BEAM2, BEAM3,
00381         TRUSS, TRUSS2, TRUSS3,
00382         SPRING,
00383         TRIthree, TRI3, TRI6, TRI7,
00384         TRISHELL, TRISHELL3, TRISHELL6, TRISHELL7,
00385         SHEL, SHELL4, SHELL8, SHELL9,
00386         QUADfour, QUAD4, QUAD5, QUAD8, QUAD9,
00387         TETRAfour, TETRA4, TETRA8, TETRA10, TETRA14,
00388         PYRAMIDfive, PYRAMID5, PYRAMID8, PYRAMID13, PYRAMID18,
00389         HEXeight, HEX8, HEX9, HEX20, HEX27, HEXSHELL, 
00390         INVALID_ELEMENT_TYPE};
00391   static const EntityType block_type_to_mb_type[];
00392   static const int cub_elem_num_verts[];
00393   static const int cub_elem_num_verts_len;
00394 
00396   static const EntityType mp_type_to_mb_type[];
00397   
00400   ErrorCode get_entities(const unsigned int *mem_types,
00401                            int *id_buf, const unsigned int id_buf_size,
00402                            const bool is_group,
00403                            std::vector<EntityHandle> &entities);
00404   
00406   ErrorCode get_entities(const unsigned int this_type, 
00407                            int *id_buf, const unsigned int id_buf_size,
00408                            std::vector<EntityHandle> &entities,
00409                            std::vector<EntityHandle> &excl_entities);
00410   
00412   ErrorCode get_ref_entities(const unsigned int this_type, 
00413                                int *id_buf, const unsigned id_buf_size,
00414                                std::vector<EntityHandle> &entities);
00415   
00417   ErrorCode get_mesh_entities(const unsigned int this_type, 
00418                                 int *id_buf, const unsigned id_buf_size,
00419                                 std::vector<EntityHandle> &entities,
00420                                 std::vector<EntityHandle> &excl_entities);
00421   
00424   ErrorCode process_sideset_10(const int this_type, const int num_ents,
00425                                  const int sense_size,
00426                                  std::vector<EntityHandle> &ss_entities,
00427                                  Tqdcfr::SidesetHeader *sideseth);
00428 
00429   ErrorCode process_sideset_11(std::vector<EntityHandle> &ss_entities,
00430                                  int num_wrts,
00431                                  Tqdcfr::SidesetHeader *sideseth);
00432   
00433     // put entities into the specfied set, and excluded entities into a 
00434     // std::vector pointed to by the "Exclude_Entities" tag on that set
00435   ErrorCode put_into_set(EntityHandle set_handle,
00436                            std::vector<EntityHandle> &entities,
00437                            std::vector<EntityHandle> &excl_entities);
00438   
00439     // look in metadatacontainer[set_index] for name data; if found, set name (and extra names,
00440     // if multiple found) on set handle
00441   ErrorCode get_names(MetaDataContainer &md, unsigned int set_index, EntityHandle seth);
00442   
00443 };
00444 
00445 } // namespace moab
00446 
00447 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines