ENH: more explicit about handling empty matchers for index lookup

- for boundary meshes, zones etc. The behaviour with an empty matcher
  was either not properly documented, and looped through all
  names just to establish there was no match.

STYLE: removed redundant typedefs for point fields
This commit is contained in:
Mark Olesen
2020-12-07 11:46:28 +01:00
parent df74e8448c
commit 0b68f14f7d
18 changed files with 89 additions and 43 deletions

View File

@ -43,25 +43,6 @@ SourceFiles
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef GeometricField<scalar, pointPatchField, pointMesh> pointScalarField;
typedef GeometricField<vector, pointPatchField, pointMesh> pointVectorField;
typedef GeometricField<sphericalTensor, pointPatchField, pointMesh>
pointSphericalTensorField;
typedef GeometricField<symmTensor, pointPatchField, pointMesh>
pointSymmTensorField;
typedef GeometricField<tensor, pointPatchField, pointMesh> pointTensorField;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -47,14 +47,16 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Forward Declarations
class pointMesh; class pointMesh;
template<class Type> template<class Type> class pointPatchField;
class pointPatchField;
template<class Type, template<class> class PatchField, class GeoMesh> template<class Type, template<class> class PatchField, class GeoMesh>
class GeometricField; class GeometricField;
// Typedefs
typedef GeometricField<scalar, pointPatchField, pointMesh> pointScalarField; typedef GeometricField<scalar, pointPatchField, pointMesh> pointScalarField;
typedef GeometricField<vector, pointPatchField, pointMesh> pointVectorField; typedef GeometricField<vector, pointPatchField, pointMesh> pointVectorField;
typedef GeometricField<sphericalTensor, pointPatchField, pointMesh> typedef GeometricField<sphericalTensor, pointPatchField, pointMesh>

View File

