![]() |
Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
00001 #include "moab/MOABConfig.h"
00002 #include "FBiGeom.h"
00003 #include "iMesh.h"
00004 #include "iRel.h"
00005
00006 #include
00007 #include
00008 #include
00009
00010 #define DEFAULT_TEST_FILE shell.h5m
00011 #define DEFAULT_TEST_FILE1 shellQuad.h5m
00012
00013 // clang-format off
00014
00015 #define STRINGIFY_( X ) #X
00016 #define STRINGIFY( X ) STRINGIFY_( X )
00017 #if defined( MESHDIR ) && defined( MOAB_HAVE_HDF5 )
00018 #define DEFAULT_INPUT_FILE STRINGIFY( MESHDIR/fbigeom/DEFAULT_TEST_FILE )
00019 #define DEFAULT_INPUT_FILE1 STRINGIFY( MESHDIR/fbigeom/DEFAULT_TEST_FILE1 )
00020 #else
00021 #error Specify MESHDIR to compile test
00022 #endif
00023
00024 #define CHECK_SIZE_C( type, array, allocated_size, size ) \
00025 if( NULL == *(array) || *(allocated_size) == 0 ) \
00026 { \
00027 *(array) = (type*)malloc( sizeof( type ) * (size) ); \
00028 *(allocated_size) = size; \
00029 } \
00030 else if( *(allocated_size) < (size) ) \
00031 { \
00032 printf( " Array passed in is non-zero but too short.\n" ); \
00033 }
00034
00035 // clang-format on
00036
00037 typedef void* iRel_EntityHandle;
00038
00039 /*!
00040 prints out a result string based on the value of error_code
00041 */
00042 void handle_error_code( const int result, int* number_failed, int* number_not_implemented, int* number_successful )
00043 {
00044 if( result )
00045 {
00046 printf( "Success" );
00047 ( *number_successful )++;
00048 }
00049 else
00050 {
00051 printf( "Failure" );
00052 ( *number_failed )++;
00053 }
00054 }
00055
00056 int print_geom_info( FBiGeom_Instance geom, iBase_EntityHandle gent )
00057 {
00058 /* print information about this entity */
00059 int ent_type;
00060 int result;
00061 const char* type_names[] = { "Vertex", "Edge", "Face", "Region" };
00062
00063 FBiGeom_getEntType( geom, gent, &ent_type, &result );
00064
00065 if( iBase_SUCCESS != result )
00066 {
00067 printf( "Trouble getting entity adjacencies or types." );
00068 return 0;
00069 }
00070
00071 printf( "%s 0x%lx\n", type_names[ent_type], (unsigned long)gent );
00072
00073 return 1;
00074 }
00075
00076 int print_mesh_info( iMesh_Instance mesh, iBase_EntityHandle ment )
00077 {
00078 /* print information about this entity */
00079
00080 /* get adjacencies first; assume not more than 50 */
00081 iBase_EntityHandle adj_ents[50], *adj_ents_ptr = adj_ents;
00082 int ent_types[50], *ent_types_ptr = ent_types;
00083 int adj_ents_alloc = 50, adj_ents_size, ent_types_size, ent_types_allocated = 50;
00084 int result;
00085 iBase_TagHandle* ment_tags = NULL;
00086 int ment_tags_size, ment_tags_alloc;
00087 char** tag_names;
00088 int i;
00089 const char* type_names[] = { "Vertex", "Edge", "Face", "Region" };
00090 int tag_type;
00091
00092 char* dum_handle = NULL;
00093 int dum_handle_alloc = 0, dum_handle_size = 0;
00094 int int_data;
00095 double dbl_data;
00096 iBase_EntityHandle eh_data;
00097
00098 iMesh_getEntAdj( mesh, ment, iBase_ALL_TYPES, &adj_ents_ptr, &adj_ents_alloc, &adj_ents_size, &result );
00099
00100 if( iBase_SUCCESS != result ) return 0;
00101
00102 /* put this ent on the end, then get types */
00103 adj_ents[adj_ents_size] = ment;
00104 iMesh_getEntArrType( mesh, adj_ents, adj_ents_size + 1, &ent_types_ptr, &ent_types_allocated, &ent_types_size,
00105 &result );
00106 if( iBase_SUCCESS != result )
00107 {
00108 printf( "Trouble getting entity adjacencies or types." );
00109 return 0;
00110 }
00111
00112 /* get tags on ment */
00113 iMesh_getAllTags( mesh, ment, &ment_tags, &ment_tags_alloc, &ment_tags_size, &result );
00114
00115 printf( "Trouble getting tags on an entity or their names." );
00116
00117 /* while we're at it, get all the tag names */
00118
00119 tag_names = (char**)malloc( ment_tags_size * sizeof( char* ) );
00120
00121 for( i = 0; i < ment_tags_size; i++ )
00122 {
00123 tag_names[i] = (char*)malloc( 120 * sizeof( char ) );
00124 iMesh_getTagName( mesh, ment_tags[i], tag_names[i], &result, 120 );
00125 }
00126
00127 /* now print the information */
00128 printf( "%s %ld:\n", type_names[ent_types[ent_types_size - 1]], (long)ment );
00129 printf( "Adjacencies:" );
00130 for( i = 0; i < adj_ents_size; i++ )
00131 {
00132 if( i > 0 ) printf( ", " );
00133 printf( "%s %ld", type_names[ent_types[i]], (long)adj_ents[i] );
00134 }
00135 printf( "\nTags: \n" );
00136 for( i = 0; i < ment_tags_size; i++ )
00137 {
00138 printf( "%s ", tag_names[i] );
00139 iMesh_getTagType( mesh, ment_tags[i], &tag_type, &result );
00140 if( iBase_SUCCESS != result )
00141 printf( "(trouble getting type...)\n" );
00142 else
00143 {
00144 dum_handle = NULL;
00145 dum_handle_alloc = 0, dum_handle_size = 0;
00146
00147 switch( tag_type )
00148 {
00149 case iBase_INTEGER:
00150 iMesh_getIntData( mesh, ment, ment_tags[i], &int_data, &result );
00151 printf( "(Int value=%d)", int_data );
00152 break;
00153 case iBase_DOUBLE:
00154 iMesh_getDblData( mesh, ment, ment_tags[i], &dbl_data, &result );
00155 printf( "(Dbl value=%f)", dbl_data );
00156 break;
00157 case iBase_ENTITY_HANDLE:
00158 iMesh_getEHData( mesh, ment, ment_tags[i], &eh_data, &result );
00159 printf( "(EH value=%ld)", (long)eh_data );
00160 break;
00161 case iBase_BYTES:
00162 iMesh_getData( mesh, ment, ment_tags[i], (void**)&dum_handle, &dum_handle_alloc, &dum_handle_size,
00163 &result );
00164 if( NULL != dum_handle && dum_handle_size > 0 ) printf( "(Opaque value=%c)", dum_handle[0] );
00165 break;
00166 }
00167 }
00168
00169 printf( "\n" );
00170 }
00171 printf( "(end tags)\n\n" );
00172 free( ment_tags );
00173 return 1;
00174 }
00175
00176 /*!
00177 @test
00178 Load Mesh
00179 @li Load a geom and a mesh file
00180 */
00181 int load_geom_mesh_test( const char* geom_filename,
00182 const char* mesh_filename,
00183 FBiGeom_Instance geom,
00184 iMesh_Instance mesh )
00185 {
00186 /* load a geom */
00187 int result;
00188 FBiGeom_load( geom, geom_filename, 0, &result, strlen( geom_filename ), 0 );
00189 if( iBase_SUCCESS != result )
00190 {
00191 printf( "ERROR : can not load a geometry\n" );
00192 return 0;
00193 }
00194
00195 /* load a mesh */
00196 iMesh_load( mesh, 0, mesh_filename, 0, &result, strlen( mesh_filename ), 0 );
00197 if( iBase_SUCCESS != result )
00198 {
00199 printf( "ERROR : can not load a mesh\n" );
00200 return 0;
00201 }
00202
00203 return 1;
00204 }
00205
00206 /*!
00207 @test
00208 TSTTLasso create relation Test
00209 @li Create relation between geom and mesh
00210 */
00211 int create_relation_test( iRel_Instance assoc, FBiGeom_Instance geom, iMesh_Instance mesh, iRel_PairHandle* pair )
00212 {
00213 int result;
00214
00215 iBase_Instance iface1, iface2;
00216 int type1, type2;
00217 int ent_or_set1, ent_or_set2;
00218 int status1, status2;
00219
00220 iRel_PairHandle tmp_pair;
00221 iRel_PairHandle* pair_ptr = &tmp_pair;
00222 int pairs_alloc = 1, pairs_size;
00223
00224 /* create an relation, entity to set */
00225 iRel_createPair( assoc, geom, iRel_ENTITY, iRel_FBIGEOM_IFACE, iRel_ACTIVE, mesh, iRel_SET, iRel_IMESH_IFACE,
00226 iRel_ACTIVE, pair, &result );
00227 if( iBase_SUCCESS != result )
00228 {
00229 printf( "Couldn't create a new relation.\n" );
00230 return 0;
00231 }
00232
00233 iRel_getPairInfo( assoc, *pair, &iface1, &ent_or_set1, &type1, &status1, &iface2, &ent_or_set2, &type2, &status2,
00234 &result );
00235 if( iBase_SUCCESS != result )
00236 {
00237 printf( "Couldn't retrieve relation info.\n" );
00238 return 0;
00239 }
00240 if( iface1 != geom || ent_or_set1 != iRel_ENTITY || type1 != iRel_FBIGEOM_IFACE || iface2 != mesh ||
00241 ent_or_set2 != iRel_SET || type2 != iRel_IMESH_IFACE )
00242 {
00243 printf( "Unexpected relation info returned.\n" );
00244 return 0;
00245 }
00246
00247 iRel_findPairs( assoc, geom, &pair_ptr, &pairs_alloc, &pairs_size, &result );
00248 if( iBase_SUCCESS != result )
00249 {
00250 printf( "Couldn't find relation pair when querying geom.\n" );
00251 return 0;
00252 }
00253 if( pairs_size != 1 || tmp_pair != *pair )
00254 {
00255 printf( "Unexpected relation pairs returned when querying geom.\n" );
00256 return 0;
00257 }
00258
00259 iRel_findPairs( assoc, mesh, &pair_ptr, &pairs_alloc, &pairs_size, &result );
00260 if( iBase_SUCCESS != result )
00261 {
00262 printf( "Couldn't find relation pair when querying mesh.\n" );
00263 return 0;
00264 }
00265 if( pairs_size != 1 || tmp_pair != *pair )
00266 {
00267 printf( "Unexpected relation pairs returned when querying mesh.\n" );
00268 return 0;
00269 }
00270
00271 return 1;
00272 }
00273
00274 /*!
00275 @test
00276 TSTTLasso relate geom and mesh Test
00277 @li Check relation between geom and mesh
00278 */
00279 int relate_geom_mesh_test( iRel_Instance assoc, FBiGeom_Instance geom, iMesh_Instance mesh, iRel_PairHandle pair )
00280 {
00281 /* relate geometry entities with coresponding mesh entity sets */
00282 iBase_EntityHandle* gentities = NULL;
00283 int gentities_size = 0, gentities_alloc = 0;
00284 int result;
00285
00286 iBase_EntitySetHandle* mentity_handles = NULL;
00287 int mentity_handles_size = 0, mentity_handles_alloc = 0;
00288
00289 const char* dim_tag_name = "GEOM_DIMENSION";
00290 iBase_TagHandle dim_tag_mesh;
00291
00292 iBase_EntitySetHandle* mentities_vec;
00293 int mentities_vec_size;
00294 int i;
00295
00296 iBase_EntitySetHandle* out_mentities = NULL;
00297 int out_mentities_size = 0, out_mentities_alloc = 0;
00298
00299 iBase_EntitySetHandle* out_mentities2 = NULL;
00300 int out_mentities2_size = 0, out_mentities2_alloc = 0;
00301
00302 iBase_EntityHandle* out_gentities = NULL;
00303 int out_gentities_size = 0, out_gentities_alloc = 0;
00304
00305 FBiGeom_getEntities( geom, NULL, iBase_VERTEX, &gentities, &gentities_alloc, &gentities_size, &result );
00306 if( iBase_SUCCESS != result )
00307 {
00308 printf( "Failed to get gentities by type in relate_geom_mesh_test.\n" );
00309 return 0;
00310 }
00311
00312 iRel_inferEntArrRelations( assoc, pair, gentities, gentities_size, 0, &result );
00313 if( iBase_SUCCESS != result )
00314 {
00315 printf( "Failed to relate geom entities in relate_geom_mesh_test.\n" );
00316 return 0;
00317 }
00318
00319 /* relate coresponding mesh entity sets for geometry entities */
00320 /* get 1-dimensional mesh entitysets */
00321
00322 iMesh_getEntSets( mesh, NULL, 1, &mentity_handles, &mentity_handles_alloc, &mentity_handles_size, &result );
00323 if( iBase_SUCCESS != result )
00324 {
00325 printf( "Problem to get all entity sets.\n" );
00326 return 0;
00327 }
00328
00329 /* get geom dimension tags for mesh entitysets */
00330 iMesh_createTag( mesh, dim_tag_name, 1, iBase_INTEGER, &dim_tag_mesh, &result, 15 );
00331 if( iBase_SUCCESS != result && result != iBase_TAG_ALREADY_EXISTS )
00332 {
00333 printf( "Couldn't create geom dim tag for mesh entities.\n" );
00334 return 0;
00335 }
00336
00337 /* get 1-dimensional mesh entitysets */
00338 mentities_vec = (iBase_EntitySetHandle*)malloc( mentity_handles_size * sizeof( iBase_EntitySetHandle ) );
00339 mentities_vec_size = 0;
00340
00341 for( i = 0; i < mentity_handles_size; i++ )
00342 {
00343 int dim;
00344 iMesh_getEntSetIntData( mesh, mentity_handles[i], dim_tag_mesh, &dim, &result );
00345 if( iBase_SUCCESS != result ) continue;
00346
00347 if( dim == 1 ) mentities_vec[mentities_vec_size++] = mentity_handles[i];
00348 }
00349
00350 iRel_inferSetArrRelations( assoc, pair, mentities_vec, mentities_vec_size, 1, &result );
00351 if( iBase_SUCCESS != result )
00352 {
00353 printf( "Failed to relate mesh entities in relate_geom_mesh_test.\n" );
00354 return 0;
00355 }
00356
00357 /* relate all geometry and mesh entities */
00358 iRel_inferAllRelations( assoc, pair, &result );
00359 if( iBase_SUCCESS != result )
00360 {
00361 printf( "Failed to relate all geom and mesh entities in relate_geom_mesh_test.\n" );
00362 return 0;
00363 }
00364
00365 /* reset geom entities list and get all geom entities (prev
00366 only vertices) */
00367 free( gentities );
00368 gentities = NULL;
00369 gentities_alloc = 0;
00370 FBiGeom_getEntities( geom, NULL, iBase_ALL_TYPES, &gentities, &gentities_alloc, &gentities_size, &result );
00371 if( iBase_SUCCESS != result )
00372 {
00373 printf( "Failed to get gentities by type in relate_geom_mesh_test.\n" );
00374 return 0;
00375 }
00376
00377 /* get related mesh entity sets for geometry entities */
00378 iRel_getEntArrSetArrRelation( assoc, pair, gentities, gentities_size, 0, &out_mentities, &out_mentities_alloc,
00379 &out_mentities_size, &result );
00380 if( iBase_SUCCESS != result )
00381 {
00382 printf( "Failed to get geom entities in relate_geom_mesh_test.\n" );
00383 return 0;
00384 }
00385
00386 if( out_mentities_size != gentities_size )
00387 {
00388 printf( "Number of input geom entities and output mesh entity sets should be same\n" );
00389 return 0;
00390 }
00391
00392 /* now try deleting this relation */
00393 iRel_rmvEntArrRelation( assoc, pair, gentities, gentities_size, 0, &result );
00394 if( iBase_SUCCESS != result )
00395 {
00396 printf( "Failed to remove relation in relate_geom_mesh_test.\n" );
00397 return 0;
00398 }
00399 iRel_getEntArrSetArrRelation( assoc, pair, gentities, gentities_size, 0, &out_mentities2, &out_mentities2_alloc,
00400 &out_mentities2_size, &result );
00401 if( iBase_SUCCESS == result )
00402 {
00403 printf( "Shouldn't have gotten mesh sets in relate_geom_mesh_test.\n" );
00404 return 0;
00405 }
00406
00407 /* restore the relation, since we need it later */
00408 iRel_setEntArrSetArrRelation( assoc, pair, gentities, gentities_size, out_mentities, out_mentities_size, &result );
00409 if( iBase_SUCCESS != result )
00410 {
00411 printf( "Failed to restore relation in relate_geom_mesh_test.\n" );
00412 return 0;
00413 }
00414
00415 /* get related geometry entities for mesh entity sets */
00416 iRel_getSetArrEntArrRelation( assoc, pair, out_mentities, out_mentities_size, 1, &out_gentities,
00417 &out_gentities_alloc, &out_gentities_size, &result );
00418 if( iBase_SUCCESS != result )
00419 {
00420 printf( "Failed to get mesh entities in relate_geom_mesh_test.\n" );
00421 return 0;
00422 }
00423
00424 if( out_mentities_size != out_gentities_size )
00425 {
00426 printf( "Number of input mesh entity sets and output geom entities should be same\n" );
00427 return 0;
00428 }
00429 free( mentity_handles );
00430 mentity_handles = NULL;
00431 free( gentities );
00432 gentities = NULL;
00433 free( mentity_handles );
00434 mentity_handles = NULL;
00435 free( out_mentities );
00436 out_mentities = NULL;
00437 free( mentities_vec );
00438 mentities_vec = NULL;
00439 free( out_gentities );
00440 out_gentities = NULL;
00441 return 1;
00442 }
00443
00444 /*!
00445 @test
00446 TSTTAssoc move to test
00447 @li Move meshes onto the given geometry
00448 */
00449 int query_relations_test( iRel_Instance assoc, FBiGeom_Instance geom, iMesh_Instance mesh, iRel_PairHandle pair )
00450 {
00451 /* get all the geom entities, and find relation to some mesh entity */
00452 iBase_EntityHandle* gentities = NULL;
00453 int gentities_size = 0, gentities_alloc = 0;
00454 int result;
00455
00456 iBase_EntitySetHandle* out_mentities = NULL;
00457 int out_mentities_size, out_mentities_alloc = 0;
00458
00459 char descr[120];
00460 int i;
00461 int is_list;
00462
00463 iBase_EntityHandle* out_gentities = NULL;
00464 int out_gentities_size, out_gentities_alloc = 0;
00465
00466 FBiGeom_getEntities( geom, NULL, iBase_ALL_TYPES, &gentities, &gentities_alloc, &gentities_size, &result );
00467 if( iBase_SUCCESS != result )
00468 {
00469 printf( "Problem getting all geom entities.\n" );
00470 return 0;
00471 }
00472
00473 iRel_getEntArrSetArrRelation( assoc, pair, gentities, gentities_size, 0, &out_mentities, &out_mentities_alloc,
00474 &out_mentities_size, &result );
00475 /* might not all be */
00476 if( iBase_SUCCESS != result )
00477 {
00478 printf( "Failed to get mesh entities related to geom entities in query_relations_test.\n" );
00479
00480 iRel_getDescription( assoc, descr, sizeof( descr ) - 1 );
00481 printf( "Entities missing relations: %s\n", descr );
00482
00483 for( i = 0; i < gentities_size; i++ )
00484 {
00485 print_geom_info( geom, gentities[i] );
00486 }
00487
00488 return 0;
00489 }
00490
00491 /* check that they're all non-null */
00492 if( out_mentities_size != gentities_size )
00493 {
00494 printf( "Number of mesh & related geom entities don't match.\n" );
00495 return 0;
00496 }
00497
00498 /* check to make sure they're mesh sets; how to do that? */
00499 for( i = 0; i < out_mentities_size; i++ )
00500 {
00501 iMesh_isList( mesh, (iBase_EntitySetHandle)out_mentities[i], &is_list, &result );
00502 if( iBase_SUCCESS != result )
00503 {
00504 printf( "Entity set returned from classification wasn't valid.\n" );
00505 return 0;
00506 }
00507 }
00508
00509 /* now turn around and check classification of those mesh entities */
00510 iRel_getSetArrEntArrRelation( assoc, pair, out_mentities, out_mentities_size, 1, &out_gentities,
00511 &out_gentities_alloc, &out_gentities_size, &result );
00512 if( iBase_SUCCESS != result )
00513 {
00514 printf( "Failed to get geom entities related to mesh entities in query_relations_test.\n" );
00515 return 0;
00516 }
00517
00518 /* check that they're all non-null */
00519 if( out_mentities_size != out_gentities_size )
00520 {
00521 printf( "Number of geom & related mesh entities don't match.\n" );
00522 return 0;
00523 }
00524
00525 free( gentities );
00526 gentities = NULL;
00527 free( out_mentities );
00528 out_mentities = NULL;
00529 free( out_gentities );
00530 out_gentities = NULL;
00531 /* ok, we're done */
00532 return 1;
00533 }
00534
00535 int main( int argc, char* argv[] )
00536 {
00537 /* Check command line arg */
00538 const char* geom_filename = DEFAULT_INPUT_FILE;
00539 const char* mesh_filename = DEFAULT_INPUT_FILE1;
00540
00541 int result;
00542 int number_tests = 0;
00543 int number_tests_successful = 0;
00544 int number_tests_not_implemented = 0;
00545 int number_tests_failed = 0;
00546
00547 FBiGeom_Instance geom;
00548 iMesh_Instance mesh;
00549 iRel_Instance assoc;
00550 iRel_PairHandle pair;
00551
00552 if( argc == 2 && !strcmp( argv[1], "-h" ) )
00553 {
00554 printf( "Usage: %s \n", argv[0] );
00555 return 1;
00556 }
00557 else if( argc == 2 )
00558 {
00559 geom_filename = argv[1];
00560 mesh_filename = argv[1];
00561 }
00562 else if( argc == 3 )
00563 {
00564 geom_filename = argv[1];
00565 mesh_filename = argv[2];
00566 }
00567
00568 /* initialize the Geometry */
00569 FBiGeom_newGeom( 0, &geom, &result, 0 );
00570
00571 /* initialize the Mesh */
00572 iMesh_newMesh( 0, &mesh, &result, 0 );
00573
00574 /* initialize the Associate */
00575 iRel_create( 0, &assoc, &result, 0 );
00576
00577 /* Print out Header information */
00578 printf( "\n\niRel TEST PROGRAM:\n\n" );
00579
00580 /* load_geom_mesh test */
00581 printf( " load_geom_mesh: " );
00582 result = load_geom_mesh_test( geom_filename, mesh_filename, geom, mesh );
00583 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
00584 number_tests++;
00585 printf( "\n" );
00586
00587 /* create_relation test */
00588 printf( " create_relation: " );
00589 result = create_relation_test( assoc, geom, mesh, &pair );
00590 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
00591 number_tests++;
00592 printf( "\n" );
00593
00594 /* relate_geom_mesh test */
00595 printf( " relate_geom_mesh: " );
00596 result = relate_geom_mesh_test( assoc, geom, mesh, pair );
00597 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
00598 number_tests++;
00599 printf( "\n" );
00600
00601 /* query_relations test */
00602 printf( " query_relations: " );
00603 result = query_relations_test( assoc, geom, mesh, pair );
00604 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
00605 number_tests++;
00606 printf( "\n" );
00607
00608 /* summary */
00609
00610 printf( "\niRel TEST SUMMARY: \n" );
00611 printf( " Number Tests: %d\n", number_tests );
00612 printf( " Number Successful: %d\n", number_tests_successful );
00613 printf( " Number Not Implemented: %d\n", number_tests_not_implemented );
00614 printf( " Number Failed: %d\n", number_tests_failed );
00615 printf( "\n\n" );
00616
00617 iRel_destroy( assoc, &result );
00618 iMesh_dtor( mesh, &result );
00619 FBiGeom_dtor( geom, &result );
00620
00621 return number_tests_failed != 0;
00622 }