From dc8179f5e08d5e2b5245b8ccee700206d1bcd467 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Sun, 16 Dec 2018 14:21:45 +0100 Subject: [PATCH] ENH: add some storage queries to PrimitivePatch - for quantities such as face area/normals etc, it can be useful to calculate directly and avoid the overhead of caching all the values. STYLE: comments, use HashTable lookup() method in whichPoint() --- .../PrimitivePatch/PrimitivePatch.C | 13 +------ .../PrimitivePatch/PrimitivePatch.H | 37 +++++++++++-------- .../PrimitivePatch/PrimitivePatchAddressing.C | 3 +- .../PrimitivePatch/PrimitivePatchBdryPoints.C | 5 +-- .../PrimitivePatch/PrimitivePatchEdgeLoops.C | 3 +- .../PrimitivePatchLocalPointOrder.C | 3 +- .../PrimitivePatch/PrimitivePatchMeshData.C | 23 ++++-------- .../PrimitivePatchPointAddressing.C | 6 +-- 8 files changed, 39 insertions(+), 54 deletions(-) diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.C index 5cc8103d9c1..d82ca60a81a 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.C @@ -498,17 +498,8 @@ whichPoint const label gp ) const { - Map<label>::const_iterator fnd = meshPointMap().find(gp); - - if (fnd != meshPointMap().end()) - { - return fnd(); - } - else - { - // Not found - return -1; - } + // The point found, or -1 if not found + return meshPointMap().lookup(gp, -1); } diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.H b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.H index 893274dd25c..b98ceb52075 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.H +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatch.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 | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -152,8 +152,8 @@ private: //- Labels of mesh points mutable labelList* meshPointsPtr_; - //- Mesh point map. Given the global point index find its - //location in the patch + //- Mesh point map. Given the global point index find its + //- location in the patch mutable Map<label>* meshPointMapPtr_; //- Outside edge loops @@ -301,7 +301,7 @@ public: } - // Access functions for demand driven data + // Access functions for demand-driven data // Topological data; no mesh required. @@ -329,8 +329,7 @@ public: return edgei < nInternalEdges(); } - //- Return list of boundary points, - // address into LOCAL point list + //- Return list of boundary points, address into LOCAL point list const labelList& boundaryPoints() const; //- Return face-face addressing @@ -354,13 +353,13 @@ public: // Addressing into mesh - //- Return labelList of mesh points in patch. They are constructed - // walking through the faces in incremental order and not sorted - // anymore. + //- Return labelList of mesh points in patch. + // They are constructed by walking through the faces in + // incremental order and not sorted anymore. const labelList& meshPoints() const; - //- Mesh point map. Given the global point index find its - // location in the patch + //- Mesh point map. + // Given the global point index find its location in the patch const Map<label>& meshPointMap() const; //- Return pointField of points in patch @@ -374,11 +373,11 @@ public: label whichPoint(const label gp) const; //- Given an edge in local point labels, return its - // index in the edge list. If the edge is not found, return -1 + //- index in the edge list. If the edge is not found, return -1 label whichEdge(const edge&) const; //- Return labels of patch edges in the global edge list using - // cell addressing + //- cell addressing labelList meshEdges ( const edgeList& allEdges, @@ -387,7 +386,7 @@ public: ) const; //- Return labels of patch edges in the global edge list using - // basic edge addressing. + //- basic edge addressing. labelList meshEdges ( const edgeList& allEdges, @@ -410,6 +409,14 @@ public: const Field<PointType>& pointNormals() const; + // Storage Management + + inline bool hasFaceAreas() const { return faceAreasPtr_; } + inline bool hasFaceCentres() const { return faceCentresPtr_; } + inline bool hasFaceNormals() const { return faceNormalsPtr_; } + inline bool hasPointNormals() const { return pointNormalsPtr_; } + + // Other patch operations //- Project vertices of patch onto another patch @@ -475,7 +482,7 @@ public: virtual void movePoints(const Field<PointType>&); - // Member operators + // Member Operators //- Assignment void operator= diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchAddressing.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchAddressing.C index bbfcad9f2da..f95ecfe35fb 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchAddressing.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchAddressing.C @@ -60,8 +60,7 @@ calcAddressing() const if (edgesPtr_ || faceFacesPtr_ || edgeFacesPtr_ || faceEdgesPtr_) { - // it is considered an error to attempt to recalculate - // if already allocated + // An error to recalculate if already allocated FatalErrorInFunction << "addressing already calculated" << abort(FatalError); diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchBdryPoints.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchBdryPoints.C index 96516bfa096..01e4e69662e 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchBdryPoints.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchBdryPoints.C @@ -46,10 +46,9 @@ calcBdryPoints() const if (boundaryPointsPtr_) { - // it is considered an error to attempt to recalculate - // if already allocated + // Error to recalculate if already allocated FatalErrorInFunction - << "edge types already calculated" + << "boundaryPoints already calculated" << abort(FatalError); } diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchEdgeLoops.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchEdgeLoops.C index 48094cce32c..1e0ccb4f438 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchEdgeLoops.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchEdgeLoops.C @@ -50,8 +50,7 @@ calcEdgeLoops() const if (edgeLoopsPtr_) { - // it is considered an error to attempt to recalculate - // if already allocated + // An error to recalculate if already allocated FatalErrorInFunction << "edge loops already calculated" << abort(FatalError); diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchLocalPointOrder.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchLocalPointOrder.C index 2a6ab9621a4..235c1fec65e 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchLocalPointOrder.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchLocalPointOrder.C @@ -56,8 +56,7 @@ calcLocalPointOrder() const if (localPointOrderPtr_) { - // it is considered an error to attempt to recalculate - // if already allocated + // An error to recalculate if already allocated FatalErrorInFunction << "local point order already calculated" << abort(FatalError); diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchMeshData.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchMeshData.C index 9a76270169c..9e4fab24058 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchMeshData.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchMeshData.C @@ -47,10 +47,9 @@ calcMeshData() const << endl; } - // It is considered an error to attempt to recalculate meshPoints - // if they have already been calculated. if (meshPointsPtr_ || localFacesPtr_) { + // An error to recalculate if already allocated FatalErrorInFunction << "meshPointsPtr_ or localFacesPtr_ already allocated" << abort(FatalError); @@ -157,10 +156,9 @@ calcMeshPointMap() const << endl; } - // It is considered an error to attempt to recalculate meshPoints - // if they have already been calculated. if (meshPointMapPtr_) { + // An error to recalculate if already allocated FatalErrorInFunction << "meshPointMapPtr_ already allocated" << abort(FatalError); @@ -205,10 +203,9 @@ calcLocalPoints() const << endl; } - // It is considered an error to attempt to recalculate localPoints - // if they have already been calculated. if (localPointsPtr_) { + // An error to recalculate if already allocated FatalErrorInFunction << "localPointsPtr_ already allocated" << abort(FatalError); @@ -254,10 +251,9 @@ calcPointNormals() const << endl; } - // It is considered an error to attempt to recalculate pointNormals - // if they have already been calculated. if (pointNormalsPtr_) { + // An error to recalculate if already allocated FatalErrorInFunction << "pointNormalsPtr_ already allocated" << abort(FatalError); @@ -318,10 +314,9 @@ calcFaceCentres() const << endl; } - // It is considered an error to attempt to recalculate faceCentres - // if they have already been calculated. if (faceCentresPtr_) { + // An error to recalculate if already allocated FatalErrorInFunction << "faceCentresPtr_ already allocated" << abort(FatalError); @@ -365,9 +360,9 @@ calcMagFaceAreas() const << endl; } - // It is an error to calculate these more than once. if (magFaceAreasPtr_) { + // An error to recalculate if already allocated FatalErrorInFunction << "magFaceAreasPtr_ already allocated" << abort(FatalError); @@ -410,10 +405,9 @@ calcFaceAreas() const << endl; } - // It is considered an error to attempt to recalculate faceNormals - // if they have already been calculated. if (faceAreasPtr_) { + // An error to recalculate if already allocated FatalErrorInFunction << "faceAreasPtr_ already allocated" << abort(FatalError); @@ -457,10 +451,9 @@ calcFaceNormals() const << endl; } - // It is considered an error to attempt to recalculate faceNormals - // if they have already been calculated. if (faceNormalsPtr_) { + // An error to recalculate if already allocated FatalErrorInFunction << "faceNormalsPtr_ already allocated" << abort(FatalError); diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchPointAddressing.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchPointAddressing.C index 212396e419b..3e11f57425a 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchPointAddressing.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchPointAddressing.C @@ -51,8 +51,7 @@ calcPointEdges() const if (pointEdgesPtr_) { - // it is considered an error to attempt to recalculate - // if already allocated + // An error to recalculate if already allocated FatalErrorInFunction << "pointEdges already calculated" << abort(FatalError); @@ -89,8 +88,7 @@ calcPointFaces() const if (pointFacesPtr_) { - // it is considered an error to attempt to recalculate - // if already allocated + // An error to recalculate if already allocated FatalErrorInFunction << "pointFaces already calculated" << abort(FatalError); -- GitLab