Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
moab::ReadIDEAS Class Reference

#include <ReadIDEAS.hpp>

+ Inheritance diagram for moab::ReadIDEAS:
+ Collaboration diagram for moab::ReadIDEAS:

Public Member Functions

ErrorCode load_file (const char *file_name, const EntityHandle *file_set, const FileOptions &opts, const SubsetList *subset_list=0, const Tag *file_id_tag=0)
 Load mesh from a file. More...
 
ErrorCode read_tag_values (const char *file_name, const char *tag_name, const FileOptions &opts, std::vector< int > &tag_values_out, const SubsetList *subset_list=0)
 Read tag values from a file. More...
 
 ReadIDEAS (Interface *impl=NULL)
 Constructor. More...
 
virtual ~ReadIDEAS ()
 Destructor. More...
 
- Public Member Functions inherited from moab::ReaderIface
virtual ~ReaderIface ()
 

Static Public Member Functions

static ReaderIfacefactory (Interface *)
 

Protected Member Functions

ErrorCode skip_header ()
 
ErrorCode create_vertices (EntityHandle &first_vertex, const Tag *file_id_tag)
 
ErrorCode create_elements (EntityHandle first_vertex, const Tag *file_id_tag)
 

Private Attributes

std::ifstream file
 
RangeMap< int, EntityHandlenodeIdMap
 
ReadUtilIfacereadMeshIface
 
InterfaceMBI
 

Static Private Attributes

static const unsigned SINGLE_PRECISION_NODES = 15
 
static const unsigned DOUBLE_PRECISION_NODES0 = 781
 
static const unsigned DOUBLE_PRECISION_NODES1 = 2411
 
static const unsigned ELEMENTS0 = 71
 
static const unsigned ELEMENTS1 = 780
 
static const unsigned ELEMENTS2 = 2412
 
static const int ROD0 = 11
 
static const int ROD1 = 171
 
static const int TRI0 = 41
 
static const int TRI1 = 91
 
static const int QUAD0 = 44
 
static const int QUAD1 = 94
 
static const int TET = 111
 
static const int WEDGE = 112
 
static const int HEX = 115
 

Detailed Description

Definition at line 24 of file ReadIDEAS.hpp.

Constructor & Destructor Documentation

◆ ReadIDEAS()

moab::ReadIDEAS::ReadIDEAS ( Interface impl = NULL)

Constructor.

Definition at line 25 of file ReadIDEAS.cpp.

25  : MBI( impl )
26 {
28 }

References moab::Interface::query_interface(), and readMeshIface.

Referenced by factory().

◆ ~ReadIDEAS()

virtual moab::ReadIDEAS::~ReadIDEAS ( )
inlinevirtual

Destructor.

Definition at line 46 of file ReadIDEAS.hpp.

46 {}

Member Function Documentation

◆ create_elements()

ErrorCode moab::ReadIDEAS::create_elements ( EntityHandle  first_vertex,
const Tag file_id_tag 
)
protected

Definition at line 210 of file ReadIDEAS.cpp.

