ENH: polyMesh: added patchGroup handling

This commit is contained in:
mattijs 2013-11-06 16:58:22 +00:00
parent ea064d9cb0
commit 967c9e3ecf
4 changed files with 65 additions and 2 deletions

View File

@ -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())

View File

@ -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;

View File

@ -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;

View File

@ -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