[MOAB-dev] r1505 - MOAB/trunk
tautges at mcs.anl.gov
tautges at mcs.anl.gov
Thu Jan 3 15:04:35 CST 2008
Author: tautges
Date: 2008-01-03 15:04:34 -0600 (Thu, 03 Jan 2008)
New Revision: 1505
Modified:
MOAB/trunk/MBRange.cpp
MOAB/trunk/Tqdcfr.cpp
Log:
Implementing subrange-based subtract in MBRange. Reduces runtime for one of my mesh-loading tests by 65% or so. Also, in Tqdcfr, waiting to add entities to file set until very end (cacheing extant entities at start of load then subtracting those from total at end). This reduces runtime by about 5% for that same example.
Modified: MOAB/trunk/MBRange.cpp
===================================================================
--- MOAB/trunk/MBRange.cpp 2008-01-03 00:13:56 UTC (rev 1504)
+++ MOAB/trunk/MBRange.cpp 2008-01-03 21:04:34 UTC (rev 1505)
@@ -609,12 +609,61 @@
MBRange MBRange::subtract(const MBRange &range2) const
{
- // brain-dead implementation right now
- MBRange res = *this;
- for (MBRange::const_iterator rit = range2.begin(); rit != range2.end(); rit++)
- res.erase(*rit);
+ const bool braindead = false;
+
+ if (braindead) {
+ // brain-dead implementation right now
+ MBRange res = *this;
+ for (MBRange::const_iterator rit = range2.begin(); rit != range2.end(); rit++)
+ res.erase(*rit);
- return res;
+ return res;
+ }
+ else {
+ MBRange lhs = *this;
+
+ pair_iterator r_it[2] = {pair_iterator(lhs.begin()),
+ pair_iterator(range2.begin())};
+
+ // terminate the while loop when at least one "start" iterator is at the
+ // end of the list
+ while (r_it[0] != lhs.end() && r_it[1] != range2.end()) {
+ // case a: pair wholly within subtracted pair
+ if (r_it[0]->first >= r_it[1]->first && r_it[0]->second <= r_it[1]->second) {
+ PairNode *rtmp = r_it[0].mNode;
+ r_it[0]++;
+ lhs.delete_pair_node(rtmp);
+ }
+ // case b: pair overlaps upper part of subtracted pair
+ else if (r_it[0]->first <= r_it[1]->second &&
+ r_it[0]->first >= r_it[1]->first) {
+ r_it[0]->first = r_it[1]->second + 1;
+ r_it[1]++;
+ }
+ // case c: pair overlaps lower part of subtracted pair
+ else if (r_it[0]->second >= r_it[1]->first &&
+ r_it[0]->second <= r_it[1]->second) {
+ r_it[0]->second = r_it[1]->first - 1;
+ r_it[0]++;
+ }
+ // case d: pair completely surrounds subtracted pair
+ else if (r_it[0]->first < r_it[1]->first &&
+ r_it[0]->second > r_it[1]->second) {
+ PairNode* new_node = alloc_pair(r_it[0].mNode, r_it[0].mNode->mPrev,
+ r_it[0]->first, r_it[1]->first - 1);
+ new_node->mPrev->mNext = new_node->mNext->mPrev = new_node;
+ r_it[0].mNode->first = r_it[1]->second+1;
+ r_it[1]++;
+ }
+ else {
+ while (r_it[0]->second < r_it[1]->first && r_it[0] != lhs.end()) r_it[0]++;
+ if (r_it[0] == lhs.end()) break;
+ while (r_it[1]->second < r_it[0]->first && r_it[1] != range2.end()) r_it[1]++;
+ }
+ }
+
+ return lhs;
+ }
}
MBRange::const_iterator MBRange::lower_bound(MBRange::const_iterator first,
Modified: MOAB/trunk/Tqdcfr.cpp
===================================================================
--- MOAB/trunk/Tqdcfr.cpp 2008-01-03 00:13:56 UTC (rev 1504)
+++ MOAB/trunk/Tqdcfr.cpp 2008-01-03 21:04:34 UTC (rev 1505)
@@ -183,6 +183,12 @@
return result;
mFileSet = file_set;
+ // get "before" entities
+ MBRange before_ents;
+ result = mdbImpl->get_entities_by_handle(0, before_ents);
+ if (MB_SUCCESS != result)
+ return result;
+
// ***********************
// read model header type information...
// ***********************
@@ -305,6 +311,14 @@
// convert blocks to nodesets/sidesets if tag is set
result = convert_nodesets_sidesets();
+ MBRange after_ents;
+ result = mdbImpl->get_entities_by_handle(0, after_ents);
+ if (MB_SUCCESS != result)
+ return result;
+
+ after_ents = after_ents.subtract(before_ents);
+ result = mdbImpl->add_entities(mFileSet, after_ents);
+
return result;
}
@@ -929,8 +943,6 @@
node_handle+entity->nodeCt-1);
MBErrorCode result = mdbImpl->add_entities(entity->setHandle, dum_range);
if (MB_SUCCESS != result) return result;
- result = mdbImpl->add_entities( mFileSet, dum_range );
- if (MB_SUCCESS != result) return result;
// set global ids on nodes
result = mdbImpl->tag_set_data(globalIdTag, dum_range, &int_buf[0]);
@@ -1128,8 +1140,6 @@
MBRange dum_range(start_handle, start_handle+num_elem-1);
result = mdbImpl->add_entities(entity->setHandle, dum_range);
if (MB_SUCCESS != result) return result;
- result = mdbImpl->add_entities(mFileSet, dum_range);
- if (MB_SUCCESS != result) return result;
// set global ids
result = mdbImpl->tag_set_data(globalIdTag, dum_range, &int_buf[0]);
@@ -2408,11 +2418,6 @@
if (!mFileSet)
return MB_FAILURE;
rval = mdbImpl->create_meshset( flags, h );
- if (MB_SUCCESS != rval)
- return rval;
- rval = mdbImpl->add_entities( mFileSet, &h, 1 );
- if (MB_SUCCESS != rval)
- mdbImpl->delete_entities( &h, 1 );
return rval;
}
More information about the moab-dev
mailing list