#include <ReadSms.hpp>
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... | |
ReadSms (Interface *impl=NULL) | |
Constructor. More... | |
virtual | ~ReadSms () |
Destructor. More... | |
![]() | |
virtual | ~ReaderIface () |
Static Public Member Functions | |
static ReaderIface * | factory (Interface *) |
factory method More... | |
Private Member Functions | |
ErrorCode | add_entities (EntityHandle start, EntityHandle count, const Tag *file_id_tag) |
ErrorCode | load_file_impl (FILE *file, const Tag *file_id_tag) |
ErrorCode | get_set (std::vector< EntityHandle > *sets, int set_type, int set_id, Tag set_tag, EntityHandle &this_set, const Tag *file_id_tag) |
ErrorCode | read_parallel_info (FILE *file_ptr) |
Private Attributes | |
ReadUtilIface * | readMeshIface |
Interface * | mdbImpl |
interface instance More... | |
Tag | globalId |
Tag | paramCoords |
Tag | geomDimension |
int | setId |
Definition at line 15 of file ReadSms.hpp.
ReadSms::ReadSms | ( | Interface * | impl = NULL | ) |
Constructor.
Definition at line 56 of file ReadSms.cpp.
56 : mdbImpl( impl ), globalId( 0 ), paramCoords( 0 ), geomDimension( 0 ), setId( 0 ) 57 { 58 mdbImpl->query_interface( readMeshIface ); 59 }
References mdbImpl, moab::Interface::query_interface(), and readMeshIface.
Referenced by factory().
|
virtual |
Destructor.
Definition at line 61 of file ReadSms.cpp.
62 { 63 if( readMeshIface ) 64 { 65 mdbImpl->release_interface( readMeshIface ); 66 readMeshIface = 0; 67 } 68 }
References mdbImpl, readMeshIface, and moab::Interface::release_interface().
|
private |
Definition at line 483 of file ReadSms.cpp.
484 {
485 if( !count || !file_id_tag ) return MB_FAILURE;
486
487 Range range;
488 range.insert( start, start + count - 1 );
489 return readMeshIface->assign_ids( *file_id_tag, range, 1 );
490 }
References moab::ReadUtilIface::assign_ids(), moab::Range::insert(), and readMeshIface.
Referenced by load_file_impl().
|
static |
factory method
Definition at line 51 of file ReadSms.cpp.
52 {
53 return new ReadSms( iface );
54 }
References iface, and ReadSms().
Referenced by moab::ReaderWriterSet::ReaderWriterSet().
|
private |
Definition at line 401 of file ReadSms.cpp.
407 {
408 ErrorCode result = MB_SUCCESS;
409
410 if( set_dim < 0 || set_dim > 3 ) return MB_FILE_WRITE_ERROR;
411
412 if( (int)sets[set_dim].size() <= set_id || !sets[set_dim][set_id] )
413 {
414 if( (int)sets[set_dim].size() <= set_id ) sets[set_dim].resize( set_id + 1, 0 );
415
416 if( !sets[set_dim][set_id] )
417 {
418 result = mdbImpl->create_meshset( MESHSET_SET, sets[set_dim][set_id] );
419 if( MB_SUCCESS != result ) return result;
420 result = mdbImpl->tag_set_data( globalId, &sets[set_dim][set_id], 1, &set_id );
421 if( MB_SUCCESS != result ) return result;
422 result = mdbImpl->tag_set_data( dim_tag, &sets[set_dim][set_id], 1, &set_dim );
423 if( MB_SUCCESS != result ) return result;
424
425 if( file_id_tag )
426 {
427 result = mdbImpl->tag_set_data( *file_id_tag, &sets[set_dim][set_id], 1, &setId );
428 ++setId;
429 }
430 }
431 }
432
433 this_set = sets[set_dim][set_id];
434
435 return result;
436 }
References moab::Interface::create_meshset(), ErrorCode, globalId, MB_FILE_WRITE_ERROR, MB_SUCCESS, mdbImpl, MESHSET_SET, setId, size, and moab::Interface::tag_set_data().
Referenced by load_file_impl().
|
virtual |
Load mesh from a file.
Method all readers must provide to import a mesh.
file_name | The file to read. |
file_set | Optional 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_list | An optional struct pointer specifying the tags identifying entity sets to be read. |
file_id_tag | If specified, reader should store for each entity it reads, a unique integer ID for this tag. |
Implements moab::ReaderIface.
Definition at line 79 of file ReadSms.cpp.
84 {
85 if( subset_list )
86 {
87 MB_SET_ERR( MB_UNSUPPORTED_OPERATION, "Reading subset of files not supported for Sms" );
88 }
89
90 setId = 1;
91
92 // Open file
93 FILE* file_ptr = fopen( filename, "r" );
94 if( !file_ptr )
95 {
96 MB_SET_ERR( MB_FILE_DOES_NOT_EXIST, filename << ": " << strerror( errno ) );
97 }
98
99 const ErrorCode result = load_file_impl( file_ptr, file_id_tag );
100 fclose( file_ptr );
101
102 return result;
103 }
References ErrorCode, load_file_impl(), MB_FILE_DOES_NOT_EXIST, MB_SET_ERR, MB_UNSUPPORTED_OPERATION, and setId.
Definition at line 105 of file ReadSms.cpp.
106 {
107 bool warned = false;
108 double dum_params[] = { 0.0, 0.0, 0.0 };
109
110 globalId = mdbImpl->globalId_tag();
111
112 ErrorCode result =
113 mdbImpl->tag_get_handle( "PARAMETER_COORDS", 3, MB_TYPE_DOUBLE, paramCoords, MB_TAG_DENSE | MB_TAG_CREAT );
114 CHECK( "Failed to create param coords tag." );
115
116 int negone = -1;
117 result = mdbImpl->tag_get_handle( GEOM_DIMENSION_TAG_NAME, 1, MB_TYPE_INTEGER, geomDimension,
118 MB_TAG_SPARSE | MB_TAG_CREAT, &negone );
119 CHECK( "Failed to create geom dim tag." );
120
121 int n;
122 char line[256], all_line[1024];
123 int file_type;
124
125 if( fgets( all_line, sizeof( all_line ), file_ptr ) == NULL )
126 {
127 return MB_FAILURE;
128 }
129 if( sscanf( all_line, "%s %d", line, &file_type ) != 2 )
130 {
131 return MB_FAILURE;
132 }
133
134 if( 3 == file_type )
135 {
136 result = read_parallel_info( file_ptr );
137 CHECK( "Failed to read parallel info." );
138 }
139
140 int nregions, nfaces, nedges, nvertices, npoints;
141 n = fscanf( file_ptr, "%d %d %d %d %d", &nregions, &nfaces, &nedges, &nvertices, &npoints );
142 CHECKN( 5 );
143 if( nregions < 0 || nfaces < 0 || nedges < 0 || nvertices < 0 || npoints < 0 ) return MB_FILE_WRITE_ERROR;
144
145 // Create the vertices
146 std::vector< double* > coord_arrays;
147 EntityHandle vstart = 0;
148 result = readMeshIface->get_node_coords( 3, nvertices, MB_START_ID, vstart, coord_arrays );
149 CHECK( "Failed to get node arrays." );
150
151 if( file_id_tag )
152 {
153 result = add_entities( vstart, nvertices, file_id_tag );MB_CHK_ERR( result );
154 }
155
156 EntityHandle this_gent, new_handle;
157 std::vector< EntityHandle > gentities[4];
158 int gent_id, dum_int;
159 int gent_type, num_connections;
160
161 for( int i = 0; i < nvertices; i++ )
162 {
163 n = fscanf( file_ptr, "%d", &gent_id );
164 CHECKN( 1 );
165 if( !gent_id ) continue;
166
167 n = fscanf( file_ptr, "%d %d %lf %lf %lf", &gent_type, &num_connections, coord_arrays[0] + i,
168 coord_arrays[1] + i, coord_arrays[2] + i );
169 CHECKN( 5 );
170
171 result = get_set( gentities, gent_type, gent_id, geomDimension, this_gent, file_id_tag );MB_CHK_ERR( result );
172
173 new_handle = vstart + i;
174 result = mdbImpl->add_entities( this_gent, &new_handle, 1 );
175 CHECK( "Adding vertex to geom set failed." );
176
177 switch( gent_type )
178 {
179 case 1:
180 n = fscanf( file_ptr, "%le", dum_params );
181 CHECKN( 1 );
182 result = mdbImpl->tag_set_data( paramCoords, &new_handle, 1, dum_params );
183 CHECK( "Failed to set param coords tag for vertex." );
184 break;
185 case 2:
186 n = fscanf( file_ptr, "%le %le %d", dum_params, dum_params + 1, &dum_int );
187 CHECKN( 3 );
188 dum_params[2] = dum_int;
189 result = mdbImpl->tag_set_data( paramCoords, &new_handle, 1, dum_params );
190 CHECK( "Failed to set param coords tag for vertex." );
191 break;
192 default:
193 break;
194 }
195 } // End of reading vertices
196
197 // *******************************
198 // Read Edges
199 // *******************************
200
201 int vert1, vert2, num_pts;
202 std::vector< EntityHandle > everts( 2 );
203 EntityHandle estart, *connect;
204 result = readMeshIface->get_element_connect( nedges, 2, MBEDGE, 1, estart, connect );
205 CHECK( "Failed to create array of edges." );
206
207 if( file_id_tag )
208 {
209 result = add_entities( estart, nedges, file_id_tag );
210 if( MB_SUCCESS != result ) return result;
211 }
212
213 for( int i = 0; i < nedges; i++ )
214 {
215 n = fscanf( file_ptr, "%d", &gent_id );
216 CHECKN( 1 );
217 if( !gent_id ) continue;
218
219 n = fscanf( file_ptr, "%d %d %d %d %d", &gent_type, &vert1, &vert2, &num_connections, &num_pts );
220 CHECKN( 5 );
221 if( vert1 < 1 || vert1 > nvertices ) return MB_FILE_WRITE_ERROR;
222 if( vert2 < 1 || vert2 > nvertices ) return MB_FILE_WRITE_ERROR;
223
224 connect[0] = vstart + vert1 - 1;
225 connect[1] = vstart + vert2 - 1;
226 if( num_pts > 1 && !warned )
227 {
228 std::cout << "Warning: num_points > 1 not supported; choosing last one." << std::endl;
229 warned = true;
230 }
231
232 result = get_set( gentities, gent_type, gent_id, geomDimension, this_gent, file_id_tag );
233 CHECK( "Problem getting geom set for edge." );
234
235 new_handle = estart + i;
236 result = mdbImpl->add_entities( this_gent, &new_handle, 1 );
237 CHECK( "Failed to add edge to geom set." );
238
239 connect += 2;
240
241 for( int j = 0; j < num_pts; j++ )
242 {
243 switch( gent_type )
244 {
245 case 1:
246 n = fscanf( file_ptr, "%le", dum_params );
247 CHECKN( 1 );
248 result = mdbImpl->tag_set_data( paramCoords, &new_handle, 1, dum_params );
249 CHECK( "Failed to set param coords tag for edge." );
250 break;
251 case 2:
252 n = fscanf( file_ptr, "%le %le %d", dum_params, dum_params + 1, &dum_int );
253 CHECKN( 3 );
254 dum_params[2] = dum_int;
255 result = mdbImpl->tag_set_data( paramCoords, &new_handle, 1, dum_params );
256 CHECK( "Failed to set param coords tag for edge." );
257 break;
258 default:
259 break;
260 }
261 }
262 } // End of reading edges
263
264 // *******************************
265 // Read Faces
266 // *******************************
267 std::vector< EntityHandle > bound_ents, bound_verts, new_faces;
268 int bound_id;
269 Range shverts;
270 new_faces.resize( nfaces );
271 int num_bounding;
272
273 for( int i = 0; i < nfaces; i++ )
274 {
275 n = fscanf( file_ptr, "%d", &gent_id );
276 CHECKN( 1 );
277 if( !gent_id ) continue;
278
279 n = fscanf( file_ptr, "%d %d", &gent_type, &num_bounding );
280 CHECKN( 2 );
281
282 result = get_set( gentities, gent_type, gent_id, geomDimension, this_gent, file_id_tag );
283 CHECK( "Problem getting geom set for face." );
284
285 bound_ents.resize( num_bounding + 1 );
286 bound_verts.resize( num_bounding );
287 for( int j = 0; j < num_bounding; j++ )
288 {
289 n = fscanf( file_ptr, "%d ", &bound_id );
290 CHECKN( 1 );
291 if( 0 > bound_id ) bound_id = abs( bound_id );
292 assert( 0 < bound_id && bound_id <= nedges );
293 if( bound_id < 1 || bound_id > nedges ) return MB_FILE_WRITE_ERROR;
294 bound_ents[j] = estart + abs( bound_id ) - 1;
295 }
296
297 // Convert edge-based model to vertex-based one
298 for( int j = 0; j < num_bounding; j++ )
299 {
300 if( j == num_bounding - 1 ) bound_ents[j + 1] = bound_ents[0];
301 result = mdbImpl->get_adjacencies( &bound_ents[j], 2, 0, false, shverts );
302 CHECK( "Failed to get vertices bounding edge." );
303 assert( shverts.size() == 1 );
304 bound_verts[j] = *shverts.begin();
305 shverts.clear();
306 }
307
308 result = mdbImpl->create_element( (EntityType)( MBTRI + num_bounding - 3 ), &bound_verts[0], bound_verts.size(),
309 new_faces[i] );
310 CHECK( "Failed to create edge." );
311
312 result = mdbImpl->add_entities( this_gent, &new_faces[i], 1 );
313 CHECK( "Failed to add edge to geom set." );
314
315 int num_read = fscanf( file_ptr, "%d", &num_pts );
316 if( !num_pts || !num_read ) continue;
317
318 for( int j = 0; j < num_pts; j++ )
319 {
320 switch( gent_type )
321 {
322 case 1:
323 n = fscanf( file_ptr, "%le", dum_params );
324 CHECKN( 1 );
325 result = mdbImpl->tag_set_data( paramCoords, &new_faces[i], 1, dum_params );
326 CHECK( "Failed to set param coords tag for face." );
327 break;
328 case 2:
329 n = fscanf( file_ptr, "%le %le %d", dum_params, dum_params + 1, &dum_int );
330 CHECKN( 3 );
331 dum_params[2] = dum_int;
332 result = mdbImpl->tag_set_data( paramCoords, &new_faces[i], 1, dum_params );
333 CHECK( "Failed to set param coords tag for face." );
334 break;
335 default:
336 break;
337 }
338 }
339 } // End of reading faces
340
341 if( file_id_tag )
342 {
343 result = readMeshIface->assign_ids( *file_id_tag, &new_faces[0], new_faces.size(), 1 );
344 if( MB_SUCCESS != result ) return result;
345 }
346
347 // *******************************
348 // Read Regions
349 // *******************************
350 int sense[MAX_SUB_ENTITIES];
351 bound_verts.resize( MAX_SUB_ENTITIES );
352
353 std::vector< EntityHandle > regions;
354 if( file_id_tag ) regions.resize( nregions );
355 for( int i = 0; i < nregions; i++ )
356 {
357 n = fscanf( file_ptr, "%d", &gent_id );
358 CHECKN( 1 );
359 if( !gent_id ) continue;
360 result = get_set( gentities, 3, gent_id, geomDimension, this_gent, file_id_tag );
361 CHECK( "Couldn't get geom set for region." );
362 n = fscanf( file_ptr, "%d", &num_bounding );
363 CHECKN( 1 );
364 bound_ents.resize( num_bounding );
365 for( int j = 0; j < num_bounding; j++ )
366 {
367 n = fscanf( file_ptr, "%d ", &bound_id );
368 CHECKN( 1 );
369 assert( abs( bound_id ) < (int)new_faces.size() + 1 && bound_id );
370 if( !bound_id || abs( bound_id ) > nfaces ) return MB_FILE_WRITE_ERROR;
371 sense[j] = ( bound_id < 0 ) ? -1 : 1;
372 bound_ents[j] = new_faces[abs( bound_id ) - 1];
373 }
374
375 EntityType etype;
376 result = readMeshIface->get_ordered_vertices( &bound_ents[0], sense, num_bounding, 3, &bound_verts[0], etype );
377 CHECK( "Failed in get_ordered_vertices." );
378
379 // Make the element
380 result = mdbImpl->create_element( etype, &bound_verts[0], CN::VerticesPerEntity( etype ), new_handle );
381 CHECK( "Failed to create region." );
382
383 result = mdbImpl->add_entities( this_gent, &new_handle, 1 );
384 CHECK( "Failed to add region to geom set." );
385
386 if( file_id_tag ) regions[i] = new_handle;
387
388 n = fscanf( file_ptr, "%d ", &dum_int );
389 CHECKN( 1 );
390 } // End of reading regions
391
392 if( file_id_tag )
393 {
394 result = readMeshIface->assign_ids( *file_id_tag, ®ions[0], regions.size(), 1 );
395 if( MB_SUCCESS != result ) return result;
396 }
397
398 return MB_SUCCESS;
399 }
References moab::Interface::add_entities(), add_entities(), moab::ReadUtilIface::assign_ids(), moab::Range::begin(), CHECK, CHECKN, moab::Range::clear(), moab::Interface::create_element(), ErrorCode, GEOM_DIMENSION_TAG_NAME, geomDimension, moab::Interface::get_adjacencies(), moab::ReadUtilIface::get_element_connect(), moab::ReadUtilIface::get_node_coords(), moab::ReadUtilIface::get_ordered_vertices(), get_set(), globalId, moab::Interface::globalId_tag(), moab::MAX_SUB_ENTITIES, MB_CHK_ERR, MB_FILE_WRITE_ERROR, MB_START_ID, MB_SUCCESS, MB_TAG_CREAT, MB_TAG_DENSE, MB_TAG_SPARSE, MB_TYPE_DOUBLE, MB_TYPE_INTEGER, MBEDGE, MBTRI, mdbImpl, paramCoords, read_parallel_info(), readMeshIface, moab::Range::size(), moab::Interface::tag_get_handle(), moab::Interface::tag_set_data(), and moab::CN::VerticesPerEntity().
Referenced by load_file().
|
private |
Definition at line 438 of file ReadSms.cpp.
439 {
440 // ErrorCode result;
441
442 // Read partition info
443 int nparts, part_id, num_ifaces, num_corner_ents;
444 int num_read = fscanf( file_ptr, "%d %d %d %d", &nparts, &part_id, &num_ifaces, &num_corner_ents );
445 if( !num_read ) return MB_FAILURE;
446
447 // Read interfaces
448 int iface_id, iface_dim, iface_own, num_iface_corners;
449 // EntityHandle this_iface;
450 std::vector< int >* iface_corners = NULL;
451 for( int i = 0; i < num_ifaces; i++ )
452 {
453 num_read = fscanf( file_ptr, "%d %d %d %d", &iface_id, &iface_dim, &iface_own, &num_iface_corners );
454 if( !num_read ) return MB_FAILURE;
455
456 // result = get_set(sets, iface_dim, iface_id, dim_tag, iface_own, this_iface);
457 // CHECK("Failed to make iface set.");
458
459 // Read the corner ids and store them on the set for now
460 iface_corners = new std::vector< int >( num_iface_corners );
461 for( int j = 0; j < num_iface_corners; j++ )
462 {
463 num_read = fscanf( file_ptr, "%d", &( *iface_corners )[j] );
464 if( !num_read )
465 {
466 delete iface_corners;
467 return MB_FAILURE;
468 }
469 }
470
471 // result = tag_set_data(ifaceCornerTag, &this_iface, 1,
472 //&iface_corners);
473 // CHECK("Failed to set iface corner tag.");
474
475 delete iface_corners;
476 iface_corners = NULL;
477 }
478
479 // Interface data has been read
480 return MB_SUCCESS;
481 }
References MB_SUCCESS, and nparts.
Referenced by load_file_impl().
|
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.
file_name | The file to read. |
tag_name | The tag for which to read values |
tag_values_out | Output: The list of tag values. |
subset_list | An 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_length | The length of the 'subset_list' array. |
Implements moab::ReaderIface.
Definition at line 70 of file ReadSms.cpp.
75 {
76 return MB_NOT_IMPLEMENTED;
77 }
References MB_NOT_IMPLEMENTED.
|
private |
Definition at line 59 of file ReadSms.hpp.
Referenced by load_file_impl().
|
private |
Definition at line 59 of file ReadSms.hpp.
Referenced by get_set(), and load_file_impl().
|
private |
interface instance
Definition at line 57 of file ReadSms.hpp.
Referenced by get_set(), load_file_impl(), ReadSms(), and ~ReadSms().
|
private |
Definition at line 59 of file ReadSms.hpp.
Referenced by load_file_impl().
|
private |
Definition at line 54 of file ReadSms.hpp.
Referenced by add_entities(), load_file_impl(), ReadSms(), and ~ReadSms().
|
private |
Definition at line 61 of file ReadSms.hpp.
Referenced by get_set(), and load_file().