@ -61,7 +61,6 @@ Foam::pointBoundaryMesh::pointBoundaryMesh
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::labelList Foam::pointBoundaryMesh::indices Foam::labelList Foam::pointBoundaryMesh::indices
( (
const keyType& key, const keyType& key,

View File

@ -45,7 +45,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declarations // Forward Declarations
class pointMesh; class pointMesh;
class polyBoundaryMesh; class polyBoundaryMesh;
@ -57,7 +57,7 @@ class pointBoundaryMesh
: :
public pointPatchList public pointPatchList
{ {
// Private data // Private Data
//- Reference to mesh //- Reference to mesh
const pointMesh& mesh_; const pointMesh& mesh_;
@ -100,9 +100,11 @@ public:
} }
//- Find patch indices given a name //- 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 keyType& key, const bool useGroups) const;
//- Find patch index given a name //- Find patch index given a name
// A no-op (returns -1) for an empty patchName
label findPatchID(const word& patchName) const; label findPatchID(const word& patchName) const;
//- Correct polyBoundaryMesh after moving points //- Correct polyBoundaryMesh after moving points

View File

@ -768,6 +768,11 @@ Foam::label Foam::polyBoundaryMesh::findPatchID
bool allowNotFound bool allowNotFound
) const ) const
{ {
if (patchName.empty())
{
return -1;
}
const label patchId = findIndexImpl(*this, patchName); const label patchId = findIndexImpl(*this, patchName);
if (patchId >= 0) if (patchId >= 0)

View File

@ -49,7 +49,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declarations // Forward Declarations
class polyMesh; class polyMesh;
class wordRe; class wordRe;
@ -194,6 +194,7 @@ public:
//- Return patch indices for all matches. //- Return patch indices for all matches.
// Optionally matches patchGroups // Optionally matches patchGroups
// A no-op (returns empty list) for an empty key
labelList indices labelList indices
( (
const keyType& key, const keyType& key,
@ -202,9 +203,11 @@ public:
//- Return patch index for the first match, return -1 if not found //- 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 keyType& key) const;
//- Find patch index given a name, return -1 if not found //- Find patch index given a name, return -1 if not found
// A no-op (returns -1) for an empty patchName
label findPatchID label findPatchID
( (
const word& patchName, const word& patchName,

View File

@ -485,6 +485,11 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findZoneID
const word& zoneName const word& zoneName
) const ) const
{ {
if (zoneName.empty())
{
return -1;
}
label zoneId = findIndexImpl(*this, zoneName); label zoneId = findIndexImpl(*this, zoneName);
if (zoneId < 0) if (zoneId < 0)
@ -514,6 +519,11 @@ const ZoneType* Foam::ZoneMesh<ZoneType, MeshType>::cfindZone
const word& zoneName const word& zoneName
) const ) const
{ {
if (zoneName.empty())
{
return nullptr;
}
const PtrList<ZoneType>& zones = *this; const PtrList<ZoneType>& zones = *this;
for (auto iter = zones.begin(); iter != zones.end(); ++iter) for (auto iter = zones.begin(); iter != zones.end(); ++iter)
@ -585,6 +595,7 @@ Foam::bitSet Foam::ZoneMesh<ZoneType, MeshType>::selection
const keyType& key const keyType& key
) const ) const
{ {
// key.empty() is handled by indices()
return this->selection(this->indices(key)); return this->selection(this->indices(key));
} }
@ -595,6 +606,7 @@ Foam::bitSet Foam::ZoneMesh<ZoneType, MeshType>::selection
const wordRes& matcher const wordRes& matcher
) const ) const
{ {
// matcher.empty() is handled by indices()
return this->selection(this->indices(matcher)); return this->selection(this->indices(matcher));
} }

View File

@ -193,24 +193,31 @@ public:
//- Return zone indices for all matches //- Return zone indices for all matches
// A no-op (returns empty list) for an empty key
labelList indices(const keyType& key) const; labelList indices(const keyType& key) const;
//- Return zone indices for all matches //- Return zone indices for all matches
// A no-op (returns empty list) for an empty matcher
labelList indices(const wordRes& matcher) const; labelList indices(const wordRes& matcher) const;
//- Zone index for the first match, return -1 if not found //- 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 keyType& key) const;
//- Zone index for the first match, return -1 if not found //- Zone 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; label findIndex(const wordRes& matcher) const;
//- Find zone index by name, return -1 if not found //- Find zone index by name, return -1 if not found
// A no-op (returns -1) for an empty zoneName
label findZoneID(const word& zoneName) const; label findZoneID(const word& zoneName) const;
//- Find zone by name and return const pointer, nullptr on error //- Find zone by name and return const pointer, nullptr on error
// A no-op (returns nullptr) for an empty zoneName
const ZoneType* cfindZone(const word& zoneName) const; const ZoneType* cfindZone(const word& zoneName) const;
//- Find zone by name and return pointer, nullptr on error //- Find zone by name and return pointer, nullptr on error
// A no-op (returns nullptr) for an empty zoneName
ZoneType* findZone(const word& zoneName); ZoneType* findZone(const word& zoneName);
@ -224,12 +231,14 @@ public:
//- specification as a bitSet. //- specification as a bitSet.
// The bitSet is empty (zero-size) if there are no elements matched // The bitSet is empty (zero-size) if there are no elements matched
// anywhere. // anywhere.
// A no-op (returns empty bitSet) for an empty key
bitSet selection(const keyType& key) const; bitSet selection(const keyType& key) const;
//- Return all elements (cells, faces, points) that match the zone //- Return all elements (cells, faces, points) that match the zone
//- specification as a bitSet. //- specification as a bitSet.
// The bitSet is empty (zero-size) if there are no elements matched // The bitSet is empty (zero-size) if there are no elements matched
// anywhere. // anywhere.
// A no-op (returns empty bitSet) for an empty matcher
bitSet selection(const wordRes& matcher) const; bitSet selection(const wordRes& matcher) const;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2018-2019 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -289,6 +289,11 @@ Foam::label Foam::faBoundaryMesh::findIndex(const keyType& key) const
Foam::label Foam::faBoundaryMesh::findPatchID(const word& patchName) const Foam::label Foam::faBoundaryMesh::findPatchID(const word& patchName) const
{ {
if (patchName.empty())
{
return -1;
}
return findIndexImpl(*this, patchName); return findIndexImpl(*this, patchName);
} }

View File

@ -55,7 +55,7 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Forward declarations // Forward Declarations
class faMesh; class faMesh;
class faBoundaryMesh; class faBoundaryMesh;
Ostream& operator<<(Ostream&, const faBoundaryMesh&); Ostream& operator<<(Ostream&, const faBoundaryMesh&);
@ -121,7 +121,7 @@ public:
const faMesh& mesh() const; const faMesh& mesh() const;
//- Return a list of pointers for each patch //- Return a list of pointers for each patch
// with only those pointing to interfaces being set //- with only those pointing to interfaces being set
lduInterfacePtrsList interfaces() const; lduInterfacePtrsList interfaces() const;
//- Return a list of patch names //- Return a list of patch names
@ -131,7 +131,8 @@ public:
wordList types() const; wordList types() const;
//- Return patch indices for all matches. //- Return patch indices for all matches.
// \not Matching patchGroups currently not supported // A no-op (returns -1) for an empty key
// \note Matching patchGroups currently not supported
labelList indices labelList indices
( (
const keyType& key, const keyType& key,
@ -139,9 +140,11 @@ public:
) const; ) const;
//- Return patch index for the first match, return -1 if not found //- 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 keyType& key) const;
//- Find patch index given a name, return -1 if not found //- Find patch index given a name, return -1 if not found
// A no-op (returns -1) for an empty name
label findPatchID(const word& patchName) const; label findPatchID(const word& patchName) const;
//- Return patch index for a given edge label //- Return patch index for a given edge label

View File

@ -44,14 +44,16 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Forward Declarations
class areaMesh; class areaMesh;
template<class Type> template<class Type> class faPatchField;
class faPatchField;
template<class Type, template<class> class PatchField, class GeoMesh> template<class Type, template<class> class PatchField, class GeoMesh>
class GeometricField; class GeometricField;
// Typedefs
typedef GeometricField<scalar, faPatchField, areaMesh> areaScalarField; typedef GeometricField<scalar, faPatchField, areaMesh> areaScalarField;
typedef GeometricField<vector, faPatchField, areaMesh> areaVectorField; typedef GeometricField<vector, faPatchField, areaMesh> areaVectorField;
typedef GeometricField<sphericalTensor, faPatchField, areaMesh> typedef GeometricField<sphericalTensor, faPatchField, areaMesh>
@ -60,7 +62,6 @@ typedef GeometricField<symmTensor, faPatchField, areaMesh> areaSymmTensorField;
typedef GeometricField<tensor, faPatchField, areaMesh> areaTensorField; typedef GeometricField<tensor, faPatchField, areaMesh> areaTensorField;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Namespace fieldTypes Declaration Namespace fieldTypes Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/

View File

@ -43,14 +43,16 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Forward Declarations
class edgeMesh; class edgeMesh;
template<class Type> template<class Type> class faePatchField;
class faePatchField;
template<class Type, template<class> class PatchField, class GeoMesh> template<class Type, template<class> class PatchField, class GeoMesh>
class GeometricField; class GeometricField;
// Typedefs
typedef GeometricField<scalar, faePatchField, edgeMesh> edgeScalarField; typedef GeometricField<scalar, faePatchField, edgeMesh> edgeScalarField;
typedef GeometricField<vector, faePatchField, edgeMesh> edgeVectorField; typedef GeometricField<vector, faePatchField, edgeMesh> edgeVectorField;
typedef GeometricField<sphericalTensor, faePatchField, edgeMesh> typedef GeometricField<sphericalTensor, faePatchField, edgeMesh>

View File

@ -45,14 +45,16 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Forward Declarations
class surfaceMesh; class surfaceMesh;
template<class Type> template<class Type> class fvsPatchField;
class fvsPatchField;
template<class Type, template<class> class PatchField, class GeoMesh> template<class Type, template<class> class PatchField, class GeoMesh>
class GeometricField; class GeometricField;
// Typedefs
typedef GeometricField<scalar, fvsPatchField, surfaceMesh> surfaceScalarField; typedef GeometricField<scalar, fvsPatchField, surfaceMesh> surfaceScalarField;
typedef GeometricField<vector, fvsPatchField, surfaceMesh> surfaceVectorField; typedef GeometricField<vector, fvsPatchField, surfaceMesh> surfaceVectorField;
typedef GeometricField<sphericalTensor, fvsPatchField, surfaceMesh> typedef GeometricField<sphericalTensor, fvsPatchField, surfaceMesh>

View File

@ -48,14 +48,16 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Forward Declarations
class volMesh; class volMesh;
template<class Type> template<class Type> class fvPatchField;
class fvPatchField;
template<class Type, template<class> class PatchField, class GeoMesh> template<class Type, template<class> class PatchField, class GeoMesh>
class GeometricField; class GeometricField;
// Typedefs
typedef GeometricField<scalar, fvPatchField, volMesh> volScalarField; typedef GeometricField<scalar, fvPatchField, volMesh> volScalarField;
typedef GeometricField<vector, fvPatchField, volMesh> volVectorField; typedef GeometricField<vector, fvPatchField, volMesh> volVectorField;
typedef GeometricField<sphericalTensor, fvPatchField, volMesh> typedef GeometricField<sphericalTensor, fvPatchField, volMesh>

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -85,6 +85,11 @@ Foam::labelList Foam::fvBoundaryMesh::indices
Foam::label Foam::fvBoundaryMesh::findPatchID(const word& patchName) const Foam::label Foam::fvBoundaryMesh::findPatchID(const word& patchName) const
{ {
if (patchName.empty())
{
return -1;
}
const fvPatchList& patches = *this; const fvPatchList& patches = *this;
forAll(patches, patchi) forAll(patches, patchi)

View File

@ -46,8 +46,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declarations // Forward Declarations
class fvMesh; class fvMesh;
class polyBoundaryMesh; class polyBoundaryMesh;
@ -59,7 +58,7 @@ class fvBoundaryMesh
: :
public fvPatchList public fvPatchList
{ {
// Private data // Private Data
//- Reference to mesh //- Reference to mesh
const fvMesh& mesh_; const fvMesh& mesh_;
@ -107,13 +106,15 @@ public:
} }
//- Return a list of pointers for each patch //- Return a list of pointers for each patch
// with only those pointing to interfaces being set //- with only those pointing to interfaces being set
lduInterfacePtrsList interfaces() const; lduInterfacePtrsList interfaces() const;
//- Return patch indices for all matches. //- 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; labelList indices(const keyType& key, const bool useGroups) const;
//- Find patch index given a name //- Find patch index given a name
// A no-op (returns -1) for an empty patchName
label findPatchID(const word& patchName) const; label findPatchID(const word& patchName) const;
//- Correct patches after moving points //- Correct patches after moving points

View File

@ -291,6 +291,10 @@ Foam::labelList Foam::coordinateSystems::indices(const keyType& key) const
Foam::labelList Foam::coordinateSystems::indices(const wordRes& matcher) const Foam::labelList Foam::coordinateSystems::indices(const wordRes& matcher) const
{ {
if (matcher.empty())
{
return labelList();
}
return indicesImpl(*this, matcher); return indicesImpl(*this, matcher);
} }
@ -319,6 +323,10 @@ Foam::label Foam::coordinateSystems::findIndex(const keyType& key) const
Foam::label Foam::coordinateSystems::findIndex(const wordRes& matcher) const Foam::label Foam::coordinateSystems::findIndex(const wordRes& matcher) const
{ {
if (matcher.empty())
{
return -1;
}
return findIndexImpl(*this, matcher); return findIndexImpl(*this, matcher);
} }

View File

@ -133,15 +133,19 @@ public:
// Member Functions // Member Functions
//- Find and return indices for all matches //- 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 keyType& key) const;
//- Find and return indices for all matches //- Find and return indices for all matches
// A no-op (returns empty list) for an empty matcher
labelList indices(const wordRes& matcher) const; labelList indices(const wordRes& matcher) const;
//- Find and return index for the first match, return -1 if not found //- 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 keyType& key) const;
//- Find and return index for the first match, return -1 if not found //- 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; label findIndex(const wordRes& matcher) const;
//- Search if given key exists //- Search if given key exists