[MOAB-dev] r3031 - MOAB/trunk
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Mon Jul 20 12:18:16 CDT 2009
Author: kraftche
Date: 2009-07-20 12:18:16 -0500 (Mon, 20 Jul 2009)
New Revision: 3031
Modified:
MOAB/trunk/AEntityFactory.cpp
MOAB/trunk/MBCore.cpp
MOAB/trunk/MBTest.cpp
Log:
o Add unit test for merging that demonstrates bug updating references to
merged vertices when vertices are contained in tracking sets.
o Fix above bug
o Fix incorrect error handling in MBCore::merge_entities: if updating
of references fails, don't delete the entity.
Modified: MOAB/trunk/AEntityFactory.cpp
===================================================================
--- MOAB/trunk/AEntityFactory.cpp 2009-07-19 02:48:22 UTC (rev 3030)
+++ MOAB/trunk/AEntityFactory.cpp 2009-07-20 17:18:16 UTC (rev 3031)
@@ -1339,8 +1339,15 @@
return result;
// set them all, and if to_entity is a set, add to that one too
for (unsigned int i = 0; i < adjs.size(); i++) {
- if(ent_dim == 0)
+ if (TYPE_FROM_HANDLE(adjs[i]) == MBENTITYSET)
{
+ result = this->add_adjacency(entity_to_keep, adjs[i]);
+ if(result != MB_SUCCESS) return result;
+ result = thisMB->add_entities(adjs[i], &entity_to_keep, 1);
+ if(result != MB_SUCCESS) return result;
+ }
+ else if(ent_dim == 0)
+ {
conn.clear();
result = thisMB->get_connectivity(&adjs[i], 1, conn);
@@ -1355,10 +1362,6 @@
else {
result = this->add_adjacency(entity_to_keep, adjs[i]);
if(result != MB_SUCCESS) return result;
- if (TYPE_FROM_HANDLE(adjs[i]) == MBENTITYSET) {
- result = thisMB->add_entities(adjs[i], &entity_to_keep, 1);
- if(result != MB_SUCCESS) return result;
- }
}
}
Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp 2009-07-19 02:48:22 UTC (rev 3030)
+++ MOAB/trunk/MBCore.cpp 2009-07-20 17:18:16 UTC (rev 3031)
@@ -1934,7 +1934,7 @@
result = aEntityFactory->merge_adjust_adjacencies(entity_to_keep, entity_to_remove);
- if (delete_removed_entity)
+ if (MB_SUCCESS == result && delete_removed_entity)
result = delete_entities(&entity_to_remove, 1);
return result;
Modified: MOAB/trunk/MBTest.cpp
===================================================================
--- MOAB/trunk/MBTest.cpp 2009-07-19 02:48:22 UTC (rev 3030)
+++ MOAB/trunk/MBTest.cpp 2009-07-20 17:18:16 UTC (rev 3031)
@@ -4323,7 +4323,123 @@
return result;
}
+MBErrorCode mb_merge_update_test(MBInterface*)
+{
+ MBCore moab;
+ MBInterface* mb = &moab;
+ MBErrorCode rval;
+
+ // create two quads with a coincident edge pair
+ double coords[] = { 0, 0, 0,
+ 1, 0, 0,
+ 1, 1, 0,
+ 0, 1, 0,
+ 1, 1, 0,
+ 1, 0, 0,
+ 2, 0, 0,
+ 2, 1, 0 };
+ MBEntityHandle verts[8];
+ for (int i = 0; i < 8; ++i)
+ mb->create_vertex( coords + 3*i, verts[i] );
+ MBEntityHandle quad1, quad2, edge1, edge2;
+ mb->create_element( MBQUAD, verts, 4, quad1 );
+ mb->create_element( MBQUAD, verts+4, 4, quad2 );
+ mb->create_element( MBEDGE, verts+1, 2, edge1 );
+ mb->create_element( MBEDGE, verts+4, 2, edge2 );
+
+ // create two tracking sets containing the vertices
+ // and edge of each quad
+ MBEntityHandle set1, set2;
+ mb->create_meshset( MESHSET_TRACK_OWNER, set1 );
+ mb->create_meshset( MESHSET_TRACK_OWNER, set2 );
+ mb->add_entities( set1, verts, 4 );
+ mb->add_entities( set2, verts+4, 4 );
+ mb->add_entities( set1, &edge1, 1 );
+ mb->add_entities( set2, &edge2, 1 );
+
+ // now merge the coincident edges
+ rval = mb->merge_entities( verts[1], verts[5], false, true );
+ if (MB_SUCCESS != rval) {
+ std::cerr << "Merge failed at " << __FILE__ << ":" << __LINE__ << std::endl;
+ return rval;
+ }
+ rval = mb->merge_entities( verts[2], verts[4], false, true );
+ if (MB_SUCCESS != rval) {
+ std::cerr << "Merge failed at " << __FILE__ << ":" << __LINE__ << std::endl;
+ return rval;
+ }
+ rval = mb->merge_entities( edge1, edge2, false, true );
+ if (MB_SUCCESS != rval) {
+ std::cerr << "Merge failed at " << __FILE__ << ":" << __LINE__ << std::endl;
+ return rval;
+ }
+
+ // check that there is only one edge and that it has the correct connectivity
+ MBRange r;
+ mb->get_entities_by_type( 0, MBEDGE, r );
+ if (r.size() != 1 || r.front() != edge1) {
+ std::cerr << "Edge merge failed at " << __FILE__ << ":" << __LINE__ << std::endl;
+ return MB_FAILURE;
+ }
+ std::vector<MBEntityHandle> exp(verts+1, verts+3), act;
+ mb->get_connectivity( &edge1, 1, act );
+ if (exp != act) {
+ std::cerr << "Incorrect conn for edge at " << __FILE__ << ":" << __LINE__ << std::endl;
+ return MB_FAILURE;
+ }
+
+ // check that quad connectivity is as expected
+ exp = std::vector<MBEntityHandle>(verts, verts+4);
+ act.clear();
+ mb->get_connectivity( &quad1, 1, act );
+ if (exp != act) {
+ std::cerr << "Incorrect conn for quad at " << __FILE__ << ":" << __LINE__ << std::endl;
+ return MB_FAILURE;
+ }
+ exp.resize(4);
+ exp[0] = verts[2];
+ exp[1] = verts[1];
+ exp[2] = verts[6];
+ exp[3] = verts[7];
+ act.clear();
+ mb->get_connectivity( &quad2, 1, act );
+ if (exp != act) {
+ std::cerr << "Incorrect conn for quad at " << __FILE__ << ":" << __LINE__ << std::endl;
+ return MB_FAILURE;
+ }
+
+ // check that set contents are correctly updated
+ exp = std::vector<MBEntityHandle>(verts, verts+4);
+ exp.push_back( edge1 );
+ act.clear();
+ mb->get_entities_by_handle( set1, act );
+ std::sort( exp.begin(), exp.end() );
+ std::sort( act.begin(), act.end() );
+ if (exp != act) {
+ std::cerr << "Incorrect set contents at " << __FILE__ << ":" << __LINE__ << std::endl;
+ return MB_FAILURE;
+ }
+
+ exp.resize(5);
+ exp[0] = verts[2];
+ exp[1] = verts[1];
+ exp[2] = verts[6];
+ exp[3] = verts[7];
+ exp[4] = edge1;
+ act.clear();
+ mb->get_entities_by_handle( set2, act );
+ std::sort( exp.begin(), exp.end() );
+ std::sort( act.begin(), act.end() );
+ if (exp != act) {
+ std::cerr << "Incorrect set contents at " << __FILE__ << ":" << __LINE__ << std::endl;
+ return MB_FAILURE;
+ }
+ return MB_SUCCESS;
+}
+
+
+
MBErrorCode mb_stress_test(MBInterface *MB)
{
// delete the existing mesh
@@ -6040,6 +6156,7 @@
RUN_TEST( mb_poly_adjacency_test );
RUN_TEST( mb_memory_use_test );
RUN_TEST( mb_merge_test );
+ RUN_TEST( mb_merge_update_test );
if (stress_test) RUN_TEST( mb_stress_test );
// summary
More information about the moab-dev
mailing list