Started work to support periodic boundaries in KDTree

This commit is contained in:
Guilhem Lavaux 2013-03-04 22:48:13 -05:00
parent d724a7be66
commit 1b06786e63
3 changed files with 54 additions and 2 deletions

View File

@ -184,6 +184,8 @@ namespace CosmoTool {
Cell **sortingHelper;
Cell *base_cell;
bool periodic;
Node *buildTree(Cell **cell0,
uint32_t NumCells,
uint32_t depth,

View File

@ -31,7 +31,8 @@ namespace CosmoTool {
template<int N, typename ValType, typename CType, typename CellSplitter>
KDTree<N,ValType,CType,CellSplitter>::KDTree(Cell *cells, uint32_t Ncells)
{
periodic = false;
base_cell = cells;
numNodes = Ncells;
nodes = new Node[numNodes];
@ -365,7 +366,19 @@ namespace CosmoTool {
CoordType R2 = INFINITY;
Cell *best = 0;
recursiveNearest(root, 0, x, R2, best);
recursiveNearest(root, 0, x, R2, best);
if (periodic)
{
#if 0
ReplicateGenerator<N> replicate(x);
do
{
recursiveNearest(root, 0, replicate.getPosition(), R2, best);
}
while (replicate.next());
#endif
}
return best;
}

View File

@ -0,0 +1,37 @@
#ifndef __REPLICATE_GENERATOR_HPP
#define __REPLICATE_GENERATOR_HPP
namespace CosmoTool
{
template<typename Coord, int N>
class ReplicateGenerator
{
public:
ReplicateGenerator(const Coord x[N])
{
face = 0;
}
bool next()
{
if (face == (2*N))
return false;
face++;
}
Coord getPosition()
{
return x_shifted;
}
private:
Coord x_shifted[N];
int face;
};
};
#endif