openfoam/applications/utilities/preProcessing/createZeroDirectory/boundaryInfo.C
Mark Olesen a8d2ebf298 ENH: cleanup wordRe interfaces etc.
- ensure that the string-related classes have consistently similar
  matching methods. Use operator()(const std::string) as an entry
  point for the match() method, which makes it easier to use for
  filters and predicates. In some cases this will also permit using
  a HashSet as a match predicate.

regExp
====
- the set method now returns a bool to signal that the requested
  pattern was compiled.

wordRe
====
- have separate constructors with the compilation option (was previously
  a default parameter). This leaves the single parameter constructor
  explicit, but the two parameter version is now non-explicit, which
  makes it easier to use when building lists.

- renamed compile-option from REGEX (to REGEXP) for consistency with
  with the <regex.h>, <regex> header names etc.

wordRes
====
- renamed from wordReListMatcher -> wordRes. For reduced typing and
  since it behaves as an entity only slightly related to its underlying
  list nature.

- Provide old name as typedef and include for code transition.

- pass through some list methods into wordRes

hashedWordList
====
- hashedWordList[const word& name] now returns a -1 if the name is is
  not found in the list of indices. That has been a pending change
  ever since hashedWordList was generalized out of speciesTable
  (Oct-2010).

- add operator()(const word& name) for easy use as a predicate

STYLE: adjust parameter names in stringListOps

- reflect if the parameter is being used as a primary matcher, or the
  matcher will be derived from the parameter.
  For example,
      (const char* re), which first creates a regExp
      versus (const regExp& matcher) which is used directly.
2017-05-16 23:54:43 +02:00

199 lines
5.0 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "boundaryInfo.H"
#include "Time.H"
#include "polyMesh.H"
#include "processorPolyPatch.H"
using namespace Foam;
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTemplateTypeNameAndDebug(IOPtrList<entry>, 0);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::IOPtrList<Foam::entry> Foam::boundaryInfo::readBoundaryDict
(
const Time& runTime,
const word& regionName
) const
{
Info<< " Reading mesh boundaries" << endl;
const_cast<word&>(IOPtrList<entry>::typeName) = polyBoundaryMesh::typeName;
IOPtrList<entry> boundaryPatchList
(
IOobject
(
"boundary",
runTime.findInstance(regionName/polyMesh::meshSubDir, "boundary"),
regionName/polyMesh::meshSubDir,
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
// remove zero-sized patches
PtrList<entry> boundaryPatchListNew;
forAll(boundaryPatchList, patchI)
{
const dictionary& dict = boundaryPatchList[patchI].dict();
const word pType = dict.lookup("type");
bool procPatch = pType == processorPolyPatch::typeName;
bool addPatch = true;
if (!procPatch)
{
label nFaces = readLabel(dict.lookup("nFaces"));
reduce(nFaces, sumOp<label>());
if (nFaces == 0)
{
addPatch = false;
}
}
if (addPatch)
{
boundaryPatchListNew.append(boundaryPatchList[patchI].clone());
}
}
boundaryPatchList.transfer(boundaryPatchListNew);
return boundaryPatchList;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::boundaryInfo::boundaryInfo(const Time& runTime, const word& regionName)
:
boundaryDict_(readBoundaryDict(runTime, regionName)),
names_(),
types_(),
constraint_(),
groups_(),
allGroupNames_()
{
names_.setSize(boundaryDict_.size());
types_.setSize(boundaryDict_.size());
constraint_.setSize(boundaryDict_.size(), false);
groups_.setSize(boundaryDict_.size());
forAll(boundaryDict_, patchI)
{
const dictionary& dict = boundaryDict_[patchI].dict();
names_[patchI] = dict.dictName();
dict.lookup("type") >> types_[patchI];
if (polyPatch::constraintType(types_[patchI]))
{
constraint_[patchI] = true;
}
if (dict.found("inGroups"))
{
dict.lookup("inGroups") >> groups_[patchI];
allGroupNames_.insert(groups_[patchI]);
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::wordList& Foam::boundaryInfo::names() const
{
return names_;
}
const Foam::wordList& Foam::boundaryInfo::types() const
{
return types_;
}
const Foam::boolList& Foam::boundaryInfo::constraint() const
{
return constraint_;
}
const Foam::List<Foam::wordList>& Foam::boundaryInfo::groups() const
{
return groups_;
}
const Foam::wordHashSet& Foam::boundaryInfo::allGroupNames() const
{
return allGroupNames_;
}
void Foam::boundaryInfo::setType(const label patchI, const word& condition)
{
if (constraint_[patchI])
{
// not overriding constraint types
return;
}
if (regExp(".*[Mm]apped.*").match(types_[patchI]))
{
// ugly hack to avoid overriding mapped types
return;
}
if (condition == "wall")
{
types_[patchI] = condition;
}
else
{
types_[patchI] = "patch";
}
dictionary& patchDict = boundaryDict_[patchI].dict();
patchDict.add("type", types_[patchI], true);
}
void Foam::boundaryInfo::write() const
{
boundaryDict_.write();
}
// ************************************************************************* //