From 0c4d2bcd76b098a09e3fd16668a8c46aeb15988b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 7 May 2017 15:49:52 +0200 Subject: [PATCH 01/17] ENH: improve consistency in access for face, triFace, edge. - ensure that each have found() and which() methods - add faceTraits for handling compile-time differences between 'normal' and tri-faces - provide line::unitVec method (complimentary to edge::unitVec) --- src/OpenFOAM/containers/Lists/UList/UList.C | 2 + src/OpenFOAM/meshes/meshShapes/edge/edge.H | 6 +- src/OpenFOAM/meshes/meshShapes/edge/edgeI.H | 22 +++++- src/OpenFOAM/meshes/meshShapes/face/face.H | 7 +- src/OpenFOAM/meshes/meshShapes/face/faceI.H | 12 ++- .../meshes/meshShapes/traits/faceTraits.H | 73 +++++++++++++++++++ .../meshes/meshShapes/triFace/triFace.H | 9 ++- .../meshes/meshShapes/triFace/triFaceI.H | 17 ++++- .../meshes/primitiveShapes/line/line.H | 9 ++- .../meshes/primitiveShapes/line/lineI.H | 10 +++ 10 files changed, 153 insertions(+), 14 deletions(-) create mode 100644 src/OpenFOAM/meshes/meshShapes/traits/faceTraits.H diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C index f3feb5b835..f479698744 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.C +++ b/src/OpenFOAM/containers/Lists/UList/UList.C @@ -112,6 +112,7 @@ Foam::UList Foam::UList::operator[](const labelRange& range) return UList(&(this->v_[slice.start()]), slice.size()); // SubList } + template const Foam::UList Foam::UList::operator[](const labelRange& range) const { @@ -132,6 +133,7 @@ Foam::UList Foam::UList::operator[] return UList(&(this->v_[slice.start()]), slice.size()); // SubList } + template const Foam::UList Foam::UList::operator[] ( diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edge.H b/src/OpenFOAM/meshes/meshShapes/edge/edge.H index 52bf97cb7c..aecb9a9c2e 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edge.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edge.H @@ -149,7 +149,11 @@ public: //- Return true if point label is found in edge. // Always false for a negative label. - inline bool found(const label index) const; + inline bool found(const label pointLabel) const; + + //- Return local index (0,1) of point label in edge -1 on failure + // Always return -1 for a negative label. + inline label which(const label pointLabel) const; //- Do the edges share a common vertex index? // Negative point labels never connect. diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H index 75a5ba2365..e4ca81e938 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H @@ -206,10 +206,28 @@ inline Foam::label Foam::edge::maxVertex() const } -inline bool Foam::edge::found(const label index) const +inline bool Foam::edge::found(const label pointLabel) const { // -1: always false - return (index >= 0 && (index == start() || index == end())); + return (pointLabel >= 0 && (pointLabel == start() || pointLabel == end())); +} + + +inline Foam::label Foam::edge::which(const label pointLabel) const +{ + // -1: always false + if (pointLabel >= 0) + { + if (pointLabel == start()) + { + return 0; + } + if (pointLabel == end()) + { + return 1; + } + } + return -1; } diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.H b/src/OpenFOAM/meshes/meshShapes/face/face.H index 2d83def920..822e3c4f9a 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.H +++ b/src/OpenFOAM/meshes/meshShapes/face/face.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -202,7 +202,10 @@ public: //- Navigation through face vertices - //- Which vertex on face (face index given a global index) + //- Return true if the global point label is found in face. + inline bool found(const label globalIndex) const; + + //- Which local vertex on face given a global index. // returns -1 if not found label which(const label globalIndex) const; diff --git a/src/OpenFOAM/meshes/meshShapes/face/faceI.H b/src/OpenFOAM/meshes/meshShapes/face/faceI.H index b45193f0e7..ce807528c6 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/faceI.H +++ b/src/OpenFOAM/meshes/meshShapes/face/faceI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -116,20 +116,24 @@ inline Foam::edge Foam::face::faceEdge(const label n) const } -// Next vertex on face +inline bool Foam::face::found(const label globalIndex) const +{ + return which(globalIndex) != -1; +} + + inline Foam::label Foam::face::nextLabel(const label i) const { return operator[](fcIndex(i)); } -// Previous vertex on face inline Foam::label Foam::face::prevLabel(const label i) const { return operator[](rcIndex(i)); } -// Number of triangles directly known from number of vertices + inline Foam::label Foam::face::nTriangles() const { return size() - 2; diff --git a/src/OpenFOAM/meshes/meshShapes/traits/faceTraits.H b/src/OpenFOAM/meshes/meshShapes/traits/faceTraits.H new file mode 100644 index 0000000000..523233a569 --- /dev/null +++ b/src/OpenFOAM/meshes/meshShapes/traits/faceTraits.H @@ -0,0 +1,73 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +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::faceTraits + +Description + Traits class for faces + +\*---------------------------------------------------------------------------*/ + +#ifndef faceTraits_H +#define faceTraits_H + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declarations +class triFace; +class labelledTri; + +/*---------------------------------------------------------------------------*\ + Class faceTraits Declaration +\*---------------------------------------------------------------------------*/ + +template +class faceTraits +{ +public: + + //- Face-type only handles triangles. Not true in general. + inline static bool isTri() { return false; } +}; + + +template<> +inline bool faceTraits::isTri() { return true; } + +template<> +inline bool faceTraits::isTri() { return true; } + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H index e0e586673a..301b845d11 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -137,6 +137,13 @@ public: // The starting points of the original and reverse face are identical. inline triFace reverseFace() const; + //- Return true if the global point label is found in face. + bool found(const label globalIndex) const; + + //- Which local index (0,1,2) on face given a global index. + // returns -1 if not found + label which(const label globalIndex) const; + //- Return swept-volume from old-points to new-points inline scalar sweptVol ( diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H index 69d2a4033b..ae2545a7aa 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -209,6 +209,21 @@ inline Foam::triFace Foam::triFace::reverseFace() const } +inline bool Foam::triFace::found(const label globalIndex) const +{ + return which(globalIndex) != -1; +} + + +inline Foam::label Foam::triFace::which(const label globalIndex) const +{ + if (operator[](0) == globalIndex) return 0; + if (operator[](1) == globalIndex) return 1; + if (operator[](2) == globalIndex) return 2; + return -1; +} + + inline Foam::scalar Foam::triFace::sweptVol ( const UList& opts, diff --git a/src/OpenFOAM/meshes/primitiveShapes/line/line.H b/src/OpenFOAM/meshes/primitiveShapes/line/line.H index 74bc680134..778a843ba7 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/line/line.H +++ b/src/OpenFOAM/meshes/primitiveShapes/line/line.H @@ -98,10 +98,10 @@ public: // Access - //- Return first vertex + //- Return first point inline PointRef start() const; - //- Return second vertex + //- Return second point inline PointRef end() const; @@ -113,9 +113,12 @@ public: //- Return scalar magnitude inline scalar mag() const; - //- Return start-end vector + //- Return start-to-end vector inline Point vec() const; + //- Return the unit vector (start-to-end) + inline Point unitVec() const; + //- Return nearest distance to line from a given point // If the nearest point is on the line, return a hit PointHit nearestDist(const Point& p) const; diff --git a/src/OpenFOAM/meshes/primitiveShapes/line/lineI.H b/src/OpenFOAM/meshes/primitiveShapes/line/lineI.H index 2dfca1e1c2..c4757716cf 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/line/lineI.H +++ b/src/OpenFOAM/meshes/primitiveShapes/line/lineI.H @@ -90,6 +90,16 @@ inline Point Foam::line::vec() const } +template +inline Point Foam::line::unitVec() const +{ + Point v = b_ - a_; + v /= ::Foam::mag(v) + VSMALL; + + return v; +} + + template Foam::PointHit Foam::line::nearestDist ( From b4f6484ddfd9c9011cdff7e04b3d9957536139a0 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 7 May 2017 16:58:44 +0200 Subject: [PATCH 02/17] ENH: use faceTraits for managing differences between face representations --- src/surfMesh/MeshedSurface/MeshedSurface.C | 64 +++++++---- src/surfMesh/MeshedSurface/MeshedSurface.H | 47 ++++---- .../MeshedSurface/MeshedSurfaceCore.C | 6 +- src/surfMesh/MeshedSurface/MeshedSurfaceI.H | 103 ------------------ src/surfMesh/MeshedSurface/MeshedSurfaceIO.C | 7 +- src/surfMesh/MeshedSurface/MeshedSurfaceNew.C | 5 +- .../MeshedSurfaceProxy/MeshedSurfaceProxy.C | 58 +++++----- .../MeshedSurfaceProxy/MeshedSurfaceProxy.H | 30 +++-- .../UnsortedMeshedSurface.C | 7 +- .../UnsortedMeshedSurfaceNew.C | 5 +- .../surfaceFormats/ac3d/AC3DsurfaceFormat.C | 9 +- .../surfaceFormats/gts/GTSsurfaceFormat.C | 12 +- .../surfaceFormats/nas/NASsurfaceFormat.C | 33 +++--- .../surfaceFormats/obj/OBJsurfaceFormat.C | 8 +- .../surfaceFormats/off/OFFsurfaceFormat.C | 10 +- .../starcd/STARCDsurfaceFormat.C | 5 +- .../surfaceFormats/stl/STLsurfaceFormat.C | 4 +- .../surfaceFormats/tri/TRIsurfaceFormat.C | 6 +- .../surfaceFormats/vtk/VTKsurfaceFormat.C | 7 +- 19 files changed, 178 insertions(+), 248 deletions(-) delete mode 100644 src/surfMesh/MeshedSurface/MeshedSurfaceI.H diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.C b/src/surfMesh/MeshedSurface/MeshedSurface.C index 0606860e64..41d0418a3b 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.C +++ b/src/surfMesh/MeshedSurface/MeshedSurface.C @@ -33,24 +33,17 @@ License #include "polyMesh.H" #include "surfMesh.H" #include "primitivePatch.H" +#include "faceTraits.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -template -inline bool Foam::MeshedSurface::isTri() -{ - return false; -} - - template Foam::wordHashSet Foam::MeshedSurface::readTypes() { return wordHashSet(*fileExtensionConstructorTablePtr_); } - template Foam::wordHashSet Foam::MeshedSurface::writeTypes() { @@ -116,25 +109,34 @@ void Foam::MeshedSurface::write const fileName& name, const MeshedSurface& surf ) +{ + write(name, name.ext(), surf); +} + + +template +void Foam::MeshedSurface::write +( + const fileName& name, + const word& ext, + const MeshedSurface& surf +) { if (debug) { InfoInFunction << "Writing to " << name << endl; } - const word ext = name.ext(); + auto mfIter = writefileExtensionMemberFunctionTablePtr_->find(ext); - typename writefileExtensionMemberFunctionTable::iterator mfIter = - writefileExtensionMemberFunctionTablePtr_->find(ext); - - if (mfIter == writefileExtensionMemberFunctionTablePtr_->end()) + if (!mfIter.found()) { // No direct writer, delegate to proxy if possible const wordHashSet& delegate = ProxyType::writeTypes(); if (delegate.found(ext)) { - MeshedSurfaceProxy(surf).write(name); + MeshedSurfaceProxy(surf).write(name, ext); } else { @@ -850,6 +852,11 @@ bool Foam::MeshedSurface::checkFaces template Foam::label Foam::MeshedSurface::nTriangles() const { + if (faceTraits::isTri()) + { + return ParentType::size(); + } + return nTriangles ( const_cast&>(List