[MOAB-dev] r3055 - MOAB/trunk
kraftche at cae.wisc.edu
kraftche at cae.wisc.edu
Thu Jul 23 13:04:20 CDT 2009
Author: kraftche
Date: 2009-07-23 13:04:18 -0500 (Thu, 23 Jul 2009)
New Revision: 3055
Modified:
MOAB/trunk/AEntityFactory.cpp
MOAB/trunk/MBCore.cpp
MOAB/trunk/MBCore.hpp
MOAB/trunk/MBInterface.hpp
MOAB/trunk/MBMeshSet.cpp
MOAB/trunk/MBMeshSet.hpp
MOAB/trunk/MBTest.cpp
Log:
o Array passed to MBInterface::contains_entities should be const
o Change arguments to MBInterface::replace_entities such that
a single non-const array is replaced by two const arrays
o Implement MBCore::replace_entities
o Call MBCore::replace_entities from AEntityFactory::merge_adjust_adjacencies
to update sets such that order is preserved for list-type sets
o Add unit tests for MBInterface::replace_entities
o Update merge unit test such that it expected order to be preserved
for tracking list sets.
Modified: MOAB/trunk/AEntityFactory.cpp
===================================================================
--- MOAB/trunk/AEntityFactory.cpp 2009-07-22 19:17:40 UTC (rev 3054)
+++ MOAB/trunk/AEntityFactory.cpp 2009-07-23 18:04:18 UTC (rev 3055)
@@ -1341,10 +1341,13 @@
for (unsigned int i = 0; i < adjs.size(); i++) {
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;
+ //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;
+ result = thisMB->replace_entities( adjs[i], &entity_to_remove, &entity_to_keep, 1 );
+ if (MB_SUCCESS != result)
+ return result;
}
else if(ent_dim == 0)
{
Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp 2009-07-22 19:17:40 UTC (rev 3054)
+++ MOAB/trunk/MBCore.cpp 2009-07-23 18:04:18 UTC (rev 3055)
@@ -2492,7 +2492,7 @@
//! return true if all entities are contained in set
bool MBCore::contains_entities(MBEntityHandle meshset,
- MBEntityHandle *entities,
+ const MBEntityHandle *entities,
int num_entities,
const int operation_type)
{
@@ -2503,38 +2503,18 @@
return false;
}
-// replace entities in a meshset; entities appear in pairs,
-// old then new entity in each pair
-bool MBCore::replace_entities(MBEntityHandle meshset,
- MBEntityHandle *entities,
- int num_entities)
+// replace entities in a meshset
+MBErrorCode MBCore::replace_entities(MBEntityHandle meshset,
+ const MBEntityHandle *old_entities,
+ const MBEntityHandle *new_entities,
+ int num_entities)
{
- return false;
- /*
- // if a regular entity set, we're simply changing contents of this set
- if (0 != meshset) {
-
- MBMeshSet* set = get_mesh_set( sequence_manager(), meshset );
- if (set)
- return set->replace_entities( meshset, entities, num_entities, a_entity_factory() );
- else
- return false;
- }
-
- // otherwise, we're actually changing an entity's handle
- // in preparation, get all the non-tracking sets
- MBRange tmp_sets, all_sets;
- MBErrorCode result = get_entities_by_type(0, MBENTITYSET, tmp_sets);
- if (MB_SUCCESS != result) return result;
- unsigned int option;
- for (MBRange::iterator rit = tmp_sets.begin(); rit != tmp_sets.end(); rit++)
- if (MB_SUCCESS == get_meshset_options(*rit, option) &&
- !(option & MESHSET_TRACK_OWNER))
- all_sets.insert(*rit);
-
- // now replace each entity
- double coords[3];
- */
+ MBMeshSet* set = get_mesh_set( sequence_manager(), meshset );
+ if (set)
+ return set->replace_entities( meshset, old_entities, new_entities,
+ num_entities, a_entity_factory());
+ else
+ return MB_ENTITY_NOT_FOUND;
}
MBErrorCode MBCore::get_parent_meshsets(const MBEntityHandle meshset,
Modified: MOAB/trunk/MBCore.hpp
===================================================================
--- MOAB/trunk/MBCore.hpp 2009-07-22 19:17:40 UTC (rev 3054)
+++ MOAB/trunk/MBCore.hpp 2009-07-23 18:04:18 UTC (rev 3055)
@@ -869,14 +869,15 @@
//! return true if all entities are contained in set
virtual bool contains_entities(MBEntityHandle meshset,
- MBEntityHandle *entities,
+ const MBEntityHandle *entities,
int num_entities,
const int operation_type = MBInterface::INTERSECT);
//! replace entities
- virtual bool replace_entities(MBEntityHandle meshset,
- MBEntityHandle *entities,
- int num_entities);
+ virtual MBErrorCode replace_entities(MBEntityHandle meshset,
+ const MBEntityHandle *old_entities,
+ const MBEntityHandle *new_entities,
+ int num_entities);
//------MeshSet Parent/Child functions------
Modified: MOAB/trunk/MBInterface.hpp
===================================================================
--- MOAB/trunk/MBInterface.hpp 2009-07-22 19:17:40 UTC (rev 3054)
+++ MOAB/trunk/MBInterface.hpp 2009-07-23 18:04:18 UTC (rev 3055)
@@ -1389,21 +1389,39 @@
* \return bool If true, all entities are contained in set
*/
virtual bool contains_entities(MBEntityHandle meshset,
- MBEntityHandle *entities,
+ const MBEntityHandle *entities,
int num_entities,
const int operation_type = MBInterface::INTERSECT) = 0;
//! Replace entities in a set with other entities
- /** Replace entities in a set with other entities; entity list
- * specified in pairs of (old, new)
+ /** Replace entities in a set with other entities
+ *
+ * \note Behavior is undefined if an entity handle exists in both the
+ * old_entities and the new_entities arrays or old_entities
+ * contains multiple copies of an entity.
+ * \note If an entity occurs multiple times in an ordered set, all
+ * occurances will be replaced.
+ * \note For list-based sets, if not all handles in old_entities
+ * occcur in the set, the corresponding new_entities will not
+ * be added and MB_ENTITY_NOT_FOUND will be returned.
+ * For set-based sets, all entities in new_entities wll be
+ * added and any contained entities in old_entities will be
+ * removed, and the return value will be MB_SUCCESS.
* \param meshset Mesh set being modified
- * \param entities Pairs of old/new entities
- * \param num_entities Number of entities \em{total} in entities list
- * \return bool If true, one or more entities were replaced
+ * \param old_entities Entities to replace
+ * \param new_entities New entities to add
+ * \param num_entities Number of entities in input arrays
+ * \return - MB_SUCCESS : all entities in old_entities replaced
+ * - MB_ENTITY_NOT_FOUND : one or more entities in new_entities
+ * not added to set because corresponding entity
+ * in old_entities did not occur in the ordered
+ * set.
+ * - MB_FAILURE : internal error
*/
- virtual bool replace_entities(MBEntityHandle meshset,
- MBEntityHandle *entities,
- int num_entities) = 0;
+ virtual MBErrorCode replace_entities(MBEntityHandle meshset,
+ const MBEntityHandle *old_entities,
+ const MBEntityHandle *new_entities,
+ int num_entities) = 0;
//@}
//! \name MeshSet parent/child functions
Modified: MOAB/trunk/MBMeshSet.cpp
===================================================================
--- MOAB/trunk/MBMeshSet.cpp 2009-07-22 19:17:40 UTC (rev 3054)
+++ MOAB/trunk/MBMeshSet.cpp 2009-07-23 18:04:18 UTC (rev 3055)
@@ -1075,63 +1075,37 @@
-bool MBMeshSet::replace_entities( MBEntityHandle my_handle,
- const MBEntityHandle* entities,
- size_t num_entities,
- AEntityFactory* adjfact )
+MBErrorCode MBMeshSet::replace_entities( MBEntityHandle my_handle,
+ const MBEntityHandle* old_entities,
+ const MBEntityHandle* new_entities,
+ size_t num_entities,
+ AEntityFactory* adjfact )
{
- assert(0 == num_entities%2);
if (vector_based()) {
- bool was_contained = false;
+ MBErrorCode result = MB_SUCCESS;
size_t count;
MBEntityHandle* vect = get_contents( count );
MBEntityHandle* const vect_end = vect+count;
- for (size_t i = 0; i < num_entities; i+=2) {
- for (MBEntityHandle* p = vect; p != vect_end; ++p ) {
- if (*p == entities[i]) {
- if (tracking()) {
- adjfact->remove_adjacency( *p, my_handle );
- adjfact->add_adjacency( entities[i+1], my_handle, false );
- }
- *p = entities[i+1];
- was_contained = true;
- }
+ for (size_t i = 0; i < num_entities; ++i) {
+ MBEntityHandle* p = std::find( vect, vect_end, old_entities[i] );
+ if (p == vect_end) {
+ result = MB_ENTITY_NOT_FOUND;
}
+ else do {
+ if (tracking()) {
+ adjfact->remove_adjacency( *p, my_handle );
+ adjfact->add_adjacency( new_entities[i], my_handle, false );
+ }
+ *p = new_entities[i];
+ p = std::find( p+1, vect_end, old_entities[i] );
+ } while (p != vect_end);
}
- return was_contained;
+ return result;
}
else {
- std::vector<MBEntityHandle> swap_list;
- swap_list.reserve( num_entities / 2 );
-
- // get list of handles to remove
- size_t count;
- MBEntityHandle* vect = get_contents( count );
- MBEntityHandle* const vect_end = vect+count;
- for (size_t i = 0; i < num_entities; i+=2) {
- MBEntityHandle* p = std::lower_bound(vect, vect_end, entities[i]);
- if (p != vect_end && (*p == entities[i] || (p-vect)%2 == 1))
- swap_list.push_back(entities[i]);
- }
- if (swap_list.empty())
- return false;
-
- // remove entities
- remove_entities( &swap_list[0], swap_list.size(), my_handle, adjfact );
-
- // get list of handles to add
- std::vector<MBEntityHandle>::iterator si = swap_list.begin();
- for (size_t i = 0; i < num_entities; ++i) {
- if (entities[i] == *si) {
- *si = entities[i+1];
- if (++si == swap_list.end())
- break;
- }
- }
-
- // add entities
- add_entities( &swap_list[0], swap_list.size(), my_handle, adjfact );
- return true;
+ MBErrorCode r1 = remove_entities( old_entities, num_entities, my_handle, adjfact );
+ MBErrorCode r2 = add_entities( new_entities, num_entities, my_handle, adjfact );
+ return (MB_SUCCESS == r2) ? r1 : r2;
}
}
Modified: MOAB/trunk/MBMeshSet.hpp
===================================================================
--- MOAB/trunk/MBMeshSet.hpp 2009-07-22 19:17:40 UTC (rev 3054)
+++ MOAB/trunk/MBMeshSet.hpp 2009-07-23 18:04:18 UTC (rev 3055)
@@ -71,10 +71,11 @@
//! replace one entity with another in the set (contents and parent/child
//! lists); returns whether it was replaced or not
- bool replace_entities(MBEntityHandle my_handle,
- const MBEntityHandle *entities,
- size_t num_entities,
- AEntityFactory* mAdjFact);
+ MBErrorCode replace_entities(MBEntityHandle my_handle,
+ const MBEntityHandle *old_entities,
+ const MBEntityHandle *new_entities,
+ size_t num_entities,
+ AEntityFactory* mAdjFact);
/** Clear *contents* of set (not parents or children) */
inline MBErrorCode clear( MBEntityHandle myhandle, AEntityFactory* adjacencies );
Modified: MOAB/trunk/MBTest.cpp
===================================================================
--- MOAB/trunk/MBTest.cpp 2009-07-22 19:17:40 UTC (rev 3054)
+++ MOAB/trunk/MBTest.cpp 2009-07-23 18:04:18 UTC (rev 3055)
@@ -57,6 +57,10 @@
#include "testdir.h"
string TestDir( TEST_DIR );
+#define CHKERR(A) do { if (MB_SUCCESS != (A)) { \
+ std::cerr << "Failure (error code " << (A) << ") at " __FILE__ ":" \
+ << __LINE__ << std::endl; \
+ return A; } } while(false)
/*!
@test
@@ -2254,6 +2258,115 @@
return mb_mesh_set_appends( mb, -1 );
}
+MBErrorCode mb_mesh_set_set_replace_test( MBInterface* )
+{
+ MBCore moab;
+ MBInterface* mb = &moab;
+ MBErrorCode rval;
+ MBRange r;
+ // create 10 vertices to put in set
+ std::vector<double> coords(30);
+ rval = mb->create_vertices( &coords[0], 10, r );
+ CHKERR(rval);
+ std::vector<MBEntityHandle> verts(r.size());
+ std::copy( r.begin(), r.end(), verts.begin() );
+ r.clear();
+ // create a set
+ MBEntityHandle set;
+ rval = mb->create_meshset( MESHSET_SET, set );
+ CHKERR(rval);
+ // put every other vertex in set
+ for (size_t i = 0; i < 10; i += 2)
+ r.insert( verts[i] );
+ rval = mb->add_entities( set, r );
+ CHKERR(rval);
+ r.clear();
+ // swap 3 of the vertices
+ MBEntityHandle old_ents[3] = { verts[2], verts[4], verts[6] };
+ MBEntityHandle new_ents[3] = { verts[1], verts[9], verts[5] };
+ rval = mb->replace_entities( set, old_ents, new_ents, 3 );
+ CHKERR(rval);
+ // check new set contents
+ rval = mb->get_entities_by_handle( set, r );
+ CHKERR(rval);
+ MBRange r2;
+ r2.insert( verts[0] );
+ r2.insert( verts[1] );
+ r2.insert( verts[9] );
+ r2.insert( verts[5] );
+ r2.insert( verts[8] );
+ if (r != r2) {
+ std::cerr << "Range does not contain expected values." << std::endl
+ << " Expected: " << r2 << std::endl
+ << " Actual : " << r << std::endl;
+ return MB_FAILURE;
+ }
+
+ return MB_SUCCESS;
+}
+
+MBErrorCode mb_mesh_set_list_replace_test( MBInterface* )
+{
+ MBCore moab;
+ MBInterface* mb = &moab;
+ MBErrorCode rval;
+ // create 10 vertices to put in set
+ MBRange r;
+ std::vector<double> coords(30);
+ rval = mb->create_vertices( &coords[0], 10, r );
+ CHKERR(rval);
+ std::vector<MBEntityHandle> verts(r.size());
+ std::copy( r.begin(), r.end(), verts.begin() );
+ r.clear();
+ // create a set
+ MBEntityHandle set;
+ rval = mb->create_meshset( MESHSET_ORDERED, set );
+ CHKERR(rval);
+ // put all vertices in set, but add the first one a second time
+ std::vector<MBEntityHandle> list( verts );
+ list.push_back( verts.front() );
+ rval = mb->add_entities( set, &list[0], list.size() );
+ // swap 3 of the vertices
+ MBEntityHandle old_ents[3] = { verts[2], verts[4], verts[6] };
+ MBEntityHandle new_ents[3] = { verts[1], verts[9], verts[5] };
+ rval = mb->replace_entities( set, old_ents, new_ents, 3 );
+ CHKERR(rval);
+ // check new set contents
+ std::vector<MBEntityHandle> list2;
+ rval = mb->get_entities_by_handle( set, list2 );
+ CHKERR(rval);
+ list[2] = verts[1];
+ list[4] = verts[9];
+ list[6] = verts[5];
+ if (list != list2) {
+ std::cerr << "Range does not contain expected values." << std::endl;
+ std::cerr << " Expected: ";
+ std::copy( list.begin(), list.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+ std::cerr << std::endl << " Actual : ";
+ std::copy( list2.begin(), list2.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+ std::cerr << std::endl;
+ return MB_FAILURE;
+ }
+ // now try replacing a repeated value
+ rval = mb->replace_entities( set, &verts[0], &verts[3], 1 );
+ CHKERR(rval);
+ list[0] = list[10] = verts[3];
+ list2.clear();
+ rval = mb->get_entities_by_handle( set, list2 );
+ CHKERR(rval);
+ if (list != list2) {
+ std::cerr << "Range does not contain expected values." << std::endl;
+ std::cerr << " Expected: ";
+ std::copy( list.begin(), list.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+ std::cerr << std::endl << " Actual : ";
+ std::copy( list2.begin(), list2.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+ std::cerr << std::endl;
+ return MB_FAILURE;
+ }
+
+ return MB_SUCCESS;
+}
+
// number of entities of type MBVERTEX, MBEDGE, MBDTri, MBQUAD, MBTET, and MBHEX
// in mbtest1.g (all other values are 0.
static const unsigned int num_entities[MBMAXTYPE] = {47,12,18,8,22,8};
@@ -4350,8 +4463,8 @@
// 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->create_meshset( MESHSET_TRACK_OWNER|MESHSET_SET, set1 );
+ mb->create_meshset( MESHSET_TRACK_OWNER|MESHSET_ORDERED, set2 );
mb->add_entities( set1, verts, 4 );
mb->add_entities( set2, verts+4, 4 );
mb->add_entities( set1, &edge1, 1 );
@@ -4417,6 +4530,11 @@
std::sort( act.begin(), act.end() );
if (exp != act) {
std::cerr << "Incorrect set contents at " << __FILE__ << ":" << __LINE__ << std::endl;
+ std::cerr << " Expected: ";
+ std::copy( exp.begin(), exp.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+ std::cerr << std::endl << " Actual : ";
+ std::copy( act.begin(), act.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+ std::cerr << std::endl;
return MB_FAILURE;
}
@@ -4428,17 +4546,18 @@
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;
+ std::cerr << " Expected: ";
+ std::copy( exp.begin(), exp.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+ std::cerr << std::endl << " Actual : ";
+ std::copy( act.begin(), act.end(), std::ostream_iterator<MBEntityHandle>(std::cerr, " ") );
+ std::cerr << std::endl;
return MB_FAILURE;
}
return MB_SUCCESS;
}
-
-
MBErrorCode mb_stress_test(MBInterface *MB)
{
@@ -6380,6 +6499,8 @@
RUN_TEST( mb_mesh_set_set_appends );
RUN_TEST( mb_mesh_set_list_appends );
RUN_TEST( mb_mesh_set_root_appends );
+ RUN_TEST( mb_mesh_set_set_replace_test );
+ RUN_TEST( mb_mesh_set_list_replace_test );
RUN_TEST( mb_tags_test );
RUN_TEST( mb_dense_tag_test );
RUN_TEST( mb_sparse_tag_test );
@@ -6404,8 +6525,8 @@
RUN_TEST( mb_skin_surface_adj_test );
RUN_TEST( mb_skin_volume_test );
RUN_TEST( mb_skin_volume_adj_test );
+ RUN_TEST( mb_merge_update_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