From 967c9e3ecfe21dcb5a23a63198e3d1815d7c7fe2 Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Wed, 6 Nov 2013 16:58:22 +0000 Subject: [PATCH] ENH: polyMesh: added patchGroup handling --- .../Identifiers/patch/patchIdentifier.C | 9 +++- .../Identifiers/patch/patchIdentifier.H | 4 +- .../polyBoundaryMesh/polyBoundaryMesh.C | 51 +++++++++++++++++++ .../polyBoundaryMesh/polyBoundaryMesh.H | 3 ++ 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.C b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.C index 61379861657..b69ffae4f4c 100644 --- a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.C +++ b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.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-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,6 +25,7 @@ License #include "patchIdentifier.H" #include "dictionary.H" +#include "ListOps.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -79,6 +80,12 @@ Foam::patchIdentifier::~patchIdentifier() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +bool Foam::patchIdentifier::inGroup(const word& name) const +{ + return findIndex(inGroups_, name) != -1; +} + + void Foam::patchIdentifier::write(Ostream& os) const { if (physicalType_.size()) diff --git a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H index cb7d60b7b5b..e54d2767330 100644 --- a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H +++ b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.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-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -154,6 +154,8 @@ public: return inGroups_; } + //- Test if in group + bool inGroup(const word&) const; //- Write patchIdentifier as a dictionary void write(Ostream&) const; diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index a1935d03684..1e104b4602e 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -486,6 +486,57 @@ Foam::polyBoundaryMesh::groupPatchIDs() const } +void Foam::polyBoundaryMesh::setGroup +( + const word& groupName, + const labelList& patchIDs +) +{ + groupPatchIDsPtr_.clear(); + + polyPatchList& patches = *this; + + boolList donePatch(patches.size(), false); + + // Add to specified patches + forAll(patchIDs, i) + { + label patchI = patchIDs[i]; + polyPatch& pp = patches[patchI]; + + if (!pp.inGroup(groupName)) + { + pp.inGroups().append(groupName); + } + donePatch[patchI] = true; + } + + // Remove from other patches + forAll(patches, patchI) + { + if (!donePatch[patchI]) + { + polyPatch& pp = patches[patchI]; + + label newI = 0; + if (pp.inGroup(groupName)) + { + wordList& groups = pp.inGroups(); + + forAll(groups, i) + { + if (groups[i] != groupName) + { + groups[newI++] = groups[i]; + } + } + groups.setSize(newI); + } + } + } +} + + Foam::wordList Foam::polyBoundaryMesh::names() const { const polyPatchList& patches = *this; diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H index 3878c80b366..1906b422ac5 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H @@ -186,6 +186,9 @@ public: //- Per patch group the patch indices const HashTable<labelList, word>& groupPatchIDs() const; + //- Set/add group with patches + void setGroup(const word& groupName, const labelList& patchIDs); + //- Return the set of patch IDs corresponding to the given names // By default warns if given names are not found. Optionally // matches to patchGroups as well as patchNames -- GitLab