Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
00001 #include "iGeom.h" 00002 #include "iMesh.h" 00003 #include "iRel.h" 00004 00005 #include "TestUtil.hpp" 00006 00007 #include <cstdlib> 00008 00009 using namespace moab; 00010 iGeom_Instance geom; 00011 iMesh_Instance mesh; 00012 iRel_Instance rel; 00013 00014 iBase_EntityHandle geom_ent; 00015 iBase_EntityHandle mesh_ents[4]; 00016 iBase_EntitySetHandle mesh_set; 00017 00018 void test_both() 00019 { 00020 int err; 00021 iRel_PairHandle pair; 00022 00023 iRel_createPair( rel, geom, iRel_ENTITY, iRel_IGEOM_IFACE, iRel_ACTIVE, mesh, iRel_BOTH, iRel_IMESH_IFACE, 00024 iRel_ACTIVE, &pair, &err );CHECK_ERR( err ); 00025 00026 iRel_setEntSetRelation( rel, pair, geom_ent, mesh_set, &err );CHECK_ERR( err ); 00027 00028 iBase_EntityHandle* related_ents = NULL; 00029 int related_ents_alloc = 0, related_ents_size; 00030 iRel_getEntArrEntArrRelation( rel, pair, mesh_ents, 4, 1, &related_ents, &related_ents_alloc, &related_ents_size, 00031 &err );CHECK_ERR( err ); 00032 00033 for( int i = 0; i < related_ents_size; i++ ) 00034 CHECK_EQUAL( related_ents[i], geom_ent ); 00035 00036 free( related_ents ); 00037 } 00038 00039 void test_change_to_both() 00040 { 00041 int err; 00042 iRel_PairHandle pair; 00043 00044 iRel_createPair( rel, geom, iRel_ENTITY, iRel_IGEOM_IFACE, iRel_ACTIVE, mesh, iRel_SET, iRel_IMESH_IFACE, 00045 iRel_ACTIVE, &pair, &err );CHECK_ERR( err ); 00046 00047 iRel_setEntSetRelation( rel, pair, geom_ent, mesh_set, &err );CHECK_ERR( err ); 00048 00049 iRel_changePairType( rel, pair, iRel_ENTITY, iRel_BOTH, &err );CHECK_ERR( err ); 00050 00051 iBase_EntityHandle* related_ents = NULL; 00052 int related_ents_alloc = 0, related_ents_size; 00053 iRel_getEntArrEntArrRelation( rel, pair, mesh_ents, 4, 1, &related_ents, &related_ents_alloc, &related_ents_size, 00054 &err );CHECK_ERR( err ); 00055 00056 for( int i = 0; i < related_ents_size; i++ ) 00057 CHECK_EQUAL( related_ents[i], geom_ent ); 00058 00059 free( related_ents ); 00060 } 00061 00062 void test_change_to_set() 00063 { 00064 int err; 00065 iRel_PairHandle pair; 00066 00067 iRel_createPair( rel, geom, iRel_ENTITY, iRel_IGEOM_IFACE, iRel_ACTIVE, mesh, iRel_BOTH, iRel_IMESH_IFACE, 00068 iRel_ACTIVE, &pair, &err );CHECK_ERR( err ); 00069 00070 iRel_setEntSetRelation( rel, pair, geom_ent, mesh_set, &err );CHECK_ERR( err ); 00071 00072 iRel_changePairType( rel, pair, iRel_ENTITY, iRel_SET, &err );CHECK_ERR( err ); 00073 00074 for( int i = 0; i < 4; i++ ) 00075 { 00076 iBase_EntityHandle related_ent; 00077 iRel_getEntEntRelation( rel, pair, mesh_ents[i], 1, &related_ent, &err ); 00078 CHECK( err != iBase_SUCCESS ); 00079 } 00080 } 00081 00082 int main() 00083 { 00084 int err; 00085 int num_fail = 0; 00086 00087 iGeom_newGeom( 0, &geom, &err, 0 ); 00088 iMesh_newMesh( 0, &mesh, &err, 0 ); 00089 iRel_create( 0, &rel, &err, 0 ); 00090 00091 iGeom_createBrick( geom, 2, 2, 2, &geom_ent, &err ); 00092 00093 double coords[] = { 00094 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 00095 }; 00096 00097 iBase_EntityHandle* mesh_ents_ptr = mesh_ents; 00098 int mesh_ents_alloc = 4, mesh_ents_size; 00099 iMesh_createVtxArr( mesh, 4, iBase_INTERLEAVED, coords, 12, &mesh_ents_ptr, &mesh_ents_alloc, &mesh_ents_size, 00100 &err ); 00101 00102 iMesh_createEntSet( mesh, false, &mesh_set, &err ); 00103 iMesh_addEntArrToSet( mesh, mesh_ents, mesh_ents_size, mesh_set, &err ); 00104 00105 num_fail += RUN_TEST( test_both ); 00106 num_fail += RUN_TEST( test_change_to_both ); 00107 num_fail += RUN_TEST( test_change_to_set ); 00108 00109 iRel_destroy( rel, &err ); 00110 iMesh_dtor( mesh, &err ); 00111 iGeom_dtor( geom, &err ); 00112 00113 return num_fail; 00114 }