diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.C b/src/OpenFOAM/meshes/boundBox/boundBox.C index 74061716c2..f781bce558 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.C +++ b/src/OpenFOAM/meshes/boundBox/boundBox.C @@ -47,7 +47,7 @@ const Foam::boundBox Foam::boundBox::invertedBox // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::boundBox::calculate(const pointField& points, const bool doReduce) +void Foam::boundBox::calculate(const UList& points, const bool doReduce) { if (points.empty()) { @@ -84,7 +84,7 @@ void Foam::boundBox::calculate(const pointField& points, const bool doReduce) // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::boundBox::boundBox(const pointField& points, const bool doReduce) +Foam::boundBox::boundBox(const UList& points, const bool doReduce) : min_(point::zero), max_(point::zero) @@ -103,9 +103,43 @@ Foam::boundBox::boundBox(const tmp& points, const bool doReduce) } -Foam::boundBox::boundBox(Istream& is) +Foam::boundBox::boundBox +( + const UList& points, + const labelUList& indices, + const bool doReduce +) +: + min_(point::zero), + max_(point::zero) { - operator>>(is, *this); + if (points.empty() || indices.empty()) + { + if (doReduce && Pstream::parRun()) + { + // Use values that get overwritten by reduce minOp, maxOp below + min_ = point(VGREAT, VGREAT, VGREAT); + max_ = point(-VGREAT, -VGREAT, -VGREAT); + } + } + else + { + min_ = points[indices[0]]; + max_ = points[indices[0]]; + + for (label i=1; i < indices.size(); ++i) + { + min_ = ::Foam::min(min_, points[indices[i]]); + max_ = ::Foam::max(max_, points[indices[i]]); + } + } + + // Reduce parallel information + if (doReduce) + { + reduce(min_, minOp()); + reduce(max_, maxOp()); + } } @@ -172,4 +206,5 @@ Foam::Istream& Foam::operator>>(Istream& is, boundBox& bb) return is; } + // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.H b/src/OpenFOAM/meshes/boundBox/boundBox.H index 2f510bc9e7..101260a3a5 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.H +++ b/src/OpenFOAM/meshes/boundBox/boundBox.H @@ -44,7 +44,8 @@ namespace Foam class boundBox; template class tmp; -Ostream& operator<<(Ostream& os, const boundBox& b); +Istream& operator>>(Istream&, boundBox&); +Ostream& operator<<(Ostream&, const boundBox&); /*---------------------------------------------------------------------------*\ @@ -60,9 +61,9 @@ class boundBox // Private Member Functions - //- Calculate the bounding box from the given pointField. + //- Calculate the bounding box from the given points. // Does parallel communication (doReduce = true) - void calculate(const pointField&, const bool doReduce = true); + void calculate(const UList&, const bool doReduce = true); public: @@ -81,29 +82,42 @@ public: // Constructors //- Construct null, setting points to zero - boundBox() - : - min_(point::zero), - max_(point::zero) - {} + inline boundBox(); //- Construct from components - boundBox(const point& min, const point& max) - : - min_(min), - max_(max) - {} + inline boundBox(const point& min, const point& max); - //- Construct as the bounding box of the given pointField. + //- Construct as the bounding box of the given points // Does parallel communication (doReduce = true) - boundBox(const pointField&, const bool doReduce = true); + boundBox(const UList&, const bool doReduce = true); //- Construct as the bounding box of the given temporary pointField. // Does parallel communication (doReduce = true) boundBox(const tmp&, const bool doReduce = true); + //- Construct bounding box as subset of the pointField. + // The indices could be from cell/face etc. + // Does parallel communication (doReduce = true) + boundBox + ( + const UList&, + const labelUList& indices, + const bool doReduce = true + ); + + //- Construct bounding box as subset of the pointField. + // The indices could be from edge/triFace etc. + // Does parallel communication (doReduce = true) + template + boundBox + ( + const UList&, + const FixedList& indices, + const bool doReduce = true + ); + //- Construct from Istream - boundBox(Istream&); + inline boundBox(Istream&); // Member functions @@ -111,70 +125,37 @@ public: // Access //- Minimum describing the bounding box - const point& min() const - { - return min_; - } + inline const point& min() const; //- Maximum describing the bounding box - const point& max() const - { - return max_; - } + inline const point& max() const; //- Minimum describing the bounding box, non-const access - point& min() - { - return min_; - } + inline point& min(); //- Maximum describing the bounding box, non-const access - point& max() - { - return max_; - } + inline point& max(); //- The midpoint of the bounding box - point midpoint() const - { - return 0.5 * (max_ + min_); - } + inline point midpoint() const; //- The bounding box span (from minimum to maximum) - vector span() const - { - return (max_ - min_); - } + inline vector span() const; //- The magnitude of the bounding box span - scalar mag() const - { - return ::Foam::mag(max_ - min_); - } + inline scalar mag() const; //- The volume of the bound box - scalar volume() const - { - return cmptProduct(span()); - } + inline scalar volume() const; //- Smallest length/height/width dimension - scalar minDim() const - { - return cmptMin(span()); - } + inline scalar minDim() const; //- Largest length/height/width dimension - scalar maxDim() const - { - return cmptMax(span()); - } + inline scalar maxDim() const; //- Average length/height/width dimension - scalar avgDim() const - { - return cmptAv(span()); - } + inline scalar avgDim() const; //- Return corner points in an order corresponding to a 'hex' cell tmp corners() const; @@ -182,56 +163,28 @@ public: // Query //- Overlaps/touches boundingBox? - bool overlaps(const boundBox& bb) const - { - return - ( - bb.max_.x() >= min_.x() && bb.min_.x() <= max_.x() - && bb.max_.y() >= min_.y() && bb.min_.y() <= max_.y() - && bb.max_.z() >= min_.z() && bb.min_.z() <= max_.z() - ); - } + inline bool overlaps(const boundBox&) const; //- Contains point? (inside or on edge) - bool contains(const point& pt) const - { - return - ( - pt.x() >= min_.x() && pt.x() <= max_.x() - && pt.y() >= min_.y() && pt.y() <= max_.y() - && pt.z() >= min_.z() && pt.z() <= max_.z() - ); - } + inline bool contains(const point&) const; + + //- Fully contains other boundingBox? + inline bool contains(const boundBox&) const; //- Contains point? (inside only) - bool containsInside(const point& pt) const - { - return - ( - pt.x() > min_.x() && pt.x() < max_.x() - && pt.y() > min_.y() && pt.y() < max_.y() - && pt.z() > min_.z() && pt.z() < max_.z() - ); - } + inline bool containsInside(const point&) const; // Friend Operators - friend bool operator==(const boundBox& a, const boundBox& b) - { - return (a.min_ == b.min_) && (a.max_ == b.max_); - } - - friend bool operator!=(const boundBox& a, const boundBox& b) - { - return !(a == b); - } + inline friend bool operator==(const boundBox&, const boundBox&); + inline friend bool operator!=(const boundBox&, const boundBox&); // IOstream operator - friend Istream& operator>>(Istream& is, boundBox&); - friend Ostream& operator<<(Ostream& os, const boundBox&); + friend Istream& operator>>(Istream&, boundBox&); + friend Ostream& operator<<(Ostream&, const boundBox&); }; @@ -244,7 +197,11 @@ inline bool contiguous() {return contiguous();} } // End namespace Foam -// #include "boundBoxI.H" +#include "boundBoxI.H" + +#ifdef NoRepository +# include "boundBoxTemplates.C" +#endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/meshes/boundBox/boundBoxI.H b/src/OpenFOAM/meshes/boundBox/boundBoxI.H new file mode 100644 index 0000000000..51e75d41a5 --- /dev/null +++ b/src/OpenFOAM/meshes/boundBox/boundBoxI.H @@ -0,0 +1,174 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\/ 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 . + +\*---------------------------------------------------------------------------*/ + +#include "boundBox.H" +#include "pointField.H" + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +inline Foam::boundBox::boundBox() +: + min_(point::zero), + max_(point::zero) +{} + + +inline Foam::boundBox::boundBox(const point& min, const point& max) +: + min_(min), + max_(max) +{} + + +inline Foam::boundBox::boundBox(Istream& is) +{ + operator>>(is, *this); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +inline const Foam::point& Foam::boundBox::min() const +{ + return min_; +} + + +inline const Foam::point& Foam::boundBox::max() const +{ + return max_; +} + + +inline Foam::point& Foam::boundBox::min() +{ + return min_; +} + + +inline Foam::point& Foam::boundBox::max() +{ + return max_; +} + + +inline Foam::point Foam::boundBox::midpoint() const +{ + return 0.5 * (max_ + min_); +} + + +inline Foam::vector Foam::boundBox::span() const +{ + return (max_ - min_); +} + + +inline Foam::scalar Foam::boundBox::mag() const +{ + return ::Foam::mag(max_ - min_); +} + + +inline Foam::scalar Foam::boundBox::volume() const +{ + return cmptProduct(span()); +} + + +inline Foam::scalar Foam::boundBox::minDim() const +{ + return cmptMin(span()); +} + + +inline Foam::scalar Foam::boundBox::maxDim() const +{ + return cmptMax(span()); +} + + +inline Foam::scalar Foam::boundBox::avgDim() const +{ + return cmptAv(span()); +} + + +inline bool Foam::boundBox::overlaps(const boundBox& bb) const +{ + return + ( + bb.max_.x() >= min_.x() && bb.min_.x() <= max_.x() + && bb.max_.y() >= min_.y() && bb.min_.y() <= max_.y() + && bb.max_.z() >= min_.z() && bb.min_.z() <= max_.z() + ); +} + + +inline bool Foam::boundBox::contains(const point& pt) const +{ + return + ( + pt.x() >= min_.x() && pt.x() <= max_.x() + && pt.y() >= min_.y() && pt.y() <= max_.y() + && pt.z() >= min_.z() && pt.z() <= max_.z() + ); +} + + +// this.bb fully contains bb +inline bool Foam::boundBox::contains(const boundBox& bb) const +{ + return contains(bb.min()) && contains(bb.max()); +} + + +inline bool Foam::boundBox::containsInside(const point& pt) const +{ + return + ( + pt.x() > min_.x() && pt.x() < max_.x() + && pt.y() > min_.y() && pt.y() < max_.y() + && pt.z() > min_.z() && pt.z() < max_.z() + ); +} + + +// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // + +inline bool Foam::operator==(const boundBox& a, const boundBox& b) +{ + return (a.min_ == b.min_) && (a.max_ == b.max_); +} + + +inline bool Foam::operator!=(const boundBox& a, const boundBox& b) +{ + return !(a == b); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C b/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C new file mode 100644 index 0000000000..0fd6c3a40f --- /dev/null +++ b/src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C @@ -0,0 +1,76 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\/ 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 . + +\*---------------------------------------------------------------------------*/ + +#include "boundBox.H" +#include "FixedList.H" +#include "PstreamReduceOps.H" + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + + +template +Foam::boundBox::boundBox +( + const UList& points, + const FixedList& indices, + const bool doReduce +) +: + min_(point::zero), + max_(point::zero) +{ + // a FixedList is never empty + if (points.empty()) + { + if (doReduce && Pstream::parRun()) + { + // Use values that get overwritten by reduce minOp, maxOp below + min_ = point(VGREAT, VGREAT, VGREAT); + max_ = point(-VGREAT, -VGREAT, -VGREAT); + } + } + else + { + min_ = points[indices[0]]; + max_ = points[indices[0]]; + + for (unsigned i=1; i < Size; ++i) + { + min_ = ::Foam::min(min_, points[indices[i]]); + max_ = ::Foam::max(max_, points[indices[i]]); + } + } + + // Reduce parallel information + if (doReduce) + { + reduce(min_, minOp()); + reduce(max_, maxOp()); + } +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H index 8a80eb663f..7c47d887be 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H @@ -209,8 +209,8 @@ public: // Friend Operators - friend bool operator==(const triFace&, const triFace&); - friend bool operator!=(const triFace&, const triFace&); + inline friend bool operator==(const triFace&, const triFace&); + inline friend bool operator!=(const triFace&, const triFace&); }; diff --git a/src/meshTools/octree/treeBoundBox.C b/src/meshTools/octree/treeBoundBox.C index 8906affeaa..60fb789e8a 100644 --- a/src/meshTools/octree/treeBoundBox.C +++ b/src/meshTools/octree/treeBoundBox.C @@ -124,10 +124,9 @@ Foam::FixedList Foam::treeBoundBox::calcFaceNormals() // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// Construct as the bounding box of the given pointField Foam::treeBoundBox::treeBoundBox(const UList& points) : - boundBox() + boundBox(points, false) { if (points.empty()) { @@ -139,57 +138,31 @@ Foam::treeBoundBox::treeBoundBox(const UList& points) return; } - - min() = points[0]; - max() = points[0]; - - for (label i = 1; i < points.size(); i++) - { - min() = ::Foam::min(min(), points[i]); - max() = ::Foam::max(max(), points[i]); - } } -// Construct as the bounding box of the given pointField Foam::treeBoundBox::treeBoundBox ( const UList& points, - const labelUList& meshPoints + const labelUList& indices ) : - boundBox() + boundBox(points, indices, false) { - if (points.empty() || meshPoints.empty()) + if (points.empty() || indices.empty()) { WarningIn ( "treeBoundBox::treeBoundBox" "(const UList&, const labelUList&)" - ) << "cannot find bounding box for zero-sized pointField" + ) << "cannot find bounding box for zero-sized pointField, " << "returning zero" << endl; return; } - - min() = points[meshPoints[0]]; - max() = points[meshPoints[0]]; - - for (label i = 1; i < meshPoints.size(); i++) - { - min() = ::Foam::min(min(), points[meshPoints[i]]); - max() = ::Foam::max(max(), points[meshPoints[i]]); - } } -// Construct from Istream -Foam::treeBoundBox::treeBoundBox(Istream& is) -: - boundBox(is) -{} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::pointField Foam::treeBoundBox::points() const @@ -458,13 +431,6 @@ bool Foam::treeBoundBox::intersects } -// this.bb fully contains bb -bool Foam::treeBoundBox::contains(const treeBoundBox& bb) const -{ - return contains(bb.min()) && contains(bb.max()); -} - - bool Foam::treeBoundBox::contains(const vector& dir, const point& pt) const { // diff --git a/src/meshTools/octree/treeBoundBox.H b/src/meshTools/octree/treeBoundBox.H index f462c719ae..6c2f0d68fc 100644 --- a/src/meshTools/octree/treeBoundBox.H +++ b/src/meshTools/octree/treeBoundBox.H @@ -50,6 +50,7 @@ Description SourceFiles treeBoundBoxI.H treeBoundBox.C + treeBoundBoxTemplates.C \*---------------------------------------------------------------------------*/ @@ -69,7 +70,7 @@ namespace Foam class Random; /*---------------------------------------------------------------------------*\ - Class treeBoundBox Declaration + Class treeBoundBox Declaration \*---------------------------------------------------------------------------*/ class treeBoundBox @@ -165,11 +166,11 @@ public: //- Construct null setting points to zero inline treeBoundBox(); - //- Construct from components - inline treeBoundBox(const point& min, const point& max); + //- Construct from a boundBox + explicit inline treeBoundBox(const boundBox& bb); //- Construct from components - explicit inline treeBoundBox(const boundBox& bb); + inline treeBoundBox(const point& min, const point& max); //- Construct as the bounding box of the given pointField. // Local processor domain only (no reduce as in boundBox) @@ -177,10 +178,21 @@ public: //- Construct as subset of points // Local processor domain only (no reduce as in boundBox) - treeBoundBox(const UList&, const labelUList& meshPoints); + treeBoundBox(const UList&, const labelUList& indices); + + //- Construct as subset of points + // The indices could be from edge/triFace etc. + // Local processor domain only (no reduce as in boundBox) + template + treeBoundBox + ( + const UList&, + const FixedList& indices + ); + //- Construct from Istream - treeBoundBox(Istream&); + inline treeBoundBox(Istream&); // Member functions @@ -257,8 +269,8 @@ public: FixedList& octantOrder ) const; - //- Overlaps other boundingbox? - inline bool overlaps(const treeBoundBox&) const; + //- Overlaps other bounding box? + using boundBox::overlaps; //- Overlaps boundingSphere (centre + sqr(radius))? bool overlaps(const point&, const scalar radiusSqr) const; @@ -289,18 +301,15 @@ public: point& pt ) const; - //- fully contains other boundingBox? - inline bool contains(const treeBoundBox&) const; - - //- Contains point? (inside or on edge) - inline bool contains(const point&) const; + //- Contains point or other bounding box? + using boundBox::contains; //- Contains point (inside or on edge) and moving in direction // dir would cause it to go inside. bool contains(const vector& dir, const point&) const; - //- Code position of pt on bounding box faces - direction faceBits(const point& pt) const; + //- Code position of point on bounding box faces + direction faceBits(const point&) const; //- Position of point relative to bounding box direction posBits(const point&) const; @@ -355,6 +364,10 @@ inline bool contiguous() {return contiguous();} #include "treeBoundBoxI.H" +#ifdef NoRepository +# include "treeBoundBoxTemplates.C" +#endif + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif diff --git a/src/meshTools/octree/treeBoundBoxI.H b/src/meshTools/octree/treeBoundBoxI.H index 543e4e0256..a085eb4421 100644 --- a/src/meshTools/octree/treeBoundBoxI.H +++ b/src/meshTools/octree/treeBoundBoxI.H @@ -46,6 +46,12 @@ inline Foam::treeBoundBox::treeBoundBox(const boundBox& bb) {} +inline Foam::treeBoundBox::treeBoundBox(Istream& is) +: + boundBox(is) +{} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // inline Foam::scalar Foam::treeBoundBox::typDim() const @@ -306,20 +312,6 @@ inline void Foam::treeBoundBox::searchOrder } -// true if bb's intersect or overlap. -// Note: <= to make sure we catch all. -inline bool Foam::treeBoundBox::overlaps(const treeBoundBox& bb) const -{ - return boundBox::overlaps(bb); -} - - -inline bool Foam::treeBoundBox::contains(const point& pt) const -{ - return boundBox::contains(pt); -} - - //- Return slightly wider bounding box inline Foam::treeBoundBox Foam::treeBoundBox::extend ( @@ -346,6 +338,4 @@ inline Foam::treeBoundBox Foam::treeBoundBox::extend } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - // ************************************************************************* // diff --git a/src/meshTools/octree/treeBoundBoxTemplates.C b/src/meshTools/octree/treeBoundBoxTemplates.C new file mode 100644 index 0000000000..c8cb5fab5d --- /dev/null +++ b/src/meshTools/octree/treeBoundBoxTemplates.C @@ -0,0 +1,56 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\/ 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 . + +\*---------------------------------------------------------------------------*/ + +#include "treeBoundBox.H" +#include "FixedList.H" + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + + +template +Foam::treeBoundBox::treeBoundBox +( + const UList& points, + const FixedList& indices +) +: + boundBox(points, indices, false) +{ + // points may be empty, but a FixedList is never empty + if (points.empty()) + { + WarningIn + ( + "treeBoundBox::treeBoundBox" + "(const UList&, const FixedList&)" + ) << "cannot find bounding box for zero-sized pointField, " + << "returning zero" << endl; + + return; + } +} + +// ************************************************************************* //