From 2990b14d89edbed157b51a1c8b1c90cff7cbec45 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 20 May 2021 09:52:53 +0200 Subject: [PATCH] ENH: add more direct methods for getting meshEdge (PrimitivePatch) - refine definition of patch boundary faces to distinguish between boundaryFaces() and uniqBoundaryFaces(). * boundaryFaces() for edge to face lookup on boundary edges. * uniqBoundaryFaces() for accessing quantities such as face areas or eroding an outer layer ENH: LabelledItem container, replaces unused 'Keyed' container - method names in alignment with objectHit, pointIndexHit etc. Top-level name aligns with labelledTri. --- applications/test/LabelledItem/Make/files | 3 + applications/test/LabelledItem/Make/options | 2 + .../test/LabelledItem/Test-LabelledItem.C | 74 ++++++++ .../test/primitivePatch/Test-PrimitivePatch.C | 5 +- .../containers/Identifiers/Keyed/Keyed.H | 133 -------------- .../containers/Identifiers/Keyed/KeyedI.H | 139 -------------- .../Identifiers/LabelledItem/LabelledItem.H | 172 ++++++++++++++++++ .../Identifiers/LabelledItem/LabelledItemI.H | 66 +++++++ .../meshShapes/labelledTri/labelledTri.H | 77 +++++--- .../meshShapes/labelledTri/labelledTriI.H | 53 +++--- .../PatchTools/PatchToolsMatch.C | 48 +++-- .../PrimitivePatch/PrimitivePatch.H | 47 ++++- .../PrimitivePatch/PrimitivePatchBdryFaces.C | 55 +++++- .../PrimitivePatch/PrimitivePatchMeshEdges.C | 112 ++++++++---- .../primitiveShapes/objectHit/PointIndexHit.H | 2 +- 15 files changed, 578 insertions(+), 410 deletions(-) create mode 100644 applications/test/LabelledItem/Make/files create mode 100644 applications/test/LabelledItem/Make/options create mode 100644 applications/test/LabelledItem/Test-LabelledItem.C delete mode 100644 src/OpenFOAM/containers/Identifiers/Keyed/Keyed.H delete mode 100644 src/OpenFOAM/containers/Identifiers/Keyed/KeyedI.H create mode 100644 src/OpenFOAM/containers/Identifiers/LabelledItem/LabelledItem.H create mode 100644 src/OpenFOAM/containers/Identifiers/LabelledItem/LabelledItemI.H diff --git a/applications/test/LabelledItem/Make/files b/applications/test/LabelledItem/Make/files new file mode 100644 index 0000000000..b01e4b4fe9 --- /dev/null +++ b/applications/test/LabelledItem/Make/files @@ -0,0 +1,3 @@ +Test-LabelledItem.C + +EXE = $(FOAM_USER_APPBIN)/Test-LabelledItem diff --git a/applications/test/LabelledItem/Make/options b/applications/test/LabelledItem/Make/options new file mode 100644 index 0000000000..18e6fe47af --- /dev/null +++ b/applications/test/LabelledItem/Make/options @@ -0,0 +1,2 @@ +/* EXE_INC = */ +/* EXE_LIBS = */ diff --git a/applications/test/LabelledItem/Test-LabelledItem.C b/applications/test/LabelledItem/Test-LabelledItem.C new file mode 100644 index 0000000000..79ef7ca46b --- /dev/null +++ b/applications/test/LabelledItem/Test-LabelledItem.C @@ -0,0 +1,74 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Description + Test LabelledItem (formerly 'Keyed', but that was never used) + +\*---------------------------------------------------------------------------*/ + +#include "IOstreams.H" +#include "IOobject.H" +#include "IFstream.H" +#include "edge.H" +#include "LabelledItem.H" +#include "List.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + typedef LabelledItem labelledEdge; + + List edges(10); + + forAll(edges, edgei) + { + auto& e = edges[edgei]; + + e.insert(20-edgei); + e.insert(edgei); + + if (!(edgei % 3)) + { + e.setIndex(edgei); + } + } + + Info<< "edges: " << edges << nl; + + Foam::sort(edges); + + Info<< "sorted: " << edges << nl; + + Info<< "\nEnd\n" << endl; + + return 0; +} + + +// ************************************************************************* // diff --git a/applications/test/primitivePatch/Test-PrimitivePatch.C b/applications/test/primitivePatch/Test-PrimitivePatch.C index e53f81b409..86a6b5060c 100644 --- a/applications/test/primitivePatch/Test-PrimitivePatch.C +++ b/applications/test/primitivePatch/Test-PrimitivePatch.C @@ -244,9 +244,10 @@ int main(int argc, char *argv[]) writeFaceFaces(localPoints, localFaces, faceFaces); - const labelList bndFaceIds(pp.boundaryFaces()); + const labelList bndFaceIds(pp.uniqBoundaryFaces()); - Info<< "Have: " << bndFaceIds.size() << " boundary faces" << nl; + Info<< "Have: " << bndFaceIds.size() + << " unique boundary faces" << nl; // Can calculate by hand if (!pp.hasFaceCentres()) diff --git a/src/OpenFOAM/containers/Identifiers/Keyed/Keyed.H b/src/OpenFOAM/containers/Identifiers/Keyed/Keyed.H deleted file mode 100644 index e609c2940f..0000000000 --- a/src/OpenFOAM/containers/Identifiers/Keyed/Keyed.H +++ /dev/null @@ -1,133 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | www.openfoam.com - \\/ M anipulation | -------------------------------------------------------------------------------- - Copyright (C) 2011-2016 OpenFOAM Foundation -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -Class - Foam::Keyed - -Description - A container with an integer key attached to any item. - - The key can useful for sorting. - -SourceFiles - KeyedI.H - -\*---------------------------------------------------------------------------*/ - -#ifndef Keyed_H -#define Keyed_H - -#include "List.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// Forward declaration of friend functions and operators - -template class Keyed; - -template Istream& operator>>(Istream&, Keyed&); -template Ostream& operator<<(Ostream&, const Keyed&); - -/*---------------------------------------------------------------------------*\ - Class Keyed Declaration -\*---------------------------------------------------------------------------*/ - -template -class Keyed -: - public T -{ - // Private data - - label key_; - -public: - - // Static Members - - //- Add labels to a list of values - inline static List> createList - ( - const UList& lst, - const label key=0 - ); - - //- Add labels to a list of values - inline static List> createList - ( - const UList& lst, - const labelUList& keys - ); - - - // Constructors - - //- Construct null - inline Keyed(); - - //- Copy construct item, with a key - inline Keyed(const T& item, const label key=0); - - //- Move construct item, with a key - inline Keyed(T&& item, const label key=0); - - //- Construct from Istream - inline Keyed(Istream& is); - - - // Member Functions - - // Access - - //- Return const access to the integer key - inline label key() const; - - //- Return non-const access to the integer key - inline label& key(); - - - // IOstream Operators - - friend Istream& operator>> (Istream&, Keyed&); - friend Ostream& operator<< (Ostream&, const Keyed&); -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#include "KeyedI.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/OpenFOAM/containers/Identifiers/Keyed/KeyedI.H b/src/OpenFOAM/containers/Identifiers/Keyed/KeyedI.H deleted file mode 100644 index 93aca20ed8..0000000000 --- a/src/OpenFOAM/containers/Identifiers/Keyed/KeyedI.H +++ /dev/null @@ -1,139 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | www.openfoam.com - \\/ M anipulation | -------------------------------------------------------------------------------- - Copyright (C) 2011-2016 OpenFOAM Foundation -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "IOstreams.H" - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template -inline Foam::Keyed::Keyed() -: - key_(-1) -{} - - -template -inline Foam::Keyed::Keyed(const T& item, const label key) -: - T(item), - key_(key) -{} - - -template -inline Foam::Keyed::Keyed(T&& item, const label key) -: - T(std::move(item)), - key_(key) -{} - - -template -inline Foam::Keyed::Keyed(Istream& is) -{ - is >> *this; -} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -inline Foam::label Foam::Keyed::key() const -{ - return key_; -} - -template -inline Foam::label& Foam::Keyed::key() -{ - return key_; -} - - -template -inline Foam::List> -Foam::Keyed::createList(const UList& lst, const label key) -{ - List> newList(lst.size()); - - forAll(lst, elemI) - { - newList[elemI] = Keyed(lst[elemI], key); - } - return newList; -} - - -template -inline Foam::List> -Foam::Keyed::createList(const UList& lst, const labelUList& keys) -{ - if (lst.size() != keys.size()) - { - FatalErrorInFunction - << "size mismatch adding keys to a list:" << nl - << "List has size " << lst.size() - << " and keys has size " << keys.size() << nl - << abort(FatalError); - } - - List> newList(lst.size()); - - forAll(lst, elemI) - { - newList[elemI] = Keyed(lst[elemI], keys[elemI]); - } - return newList; -} - - -// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // - -template -inline Foam::Istream& Foam::operator>>(Istream& is, Keyed& item) -{ - is.readBegin("Keyed"); - is >> static_cast(item) >> item.key_; - is.readEnd("Keyed"); - - is.check(FUNCTION_NAME); - return is; -} - - -template -inline Foam::Ostream& Foam::operator<<(Ostream& os, const Keyed& item) -{ - os << token::BEGIN_LIST - << static_cast(item) << token::SPACE << item.key_ - << token::END_LIST; - - return os; -} - - -// ************************************************************************* // diff --git a/src/OpenFOAM/containers/Identifiers/LabelledItem/LabelledItem.H b/src/OpenFOAM/containers/Identifiers/LabelledItem/LabelledItem.H new file mode 100644 index 0000000000..6d9fc14295 --- /dev/null +++ b/src/OpenFOAM/containers/Identifiers/LabelledItem/LabelledItem.H @@ -0,0 +1,172 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::LabelledItem + +Description + A container with an integer index that can be attached to any item. + The index may be useful for sorting or storing additional information. + +SeeAlso + Foam::objectHit + Foam::PointIndexHit + +SourceFiles + LabelledItemI.H + +\*---------------------------------------------------------------------------*/ + +#ifndef LabelledItem_H +#define LabelledItem_H + +#include "label.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward Declarations +template class LabelledItem; +template Istream& operator>>(Istream&, LabelledItem&); +template Ostream& operator<<(Ostream&, const LabelledItem&); + +/*---------------------------------------------------------------------------*\ + Class LabelledItem Declaration +\*---------------------------------------------------------------------------*/ + +template +class LabelledItem +: + public T +{ + // Private Data + + //- The object index + label index_; + + +public: + + + // Constructors + + //- Default construct item, with index = -1 + LabelledItem() + : + T(), + index_(-1) + {} + + //- Copy construct item, with index = -1 + explicit LabelledItem(const T& item) + : + T(item), + index_(-1) + {} + + //- Move construct item, with index = -1 + explicit LabelledItem(T&& item) + : + T(std::move(item)), + index_(-1) + {} + + //- Construct from components + LabelledItem(const T& item, label idx) + : + T(item), + index_(idx) + {} + + //- Construct from Istream + explicit LabelledItem(Istream& is) + { + is >> *this; + } + + + // Member Functions + + //- Return the index + label index() const noexcept + { + return index_; + } + + //- Non-const access to the index + label& index() noexcept + { + return index_; + } + + //- Set the index + void setIndex(const label idx) noexcept + { + index_ = idx; + } + + + // Member Operators + + //- Test for equality of components + bool operator==(const LabelledItem& rhs) const + { + return + ( + index_ == rhs.index_ + && static_cast(*this) == static_cast(rhs) + ); + } + + //- Test for inequality of components + bool operator!=(const LabelledItem& rhs) const + { + return !(*this == rhs); + } + + + // IOstream Operators + + friend Istream& operator>> (Istream&, LabelledItem&); + friend Ostream& operator<< (Ostream&, const LabelledItem&); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "LabelledItemI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/containers/Identifiers/LabelledItem/LabelledItemI.H b/src/OpenFOAM/containers/Identifiers/LabelledItem/LabelledItemI.H new file mode 100644 index 0000000000..d4061413ac --- /dev/null +++ b/src/OpenFOAM/containers/Identifiers/LabelledItem/LabelledItemI.H @@ -0,0 +1,66 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2011 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "IOstreams.H" + +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + +template +inline Foam::Istream& Foam::operator>> +( + Istream& is, + LabelledItem& item +) +{ + is.readBegin("LabelledItem"); + is >> static_cast(item) >> item.index(); + is.readEnd("LabelledItem"); + + is.check(FUNCTION_NAME); + return is; +} + + +template +inline Foam::Ostream& Foam::operator<< +( + Ostream& os, + const LabelledItem& item +) +{ + // Output like Tuple2 + os << token::BEGIN_LIST + << static_cast(item) << token::SPACE + << item.index() + << token::END_LIST; + + return os; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/meshes/meshShapes/labelledTri/labelledTri.H b/src/OpenFOAM/meshes/meshShapes/labelledTri/labelledTri.H index 0d0f20985b..4ce38cc5a0 100644 --- a/src/OpenFOAM/meshes/meshShapes/labelledTri/labelledTri.H +++ b/src/OpenFOAM/meshes/meshShapes/labelledTri/labelledTri.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,7 +28,7 @@ Class Foam::labelledTri Description - Triangle with additional region number. + A triFace with additional (region) index. SourceFiles labelledTriI.H @@ -52,7 +52,7 @@ inline Istream& operator>>(Istream&, labelledTri&); inline Ostream& operator<<(Ostream&, const labelledTri&); /*---------------------------------------------------------------------------*\ - Class labelledTri Declaration + Class labelledTri Declaration \*---------------------------------------------------------------------------*/ class labelledTri @@ -61,14 +61,16 @@ class labelledTri { // Private Data - label region_; + //- The object index (region) + label index_; // Private Member Functions - //- Assign from a list of 3 or 4 labels. - // Default region is 0. - inline void assign(const labelUList&); + //- Assign from 3 or 4 labels, default region is 0. + template + inline void assignList(const ListType& list); + public: @@ -77,16 +79,16 @@ public: //- Default construct, with invalid point labels and region (-1). inline labelledTri(); - //- Construct from triFace and region label. - // Default region is 0 if not specified. + //- Construct from triFace + //- and optional region index (0 if unspecified) inline labelledTri ( - const triFace&, + const triFace& tri, const label region = 0 ); - //- Construct from three point labels and a region label. - // Default region is 0 if not specified. + //- Construct from three point labels + //- and optional region index (0 if unspecified) inline labelledTri ( const label a, @@ -95,26 +97,47 @@ public: const label region = 0 ); - //- Construct from a list of 3 or 4 labels. - // Default region is 0. - inline explicit labelledTri(const labelUList&); + //- Construct from a list of 3 or 4 labels. Default region is 0. + inline explicit labelledTri(const labelUList& list); - //- Construct from an initializer list of 3 or 4 labels. + //- Construct from a list of 3 or 4 labels. Default region is 0. inline explicit labelledTri(std::initializer_list