STYLE: reuse faceCentres if they already exist

This commit is contained in:
Mark Olesen
2020-04-28 15:24:56 +02:00
parent cc7af66a15
commit 8cbf55acad

View File

@ -540,15 +540,26 @@ void Foam::triSurfaceMesh::clearOut()
Foam::tmp<Foam::pointField> Foam::triSurfaceMesh::coordinates() const Foam::tmp<Foam::pointField> Foam::triSurfaceMesh::coordinates() const
{ {
auto tpts = tmp<pointField>::New(8); auto tpts = tmp<pointField>::New();
auto& pts = tpts.ref(); auto& pts = tpts.ref();
// Use copy to calculate face centres so they don't get stored if (triSurface::hasFaceCentres())
pts = PrimitivePatch<triSurface::FaceType, SubList, const pointField&> {
( // Can reuse existing values
SubList<triSurface::FaceType>(*this, triSurface::size()), pts = triSurface::faceCentres();
triSurface::points() }
).faceCentres(); else
{
typedef SubList<labelledTri> FaceListType;
// Calculate face centres from a copy to avoid incurring
// additional storage
pts = PrimitivePatch<labelledTri, SubList, const pointField&>
(
FaceListType(*this, triSurface::size()),
triSurface::points()
).faceCentres();
}
return tpts; return tpts;
} }