61 const Tag* file_id_tag )
63 int num_material_sets = 0;
64 const int* material_set_list = 0;
82 std::set< int > blocks;
83 for(
const int* mat_set_end = material_set_list + num_material_sets; material_set_list != mat_set_end;
85 blocks.insert( *material_set_list );
88 std::map< long, EntityHandle > node_id_map;
102 cg_open( filename, CG_MODE_READ, &filePtr );
110 long num_verts = 0, num_elems = 0, num_sets = 0;
111 int num_bases = 0, num_zones = 0, num_sections = 0;
119 cg_nbases( filePtr, &num_bases );
126 for(
int indexBase = 1; indexBase <= num_bases; ++indexBase )
129 cg_nzones( filePtr, indexBase, &num_zones );
136 for(
int indexZone = 1; indexZone <= num_zones; ++indexZone )
139 cg_zone_read( filePtr, indexBase, indexZone, zoneName,
size );
142 cg_nsections( filePtr, indexBase, indexZone, &num_sections );
146 num_sets = num_sections;
148 std::cout <<
"\nnumber of nodes = " << num_verts;
149 std::cout <<
"\nnumber of elems = " << num_elems;
150 std::cout <<
"\nnumber of parts = " << num_sets << std::endl;
158 std::vector< double* > coord_arrays;
163 cgsize_t beginPos = 1, endPos = num_verts;
166 cg_coord_read( filePtr, indexBase, indexZone,
"CoordinateX", RealDouble, &beginPos, &endPos,
168 cg_coord_read( filePtr, indexBase, indexZone,
"CoordinateY", RealDouble, &beginPos, &endPos,
170 cg_coord_read( filePtr, indexBase, indexZone,
"CoordinateZ", RealDouble, &beginPos, &endPos,
176 double sumZcoord = 0.0;
177 double eps = 1.0e-12;
178 for(
long i = 0; i < num_verts; ++i, ++handle )
182 node_id_map.insert( std::pair< long, EntityHandle >( index, handle ) ).second;
184 sumZcoord += *( coord_arrays[2] + i );
186 if( std::abs( sumZcoord ) <= eps )
mesh_dim = 2;
189 std::vector< int > ids( num_verts );
190 std::vector< int >::iterator id_iter = ids.begin();
191 std::vector< EntityHandle > handles( num_verts );
192 std::vector< EntityHandle >::iterator h_iter = handles.begin();
193 for( std::map< long, EntityHandle >::iterator i = node_id_map.begin(); i != node_id_map.end();
194 ++i, ++id_iter, ++h_iter )
215 long section_offset = 0;
219 std::vector< int > volumeID( num_sections, 0 );
221 for(
int section = 0; section < num_sections; ++section )
223 ElementType_t elemsType;
224 int iparent_flag, nbndry;
225 char sectionName[128];
228 int cgSection = section + 1;
230 cg_section_read( filePtr, indexBase, indexZone, cgSection, sectionName, &elemsType, &beginPos, &endPos,
231 &nbndry, &iparent_flag );
233 size_t section_size = endPos - beginPos + 1;
246 if(
mesh_dim == 2 ) volumeID[section] = 1;
251 if(
mesh_dim == 2 ) volumeID[section] = 1;
256 if(
mesh_dim == 3 ) volumeID[section] = 1;
261 if(
mesh_dim == 3 ) volumeID[section] = 1;
266 if(
mesh_dim == 3 ) volumeID[section] = 1;
271 if(
mesh_dim == 3 ) volumeID[section] = 1;
281 if( elemsType == TETRA_4 || elemsType == PYRA_5 || elemsType == PENTA_6 || elemsType == HEXA_8 ||
282 elemsType == TRI_3 || elemsType == QUAD_4 || ( ( elemsType == BAR_2 ) &&
mesh_dim == 2 ) )
290 cg_ElementDataSize( filePtr, indexBase, indexZone, cgSection, &connDataSize );
293 std::vector< cgsize_t > elemNodes( connDataSize );
295 cg_elements_read( filePtr, indexBase, indexZone, cgSection, &elemNodes[0], &iparentdata );
300 create_elements( sectionName, file_id_tag, ent_type, verts_per_elem, section_offset, section_size,
303 else if( elemsType == MIXED )
310 cg_ElementDataSize( filePtr, indexBase, indexZone, cgSection, &connDataSize );
312 std::vector< cgsize_t > elemNodes( connDataSize );
314 cg_elements_read( filePtr, indexBase, indexZone, cgSection, &elemNodes[0], &iparentdata );
316 std::vector< cgsize_t > elemsConn_EDGE;
317 std::vector< cgsize_t > elemsConn_TRI, elemsConn_QUAD;
318 std::vector< cgsize_t > elemsConn_TET, elemsConn_PYRA, elemsConn_PRISM, elemsConn_HEX;
319 cgsize_t count_EDGE, count_TRI, count_QUAD;
320 cgsize_t count_TET, count_PYRA, count_PRISM, count_HEX;
324 count_EDGE = count_TRI = count_QUAD = 0;
325 count_TET = count_PYRA = count_PRISM = count_HEX = 0;
328 for(
int i = beginPos; i <= endPos; i++ )
330 elemsType = ElementType_t( elemNodes[connIndex] );
333 cg_npe( elemsType, &verts_per_elem );
362 connIndex += ( verts_per_elem + 1 );
365 if( count_EDGE > 0 ) elemsConn_EDGE.resize( count_EDGE * 2 );
366 if( count_TRI > 0 ) elemsConn_TRI.resize( count_TRI * 3 );
367 if( count_QUAD > 0 ) elemsConn_QUAD.resize( count_QUAD * 4 );
368 if( count_TET > 0 ) elemsConn_TET.resize( count_TET * 4 );
369 if( count_PYRA > 0 ) elemsConn_PYRA.resize( count_PYRA * 5 );
370 if( count_PRISM > 0 ) elemsConn_PRISM.resize( count_PRISM * 6 );
371 if( count_HEX > 0 ) elemsConn_HEX.resize( count_HEX * 8 );
375 int idx_edge, idx_tri, idx_quad;
376 int idx_tet, idx_pyra, idx_prism, idx_hex;
377 idx_edge = idx_tri = idx_quad = 0;
378 idx_tet = idx_pyra = idx_prism = idx_hex = 0;
381 for(
int i = beginPos; i <= endPos; i++ )
383 elemsType = ElementType_t( elemNodes[connIndex] );
386 cg_npe( elemsType, &verts_per_elem );
391 for(
int j = 0; j < 2; ++j )
392 elemsConn_EDGE[idx_edge + j] = elemNodes[connIndex + j + 1];
396 for(
int j = 0; j < 3; ++j )
397 elemsConn_TRI[idx_tri + j] = elemNodes[connIndex + j + 1];
401 for(
int j = 0; j < 4; ++j )
402 elemsConn_QUAD[idx_quad + j] = elemNodes[connIndex + j + 1];
406 for(
int j = 0; j < 4; ++j )
407 elemsConn_TET[idx_tet + j] = elemNodes[connIndex + j + 1];
411 for(
int j = 0; j < 5; ++j )
412 elemsConn_PYRA[idx_pyra + j] = elemNodes[connIndex + j + 1];
416 for(
int j = 0; j < 6; ++j )
417 elemsConn_PRISM[idx_prism + j] = elemNodes[connIndex + j + 1];
421 for(
int j = 0; j < 8; ++j )
422 elemsConn_HEX[idx_hex + j] = elemNodes[connIndex + j + 1];
429 connIndex += ( verts_per_elem + 1 );
440 create_elements( sectionName, file_id_tag,
MBTRI, 3, section_offset, count_TRI, elemsConn_TRI );
447 create_elements( sectionName, file_id_tag,
MBTET, 4, section_offset, count_TET, elemsConn_TET );
453 if( count_PRISM > 0 )
458 create_elements( sectionName, file_id_tag,
MBHEX, 8, section_offset, count_HEX, elemsConn_HEX );
472 const Tag* file_id_tag,
473 const EntityType& ent_type,
474 const int& verts_per_elem,
475 long& section_offset,
477 const std::vector< cgsize_t >& elemsConn )
490 memcpy( conn_array, &elemsConn[0], elemsConn.size() *
sizeof(
EntityHandle ) );
494 std::vector< EntityHandle > elemsConnTwin( elemsConn.size(), 0 );
495 for(
int i = 0; i < elemsConn.size(); i++ )
497 elemsConnTwin[i] =
static_cast< EntityHandle >( elemsConn[i] );
499 memcpy( conn_array, &elemsConnTwin[0], elemsConnTwin.size() *
sizeof(
EntityHandle ) );
509 Range elements( handle, handle + elems_count - 1 );
513 std::vector< int > id_list( elems_count );
516 for(
cgsize_t i = 0; i < elems_count; ++i )
517 id_list[i] = i + 1 + section_offset;
518 section_offset += elems_count;
520 create_sets( sectionName, file_id_tag, ent_type, elements, id_list, 0 );
526 const Tag* file_id_tag,
528 const Range& elements,
529 const std::vector< int >& set_ids,
547 const char* setName = sectionName;