76 const char* gmsh_filename;
80 unsigned node_offset, node_id;
81 unsigned* connectivity;
92 char* hexgroup = NULL;
96 unsigned* hexconnectivity;
102 unsigned num_elem_groups;
108 int havesparse, havedense;
110 hid_t sparse_handle[2];
111 unsigned* sparse_entities;
112 unsigned* sparse_ids;
114 long fileid, globalid;
115 long ncount = 0, hcount = 0;
125 fprintf( stderr,
"Usage: %s <input_file> <output_file>\n", argv[0] );
129 gmsh_filename = argv[2];
136 nodecoords = (
double*)malloc( dimension * numnode *
sizeof(
double ) );
142 for( k = 0; k < num_elem_groups; ++k )
146 hexgroup = strdup( elem_groups[k] );
148 printf(
"Skipping element group '%s' containing element of type '%s'\n", elem_groups[k], namebuffer );
154 fprintf( stderr,
"No Hexahedra defined in file\n" );
160 hexconnectivity = (
unsigned*)malloc( numhex * nodes_per_hex *
sizeof(
unsigned ) );
168 nodeids = (
unsigned*)malloc( numnode *
sizeof(
unsigned ) );
169 hexids = (
unsigned*)malloc( numhex *
sizeof(
unsigned ) );
170 mhdf_getTagInfo( file,
"GLOBAL_ID", &tagtype, &tagsize, &ts, &td, &tg, &havesparse, sptr );
178 fprintf( stderr,
"ERROR: Invalid data type for 'GLOBAL_ID' tag.\n" );
187 assert( numtag == numnode );
188 mhdf_readDenseTag( handle, 0, numtag, H5T_NATIVE_UINT, nodeids, sptr );
CHK_ERR( sptr );
197 assert( numtag == numhex );
198 mhdf_readDenseTag( handle, 0, numtag, H5T_NATIVE_UINT, hexids, sptr );
CHK_ERR( sptr );
206 sparse_entities = (
unsigned*)malloc( numtag *
sizeof(
unsigned ) );
208 sparse_ids = (
unsigned*)malloc( numtag *
sizeof(
unsigned ) );
209 mhdf_readSparseTagValues( sparse_handle[1], 0, numtag, H5T_NATIVE_UINT, sparse_ids, sptr );
CHK_ERR( sptr );
214 for( i = 0; i < numtag; ++i )
216 fileid = sparse_entities[i];
217 globalid = sparse_ids[i];
218 if( fileid >= nodestart && fileid - nodestart < numnode )
220 nodeids[fileid - nodestart] = globalid;
223 else if( fileid >= hexstart && fileid - hexstart < numhex )
225 hexids[fileid - hexstart] = globalid;
230 free( sparse_entities );
233 if( ncount == numnode ) have_nodeids = 1;
234 if( hcount == numhex ) have_hexids = 1;
245 for( i = 0; i < numnode; ++i )
248 for( i = 0; i < numhex; ++i )
254 if( nodes_per_hex == 8 )
256 else if( nodes_per_hex == 27 )
260 fprintf( stderr,
"Cannot store %d node hex in gmsh file.\n", nodes_per_hex );
265 gmsh = fopen( gmsh_filename,
"w" );
272 fprintf( gmsh,
"$NOD\n" );
273 fprintf( gmsh,
"%lu\n", numnode );
274 for( i = 0; i < numnode; ++i )
276 x = nodecoords[dimension * i];
280 y = nodecoords[dimension * i + 1];
283 z = nodecoords[dimension * i + 2];
286 fprintf( gmsh,
"%u %f %f %f\n", nodeids[i], x, y, z );
290 fprintf( gmsh,
"$ENDNOD\n$ELM\n" );
291 fprintf( gmsh,
"%lu\n", numhex );
292 for( i = 0; i < numhex; ++i )
294 fprintf( gmsh,
"%u %u 1 1 %d", hexids[i], gmsh_type, nodes_per_hex );
296 connectivity = hexconnectivity + i * nodes_per_hex;
297 for( j = 0; j < nodes_per_hex; ++j )
300 node_offset = connectivity[j] - nodestart;
302 node_id = nodeids[node_offset];
303 fprintf( gmsh,
" %u", node_id );
305 fprintf( gmsh,
"\n" );
307 fprintf( gmsh,
"$ENDELM\n" );