211 {
212  char line1[10000], line2[10000];
213  int il1, il2;
214  char *ctmp1, *ctmp2;
215  std::string s1, s2;
216  ErrorCode rval;
217  EntityHandle handle;
218 
219  Tag mat_tag, phys_tag, id_tag;
221  if( MB_SUCCESS != rval && MB_ALREADY_ALLOCATED != rval ) return rval;
223  if( MB_SUCCESS != rval && MB_ALREADY_ALLOCATED != rval ) return rval;
224  id_tag = MBI->globalId_tag();
225 
226  for( ;; )
227  {
228  if( !file.getline( line1, 10000 ) || !file.getline( line2, 10000 ) ) return MB_FAILURE;
229 
230  // Check if we are at the end of the block
231  il1 = std::strtol( line1, &ctmp1, 10 );
232  il2 = std::strtol( line2, &ctmp2, 10 );
233  if( ( il1 == -1 ) && ( il2 == -1 ) )
234  {
235  s1 = ctmp1;
236  s2 = ctmp2;
237  if( ( s1.empty() ) && ( s2.empty() ) ) return MB_SUCCESS;
238  }
239 
240  // The first line describes attributes of the element other than connectivity.
241  const int element_id = strtol( line1 + 1, &ctmp1, 10 );
242  const int ideas_type = strtol( line1 + 11, &ctmp1, 10 );
243  const int phys_table = strtol( line1 + 21, &ctmp1, 10 );
244  const int mat_table = strtol( line1 + 31, &ctmp1, 10 );
245 
246  // Determine the element type.
247  EntityType mb_type;
248  if( TRI0 == ideas_type || TRI1 == ideas_type )
249  mb_type = MBTRI;
250  else if( QUAD0 == ideas_type || QUAD1 == ideas_type )
251  mb_type = MBQUAD;
252  else if( TET == ideas_type )
253  mb_type = MBTET;
254  else if( HEX == ideas_type )
255  mb_type = MBHEX;
256  else if( WEDGE == ideas_type )
257  mb_type = MBPRISM;
258  else
259  {
260  std::cout << "IDEAS element type not yet added to MOAB reader." << std::endl;
261  return MB_NOT_IMPLEMENTED;
262  }
263 
264  // Get the connectivity out of the 2nd line
265  std::stringstream ss( line2 );
266  const int n_conn = CN::VerticesPerEntity( mb_type );
268  EntityHandle vert;
269  for( int i = 0; i < n_conn; ++i )
270  {
271  ss >> vert;
272  conn[i] = vstart + vert - 1;
273  }
274 
275  // Make the element. According to the Gmsh 2.2.3 source code, the IDEAS
276  // canonical numbering is the same as MBCN.
277  MB_CHK_SET_ERR( MBI->create_element( mb_type, conn, n_conn, handle ),
278  "can't create elements of type " << mb_type );
279 
280  // If the phys set does not already exist, create it.
281  Range phys_sets;
282  EntityHandle phys_set;
283  const void* const phys_set_id_val[] = { &phys_table };
284  MB_CHK_SET_ERR( MBI->get_entities_by_type_and_tag( 0, MBENTITYSET, &phys_tag, phys_set_id_val, 1, phys_sets ),
285  "can't get phys sets" );
286  if( phys_sets.empty() )
287  {
288  MB_CHK_SET_ERR( MBI->create_meshset( MESHSET_SET, phys_set ), "can't create phys set" );
289  MB_CHK_SET_ERR( MBI->tag_set_data( phys_tag, &phys_set, 1, &phys_table ), "can't set tag to phys set" );
290  }
291  else if( 1 == phys_sets.size() )
292  {
293  phys_set = phys_sets.front();
294  }
295  else
296  {
298  }
299  MB_CHK_SET_ERR( MBI->add_entities( phys_set, &handle, 1 ), "can't add entities to phys set" );
300 
301  // If the material set does not already exist, create it.
302  Range mat_sets;
303  EntityHandle mat_set;
304  const void* const mat_set_id_val[] = { &mat_table };
305  rval = MBI->get_entities_by_type_and_tag( 0, MBENTITYSET, &mat_tag, mat_set_id_val, 1, mat_sets );
306  if( MB_SUCCESS != rval ) return rval;
307  if( mat_sets.empty() )
308  {
309  rval = MBI->create_meshset( MESHSET_SET, mat_set );
310  if( MB_SUCCESS != rval ) return rval;
311  rval = MBI->tag_set_data( mat_tag, &mat_set, 1, &mat_table );
312  if( MB_SUCCESS != rval ) return rval;
313  }
314  else if( 1 == mat_sets.size() )
315  {
316  mat_set = mat_sets.front();
317  }
318  else
319  {
321  }
322  rval = MBI->add_entities( mat_set, &handle, 1 );
323  if( MB_SUCCESS != rval ) return rval;
324 
325  // Tag the element with its id
326  MB_CHK_SET_ERR( MBI->tag_set_data( id_tag, &handle, 1, &element_id ), "Failed to assign IDs" );
327  if( file_id_tag )
328  {
329  MB_CHK_SET_ERR( MBI->tag_set_data( *file_id_tag, &handle, 1, &element_id ), "Failed to assign file IDs" );
330  }
331  }
332 }

References moab::Interface::add_entities(), moab::Interface::create_element(), moab::Interface::create_meshset(), moab::Range::empty(), ErrorCode, file, moab::Range::front(), moab::Interface::get_entities_by_type_and_tag(), moab::Interface::globalId_tag(), HEX, MAT_PROP_TABLE_TAG, moab::CN::MAX_NODES_PER_ELEMENT, MB_ALREADY_ALLOCATED, MB_CHK_SET_ERR, MB_MULTIPLE_ENTITIES_FOUND, MB_NOT_IMPLEMENTED, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_DENSE, MB_TYPE_INTEGER, MBENTITYSET, MBHEX, MBI, MBPRISM, MBQUAD, MBTET, MBTRI, MESHSET_SET, PHYS_PROP_TABLE_TAG, QUAD0, QUAD1, moab::Range::size(), moab::Interface::tag_get_handle(), moab::Interface::tag_set_data(), TET, TRI0, TRI1, moab::CN::VerticesPerEntity(), and WEDGE.

