25# ifndef __BITPIT_PATCH_SKD_TREE_HPP__
26# define __BITPIT_PATCH_SKD_TREE_HPP__
28#include "patch_kernel.hpp"
30#include "bitpit_common.hpp"
49 const std::array<std::array<double, 3>, 2> &
getCachedBox(std::size_t rawId)
const;
60 const std::vector<std::size_t> *m_cellRawIds;
62 std::unique_ptr<BoxCache> m_cellBoxes;
70 SkdBox(
const std::array<double,3> &boxMin,
const std::array<double,3> &boxMax);
74 const std::array<double, 3> &
getBoxMin()
const;
75 const std::array<double, 3> &
getBoxMax()
const;
87 bool boxContainsPoint(
const std::array<double,3> &point,
double offset)
const;
91 std::array<double, 3> m_boxMin;
92 std::array<double, 3> m_boxMax;
101 BITPIT_PUBLIC_API
static const std::size_t
NULL_ID;
103 BITPIT_PUBLIC_API
constexpr static const int MAX_CHILDREN = 2;
113 SkdNode(
const SkdPatchInfo *patchInfo, std::size_t cellRangeBegin, std::size_t cellRangeEnd);
117 long getCell(std::size_t n)
const;
125 bool hasChild(ChildLocation child)
const;
126 std::size_t
getChildId(ChildLocation child)
const;
128 double evalPointDistance(
const std::array<double, 3> &point,
bool interiorCellsOnly)
const;
130 void findPointClosestCell(
const std::array<double, 3> &point,
bool interiorCellsOnly,
long *closestId,
double *closestDistance)
const;
131 void updatePointClosestCell(
const std::array<double, 3> &point,
bool interiorCellsOnly,
long *closestId,
double *closestDistance)
const;
132 void updatePointClosestCells(
const std::array<double, 3> &point,
bool interiorCellsOnly, std::vector<long> *closestIds,
double *closestDistance)
const;
137 std::size_t m_cellRangeBegin;
138 std::size_t m_cellRangeEnd;
140 std::array<std::size_t, MAX_CHILDREN> m_children;
142 void initializeBoundingBox();
158 void exportData(
int *rank,
long *
id,
double *distance)
const;
161 static bool m_MPIDatatypeInitialized;
162 static MPI_Datatype m_MPIDatatype;
164 static bool m_MPIMinOperationInitialized;
165 static MPI_Op m_MPIMinOperation;
179 void build(std::size_t leaftThreshold = 1,
bool squeezeStorage =
false);
180 void clear(
bool release =
false);
203 std::vector<std::size_t> m_cellRawIds;
205 std::size_t m_nLeafs;
206 std::size_t m_nMinLeafCells;
207 std::size_t m_nMaxLeafCells;
209 std::vector<SkdNode> m_nodes;
211 bool m_interiorCellsOnly;
213 bool m_threadSafeLookups;
218 MPI_Comm m_communicator;
219 std::vector<SkdBox> m_partitionBoxes;
234 void createChildren(std::size_t parentId, std::size_t leaftThreshold);
235 void createLeaf(std::size_t nodeId);
238 void buildPartitionBoxes();
The PatchKernel class provides an interface for defining patches.
PatchSkdTree is the class that implements a spatial kd-tree (skd-tree) a bitpit patch.
bool isCommunicatorSet() const
std::size_t evalMaxDepth(std::size_t rootId=0) const
const SkdBox & getPartitionBox(int rank) const
std::size_t getLeafMinCellCount() const
std::size_t getLeafMaxCellCount() const
bool areLookupsThreadSafe() const
void setCommunicator(MPI_Comm communicator)
std::size_t getLeafCount() const
SkdNode & _getNode(std::size_t nodeId)
void enableThreadSafeLookups(bool enable)
const SkdNode & getNode(std::size_t nodeId) const
void build(std::size_t leaftThreshold=1, bool squeezeStorage=false)
std::size_t getNodeCount() const
void clear(bool release=false)
PatchSkdTree(const PatchKernel *patch, bool interiorCellsOnly=false)
const MPI_Comm & getCommunicator() const
const PatchKernel & getPatch() const
The PiercedStorageRange allow to iterate using range-based loops over a PiercedStorage.
Metafunction for generating a pierced storage.
The SkdBox class defines a box.
bool boxIntersectsSphere(const std::array< double, 3 > ¢er, double radius) const
double evalPointMaxSquareDistance(const std::array< double, 3 > &point) const
const std::array< double, 3 > & getBoxMin() const
double evalPointMaxDistance(const std::array< double, 3 > &point) const
double evalPointMinDistance(const std::array< double, 3 > &point) const
double evalPointMinSquareDistance(const std::array< double, 3 > &point) const
const std::array< double, 3 > & getBoxMax() const
bool boxContainsPoint(const std::array< double, 3 > &point, double offset) const
The SkdPatchInfo class defines a node of the skd-tree.
double evalPointDistance(const std::array< double, 3 > &point, bool interiorCellsOnly) const
std::vector< long > getCells() const
long getCell(std::size_t n) const
void updatePointClosestCell(const std::array< double, 3 > &point, bool interiorCellsOnly, long *closestId, double *closestDistance) const
void findPointClosestCell(const std::array< double, 3 > &point, bool interiorCellsOnly, long *closestId, double *closestDistance) const
std::array< double, 3 > evalBoxWeightedMean() const
const SkdBox & getBoundingBox() const
void updatePointClosestCells(const std::array< double, 3 > &point, bool interiorCellsOnly, std::vector< long > *closestIds, double *closestDistance) const
static BITPIT_PUBLIC_API const std::size_t NULL_ID
std::size_t getChildId(ChildLocation child) const
bool hasChild(ChildLocation child) const
std::size_t getCellCount() const
The SkdGlobalCellDistance class allows to define a distance between a point and a cell.
static MPI_Datatype getMPIDatatype()
static void executeMPIMinOperation(SkdGlobalCellDistance *in, SkdGlobalCellDistance *inout, int *len, MPI_Datatype *datatype)
void exportData(int *rank, long *id, double *distance) const
static MPI_Op getMPIMinOperation()
The SkdPatchInfo class allows to store patch information needed for the construction and the utilizat...
std::array< double, 3 > evalCachedBoxMean(std::size_t rawId) const
SkdPatchInfo(const PatchKernel *patch, const std::vector< std::size_t > *cellRawIds)
const PatchKernel & getPatch() const
const std::vector< std::size_t > & getCellRawIds() const
const std::array< std::array< double, 3 >, 2 > & getCachedBox(std::size_t rawId) const
std::size_t getCellRawId(std::size_t n) const