From fb9f93dd7ca430ef4b5972dcff06c3ecfd8a896b Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 20 Oct 2016 08:36:02 +0200 Subject: [PATCH] ENH: propogate face area support into surface-type meshes (issue #266) * MeshedSurface / surfMesh / triSurface - use shorter method names similar to those from volume meshes: Sf(), magSf(), Cf() instead of the longer ones from PrimitivePatch: faceAreas(), magFaceAreas(), faceCentres() - similar names throughout to ease switching between triSurface and MeshedSurface storage. --- .../surfaceMeshConvertTesting.C | 24 ++++++++++----- src/surfMesh/MeshedSurface/MeshedSurface.C | 16 ++++++---- src/surfMesh/MeshedSurface/MeshedSurface.H | 30 +++++++++++++++---- src/surfMesh/surfMesh/surfMesh.H | 19 ++++++++++++ src/surfMesh/surfMesh/surfMeshClear.C | 4 ++- src/surfMesh/surfMesh/surfMeshIO.C | 2 +- src/triSurface/triSurface/triSurface.H | 19 ++++++++++++ 7 files changed, 94 insertions(+), 20 deletions(-) diff --git a/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C b/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C index e0dcfcf0cc..edb8527698 100644 --- a/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C +++ b/applications/utilities/surface/surfaceMeshConvertTesting/surfaceMeshConvertTesting.C @@ -161,7 +161,8 @@ int main(int argc, char *argv[]) Info<< "Read surface:" << endl; surf.writeStats(Info); - Info<< endl; + Info<< "Area : " << sum(surf.magSf()) << nl + << endl; // check: output to ostream, construct from istream { @@ -205,7 +206,8 @@ int main(int argc, char *argv[]) Info<< " with scaling " << scaleFactor << endl; surf.scalePoints(scaleFactor); surf.writeStats(Info); - Info<< endl; + Info<< "Area : " << sum(surf.magSf()) << nl + << endl; } if (optStdout) @@ -224,7 +226,8 @@ int main(int argc, char *argv[]) Info<< "Read surface:" << endl; surf.writeStats(Info); - Info<< endl; + Info<< "Area : " << sum(surf.magSf()) << nl + << endl; // check: output to ostream, construct from istream { @@ -268,7 +271,8 @@ int main(int argc, char *argv[]) Info<< " with scaling " << scaleFactor << endl; surf.scalePoints(scaleFactor); surf.writeStats(Info); - Info<< endl; + Info<< "Area : " << sum(surf.magSf()) << nl + << endl; } if (optStdout) @@ -286,7 +290,8 @@ int main(int argc, char *argv[]) Info<< "Read surface:" << endl; surf.writeStats(Info); - Info<< endl; + Info<< "Area : " << sum(surf.magSf()) << nl + << endl; // check: output to ostream, construct from istream { @@ -330,7 +335,8 @@ int main(int argc, char *argv[]) Info<< " with scaling " << scaleFactor << endl; surf.scalePoints(scaleFactor); surf.writeStats(Info); - Info<< endl; + Info<< "Area : " << sum(surf.magSf()) << nl + << endl; } if (optStdout) @@ -348,7 +354,8 @@ int main(int argc, char *argv[]) Info<< "Read surface:" << endl; surf.writeStats(Info); - Info<< endl; + Info<< "Area : " << sum(surf.magSf()) << nl + << endl; // check: output to ostream, construct from istream { @@ -392,7 +399,8 @@ int main(int argc, char *argv[]) Info<< " with scaling " << scaleFactor << endl; surf.scalePoints(scaleFactor); surf.writeStats(Info); - Info<< endl; + Info<< "Area : " << sum(surf.magSf()) << nl + << endl; } if (optStdout) diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.C b/src/surfMesh/MeshedSurface/MeshedSurface.C index 825949ebd4..e6cd398505 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.C +++ b/src/surfMesh/MeshedSurface/MeshedSurface.C @@ -431,7 +431,9 @@ Foam::MeshedSurface::MeshedSurface template Foam::MeshedSurface::~MeshedSurface() -{} +{ + clear(); +} // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // @@ -500,6 +502,9 @@ void Foam::MeshedSurface::clear() template void Foam::MeshedSurface::movePoints(const pointField& newPoints) { + // Changes areas, normals etc. + ParentType::clearGeom(); + // Adapt for new point position ParentType::movePoints(newPoints); @@ -511,9 +516,12 @@ void Foam::MeshedSurface::movePoints(const pointField& newPoints) template void Foam::MeshedSurface::scalePoints(const scalar scaleFactor) { - // avoid bad scaling + // Avoid bad scaling if (scaleFactor > 0 && scaleFactor != 1.0) { + // Changes areas, normals etc. + ParentType::clearGeom(); + pointField newPoints(scaleFactor*this->points()); // Adapt for new point position @@ -586,7 +594,7 @@ void Foam::MeshedSurface::reset template void Foam::MeshedSurface::cleanup(const bool verbose) { - // merge points (already done for STL, TRI) + // Merge points (already done for STL, TRI) stitchFaces(SMALL, verbose); checkFaces(verbose); @@ -943,8 +951,6 @@ Foam::label Foam::MeshedSurface::triangulate } - - template Foam::MeshedSurface Foam::MeshedSurface::subsetMesh ( diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.H b/src/surfMesh/MeshedSurface/MeshedSurface.H index 1362197d8c..9f3a34a80a 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.H +++ b/src/surfMesh/MeshedSurface/MeshedSurface.H @@ -339,6 +339,31 @@ public: return zones_; } + //- Face area vectors (normals) + inline const vectorField& Sf() const + { + return ParentType::faceAreas(); + } + + //- Face area magnitudes + inline const scalarField& magSf() const + { + return ParentType::magFaceAreas(); + } + + //- Face centres + inline const vectorField& Cf() const + { + return ParentType::faceCentres(); + } + + + // Edit + + //- Clear all storage + virtual void clear(); + + //- Add surface zones virtual void addZones ( @@ -365,11 +390,6 @@ public: virtual void removeZones(); - // Edit - - //- Clear all storage - virtual void clear(); - //- Move points virtual void movePoints(const pointField&); diff --git a/src/surfMesh/surfMesh/surfMesh.H b/src/surfMesh/surfMesh/surfMesh.H index d8bbff5fe4..f936d3f46d 100644 --- a/src/surfMesh/surfMesh/surfMesh.H +++ b/src/surfMesh/surfMesh/surfMesh.H @@ -233,6 +233,25 @@ public: //- Check the surface zone definitions void checkZones(); + + //- Return face area vectors (normals) + inline const vectorField& Sf() const + { + return MeshReference::faceAreas(); + } + + //- Return face area magnitudes + inline const scalarField& magSf() const + { + return MeshReference::magFaceAreas(); + } + + //- Face centres + inline const vectorField& Cf() const + { + return MeshReference::faceCentres(); + } + //- Add surface zones void addZones ( diff --git a/src/surfMesh/surfMesh/surfMeshClear.C b/src/surfMesh/surfMesh/surfMeshClear.C index 179f202c2d..39bef03a02 100644 --- a/src/surfMesh/surfMesh/surfMeshClear.C +++ b/src/surfMesh/surfMesh/surfMeshClear.C @@ -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) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -69,6 +69,8 @@ void Foam::surfMesh::clearAddressing() void Foam::surfMesh::clearOut() { + MeshReference::clearOut(); + clearGeom(); clearAddressing(); } diff --git a/src/surfMesh/surfMesh/surfMeshIO.C b/src/surfMesh/surfMesh/surfMeshIO.C index 5e7072e3a4..f2a5c54245 100644 --- a/src/surfMesh/surfMesh/surfMeshIO.C +++ b/src/surfMesh/surfMesh/surfMeshIO.C @@ -168,7 +168,7 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate() Info<< "Point motion" << endl; } - clearGeom(); + clearOut(); storedIOPoints().instance() = pointsInst; storedIOPoints() = pointIOField diff --git a/src/triSurface/triSurface/triSurface.H b/src/triSurface/triSurface/triSurface.H index c892fb22c0..0383c14a2b 100644 --- a/src/triSurface/triSurface/triSurface.H +++ b/src/triSurface/triSurface/triSurface.H @@ -335,6 +335,25 @@ public: const labelList& edgeOwner() const; + //- Face area vectors (normals) + inline const vectorField& Sf() const + { + return ParentType::faceAreas(); + } + + //- Face area magnitudes + inline const scalarField& magSf() const + { + return ParentType::magFaceAreas(); + } + + //- Face centres + inline const vectorField& Cf() const + { + return ParentType::faceCentres(); + } + + // Edit //- Move points