Referenced by load_file().

◆ create_vertices()

ErrorCode moab::ReadIDEAS::create_vertices ( EntityHandle first_vertex,
const Tag file_id_tag 
)
protected

Definition at line 129 of file ReadIDEAS.cpp.

130 {
131  // Read two lines: first has some data, second has coordinates
132  char line1[10000], line2[10000];
133  int il1, il2;
134  char *ctmp1, *ctmp2;
135  std::string s1, s2;
136 
137  ErrorCode rval;
138 
139  std::streampos top_of_block = file.tellg();
140  unsigned int num_verts = 0;
141 
142  for( ;; )
143  {
144  // Read both lines
145  if( !file.getline( line1, 10000 ) ) return MB_FAILURE;
146  if( !file.getline( line2, 10000 ) ) return MB_FAILURE;
147 
148  // Check if we are at the end of the block
149  il1 = std::strtol( line1, &ctmp1, 10 );
150  il2 = std::strtol( line2, &ctmp2, 10 );
151  if( ( il1 == -1 ) && ( il2 == -1 ) )
152  {
153  s1 = ctmp1;
154  s2 = ctmp2;
155  if( ( s1.empty() ) && ( s2.empty() ) ) break;
156  }
157  num_verts++;
158  }
159 
160  file.seekg( top_of_block );
161 
162  std::vector< double* > arrays;
163  rval = readMeshIface->get_node_coords( 3, num_verts, 0, first_vertex, arrays );
164  if( MB_SUCCESS != rval ) return rval;
165 
166  Range verts;
167  verts.insert( first_vertex, first_vertex + num_verts - 1 );
168 
169  double* x = arrays[0];
170  double* y = arrays[1];
171  double* z = arrays[2];
172 
173  // For now, assume ids are sequential and begin with 1
174  Tag id_tag = MBI->globalId_tag();
175  const int beginning_node_id = 1;
176  int node_id = beginning_node_id;
177 
178  for( unsigned int i = 0; i < num_verts; i++ )
179  {
180  if( !file.getline( line1, 10000 ) ) return MB_FAILURE;
181  if( !file.getline( line2, 10000 ) ) return MB_FAILURE;
182 
183  // Get the id out of the 1st line. Check the assumption that node ids are
184  // sequential and begin with 1.
185  if( node_id != std::strtol( line1, &ctmp1, 10 ) )
186  MB_SET_ERR( MB_FAILURE, "node_id " << node_id << " line2:" << line2 << " ctmp1:" << ctmp1 );
187  else
188  ++node_id;
189 
190  // Get the doubles out of the 2nd line
191  x[i] = std::strtod( line2, &ctmp2 );
192  y[i] = std::strtod( ctmp2 + 1, &ctmp2 );
193  z[i] = std::strtod( ctmp2 + 1, NULL );
194  }
195 
196  if( !file.getline( line1, 10000 ) ) MB_SET_ERR( MB_FAILURE, " expect more lines" );
197  if( !file.getline( line2, 10000 ) ) MB_SET_ERR( MB_FAILURE, " expect more lines 2" );
198 
199  // Tag the nodes with ids
200  MB_CHK_SET_ERR( readMeshIface->assign_ids( id_tag, verts, beginning_node_id ), "Failed to assign IDs" );
201  if( file_id_tag )
202  {
203  MB_CHK_SET_ERR( readMeshIface->assign_ids( *file_id_tag, verts, beginning_node_id ),
204  "Failed to assign file IDs" );
205  }
206 
207  return MB_SUCCESS;
208 }

References moab::ReadUtilIface::assign_ids(), ErrorCode, file, moab::ReadUtilIface::get_node_coords(), moab::Interface::globalId_tag(), moab::Range::insert(), MB_CHK_SET_ERR, MB_SET_ERR, MB_SUCCESS, MBI, and readMeshIface.

Referenced by load_file().

◆ factory()

ReaderIface * moab::ReadIDEAS::factory ( Interface iface)
static

Definition at line 20 of file ReadIDEAS.cpp.

21 {
22  return new ReadIDEAS( iface );
23 }

References iface, and ReadIDEAS().

Referenced by moab::ReaderWriterSet::ReaderWriterSet().

◆ load_file()

ErrorCode moab::ReadIDEAS::load_file ( const char *  file_name,
const EntityHandle file_set,
const FileOptions opts,
const SubsetList subset_list = 0,
const Tag file_id_tag = 0 
)
virtual

Load mesh from a file.

Method all readers must provide to import a mesh.

Parameters
file_nameThe file to read.
file_setOptional pointer to entity set representing file. If this is not NULL, reader may optionally tag the pointed-to set with format-specific meta-data.
subset_listAn optional struct pointer specifying the tags identifying entity sets to be read.
file_id_tagIf specified, reader should store for each entity it reads, a unique integer ID for this tag.
Author
Jason Kraftcheck

Implements moab::ReaderIface.

Definition at line 39 of file ReadIDEAS.cpp.

44 {
45  if( subset_list )
46  {
47  MB_SET_ERR( MB_UNSUPPORTED_OPERATION, "Reading subset of files not supported for IDEAS" );
48  }
49 
50  file.open( fname );
51  if( !file.good() )
52  {
53  MB_SET_ERR( MB_FILE_DOES_NOT_EXIST, "Failed to open file: " << fname );
54  }
55 
56  ErrorCode rval;
57 
58  char line[10000];
59  file.getline( line, 10000 );
60  char* liter = line;
61  while( *liter && isspace( *liter ) )
62  ++liter;
63  if( *liter != '-' ) return MB_FAILURE;
64  ++liter;
65  if( *liter != '1' ) return MB_FAILURE;
66  while( *++liter )
67  if( !isspace( *liter ) ) return MB_FAILURE;
68 
69  EntityHandle first_vertex = 0;
70  while( !file.eof() )
71  {
72  file.getline( line, 10000 );
73  unsigned int header_id = (unsigned int)strtol( line, NULL, 10 );
74 
75  // Create vertices
76  if( DOUBLE_PRECISION_NODES0 == header_id || DOUBLE_PRECISION_NODES1 == header_id )
77  {
78  if( first_vertex ) // multiple vertex blocks?
79  return MB_FAILURE;
80  MB_CHK_SET_ERR( create_vertices( first_vertex, file_id_tag ), "Failed to read vertices" );
81  }
82  // Create elements
83  else if( ELEMENTS0 == header_id || ELEMENTS1 == header_id || ELEMENTS2 == header_id )
84  {
85  if( !first_vertex ) // Need to read vertices first
86  return MB_FAILURE;
87  MB_CHK_SET_ERR( create_elements( first_vertex, file_id_tag ), "Failed to read elements" );
88  }
89  // Skip everything else
90  else
91  {
92  rval = skip_header();
93  if( MB_SUCCESS != rval ) return MB_FAILURE;
94  }
95  }
96 
97  file.close();
98  return MB_SUCCESS;
99 }

References create_elements(), create_vertices(), DOUBLE_PRECISION_NODES0, DOUBLE_PRECISION_NODES1, ELEMENTS0, ELEMENTS1, ELEMENTS2, ErrorCode, file, MB_CHK_SET_ERR, MB_FILE_DOES_NOT_EXIST, MB_SET_ERR, MB_SUCCESS, MB_UNSUPPORTED_OPERATION, and skip_header().

◆ read_tag_values()

ErrorCode moab::ReadIDEAS::read_tag_values ( const char *  file_name,
const char *  tag_name,
const FileOptions opts,
std::vector< int > &  tag_values_out,
const SubsetList subset_list = 0 
)
virtual

Read tag values from a file.

Read the list if all integer tag values from the file for a tag that is a single integer value per entity.

Parameters
file_nameThe file to read.
tag_nameThe tag for which to read values
tag_values_outOutput: The list of tag values.
subset_listAn array of tag name and value sets specifying the subset of the file to read. If multiple tags are specified, the sets that match all tags (intersection) should be read.
subset_list_lengthThe length of the 'subset_list' array.

Implements moab::ReaderIface.

Definition at line 30 of file ReadIDEAS.cpp.

35 {
36  return MB_NOT_IMPLEMENTED;
37 }

References MB_NOT_IMPLEMENTED.

◆ skip_header()

ErrorCode moab::ReadIDEAS::skip_header ( )
protected

Definition at line 101 of file ReadIDEAS.cpp.

