Commit 2b0978af authored by BRAMAS Berenger's avatar BRAMAS Berenger

Add functeur to octree using lambda function to make it clean

parent 7c2112b9
......@@ -28,7 +28,7 @@
*
* If you want to create you own kernels you have to inherit from this class.
*/
template< class ParticleClass, class CellClass, class ContainerClass >
template< class CellClass, class ContainerClass >
class FAbstractKernels{
public:
/** Default destructor */
......
......@@ -28,8 +28,8 @@
*
* This kernels is empty and does nothing.
*/
template< class ParticleClass, class CellClass, class ContainerClass>
class FBasicKernels : public FAbstractKernels<ParticleClass,CellClass,ContainerClass> {
template< class CellClass, class ContainerClass>
class FBasicKernels : public FAbstractKernels<CellClass,ContainerClass> {
public:
/** Default destructor */
virtual ~FBasicKernels(){
......
......@@ -36,8 +36,8 @@
* A the end of a computation, the particles should host then number of particles
* in the simulation (-1).
*/
template< class ParticleClass, class CellClass, class ContainerClass>
class FTestKernels : public FAbstractKernels<ParticleClass,CellClass,ContainerClass> {
template< class CellClass, class ContainerClass>
class FTestKernels : public FAbstractKernels<CellClass,ContainerClass> {
public:
/** Default destructor */
virtual ~FTestKernels(){
......@@ -46,7 +46,7 @@ public:
/** Before upward */
void P2M(CellClass* const pole, const ContainerClass* const particles) {
// the pole represents all particles under
pole->setDataUp(pole->getDataUp() + particles->getSize());
pole->setDataUp(pole->getDataUp() + particles->getNbParticles());
}
/** During upward */
......@@ -82,13 +82,11 @@ public:
/** After Downward */
void L2P(const CellClass* const local, ContainerClass*const particles){
// The particles is impacted by the parent cell
typename ContainerClass::BasicIterator iter(*particles);
while( iter.hasNotFinished() ){
iter.data().setDataDown(iter.data().getDataDown() + local->getDataDown());
iter.gotoNext();
// The particles is impacted by the parent cell
int*const particlesAttributes = targets->getDataDown();
for(int idxPart = 0 ; idxPart < targets ; ++idxPart){
particlesAttributes[idxPart] += local->getDataDown();
}
}
......@@ -103,16 +101,14 @@ public:
}
for(int idx = 0 ; idx < 27 ; ++idx){
if( directNeighborsParticles[idx] ){
inc += directNeighborsParticles[idx]->getSize();
inc += directNeighborsParticles[idx]->getNbParticles();
}
}
typename ContainerClass::BasicIterator iter(*targets);
while( iter.hasNotFinished() ){
iter.data().setDataDown(iter.data().getDataDown() + inc);
iter.gotoNext();
int*const particlesAttributes = targets->getDataDown();
for(int idxPart = 0 ; idxPart < targets ; ++idxPart){
particlesAttributes[idxPart] += inc;
}
}
/** After Downward */
......@@ -123,16 +119,14 @@ public:
long long int inc = 0;
for(int idx = 0 ; idx < 27 ; ++idx){
if( directNeighborsParticles[idx] ){
inc += directNeighborsParticles[idx]->getSize();
inc += directNeighborsParticles[idx]->getNbParticles();
}
}
typename ContainerClass::BasicIterator iter(*targets);
while( iter.hasNotFinished() ){
iter.data().setDataDown(iter.data().getDataDown() + inc);
iter.gotoNext();
int*const particlesAttributes = targets->getDataDown();
for(int idxPart = 0 ; idxPart < targets ; ++idxPart){
particlesAttributes[idxPart] += inc;
}
}
};
......@@ -140,7 +134,7 @@ public:
/** This function test the octree to be sure that the fmm algorithm
* has worked completly.
*/
template< class OctreeClass, class ParticleClass, class CellClass, class ContainerClass, class LeafClass>
template< class OctreeClass, class CellClass, class ContainerClass, class LeafClass>
void ValidateFMMAlgo(OctreeClass* const tree){
std::cout << "Check Result\n";
const int TreeHeight = tree->getHeight();
......
......@@ -1120,6 +1120,25 @@ public:
octreeIterator = avoidGoLeft;
}
}
/**
* @brief forEachLeaf iterate on the cell and apply the function
* @param function
*/
void forEachCellLeaf(std::function<void(CellClass*,LeafClass*)> function){
Iterator octreeIterator(this);
octreeIterator.gotoBottomLeft();
Iterator avoidGoLeft(octreeIterator);
for(int idx = 0 ; idx < this->height - 1 ; ++idx ){
do{
function(octreeIterator.getCurrentCell(),octreeIterator.getCurrentLeaf());
} while(octreeIterator.moveRight());
avoidGoLeft.moveUp();
octreeIterator = avoidGoLeft;
}
}
};
#endif //FOCTREE_HPP
......
......@@ -78,6 +78,10 @@ int main(int argc, char ** argv){
});
std::cout << "There are " << nbCells << " cells " << std::endl;
// To get cell and particles at leaf level
tree.forEachCellLeaf([&](FBasicCell* /*cell*/, LeafClass* /*leaf*/){
});
return 0;
}
......
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