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