102 {
103  // Go until finding a pair of -1 lines
104  char* ctmp;
105  char line[10000];
106  std::string s;
107 
108  int end_of_block = 0;
109 
110  long int il;
111 
112  while( file.getline( line, 10000 ) )
113  {
114  il = std::strtol( line, &ctmp, 10 );
115  if( il == -1 )
116  {
117  s = ctmp;
118  if( s.empty() ) end_of_block++;
119  }
120  else
121  end_of_block = 0;
122 
123  if( end_of_block >= 2 ) return MB_SUCCESS;
124  }
125 
126  return MB_SUCCESS;
127 }

References file, and MB_SUCCESS.

Referenced by load_file().

Member Data Documentation

◆ DOUBLE_PRECISION_NODES0

const unsigned moab::ReadIDEAS::DOUBLE_PRECISION_NODES0 = 781
staticprivate

Definition at line 82 of file ReadIDEAS.hpp.

Referenced by load_file().

◆ DOUBLE_PRECISION_NODES1

const unsigned moab::ReadIDEAS::DOUBLE_PRECISION_NODES1 = 2411
staticprivate

Definition at line 83 of file ReadIDEAS.hpp.

Referenced by load_file().

◆ ELEMENTS0

const unsigned moab::ReadIDEAS::ELEMENTS0 = 71
staticprivate

Definition at line 91 of file ReadIDEAS.hpp.

Referenced by load_file().

◆ ELEMENTS1

const unsigned moab::ReadIDEAS::ELEMENTS1 = 780
staticprivate

Definition at line 92 of file ReadIDEAS.hpp.

Referenced by load_file().

◆ ELEMENTS2

const unsigned moab::ReadIDEAS::ELEMENTS2 = 2412
staticprivate

Definition at line 93 of file ReadIDEAS.hpp.

Referenced by load_file().

◆ file

std::ifstream moab::ReadIDEAS::file
private

Definition at line 54 of file ReadIDEAS.hpp.

Referenced by create_elements(), create_vertices(), load_file(), and skip_header().

◆ HEX

const int moab::ReadIDEAS::HEX = 115
staticprivate

Definition at line 107 of file ReadIDEAS.hpp.

Referenced by create_elements().

◆ MBI

Interface* moab::ReadIDEAS::MBI
private

Definition at line 61 of file ReadIDEAS.hpp.

Referenced by create_elements(), and create_vertices().

◆ nodeIdMap

RangeMap< int, EntityHandle > moab::ReadIDEAS::nodeIdMap
private

Definition at line 55 of file ReadIDEAS.hpp.

◆ QUAD0

const int moab::ReadIDEAS::QUAD0 = 44
staticprivate

Definition at line 103 of file ReadIDEAS.hpp.

Referenced by create_elements().

◆ QUAD1

const int moab::ReadIDEAS::QUAD1 = 94
staticprivate

Definition at line 104 of file ReadIDEAS.hpp.

Referenced by create_elements().

◆ readMeshIface

ReadUtilIface* moab::ReadIDEAS::readMeshIface
private

Definition at line 58 of file ReadIDEAS.hpp.

Referenced by create_vertices(), and ReadIDEAS().

◆ ROD0

const int moab::ReadIDEAS::ROD0 = 11
staticprivate

Definition at line 99 of file ReadIDEAS.hpp.

◆ ROD1

const int moab::ReadIDEAS::ROD1 = 171
staticprivate

Definition at line 100 of file ReadIDEAS.hpp.

◆ SINGLE_PRECISION_NODES

const unsigned moab::ReadIDEAS::SINGLE_PRECISION_NODES = 15
staticprivate

Definition at line 76 of file ReadIDEAS.hpp.

◆ TET

const int moab::ReadIDEAS::TET = 111
staticprivate

Definition at line 105 of file ReadIDEAS.hpp.

Referenced by create_elements().

◆ TRI0

const int moab::ReadIDEAS::TRI0 = 41
staticprivate

Definition at line 101 of file ReadIDEAS.hpp.

Referenced by create_elements().

◆ TRI1

const int moab::ReadIDEAS::TRI1 = 91
staticprivate

Definition at line 102 of file ReadIDEAS.hpp.

Referenced by create_elements().

◆ WEDGE

const int moab::ReadIDEAS::WEDGE = 112
staticprivate

Definition at line 106 of file ReadIDEAS.hpp.

Referenced by create_elements().


The documentation for this class was generated from the following files: