Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
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 <cstdio> 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, 00130 const FEModelHeader::ArrayInfo& info, 00131 Tqdcfr* instance, 00132 GeomHeader*& entity_headers ); 00133 00134 GeomHeader(); 00135 }; 00136 00137 class GroupHeader 00138 { 00139 public: 00140 unsigned int grpID, grpType, memCt, memOffset, memTypeCt, grpLength; 00141 00142 EntityHandle setHandle; 00143 00144 void print(); 00145 00146 static ErrorCode read_info_header( const unsigned int model_offset, 00147 const FEModelHeader::ArrayInfo& info, 00148 Tqdcfr* instance, 00149 GroupHeader*& entity_headers ); 00150 00151 GroupHeader(); 00152 }; 00153 00154 class BlockHeader 00155 { 00156 public: 00157 unsigned int blockID, blockElemType, memCt, memOffset, memTypeCt, attribOrder, blockCol, blockMixElemType, 00158 blockPyrType, blockMat, blockLength, blockDim; 00159 00160 EntityHandle setHandle; 00161 00162 EntityType blockEntityType; 00163 00164 int hasMidNodes[4]; 00165 00166 void print(); 00167 00168 static ErrorCode read_info_header( const double data_version, 00169 const unsigned int model_offset, 00170 const FEModelHeader::ArrayInfo& info, 00171 Tqdcfr* instance, 00172 BlockHeader*& block_headers ); 00173 00174 BlockHeader(); 00175 }; 00176 00177 class NodesetHeader 00178 { 00179 public: 00180 unsigned int nsID, memCt, memOffset, memTypeCt, pointSym, nsCol, nsLength; 00181 00182 EntityHandle setHandle; 00183 00184 void print(); 00185 00186 static ErrorCode read_info_header( const unsigned int model_offset, 00187 const FEModelHeader::ArrayInfo& info, 00188 Tqdcfr* instance, 00189 NodesetHeader*& entity_headers ); 00190 00191 NodesetHeader(); 00192 }; 00193 00194 class SidesetHeader 00195 { 00196 public: 00197 unsigned int ssID, memCt, memOffset, memTypeCt, numDF, ssCol, useShell, ssLength; 00198 00199 EntityHandle setHandle; 00200 00201 void print(); 00202 00203 static ErrorCode read_info_header( const unsigned int model_offset, 00204 const FEModelHeader::ArrayInfo& info, 00205 Tqdcfr* instance, 00206 SidesetHeader*& entity_headers ); 00207 00208 SidesetHeader(); 00209 }; 00210 00211 // class to hold model entry data for various kinds of models 00212 // (acis, free mesh, etc.) 00213 class ModelEntry 00214 { 00215 public: 00216 ModelEntry(); 00217 00218 ~ModelEntry(); 00219 00220 unsigned int modelHandle, modelOffset, modelLength, modelType, modelOwner, modelPad; 00221 00222 FEModelHeader feModelHeader; 00223 GeomHeader* feGeomH; 00224 GroupHeader* feGroupH; 00225 BlockHeader* feBlockH; 00226 NodesetHeader* feNodeSetH; 00227 SidesetHeader* feSideSetH; 00228 00229 MetaDataContainer geomMD, nodeMD, elementMD, groupMD, blockMD, nodesetMD, sidesetMD; 00230 00231 void print(); 00232 00233 void print_geom_headers( const char* prefix, GeomHeader* header, unsigned int num_headers ); 00234 00235 void print_group_headers( const char* prefix, GroupHeader* header, const unsigned int num_headers ); 00236 00237 void print_block_headers( const char* prefix, BlockHeader* header, const unsigned int num_headers ); 00238 00239 void print_nodeset_headers( const char* prefix, NodesetHeader* header, const unsigned int num_headers ); 00240 00241 void print_sideset_headers( const char* prefix, SidesetHeader* header, const unsigned int num_headers ); 00242 00243 ErrorCode read_header_info( Tqdcfr* instance, const double data_version ); 00244 ErrorCode read_metadata_info( Tqdcfr* tqd ); 00245 }; 00246 00247 enum 00248 { 00249 aBODY, 00250 LUMP, 00251 SHELL, 00252 FACE, 00253 LOOP, 00254 COEDGE, 00255 aEDGE, 00256 aVERTEX, 00257 ATTRIB, 00258 UNKNOWN 00259 }; 00260 00261 struct AcisRecord 00262 { 00263 unsigned int rec_type; 00264 std::string att_string; 00265 bool processed; 00266 int first_attrib; 00267 int att_prev, att_next, att_ent_num; 00268 EntityHandle entity; 00269 }; 00270 00271 ~Tqdcfr(); 00272 00273 ReadUtilIface* readUtilIface; 00274 Interface* mdbImpl; 00275 FILE* cubFile; 00276 FileTOC fileTOC; 00277 std::vector< ModelEntry > modelEntries; 00278 MetaDataContainer modelMetaData; 00279 long currVHandleOffset; 00280 Range beforeEnts; 00281 long currElementIdOffset[MBMAXTYPE]; 00282 Tag globalIdTag, cubIdTag, geomTag, uniqueIdTag, blockTag, nsTag, ssTag, attribVectorTag, entityNameTag, 00283 categoryTag, hasMidNodesTag; 00284 std::map< int, EntityHandle > uidSetMap; 00285 std::map< int, EntityHandle > gidSetMap[6]; 00286 bool swapForEndianness; 00287 00288 std::vector< unsigned int > uint_buf; 00289 int* int_buf; 00290 std::vector< double > dbl_buf; 00291 std::vector< char > char_buf; 00292 00293 static ReaderIface* factory( Interface* ); 00294 00295 // read cub file 00296 ErrorCode load_file( const char* file_name, 00297 const EntityHandle* file_set, 00298 const FileOptions& opts, 00299 const SubsetList* subset_list = 0, 00300 const Tag* file_id_tag = 0 ); 00301 00302 ErrorCode read_tag_values( const char* file_name, 00303 const char* tag_name, 00304 const FileOptions& opts, 00305 std::vector< int >& tag_values_out, 00306 const SubsetList* subset_list = 0 ); 00307 00308 ErrorCode read_nodeset( const unsigned int nsindex, ModelEntry* model, NodesetHeader* nodeseth ); 00309 ErrorCode read_sideset( const unsigned int ssindex, 00310 const double data_version, 00311 ModelEntry* model, 00312 SidesetHeader* sideseth ); 00313 ErrorCode read_block( const unsigned int blindex, 00314 const double data_version, 00315 ModelEntry* model, 00316 BlockHeader* blockh ); 00317 ErrorCode read_group( const unsigned int gr_index, ModelEntry* model, GroupHeader* grouph ); 00318 ErrorCode read_nodes( const unsigned int gindex, ModelEntry* model, GeomHeader* entity ); 00319 ErrorCode read_elements( ModelEntry* model, GeomHeader* entity ); 00320 ErrorCode read_file_header(); 00321 ErrorCode read_model_entries(); 00322 int find_model( const unsigned int model_type ); 00323 ErrorCode read_meta_data( const unsigned int metadata_offset, MetaDataContainer& mc ); 00324 ErrorCode read_md_string( std::string& name ); 00325 00326 enum 00327 { 00328 mesh, 00329 acist, 00330 acisb, 00331 facet, 00332 exodusmesh 00333 }; 00334 EntityType type_from_cub_type( const unsigned int cub_type, const unsigned int nodes_per_elem ); 00335 void check_contiguous( const unsigned int num_ents, int& contig, unsigned int& min_id, unsigned int& max_id ); 00336 00337 Tqdcfr( Interface* impl ); 00338 00339 ErrorCode create_set( EntityHandle& h, unsigned int flags = MESHSET_SET ); 00340 00341 private: 00342 EntityHandle mFileSet; // set containing read entities. 00343 00344 bool printedSeqWarning; // only print acis sequence #'s warning once 00345 00346 bool printedElemWarning; // only print element #'s warning once 00347 00348 ErrorCode convert_nodesets_sidesets(); 00349 00350 ErrorCode read_acis_records( const char* sat_file_name = 0 ); 00351 00352 ErrorCode parse_acis_attribs( const unsigned int entity_rec_num, std::vector< AcisRecord >& records ); 00353 ErrorCode interpret_acis_records( std::vector< AcisRecord >& records ); 00354 00355 ErrorCode reset_record( AcisRecord& this_record ); 00356 00357 ErrorCode process_record( AcisRecord& this_record ); 00358 00359 static const char geom_categories[][CATEGORY_TAG_SIZE]; 00360 00361 FILE* acisDumpFile; 00362 00363 // map between cub ids and MOAB handles 00364 std::vector< EntityHandle >* cubMOABVertexMap; 00365 00366 // enum used to identify element/entity type in groups 00367 enum 00368 { 00369 GROUP = 0, 00370 BODY, 00371 VOLUME, 00372 SURFACE, 00373 CURVE, 00374 VERTEX, 00375 HEX, 00376 TET, 00377 PYRAMID, 00378 QUAD, 00379 TRI, 00380 EDGE, 00381 NODE 00382 }; 00383 static const EntityType group_type_to_mb_type[]; 00384 00385 enum 00386 { 00387 SPHERE_EXO = 0, 00388 BAR, 00389 BAR2, 00390 BAR3, 00391 BEAM, 00392 BEAM2, 00393 BEAM3, 00394 TRUSS, 00395 TRUSS2, 00396 TRUSS3, 00397 SPRING, 00398 TRIthree, 00399 TRI3, 00400 TRI6, 00401 TRI7, 00402 TRISHELL, 00403 TRISHELL3, 00404 TRISHELL6, 00405 TRISHELL7, 00406 SHEL, 00407 SHELL4, 00408 SHELL8, 00409 SHELL9, 00410 QUADfour, 00411 QUAD4, 00412 QUAD5, 00413 QUAD8, 00414 QUAD9, 00415 TETRAfour, 00416 TETRA4, 00417 TETRA8, 00418 TETRA10, 00419 TETRA14, 00420 PYRAMIDfive, 00421 PYRAMID5, 00422 PYRAMID8, 00423 PYRAMID13, 00424 PYRAMID18, 00425 HEXeight, 00426 HEX8, 00427 HEX9, 00428 HEX20, 00429 HEX27, 00430 HEXSHELL, 00431 INVALID_ELEMENT_TYPE 00432 }; 00433 static const EntityType block_type_to_mb_type[]; 00434 static const int cub_elem_num_verts[]; 00435 static const int cub_elem_num_verts_len; 00436 00437 //! mapping from mesh packet type to moab type 00438 static const EntityType mp_type_to_mb_type[]; 00439 00440 //! get entities with individually-specified types; if is_group is false, 00441 //! increment each mem_type by 2 since they're CSOEntityType's and not group types 00442 ErrorCode get_entities( const unsigned int* mem_types, 00443 int* id_buf, 00444 const unsigned int id_buf_size, 00445 const bool is_group, 00446 std::vector< EntityHandle >& entities ); 00447 00448 //! get entities specified by type and ids, append to entities 00449 ErrorCode get_entities( const unsigned int this_type, 00450 int* id_buf, 00451 const unsigned int id_buf_size, 00452 std::vector< EntityHandle >& entities, 00453 std::vector< EntityHandle >& excl_entities ); 00454 00455 //! get ref entity sets with specified type and ids 00456 ErrorCode get_ref_entities( const unsigned int this_type, 00457 int* id_buf, 00458 const unsigned id_buf_size, 00459 std::vector< EntityHandle >& entities ); 00460 00461 //! get mesh entities with specified type and ids 00462 ErrorCode get_mesh_entities( const unsigned int this_type, 00463 int* id_buf, 00464 const unsigned id_buf_size, 00465 std::vector< EntityHandle >& entities, 00466 std::vector< EntityHandle >& excl_entities ); 00467 00468 //! process entities in a sideset according to sense flags stored in uint_buf 00469 //! or char_buf (depending on sense_size) 00470 ErrorCode process_sideset_10( const int this_type, 00471 const int num_ents, 00472 const int sense_size, 00473 std::vector< EntityHandle >& ss_entities, 00474 Tqdcfr::SidesetHeader* sideseth ); 00475 00476 ErrorCode process_sideset_11( std::vector< EntityHandle >& ss_entities, 00477 int num_wrts, 00478 Tqdcfr::SidesetHeader* sideseth ); 00479 00480 // put entities into the specfied set, and excluded entities into a 00481 // std::vector pointed to by the "Exclude_Entities" tag on that set 00482 ErrorCode put_into_set( EntityHandle set_handle, 00483 std::vector< EntityHandle >& entities, 00484 std::vector< EntityHandle >& excl_entities ); 00485 00486 // look in metadatacontainer[set_index] for name data; if found, set name (and extra names, 00487 // if multiple found) on set handle 00488 ErrorCode get_names( MetaDataContainer& md, unsigned int set_index, EntityHandle seth ); 00489 }; 00490 00491 } // namespace moab 00492 00493 #endif