From 8c9af7f20130ccb69df550e237242ee93b3f77e8 Mon Sep 17 00:00:00 2001 From: bramas <berenger.bramas@inria.fr> Date: Fri, 7 Jun 2013 14:31:24 +0200 Subject: [PATCH] update code and remove error --- Src/Containers/FOctree.hpp | 19 +++++ Src/Core/FFmmAlgorithmPeriodic.hpp | 3 +- Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp | 2 +- Src/Files/FEwalLoader.hpp | 25 ++++--- Tests/Kernels/testCompareKernels.cpp | 12 +-- Tests/Kernels/testFlopsChebAlgorithm.cpp | 4 +- Tests/Kernels/testSphericalEwalAlgorithm.cpp | 4 +- Tests/Utils/testCompareIOTree.cpp | 79 ++++++++++---------- Tests/Utils/testFmmAlgorithmPeriodic.cpp | 20 +++-- 9 files changed, 93 insertions(+), 75 deletions(-) diff --git a/Src/Containers/FOctree.hpp b/Src/Containers/FOctree.hpp index 21b6b8648..c0d01e2ae 100755 --- a/Src/Containers/FOctree.hpp +++ b/Src/Containers/FOctree.hpp @@ -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 diff --git a/Src/Core/FFmmAlgorithmPeriodic.hpp b/Src/Core/FFmmAlgorithmPeriodic.hpp index 0caded4a1..fe858a673 100755 --- a/Src/Core/FFmmAlgorithmPeriodic.hpp +++ b/Src/Core/FFmmAlgorithmPeriodic.hpp @@ -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]; diff --git a/Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp b/Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp index c8031f69b..7328d192c 100755 --- a/Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp +++ b/Src/Core/FFmmAlgorithmThreadProcPeriodic.hpp @@ -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; } diff --git a/Src/Files/FEwalLoader.hpp b/Src/Files/FEwalLoader.hpp index a67620815..5e8125dac 100755 --- a/Src/Files/FEwalLoader.hpp +++ b/Src/Files/FEwalLoader.hpp @@ -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; } } diff --git a/Tests/Kernels/testCompareKernels.cpp b/Tests/Kernels/testCompareKernels.cpp index 72c0c554a..903491373 100755 --- a/Tests/Kernels/testCompareKernels.cpp +++ b/Tests/Kernels/testCompareKernels.cpp @@ -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; diff --git a/Tests/Kernels/testFlopsChebAlgorithm.cpp b/Tests/Kernels/testFlopsChebAlgorithm.cpp index 420c9d144..1448eb446 100755 --- a/Tests/Kernels/testFlopsChebAlgorithm.cpp +++ b/Tests/Kernels/testFlopsChebAlgorithm.cpp @@ -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 diff --git a/Tests/Kernels/testSphericalEwalAlgorithm.cpp b/Tests/Kernels/testSphericalEwalAlgorithm.cpp index 8e13fcc42..ab49cec8d 100755 --- a/Tests/Kernels/testSphericalEwalAlgorithm.cpp +++ b/Tests/Kernels/testSphericalEwalAlgorithm.cpp @@ -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; diff --git a/Tests/Utils/testCompareIOTree.cpp b/Tests/Utils/testCompareIOTree.cpp index 06b385c7f..101d74e89 100755 --- a/Tests/Utils/testCompareIOTree.cpp +++ b/Tests/Utils/testCompareIOTree.cpp @@ -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(); diff --git a/Tests/Utils/testFmmAlgorithmPeriodic.cpp b/Tests/Utils/testFmmAlgorithmPeriodic.cpp index 4fad5a32f..a1f2160c0 100755 --- a/Tests/Utils/testFmmAlgorithmPeriodic.cpp +++ b/Tests/Utils/testFmmAlgorithmPeriodic.cpp @@ -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; + ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// -- GitLab