Skip to content

Commit

Permalink
Set intersection for block check (idaholab#22563)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Feb 22, 2023
1 parent d7e150d commit 6d909cb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
28 changes: 28 additions & 0 deletions framework/include/utils/MooseUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,34 @@ get(const std::shared_ptr<T> & s)
return s.get();
}

/**
* This method detects whether two sets intersect without building a result set.
* It exits as soon as any intersection is detected.
*/
template <class InputIterator>
bool
setsIntersect(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2)
{
while (first1 != last1 && first2 != last2)
{
if (*first1 == *first2)
return true;

if (*first1 < *first2)
++first1;
else if (*first1 > *first2)
++first2;
}
return false;
}

template <class T>
bool
setsIntersect(const T & s1, const T & s2)
{
return setsIntersect(s1.begin(), s1.end(), s2.begin(), s2.end());
}

} // MooseUtils namespace

/**
Expand Down
23 changes: 0 additions & 23 deletions modules/phase_field/include/postprocessors/FeatureFloodCount.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,29 +541,6 @@ class FeatureFloodCount : public GeneralPostprocessor,
*/
void updateRegionOffsets();

/**
* This method detects whether two sets intersect without building a result set.
* It exits as soon as any intersection is detected.
*/
template <class InputIterator>
static bool setsIntersect(InputIterator first1,
InputIterator last1,
InputIterator first2,
InputIterator last2)
{
while (first1 != last1 && first2 != last2)
{
if (*first1 == *first2)
return true;

if (*first1 < *first2)
++first1;
else if (*first1 > *first2)
++first2;
}
return false;
}

/*************************************************
*************** Data Structures *****************
************************************************/
Expand Down
11 changes: 3 additions & 8 deletions modules/phase_field/src/postprocessors/FeatureFloodCount.C
Original file line number Diff line number Diff line change
Expand Up @@ -1964,24 +1964,19 @@ FeatureFloodCount::FeatureData::boundingBoxesIntersect(const FeatureData & rhs)
bool
FeatureFloodCount::FeatureData::halosIntersect(const FeatureData & rhs) const
{
return setsIntersect(
_halo_ids.begin(), _halo_ids.end(), rhs._halo_ids.begin(), rhs._halo_ids.end());
return MooseUtils::setsIntersect(_halo_ids, rhs._halo_ids);
}

bool
FeatureFloodCount::FeatureData::periodicBoundariesIntersect(const FeatureData & rhs) const
{
return setsIntersect(_periodic_nodes.begin(),
_periodic_nodes.end(),
rhs._periodic_nodes.begin(),
rhs._periodic_nodes.end());
return MooseUtils::setsIntersect(_periodic_nodes, rhs._periodic_nodes);
}

bool
FeatureFloodCount::FeatureData::ghostedIntersect(const FeatureData & rhs) const
{
return setsIntersect(
_ghosted_ids.begin(), _ghosted_ids.end(), rhs._ghosted_ids.begin(), rhs._ghosted_ids.end());
return MooseUtils::setsIntersect(_ghosted_ids, rhs._ghosted_ids);
}

bool
Expand Down

0 comments on commit 6d909cb

Please sign in to comment.