From 8cbf55acad84c4096e07666c080b0d77bb0d848c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 28 Apr 2020 15:24:56 +0200 Subject: [PATCH] STYLE: reuse faceCentres if they already exist --- .../triSurfaceMesh/triSurfaceMesh.C | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C index 82dc592c6a..fadb41dab1 100644 --- a/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C +++ b/src/meshTools/searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C @@ -540,15 +540,26 @@ void Foam::triSurfaceMesh::clearOut() Foam::tmp Foam::triSurfaceMesh::coordinates() const { - auto tpts = tmp::New(8); + auto tpts = tmp::New(); auto& pts = tpts.ref(); - // Use copy to calculate face centres so they don't get stored - pts = PrimitivePatch - ( - SubList(*this, triSurface::size()), - triSurface::points() - ).faceCentres(); + if (triSurface::hasFaceCentres()) + { + // Can reuse existing values + pts = triSurface::faceCentres(); + } + else + { + typedef SubList FaceListType; + + // Calculate face centres from a copy to avoid incurring + // additional storage + pts = PrimitivePatch + ( + FaceListType(*this, triSurface::size()), + triSurface::points() + ).faceCentres(); + } return tpts; }