Commit 8c9af7f2 authored by BRAMAS Berenger's avatar BRAMAS Berenger

update code and remove error

parent 70ea38d5
......@@ -1142,6 +1142,25 @@ public:
}
}
/**
* @brief forEachLeaf iterate on the cell and apply the function
* @param function
*/
void forEachCellWithLevel(std::function<void(CellClass*,const int)> function){
Iterator octreeIterator(this);
octreeIterator.gotoBottomLeft();
Iterator avoidGoLeft(octreeIterator);
for(int idx = this->height-1 ; idx >= 1 ; --idx ){
do{
function(octreeIterator.getCurrentCell(),idx);
} while(octreeIterator.moveRight());
avoidGoLeft.moveUp();
octreeIterator = avoidGoLeft;
}
}
/**
* @brief forEachLeaf iterate on the cell and apply the function
* @param function
......
......@@ -426,7 +426,7 @@ public:
// for all z in interval
for(int idxZ = startZ ; idxZ <= endZ ; ++idxZ){
// do not fill close neigbors
if( FMath::Abs(idxX) > 1 && FMath::Abs(idxY) > 1 && FMath::Abs(idxZ) > 1 ){
if( FMath::Abs(idxX) > 1 || FMath::Abs(idxY) > 1 || FMath::Abs(idxZ) > 1 ){
neighbors[neighIndex(idxX,idxY,idxZ)] = &source;
++counter;
}
......@@ -777,7 +777,6 @@ public:
processTopM2MInIntervals( &angleborder, upperCells[nbLevelsAboveRoot+1], 1,1 , 1,1 , 1,1);
counter += fillM2LVectorFromIntervals(neighbors, angleborder, -2,-2 , -2,-2, -2,-2);
kernels->M2L( &upperCells[0] , neighbors, counter, 2);
CellClass* virtualChild[8];
......
......@@ -1686,7 +1686,7 @@ public:
// for all z in interval
for(int idxZ = startZ ; idxZ <= endZ ; ++idxZ){
// do not fill close neigbors
if( FMath::Abs(idxX) > 1 && FMath::Abs(idxY) > 1 && FMath::Abs(idxZ) > 1 ){
if( FMath::Abs(idxX) > 1 || FMath::Abs(idxY) > 1 || FMath::Abs(idxZ) > 1 ){
neighbors[neighIndex(idxX,idxY,idxZ)] = &source;
++counter;
}
......
......@@ -126,6 +126,10 @@ public:
return this->boxWidth;
}
FReal getEnergy() const{
return 0.0;
}
/**
* Fill a particle
* @warning to work with the loader, particles has to expose a setPosition method
......@@ -135,7 +139,7 @@ public:
7.64746800518 -1.34490700206 -2.81036521708
-4406.48579000 6815.52906417 10340.2577024
*/
void fillParticle(FReal inParticle[7], int inIndex [1], Type inType[1]){
void fillParticle(FPoint* inPosition, FReal inForces[3], FReal* inPhysicalValue, int* inIndex){
FReal x, y, z, fx, fy, fz, vx, vy, vz;
int index;
char type[2];
......@@ -156,21 +160,20 @@ public:
file >> fx >> fy >> fz;
}
inParticle[0] = x;
inParticle[1] = y;
inParticle[2] = z;
inParticle[3] = fx;
inParticle[4] = fy;
inParticle[5] = fz;
inIndex[0] = index;
inPosition->setPosition( x, y ,z);
inForces[0] = fx;
inForces[1] = fy;
inForces[2] = fz;
if( strncmp(type, "OW", 2) == 0){
inParticle[6] = FReal(-0.82);
inType[0] = OW;
*inPhysicalValue = FReal(-0.82);
*inIndex = OW;
}
else{
inParticle[6] = FReal(-0.41);
inType[0] = HW;
*inPhysicalValue = FReal(-0.41);
*inIndex = HW;
}
}
......
......@@ -141,9 +141,6 @@ int main(int argc, char* argv[])
time.tic();
for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
FPoint position;
FReal physicalValue;
loader.fillParticle(&position,&physicalValue);
// put in tree
tree.insert(particles[idxPart].position, idxPart, particles[idxPart].physicalValue);
}
......@@ -185,8 +182,6 @@ int main(int argc, char* argv[])
});
}
delete[] particles;
// Print for information
std::cout << "Potential " << potentialDiff << std::endl;
std::cout << "Fx " << potentialDiff << std::endl;
......@@ -200,7 +195,7 @@ int main(int argc, char* argv[])
{ // begin FFmaBlas kernel
// accuracy
const int DevP = FParameters::getValue(argc, argv, "-p", 5);
const int DevP = FParameters::getValue(argc, argv, "-p", 6);
// typedefs
typedef FSphericalCell CellClass;
......@@ -228,9 +223,6 @@ int main(int argc, char* argv[])
time.tic();
for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
FPoint position;
FReal physicalValue;
loader.fillParticle(&position,&physicalValue);
// put in tree
tree.insert(particles[idxPart].position, idxPart, particles[idxPart].physicalValue);
}
......@@ -272,8 +264,6 @@ int main(int argc, char* argv[])
});
}
delete[] particles;
// Print for information
std::cout << "Potential " << potentialDiff << std::endl;
std::cout << "Fx " << potentialDiff << std::endl;
......
......@@ -70,8 +70,8 @@ int main(int argc, char* argv[])
std::cout << ">> Testing the Chebyshev interpolation base FMM algorithm.\n";
// open particle file
//FFmaScanfLoader<ParticleClass> loader(filename);
FFmaBinLoader loader(filename);
FFmaScanfLoader loader(filename);
//FFmaBinLoader loader(filename);
if(!loader.isOpen()) throw std::runtime_error("Particle file couldn't be opened!");
// init oct-tree
......
......@@ -81,8 +81,8 @@ int main(int argc, char ** argv){
// -----------------------------------------------------
std::cout << "Opening : " << filename << "\n";
//FEwalLoader loader(filename);
FEwalBinLoader loader(filename);
FEwalLoader loader(filename);
//FEwalBinLoader loader(filename);
if(!loader.isOpen()){
std::cout << "Loader Error, " << filename << " is missing\n";
return 1;
......
......@@ -54,7 +54,7 @@ int main(int argc, char ** argv){
// -----------------------------------------------------
const char* const filename1 = FParameters::getStr(argc,argv,"-f1", "tree.data");
const char* const filename2 = FParameters::getStr(argc,argv,"-f1", "dtree.data");
const char* const filename2 = FParameters::getStr(argc,argv,"-f2", "dtree.data");
std::cout << "Compare tree " << filename1 << " and " << filename2 << std::endl;
FTreeIO::Load<OctreeClass, CellClass, LeafClass, ContainerClass >(filename1, tree1);
......@@ -111,50 +111,49 @@ int main(int argc, char ** argv){
for(int idxLevel = tree1.getHeight() - 1 ; idxLevel > 1 ; --idxLevel ){
int nbCells = 0;
if( idxLevel == 2 ){
do{
if( octreeIterator1.getCurrentGlobalIndex() != octreeIterator2.getCurrentGlobalIndex()){
std::cout << "Index is different\n";
break;
}
do{
if( octreeIterator1.getCurrentGlobalIndex() != octreeIterator2.getCurrentGlobalIndex()){
std::cout << "Index is different\n";
break;
}
const CellClass*const cell1 = octreeIterator1.getCurrentCell();
const CellClass*const cell2 = octreeIterator2.getCurrentCell();
const CellClass*const cell1 = octreeIterator1.getCurrentCell();
const CellClass*const cell2 = octreeIterator2.getCurrentCell();
FReal cumul = 0;
for(int idx = 0; idx < FSphericalCell::GetPoleSize(); ++idx){
cumul += FMath::Abs( cell1->getMultipole()[idx].getImag() - cell2->getMultipole()[idx].getImag() );
cumul += FMath::Abs( cell1->getMultipole()[idx].getReal() - cell2->getMultipole()[idx].getReal() );
}
if( cumul > 0.00001 || FMath::IsNan(cumul)){
std::cout << "Pole Data are different. Cumul " << cumul << " at level " << idxLevel
<< " index is " << octreeIterator1.getCurrentGlobalIndex() << std::endl;
}
cumul = 0;
for(int idx = 0; idx < FSphericalCell::GetLocalSize(); ++idx){
cumul += FMath::Abs( cell1->getLocal()[idx].getImag() - cell2->getLocal()[idx].getImag() );
cumul += FMath::Abs( cell1->getLocal()[idx].getReal() - cell2->getLocal()[idx].getReal() );
}
if( cumul > 0.00001 || FMath::IsNan(cumul)){
std::cout << "Local Data are different. Cumul " << cumul << " at level " << idxLevel
<< " index is " << octreeIterator1.getCurrentGlobalIndex() << std::endl;
}
FReal cumul = 0;
for(int idx = 0; idx < FSphericalCell::GetPoleSize(); ++idx){
cumul += FMath::Abs( cell1->getMultipole()[idx].getImag() - cell2->getMultipole()[idx].getImag() );
cumul += FMath::Abs( cell1->getMultipole()[idx].getReal() - cell2->getMultipole()[idx].getReal() );
}
if( cumul > 0.00001 || FMath::IsNan(cumul)){
std::cout << "Pole Data are different. Cumul " << cumul << " at level " << idxLevel
<< " index is " << octreeIterator1.getCurrentGlobalIndex() << std::endl;
}
cumul = 0;
for(int idx = 0; idx < FSphericalCell::GetLocalSize(); ++idx){
cumul += FMath::Abs( cell1->getLocal()[idx].getImag() - cell2->getLocal()[idx].getImag() );
cumul += FMath::Abs( cell1->getLocal()[idx].getReal() - cell2->getLocal()[idx].getReal() );
}
if( cumul > 0.00001 || FMath::IsNan(cumul)){
std::cout << "Local Data are different. Cumul " << cumul << " at level " << idxLevel
<< " index is " << octreeIterator1.getCurrentGlobalIndex() << std::endl;
}
nbCells += 1;
if( octreeIterator1.moveRight() ){
if( !octreeIterator2.moveRight() ){
std::cout << "Not the same number of leaf, tree2 end before tree1\n";
break;
}
}
else {
if( octreeIterator2.moveRight() ){
std::cout << "Not the same number of leaf, tree1 end before tree2\n";
}
nbCells += 1;
if( octreeIterator1.moveRight() ){
if( !octreeIterator2.moveRight() ){
std::cout << "Not the same number of leaf, tree2 end before tree1\n";
break;
}
} while(true);
}
}
else {
if( octreeIterator2.moveRight() ){
std::cout << "Not the same number of leaf, tree1 end before tree2\n";
}
break;
}
} while(true);
octreeIterator1.moveUp();
octreeIterator1.gotoLeft();
......
......@@ -25,6 +25,8 @@
#include "../../Src/Files/FRandomLoader.hpp"
#include "../../Src/Files/FPerLeafLoader.hpp"
#include "../../Src/Containers/FOctree.hpp"
#include "../../Src/Containers/FVector.hpp"
......@@ -59,7 +61,7 @@ int main(int argc, char ** argv){
std::cout << ">> This executable has to be used to test the FMM algorithm.\n";
//////////////////////////////////////////////////////////////
const int NbLevels = FParameters::getValue(argc,argv,"-h", 7);
const int NbLevels = FParameters::getValue(argc,argv,"-h", 5);
const int SizeSubLevels = FParameters::getValue(argc,argv,"-sh", 3);
const long NbParticles = FParameters::getValue(argc,argv,"-nb", 1000);
const int PeriodicDeep = FParameters::getValue(argc,argv,"-per", 2);
......@@ -77,11 +79,13 @@ int main(int argc, char ** argv){
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
std::cout << "Creating & Inserting " << NbParticles << " particles ..." << std::endl;
FRandomLoader loader(NbParticles);
//FPerLeafLoader loader(NbLevels);
std::cout << "Creating & Inserting " << loader.getNumberOfParticles() << " particles ..." << std::endl;
std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SizeSubLevels << std::endl;
counter.tic();
FRandomLoader loader(NbParticles);
OctreeClass tree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
{
......@@ -124,8 +128,9 @@ int main(int argc, char ** argv){
counterNbPart += leaf->getSrc()->getNbParticles();
});
if( counterNbPart != NbParticles){
std::cout << "Problem global nb part, counter = " << counterNbPart << " created = " << NbParticles << std::endl;
if( counterNbPart != loader.getNumberOfParticles()){
std::cout << "Problem global nb part, counter = " << counterNbPart << " created = " <<
loader.getNumberOfParticles() << std::endl;
}
}
{
......@@ -133,8 +138,9 @@ int main(int argc, char ** argv){
const int totalRepeatedBox = repetitions.getX() * repetitions.getY() * repetitions.getZ();
std::cout << "The box is repeated " << repetitions.getX() <<" "<< repetitions.getY()<<" "<<
repetitions.getZ() << " there are " << totalRepeatedBox << " boxes in total\n";
const long long NbParticlesEntireSystem = NbParticles * totalRepeatedBox;
const long long NbParticlesEntireSystem = loader.getNumberOfParticles() * totalRepeatedBox;
std::cout << "The total number of particles is " << NbParticlesEntireSystem << "\n";
FTreeCoordinate min, max;
algo.repetitionsIntervals(&min, &max);
std::cout << "Min is " << min << " Max is " << max << std::endl;
......@@ -149,6 +155,8 @@ int main(int argc, char ** argv){
});
}
std::cout << "Test done..." << std::endl;
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
......
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