Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
Tqdcfr.hpp
Go to the documentation of this file.
1 /**
2  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3  * storing and accessing finite element mesh data.
4  *
5  * Copyright 2004 Sandia Corporation. Under the terms of Contract
6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7  * retains certain rights in this software.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  */
15 
16 /*
17  * Tim's Quick 'N Dirty Cub File Reader (Tqdcfr)
18  *
19  */
20 
21 #ifndef TQDCFR
22 #define TQDCFR
23 
24 #include "moab/Forward.hpp"
25 #include "moab/ReaderIface.hpp"
26 #include "MBTagConventions.hpp"
27 #include "moab/Range.hpp"
28 
29 #include <cstdio>
30 #include <string>
31 #include <vector>
32 #include <map>
33 
34 namespace moab
35 {
36 
37 class ReadUtilIface;
38 class FEModelHeader;
39 class GeomHeader;
40 class GroupHeader;
41 class BlockHeader;
42 class NodesetHeader;
43 class SidesetHeader;
44 
45 class Tqdcfr : public ReaderIface
46 {
47  public:
48  void FSEEK( unsigned offset ); // set cubFile offset to specified value
49  void FREADI( unsigned num_ents ); // read integers into uint_buf
50  void FREADD( unsigned num_ents ); // read doubles into dbl_buf
51  void FREADC( unsigned num_ents ); // read characters into char_buf
52  void FREADIA( unsigned num_ents, unsigned int* array ); // read integers
53  void FREADDA( unsigned num_ents, double* array ); // read doubles
54  void FREADCA( unsigned num_ents, char* arrat ); // read bytes
55  void CONVERT_TO_INTS( unsigned int num_ents ); // convert uint_buf to int_buf in-place
56 
57  // class for holding the file table of contents
58  class FileTOC
59  {
60  public:
62 
63  FileTOC();
64  void print();
65  };
66 
67  //
69  {
70  public:
72 
73  class ArrayInfo
74  {
75  public:
77 
78  ArrayInfo();
79 
80  void print();
81  void init( const std::vector< unsigned int >& uint_buf_in );
82  };
83 
85 
86  void init( const unsigned int offset, Tqdcfr* instance );
87 
88  void print();
89  };
90 
92  {
93  public:
94  unsigned int mdSchema, compressFlag;
95 
97  {
98  public:
99  unsigned int mdOwner, mdDataType, mdIntValue;
100  std::string mdName, mdStringValue;
101  std::vector< unsigned int > mdIntArrayValue;
102  double mdDblValue;
103  std::vector< double > mdDblArrayValue;
104 
105  MetaDataEntry();
106 
107  void print();
108  };
109 
110  void print();
111 
112  int get_md_entry( const unsigned int owner, const std::string& name );
113 
114  std::vector< MetaDataEntry > metadataEntries;
116  };
117 
119  {
120  public:
122 
123  int maxDim;
124 
126 
127  void print();
128 
129  static ErrorCode read_info_header( const unsigned int model_offset,
130  const FEModelHeader::ArrayInfo& info,
131  Tqdcfr* instance,
132  GeomHeader*& entity_headers );
133 
134  GeomHeader();
135  };
136 
138  {
139  public:
141 
143 
144  void print();
145 
146  static ErrorCode read_info_header( const unsigned int model_offset,
147  const FEModelHeader::ArrayInfo& info,
148  Tqdcfr* instance,
149  GroupHeader*& entity_headers );
150 
151  GroupHeader();
152  };
153 
155  {
156  public:
159 
161 
162  EntityType blockEntityType;
163 
164  int hasMidNodes[4];
165 
166  void print();
167 
168  static ErrorCode read_info_header( const double data_version,
169  const unsigned int model_offset,
170  const FEModelHeader::ArrayInfo& info,
171  Tqdcfr* instance,
172  BlockHeader*& block_headers );
173 
174  BlockHeader();
175  };
176 
178  {
179  public:
181 
183 
184  void print();
185 
186  static ErrorCode read_info_header( const unsigned int model_offset,
187  const FEModelHeader::ArrayInfo& info,
188  Tqdcfr* instance,
189  NodesetHeader*& entity_headers );
190 
191  NodesetHeader();
192  };
193 
195  {
196  public:
198 
200 
201  void print();
202 
203  static ErrorCode read_info_header( const unsigned int model_offset,
204  const FEModelHeader::ArrayInfo& info,
205  Tqdcfr* instance,
206  SidesetHeader*& entity_headers );
207 
208  SidesetHeader();
209  };
210 
211  // class to hold model entry data for various kinds of models
212  // (acis, free mesh, etc.)
214  {
215  public:
216  ModelEntry();
217 
218  ~ModelEntry();
219 
221 
228 
230 
231  void print();
232 
233  void print_geom_headers( const char* prefix, GeomHeader* header, unsigned int num_headers );
234 
235  void print_group_headers( const char* prefix, GroupHeader* header, const unsigned int num_headers );
236 
237  void print_block_headers( const char* prefix, BlockHeader* header, const unsigned int num_headers );
238 
239  void print_nodeset_headers( const char* prefix, NodesetHeader* header, const unsigned int num_headers );
240 
241  void print_sideset_headers( const char* prefix, SidesetHeader* header, const unsigned int num_headers );
242 
243  ErrorCode read_header_info( Tqdcfr* instance, const double data_version );
245  };
246 
247  enum
248  {
258  UNKNOWN
259  };
260 
261  struct AcisRecord
262  {
263  unsigned int rec_type;
264  std::string att_string;
265  bool processed;
269  };
270 
271  ~Tqdcfr();
272 
275  FILE* cubFile;
277  std::vector< ModelEntry > modelEntries;
284  std::map< int, EntityHandle > uidSetMap;
285  std::map< int, EntityHandle > gidSetMap[6];
287 
288  std::vector< unsigned int > uint_buf;
289  int* int_buf;
290  std::vector< double > dbl_buf;
291  std::vector< char > char_buf;
292 
293  static ReaderIface* factory( Interface* );
294 
295  // read cub file
296  ErrorCode load_file( const char* file_name,
297  const EntityHandle* file_set,
298  const FileOptions& opts,
299  const SubsetList* subset_list = 0,
300  const Tag* file_id_tag = 0 );
301 
302  ErrorCode read_tag_values( const char* file_name,
303  const char* tag_name,
304  const FileOptions& opts,
305  std::vector< int >& tag_values_out,
306  const SubsetList* subset_list = 0 );
307 
308  ErrorCode read_nodeset( const unsigned int nsindex, ModelEntry* model, NodesetHeader* nodeseth );
309  ErrorCode read_sideset( const unsigned int ssindex,
310  const double data_version,
311  ModelEntry* model,
312  SidesetHeader* sideseth );
313  ErrorCode read_block( const unsigned int blindex,
314  const double data_version,
315  ModelEntry* model,
316  BlockHeader* blockh );
317  ErrorCode read_group( const unsigned int gr_index, ModelEntry* model, GroupHeader* grouph );
318  ErrorCode read_nodes( const unsigned int gindex, ModelEntry* model, GeomHeader* entity );
319  ErrorCode read_elements( ModelEntry* model, GeomHeader* entity );
322  int find_model( const unsigned int model_type );
323  ErrorCode read_meta_data( const unsigned int metadata_offset, MetaDataContainer& mc );
324  ErrorCode read_md_string( std::string& name );
325 
326  enum
327  {
332  exodusmesh
333  };
334  EntityType type_from_cub_type( const unsigned int cub_type, const unsigned int nodes_per_elem );
335  void check_contiguous( const unsigned int num_ents, int& contig, unsigned int& min_id, unsigned int& max_id );
336 
337  Tqdcfr( Interface* impl );
338 
339  ErrorCode create_set( EntityHandle& h, unsigned int flags = MESHSET_SET );
340 
341  private:
342  EntityHandle mFileSet; // set containing read entities.
343 
344  bool printedSeqWarning; // only print acis sequence #'s warning once
345 
346  bool printedElemWarning; // only print element #'s warning once
347 
349 
350  ErrorCode read_acis_records( const char* sat_file_name = 0 );
351 
352  ErrorCode parse_acis_attribs( const unsigned int entity_rec_num, std::vector< AcisRecord >& records );
353  ErrorCode interpret_acis_records( std::vector< AcisRecord >& records );
354 
355  ErrorCode reset_record( AcisRecord& this_record );
356 
357  ErrorCode process_record( AcisRecord& this_record );
358 
359  static const char geom_categories[][CATEGORY_TAG_SIZE];
360 
362 
363  // map between cub ids and MOAB handles
364  std::vector< EntityHandle >* cubMOABVertexMap;
365 
366  // enum used to identify element/entity type in groups
367  enum
368  {
369  GROUP = 0,
381  NODE
382  };
383  static const EntityType group_type_to_mb_type[];
384 
385  enum
386  {
432  };
433  static const EntityType block_type_to_mb_type[];
434  static const int cub_elem_num_verts[];
435  static const int cub_elem_num_verts_len;
436 
437  //! mapping from mesh packet type to moab type
438  static const EntityType mp_type_to_mb_type[];
439 
440  //! get entities with individually-specified types; if is_group is false,
441  //! increment each mem_type by 2 since they're CSOEntityType's and not group types
442  ErrorCode get_entities( const unsigned int* mem_types,
443  int* id_buf,
444  const unsigned int id_buf_size,
445  const bool is_group,
446  std::vector< EntityHandle >& entities );
447 
448  //! get entities specified by type and ids, append to entities
449  ErrorCode get_entities( const unsigned int this_type,
450  int* id_buf,
451  const unsigned int id_buf_size,
452  std::vector< EntityHandle >& entities,
453  std::vector< EntityHandle >& excl_entities );
454 
455  //! get ref entity sets with specified type and ids
456  ErrorCode get_ref_entities( const unsigned int this_type,
457  int* id_buf,
458  const unsigned id_buf_size,
459  std::vector< EntityHandle >& entities );
460 
461  //! get mesh entities with specified type and ids
462  ErrorCode get_mesh_entities( const unsigned int this_type,
463  int* id_buf,
464  const unsigned id_buf_size,
465  std::vector< EntityHandle >& entities,
466  std::vector< EntityHandle >& excl_entities );
467 
468  //! process entities in a sideset according to sense flags stored in uint_buf
469  //! or char_buf (depending on sense_size)
470  ErrorCode process_sideset_10( const int this_type,
471  const int num_ents,
472  const int sense_size,
473  std::vector< EntityHandle >& ss_entities,
474  Tqdcfr::SidesetHeader* sideseth );
475 
476  ErrorCode process_sideset_11( std::vector< EntityHandle >& ss_entities,
477  int num_wrts,
478  Tqdcfr::SidesetHeader* sideseth );
479 
480  // put entities into the specfied set, and excluded entities into a
481  // std::vector pointed to by the "Exclude_Entities" tag on that set
482  ErrorCode put_into_set( EntityHandle set_handle,
483  std::vector< EntityHandle >& entities,
484  std::vector< EntityHandle >& excl_entities );
485 
486  // look in metadatacontainer[set_index] for name data; if found, set name (and extra names,
487  // if multiple found) on set handle
488  ErrorCode get_names( MetaDataContainer& md, unsigned int set_index, EntityHandle seth );
489 };
490 
491 } // namespace moab
492 
493 #endif