diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkTools.C b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C index 3b71ef1cc8..e7ab6c2d17 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkTools.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C @@ -133,12 +133,9 @@ void Foam::printMeshStats(const polyMesh& mesh, const bool allTopology) << endl; // Construct shape recognizers - hexMatcher hex; prismMatcher prism; wedgeMatcher wedge; - pyrMatcher pyr; tetWedgeMatcher tetWedge; - tetMatcher tet; // Counters for different cell types label nHex = 0; @@ -153,15 +150,15 @@ void Foam::printMeshStats(const polyMesh& mesh, const bool allTopology) for (label celli = 0; celli < mesh.nCells(); celli++) { - if (hex.isA(mesh, celli)) + if (hexMatcher::test(mesh, celli)) { nHex++; } - else if (tet.isA(mesh, celli)) + else if (tetMatcher::test(mesh, celli)) { nTet++; } - else if (pyr.isA(mesh, celli)) + else if (pyrMatcher::test(mesh, celli)) { nPyr++; } diff --git a/src/OpenFOAM/meshes/meshShapes/cellMatcher/hexMatcher.C b/src/OpenFOAM/meshes/meshShapes/cellMatcher/hexMatcher.C index fc76b142b7..6446899751 100644 --- a/src/OpenFOAM/meshes/meshShapes/cellMatcher/hexMatcher.C +++ b/src/OpenFOAM/meshes/meshShapes/cellMatcher/hexMatcher.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,6 +30,71 @@ License #include "primitiveMesh.H" #include "ListOps.H" +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Check (6 quad) +static inline bool checkFaceSizeMatch(const UList& faces) +{ + if (faces.size() != 6) // facePerCell + { + return false; + } + + for (const face& f : faces) + { + if (f.size() != 4) // quad + { + return false; + } + } + + return true; +} + + +// Check (6 quad) +static inline bool checkFaceSizeMatch +( + const UList& meshFaces, + const labelUList& cellFaces +) +{ + if (cellFaces.size() != 6) // facePerCell + { + return false; + } + + for (const label facei : cellFaces) + { + if (meshFaces[facei].size() != 4) // quad + { + return false; + } + } + + return true; +} + + +} // End namespace Foam + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +bool Foam::hexMatcher::test(const UList& faces) +{ + return checkFaceSizeMatch(faces); +} + +bool Foam::hexMatcher::test(const primitiveMesh& mesh, const label celli) +{ + return checkFaceSizeMatch(mesh.faces(), mesh.cells()[celli]); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::hexMatcher::hexMatcher() @@ -241,53 +307,11 @@ Foam::label Foam::hexMatcher::faceHashValue() const bool Foam::hexMatcher::faceSizeMatch ( - const faceList& faces, - const labelList& myFaces + const faceList& meshFaces, + const labelList& cellFaces ) const { - if (myFaces.size() != facePerCell) - { - return false; - } - - for (const label facei : myFaces) - { - const label size = faces[facei].size(); - - if (size != 4) - { - return false; - } - } - - return true; -} - - -bool Foam::hexMatcher::isA(const primitiveMesh& mesh, const label celli) -{ - return matchShape - ( - true, - mesh.faces(), - mesh.faceOwner(), - celli, - mesh.cells()[celli] - ); -} - - -bool Foam::hexMatcher::isA(const faceList& faces) -{ - // Do as if mesh with one cell only - return matchShape - ( - true, - faces, // all faces in mesh - labelList(faces.size(), Zero), // cell 0 is owner of all faces - 0, // cell label - identity(faces.size()) // faces of cell 0 - ); + return checkFaceSizeMatch(meshFaces, cellFaces); } diff --git a/src/OpenFOAM/meshes/meshShapes/cellMatcher/hexMatcher.H b/src/OpenFOAM/meshes/meshShapes/cellMatcher/hexMatcher.H index 04db020287..372dd48b91 100644 --- a/src/OpenFOAM/meshes/meshShapes/cellMatcher/hexMatcher.H +++ b/src/OpenFOAM/meshes/meshShapes/cellMatcher/hexMatcher.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -84,6 +85,17 @@ public: ~hexMatcher() = default; + // Static Functions + + //- Test if given list of faces satisfies criteria for HEX. + //- (6 quad) + static bool test(const UList& faces); + + //- Test if given cell satisfies criteria for HEX. + //- (6 quad) + static bool test(const primitiveMesh& mesh, const label celli); + + // Member Functions virtual label nVertPerCell() const @@ -114,9 +126,15 @@ public: const labelList& myFaces ); - virtual bool isA(const primitiveMesh& mesh, const label celli); + virtual bool isA(const faceList& faces) + { + return hexMatcher::test(faces); + } - virtual bool isA(const faceList&); + virtual bool isA(const primitiveMesh& mesh, const label celli) + { + return hexMatcher::test(mesh, celli); + } virtual bool matches ( diff --git a/src/OpenFOAM/meshes/meshShapes/cellMatcher/pyrMatcher.C b/src/OpenFOAM/meshes/meshShapes/cellMatcher/pyrMatcher.C index 6667d5413a..73ce01907f 100644 --- a/src/OpenFOAM/meshes/meshShapes/cellMatcher/pyrMatcher.C +++ b/src/OpenFOAM/meshes/meshShapes/cellMatcher/pyrMatcher.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,6 +32,96 @@ License #include "cellModel.H" #include "ListOps.H" +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Check (4 tri, 1 quad) +static inline bool checkFaceSizeMatch(const UList& faces) +{ + if (faces.size() != 5) // facePerCell + { + return false; + } + + int nTris = 0; + int nQuads = 0; + + for (const face& f : faces) + { + const label size = f.size(); + + if (size == 3) + { + ++nTris; + } + else if (size == 4) + { + ++nQuads; + } + else + { + return false; + } + } + + return (nTris == 4 && nQuads == 1); +} + + +// Check (4 tri, 1 quad) +static inline bool checkFaceSizeMatch +( + const UList& meshFaces, + const labelUList& cellFaces +) +{ + if (cellFaces.size() != 5) // facePerCell + { + return false; + } + + int nTris = 0; + int nQuads = 0; + + for (const label facei : cellFaces) + { + const label size = meshFaces[facei].size(); + + if (size == 3) + { + ++nTris; + } + else if (size == 4) + { + ++nQuads; + } + else + { + return false; + } + } + + return (nTris == 4 && nQuads == 1); +} + +} // End namespace Foam + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +bool Foam::pyrMatcher::test(const UList& faces) +{ + return checkFaceSizeMatch(faces); +} + +bool Foam::pyrMatcher::test(const primitiveMesh& mesh, const label celli) +{ + return checkFaceSizeMatch(mesh.faces(), mesh.cells()[celli]); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::pyrMatcher::pyrMatcher() @@ -211,64 +302,11 @@ Foam::label Foam::pyrMatcher::faceHashValue() const bool Foam::pyrMatcher::faceSizeMatch ( - const faceList& faces, - const labelList& myFaces + const faceList& meshFaces, + const labelList& cellFaces ) const { - if (myFaces.size() != 5) - { - return false; - } - - label nTris = 0; - label nQuads = 0; - - for (const label facei : myFaces) - { - const label size = faces[facei].size(); - - if (size == 3) - { - ++nTris; - } - else if (size == 4) - { - ++nQuads; - } - else - { - return false; - } - } - - return (nTris == 4 && nQuads == 1); -} - - -bool Foam::pyrMatcher::isA(const primitiveMesh& mesh, const label celli) -{ - return matchShape - ( - true, - mesh.faces(), - mesh.faceOwner(), - celli, - mesh.cells()[celli] - ); -} - - -bool Foam::pyrMatcher::isA(const faceList& faces) -{ - // Do as if mesh with one cell only - return matchShape - ( - true, - faces, // all faces in mesh - labelList(faces.size(), Zero), // cell 0 is owner of all faces - 0, // cell label - identity(faces.size()) // faces of cell 0 - ); + return checkFaceSizeMatch(meshFaces, cellFaces); } diff --git a/src/OpenFOAM/meshes/meshShapes/cellMatcher/pyrMatcher.H b/src/OpenFOAM/meshes/meshShapes/cellMatcher/pyrMatcher.H index 908dd98bfc..561948f9ec 100644 --- a/src/OpenFOAM/meshes/meshShapes/cellMatcher/pyrMatcher.H +++ b/src/OpenFOAM/meshes/meshShapes/cellMatcher/pyrMatcher.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -84,6 +85,17 @@ public: ~pyrMatcher() = default; + // Static Functions + + //- Test if given list of faces satisfies criteria for PYR. + //- (4 tri, 1 quad) + static bool test(const UList& faces); + + //- Test if given cell satisfies criteria for PYR. + //- (4 tri, 1 quad) + static bool test(const primitiveMesh& mesh, const label celli); + + // Member Functions virtual label nVertPerCell() const @@ -114,9 +126,15 @@ public: const labelList& myFaces ); - virtual bool isA(const primitiveMesh& mesh, const label celli); + virtual bool isA(const faceList& faces) + { + return pyrMatcher::test(faces); + } - virtual bool isA(const faceList&); + virtual bool isA(const primitiveMesh& mesh, const label celli) + { + return pyrMatcher::test(mesh, celli); + } virtual bool matches ( diff --git a/src/OpenFOAM/meshes/meshShapes/cellMatcher/tetMatcher.C b/src/OpenFOAM/meshes/meshShapes/cellMatcher/tetMatcher.C index 2d59c19783..27b7fc0020 100644 --- a/src/OpenFOAM/meshes/meshShapes/cellMatcher/tetMatcher.C +++ b/src/OpenFOAM/meshes/meshShapes/cellMatcher/tetMatcher.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,6 +32,72 @@ License #include "cellModel.H" #include "ListOps.H" +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Check (4 tri) +static inline bool checkFaceSizeMatch(const UList& faces) +{ + if (faces.size() != 4) // facePerCell + { + return false; + } + + for (const face& f : faces) + { + if (f.size() != 3) // tri + { + return false; + } + } + + return true; +} + + +// Check (4 tri) +static inline bool checkFaceSizeMatch +( + const UList& meshFaces, + const labelUList& cellFaces +) +{ + if (cellFaces.size() != 4) // facePerCell + { + return false; + } + + for (const label facei : cellFaces) + { + if (meshFaces[facei].size() != 3) // tri + { + return false; + } + } + + return true; +} + + +} // End namespace Foam + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +bool Foam::tetMatcher::test(const UList& faces) +{ + return checkFaceSizeMatch(faces); +} + + +bool Foam::tetMatcher::test(const primitiveMesh& mesh, const label celli) +{ + return checkFaceSizeMatch(mesh.faces(), mesh.cells()[celli]); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::tetMatcher::tetMatcher() @@ -180,53 +247,11 @@ Foam::label Foam::tetMatcher::faceHashValue() const bool Foam::tetMatcher::faceSizeMatch ( - const faceList& faces, - const labelList& myFaces + const faceList& meshFaces, + const labelList& cellFaces ) const { - if (myFaces.size() != 4) - { - return false; - } - - for (const label facei : myFaces) - { - const label size = faces[facei].size(); - - if (size != 3) - { - return false; - } - } - - return true; -} - - -bool Foam::tetMatcher::isA(const primitiveMesh& mesh, const label celli) -{ - return matchShape - ( - true, - mesh.faces(), - mesh.faceOwner(), - celli, - mesh.cells()[celli] - ); -} - - -bool Foam::tetMatcher::isA(const faceList& faces) -{ - // Do as if mesh with one cell only - return matchShape - ( - true, - faces, // all faces in mesh - labelList(faces.size(), Zero), // cell 0 is owner of all faces - 0, // cell label - identity(faces.size()) // faces of cell 0 - ); + return checkFaceSizeMatch(meshFaces, cellFaces); } diff --git a/src/OpenFOAM/meshes/meshShapes/cellMatcher/tetMatcher.H b/src/OpenFOAM/meshes/meshShapes/cellMatcher/tetMatcher.H index f93c2042f3..2794d774a1 100644 --- a/src/OpenFOAM/meshes/meshShapes/cellMatcher/tetMatcher.H +++ b/src/OpenFOAM/meshes/meshShapes/cellMatcher/tetMatcher.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -84,6 +85,17 @@ public: ~tetMatcher() = default; + // Static Functions + + //- Test if given list of faces satisfies criteria for TET. + //- (4 tri) + static bool test(const UList& faces); + + //- Test if given cell satisfies criteria for TET. + //- (4 tri) + static bool test(const primitiveMesh& mesh, const label celli); + + // Member Functions virtual label nVertPerCell() const @@ -114,9 +126,15 @@ public: const labelList& myFaces ); - virtual bool isA(const primitiveMesh& mesh, const label celli); + virtual bool isA(const primitiveMesh& mesh, const label celli) + { + return tetMatcher::test(mesh, celli); + } - virtual bool isA(const faceList&); + virtual bool isA(const faceList& faces) + { + return tetMatcher::test(faces); + } virtual bool matches ( diff --git a/src/OpenFOAM/meshes/meshShapes/tetCell/tetCell.H b/src/OpenFOAM/meshes/meshShapes/tetCell/tetCell.H index 93a1f408af..cc0a71a8e2 100644 --- a/src/OpenFOAM/meshes/meshShapes/tetCell/tetCell.H +++ b/src/OpenFOAM/meshes/meshShapes/tetCell/tetCell.H @@ -102,7 +102,7 @@ public: // Access //- Return i-th face - inline triFace face(const label facei) const; + inline Foam::triFace face(const label facei) const; //- Return first face adjacent to the given edge inline label edgeFace(const label edgei) const; @@ -114,8 +114,14 @@ public: const label facei ) const; - //- Return i-th edge - inline edge tetEdge(const label edgei) const; + //- Return i-th edge from tet. + inline Foam::edge tetEdge(const label edgei) const; + + //- Return i-th edge. Identical to tetEdge but with generic name + inline Foam::edge edge(const label edgei) const; + + //- Return i-th edge reversed + inline Foam::edge reverseEdge(const label edgei) const; // Operations diff --git a/src/OpenFOAM/meshes/meshShapes/tetCell/tetCellI.H b/src/OpenFOAM/meshes/meshShapes/tetCell/tetCellI.H index 1b2be3923f..63fd0d31d4 100644 --- a/src/OpenFOAM/meshes/meshShapes/tetCell/tetCellI.H +++ b/src/OpenFOAM/meshes/meshShapes/tetCell/tetCellI.H @@ -24,12 +24,8 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . -Description - \*---------------------------------------------------------------------------*/ -#include "IOstreams.H" - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // inline Foam::tetCell::tetCell() @@ -182,7 +178,20 @@ inline Foam::edge Foam::tetCell::tetEdge(const label edgei) const } #endif - return edge(operator[](pt0[edgei]), operator[](pt1[edgei])); + return Foam::edge(operator[](pt0[edgei]), operator[](pt1[edgei])); +} + + +inline Foam::edge Foam::tetCell::edge(const label edgei) const +{ + return tetEdge(edgei); +} + + +inline Foam::edge Foam::tetCell::reverseEdge(const label edgei) const +{ + // Reverse edge. Using a copy is cheaper than inplace flip + return tetEdge(edgei).reverseEdge(); } diff --git a/src/dynamicMesh/meshCut/cellLooper/topoCellLooper.C b/src/dynamicMesh/meshCut/cellLooper/topoCellLooper.C index 90e6ce2e99..29e00d342f 100644 --- a/src/dynamicMesh/meshCut/cellLooper/topoCellLooper.C +++ b/src/dynamicMesh/meshCut/cellLooper/topoCellLooper.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -700,7 +701,7 @@ bool Foam::topoCellLooper::cut { cellFeatures superCell(mesh(), featureCos, celli); - if (hexMatcher().isA(superCell.faces())) + if (hexMatcher::test(superCell.faces())) { label edgeI = getAlignedNonFeatureEdge diff --git a/src/dynamicMesh/meshCut/directions/directionInfo/directionInfoI.H b/src/dynamicMesh/meshCut/directions/directionInfo/directionInfoI.H index a50fb84446..6005807f33 100644 --- a/src/dynamicMesh/meshCut/directions/directionInfo/directionInfoI.H +++ b/src/dynamicMesh/meshCut/directions/directionInfo/directionInfoI.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -137,7 +138,7 @@ inline bool Foam::directionInfo::updateCell return false; } - if (hexMatcher().isA(mesh, thisCelli)) + if (hexMatcher::test(mesh, thisCelli)) { const face& f = mesh.faces()[neighbourFacei]; diff --git a/src/dynamicMesh/meshCut/directions/directions.C b/src/dynamicMesh/meshCut/directions/directions.C index fb566f919c..67e475aecc 100644 --- a/src/dynamicMesh/meshCut/directions/directions.C +++ b/src/dynamicMesh/meshCut/directions/directions.C @@ -151,7 +151,7 @@ Foam::vectorField Foam::directions::propagateDirection label celli = mesh.faceOwner()[meshFacei]; - if (!hexMatcher().isA(mesh, celli)) + if (!hexMatcher::test(mesh, celli)) { FatalErrorInFunction << "useHexTopology specified but cell " << celli diff --git a/src/meshTools/meshTools/meshTools.C b/src/meshTools/meshTools/meshTools.C index 00f4454594..50ee9d8488 100644 --- a/src/meshTools/meshTools/meshTools.C +++ b/src/meshTools/meshTools/meshTools.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2017 OpenCFD Ltd. + Copyright (C) 2015-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -766,7 +766,7 @@ Foam::vector Foam::meshTools::edgeToCutDir const label startEdgeI ) { - if (!hexMatcher().isA(mesh, celli)) + if (!hexMatcher::test(mesh, celli)) { FatalErrorInFunction << "Not a hex : cell:" << celli << abort(FatalError); @@ -813,7 +813,7 @@ Foam::label Foam::meshTools::cutDirToEdge const vector& cutDir ) { - if (!hexMatcher().isA(mesh, celli)) + if (!hexMatcher::test(mesh, celli)) { FatalErrorInFunction << "Not a hex : cell:" << celli << abort(FatalError); diff --git a/src/meshTools/sets/cellSources/shapeToCell/shapeToCell.C b/src/meshTools/sets/cellSources/shapeToCell/shapeToCell.C index 46de3ff37b..c9fba49e03 100644 --- a/src/meshTools/sets/cellSources/shapeToCell/shapeToCell.C +++ b/src/meshTools/sets/cellSources/shapeToCell/shapeToCell.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -68,7 +68,7 @@ void Foam::shapeToCell::combine(topoSet& set, const bool add) const { cellFeatures superCell(mesh_, featureCos, celli); - if (hexMatcher().isA(superCell.faces())) + if (hexMatcher::test(superCell.faces())) { addOrDelete(set, celli, add); } diff --git a/src/sampling/surface/isoSurface/isoSurfaceCell.C b/src/sampling/surface/isoSurface/isoSurfaceCell.C index 09b74ddbf0..7ca788a7b6 100644 --- a/src/sampling/surface/isoSurface/isoSurfaceCell.C +++ b/src/sampling/surface/isoSurface/isoSurfaceCell.C @@ -1355,11 +1355,9 @@ Foam::isoSurfaceCell::isoSurfaceCell // Determine if cell is tet bitSet isTet(mesh_.nCells()); { - tetMatcher tet; - forAll(isTet, celli) { - if (tet.isA(mesh_, celli)) + if (tetMatcher::test(mesh_, celli)) { isTet.set(celli); } diff --git a/src/sampling/surface/isoSurface/isoSurfaceCellTemplates.C b/src/sampling/surface/isoSurface/isoSurfaceCellTemplates.C index 660db72327..cac36fe042 100644 --- a/src/sampling/surface/isoSurface/isoSurfaceCellTemplates.C +++ b/src/sampling/surface/isoSurface/isoSurfaceCellTemplates.C @@ -280,7 +280,6 @@ void Foam::isoSurfaceCell::generateTriPoints DynamicList