Commit 5b1689e8 authored by PIACIBELLO Cyrille's avatar PIACIBELLO Cyrille

Method scalfmm_apply_on_leaf added. See CScalfmmApi.h for the documentation.

parent 8c822839
......@@ -159,6 +159,22 @@ typedef FSize (*Callback_get_cell_size)(int level, void * userDatas, long long m
*/
typedef void (*Callback_copy_cell)(void * userDatas, FSize size, void * memoryAllocated);
/**
* @brief Callback called if scalfmm_finalize_cell is called.
* @param level current level of leaves (ie height of the tree)
* @param nbParts Number of particles inside that leaf
* @param idxParts array of size nbParts, containing the indices of each parts
* @param morton_index of the current cell
* @param center of the current leaf (3 double)
* @param userData cell user data
* @param userData Kernel user data
*/
typedef void (*Callback_finalize_leaf)(int level, FSize nbParts, const FSize * idxParts, long long morton_index, double center[3],
void * cellDatas, void * userDatas);
/**
* @brief Callback used to initialize again userDat from what's have
* been stored inside an array with Callback_copy_cell.
......@@ -611,6 +627,13 @@ void scalfmm_user_kernel_config(scalfmm_handle Handle, Scalfmm_Kernel_Descriptor
*/
void scalfmm_execute_fmm(scalfmm_handle Handle);
/**
* @brief This function apply the call back on each leaf. Should be
* called after insert_parts.
* @param
*/
void scalfmm_apply_on_leaf(scalfmm_handle Handle, Callback_finalize_leaf function);
/////////////////////////////////////////////////////////////////////
////////////////// Dealloc Part /////////////////
......
......@@ -173,7 +173,9 @@ public:
virtual void set_potentials_npart( int nbParts, int* idxOfParticles, FReal * potentialsToRead, PartType type){
FAssertLF(0,"No tree instancied, exiting ...\n");
}
virtual void apply_on_each_leaf(Callback_finalize_leaf function){
FAssertLF(0,"No tree instancied, exiting ...\n");
}
/** Test ... */
......@@ -452,6 +454,7 @@ public:
update_tree();
}
template<class ContainerClass,class LeafClass,class CellClass>
void generic_set_positions(FOctree<FReal,CellClass,ContainerClass,LeafClass> * octree,
int NbPositions, FReal * X, FReal * Y, FReal * Z, PartType type){
......@@ -1066,6 +1069,10 @@ extern "C" void scalfmm_set_upper_limit(scalfmm_handle Handle, int upperLimit){
((ScalFmmCoreHandle<double> * ) Handle)->engine->set_upper_limit(upperLimit);
}
extern "C" void scalfmm_apply_on_leaf(scalfmm_handle Handle, Callback_finalize_leaf function){
((ScalFmmCoreHandle<double> * ) Handle)->engine->apply_on_each_leaf(function);
}
#ifdef SCALFMM_USE_MPI
extern "C" void scalfmm_create_local_partition(scalfmm_handle handle, int nbPoints, double * particleXYZ, double ** localArrayFilled,
FSize ** indexesFilled, FSize * outputNbPoint){
......
......@@ -637,10 +637,18 @@ public:
});
}
void apply_on_each_leaf(Callback_finalize_leaf function){
if(octreeDist){
FUserKernelEngine<FReal,LeafClass>::template generic_apply_on_each_leaf<ContainerClass,CoreCellDist>(octreeDist,kernel->getUserKernelDatas(),function);
}else{
std::cout << "Need to Build the tree and insert the parts First\n" << std::endl;
}
}
void execute_fmm(){
FAssertLF(octreeDist,
"No kernel set, please use scalfmm_user_kernel_config before calling the execute routine ... Exiting \n");
"No Tree set, please use scalfmm_user_kernel_config before calling the execute routine ... Exiting \n");
//Only one config shall work , so let's use it
switch(FScalFMMEngine<FReal>::Algorithm){
case 5:
......
......@@ -188,7 +188,7 @@ public:
kernel.p2p_full(targets->getNbParticles(),targets->getIndexes().data(),indicesPerNeighbors,nbPartPerNeighbors,sourcePosition,size,userData);
}
if(kernel.p2p_sym){
for(int idx = 0 ; ((idx < size) && (idx < 14)) ; ++idx){
for(int idx = 0 ; ((idx < size) && (sourcePosition[idx] < 14)) ; ++idx){
kernel.p2p_sym(targets->getNbParticles(), targets->getIndexes().data(),
neighbors[idx]->getNbParticles(), neighbors[idx]->getIndexes().data(), userData);
}
......@@ -431,28 +431,28 @@ public:
FScalFMMEngine<FReal>::template generic_set_positions_npart<ContainerClass,LeafClass,CoreCell>(octree,NbPositions,idxOfParticles,X,Y,Z,type);
}
// void update_tree(){
// if(arranger){
// arranger->rearrange();
// //then, we need to re-allocate cells user data for the
// //cells created during the process and free user datas for
// //the cells removed during the process
// init_cell();
// }
// else{
// if(FScalFMMEngine<FReal>::Algorithm == 2){ //case in wich the periodic algorithm is used
// arranger = new ArrangerClassPeriodic(octree);
// arranger->rearrange();
// init_cell();
// }
// else{
// arranger = new ArrangerClass(octree);
// arranger->rearrange();
// init_cell();
// }
// }
// }
template<class ContainerClass,class CellClass>
void generic_apply_on_each_leaf(FOctree<FReal,CellClass,ContainerClass,LeafClass>* octreeIn,
void * kernelUserData,
Callback_finalize_leaf function){
if(octreeIn){
octreeIn->forEachCellLeaf([&](CoreCell * currCell, LeafClass * leaf){
int lvl = octreeIn->getHeight();
MortonIndex currMorton = currCell->getMortonIndex();
//Computation of the Center from Coordinate
FTreeCoordinate treeCoord = currCell->getCoordinate();
double boxWidthLeafLevel = octreeIn->getBoxWidth() / (2 << lvl);
FPoint<double> absolutCoord = FPoint<double>(treeCoord.getX()*boxWidthLeafLevel,
treeCoord.getY()*boxWidthLeafLevel,
treeCoord.getZ()*boxWidthLeafLevel);
FPoint<double> leafCenter = absolutCoord + (octreeIn->getBoxCenter()-octreeIn->getBoxWidth()) + boxWidthLeafLevel/2;
function(lvl,leaf->getSrc()->getNbParticles(),leaf->getSrc()->getIndexes().data(),currMorton,leafCenter.getDataValue(),
currCell->getContainer(),kernelUserData);
});
}else{
std::cout << "Need to Build the tree and insert the parts First\n" << std::endl;
}
}
/*
* Call the user allocator on userDatas member field of each cell
......
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