diff --git a/src/OpenFOAM/meshes/GeoMesh/GeoMesh.H b/src/OpenFOAM/meshes/GeoMesh/GeoMesh.H index 21f0377d1f9517938c99d16639ce51bd8075fb4a..9845e9dd8614d29217d2fc9d8dc62489a670b465 100644 --- a/src/OpenFOAM/meshes/GeoMesh/GeoMesh.H +++ b/src/OpenFOAM/meshes/GeoMesh/GeoMesh.H @@ -29,10 +29,13 @@ Class Description Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc. + Derived classes are typically expected to implement the static methods + size() and boundary_size(). + \*---------------------------------------------------------------------------*/ -#ifndef GeoMesh_H -#define GeoMesh_H +#ifndef Foam_GeoMesh_H +#define Foam_GeoMesh_H #include "objectRegistry.H" diff --git a/src/OpenFOAM/meshes/pointMesh/pointMesh.H b/src/OpenFOAM/meshes/pointMesh/pointMesh.H index 8aaeb4f698c29acc8b6445972402e5e1c527b401..0634da54366d2c07e17d992a259e6d85edb963af 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointMesh.H +++ b/src/OpenFOAM/meshes/pointMesh/pointMesh.H @@ -121,15 +121,27 @@ public: ~pointMesh() = default; - // Member Functions + // Static Functions - //- Return size. Number of points + //- The geometric (internal) size - number of mesh points. + // Method name expected by GeoMesh interface static label size(const Mesh& mesh) { return mesh.GeoMesh<polyMesh>::mesh_.nPoints(); } - //- Return size. Number of points + //- The geometric boundary size - not implemented. + // Method name expected by GeoMesh interface + static label boundary_size(const Mesh& mesh) + { + return 0; + } + + + // Member Functions + + //- The geometric (internal) size - number of points. + // Method name expected by GeoMesh interface label size() const { return size(*this); diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H index 80af040dc7a7c3d13a5659c0d2fed5ebf33aa33d..4c19f6362de4317019f484963a82d2e97ced2246 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H @@ -244,6 +244,11 @@ public: // Same as polyMesh::nBoundaryFaces() label nFaces() const noexcept; + //- The number of boundary faces with patches that match the + //- given predicate. + template<class UnaryPredicate> + label nFaces_if(UnaryPredicate pred) const; + //- The face range for all boundary faces // Spans [nInternalFaces, nFaces) of the underlying mesh labelRange range() const noexcept; @@ -284,6 +289,17 @@ public: const bool useGroups = true ) const; + //- Return (sorted) patch indices for patches that match the + //- given polyPatch type (uses \c isA test). + //- Can be used as a direct alternative to findPatchIDs + template<class PatchType> + labelList indices_if() const; + + //- Return (sorted) patch indices for patches that match the + //- given predicate. Can be used as an alternative to findPatchIDs + template<class UnaryPredicate> + labelList indices_if(UnaryPredicate pred) 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 wordRe& key) const; @@ -296,8 +312,8 @@ public: const bool allowNotFound = true ) const; - //- Find patch indices for a given polyPatch type - template<class Type> + //- Find patch indices for a given polyPatch type (uses \c isA test). + template<class PatchType> labelHashSet findPatchIDs() const; //- Lookup mesh face index and return (patchi, patchFacei) tuple diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.txx b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.txx index 18ce94f997b5e8ff8b80f9b21b7a242685f994da..b15aab25d3548dbfd9a105bc5975309aacb95b4c 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.txx +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.txx @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2013-2016 OpenFOAM Foundation + Copyright (C) 2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,20 +28,92 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template<class Type> +template<class UnaryPredicate> +Foam::label Foam::polyBoundaryMesh::nFaces_if(UnaryPredicate pred) const +{ + const polyBoundaryMesh& patches = *this; + + label count = 0; + + for (const polyPatch& pp : patches) + { + if (pred(pp)) + { + count += pp.size(); + } + } + + return count; +} + + +template<class UnaryPredicate> +Foam::labelList Foam::polyBoundaryMesh::indices_if(UnaryPredicate pred) const +{ + const polyBoundaryMesh& patches = *this; + const label total = patches.size(); + + labelList patchIDs(total); + + label count = 0; + + for (label patchi = 0; patchi < total; ++patchi) + { + if (pred(patches[patchi])) + { + patchIDs[count] = patchi; + ++count; + } + } + + patchIDs.resize(count); + + return patchIDs; +} + + +template<class PatchType> +Foam::labelList Foam::polyBoundaryMesh::indices_if() const +{ + const polyBoundaryMesh& patches = *this; + const label total = patches.size(); + + labelList patchIDs(total); + + label count = 0; + + for (label patchi = 0; patchi < total; ++patchi) + { + if (isA<PatchType>(patches[patchi])) + { + patchIDs[count] = patchi; + ++count; + } + } + + patchIDs.resize(count); + + return patchIDs; +} + + +template<class PatchType> Foam::labelHashSet Foam::polyBoundaryMesh::findPatchIDs() const { const polyBoundaryMesh& patches = *this; + const label total = patches.size(); - labelHashSet patchIDs(patches.size()); + labelHashSet patchIDs; + patchIDs.reserve(total); - forAll(patches, patchi) + for (label patchi = 0; patchi < total; ++patchi) { - if (isA<Type>(patches[patchi])) + if (isA<PatchType>(patches[patchi])) { patchIDs.insert(patchi); } } + return patchIDs; } diff --git a/src/finiteArea/areaMesh/areaFaMesh.H b/src/finiteArea/areaMesh/areaFaMesh.H index 039a574c7c19c12149811904c585eb096592d8da..35ceba46c84b20c40b9d4dfb64201c8adc5c7dbb 100644 --- a/src/finiteArea/areaMesh/areaFaMesh.H +++ b/src/finiteArea/areaMesh/areaFaMesh.H @@ -36,8 +36,8 @@ Author \*---------------------------------------------------------------------------*/ -#ifndef areaFaMesh_H -#define areaFaMesh_H +#ifndef Foam_areaFaMesh_H +#define Foam_areaFaMesh_H #include "GeoMesh.H" #include "faMesh.H" @@ -66,13 +66,32 @@ public: {} + // Static Functions + + //- The geometric (internal) size - number of faces. + // Method name expected by GeoMesh interface + static label size(const faMesh& mesh) noexcept + { + return mesh.nFaces(); + } + + //- The geometric boundary size - number of boundary edges. + // Method name expected by GeoMesh interface + static label boundary_size(const faMesh& mesh) noexcept + { + return mesh.nBoundaryEdges(); + } + + // Member Functions - //- Return size. Number of faces - static label size(const Mesh& mesh) { return mesh.nFaces(); } + //- The geometric (internal) size - number of faces. + // Method name expected by GeoMesh interface + label size() const noexcept + { + return size(mesh_); + } - //- Return size. Number of faces - label size() const { return size(mesh_); } //- Field of face centres const areaVectorField& C() const { return mesh_.areaCentres(); } diff --git a/src/finiteArea/edgeMesh/edgeFaMesh.H b/src/finiteArea/edgeMesh/edgeFaMesh.H index 214af6a9c746464fa1871fd799297e6cc76260b2..e4a298a83db8a423c25067aba13741eddda876e3 100644 --- a/src/finiteArea/edgeMesh/edgeFaMesh.H +++ b/src/finiteArea/edgeMesh/edgeFaMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 Wikki Ltd - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,8 +36,8 @@ Author \*---------------------------------------------------------------------------*/ -#ifndef edgeFaMesh_H -#define edgeFaMesh_H +#ifndef Foam_edgeFaMesh_H +#define Foam_edgeFaMesh_H #include "GeoMesh.H" #include "faMesh.H" @@ -66,13 +66,32 @@ public: {} + // Static Functions + + //- The geometric (internal) size - number of internal edges. + // Method name expected by GeoMesh interface + static label size(const faMesh& mesh) noexcept + { + return mesh.nInternalEdges(); + } + + //- The geometric boundary size - number of boundary edges. + // Method name expected by GeoMesh interface + static label boundary_size(const faMesh& mesh) noexcept + { + return mesh.nBoundaryEdges(); + } + + // Member Functions - //- Return size. Number of internal edges - static label size(const Mesh& mesh) { return mesh.nInternalEdges(); } + //- The geometric (internal) size - number of internal edges. + // Method name expected by GeoMesh interface + label size() const noexcept + { + return size(mesh_); + } - //- Return size. Number of internal edges - label size() const { return size(mesh_); } //- Field of edge centres const edgeVectorField& C() const { return mesh_.edgeCentres(); } diff --git a/src/finiteVolume/surfaceMesh/surfaceMesh.H b/src/finiteVolume/surfaceMesh/surfaceMesh.H index b82d2ac9822ed8c855039e0d69f865743dcad837..19399a0ba9e30ca02c232515a40b1ecd6212c8b5 100644 --- a/src/finiteVolume/surfaceMesh/surfaceMesh.H +++ b/src/finiteVolume/surfaceMesh/surfaceMesh.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation + Copyright (C) 2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,8 +32,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef surfaceMesh_H -#define surfaceMesh_H +#ifndef Foam_surfaceMesh_H +#define Foam_surfaceMesh_H #include "GeoMesh.H" #include "fvMesh.H" @@ -62,20 +63,33 @@ public: {} - // Member Functions + // Static Functions - //- Return size. Number of internal faces - static label size(const Mesh& mesh) + //- The geometric (internal) size - number of internal faces. + // Method name expected by GeoMesh interface + static label size(const polyMesh& mesh) noexcept { return mesh.nInternalFaces(); } - //- Return size. Number of internal faces - label size() const + //- The geometric boundary size - number of boundary faces. + // Method name expected by GeoMesh interface + static label boundary_size(const polyMesh& mesh) noexcept + { + return mesh.nBoundaryFaces(); + } + + + // Member Functions + + //- The geometric mesh size - number of internal faces. + // Method name expected by GeoMesh interface + label size() const noexcept { return size(mesh_); } + //- Field of face centres const surfaceVectorField& C() const { diff --git a/src/finiteVolume/volMesh/volMesh.H b/src/finiteVolume/volMesh/volMesh.H index cde07521f3718dd350a31f1cb7934811b7c4dc9e..df014a7f7e065bd43e8768e7df9d0741d2154839 100644 --- a/src/finiteVolume/volMesh/volMesh.H +++ b/src/finiteVolume/volMesh/volMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021,2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,13 +32,12 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef volMesh_H -#define volMesh_H +#ifndef Foam_volMesh_H +#define Foam_volMesh_H #include "GeoMesh.H" #include "fvMesh.H" #include "primitiveMesh.H" -#include <type_traits> // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -57,23 +56,35 @@ public: // Constructors - //- Construct from fvMesh + //- Construct from fvMesh reference explicit volMesh(const fvMesh& mesh) : GeoMesh<fvMesh>(mesh) {} - // Member Functions + // Static Functions - //- Return size. Number of cells - static label size(const Mesh& mesh) + //- The geometric (internal) mesh size - number of cells. + // Method name expected by GeoMesh interface + static label size(const polyMesh& mesh) noexcept { return mesh.nCells(); } - //- Return size. Number of cells - label size() const + //- The geometric boundary size - number of boundary faces. + // Method name expected by GeoMesh interface + static label boundary_size(const polyMesh& mesh) noexcept + { + return mesh.nBoundaryFaces(); + } + + + // Member Functions + + //- The geometric (internal) mesh size - number of cells. + // Method name expected by GeoMesh interface + label size() const noexcept { return size(mesh_); } diff --git a/src/meshTools/fields/volume/polyGeoMesh.H b/src/meshTools/fields/volume/polyGeoMesh.H index dd7e5c483a714b76adebf403ffe32546e14e3f02..42c7213272a4c5382fccd7b1287620dec2f1599f 100644 --- a/src/meshTools/fields/volume/polyGeoMesh.H +++ b/src/meshTools/fields/volume/polyGeoMesh.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -61,16 +61,28 @@ public: {} - // Member Functions + // Static Functions - //- Return size. Number of cells - static label size(const Mesh& mesh) + //- The geometric (internal) mesh size - number of cells. + // Method name expected by GeoMesh interface + static label size(const polyMesh& mesh) noexcept { return mesh.nCells(); } - //- Return size. Number of cells - label size() const + //- The geometric boundary size - not used (internal fields only). + // Method name expected by GeoMesh interface + static label boundary_size(const polyMesh& mesh) noexcept + { + return 0; + } + + + // Member Functions + + //- The geometric (internal) mesh size - number of cells. + // Method name expected by GeoMesh interface + label size() const noexcept { return size(mesh_); } diff --git a/src/surfMesh/polySurface/fields/polySurfaceGeoMesh.H b/src/surfMesh/polySurface/fields/polySurfaceGeoMesh.H index 9adff973152e9535499531d1c4eda2c553cc5c1e..7cdc501d4d0dd0cecf1d06ef085639911c8bd5c6 100644 --- a/src/surfMesh/polySurface/fields/polySurfaceGeoMesh.H +++ b/src/surfMesh/polySurface/fields/polySurfaceGeoMesh.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -61,15 +61,27 @@ public: {} - // Member Functions + // Static Functions - //- Return size. Number of faces - static label size(const Mesh& mesh) + //- The geometric (internal) size - number of faces. + // Method name expected by GeoMesh interface + static label size(const polySurface& mesh) { return mesh.nFaces(); } - //- Return size. Number of faces + //- The geometric boundary size - not used. + // Method name expected by GeoMesh interface + static label boundary_size(const polySurface& mesh) noexcept + { + return 0; + } + + + // Member Functions + + //- The geometric (internal) size - number of faces. + // Method name expected by GeoMesh interface label size() const { return size(mesh_); diff --git a/src/surfMesh/polySurface/fields/polySurfacePointGeoMesh.H b/src/surfMesh/polySurface/fields/polySurfacePointGeoMesh.H index 8ccca1e11a31fec0a7b5d623221444ae0242aee8..d5cd53625e92c866aa8ed3a1ebc45bf7944d6ea6 100644 --- a/src/surfMesh/polySurface/fields/polySurfacePointGeoMesh.H +++ b/src/surfMesh/polySurface/fields/polySurfacePointGeoMesh.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -61,15 +61,27 @@ public: {} - // Member Functions + // Static Functions - //- Return size. Number of points - static label size(const Mesh& mesh) + //- The geometric (internal) size - number of points. + // Method name expected by GeoMesh interface + static label size(const polySurface& mesh) { return mesh.nPoints(); } - //- Return size. Number of points + //- The geometric boundary size - not used. + // Method name expected by GeoMesh interface + static label boundary_size(const polySurface& mesh) noexcept + { + return 0; + } + + + // Member Functions + + //- The geometric (internal) size - number of points. + // Method name expected by GeoMesh interface label size() const { return size(mesh_); diff --git a/src/surfMesh/surfMesh/fields/surfGeoMesh.H b/src/surfMesh/surfMesh/fields/surfGeoMesh.H index 4d4dd20d8767e80d22c6560da1e7497e0c4bdac2..75e94b62dd37a581359afe539a63e836db0a8402 100644 --- a/src/surfMesh/surfMesh/fields/surfGeoMesh.H +++ b/src/surfMesh/surfMesh/fields/surfGeoMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -62,15 +62,27 @@ public: {} - // Member Functions + // Static Functions - //- Return size. Number of faces - static label size(const Mesh& mesh) + //- The geometric (internal) size - number of faces. + // Method name expected by GeoMesh interface + static label size(const surfMesh& mesh) { return mesh.nFaces(); } - //- Return size. Number of faces + //- The geometric boundary size - not used. + // Method name expected by GeoMesh interface + static label boundary_size(const surfMesh& mesh) noexcept + { + return 0; + } + + + // Member Functions + + //- The geometric (internal) size - number of faces. + // Method name expected by GeoMesh interface label size() const { return size(mesh_); diff --git a/src/surfMesh/surfMesh/fields/surfPointGeoMesh.H b/src/surfMesh/surfMesh/fields/surfPointGeoMesh.H index 6a152d3fe72f6dfcb1c966a17ee7881fb55fd121..6e00f61c3b052c03bff96f554b4f39296103738b 100644 --- a/src/surfMesh/surfMesh/fields/surfPointGeoMesh.H +++ b/src/surfMesh/surfMesh/fields/surfPointGeoMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021,2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -64,15 +64,27 @@ public: {} - // Member Functions + // Static Functions - //- Return size. Number of points - static label size(const Mesh& mesh) + //- The geometric (internal) size - number of points. + // Method name expected by GeoMesh interface + static label size(const surfMesh& mesh) { return mesh.nPoints(); } - //- Return size. Number of points + //- The geometric boundary size - not used. + // Method name expected by GeoMesh interface + static label boundary_size(const surfMesh& mesh) noexcept + { + return 0; + } + + + // Member Functions + + //- The geometric (internal) size - number of points. + // Method name expected by GeoMesh interface label size() const { return size(mesh_); diff --git a/src/surfMesh/triSurface/fields/triSurfaceGeoMesh.H b/src/surfMesh/triSurface/fields/triSurfaceGeoMesh.H index e2688a39f10db446ab2518d2527208a973a660f1..9cfba9d34211f09fd454b3c8c308ce7cf217324f 100644 --- a/src/surfMesh/triSurface/fields/triSurfaceGeoMesh.H +++ b/src/surfMesh/triSurface/fields/triSurfaceGeoMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021,2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -60,15 +60,27 @@ public: {} - // Member Functions + // Static Functions - //- Return size. Numer of faces - static label size(const Mesh& mesh) + //- The geometric (internal) size - number of faces. + // Method name expected by GeoMesh interface + static label size(const triSurface& mesh) { return mesh.size(); } - //- Return size. Numer of faces + //- The geometric boundary size - not used. + // Method name expected by GeoMesh interface + static label boundary_size(const triSurface& mesh) noexcept + { + return 0; + } + + + // Member Functions + + //- The geometric (internal) size - number of faces. + // Method name expected by GeoMesh interface label size() const { return size(mesh_); diff --git a/src/surfMesh/triSurface/fields/triSurfacePointGeoMesh.H b/src/surfMesh/triSurface/fields/triSurfacePointGeoMesh.H index 031ff5fb56baa40400d1a5ceb9da9334790cb781..5ffd6fa68988858ec014b5b37a18ae97e08ceac5 100644 --- a/src/surfMesh/triSurface/fields/triSurfacePointGeoMesh.H +++ b/src/surfMesh/triSurface/fields/triSurfacePointGeoMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021,2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -60,15 +60,27 @@ public: {} - // Member Functions + // Static Functions - //- Return size. Number of points - static label size(const Mesh& mesh) + //- The geometric (internal) size - number of points. + // Method name expected by GeoMesh interface + static label size(const triSurface& mesh) { return mesh.points().size(); } - //- Return size. Number of points + //- The geometric boundary size - not applicable. + // Method name expected by GeoMesh interface + static label boundary_size(const triSurface& mesh) noexcept + { + return 0; + } + + + // Member Functions + + //- The geometric (internal) size - number of points. + // Method name expected by GeoMesh interface label size() const { return size(mesh_);