diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C index a0fd190585..b0e83ce670 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -26,8 +26,6 @@ License #include "primitiveMesh.H" #include "demandDrivenData.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // defineTypeNameAndDebug(Foam::primitiveMesh, 0); @@ -63,6 +61,8 @@ Foam::primitiveMesh::primitiveMesh() ppPtr_(NULL), cpPtr_(NULL), + cellTreePtr_(NULL), + labels_(0), cellCentresPtr_(NULL), @@ -105,6 +105,8 @@ Foam::primitiveMesh::primitiveMesh ppPtr_(NULL), cpPtr_(NULL), + cellTreePtr_(NULL), + labels_(0), cellCentresPtr_(NULL), @@ -347,4 +349,36 @@ const Foam::cellShapeList& Foam::primitiveMesh::cellShapes() const } +const Foam::indexedOctree& +Foam::primitiveMesh::cellTree() const +{ + if (!cellTreePtr_) + { + treeBoundBox overallBb(points()); + + Random rndGen(261782); + + overallBb = overallBb.extend(rndGen, 1E-4); + overallBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); + overallBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); + + cellTreePtr_ = + new indexedOctree + ( + treeDataCell + ( + false, // not cache bb + *this + ), + overallBb, + 8, // maxLevel + 10, // leafsize + 3.0 // duplicity + ); + } + + return *cellTreePtr_; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H index 23eefb0e0b..cc3bc2c80a 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -67,6 +67,8 @@ SourceFiles #include "Map.H" #include "EdgeMap.H" #include "boundBox.H" +#include "indexedOctree.H" +#include "treeDataCell.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -155,6 +157,9 @@ class primitiveMesh //- Cell-points mutable labelListList* cpPtr_; + //- Search tree to allow spatial tet searching + mutable indexedOctree* cellTreePtr_; + // On-the-fly edge addresing storage @@ -482,6 +487,10 @@ public: const labelListList& cellPoints() const; + //- Build (if necessary) and return the cell search tree + const indexedOctree& cellTree() const; + + // Geometric data (raw!) const vectorField& cellCentres() const; @@ -814,6 +823,9 @@ public: //- Clear topological data void clearAddressing(); + //- Clear cell tree data + void clearCellTree(); + //- Clear all geometry and addressing unnecessary for CFD void clearOut(); }; diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshClear.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshClear.C index f11a901c7d..cc232c162f 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshClear.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshClear.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -99,6 +99,11 @@ void Foam::primitiveMesh::printAllocated() const Pout<< " Cell-point" << endl; } + if (cellTreePtr_) + { + Pout<< " Cell-tree" << endl; + } + // Geometry if (cellCentresPtr_) { @@ -165,6 +170,14 @@ void Foam::primitiveMesh::clearAddressing() deleteDemandDrivenData(pePtr_); deleteDemandDrivenData(ppPtr_); deleteDemandDrivenData(cpPtr_); + + deleteDemandDrivenData(cellTreePtr_); +} + + +void Foam::primitiveMesh::clearCellTree() +{ + deleteDemandDrivenData(cellTreePtr_); } diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshFindCell.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshFindCell.C index a42befb41a..8183cc4f4f 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshFindCell.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshFindCell.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,11 +25,11 @@ License #include "primitiveMesh.H" #include "cell.H" - +#include "tetIndices.H" +#include "polyMeshTetDecomposition.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -// Is the point in the cell bounding box bool Foam::primitiveMesh::pointInCellBB ( const point& p, @@ -60,7 +60,6 @@ bool Foam::primitiveMesh::pointInCellBB } -// Is the point in the cell bool Foam::primitiveMesh::pointInCell(const point& p, label celli) const { const labelList& f = cells()[celli]; @@ -86,7 +85,6 @@ bool Foam::primitiveMesh::pointInCell(const point& p, label celli) const } -// Find the cell with the nearest cell centre Foam::label Foam::primitiveMesh::findNearestCell(const point& location) const { const vectorField& centres = cellCentres(); @@ -109,7 +107,6 @@ Foam::label Foam::primitiveMesh::findNearestCell(const point& location) const } -// Find cell enclosing this location Foam::label Foam::primitiveMesh::findCell(const point& location) const { if (nCells() == 0)