Merge branch 'master' of bitbucket.org:glavaux/cosmotool
This commit is contained in:
commit
84e841814a
9 changed files with 93 additions and 58 deletions
|
@ -6,7 +6,6 @@ SET(CosmoTool_SRCS
|
|||
load_data.cpp
|
||||
loadGadget.cpp
|
||||
loadRamses.cpp
|
||||
octTree.cpp
|
||||
powerSpectrum.cpp
|
||||
miniargs.cpp
|
||||
growthFactor.cpp
|
||||
|
|
|
@ -55,12 +55,20 @@ namespace CosmoTool
|
|||
|
||||
typedef octCoordType OctCoords[3];
|
||||
|
||||
template<class T = void>
|
||||
struct OctCell
|
||||
{
|
||||
octPtr numberLeaves;
|
||||
octPtr children[8];
|
||||
T data;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct OctTree_defaultUpdater {
|
||||
void operator()(T& d) { }
|
||||
};
|
||||
|
||||
template<typename T_dataUpdater = OctTree_defaultUpdater<void>, class T = void>
|
||||
class OctTree
|
||||
{
|
||||
public:
|
||||
|
@ -103,9 +111,10 @@ namespace CosmoTool
|
|||
|
||||
|
||||
protected:
|
||||
T_dataUpdater updater;
|
||||
const FCoordinates *particles;
|
||||
octPtr numParticles;
|
||||
OctCell *cells;
|
||||
OctCell<T> *cells;
|
||||
float Lbox;
|
||||
octPtr lastNode;
|
||||
octPtr numCells;
|
||||
|
@ -128,47 +137,47 @@ namespace CosmoTool
|
|||
FCoordinates center, realCenter;
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
center[j] = icoord[j]/(2.*octCoordCenter);
|
||||
realCenter[j] = xMin[j] + center[j]*lenNorm;
|
||||
}
|
||||
{
|
||||
center[j] = icoord[j]/(2.*octCoordCenter);
|
||||
realCenter[j] = xMin[j] + center[j]*lenNorm;
|
||||
}
|
||||
|
||||
f(realCenter, cells[node].numberLeaves, lenNorm*halfNodeLength/(float)octCoordCenter,
|
||||
cells[node].children[0] == invalidOctCell, // True if this is a meta-node
|
||||
false);
|
||||
cells[node].children[0] == invalidOctCell, // True if this is a meta-node
|
||||
false);
|
||||
|
||||
if (!condition(realCenter, cells[node].numberLeaves,
|
||||
lenNorm*halfNodeLength/(float)octCoordCenter,
|
||||
cells[node].children[0] == invalidOctCell))
|
||||
return;
|
||||
return;
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
octPtr newNode = cells[node].children[i];
|
||||
int ipos[3] = { (i&1), (i&2)>>1, (i&4)>>2 };
|
||||
|
||||
if (newNode == emptyOctCell || newNode == invalidOctCell)
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
newCoord[j] = icoord[j]+(2*ipos[j]-1)*halfNodeLength/2;
|
||||
|
||||
if (newNode & octParticleMarker)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
center[j] = newCoord[j]/(2.*octCoordCenter);
|
||||
realCenter[j] = xMin[j] + lenNorm*center[j];
|
||||
}
|
||||
{
|
||||
octPtr newNode = cells[node].children[i];
|
||||
int ipos[3] = { (i&1), (i&2)>>1, (i&4)>>2 };
|
||||
|
||||
if (newNode == emptyOctCell || newNode == invalidOctCell)
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
newCoord[j] = icoord[j]+(2*ipos[j]-1)*halfNodeLength/2;
|
||||
|
||||
if (newNode & octParticleMarker)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
center[j] = newCoord[j]/(2.*octCoordCenter);
|
||||
realCenter[j] = xMin[j] + lenNorm*center[j];
|
||||
}
|
||||
|
||||
f(realCenter,
|
||||
1, lenNorm*halfNodeLength/(2.*octCoordCenter),
|
||||
false, true);
|
||||
continue;
|
||||
}
|
||||
f(realCenter,
|
||||
1, lenNorm*halfNodeLength/(2.*octCoordCenter),
|
||||
false, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
walkTreeElements(f, condition, cells[node].children[i], newCoord, halfNodeLength/2);
|
||||
}
|
||||
walkTreeElements(f, condition, cells[node].children[i], newCoord, halfNodeLength/2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -177,4 +186,6 @@ namespace CosmoTool
|
|||
};
|
||||
|
||||
|
||||
#include "octTree.tcc"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -39,8 +39,9 @@ knowledge of the CeCILL license and that you accept its terms.
|
|||
#include "config.hpp"
|
||||
#include "octTree.hpp"
|
||||
|
||||
namespace CosmoTool {
|
||||
|
||||
using namespace std;
|
||||
using namespace CosmoTool;
|
||||
|
||||
//#define VERBOSE
|
||||
|
||||
|
@ -59,7 +60,8 @@ static uint32_t mypow(uint32_t i, uint32_t p)
|
|||
return j*j*i;
|
||||
}
|
||||
|
||||
OctTree::OctTree(const FCoordinates *particles, octPtr numParticles,
|
||||
template<typename Updater, typename T>
|
||||
OctTree<Updater,T>::OctTree(const FCoordinates *particles, octPtr numParticles,
|
||||
uint32_t maxMeanTreeDepth, uint32_t maxAbsoluteDepth,
|
||||
uint32_t threshold)
|
||||
{
|
||||
|
@ -94,7 +96,7 @@ OctTree::OctTree(const FCoordinates *particles, octPtr numParticles,
|
|||
}
|
||||
cout << xMin[0] << " " << xMin[1] << " " << xMin[2] << " lNorm=" << lenNorm << endl;
|
||||
|
||||
cells = new OctCell[numCells];
|
||||
cells = new OctCell<T>[numCells];
|
||||
Lbox = (float)(octCoordTypeNorm+1);
|
||||
|
||||
cells[0].numberLeaves = 0;
|
||||
|
@ -110,12 +112,14 @@ OctTree::OctTree(const FCoordinates *particles, octPtr numParticles,
|
|||
//#endif
|
||||
}
|
||||
|
||||
OctTree::~OctTree()
|
||||
template<typename Updater, typename T>
|
||||
OctTree<Updater,T>::~OctTree()
|
||||
{
|
||||
delete cells;
|
||||
}
|
||||
|
||||
void OctTree::buildTree(uint32_t maxAbsoluteDepth)
|
||||
template<typename Updater, typename T>
|
||||
void OctTree<Updater,T>::buildTree(uint32_t maxAbsoluteDepth)
|
||||
{
|
||||
for (octPtr i = 0; i < numParticles; i++)
|
||||
{
|
||||
|
@ -129,7 +133,8 @@ void OctTree::buildTree(uint32_t maxAbsoluteDepth)
|
|||
}
|
||||
|
||||
|
||||
void OctTree::insertParticle(octPtr node,
|
||||
template<typename Updater, typename T>
|
||||
void OctTree<Updater,T>::insertParticle(octPtr node,
|
||||
const OctCoords& icoord,
|
||||
octCoordType halfNodeLength,
|
||||
octPtr particleId,
|
||||
|
@ -208,3 +213,5 @@ void OctTree::insertParticle(octPtr node,
|
|||
cells[node].children[octPos] = newNode;
|
||||
}
|
||||
|
||||
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue