ENH: replace keyType with wordRe for matching selectors.

- The keyType is primarily used within dictionary reading, whereas
  wordRe and wordRes are used for selectors in code.
  Unifying on wordRe and wordRes reduces the number matching options.
This commit is contained in:
Mark Olesen 2021-04-08 13:42:38 +02:00 committed by Andrew Heather
parent 95cd8ee75c
commit 2b7b3700c2
28 changed files with 255 additions and 367 deletions

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -49,11 +50,13 @@ int main(int argc, char *argv[])
#include "createTime.H"
#include "createPolyMesh.H"
const wordRes patchSelection(args.getList<wordRe>(1));
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
labelList patchIDs
(
pbm.patchSet(args.getList<wordRe>(1)).sortedToc()
pbm.patchSet(patchSelection).sortedToc()
);
Info<< "Starting walk from patches "

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -495,7 +495,7 @@ int main(int argc, char *argv[])
wordRes zoneNames;
if (useCellZone)
{
List<wordRe> selectionNames = args.getList<wordRe>(1);
wordRes selectionNames(args.getList<wordRe>(1));
zoneNames.transfer(selectionNames);
Info<< "Using cellZone " << flatOutput(zoneNames) << nl << endl;

View File

@ -59,11 +59,9 @@ static inline void writeEntryIfPresent
)
{
const entry* eptr = dict.findEntry(key, keyType::LITERAL);
if (eptr)
{
const tokenList& toks = eptr->stream();
if (!toks.empty())
{
os.writeEntry(key, toks[0]);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -39,7 +39,7 @@ Description
#ifndef DynamicID_H
#define DynamicID_H
#include "keyType.H"
#include "wordRe.H"
#include "labelList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -47,11 +47,6 @@ Description
namespace Foam
{
// Forward declarations
template<class> class DynamicID;
template<class ObjectType>
Ostream& operator<<(Ostream&, const DynamicID<ObjectType>&);
/*---------------------------------------------------------------------------*\
Class DynamicID Declaration
\*---------------------------------------------------------------------------*/
@ -59,12 +54,12 @@ Ostream& operator<<(Ostream&, const DynamicID<ObjectType>&);
template<class ObjectType>
class DynamicID
{
// Private data
// Private Data
//- Zone name
keyType key_;
//- Selector name
wordRe key_;
//- Zone indices
//- Selection indices
labelList indices_;
@ -72,18 +67,36 @@ public:
// Constructors
//- Construct from name
DynamicID(const keyType& key, const ObjectType& obj)
//- Construct from selector name and object
DynamicID(const wordRe& key, const ObjectType& obj)
:
key_(key),
indices_(obj.indices(key_))
{}
//- Construct from Istream
//- Construct from selector name and object
DynamicID(wordRe&& key, const ObjectType& obj)
:
key_(std::move(key)),
indices_(obj.indices(key_))
{}
//- Construct from selector name and object
DynamicID(const word& key, const ObjectType& obj)
:
DynamicID(wordRe(key), obj)
{}
//- Construct from selector name and object
DynamicID(const keyType& key, const ObjectType& obj)
:
DynamicID(wordRe(key), obj)
{}
//- Construct from Istream and object
DynamicID(Istream& is, const ObjectType& obj)
:
key_(is),
indices_(obj.indices(key_))
DynamicID(wordRe(is), obj)
{}
@ -93,56 +106,50 @@ public:
// Member Functions
// Access
// Access
//- Return name
const keyType& name() const
{
return key_;
}
//- The selector name
const wordRe& name() const noexcept
{
return key_;
}
//- Return indices of matching zones
const labelList& indices() const
{
return indices_;
}
//- The indices of matching items
const labelList& indices() const noexcept
{
return indices_;
}
//- Return index of first matching zone
label index() const
{
return indices_.empty() ? -1 : indices_.first();
}
//- The index of the first matching items, -1 if no matches
label index() const
{
return indices_.empty() ? -1 : indices_.first();
}
//- Has the zone been found
bool active() const
{
return !indices_.empty();
}
//- Has the zone been found
bool active() const noexcept
{
return !indices_.empty();
}
// Edit
// Edit
//- Update
void update(const ObjectType& obj)
{
indices_ = obj.indices(key_);
}
// IOstream Operators
friend Ostream& operator<< <ObjectType>
(Ostream&, const DynamicID<ObjectType>&);
//- Update
void update(const ObjectType& obj)
{
indices_ = obj.indices(key_);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class ObjectType>
Ostream& operator<<(Ostream& os, const DynamicID<ObjectType>& dynId)
Ostream& operator<<(Ostream& os, const DynamicID<ObjectType>& obj)
{
os << token::BEGIN_LIST
<< dynId.name() << token::SPACE << dynId.index()
<< obj.name() << token::SPACE << obj.index()
<< token::END_LIST;
os.check(FUNCTION_NAME);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -63,11 +63,11 @@ Foam::pointBoundaryMesh::pointBoundaryMesh
Foam::labelList Foam::pointBoundaryMesh::indices
(
const keyType& key,
const wordRe& matcher,
const bool useGroups
) const
{
return mesh()().boundaryMesh().indices(key, useGroups);
return mesh()().boundaryMesh().indices(matcher, useGroups);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -94,14 +94,14 @@ public:
// Member Functions
//- Return the mesh reference
const pointMesh& mesh() const
const pointMesh& mesh() const noexcept
{
return mesh_;
}
//- Find patch indices given a name
// A no-op (returns empty list) for an empty key
labelList indices(const keyType& key, const bool useGroups) const;
labelList indices(const wordRe& matcher, const bool useGroups) const;
//- Find patch index given a name
// A no-op (returns -1) for an empty patchName
@ -118,7 +118,7 @@ public:
//- Identical to the indices() method (AUG-2018)
FOAM_DEPRECATED_FOR(2018-08, "indices() method")
labelList findIndices(const keyType& key, const bool useGroups) const
labelList findIndices(const wordRe& key, bool useGroups) const
{
return indices(key, useGroups);
}

View File

@ -604,20 +604,19 @@ Foam::labelRange Foam::polyBoundaryMesh::range(const label patchi) const
Foam::labelList Foam::polyBoundaryMesh::indices
(
const keyType& key,
const wordRe& matcher,
const bool useGroups
) const
{
if (key.empty())
if (matcher.empty())
{
return labelList();
}
DynamicList<label> patchIndices;
if (key.isPattern())
if (matcher.isPattern())
{
const regExp matcher(key);
patchIndices = PtrListOps::findMatching(*this, matcher);
// Only examine patch groups if requested and when they exist.
@ -648,7 +647,6 @@ Foam::labelList Foam::polyBoundaryMesh::indices
// Literal string.
// Special version of above for reduced memory footprint
const word& matcher = key;
const label patchId = PtrListOps::firstMatching(*this, matcher);
if (patchId >= 0)
@ -659,7 +657,7 @@ Foam::labelList Foam::polyBoundaryMesh::indices
// Only examine patch groups if requested and when they exist.
if (useGroups && !groupPatchIDs().empty())
{
const auto iter = groupPatchIDs().cfind(key);
const auto iter = groupPatchIDs().cfind(matcher);
if (iter.found())
{
@ -676,24 +674,13 @@ Foam::labelList Foam::polyBoundaryMesh::indices
}
Foam::label Foam::polyBoundaryMesh::findIndex(const keyType& key) const
Foam::label Foam::polyBoundaryMesh::findIndex(const wordRe& key) const
{
if (key.empty())
{
return -1;
}
else if (key.isPattern())
{
// Find as regex
const regExp matcher(key);
return PtrListOps::firstMatching(*this, matcher);
}
else
{
// Find as literal string
const word& matcher = key;
return PtrListOps::firstMatching(*this, matcher);
}
return PtrListOps::firstMatching(*this, key);
}

View File

@ -132,6 +132,7 @@ public:
//- Destructor
~polyBoundaryMesh() = default;
//- Clear geometry at this level and at patches
void clearGeom();
@ -142,7 +143,7 @@ public:
// Member Functions
//- Return the mesh reference
const polyMesh& mesh() const
const polyMesh& mesh() const noexcept
{
return mesh_;
}
@ -200,14 +201,14 @@ public:
// A no-op (returns empty list) for an empty key
labelList indices
(
const keyType& key,
const wordRe& matcher,
const bool useGroups = true
) const;
//- Return patch index for the first match, return -1 if not found
// A no-op (returns -1) for an empty key
label findIndex(const keyType& key) const;
label findIndex(const wordRe& key) const;
//- Find patch index given a name, return -1 if not found
// A no-op (returns -1) for an empty patchName
@ -296,7 +297,7 @@ public:
polyPatch& operator[](const word& patchName);
// Ostream operator
// Ostream Operator
friend Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
@ -305,11 +306,7 @@ public:
//- Identical to the indices() method (AUG-2018)
FOAM_DEPRECATED_FOR(2018-08, "indices() method")
labelList findIndices
(
const keyType& key,
const bool useGroups = true
) const
labelList findIndices(const wordRe& key, bool useGroups=true) const
{
return this->indices(key, useGroups);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -181,10 +181,10 @@ Foam::labelList Foam::processorCyclicPolyPatch::patchIDs
{
return bm.indices
(
keyType
wordRe
(
"procBoundary.*to.*through" + cyclicPolyPatchName,
keyType::REGEX
wordRe::REGEX
)
);
}

View File

@ -311,25 +311,14 @@ const
template<class ZoneType, class MeshType>
Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::indices
(
const keyType& key
const wordRe& matcher
) const
{
if (key.empty())
if (matcher.empty())
{
return labelList();
}
else if (key.isPattern())
{
// Match as regex
const regExp matcher(key);
return PtrListOps::findMatching(*this, matcher);
}
else
{
// Compare as literal string
const word& matcher = key;
return PtrListOps::findMatching(*this, matcher);
}
return PtrListOps::findMatching(*this, matcher);
}
@ -350,25 +339,14 @@ Foam::labelList Foam::ZoneMesh<ZoneType, MeshType>::indices
template<class ZoneType, class MeshType>
Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findIndex
(
const keyType& key
const wordRe& key
) const
{
if (key.empty())
{
return -1;
}
else if (key.isPattern())
{
// Find as regex
const regExp matcher(key);
return PtrListOps::firstMatching(*this, matcher);
}
else
{
// Find as literal string
const word& matcher = key;
return PtrListOps::firstMatching(*this, matcher);
}
return PtrListOps::firstMatching(*this, key);
}
@ -378,7 +356,11 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findIndex
const wordRes& matcher
) const
{
return (matcher.empty() ? -1 : PtrListOps::firstMatching(*this, matcher));
if (matcher.empty())
{
return -1;
}
return PtrListOps::firstMatching(*this, matcher);
}
@ -495,11 +477,11 @@ Foam::bitSet Foam::ZoneMesh<ZoneType, MeshType>::selection
template<class ZoneType, class MeshType>
Foam::bitSet Foam::ZoneMesh<ZoneType, MeshType>::selection
(
const keyType& key
const wordRe& matcher
) const
{
// key.empty() is handled by indices()
return this->selection(this->indices(key));
// matcher.empty() is handled by indices()
return this->selection(this->indices(matcher));
}

View File

@ -38,10 +38,10 @@ SourceFiles
#ifndef ZoneMesh_H
#define ZoneMesh_H
#include "List.H"
#include "regIOobject.H"
#include "pointField.H"
#include "Map.H"
#include "PtrList.H"
#include "bitSet.H"
#include "wordRes.H"
@ -51,7 +51,6 @@ namespace Foam
{
// Forward Declarations
template<class ZoneType, class MeshType> class ZoneMesh;
template<class ZoneType, class MeshType>
@ -131,7 +130,7 @@ public:
// Member Functions
//- Return the mesh reference
const MeshType& mesh() const
const MeshType& mesh() const noexcept
{
return mesh_;
}
@ -167,8 +166,8 @@ public:
//- Return zone indices for all matches
// A no-op (returns empty list) for an empty key
labelList indices(const keyType& key) const;
// A no-op (returns empty list) for an empty matcher
labelList indices(const wordRe& matcher) const;
//- Return zone indices for all matches
// A no-op (returns empty list) for an empty matcher
@ -176,7 +175,7 @@ public:
//- Zone index for the first match, return -1 if not found
// A no-op (returns -1) for an empty key
label findIndex(const keyType& key) const;
label findIndex(const wordRe& key) const;
//- Zone index for the first match, return -1 if not found
// A no-op (returns -1) for an empty matcher
@ -205,8 +204,8 @@ public:
//- specification as a bitSet.
// The bitSet is empty (zero-size) if there are no elements matched
// anywhere.
// A no-op (returns empty bitSet) for an empty key
bitSet selection(const keyType& key) const;
// A no-op (returns empty bitSet) for an empty matcher
bitSet selection(const wordRe& matcher) const;
//- Return all elements (cells, faces, points) that match the zone
//- specification as a bitSet.
@ -288,7 +287,7 @@ public:
//- Identical to the indices() method (AUG-2018)
FOAM_DEPRECATED_FOR(2018-08, "indices() method")
labelList findIndices(const keyType& key) const
labelList findIndices(const wordRes& key) const
{
return indices(key);
}

View File

@ -157,18 +157,17 @@ Foam::wordList Foam::faBoundaryMesh::types() const
Foam::labelList Foam::faBoundaryMesh::indices
(
const keyType& key,
const wordRe& matcher,
const bool useGroups // ignored
) const
{
if (key.empty())
if (matcher.empty())
{
return labelList();
}
if (key.isPattern())
if (matcher.isPattern())
{
const regExp matcher(key);
return PtrListOps::findMatching(*this, matcher);
}
else
@ -176,7 +175,6 @@ Foam::labelList Foam::faBoundaryMesh::indices
// Literal string.
// Special version of above for reduced memory footprint
const word& matcher = key;
const label patchId = PtrListOps::firstMatching(*this, matcher);
if (patchId >= 0)
@ -189,24 +187,13 @@ Foam::labelList Foam::faBoundaryMesh::indices
}
Foam::label Foam::faBoundaryMesh::findIndex(const keyType& key) const
Foam::label Foam::faBoundaryMesh::findIndex(const wordRe& key) const
{
if (key.empty())
{
return -1;
}
else if (key.isPattern())
{
// Find as regex
const regExp matcher(key);
return PtrListOps::firstMatching(*this, matcher);
}
else
{
// Find as literal string
const word& matcher = key;
return PtrListOps::firstMatching(*this, matcher);
}
return PtrListOps::firstMatching(*this, key);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -135,13 +135,13 @@ public:
// \note Matching patchGroups currently not supported
labelList indices
(
const keyType& key,
const wordRe& matcher,
const bool useGroups = false /* ignored */
) const;
//- Return patch index for the first match, return -1 if not found
// A no-op (returns -1) for an empty key
label findIndex(const keyType& key) const;
label findIndex(const wordRe& key) const;
//- Find patch index given a name, return -1 if not found
// A no-op (returns -1) for an empty name
@ -175,11 +175,7 @@ public:
//- Identical to the indices() method (AUG-2018)
FOAM_DEPRECATED_FOR(2018-08, "indices() method")
labelList findIndices
(
const keyType& key,
const bool useGroups = false
) const
labelList findIndices(const wordRe& key, bool useGroups=false) const
{
return indices(key, useGroups);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -99,7 +99,7 @@ Foam::porosityModel::porosityModel
coordinateSystem::New(mesh, coeffs_, coordinateSystem::typeName_())
)
{
if (zoneName_ == word::null)
if (zoneName_.empty())
{
dict.readIfPresent("active", active_);
dict_.readEntry("cellZone", zoneName_);

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2018 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -44,7 +45,6 @@ SourceFiles
#include "runTimeSelectionTables.H"
#include "coordinateSystem.H"
#include "dimensionedVector.H"
#include "keyType.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -70,7 +70,7 @@ class porosityModel
protected:
// Protected data
// Protected Data
//- Porosity name
word name_;
@ -88,7 +88,7 @@ protected:
bool active_;
//- Name(s) of cell-zone
keyType zoneName_;
wordRe zoneName_;
//- Cell zone IDs
labelList cellZoneIDs_;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -75,11 +75,11 @@ Foam::fvBoundaryMesh::fvBoundaryMesh
Foam::labelList Foam::fvBoundaryMesh::indices
(
const keyType& key,
const wordRe& matcher,
const bool useGroups
) const
{
return mesh().boundaryMesh().indices(key, useGroups);
return mesh().boundaryMesh().indices(matcher, useGroups);
}

View File

@ -110,8 +110,8 @@ public:
lduInterfacePtrsList interfaces() const;
//- Return patch indices for all matches.
// A no-op (returns empty list) for an empty key
labelList indices(const keyType& key, const bool useGroups) const;
// A no-op (returns empty list) for an empty matcher
labelList indices(const wordRe& matcher, const bool useGroups) const;
//- Find patch index given a name
// A no-op (returns -1) for an empty patchName
@ -137,7 +137,7 @@ public:
//- Identical to the indices() method (AUG-2018)
FOAM_DEPRECATED_FOR(2018-08, "indices() method")
labelList findIndices(const keyType& key, const bool useGroups) const
labelList findIndices(const wordRe& key, bool useGroups) const
{
return indices(key, useGroups);
}

View File

@ -278,7 +278,7 @@ void Foam::functionObjects::externalCoupled::writeGeometry
(
mesh.boundaryMesh().patchSet
(
List<wordRe>{groupName}
wordRes(one{}, groupName)
).sortedToc()
);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -80,7 +80,10 @@ bool Foam::functionObjects::externalCoupled::readData
}
const wordRes patchSelection(one{}, groupName);
label nFound = 0;
for (const fvMesh& mesh : meshes)
{
const volFieldType* vfptr = mesh.findObject<volFieldType>(fieldName);
@ -89,7 +92,7 @@ bool Foam::functionObjects::externalCoupled::readData
{
continue;
}
nFound++;
++nFound;
typename volFieldType::Boundary& bf =
const_cast<volFieldType*>(vfptr)->boundaryFieldRef();
@ -97,10 +100,7 @@ bool Foam::functionObjects::externalCoupled::readData
// Get the patches
const labelList patchIDs
(
mesh.boundaryMesh().patchSet
(
List<wordRe>{groupName}
).sortedToc()
mesh.boundaryMesh().patchSet(patchSelection).sortedToc()
);
// Handle column-wise reading of patch data. Supports most easy types
@ -261,7 +261,7 @@ bool Foam::functionObjects::externalCoupled::readData
}
}
return nFound > 0;
return nFound;
}
@ -352,8 +352,9 @@ bool Foam::functionObjects::externalCoupled::writeData
}
bool headerDone = false;
const wordRes patchSelection(one{}, groupName);
bool headerDone = false;
label nFound = 0;
for (const fvMesh& mesh : meshes)
@ -364,7 +365,7 @@ bool Foam::functionObjects::externalCoupled::writeData
{
continue;
}
nFound++;
++nFound;
const typename volFieldType::Boundary& bf =
vfptr->boundaryField();
@ -372,10 +373,7 @@ bool Foam::functionObjects::externalCoupled::writeData
// Get the patches
const labelList patchIDs
(
mesh.boundaryMesh().patchSet
(
List<wordRe>{groupName}
).sortedToc()
mesh.boundaryMesh().patchSet(patchSelection).sortedToc()
);
// Handle column-wise writing of patch data. Supports most easy types
@ -474,7 +472,7 @@ bool Foam::functionObjects::externalCoupled::writeData
}
}
return nFound > 0;
return nFound;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -67,15 +67,7 @@ Foam::label Foam::ParticleErosion<CloudType>::applyToPatch
const label globalPatchi
) const
{
forAll(patchIDs_, i)
{
if (patchIDs_[i] == globalPatchi)
{
return i;
}
}
return -1;
return patchIDs_.find(globalPatchi);
}
@ -120,7 +112,7 @@ Foam::ParticleErosion<CloudType>::ParticleErosion
labelHashSet uniqIds;
for (const wordRe& re : patchNames)
{
labelList ids = findStrings(re, allPatchNames);
labelList ids = findMatchingStrings(re, allPatchNames);
if (ids.empty())
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -34,39 +34,13 @@ License
Foam::patchInteractionData::patchInteractionData()
:
interactionTypeName_("unknownInteractionTypeName"),
patchName_("unknownPatch"),
e_(0.0),
mu_(0.0)
interactionTypeName_(),
patchName_(),
e_(0),
mu_(0)
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::word& Foam::patchInteractionData::interactionTypeName() const
{
return interactionTypeName_;
}
const Foam::keyType& Foam::patchInteractionData::patchName() const
{
return patchName_;
}
Foam::scalar Foam::patchInteractionData::e() const
{
return e_;
}
Foam::scalar Foam::patchInteractionData::mu() const
{
return mu_;
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -34,36 +35,31 @@ Description
#ifndef patchInteractionData_H
#define patchInteractionData_H
#include "Istream.H"
#include "wordRe.H"
#include "scalar.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward Declaration
class patchInteractionData;
Istream& operator>>(Istream& is, patchInteractionData& pid);
/*---------------------------------------------------------------------------*\
Class patchInteractionData Declaration
\*---------------------------------------------------------------------------*/
// Forward declaration of classes
class patchInteractionData;
// Forward declaration of friend functions
Istream& operator>>
(
Istream& is,
patchInteractionData& pid
);
class patchInteractionData
{
// Private data
// Private Data
//- Interaction type name
word interactionTypeName_;
//- Patch name
keyType patchName_;
//- Patch name(s)
wordRe patchName_;
//- Elasticity coefficient
scalar e_;
@ -76,35 +72,41 @@ public:
// Constructor
//- Construct null
//- Default construct
patchInteractionData();
// Member functions
// Member Functions
// Access
//- The interaction type name
const word& interactionTypeName() const noexcept
{
return interactionTypeName_;
}
//- Return const access to the interaction type name
const word& interactionTypeName() const;
//- The patch name(s)
const wordRe& patchName() const noexcept
{
return patchName_;
}
//- Return const access to the patch name
const keyType& patchName() const;
//- The elasticity coefficient
scalar e() const noexcept
{
return e_;
}
//- Return const access to the elasticity coefficient
scalar e() const;
//- Return const access to the restitution coefficient
scalar mu() const;
//- The restitution coefficient
scalar mu() const noexcept
{
return mu_;
}
// I-O
// IO Operators
//- Istream operator
friend Istream& operator>>
(
Istream& is,
patchInteractionData& pid
);
//- Istream operator
friend Istream& operator>>(Istream& is, patchInteractionData& pid);
};

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -50,14 +51,14 @@ Foam::patchInteractionDataList::patchInteractionDataList
const List<patchInteractionData>& items = *this;
forAllReverse(items, i)
{
const keyType& patchName = items[i].patchName();
const wordRe& patchName = items[i].patchName();
labelList ids = bMesh.indices(patchName);
if (ids.empty())
{
WarningInFunction
<< "Cannot find any patch names matching " << patchName
<< endl;
<< "Cannot find any patch names matching "
<< patchName << endl;
}
patchGroupIDs_[i].transfer(ids);
@ -65,9 +66,8 @@ Foam::patchInteractionDataList::patchInteractionDataList
// Check that all patches are specified
DynamicList<word> badPatches;
forAll(bMesh, patchi)
for (const polyPatch& pp : bMesh)
{
const polyPatch& pp = bMesh[patchi];
if
(
!pp.coupled()
@ -79,12 +79,13 @@ Foam::patchInteractionDataList::patchInteractionDataList
}
}
if (badPatches.size() > 0)
if (!badPatches.empty())
{
FatalErrorInFunction
<< "All patches must be specified when employing local patch "
<< "interaction. Please specify data for patches:" << nl
<< badPatches << nl << exit(FatalError);
<< badPatches << nl
<< exit(FatalError);
}
}
@ -103,15 +104,11 @@ Foam::patchInteractionDataList::patchInteractionDataList
Foam::label Foam::patchInteractionDataList::applyToPatch(const label id) const
{
forAll(patchGroupIDs_, groupI)
forAll(patchGroupIDs_, groupi)
{
const labelList& patchIDs = patchGroupIDs_[groupI];
forAll(patchIDs, patchi)
if (patchGroupIDs_[groupi].found(id))
{
if (patchIDs[patchi] == id)
{
return groupI;
}
return groupi;
}
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,6 +28,29 @@ License
#include "blockMeshTools.H"
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
static inline const Foam::entry* resolveLabel(const entry& e, const label val)
{
if (e.isStream())
{
const tokenList& toks = e.stream();
if (!toks.empty() && toks[0].isLabel(val))
{
return &e;
}
}
return nullptr;
}
} // End namespace Foam
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::blockMeshTools::read
@ -93,21 +117,18 @@ void Foam::blockMeshTools::write
{
for (const entry& e : dict)
{
if (e.isStream())
const entry* eptr = resolveLabel(e, val);
if (eptr)
{
label keyVal(Foam::readLabel(e.stream()));
if (keyVal == val)
{
os << e.keyword();
return;
}
os << eptr->keyword();
return;
}
}
os << val;
}
const Foam::keyType& Foam::blockMeshTools::findEntry
const Foam::entry* Foam::blockMeshTools::findEntry
(
const dictionary& dict,
const label val
@ -115,17 +136,14 @@ const Foam::keyType& Foam::blockMeshTools::findEntry
{
for (const entry& e : dict)
{
if (e.isStream())
const entry* eptr = resolveLabel(e, val);
if (eptr)
{
label keyVal(Foam::readLabel(e.stream()));
if (keyVal == val)
{
return e.keyword();
}
return eptr;
}
}
return keyType::null;
return nullptr;
}

View File

@ -50,11 +50,11 @@ namespace blockMeshTools
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- In-place read with dictionary lookup
void read(Istream&, label&, const dictionary&);
void read(Istream&, label& val, const dictionary&);
//- In-place read with dictionary lookup
template<class T>
void read(Istream&, List<T>&, const dictionary&);
void read(Istream&, List<T>& list, const dictionary&);
//- Return-read with dictionary lookup
label read(Istream&, const dictionary&);
@ -64,10 +64,10 @@ namespace blockMeshTools
List<T> read(Istream& is, const dictionary&);
//- Write with dictionary lookup
void write(Ostream&, const label, const dictionary&);
void write(Ostream&, const label val, const dictionary&);
//- Linear search for label entry
const keyType& findEntry(const dictionary&, const label);
//- Linear search for labelled entry, nullptr if not found
const entry* findEntry(const dictionary& dict, const label val);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -532,7 +532,7 @@ Foam::layerParameters::layerParameters
const labelHashSet patchIDs
(
boundaryMesh.patchSet(List<wordRe>(1, wordRe(key)))
boundaryMesh.patchSet(wordRes(one{}, wordRe(key)))
);
if (patchIDs.size() == 0)

View File

@ -179,24 +179,13 @@ const Foam::coordinateSystems& Foam::coordinateSystems::New
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::labelList Foam::coordinateSystems::indices(const keyType& key) const
Foam::labelList Foam::coordinateSystems::indices(const wordRe& key) const
{
if (key.empty())
{
return labelList();
}
else if (key.isPattern())
{
// Match as regex
const regExp matcher(key);
return PtrListOps::findMatching(*this, matcher);
}
else
{
// Compare as literal string
const word& matcher = key;
return PtrListOps::findMatching(*this, matcher);
}
return PtrListOps::findMatching(*this, key);
}
@ -210,24 +199,13 @@ Foam::labelList Foam::coordinateSystems::indices(const wordRes& matcher) const
}
Foam::label Foam::coordinateSystems::findIndex(const keyType& key) const
Foam::label Foam::coordinateSystems::findIndex(const wordRe& key) const
{
if (key.empty())
{
return -1;
}
else if (key.isPattern())
{
// Find as regex
const regExp matcher(key);
return PtrListOps::firstMatching(*this, matcher);
}
else
{
// Find as literal string
const word& matcher = key;
return PtrListOps::firstMatching(*this, matcher);
}
return PtrListOps::firstMatching(*this, key);
}
@ -241,7 +219,7 @@ Foam::label Foam::coordinateSystems::findIndex(const wordRes& matcher) const
}
bool Foam::coordinateSystems::found(const keyType& key) const
bool Foam::coordinateSystems::found(const wordRe& key) const
{
return findIndex(key) != -1;
}
@ -250,13 +228,16 @@ bool Foam::coordinateSystems::found(const keyType& key) const
const Foam::coordinateSystem*
Foam::coordinateSystems::cfind(const word& name) const
{
const label index = this->findIndex(name);
const label index =
(
name.empty() ? -1 : PtrListOps::firstMatching(*this, name)
);
if (coordinateSystem::debug)
{
InfoInFunction
<< "Global coordinate system: "
<< name << "=" << index << endl;
<< name << '=' << index << endl;
}
if (index < 0)
@ -271,9 +252,9 @@ Foam::coordinateSystems::cfind(const word& name) const
const Foam::coordinateSystem&
Foam::coordinateSystems::lookup(const word& name) const
{
const label index = this->findIndex(name);
const coordinateSystem* ptr = this->cfind(name);
if (index < 0)
if (!ptr)
{
FatalErrorInFunction
<< "Could not find coordinate system: " << name << nl
@ -281,14 +262,8 @@ Foam::coordinateSystems::lookup(const word& name) const
<< flatOutput(names()) << nl << nl
<< exit(FatalError);
}
if (coordinateSystem::debug)
{
InfoInFunction
<< "Global coordinate system: "
<< name << "=" << index << endl;
}
return this->operator[](index);
return *ptr;
}
@ -298,34 +273,13 @@ Foam::wordList Foam::coordinateSystems::names() const
}
Foam::wordList Foam::coordinateSystems::names(const keyType& key) const
Foam::wordList Foam::coordinateSystems::names(const wordRe& key) const
{
if (key.empty())
{
return wordList();
}
else if (key.isPattern())
{
// Find as regex
const regExp matcher(key);
return PtrListOps::names(*this, matcher);
}
else
{
// Find as literal string
const word& matcher = key;
return PtrListOps::names(*this, matcher);
}
}
Foam::wordList Foam::coordinateSystems::names(const wordRe& matcher) const
{
if (matcher.empty())
{
return wordList();
}
return PtrListOps::names(*this, matcher);
return PtrListOps::names(*this, key);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -134,7 +134,7 @@ public:
//- Find and return indices for all matches
// A no-op (returns empty list) for an empty key
labelList indices(const keyType& key) const;
labelList indices(const wordRe& key) const;
//- Find and return indices for all matches
// A no-op (returns empty list) for an empty matcher
@ -142,14 +142,14 @@ public:
//- Find and return index for the first match, return -1 if not found
// A no-op (returns -1) for an empty key
label findIndex(const keyType& key) const;
label findIndex(const wordRe& key) const;
//- Find and return index for the first match, return -1 if not found
// A no-op (returns -1) for an empty matcher
label findIndex(const wordRes& matcher) const;
//- Search if given key exists
bool found(const keyType& key) const;
bool found(const wordRe& key) const;
//- Return pointer to named coordinateSystem or nullptr on error
const coordinateSystem* cfind(const word& name) const;
@ -161,10 +161,7 @@ public:
wordList names() const;
//- A list of the coordinate-system names satisfying the input matcher
wordList names(const keyType& key) const;
//- A list of the coordinate-system names satisfying the input matcher
wordList names(const wordRe& matcher) const;
wordList names(const wordRe& key) const;
//- A list of the coordinate-system names satisfying the input matcher
wordList names(const wordRes& matcher) const;
@ -193,7 +190,7 @@ public:
//- Identical to the indices() method (AUG-2018)
FOAM_DEPRECATED_FOR(2018-08, "indices() method")
labelList findIndices(const keyType& key) const
labelList findIndices(const wordRe& key) const
{
return this->indices(key);
}