Commit 6834152e authored by berenger-bramas's avatar berenger-bramas

Cells do not need to extend position anymore.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@367 2616d619-271b-44dc-8df4-d4a8f33a7222
parent 38c4a6a2
No preview for this file type
......@@ -27,7 +27,7 @@
* By using this extension it will implement the FAbstractCell without
* inheriting from it.
*/
class FBasicCell : public FExtendPosition, public FExtendMortonIndex, public FExtendCoordinate {
class FBasicCell : public FExtendMortonIndex, public FExtendCoordinate {
public:
/** Default destructor */
virtual ~FBasicCell(){
......
......@@ -38,7 +38,7 @@
*
* Particles and cells has to respect the Abstract class definition.
* Particle must extend {FExtendPosition}
* Cell must extend extend {FExtendPosition,FExtendMortonIndex}
* Cell must extend extend {FTreeCoordinate,FExtendMortonIndex}
*/
template< class ParticleClass, class CellClass, class ContainerClass, class LeafClass>
class FOctree : protected FAssertable, public FNoCopyable {
......@@ -173,7 +173,7 @@ public:
void insert(const ParticleClass& inParticle){
const FTreeCoordinate host = getCoordinateFromPosition( inParticle.getPosition() );
const MortonIndex particleIndex = host.getMortonIndex(leafIndex);
root->insert( particleIndex, host, inParticle, this->height, this->boxWidthAtLevel);
root->insert( particleIndex, host, inParticle, this->height);
}
/** Remove a leaf from its morton index
......@@ -762,7 +762,7 @@ public:
* @param inLevel the level of the element
* @return the number of neighbors
*/
int getDistantNeighbors(const CellClass* inNeighbors[189],
int getDistantNeighbors(const CellClass* inNeighbors[343],
const FTreeCoordinate& workingCell,
const int inLevel) const{
......
......@@ -84,7 +84,7 @@ protected:
* when computing
* @param arrayIndex the index at the leaf index of the new element
*/
void createPreviousCells(MortonIndex arrayIndex, MortonIndex inLeafCellIndex, const FTreeCoordinate& treePosition, const FReal* const inBoxWidthAtLevel){
void createPreviousCells(MortonIndex arrayIndex, MortonIndex inLeafCellIndex, const FTreeCoordinate& treePosition){
int indexLevel = this->subOctreeHeight - 1;
int bottomToTop = 0;
while(indexLevel >= 0 && !this->cells[indexLevel][arrayIndex]){
......@@ -95,13 +95,6 @@ protected:
treePosition.getY() >> bottomToTop,
treePosition.getZ() >> bottomToTop);
const int realLevel = indexLevel + this->getSubOctreePosition();
const FReal widthAtLevel = inBoxWidthAtLevel[realLevel];
newNode->setPosition(F3DPosition(
FReal(treePosition.getX()) * widthAtLevel + widthAtLevel/ FReal(2.0),
FReal(treePosition.getY()) * widthAtLevel + widthAtLevel/ FReal(2.0),
FReal(treePosition.getZ()) * widthAtLevel + widthAtLevel/ FReal(2.0) ));
this->cells[indexLevel][arrayIndex] = newNode;
--indexLevel;
......@@ -117,8 +110,8 @@ protected:
* for example it updates the leaf array marges and calls createPreviousCells()
* @param arrayIndex the position of the new leaf in the leafs array
*/
void newLeafInserted(const int arrayIndex, const MortonIndex inLeafCellIndex, const FTreeCoordinate& host, const FReal* const inBoxWidthAtLevel){
createPreviousCells(arrayIndex,inLeafCellIndex, host, inBoxWidthAtLevel);
void newLeafInserted(const int arrayIndex, const MortonIndex inLeafCellIndex, const FTreeCoordinate& host){
createPreviousCells(arrayIndex,inLeafCellIndex, host);
// Update if this is the bottom left
if(arrayIndex < this->leftLeafIndex) this->leftLeafIndex = arrayIndex;
if(arrayIndex > this->rightLeafIndex) this->rightLeafIndex = arrayIndex;
......@@ -234,7 +227,7 @@ public:
* @param inParticle the particle to insert (must inherite from FAbstractParticle)
* @param inParticle the inTreeHeight the height of the tree
*/
virtual void insert(const MortonIndex index, const FTreeCoordinate& host, const ParticleClass& inParticle, const int inTreeHeight, const FReal* const inBoxWidthAtLevel) = 0;
virtual void insert(const MortonIndex index, const FTreeCoordinate& host, const ParticleClass& inParticle, const int inTreeHeight) = 0;
/**
* Remove a leaf and every cells if needed
......@@ -381,14 +374,14 @@ public:
/**
* Refer to FAbstractSubOctree::insert
*/
void insert(const MortonIndex index, const FTreeCoordinate& host, const ParticleClass& inParticle, const int inTreeHeight, const FReal* const inBoxWidthAtLevel){
void insert(const MortonIndex index, const FTreeCoordinate& host, const ParticleClass& inParticle, const int inTreeHeight){
// Get the morton index for the leaf level
const MortonIndex arrayIndex = FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::getLeafIndex(index,inTreeHeight);
// is there already a leaf?
if( !this->leafs[arrayIndex] ){
this->leafs[arrayIndex] = new LeafClass();
FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::newLeafInserted( int(arrayIndex) , index, host, inBoxWidthAtLevel);
FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::newLeafInserted( int(arrayIndex) , index, host);
}
// add particle to leaf list
this->leafs[arrayIndex]->push(inParticle);
......@@ -510,7 +503,7 @@ public:
/**
* Refer to FAbstractSubOctree::insert
*/
void insert(const MortonIndex index, const FTreeCoordinate& host, const ParticleClass& inParticle, const int inTreeHeight, const FReal* const inBoxWidthAtLevel){
void insert(const MortonIndex index, const FTreeCoordinate& host, const ParticleClass& inParticle, const int inTreeHeight){
// We need the morton index at the bottom level of this sub octree
// so we remove the right side
const MortonIndex arrayIndex = FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::getLeafIndex(index,inTreeHeight);
......@@ -535,10 +528,10 @@ public:
host.getZ() >> (inTreeHeight - nextSubOctreePosition ));
// We need to inform parent class
FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::newLeafInserted( int(arrayIndex), index >> (3 * (inTreeHeight-nextSubOctreePosition) ), hostAtLevel, inBoxWidthAtLevel);
FAbstractSubOctree<ParticleClass,CellClass,ContainerClass,LeafClass>::newLeafInserted( int(arrayIndex), index >> (3 * (inTreeHeight-nextSubOctreePosition) ), hostAtLevel);
}
// Ask next suboctree to insert the particle
this->subleafs[arrayIndex]->insert( index, host, inParticle, inTreeHeight, inBoxWidthAtLevel);
this->subleafs[arrayIndex]->insert( index, host, inParticle, inTreeHeight);
}
/**
......
......@@ -32,7 +32,11 @@ protected:
const FReal boxWidth; //< the box width at leaf level
const int treeHeight; //< The height of the tree
const int periodicLevels; //< The number of levels above 1 used for periodicity
const int periodicLevels; //< The number of levels above 1 used for periodicity
const FReal widthAtLeafLevel; //< the width of a box at leaf level
const FReal widthAtLeafLevelDiv2; //< the width of a box at leaf level divided by 2
const F3DPosition boxCorner; //< the corner of the box system
FHarmonic harmonic; //< The harmonic computation class
......@@ -81,21 +85,42 @@ protected:
}
}
/** Get a leaf real position from its tree coordinate */
F3DPosition getLeafCenter(const FTreeCoordinate coordinate) const {
return F3DPosition(
FReal(coordinate.getX()) * widthAtLeafLevel + widthAtLeafLevelDiv2 + boxCorner.getX(),
FReal(coordinate.getY()) * widthAtLeafLevel + widthAtLeafLevelDiv2 + boxCorner.getX(),
FReal(coordinate.getZ()) * widthAtLeafLevel + widthAtLeafLevelDiv2 + boxCorner.getX());
}
public:
/** Kernel constructor */
FAbstractSphericalKernel(const int inDevP, const int inTreeHeight, const FReal inBoxWidth, const int inPeriodicLevel = 0)
: devP(inDevP), boxWidth(inBoxWidth),
treeHeight(inTreeHeight), periodicLevels(inPeriodicLevel), harmonic(inDevP),
preL2LTransitions(0), preM2MTransitions(0) {
FAbstractSphericalKernel(const int inDevP, const int inTreeHeight, const FReal inBoxWidth, const F3DPosition& inBoxCenter, const int inPeriodicLevel = 0)
: devP(inDevP),
boxWidth(inBoxWidth),
treeHeight(inTreeHeight),
periodicLevels(inPeriodicLevel),
widthAtLeafLevel(inBoxWidth/FReal(1 << inTreeHeight)),
widthAtLeafLevelDiv2(widthAtLeafLevel/2),
boxCorner(inBoxCenter.getX()-(inBoxWidth/2),inBoxCenter.getY()-(inBoxWidth/2),inBoxCenter.getZ()-(inBoxWidth/2)),
harmonic(inDevP),
preL2LTransitions(0),
preM2MTransitions(0) {
allocAndInit();
}
/** Copy constructor */
FAbstractSphericalKernel(const FAbstractSphericalKernel& other)
: devP(other.devP), boxWidth(other.boxWidth),
treeHeight(other.treeHeight), periodicLevels(other.periodicLevels), harmonic(other.devP),
: devP(other.devP),
boxWidth(other.boxWidth),
treeHeight(other.treeHeight),
periodicLevels(other.periodicLevels),
widthAtLeafLevel(other.widthAtLeafLevel),
widthAtLeafLevelDiv2(other.widthAtLeafLevelDiv2),
boxCorner(other.boxCorner),
harmonic(other.devP),
preL2LTransitions(0), preM2MTransitions(0) {
allocAndInit();
......@@ -113,7 +138,7 @@ public:
void P2M(CellClass* const inPole, const ContainerClass* const inParticles) {
FComplexe* FRestrict const cellMultiPole = inPole->getMultipole();
// Copying the position is faster than using cell position
const F3DPosition polePosition = inPole->getPosition();
const F3DPosition polePosition = getLeafCenter(inPole->getCoordinate());
// For all particles in the leaf box
typename ContainerClass::ConstBasicIterator iterParticle(*inParticles);
while( iterParticle.hasNotFinished()){
......@@ -154,7 +179,7 @@ public:
void L2P(const CellClass* const local, ContainerClass* const particles){
const FComplexe* const cellLocal = local->getLocal();
// Copying the position is faster than using cell position
const F3DPosition localPosition = local->getPosition();
const F3DPosition localPosition = getLeafCenter(local->getCoordinate());
// For all particles in the leaf box
typename ContainerClass::BasicIterator iterTarget(*particles);
while( iterTarget.hasNotFinished() ){
......
......@@ -95,8 +95,8 @@ public:
* @param inBoxWidth the size of the simulation box
* @param inPeriodicLevel the number of level upper to 0 that will be requiried
*/
FSphericalBlasKernel(const int inDevP, const int inTreeHeight, const FReal inBoxWidth, const int inPeriodicLevel = 0)
: Parent(inDevP, inTreeHeight, inBoxWidth, inPeriodicLevel),
FSphericalBlasKernel(const int inDevP, const int inTreeHeight, const FReal inBoxWidth, const F3DPosition& inBoxCenter, const int inPeriodicLevel = 0)
: Parent(inDevP, inTreeHeight, inBoxWidth, inBoxCenter, inPeriodicLevel),
FF_MATRIX_ROW_DIM(Parent::harmonic.getExpSize()), FF_MATRIX_COLUMN_DIM(Parent::harmonic.getNExpSize()),
FF_MATRIX_SIZE(FF_MATRIX_ROW_DIM * FF_MATRIX_COLUMN_DIM),
temporaryMultiSource(0), preM2LTransitions(0){
......
......@@ -95,8 +95,8 @@ public:
* @param inBoxWidth the size of the simulation box
* @param inPeriodicLevel the number of level upper to 0 that will be requiried
*/
FSphericalBlockBlasKernel(const int inDevP, const int inTreeHeight, const FReal inBoxWidth, const int inPeriodicLevel = 0)
: Parent(inDevP, inTreeHeight, inBoxWidth, inPeriodicLevel),
FSphericalBlockBlasKernel(const int inDevP, const int inTreeHeight, const FReal inBoxWidth, const F3DPosition& inBoxCenter, const int inPeriodicLevel = 0)
: Parent(inDevP, inTreeHeight, inBoxWidth, inBoxCenter, inPeriodicLevel),
FF_MATRIX_ROW_DIM(Parent::harmonic.getExpSize()), FF_MATRIX_COLUMN_DIM(Parent::harmonic.getNExpSize()),
FF_MATRIX_SIZE(FF_MATRIX_ROW_DIM * FF_MATRIX_COLUMN_DIM),
temporaryMultiSource(0), preM2LTransitions(0){
......
......@@ -68,8 +68,8 @@ public:
* @param inBoxWidth the size of the simulation box
* @param inPeriodicLevel the number of level upper to 0 that will be requiried
*/
FSphericalKernel(const int inDevP, const int inTreeHeight, const FReal inBoxWidth, const int inPeriodicLevel = 0)
: Parent(inDevP, inTreeHeight, inBoxWidth, inPeriodicLevel),
FSphericalKernel(const int inDevP, const int inTreeHeight, const FReal inBoxWidth, const F3DPosition& inBoxCenter, const int inPeriodicLevel = 0)
: Parent(inDevP, inTreeHeight, inBoxWidth, inBoxCenter, inPeriodicLevel),
devM2lP(int(((inDevP*2)+1) * ((inDevP*2)+2) * 0.5)), preM2LTransitions(0) {
allocAndInit();
}
......
......@@ -385,8 +385,8 @@ public:
* @param inBoxWidth the size of the simulation box
* @param inPeriodicLevel the number of level upper to 0 that will be requiried
*/
FSphericalRotationKernel(const int inDevP, const int inTreeHeight, const FReal inBoxWidth, const int inPeriodicLevel = 0)
: Parent(inDevP, inTreeHeight, inBoxWidth, inPeriodicLevel),
FSphericalRotationKernel(const int inDevP, const int inTreeHeight, const FReal inBoxWidth, const F3DPosition& inBoxCenter, const int inPeriodicLevel = 0)
: Parent(inDevP, inTreeHeight, inBoxWidth, inBoxCenter, inPeriodicLevel),
devM2lP(int(((inDevP*2)+1) * ((inDevP*2)+2) * 0.5)), preM2LTransitions(0), rotation_Info(inDevP) {
allocAndInit();
}
......
......@@ -86,7 +86,7 @@ int main(int argc, char ** argv){
std::cout << "Working on particles ..." << std::endl;
counter.tic();
KernelClass kernels(DevP, NbLevels,loader.getBoxWidth());
KernelClass kernels(DevP, NbLevels,loader.getBoxWidth(), loader.getCenterOfBox());
FmmClass algo(&tree,&kernels);
algo.execute();
......
......@@ -239,7 +239,7 @@ int main(int argc, char ** argv){
std::cout << "Working on particles ..." << std::endl;
counter.tic();
KernelClass kernels(DevP, NbLevels,loader.getBoxWidth());
KernelClass kernels(DevP, NbLevels,loader.getBoxWidth(), loader.getCenterOfBox());
FmmClass algo(app.global(),&tree,&kernels);
algo.execute();
......
......@@ -87,7 +87,7 @@ int main(int argc, char ** argv){
std::cout << "Working on particles ..." << std::endl;
counter.tic();
KernelClass kernels(DevP, NbLevels, loader.getBoxWidth());
KernelClass kernels(DevP, NbLevels, loader.getBoxWidth(), loader.getCenterOfBox());
FmmClass algo(&tree,&kernels);
algo.execute();
......
......@@ -193,7 +193,7 @@ int main(int argc, char ** argv){
std::cout << "Working on particles ..." << std::endl;
counter.tic();
KernelClass kernels(DevP, NbLevels, loader.getBoxWidth());
KernelClass kernels(DevP, NbLevels, loader.getBoxWidth(), loader.getCenterOfBox());
FmmClass algo(&tree,&kernels);
algo.execute();
......
......@@ -133,7 +133,7 @@ int main(int argc, char ** argv){
std::cout << "Working on particles ..." << std::endl;
counter.tic();
KernelClass kernels(DevP, NbLevels,loader.getBoxWidth(),BoundaryDeep);
KernelClass kernels(DevP, NbLevels,loader.getBoxWidth(),loader.getCenterOfBox(), BoundaryDeep);
FmmClass algo(&tree,&kernels,BoundaryDeep);
algo.execute();
......
......@@ -111,7 +111,7 @@ int main(int argc, char ** argv){
// -----------------------------------------------------
KernelClass kernels( DevP, NbLevels, loader.getBoxWidth());
KernelClass kernels( DevP, NbLevels, loader.getBoxWidth(), loader.getCenterOfBox());
FmmClass algo( &tree, &kernels);
FOctreeArranger<OctreeClass, ContainerClass, ParticleClass> arranger(&tree);
MassSaver<OctreeClass, ContainerClass, ParticleClass> saver("./out/test%d.csv");
......
......@@ -92,7 +92,7 @@ int main(int argc, char ** argv){
std::cout << "Working on particles ..." << std::endl;
counter.tic();
KernelClass kernels(DevP, NbLevels, loader.getBoxWidth());
KernelClass kernels(DevP, NbLevels, loader.getBoxWidth(), loader.getCenterOfBox());
FmmClass algo(&tree,&kernels);
algo.execute();
......
......@@ -85,7 +85,7 @@ int main(int argc, char ** argv){
std::cout << "Working on particles ..." << std::endl;
counter.tic();
KernelClass kernels(DevP, NbLevels, loader.getBoxWidth());
KernelClass kernels(DevP, NbLevels, loader.getBoxWidth(), loader.getCenterOfBox());
FmmClass algo(&tree,&kernels);
algo.execute();
......
......@@ -120,8 +120,8 @@ int main(int argc, char ** argv){
std::cout << "Working on particles ..." << std::endl;
counter.tic();
KernelClass kernels(DevP, NbLevels, BoxWidth);
KernelClassTyped kernelsTyped(DevP, NbLevels, BoxWidth);
KernelClass kernels(DevP, NbLevels, BoxWidth, CenterOfBox);
KernelClassTyped kernelsTyped(DevP, NbLevels, BoxWidth, CenterOfBox);
FmmClass algo(&tree,&kernels);
FmmClassTyped algoTyped(&treeTyped,&kernelsTyped);
......
......@@ -65,7 +65,7 @@ int main(int argc, char ** argv){
const long NbPart = FParameters::getValue(argc,argv,"-nb", 2000000);
const long DevP = FParameters::getValue(argc,argv,"-p", 5);
const FReal FRandMax = FReal(RAND_MAX);
const F3DPosition centerOfBox = F3DPosition(0.5,0.5,0.5);
FTic counter;
srand ( 1 ); // volontary set seed to constant
......@@ -75,7 +75,7 @@ int main(int argc, char ** argv){
CellClass::Init(DevP);
const FReal boxWidth = 1.0;
OctreeClass tree(NbLevels, SizeSubLevels, boxWidth, F3DPosition(0.5,0.5,0.5));
OctreeClass tree(NbLevels, SizeSubLevels, boxWidth, centerOfBox);
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
......@@ -103,7 +103,7 @@ int main(int argc, char ** argv){
// FTestKernels FBasicKernels
//KernelClass kernels;
KernelClass kernels(DevP, NbLevels,boxWidth);
KernelClass kernels(DevP, NbLevels,boxWidth, centerOfBox);
FmmClass algo(&tree,&kernels);
algo.execute();
......
......@@ -94,8 +94,6 @@ class TestFmb : public FUTester<TestFmb> {
const int SizeSubLevels = 3;
const int DevP = 12;
FSphericalCell::Init(DevP);
// Load the particles file
FFmaBinLoader<ParticleClass> loader(ParticleFile);
if(!loader.isOpen()){
......@@ -105,17 +103,12 @@ class TestFmb : public FUTester<TestFmb> {
}
// Create octree
FSphericalCell::Init(DevP);
OctreeClass testTree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
{
ParticleClass particleToFill;
for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
loader.fillParticle(particleToFill);
testTree.insert(particleToFill);
}
}
loader.fillTree(testTree);
// Run simulation
KernelClass kernels(DevP,NbLevels,loader.getBoxWidth());
KernelClass kernels(DevP, NbLevels, loader.getBoxWidth(), loader.getCenterOfBox());
FmmClass algo(&testTree,&kernels);
algo.execute();
......
......@@ -89,7 +89,7 @@ class TestFmbDirect : public FUTester<TestFmbDirect> {
// Run FMM
Print("Fmm...");
//KernelClass kernels(NbLevels,loader.getBoxWidth());
KernelClass kernels(DevP,NbLevels,loader.getBoxWidth());
KernelClass kernels(DevP,NbLevels,loader.getBoxWidth(), loader.getCenterOfBox());
FmmClass algo(&tree,&kernels);
algo.execute();
......
......@@ -64,13 +64,14 @@ class TestFmbDirectPeriodic : public FUTester<TestFmbDirectPeriodic> {
const long NbSmallBoxesPerSide = (1 << (NbLevels-1));
const FReal SmallBoxWidth = BoxWidth / FReal(NbSmallBoxesPerSide);
const FReal SmallBoxWidthDiv2 = SmallBoxWidth / 2;
const F3DPosition CenterOfBox = F3DPosition(0.5,0.5,0.5);
const int NbPart = NbSmallBoxesPerSide * NbSmallBoxesPerSide * NbSmallBoxesPerSide;
FSphericalCell::Init(DevP);
// Create octree
OctreeClass tree(NbLevels, SizeSubLevels, BoxWidth, F3DPosition(0.5,0.5,0.5));
OctreeClass tree(NbLevels, SizeSubLevels, BoxWidth, CenterOfBox);
{
int idxPart = 0;
for(int idxX = 0 ; idxX < NbSmallBoxesPerSide ; ++idxX){
......@@ -91,7 +92,7 @@ class TestFmbDirectPeriodic : public FUTester<TestFmbDirectPeriodic> {
// Run FMM
Print("Fmm...");
KernelClass kernels( DevP, NbLevels, BoxWidth, PeriodicDeep);
KernelClass kernels( DevP, NbLevels, BoxWidth, CenterOfBox, PeriodicDeep);
FmmClass algo(&tree,&kernels,PeriodicDeep);
algo.execute();
......@@ -234,11 +235,12 @@ class TestFmbDirectPeriodic : public FUTester<TestFmbDirectPeriodic> {
const long NbSmallBoxesPerSide = (1 << (NbLevels-1));
const FReal SmallBoxWidth = BoxWidth / FReal(NbSmallBoxesPerSide);
const FReal SmallBoxWidthDiv2 = SmallBoxWidth / 2;
const F3DPosition CenterOfBox = F3DPosition(0.5,0.5,0.5);
const int NbPart = NbSmallBoxesPerSide * NbSmallBoxesPerSide * NbSmallBoxesPerSide;
// Create octree
TestOctreeClass tree(NbLevels, SizeSubLevels, BoxWidth, F3DPosition(0.5,0.5,0.5));
TestOctreeClass tree(NbLevels, SizeSubLevels, BoxWidth, CenterOfBox);
{
for(int idxX = 0 ; idxX < NbSmallBoxesPerSide ; ++idxX){
for(int idxY = 0 ; idxY < NbSmallBoxesPerSide ; ++idxY){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment