diff --git a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C index 7e9274616e..9e35ee1edc 100644 --- a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C +++ b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C @@ -25,11 +25,10 @@ License \*---------------------------------------------------------------------------*/ #include "sampledTriSurfaceMesh.H" -#include "dictionary.H" -#include "polyMesh.H" -#include "polyPatch.H" -#include "volFields.H" +#include "treeDataPoint.H" #include "meshSearch.H" +#include "Tuple2.H" +#include "globalIndex.H" #include "addToRunTimeSelectionTable.H" @@ -44,6 +43,25 @@ namespace Foam sampledTriSurfaceMesh, word ); + + //- Private class for finding nearest + // - global index + // - sqr(distance) + typedef Tuple2 nearInfo; + + class nearestEqOp + { + + public: + + void operator()(nearInfo& x, const nearInfo& y) const + { + if (y.first() < x.first()) + { + x = y; + } + } + }; } @@ -63,16 +81,16 @@ Foam::sampledTriSurfaceMesh::sampledTriSurfaceMesh ( name, mesh.time().constant(), // instance - "triSurface", // local - mesh, // registry + "triSurface", // local + mesh, // registry IOobject::MUST_READ, - IOobject::NO_WRITE + IOobject::NO_WRITE, + false ) ), needsUpdate_(true), cellLabels_(0), - pointMap_(0), - faceMap_(0) + pointToFace_(0) {} @@ -90,16 +108,16 @@ Foam::sampledTriSurfaceMesh::sampledTriSurfaceMesh ( dict.lookup("surface"), mesh.time().constant(), // instance - "triSurface", // local - mesh, // registry + "triSurface", // local + mesh, // registry IOobject::MUST_READ, - IOobject::NO_WRITE + IOobject::NO_WRITE, + false ) ), needsUpdate_(true), cellLabels_(0), - pointMap_(0), - faceMap_(0) + pointToFace_(0) {} @@ -128,8 +146,7 @@ bool Foam::sampledTriSurfaceMesh::expire() sampledSurface::clearGeom(); MeshStorage::clear(); cellLabels_.clear(); - pointMap_.clear(); - faceMap_.clear(); + pointToFace_.clear(); needsUpdate_ = true; return true; @@ -148,93 +165,137 @@ bool Foam::sampledTriSurfaceMesh::update() // Does approximation by looking at the face centres only const pointField& fc = surface_.faceCentres(); - cellLabels_.setSize(fc.size()); - meshSearch meshSearcher(mesh(), false); + const indexedOctree& cellCentreTree = + meshSearcher.cellCentreTree(); + + + // Global numbering for cells - only used to uniquely identify local cells. + globalIndex globalCells(mesh().nCells()); + List nearest(fc.size()); + forAll(nearest, i) + { + nearest[i].first() = GREAT; + nearest[i].second() = labelMax; + } + + // Search triangles using nearest on local mesh forAll(fc, triI) { - cellLabels_[triI] = meshSearcher.findCell + pointIndexHit nearInfo = cellCentreTree.findNearest ( fc[triI], - -1, // seed - true // use tree + sqr(GREAT) ); - } - - - boolList include(surface_.size(), true); - - label nNotFound = 0; - - forAll(cellLabels_, triI) - { - if (cellLabels_[triI] == -1) + if (nearInfo.hit()) { - include[triI] = false; - nNotFound++; + nearest[triI].first() = magSqr(nearInfo.hitPoint()-fc[triI]); + nearest[triI].second() = globalCells.toGlobal(nearInfo.index()); } } - label nTotalNotFound = returnReduce(nNotFound, sumOp