mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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<point>());
reduce(bb.max(), maxOp<point>());
STYLE:
- use initializer list for creating static content
- use point::min/point::max when defining standard boxes
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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<vector>());
|
||||
reduce(bb.max(), maxOp<vector>());
|
||||
bb.reduce();
|
||||
Info<< ' ' << bb;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<face, label, 6, 4>(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<point>& 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<point>& points, const bool doReduce)
|
||||
// Reduce parallel information
|
||||
if (doReduce)
|
||||
{
|
||||
reduce(min_, minOp<point>());
|
||||
reduce(max_, maxOp<point>());
|
||||
reduce();
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,8 +138,7 @@ Foam::boundBox::boundBox
|
||||
// Reduce parallel information
|
||||
if (doReduce)
|
||||
{
|
||||
reduce(min_, minOp<point>());
|
||||
reduce(max_, maxOp<point>());
|
||||
reduce();
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,6 +172,13 @@ void Foam::boundBox::inflate(const scalar s)
|
||||
}
|
||||
|
||||
|
||||
void Foam::boundBox::reduce()
|
||||
{
|
||||
Foam::reduce(min_, minOp<point>());
|
||||
Foam::reduce(max_, maxOp<point>());
|
||||
}
|
||||
|
||||
|
||||
bool Foam::boundBox::contains(const UList<point>& points) const
|
||||
{
|
||||
if (points.empty())
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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<point>());
|
||||
reduce(max_, maxOp<point>());
|
||||
reduce();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -920,8 +920,7 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs
|
||||
{
|
||||
forAll(bbs[procI], i)
|
||||
{
|
||||
reduce(bbs[procI][i].min(), minOp<point>());
|
||||
reduce(bbs[procI][i].max(), maxOp<point>());
|
||||
bbs[procI][i].reduce();
|
||||
}
|
||||
}
|
||||
return bbs;
|
||||
@ -1334,8 +1333,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh
|
||||
{
|
||||
read();
|
||||
|
||||
reduce(bounds().min(), minOp<point>());
|
||||
reduce(bounds().max(), maxOp<point>());
|
||||
bounds().reduce();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
@ -1390,8 +1388,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh(const IOobject& io)
|
||||
{
|
||||
read();
|
||||
|
||||
reduce(bounds().min(), minOp<point>());
|
||||
reduce(bounds().max(), maxOp<point>());
|
||||
bounds().reduce();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
@ -1452,8 +1449,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh
|
||||
{
|
||||
read();
|
||||
|
||||
reduce(bounds().min(), minOp<point>());
|
||||
reduce(bounds().max(), maxOp<point>());
|
||||
bounds().reduce();
|
||||
|
||||
if (debug)
|
||||
{
|
||||
@ -2434,8 +2430,7 @@ void Foam::distributedTriSurfaceMesh::writeStats(Ostream& os) const
|
||||
boundBox bb;
|
||||
label nPoints;
|
||||
PatchTools::calcBounds(static_cast<const triSurface&>(*this), bb, nPoints);
|
||||
reduce(bb.min(), minOp<point>());
|
||||
reduce(bb.max(), maxOp<point>());
|
||||
bb.reduce();
|
||||
|
||||
os << "Triangles : " << returnReduce(triSurface::size(), sumOp<label>())
|
||||
<< endl
|
||||
|
||||
Reference in New Issue
Block a user