Commit d9dec37a authored by PIACIBELLO Cyrille's avatar PIACIBELLO Cyrille

API is usable, see testUseNewApi to have an example of its use, arranger part...

API is usable, see testUseNewApi to have an example of its use, arranger part is suppose to be complete
parent 3b0047b0
......@@ -68,26 +68,27 @@ typedef enum kernel_type {
} scalfmm_kernel_type;
/**
* Enum over the different way scalfmm can handle a particule moving
* out of the simulation box
*/
typedef enum out_of_the_box_config {
exiting = 0, /*If a particule move outside the simulation box,
the simulation stop*/
periodic = 1, /*If a particule move outside the simulation box,
the particules is inserted back at the other side
of the simulation box*/
erasing = 2 /*If a particule move outside the simulation box, it
simply disappears from the simulation */
} scalfmm_out_of_box_behavior;
/* /\** */
/* * Enum over the different way scalfmm can handle a particule moving */
/* * out of the simulation box */
/* *\/ */
/* typedef enum out_of_the_box_config { */
/* exiting = 0, /\*If a particule move outside the simulation box, */
/* the simulation stop*\/ */
/* periodic = 1, /\*If a particule move outside the simulation box, */
/* the particules is inserted back at the other side */
/* of the simulation box*\/ */
/* erasing = 2 /\*If a particule move outside the simulation box, it */
/* simply disappears from the simulation *\/ */
/* } scalfmm_out_of_box_behavior; */
/**
* Enum over the different algorithm that scalfmm can use
*/
typedef enum scalfmm_algorithm_config {
sequential = 0, /* Use the sequential version of Scalfmm*/
multi_thread = 1 /* Use the Multi thread version of Scalfmm*/
multi_thread = 1, /* Use the Multi thread version of Scalfmm*/
periodic = 2 /* Use the periodic version of Scalfmm*/
} scalfmm_algorithm;
......@@ -236,7 +237,7 @@ void scalfmm_set_forces_npart(scalfmm_handle Handle, int nbParts, int* idxOfPart
void scalfmm_get_potentials(scalfmm_handle Handle, int nbParts, double * potentialsToFill);
void scalfmm_set_potentials(scalfmm_handle Handle, int nbParts, double * potentialsToRead);
void scalfmm_get_potentials_npart(scalfmm_handle Handle, int nbParts, int* idxOfParticles, double * potentialsToFill);
void scalfmm_set_potentials_npart(scalfmm_handle Handle, int nbParts, int* idxOfParticles, double * potentialsToFill);
void scalfmm_set_potentials_npart(scalfmm_handle Handle, int nbParts, int* idxOfParticles, double * potentialsToRead);
/**
......@@ -274,20 +275,27 @@ void scalfmm_set_positions(scalfmm_handle Handle, int NbPositions, double * X, d
void scalfmm_set_positions_xyz_npart(scalfmm_handle Handle, int NbPositions, int* idxOfParticles, double * updatedXYZ);
void scalfmm_set_positions_npart(scalfmm_handle Handle, int NbPositions, int* idxOfParticles, double * X, double * Y , double * Z);
void scalfmm_get_positions_xyz(scalfmm_handle Handle, int NbPositions, double * updatedXYZ);
/**
*@brief This is function is to be called after a call modifying some
*of the particles positions (add_to_position or set_position)
*
*/
void scalfmm_update_tree(scalfmm_handle handle);
void scalfmm_get_positions_xyz(scalfmm_handle Handle, int NbPositions, double * positionsToFill);
void scalfmm_get_positions(scalfmm_handle Handle, int NbPositions, double * X, double * Y , double * Z);
void scalfmm_get_positions_xyz_npart(scalfmm_handle Handle, int NbPositions, int* idxOfParticles, double * updatedXYZ);
void scalfmm_get_positions_xyz_npart(scalfmm_handle Handle, int NbPositions, int* idxOfParticles, double * positionsToFill);
void scalfmm_get_positions_npart(scalfmm_handle Handle, int NbPositions, int* idxOfParticles, double * X, double * Y , double * Z);
/**
* @brief This function provides a way for the user to define scalfmm
* behavior in case a particule get out of the box after a
* displacement
* @param Handle scalfmm_handle provided by scalfmm_init
* @param Member of enum scalfmm_out_of_box_behavior
*/
/* /\** */
/* * @brief This function provides a way for the user to define scalfmm */
/* * behavior in case a particule get out of the box after a */
/* * displacement */
/* * @param Handle scalfmm_handle provided by scalfmm_init */
/* * @param Member of enum scalfmm_out_of_box_behavior */
/* *\/ */
void scalfmm_out_of_the_box_config(scalfmm_handle Handle,scalfmm_out_of_box_behavior config);
/* void scalfmm_out_of_the_box_config(scalfmm_handle Handle,scalfmm_out_of_box_behavior config); */
/**
* @brief This function provides a way for choosing the algorithm to
......
This diff is collapsed.
......@@ -49,13 +49,13 @@
class FScalFMMEngine{
protected:
scalfmm_kernel_type kernelType;
scalfmm_out_of_box_behavior OutOfBoxBehavior;
scalfmm_algorithm Algorithm;
FVector<bool> progress;
int nbPart;
public:
FScalFMMEngine() : OutOfBoxBehavior(exiting), Algorithm(multi_thread), progress(), nbPart(0){
FScalFMMEngine() : Algorithm(multi_thread), progress(), nbPart(0){
//Default behavior in case of out of the box particles is exiting
}
......@@ -65,10 +65,10 @@ public:
return this->kernelType;
}
//To deal with particles moving outside the box
void out_of_the_box_config(scalfmm_out_of_box_behavior config){
this->OutOfBoxBehavior = config;
}
// //To deal with particles moving outside the box
// void out_of_the_box_config(scalfmm_out_of_box_behavior config){
// this->OutOfBoxBehavior = config;
// }
//To change default algorithm
void algorithm_config(scalfmm_algorithm config){
......@@ -173,13 +173,21 @@ public:
double * X, double * Y , double * Z){
FAssertLF(0,"No tree instancied, exiting ...\n");
}
virtual void get_positions_xyz( int NbPositions, double * updatedXYZ){
//Function to update the tree
virtual void update_tree(){
FAssertLF(0,"No tree instancied, exiting ...\n");
}
//Function to get the positions
virtual void get_positions_xyz( int NbPositions, double * positionsToFill){
FAssertLF(0,"No tree instancied, exiting ...\n");
}
virtual void get_positions( int NbPositions, double * X, double * Y , double * Z){
FAssertLF(0,"No tree instancied, exiting ...\n");
}
virtual void get_positions_xyz_npart( int NbPositions, int* idxOfParticles, double * updatedXYZ){
virtual void get_positions_xyz_npart( int NbPositions, int* idxOfParticles, double * positionsToFill){
FAssertLF(0,"No tree instancied, exiting ...\n");
}
virtual void get_positions_npart( int NbPositions, int* idxOfParticles,
......@@ -294,11 +302,11 @@ extern "C" void scalfmm_set_potentials_npart(scalfmm_handle Handle, int nbParts,
}
//To deal with positions
//Out of the box behavior
extern "C" void scalfmm_out_of_the_box_config(scalfmm_handle Handle,scalfmm_out_of_box_behavior config){
((ScalFmmCoreHandle * ) Handle)->engine->out_of_the_box_config(config);
}
// //To deal with positions
// //Out of the box behavior
// extern "C" void scalfmm_out_of_the_box_config(scalfmm_handle Handle,scalfmm_out_of_box_behavior config){
// ((ScalFmmCoreHandle * ) Handle)->engine->out_of_the_box_config(config);
// }
//Update
extern "C" void scalfmm_add_to_positions_xyz(scalfmm_handle Handle, int NbPositions, double * updatedXYZ){
......@@ -334,6 +342,11 @@ extern "C" void scalfmm_set_positions_npart(scalfmm_handle Handle, int NbPositio
double * X, double * Y , double * Z){
((ScalFmmCoreHandle * ) Handle)->engine->set_positions_npart(NbPositions, idxOfParticles, X, Y, Z);
}
extern "C" void scalfmm_update_tree(scalfmm_handle Handle){
((ScalFmmCoreHandle * ) Handle)->engine->update_tree();
}
//Get back positions
extern "C" void scalfmm_get_positions_xyz(scalfmm_handle Handle, int NbPositions, double * updatedXYZ){
((ScalFmmCoreHandle * ) Handle)->engine->get_positions_xyz(NbPositions, updatedXYZ);
......
......@@ -7,8 +7,13 @@
void compute_displacement_from_forces(double * fXYZ, double* dXYZ, int nb_xyz){
//Do some things
void compute_displacement_from_forces(double * fXYZ, double * charge,double* dXYZ, int nb_xyz){
int idPart;
for(idPart = 0 ; idPart < nb_xyz ; ++idPart){
dXYZ[idPart*3+0] = fXYZ[idPart*3+0]*0.001/charge[idPart];
dXYZ[idPart*3+1] = fXYZ[idPart*3+1]*0.001/charge[idPart];
dXYZ[idPart*3+2] = fXYZ[idPart*3+2]*0.001/charge[idPart];
}
}
......@@ -19,16 +24,18 @@ int main(int argc, char ** av){
//Octree configuration
int TreeHeight = 5;
double boxWidth = 1.0;
double boxWidth = 2.0;
double boxCenter[3] = {0.0,0.0,0.0};
//Init our lib
scalfmm_handle handle = scalfmm_init(TreeHeight,boxWidth,boxCenter,myChoice); //The tree is built
//Creation of an array of particles
int nb_of_parts = 200;
int nb_of_parts = 10;
int idxPart;
double * positionsXYZ = malloc(sizeof(double)*3*nb_of_parts);
memset(positionsXYZ,0,sizeof(double)*3*nb_of_parts);
for(idxPart = 0; idxPart<nb_of_parts ; ++idxPart){
positionsXYZ[idxPart*3+0] = (random()/(double)(RAND_MAX))*boxWidth - boxWidth/2 + boxCenter[0];
positionsXYZ[idxPart*3+1] = (random()/(double)(RAND_MAX))*boxWidth - boxWidth/2 + boxCenter[1];
......@@ -38,11 +45,12 @@ int main(int argc, char ** av){
//Creation of charge for each part
double * array_of_charge = malloc(sizeof(double)*nb_of_parts);
for(idxPart = 0; idxPart<nb_of_parts ; ++idxPart){
array_of_charge[idxPart] = (random()/(double)(RAND_MAX)); //charge in [-1,1]
array_of_charge[idxPart] = 1.0*(idxPart%2);
}
//Inserting the array in the tree
scalfmm_tree_insert_particles_xyz(handle,nb_of_parts,positionsXYZ);
//Set the charge
scalfmm_set_physical_values(handle,nb_of_parts,array_of_charge);
......@@ -51,11 +59,15 @@ int main(int argc, char ** av){
int nb_iteration = 100;
int curr_iteration = 0;
//Array to store the forces
//Array to store the output
double * array_of_forces = malloc(sizeof(double)*3*nb_of_parts);
memset(array_of_forces,0,sizeof(double)*3*nb_of_parts);
double * array_of_pot = malloc(sizeof(double)*nb_of_parts);
memset(array_of_pot,0,sizeof(double)*nb_of_parts);
//Array to store the displacement
double * array_of_displacement = malloc(sizeof(double)*3*nb_of_parts);
memset(array_of_displacement,0,sizeof(double)*3*nb_of_parts);
//Start of an iteration loop
while(curr_iteration < nb_iteration){
......@@ -64,13 +76,39 @@ int main(int argc, char ** av){
//Get the resulting forces
scalfmm_get_forces_xyz(handle,nb_of_parts,array_of_forces);
//Get the resulting potential
scalfmm_get_potentials(handle,nb_of_parts,array_of_pot);
//User function to compute the movement of each part
compute_displacement_from_forces(array_of_forces,array_of_displacement,nb_of_parts);
//User function to compute the movement of each part
compute_displacement_from_forces(array_of_forces,array_of_charge,array_of_displacement,nb_of_parts);
//get position in order to display
scalfmm_get_positions_xyz(handle,nb_of_parts,positionsXYZ);
//Display forces :
{
printf("Iteration n° %d\n",curr_iteration);
for(idxPart = 0 ; idxPart< nb_of_parts ; ++idxPart){
printf("Pos : %e, %e, %e, Fxyz %e %e %e, \n \t displ : %e, %e, %e \n",
positionsXYZ[idxPart*3+0],
positionsXYZ[idxPart*3+1],
positionsXYZ[idxPart*3+2],
array_of_forces[idxPart*3],
array_of_forces[idxPart*3+1],
array_of_forces[idxPart*3+2],
array_of_displacement[idxPart*3+0],
array_of_displacement[idxPart*3+1],
array_of_displacement[idxPart*3+2]);
}
}
//Apply displacement computed
scalfmm_add_to_positions_xyz(handle,nb_of_parts,array_of_displacement);
//Update Consequently the tree
scalfmm_update_tree(handle);
//Continue the loop
curr_iteration++;
}
......
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Bérenger Bramas, Matthias Messner
// olivier.coulaud@inria.fr, berenger.bramas@inria.fr
// This software is a computer program whose purpose is to compute the FMM.
//
// This software is governed by the CeCILL-C and LGPL licenses and
// abiding by the rules of distribution of free software.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info".
// "http://www.gnu.org/licenses".
// ===================================================================================
#ifndef FARRANGERPERIODIC_HPP
#define FARRANGERPERIODIC_HPP
#include "Utils/FGlobalPeriodic.hpp"
#include "Arranger/FOctreeArranger.hpp"
template <class OctreeClass, class ContainerClass, class LeafInterface >
class FArrangerPeriodic : public FOctreeArranger<OctreeClass,ContainerClass,LeafInterface>{
public:
FArrangerPeriodic(OctreeClass * octree) : FOctreeArranger<OctreeClass,ContainerClass,LeafInterface>(octree){
}
// To put in inhereed class
void checkPosition(FPoint& particlePos) override {
particlePos.setX( getPeriodicPos( particlePos.getX(), DirMinusX, DirPlusX, (this->MaxBox).getX(),(this->MinBox).getX(),DirX));
particlePos.setY( getPeriodicPos( particlePos.getY(), DirMinusY, DirPlusY, (this->MaxBox).getY(),(this->MinBox).getY(),DirY));
particlePos.setZ( getPeriodicPos( particlePos.getZ(), DirMinusZ, DirPlusZ, (this->MaxBox).getZ(),(this->MinBox).getZ(),DirZ));
}
FReal getPeriodicPos(FReal pos, PeriodicCondition periodicPlus, PeriodicCondition periodicMinus,FReal minDir,FReal maxDir,const int dir){
FReal res = pos;
if( TestPeriodicCondition(dir, periodicPlus) ){
while(res >= maxDir){
res += (-(this->boxWidth));
}
}
if( TestPeriodicCondition(dir, periodicMinus) ){
while(res < minDir){
res += (this->boxWidth);
}
}
return res;
}
};
#endif // FCONVERTERPERIODIC_HPP
......@@ -40,31 +40,32 @@
template <class OctreeClass, class ContainerClass, class LeafInterface >
class FOctreeArranger {
OctreeClass* const tree; //< The tree to work on
FReal boxWidth;
FPoint min;
FPoint max;
public:
FReal boxWidth;
FPoint MinBox;
FPoint MaxBox;
LeafInterface * interface;
public:
/** Basic constructor */
FOctreeArranger(OctreeClass* const inTree) : tree(inTree), boxWidth(tree->getBoxWidth()),
min(tree->getBoxCenter(),-tree->getBoxWidth()/2),
max(tree->getBoxCenter(),tree->getBoxWidth()/2),
MinBox(tree->getBoxCenter(),-tree->getBoxWidth()/2),
MaxBox(tree->getBoxCenter(),tree->getBoxWidth()/2),
interface(){
FAssertLF(tree, "Tree cannot be null" );
interface = new LeafInterface();
}
}
virtual ~FOctreeArranger(){
delete interface;
}
virtual void checkPosition(const FPoint& particlePos){
virtual void checkPosition(FPoint& particlePos){
// Assert
FAssertLF( min.getX() < particlePos.getX() && max.getX() > particlePos.getX()
&& min.getY() < particlePos.getY() && max.getY() > particlePos.getY()
&& min.getZ() < particlePos.getZ() && max.getZ() > particlePos.getZ());
FAssertLF( MinBox.getX() < particlePos.getX() && MaxBox.getX() > particlePos.getX()
&& MinBox.getY() < particlePos.getY() && MaxBox.getY() > particlePos.getY()
&& MinBox.getZ() < particlePos.getZ() && MaxBox.getZ() > particlePos.getZ());
}
......
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