From 6e68e105ca13e2aeb5c8c03a595ecf0b8121fcd7 Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Wed, 27 Jun 2012 13:03:50 +0100 Subject: [PATCH] ENH: polyBoundaryMesh: matches patches to patchgroups --- .../miscellaneous/patchSummary/patchSummary.C | 82 ++++--------------- .../polyBoundaryMesh/polyBoundaryMesh.C | 48 ++++++++++- .../polyBoundaryMesh/polyBoundaryMesh.H | 11 ++- 3 files changed, 73 insertions(+), 68 deletions(-) diff --git a/applications/utilities/miscellaneous/patchSummary/patchSummary.C b/applications/utilities/miscellaneous/patchSummary/patchSummary.C index 51d59163f20..d23acc6a691 100644 --- a/applications/utilities/miscellaneous/patchSummary/patchSummary.C +++ b/applications/utilities/miscellaneous/patchSummary/patchSummary.C @@ -42,60 +42,6 @@ Description // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// Return names of groups and patches. If multiple groups the first one wins. -wordHashSet matchGroupOrPatch -( - const polyBoundaryMesh& bm, - const labelList& patchIDs -) -{ - // Current matched groups - wordHashSet matchedGroups; - - // Current set of unmatched patches - labelHashSet nonGroupPatches(patchIDs); - - const HashTable<labelList, word>& groupPatchIDs = - bm.groupPatchIDs(); - for - ( - HashTable<labelList,word>::const_iterator iter = - groupPatchIDs.begin(); - iter != groupPatchIDs.end(); - ++iter - ) - { - // Store currently unmatched patches - labelHashSet oldNonGroupPatches(nonGroupPatches); - - // Match by deleting patches in group from the current set and seeing - // if all have been deleted. - labelHashSet groupPatchSet(iter()); - - label nMatch = nonGroupPatches.erase(groupPatchSet); - - if (nMatch == groupPatchSet.size()) - { - matchedGroups.insert(iter.key()); - } - else - { - // No full match. Undo. - nonGroupPatches.transfer(oldNonGroupPatches); - } - } - - // Add remaining patches - forAllConstIter(labelHashSet, nonGroupPatches, iter) - { - matchedGroups.insert(bm[iter.key()].name()); - } - - return matchedGroups; -} - - - int main(int argc, char *argv[]) { timeSelector::addOptions(); @@ -172,7 +118,7 @@ int main(int argc, char *argv[]) forAll(bm, patchI) { - Info<< bm[patchI].type() << ": " << bm[patchI].name() << nl; + Info<< bm[patchI].type() << "\t: " << bm[patchI].name() << nl; outputFieldList<scalar>(vsf, patchI); outputFieldList<vector>(vvf, patchI); outputFieldList<sphericalTensor>(vsptf, patchI); @@ -221,19 +167,23 @@ int main(int argc, char *argv[]) if (patchIDs.size() > 1) { // Check if part of a group - wordList patchOrGroup - ( - matchGroupOrPatch(bm, patchIDs).sortedToc() - ); - - //Info<< patchOrGroup << endl; - Info<< patchOrGroup[0]; - for (label i = 1; i < patchOrGroup.size(); i++) + wordList groups; + labelHashSet nonGroupPatches; + bm.matchGroups(patchIDs, groups, nonGroupPatches); + + const labelList sortedPatches(nonGroupPatches.sortedToc()); + forAll(sortedPatches, i) { - Info<< ' ' << patchOrGroup[i]; + Info<< bm[sortedPatches[i]].type() + << "\t: " << bm[sortedPatches[i]].name() << nl; + } + if (groups.size()) + { + forAll(groups, i) + { + Info<< "group\t: " << groups[i] << nl; + } } - Info<< endl; - outputFieldList<scalar>(vsf, patchIDs[0]); outputFieldList<vector>(vvf, patchIDs[0]); outputFieldList<sphericalTensor>(vsptf, patchIDs[0]); diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index d5670fa3314..a54438f1051 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -792,6 +792,52 @@ Foam::labelHashSet Foam::polyBoundaryMesh::patchSet } +void Foam::polyBoundaryMesh::matchGroups +( + const labelUList& patchIDs, + wordList& groups, + labelHashSet& nonGroupPatches +) const +{ + // Current matched groups + DynamicList<word> matchedGroups(1); + + // Current set of unmatched patches + nonGroupPatches = labelHashSet(patchIDs); + + const HashTable<labelList, word>& groupPatchIDs = this->groupPatchIDs(); + for + ( + HashTable<labelList,word>::const_iterator iter = + groupPatchIDs.begin(); + iter != groupPatchIDs.end(); + ++iter + ) + { + // Store currently unmatched patches so we can restore + labelHashSet oldNonGroupPatches(nonGroupPatches); + + // Match by deleting patches in group from the current set and seeing + // if all have been deleted. + labelHashSet groupPatchSet(iter()); + + label nMatch = nonGroupPatches.erase(groupPatchSet); + + if (nMatch == groupPatchSet.size()) + { + matchedGroups.append(iter.key()); + } + else if (nMatch != 0) + { + // No full match. Undo. + nonGroupPatches.transfer(oldNonGroupPatches); + } + } + + groups.transfer(matchedGroups); +} + + bool Foam::polyBoundaryMesh::checkParallelSync(const bool report) const { if (!Pstream::parRun()) diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H index 999b3815bf5..34f0a6d409b 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -195,6 +195,15 @@ public: const bool usePatchGroups = true ) const; + //- Match the patches to groups. Returns all the (fully matched) groups + // and any remaining unmatched patches. + void matchGroups + ( + const labelUList& patchIDs, + wordList& groups, + labelHashSet& nonGroupPatches + ) const; + //- Check whether all procs have all patches and in same order. Return // true if in error. bool checkParallelSync(const bool report = false) const; -- GitLab