From 68167d23734b29ac71bea32b9336c3c1037c9aa5 Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 19 Jul 2013 11:24:50 +0100 Subject: [PATCH 01/11] ENH: searchableSurface: added boundingSphere member function --- .../searchableSurface/searchableBox.C | 35 ++++++++++ .../searchableSurface/searchableBox.H | 10 ++- .../searchableSurface/searchableCylinder.C | 17 +++++ .../searchableSurface/searchableCylinder.H | 10 ++- .../searchableSurface/searchablePlane.C | 16 ++++- .../searchableSurface/searchablePlane.H | 11 ++- .../searchableSurface/searchablePlate.C | 67 ++++++++++++++++++- .../searchableSurface/searchablePlate.H | 54 +++------------ .../searchableSurface/searchableSphere.C | 17 +++++ .../searchableSurface/searchableSphere.H | 12 +++- .../searchableSurface/searchableSurface.H | 8 +++ .../searchableSurfaceCollection.C | 36 ++++++++++ .../searchableSurfaceCollection.H | 10 ++- .../searchableSurfaceWithGaps.H | 11 +++ .../searchableSurface/triSurfaceMesh.C | 55 ++++++++++++--- .../searchableSurface/triSurfaceMesh.H | 8 +++ 16 files changed, 317 insertions(+), 60 deletions(-) diff --git a/src/meshTools/searchableSurface/searchableBox.C b/src/meshTools/searchableSurface/searchableBox.C index 7d639b99f8..5970e82575 100644 --- a/src/meshTools/searchableSurface/searchableBox.C +++ b/src/meshTools/searchableSurface/searchableBox.C @@ -249,6 +249,41 @@ Foam::tmp Foam::searchableBox::coordinates() const } +void Foam::searchableBox::boundingSpheres +( + pointField& centres, + scalarField& radiusSqr +) const +{ + centres.setSize(size()); + radiusSqr.setSize(size()); + radiusSqr = 0.0; + + const pointField pts(treeBoundBox::points()); + const faceList& fcs = treeBoundBox::faces; + + forAll(fcs, i) + { + const face& f = fcs[i]; + + centres[i] = f.centre(pts); + forAll(f, fp) + { + const point& pt = pts[f[fp]]; + + radiusSqr[i] = Foam::max + ( + radiusSqr[i], + Foam::magSqr(pt-centres[i]) + ); + } + } + + // Add a bit to make sure all points are tested inside + radiusSqr += Foam::sqr(SMALL); +} + + Foam::tmp Foam::searchableBox::points() const { return treeBoundBox::points(); diff --git a/src/meshTools/searchableSurface/searchableBox.H b/src/meshTools/searchableSurface/searchableBox.H index 40e5c5d711..d677c1b87d 100644 --- a/src/meshTools/searchableSurface/searchableBox.H +++ b/src/meshTools/searchableSurface/searchableBox.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -129,6 +129,14 @@ public: // Usually the element centres (should be of length size()). virtual tmp coordinates() const; + //- Get bounding spheres (centre and radius squared), one per element. + // Any point on element is guaranteed to be inside. + virtual void boundingSpheres + ( + pointField& centres, + scalarField& radiusSqr + ) const; + //- Get the points that define the surface. virtual tmp points() const; diff --git a/src/meshTools/searchableSurface/searchableCylinder.C b/src/meshTools/searchableSurface/searchableCylinder.C index 70d674d521..7657e883c9 100644 --- a/src/meshTools/searchableSurface/searchableCylinder.C +++ b/src/meshTools/searchableSurface/searchableCylinder.C @@ -47,6 +47,23 @@ Foam::tmp Foam::searchableCylinder::coordinates() const } +void Foam::searchableCylinder::boundingSpheres +( + pointField& centres, + scalarField& radiusSqr +) const +{ + centres.setSize(1); + centres[0] = 0.5*(point1_ + point2_); + + radiusSqr.setSize(1); + radiusSqr[0] = Foam::magSqr(point1_-centres[0]) + Foam::sqr(radius_); + + // Add a bit to make sure all points are tested inside + radiusSqr += Foam::sqr(SMALL); +} + + Foam::tmp Foam::searchableCylinder::points() const { tmp tPts(new pointField(2)); diff --git a/src/meshTools/searchableSurface/searchableCylinder.H b/src/meshTools/searchableSurface/searchableCylinder.H index 0bb570e480..ccf6850dc1 100644 --- a/src/meshTools/searchableSurface/searchableCylinder.H +++ b/src/meshTools/searchableSurface/searchableCylinder.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -154,6 +154,14 @@ public: // Usually the element centres (should be of length size()). virtual tmp coordinates() const; + //- Get bounding spheres (centre and radius squared), one per element. + // Any point on element is guaranteed to be inside. + virtual void boundingSpheres + ( + pointField& centres, + scalarField& radiusSqr + ) const; + //- Get the points that define the surface. virtual tmp points() const; diff --git a/src/meshTools/searchableSurface/searchablePlane.C b/src/meshTools/searchableSurface/searchablePlane.C index a76821d457..e6c9668b1f 100644 --- a/src/meshTools/searchableSurface/searchablePlane.C +++ b/src/meshTools/searchableSurface/searchablePlane.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-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -134,6 +134,20 @@ const Foam::wordList& Foam::searchablePlane::regions() const } +void Foam::searchablePlane::boundingSpheres +( + pointField& centres, + scalarField& radiusSqr +) const +{ + centres.setSize(1); + centres[0] = refPoint(); + + radiusSqr.setSize(1); + radiusSqr[0] = Foam::sqr(GREAT); +} + + void Foam::searchablePlane::findNearest ( const pointField& samples, diff --git a/src/meshTools/searchableSurface/searchablePlane.H b/src/meshTools/searchableSurface/searchablePlane.H index cc64844d0d..a79f93f902 100644 --- a/src/meshTools/searchableSurface/searchablePlane.H +++ b/src/meshTools/searchableSurface/searchablePlane.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -130,6 +130,15 @@ public: return tCtrs; } + //- Get bounding spheres (centre and radius squared), one per element. + // Any point on element is guaranteed to be inside. + // Note: radius limited to sqr(GREAT) + virtual void boundingSpheres + ( + pointField& centres, + scalarField& radiusSqr + ) const; + //- Get the points that define the surface. virtual tmp points() const { diff --git a/src/meshTools/searchableSurface/searchablePlate.C b/src/meshTools/searchableSurface/searchablePlate.C index 37404db051..0ed10bd675 100644 --- a/src/meshTools/searchableSurface/searchablePlate.C +++ b/src/meshTools/searchableSurface/searchablePlate.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -274,6 +274,71 @@ const Foam::wordList& Foam::searchablePlate::regions() const } +Foam::tmp Foam::searchablePlate::coordinates() const +{ + return tmp(new pointField(1, origin_ + 0.5*span_)); +} + + +void Foam::searchablePlate::boundingSpheres +( + pointField& centres, + scalarField& radiusSqr +) const +{ + centres.setSize(1); + centres[0] = origin_ + 0.5*span_; + + radiusSqr.setSize(1); + radiusSqr[0] = Foam::magSqr(0.5*span_); + + // Add a bit to make sure all points are tested inside + radiusSqr += Foam::sqr(SMALL); +} + + +Foam::tmp Foam::searchablePlate::points() const +{ + tmp tPts(new pointField(4)); + pointField& pts = tPts(); + + pts[0] = origin_; + pts[2] = origin_ + span_; + + if (span_.x() < span_.y() && span_.x() < span_.z()) + { + pts[1] = origin_ + point(0, span_.y(), 0); + pts[3] = origin_ + point(0, 0, span_.z()); + } + else if (span_.y() < span_.z()) + { + pts[1] = origin_ + point(span_.x(), 0, 0); + pts[3] = origin_ + point(0, 0, span_.z()); + } + else + { + pts[1] = origin_ + point(span_.x(), 0, 0); + pts[3] = origin_ + point(0, span_.y(), 0); + } + + return tPts; +} + + +bool Foam::searchablePlate::overlaps(const boundBox& bb) const +{ + return + ( + (origin_.x() + span_.x()) >= bb.min().x() + && origin_.x() <= bb.max().x() + && (origin_.y() + span_.y()) >= bb.min().y() + && origin_.y() <= bb.max().y() + && (origin_.z() + span_.z()) >= bb.min().z() + && origin_.z() <= bb.max().z() + ); +} + + void Foam::searchablePlate::findNearest ( const pointField& samples, diff --git a/src/meshTools/searchableSurface/searchablePlate.H b/src/meshTools/searchableSurface/searchablePlate.H index 86b0785077..af2d732ff6 100644 --- a/src/meshTools/searchableSurface/searchablePlate.H +++ b/src/meshTools/searchableSurface/searchablePlate.H @@ -145,53 +145,21 @@ public: //- Get representative set of element coordinates // Usually the element centres (should be of length size()). - virtual tmp coordinates() const - { - tmp tCtrs(new pointField(1, origin_ + 0.5*span_)); - return tCtrs; - } + virtual tmp coordinates() const; + + //- Get bounding spheres (centre and radius squared), one per element. + // Any point on element is guaranteed to be inside. + virtual void boundingSpheres + ( + pointField& centres, + scalarField& radiusSqr + ) const; //- Get the points that define the surface. - virtual tmp points() const - { - tmp tPts(new pointField(4)); - pointField& pts = tPts(); - - pts[0] = origin_; - pts[2] = origin_ + span_; - - if (span_.x() < span_.y() && span_.x() < span_.z()) - { - pts[1] = origin_ + point(0, span_.y(), 0); - pts[3] = origin_ + point(0, 0, span_.z()); - } - else if (span_.y() < span_.z()) - { - pts[1] = origin_ + point(span_.x(), 0, 0); - pts[3] = origin_ + point(0, 0, span_.z()); - } - else - { - pts[1] = origin_ + point(span_.x(), 0, 0); - pts[3] = origin_ + point(0, span_.y(), 0); - } - - return tPts; - } + virtual tmp points() const; //- Does any part of the surface overlap the supplied bound box? - virtual bool overlaps(const boundBox& bb) const - { - return - ( - (origin_.x() + span_.x()) >= bb.min().x() - && origin_.x() <= bb.max().x() - && (origin_.y() + span_.y()) >= bb.min().y() - && origin_.y() <= bb.max().y() - && (origin_.z() + span_.z()) >= bb.min().z() - && origin_.z() <= bb.max().z() - ); - } + virtual bool overlaps(const boundBox& bb) const; // Multiple point queries. diff --git a/src/meshTools/searchableSurface/searchableSphere.C b/src/meshTools/searchableSurface/searchableSphere.C index c367c6281b..e4eae4ab27 100644 --- a/src/meshTools/searchableSurface/searchableSphere.C +++ b/src/meshTools/searchableSurface/searchableSphere.C @@ -185,6 +185,23 @@ const Foam::wordList& Foam::searchableSphere::regions() const +void Foam::searchableSphere::boundingSpheres +( + pointField& centres, + scalarField& radiusSqr +) const +{ + centres.setSize(1); + centres[0] = centre_; + + radiusSqr.setSize(1); + radiusSqr[0] = Foam::sqr(radius_); + + // Add a bit to make sure all points are tested inside + radiusSqr += Foam::sqr(SMALL); +} + + void Foam::searchableSphere::findNearest ( const pointField& samples, diff --git a/src/meshTools/searchableSurface/searchableSphere.H b/src/meshTools/searchableSurface/searchableSphere.H index 5d46f8ad4b..50900f9361 100644 --- a/src/meshTools/searchableSurface/searchableSphere.H +++ b/src/meshTools/searchableSurface/searchableSphere.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -60,7 +60,7 @@ private: //- Centre point const point centre_; - //- Radius squared + //- Radius const scalar radius_; //- Names of regions @@ -139,6 +139,14 @@ public: return tCtrs; } + //- Get bounding spheres (centre and radius squared), one per element. + // Any point on element is guaranteed to be inside. + virtual void boundingSpheres + ( + pointField& centres, + scalarField& radiusSqr + ) const; + //- Get the points that define the surface. virtual tmp points() const { diff --git a/src/meshTools/searchableSurface/searchableSurface.H b/src/meshTools/searchableSurface/searchableSurface.H index 90224ae9ce..6a2adcc946 100644 --- a/src/meshTools/searchableSurface/searchableSurface.H +++ b/src/meshTools/searchableSurface/searchableSurface.H @@ -190,6 +190,14 @@ public: // Usually the element centres (should be of length size()). virtual tmp coordinates() const = 0; + //- Get bounding spheres (centre and radius squared), one per element. + // Any point on element is guaranteed to be inside. + virtual void boundingSpheres + ( + pointField& centres, + scalarField& radiusSqr + ) const = 0; + //- Get the points that define the surface. virtual tmp points() const = 0; diff --git a/src/meshTools/searchableSurface/searchableSurfaceCollection.C b/src/meshTools/searchableSurface/searchableSurfaceCollection.C index 3a02066afa..3aad85f72d 100644 --- a/src/meshTools/searchableSurface/searchableSurfaceCollection.C +++ b/src/meshTools/searchableSurface/searchableSurfaceCollection.C @@ -354,6 +354,42 @@ Foam::searchableSurfaceCollection::coordinates() const } +void Foam::searchableSurfaceCollection::boundingSpheres +( + pointField& centres, + scalarField& radiusSqr +) const +{ + centres.setSize(size()); + radiusSqr.setSize(centres.size()); + + // Append individual coordinates + label coordI = 0; + + forAll(subGeom_, surfI) + { + scalar maxScale = cmptMax(scale_[surfI]); + + pointField subCentres; + scalarField subRadiusSqr; + subGeom_[surfI].boundingSpheres(subCentres, subRadiusSqr); + + forAll(subCentres, i) + { + centres[coordI++] = transform_[surfI].globalPosition + ( + cmptMultiply + ( + subCentres[i], + scale_[surfI] + ) + ); + radiusSqr[coordI++] = maxScale*subRadiusSqr[i]; + } + } +} + + Foam::tmp Foam::searchableSurfaceCollection::points() const { diff --git a/src/meshTools/searchableSurface/searchableSurfaceCollection.H b/src/meshTools/searchableSurface/searchableSurfaceCollection.H index 53e677eaa6..dd8a21664b 100644 --- a/src/meshTools/searchableSurface/searchableSurfaceCollection.H +++ b/src/meshTools/searchableSurface/searchableSurfaceCollection.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -176,6 +176,14 @@ public: // Usually the element centres (should be of length size()). virtual tmp coordinates() const; + //- Get bounding spheres (centre and radius squared), one per element. + // Any point on element is guaranteed to be inside. + virtual void boundingSpheres + ( + pointField& centres, + scalarField& radiusSqr + ) const; + //- Get the points that define the surface. virtual tmp points() const; diff --git a/src/meshTools/searchableSurface/searchableSurfaceWithGaps.H b/src/meshTools/searchableSurface/searchableSurfaceWithGaps.H index 1344cda2d9..d07d331c8a 100644 --- a/src/meshTools/searchableSurface/searchableSurfaceWithGaps.H +++ b/src/meshTools/searchableSurface/searchableSurfaceWithGaps.H @@ -156,6 +156,17 @@ public: return surface().coordinates(); } + //- Get bounding spheres (centre and radius squared), one per element. + // Any point on element is guaranteed to be inside. + virtual void boundingSpheres + ( + pointField& centres, + scalarField& radiusSqr + ) const + { + surface().boundingSpheres(centres, radiusSqr); + } + //- Get the points that define the surface. virtual tmp points() const { diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.C b/src/meshTools/searchableSurface/triSurfaceMesh.C index 125450603b..7b6b8ad6ad 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.C +++ b/src/meshTools/searchableSurface/triSurfaceMesh.C @@ -145,10 +145,12 @@ bool Foam::triSurfaceMesh::addFaceToEdge bool Foam::triSurfaceMesh::isSurfaceClosed() const { + const pointField& pts = triSurface::points(); + // Construct pointFaces. Let's hope surface has compact point // numbering ... labelListList pointFaces; - invertManyToMany(points()().size(), *this, pointFaces); + invertManyToMany(pts.size(), *this, pointFaces); // Loop over all faces surrounding point. Count edges emanating from point. // Every edge should be used by two faces exactly. @@ -241,7 +243,9 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io, const triSurface& s) minQuality_(-1), surfaceClosed_(-1) { - bounds() = boundBox(points()); + const pointField& pts = triSurface::points(); + + bounds() = boundBox(pts); } @@ -287,7 +291,9 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io) minQuality_(-1), surfaceClosed_(-1) { - bounds() = boundBox(points()); + const pointField& pts = triSurface::points(); + + bounds() = boundBox(pts); } @@ -347,7 +353,9 @@ Foam::triSurfaceMesh::triSurfaceMesh triSurface::scalePoints(scaleFactor); } - bounds() = boundBox(points()); + const pointField& pts = triSurface::points(); + + bounds() = boundBox(pts); // Have optional minimum quality for normal calculation if (dict.readIfPresent("minQuality", minQuality_) && minQuality_ > 0) @@ -393,6 +401,34 @@ Foam::tmp Foam::triSurfaceMesh::coordinates() const } +void Foam::triSurfaceMesh::boundingSpheres +( + pointField& centres, + scalarField& radiusSqr +) const +{ + centres = coordinates(); + radiusSqr.setSize(size()); + radiusSqr = 0.0; + + const pointField& pts = triSurface::points(); + + forAll(*this, faceI) + { + const labelledTri& f = triSurface::operator[](faceI); + const point& fc = centres[faceI]; + forAll(f, fp) + { + const point& pt = pts[f[fp]]; + radiusSqr[faceI] = max(radiusSqr[faceI], Foam::magSqr(fc-pt)); + } + } + + // Add a bit to make sure all points are tested inside + radiusSqr += Foam::sqr(SMALL); +} + + Foam::tmp Foam::triSurfaceMesh::points() const { return triSurface::points(); @@ -606,6 +642,7 @@ void Foam::triSurfaceMesh::getNormal ) const { const triSurface& s = static_cast(*this); + const pointField& pts = s.points(); normal.setSize(info.size()); @@ -621,9 +658,9 @@ void Foam::triSurfaceMesh::getNormal if (info[i].hit()) { label faceI = info[i].index(); - normal[i] = s[faceI].normal(points()); + normal[i] = s[faceI].normal(pts); - scalar qual = s[faceI].tri(points()).quality(); + scalar qual = s[faceI].tri(pts).quality(); if (qual < minQuality_) { @@ -633,11 +670,11 @@ void Foam::triSurfaceMesh::getNormal forAll(fFaces, j) { label nbrI = fFaces[j]; - scalar nbrQual = s[nbrI].tri(points()).quality(); + scalar nbrQual = s[nbrI].tri(pts).quality(); if (nbrQual > qual) { qual = nbrQual; - normal[i] = s[nbrI].normal(points()); + normal[i] = s[nbrI].normal(pts); } } } @@ -662,7 +699,7 @@ void Foam::triSurfaceMesh::getNormal //normal[i] = faceNormals()[faceI]; //- Uncached - normal[i] = s[faceI].normal(points()); + normal[i] = s[faceI].normal(pts); normal[i] /= mag(normal[i]) + VSMALL; } else diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.H b/src/meshTools/searchableSurface/triSurfaceMesh.H index fa7e9e511c..e6ecd39594 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.H +++ b/src/meshTools/searchableSurface/triSurfaceMesh.H @@ -187,6 +187,14 @@ public: // Usually the element centres (should be of length size()). virtual tmp coordinates() const; + //- Get bounding spheres (centre and radius squared). Any point + // on surface is guaranteed to be inside. + virtual void boundingSpheres + ( + pointField& centres, + scalarField& radiusSqr + ) const; + //- Get the points that define the surface. virtual tmp points() const; From 25804eaad915a11f7502c784739ef6e7f53a0989 Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 19 Jul 2013 11:43:57 +0100 Subject: [PATCH 02/11] ENH: refinementSurface: search bounding sphere only --- .../refinementSurfaces/refinementSurfaces.C | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.C b/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.C index 98b16e9f6b..f0277b2990 100644 --- a/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.C +++ b/src/mesh/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.C @@ -605,8 +605,10 @@ void Foam::refinementSurfaces::setMinLevelFields // searchableBox (size=6) if (geom.regions().size() > 1 && geom.globalSize() > 10) { - // Representative local coordinates - const pointField ctrs(geom.coordinates()); + // Representative local coordinates and bounding sphere + pointField ctrs; + scalarField radiusSqr; + geom.boundingSpheres(ctrs, radiusSqr); labelList minLevelField(ctrs.size(), -1); { @@ -614,12 +616,7 @@ void Foam::refinementSurfaces::setMinLevelFields // distributed surface where local indices differ from global // ones (needed for getRegion call) List info; - geom.findNearest - ( - ctrs, - scalarField(ctrs.size(), sqr(GREAT)), - info - ); + geom.findNearest(ctrs, radiusSqr, info); // Get per element the region labelList region; @@ -628,7 +625,7 @@ void Foam::refinementSurfaces::setMinLevelFields // From the region get the surface-wise refinement level forAll(minLevelField, i) { - if (info[i].hit()) + if (info[i].hit()) //Note: should not be necessary { minLevelField[i] = minLevel(surfI, region[i]); } From 53c8a1266866f0e13c2a759ebe3b9f4aaed60c47 Mon Sep 17 00:00:00 2001 From: laurence Date: Fri, 19 Jul 2013 15:48:33 +0100 Subject: [PATCH 03/11] ENH: Pair: Add extra comparison operators. Make member functions non-member --- src/OpenFOAM/primitives/Pair/Pair.H | 93 ++++++++++++------- .../meshRefinement/meshRefinementBaffles.C | 2 +- 2 files changed, 60 insertions(+), 35 deletions(-) diff --git a/src/OpenFOAM/primitives/Pair/Pair.H b/src/OpenFOAM/primitives/Pair/Pair.H index 12c16fc6c3..6715bffd7e 100644 --- a/src/OpenFOAM/primitives/Pair/Pair.H +++ b/src/OpenFOAM/primitives/Pair/Pair.H @@ -108,12 +108,6 @@ public: return this->operator[](1); } - //- Return reverse pair - inline Pair reversePair() const - { - return Pair(second(), first()); - } - //- Return other inline const Type& other(const Type& a) const { @@ -147,11 +141,11 @@ public: // - -1: same pair, but reversed order static inline int compare(const Pair& a, const Pair& b) { - if (a[0] == b[0] && a[1] == b[1]) + if (a == b) { return 1; } - else if (a[0] == b[1] && a[1] == b[0]) + else if (a == reverse(b)) { return -1; } @@ -160,35 +154,66 @@ public: return 0; } } - - - // Friend Operators - - friend bool operator==(const Pair& a, const Pair& b) - { - return (a.first() == b.first() && a.second() == b.second()); - } - - friend bool operator!=(const Pair& a, const Pair& b) - { - return !(a == b); - } - - friend bool operator<(const Pair& a, const Pair& b) - { - return - ( - a.first() < b.first() - || - ( - !(b.first() < a.first()) - && a.second() < b.second() - ) - ); - } }; +template +Pair reverse(const Pair& p) +{ + return Pair(p.second(), p.first()); +} + + +template +bool operator==(const Pair& a, const Pair& b) +{ + return (a.first() == b.first() && a.second() == b.second()); +} + + +template +bool operator!=(const Pair& a, const Pair& b) +{ + return !(a == b); +} + + +template +bool operator<(const Pair& a, const Pair& b) +{ + return + ( + a.first() < b.first() + || + ( + !(b.first() < a.first()) + && a.second() < b.second() + ) + ); +} + + +template +bool operator<=(const Pair& a, const Pair& b) +{ + return !(b < a); +} + + +template +bool operator>(const Pair& a, const Pair& b) +{ + return (b < a); +} + + +template +bool operator>=(const Pair& a, const Pair& b) +{ + return !(a < b); +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementBaffles.C b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementBaffles.C index 6b9d1074c5..16528d3ea7 100644 --- a/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementBaffles.C +++ b/src/mesh/autoMesh/autoHexMesh/meshRefinement/meshRefinementBaffles.C @@ -450,7 +450,7 @@ Foam::Map Foam::meshRefinement::getZoneBafflePatches labelPair patches = zPatches; if (fZone.flipMap()[i]) { - patches = patches.reversePair(); + patches = reverse(patches); } if (!bafflePatch.insert(faceI, patches)) From 686b8f19d1750d8144f765036662689a9baa5167 Mon Sep 17 00:00:00 2001 From: laurence Date: Fri, 19 Jul 2013 15:50:48 +0100 Subject: [PATCH 04/11] ENH: Move longestEdge function to face.H as a global function --- src/OpenFOAM/meshes/meshShapes/face/face.C | 24 ++++++++++++++++- src/OpenFOAM/meshes/meshShapes/face/face.H | 8 +++++- .../polyTopoChange/edgeCollapser.C | 26 ------------------- .../polyTopoChange/edgeCollapser.H | 3 --- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.C b/src/OpenFOAM/meshes/meshShapes/face/face.C index 21576535e9..41650aad6c 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.C +++ b/src/OpenFOAM/meshes/meshShapes/face/face.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -829,4 +829,26 @@ Foam::label Foam::face::trianglesQuads } +Foam::label Foam::longestEdge(const face& f, const pointField& pts) +{ + const edgeList& eds = f.edges(); + + label longestEdgeI = -1; + scalar longestEdgeLength = -SMALL; + + forAll(eds, edI) + { + scalar edgeLength = eds[edI].mag(pts); + + if (edgeLength > longestEdgeLength) + { + longestEdgeI = edI; + longestEdgeLength = edgeLength; + } + } + + return longestEdgeI; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.H b/src/OpenFOAM/meshes/meshShapes/face/face.H index c481258a3c..adedf991bd 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.H +++ b/src/OpenFOAM/meshes/meshShapes/face/face.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -408,6 +408,12 @@ public: }; +// Global functions + +//- Find the longest edge on a face. Face point labels index into pts. +label longestEdge(const face& f, const pointField& pts); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/edgeCollapser.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/edgeCollapser.C index 70c2e7c558..6ea1e748b0 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/edgeCollapser.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/edgeCollapser.C @@ -42,32 +42,6 @@ defineTypeNameAndDebug(edgeCollapser, 0); } -Foam::label Foam::edgeCollapser::longestEdge -( - const face& f, - const pointField& pts -) -{ - const edgeList& eds = f.edges(); - - label longestEdgeI = -1; - scalar longestEdgeLength = -SMALL; - - forAll(eds, edI) - { - scalar edgeLength = eds[edI].mag(pts); - - if (edgeLength > longestEdgeLength) - { - longestEdgeI = edI; - longestEdgeLength = edgeLength; - } - } - - return longestEdgeI; -} - - Foam::HashSet Foam::edgeCollapser::checkBadFaces ( const polyMesh& mesh, diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/edgeCollapser.H b/src/dynamicMesh/polyTopoChange/polyTopoChange/edgeCollapser.H index 2393458cf7..dab8bd298b 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/edgeCollapser.H +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/edgeCollapser.H @@ -262,9 +262,6 @@ public: // Check - //- Find the longest edge in a face - static label longestEdge(const face& f, const pointField& pts); - //- Calls motionSmoother::checkMesh and returns a set of bad faces static HashSet