From cf0fc76a7017788d230539876bd45584a51f3000 Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Mon, 2 Apr 2012 10:49:28 +0100 Subject: [PATCH] STYLE: sampledSurfaces: extracted merging functionality to Patchtools --- .../primitiveMesh/PatchTools/PatchTools.C | 3 +- .../primitiveMesh/PatchTools/PatchTools.H | 22 ++- .../PatchTools/PatchToolsGatherAndMerge.C | 181 ++++++++++++++++++ .../sampledSurfaces/sampledSurfaces.C | 113 ++--------- 4 files changed, 215 insertions(+), 104 deletions(-) create mode 100644 src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsGatherAndMerge.C diff --git a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.C b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.C index 793411c162a..9335ba0f8f2 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -27,6 +27,7 @@ License #include "PatchToolsCheck.C" #include "PatchToolsEdgeOwner.C" +#include "PatchToolsGatherAndMerge.C" #include "PatchToolsSearch.C" #include "PatchToolsSortEdges.C" #include "PatchToolsNormals.C" diff --git a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.H b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.H index e4ade383ef3..968b0b52441 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.H +++ b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,6 +33,7 @@ SourceFiles PatchTools.C PatchToolsCheck.C PatchToolsEdgeOwner.C + PatchToolsGatherAndMerge.C PatchToolsSearch.C PatchToolsSortEdges.C PatchToolsNormals.C @@ -236,6 +237,25 @@ public: const labelList& meshFaces ); + + //- Gather points and faces onto master and merge (geometrically) into + // single patch. + template + < + class Face, + template<class> class FaceList, + class PointField, + class PointType + > + static void gatherAndMerge + ( + const scalar mergeDist, + const PrimitivePatch<Face, FaceList, PointField, PointType>& p, + Field<PointType>& mergedPoints, + List<Face>& mergedFaces, + labelList& pointMergeMap + ); + }; diff --git a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsGatherAndMerge.C b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsGatherAndMerge.C new file mode 100644 index 00000000000..1d759d37835 --- /dev/null +++ b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsGatherAndMerge.C @@ -0,0 +1,181 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ 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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "PatchTools.H" +#include "ListListOps.H" +#include "mergePoints.H" +#include "face.H" +#include "triFace.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + //- Used to offset faces in Pstream::combineOffset + template<> + class offsetOp<face> + { + + public: + + face operator() + ( + const face& x, + const label offset + ) const + { + face result(x.size()); + + forAll(x, xI) + { + result[xI] = x[xI] + offset; + } + return result; + } + }; + + //- Used to offset faces in Pstream::combineOffset + template<> + class offsetOp<triFace> + { + + public: + + triFace operator() + ( + const triFace& x, + const label offset + ) const + { + triFace result(x); + + forAll(x, xI) + { + result[xI] = x[xI] + offset; + } + return result; + } + }; +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +< + class Face, + template<class> class FaceList, + class PointField, + class PointType +> +void Foam::PatchTools::gatherAndMerge +( + const scalar mergeDist, + const PrimitivePatch<Face, FaceList, PointField, PointType>& p, + Field<PointType>& mergedPoints, + List<Face>& mergedFaces, + labelList& pointMergeMap +) +{ + // Collect points from all processors + labelList pointSizes; + { + List<Field<PointType> > gatheredPoints(Pstream::nProcs()); + gatheredPoints[Pstream::myProcNo()] = p.localPoints(); + Pstream::gatherList(gatheredPoints); + + if (Pstream::master()) + { + pointSizes = ListListOps::subSizes + ( + gatheredPoints, + accessOp<Field<PointType> >() + ); + + mergedPoints = ListListOps::combine<Field<PointType> > + ( + gatheredPoints, + accessOp<Field<PointType> >() + ); + } + } + + // Collect faces from all processors and renumber using sizes of + // gathered points + { + List<List<Face> > gatheredFaces(Pstream::nProcs()); + gatheredFaces[Pstream::myProcNo()] = p.localFaces(); + Pstream::gatherList(gatheredFaces); + + if (Pstream::master()) + { + mergedFaces = static_cast<const List<Face>&> + ( + ListListOps::combineOffset<List<Face> > + ( + gatheredFaces, + pointSizes, + accessOp<List<Face> >(), + offsetOp<Face>() + ) + ); + } + } + + if (Pstream::master()) + { + Field<PointType> newPoints; + labelList oldToNew; + + bool hasMerged = mergePoints + ( + mergedPoints, + mergeDist, + false, // verbosity + oldToNew, + newPoints + ); + + if (hasMerged) + { + // Store point mapping + pointMergeMap.transfer(oldToNew); + + // Copy points + mergedPoints.transfer(newPoints); + + // Relabel faces + List<Face>& faces = mergedFaces; + + forAll(faces, faceI) + { + inplaceRenumber(pointMergeMap, faces[faceI]); + } + } + } +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index 332e933417b..a8dfaebdfcf 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -28,9 +28,8 @@ License #include "dictionary.H" #include "Time.H" #include "IOmanip.H" -#include "ListListOps.H" -#include "mergePoints.H" #include "volPointInterpolation.H" +#include "PatchTools.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -38,34 +37,6 @@ defineTypeNameAndDebug(Foam::sampledSurfaces, 0); bool Foam::sampledSurfaces::verbose_ = false; Foam::scalar Foam::sampledSurfaces::mergeTol_ = 1e-10; -namespace Foam -{ - //- Used to offset faces in Pstream::combineOffset - template <> - class offsetOp<face> - { - - public: - - face operator() - ( - const face& x, - const label offset - ) const - { - face result(x.size()); - - forAll(x, xI) - { - result[xI] = x[xI] + offset; - } - return result; - } - }; - -} - - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::sampledSurfaces::writeGeometry() const @@ -379,80 +350,18 @@ bool Foam::sampledSurfaces::update() continue; } - - // Collect points from all processors - List<pointField> gatheredPoints(Pstream::nProcs()); - gatheredPoints[Pstream::myProcNo()] = s.points(); - Pstream::gatherList(gatheredPoints); - - if (Pstream::master()) - { - mergeList_[surfI].points = ListListOps::combine<pointField> - ( - gatheredPoints, - accessOp<pointField>() - ); - } - - // Collect faces from all processors and renumber using sizes of - // gathered points - List<faceList> gatheredFaces(Pstream::nProcs()); - gatheredFaces[Pstream::myProcNo()] = s.faces(); - Pstream::gatherList(gatheredFaces); - - if (Pstream::master()) - { - mergeList_[surfI].faces = static_cast<const faceList&> - ( - ListListOps::combineOffset<faceList> - ( - gatheredFaces, - ListListOps::subSizes - ( - gatheredPoints, - accessOp<pointField>() - ), - accessOp<faceList>(), - offsetOp<face>() - ) - ); - } - - pointField newPoints; - labelList oldToNew; - - bool hasMerged = mergePoints + PatchTools::gatherAndMerge ( - mergeList_[surfI].points, mergeDim, - false, // verbosity - oldToNew, - newPoints + primitivePatch + ( + SubList<face>(s.faces(), s.faces().size()), + s.points() + ), + mergeList_[surfI].points, + mergeList_[surfI].faces, + mergeList_[surfI].pointsMap ); - - if (hasMerged) - { - // Store point mapping - mergeList_[surfI].pointsMap.transfer(oldToNew); - - // Copy points - mergeList_[surfI].points.transfer(newPoints); - - // Relabel faces - faceList& faces = mergeList_[surfI].faces; - - forAll(faces, faceI) - { - inplaceRenumber(mergeList_[surfI].pointsMap, faces[faceI]); - } - - if (Pstream::master() && debug) - { - Pout<< "For surface " << surfI << " merged from " - << mergeList_[surfI].pointsMap.size() << " points down to " - << mergeList_[surfI].points.size() << " points" << endl; - } - } } return updated; -- GitLab