From 17d76e62610e87baa33c3e4a00993f284cbedd2c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 25 Jan 2017 18:52:37 +0100 Subject: [PATCH] ENH: boundBox 'reduce' method (related to #196) reduce() - parallel reduction of min/max values. Reduces coding for the callers. Eg, bb.reduce(); instead of the previous method: reduce(bb.min(), minOp()); reduce(bb.max(), maxOp()); STYLE: - use initializer list for creating static content - use point::min/point::max when defining standard boxes --- applications/test/boundBox/Test-boundBox.C | 12 ++++ .../manipulation/checkMesh/checkTopology.C | 3 +- src/OpenFOAM/meshes/boundBox/boundBox.C | 62 +++++++------------ src/OpenFOAM/meshes/boundBox/boundBox.H | 3 + .../meshes/boundBox/boundBoxTemplates.C | 6 +- .../distributedTriSurfaceMesh.C | 15 ++--- 6 files changed, 46 insertions(+), 55 deletions(-) diff --git a/applications/test/boundBox/Test-boundBox.C b/applications/test/boundBox/Test-boundBox.C index cb72b9ca87..8d99361a84 100644 --- a/applications/test/boundBox/Test-boundBox.C +++ b/applications/test/boundBox/Test-boundBox.C @@ -60,6 +60,18 @@ int main(int argc, char *argv[]) Info<<"boundBox faces: " << boundBox::faces << endl; Info<<"hex faces: " << hex.modelFaces() << endl; + boundBox bb = boundBox::greatBox; + Info<<"great box: " << bb << endl; + + if (Pstream::parRun()) + { + bb = cube(Pstream::myProcNo(), 1.1); + Pout<<"box: " << bb << endl; + + bb.reduce(); + Pout<<"reduced: " << bb << endl; + } + return 0; } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C b/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C index 11d6cfd523..2b58f79335 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C @@ -569,8 +569,7 @@ Foam::label Foam::checkTopology bb.min() = min(bb.min(), pts[mp[i]]); bb.max() = max(bb.max(), pts[mp[i]]); } - reduce(bb.min(), minOp()); - reduce(bb.max(), maxOp()); + bb.reduce(); Info<< ' ' << bb; } } diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.C b/src/OpenFOAM/meshes/boundBox/boundBox.C index a05ab018f6..982fe6bf53 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.C +++ b/src/OpenFOAM/meshes/boundBox/boundBox.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 | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -24,47 +24,27 @@ License \*---------------------------------------------------------------------------*/ #include "boundBox.H" -#include "ListOps.H" #include "PstreamReduceOps.H" #include "tmp.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const Foam::scalar Foam::boundBox::great(VGREAT); - -const Foam::boundBox Foam::boundBox::greatBox -( - point(-VGREAT, -VGREAT, -VGREAT), - point(VGREAT, VGREAT, VGREAT) -); - - -const Foam::boundBox Foam::boundBox::invertedBox -( - point(VGREAT, VGREAT, VGREAT), - point(-VGREAT, -VGREAT, -VGREAT) -); - - -//! \cond ignoreDocumentation -//- Skip documentation : local scope only -const Foam::label facesArray[6][4] = -{ - // point and face order as per hex cellmodel - {0, 4, 7, 3}, // x-min - {1, 2, 6, 5}, // x-max - {0, 1, 5, 4}, // y-min - {3, 7, 6, 2}, // y-max - {0, 3, 2, 1}, // z-min - {4, 5, 6, 7} // z-max -}; -//! \endcond +// (min,max) = (-VGREAT,+VGREAT) +const Foam::boundBox Foam::boundBox::greatBox(point::min, point::max); +// (min,max) = (+VGREAT,-VGREAT) +const Foam::boundBox Foam::boundBox::invertedBox(point::max, point::min); const Foam::faceList Foam::boundBox::faces -( - initListList(facesArray) -); +({ + // Point and face order as per hex cellmodel + face{0, 4, 7, 3}, // x-min + face{1, 2, 6, 5}, // x-max + face{0, 1, 5, 4}, // y-min + face{3, 7, 6, 2}, // y-max + face{0, 3, 2, 1}, // z-min + face{4, 5, 6, 7} // z-max +}); // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -88,7 +68,6 @@ void Foam::boundBox::calculate(const UList& points, const bool doReduce) min_ = points[0]; max_ = points[0]; - for (label i = 1; i < points.size(); i++) { min_ = ::Foam::min(min_, points[i]); @@ -99,8 +78,7 @@ void Foam::boundBox::calculate(const UList& points, const bool doReduce) // Reduce parallel information if (doReduce) { - reduce(min_, minOp()); - reduce(max_, maxOp()); + reduce(); } } @@ -160,8 +138,7 @@ Foam::boundBox::boundBox // Reduce parallel information if (doReduce) { - reduce(min_, minOp()); - reduce(max_, maxOp()); + reduce(); } } @@ -195,6 +172,13 @@ void Foam::boundBox::inflate(const scalar s) } +void Foam::boundBox::reduce() +{ + Foam::reduce(min_, minOp()); + Foam::reduce(max_, maxOp()); +} + + bool Foam::boundBox::contains(const UList& points) const { if (points.empty()) diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.H b/src/OpenFOAM/meshes/boundBox/boundBox.H index 940ff826c7..51ae4f52f2 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.H +++ b/src/OpenFOAM/meshes/boundBox/boundBox.H @@ -173,6 +173,9 @@ public: //- Inflate box by factor*mag(span) in all dimensions void inflate(const scalar s); + //- Parallel reduction of min/max values + void reduce(); + // Query diff --git a/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C b/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C index 81aa3f267b..1ce09cb3fa 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C +++ b/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.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) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,7 +25,6 @@ License #include "boundBox.H" #include "FixedList.H" -#include "PstreamReduceOps.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -66,8 +65,7 @@ Foam::boundBox::boundBox // Reduce parallel information if (doReduce) { - reduce(min_, minOp()); - reduce(max_, maxOp()); + reduce(); } } diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C index 38cb229c7d..830fc436e7 100644 --- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C +++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C @@ -920,8 +920,7 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs { forAll(bbs[procI], i) { - reduce(bbs[procI][i].min(), minOp()); - reduce(bbs[procI][i].max(), maxOp()); + bbs[procI][i].reduce(); } } return bbs; @@ -1334,8 +1333,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh { read(); - reduce(bounds().min(), minOp()); - reduce(bounds().max(), maxOp()); + bounds().reduce(); if (debug) { @@ -1390,8 +1388,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh(const IOobject& io) { read(); - reduce(bounds().min(), minOp()); - reduce(bounds().max(), maxOp()); + bounds().reduce(); if (debug) { @@ -1452,8 +1449,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh { read(); - reduce(bounds().min(), minOp()); - reduce(bounds().max(), maxOp()); + bounds().reduce(); if (debug) { @@ -2434,8 +2430,7 @@ void Foam::distributedTriSurfaceMesh::writeStats(Ostream& os) const boundBox bb; label nPoints; PatchTools::calcBounds(static_cast(*this), bb, nPoints); - reduce(bb.min(), minOp()); - reduce(bb.max(), maxOp()); + bb.reduce(); os << "Triangles : " << returnReduce(triSurface::size(), sumOp