From fcf090410a8440bb0359280b7057a6c511e8c1e2 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Fri, 2 Feb 2024 15:26:33 +0100 Subject: [PATCH] ENH: additional constructors for triangle and triPoints STYLE: use Foam::zero{} in expression parsers --- .../indexedCell/indexedCellI.H | 4 +-- .../CompactListList/CompactListList.C | 2 +- .../CompactListList/CompactListListI.H | 14 ++++----- .../fields/fieldExprLemonParser.lyy-m4 | 4 +-- src/OpenFOAM/meshes/meshShapes/face/face.H | 2 +- src/OpenFOAM/meshes/meshShapes/face/faceI.H | 4 +-- .../meshes/meshShapes/triFace/triFace.H | 2 +- .../primitiveShapes/triangle/triangle.H | 22 +++++++++++-- .../primitiveShapes/triangle/triangleI.H | 31 ++++++++++++++++++- .../patch/patchExprLemonParser.lyy-m4 | 4 +-- .../volume/volumeExprLemonParser.lyy-m4 | 4 +-- 11 files changed, 70 insertions(+), 23 deletions(-) diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellI.H b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellI.H index 6ebf8ca3475..e5904be854e 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellI.H +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellI.H @@ -579,8 +579,8 @@ inline bool CGAL::indexedCell<Gt, Cb>::potentialCoplanarCell() const if (nMasters == 2 && nSlaves == 2) { - Foam::vector vp0(Foam::Zero); - Foam::vector vp1(Foam::Zero); + Foam::vector vp0(Foam::zero{}); + Foam::vector vp1(Foam::zero{}); if ( diff --git a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.C b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.C index cf451306676..0684c31d18c 100644 --- a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.C +++ b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.C @@ -81,7 +81,7 @@ Foam::CompactListList<T> Foam::CompactListList<T>::pack_impl if (len) { - newOffsets.resize(len+1, Zero); + newOffsets.resize(len+1, Foam::zero{}); for (label i = 0; i < len; ++i) { diff --git a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H index 5e5209fcb95..e5c76d8c855 100644 --- a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H +++ b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H @@ -89,7 +89,7 @@ inline Foam::CompactListList<T>::CompactListList const label nVals ) : - offsets_(mRows+1, Zero), + offsets_(mRows+1, Foam::zero{}), values_(nVals) { // Optionally: enforceSizeSanity(); @@ -104,8 +104,8 @@ inline Foam::CompactListList<T>::CompactListList const Foam::zero ) : - offsets_(mRows+1, Zero), - values_(nVals, Zero) + offsets_(mRows+1, Foam::zero{}), + values_(nVals, Foam::zero{}) { // Optionally: enforceSizeSanity(); } @@ -119,7 +119,7 @@ inline Foam::CompactListList<T>::CompactListList const T& val ) : - offsets_(mRows+1, Zero), + offsets_(mRows+1, Foam::zero{}), values_(nVals, val) { // Optionally: enforceSizeSanity(); @@ -378,7 +378,7 @@ inline void Foam::CompactListList<T>::resize } else { - offsets_.resize(mRows+1, Zero); + offsets_.resize(mRows+1, Foam::zero{}); values_.resize(nVals); } } @@ -399,7 +399,7 @@ inline void Foam::CompactListList<T>::resize_nocopy } else { - offsets_.resize(mRows+1, Zero); + offsets_.resize(mRows+1, Foam::zero{}); values_.resize_nocopy(nVals); } } @@ -421,7 +421,7 @@ inline void Foam::CompactListList<T>::resize } else { - offsets_.resize(mRows+1, Zero); + offsets_.resize(mRows+1, Foam::zero{}); values_.resize(nVals, val); } } diff --git a/src/OpenFOAM/expressions/fields/fieldExprLemonParser.lyy-m4 b/src/OpenFOAM/expressions/fields/fieldExprLemonParser.lyy-m4 index ce845dda4ab..678afef0c9f 100644 --- a/src/OpenFOAM/expressions/fields/fieldExprLemonParser.lyy-m4 +++ b/src/OpenFOAM/expressions/fields/fieldExprLemonParser.lyy-m4 @@ -7,7 +7,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -163,7 +163,7 @@ operator_precedence() svalue (lhs) ::= NUMBER (tok) . { lhs = (tok).scalarValue; } // scanToken -svalue (lhs) ::= ZERO . { lhs = Foam::Zero; } +svalue (lhs) ::= ZERO . { lhs = Foam::zero{}; } svalue (lhs) ::= PI LPAREN RPAREN . { lhs = Foam::constant::mathematical::pi; } svalue (lhs) ::= DEG_TO_RAD LPAREN RPAREN . { lhs = Foam::degToRad(); } svalue (lhs) ::= RAD_TO_DEG LPAREN RPAREN . { lhs = Foam::radToDeg(); } diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.H b/src/OpenFOAM/meshes/meshShapes/face/face.H index b103c0256e2..7d9a1bd170b 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.H +++ b/src/OpenFOAM/meshes/meshShapes/face/face.H @@ -395,7 +395,7 @@ public: // Face splitting utilities //- Number of triangles after splitting - inline label nTriangles() const; + inline label nTriangles() const noexcept; //- Number of triangles after splitting label nTriangles(const UList<point>& unused) const; diff --git a/src/OpenFOAM/meshes/meshShapes/face/faceI.H b/src/OpenFOAM/meshes/meshShapes/face/faceI.H index 320b05e6c7a..36c535a9ce6 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/faceI.H +++ b/src/OpenFOAM/meshes/meshShapes/face/faceI.H @@ -199,9 +199,9 @@ inline Foam::label Foam::face::prevLabel(const label i) const } -inline Foam::label Foam::face::nTriangles() const +inline Foam::label Foam::face::nTriangles() const noexcept { - return size() - 2; + return labelList::size() - 2; } diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H index cee935febc7..3145dca25ad 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H @@ -93,7 +93,7 @@ public: //- Construct from an initializer list of three vertex labels inline explicit triFace(std::initializer_list<label> list); - //- Copy construct from a list of three vertex labels. + //- Copy construct from a list of three vertex labels. inline explicit triFace(const labelUList& list); //- Copy construct from a subset of vertex labels diff --git a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H index 88693507abc..f9767cd3dbb 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H +++ b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangle.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -110,6 +110,15 @@ public: const FixedList<label, 3>& indices ); + //- Copy construct from subset of points + inline triPoints + ( + const UList<point>& points, + const label p0, + const label p1, + const label p2 + ); + // Member Functions @@ -275,7 +284,7 @@ public: //- Construct from three points inline triangle(const FixedList<Point, 3>& pts); - //- Construct from three points in the list of points + //- Construct from three points out of the list of points // The indices could be from triFace etc. inline triangle ( @@ -283,6 +292,15 @@ public: const FixedList<label, 3>& indices ); + //- Construct from three points out of the list of points + inline triangle + ( + const UList<Point>& points, + const label p0, + const label p1, + const label p2 + ); + //- Construct from Istream inline explicit triangle(Istream& is); diff --git a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H index 0c84feb0b46..1014b569621 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H +++ b/src/OpenFOAM/meshes/primitiveShapes/triangle/triangleI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2023 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -69,6 +69,20 @@ inline Foam::triPoints::triPoints {} +inline Foam::triPoints::triPoints +( + const UList<point>& points, + const label p0, + const label p1, + const label p2 +) +{ + a() = points[p0]; + b() = points[p1]; + c() = points[p2]; +} + + template<class Point, class PointRef> inline Foam::triangle<Point, PointRef>::triangle ( @@ -108,6 +122,21 @@ inline Foam::triangle<Point, PointRef>::triangle {} +template<class Point, class PointRef> +inline Foam::triangle<Point, PointRef>::triangle +( + const UList<Point>& points, + const label p0, + const label p1, + const label p2 +) +: + a_(points[p0]), + b_(points[p1]), + c_(points[p2]) +{} + + template<class Point, class PointRef> inline Foam::triangle<Point, PointRef>::triangle(Istream& is) { diff --git a/src/finiteVolume/expressions/patch/patchExprLemonParser.lyy-m4 b/src/finiteVolume/expressions/patch/patchExprLemonParser.lyy-m4 index 71b22356690..3251f09d225 100644 --- a/src/finiteVolume/expressions/patch/patchExprLemonParser.lyy-m4 +++ b/src/finiteVolume/expressions/patch/patchExprLemonParser.lyy-m4 @@ -7,7 +7,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -129,7 +129,7 @@ identifier (lhs) ::= IDENTIFIER (tok) . %type svalue { Foam::scalar } svalue (lhs) ::= NUMBER (tok) . { lhs = (tok).scalarValue; } // scanToken -svalue (lhs) ::= ZERO . { lhs = Foam::Zero; } +svalue (lhs) ::= ZERO . { lhs = Foam::zero{}; } svalue (lhs) ::= PI LPAREN RPAREN . { lhs = Foam::constant::mathematical::pi; } svalue (lhs) ::= DEG_TO_RAD LPAREN RPAREN . { lhs = Foam::degToRad(); } svalue (lhs) ::= RAD_TO_DEG LPAREN RPAREN . { lhs = Foam::radToDeg(); } diff --git a/src/finiteVolume/expressions/volume/volumeExprLemonParser.lyy-m4 b/src/finiteVolume/expressions/volume/volumeExprLemonParser.lyy-m4 index c280458f594..6b55f9787bf 100644 --- a/src/finiteVolume/expressions/volume/volumeExprLemonParser.lyy-m4 +++ b/src/finiteVolume/expressions/volume/volumeExprLemonParser.lyy-m4 @@ -7,7 +7,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2021 OpenCFD Ltd. + Copyright (C) 2019-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -170,7 +170,7 @@ identifier (lhs) ::= IDENTIFIER (tok) . %type svalue { Foam::scalar } svalue (lhs) ::= NUMBER (tok) . { lhs = (tok).scalarValue; } // scanToken -svalue (lhs) ::= ZERO . { lhs = Foam::Zero; } +svalue (lhs) ::= ZERO . { lhs = Foam::zero{}; } svalue (lhs) ::= PI LPAREN RPAREN . { lhs = Foam::constant::mathematical::pi; } svalue (lhs) ::= DEG_TO_RAD LPAREN RPAREN . { lhs = Foam::degToRad(); } svalue (lhs) ::= RAD_TO_DEG LPAREN RPAREN . { lhs = Foam::radToDeg(); } -- GitLab