Commit 093bde30 authored by berenger-bramas's avatar berenger-bramas

Improve and comment the utest.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@319 2616d619-271b-44dc-8df4-d4a8f33a7222
parent 1be7b9ff
No preview for this file type
...@@ -205,7 +205,7 @@ public: ...@@ -205,7 +205,7 @@ public:
for( int indexLevel = this->subOctreeHeight - 1 ; indexLevel >= 0 ; --indexLevel ){ for( int indexLevel = this->subOctreeHeight - 1 ; indexLevel >= 0 ; --indexLevel ){
for( int indexCells = mostLeft ; indexCells <= mostRight ; ++indexCells ){ for( int indexCells = mostLeft ; indexCells <= mostRight ; ++indexCells ){
if(this->cells[indexLevel][indexCells]){ if(this->cells[indexLevel][indexCells]){
//delete this->cells[indexLevel][indexCells]; delete this->cells[indexLevel][indexCells];
} }
} }
......
...@@ -82,7 +82,7 @@ public: ...@@ -82,7 +82,7 @@ public:
* Default destructor, simply close the file * Default destructor, simply close the file
*/ */
virtual ~FFmaBinLoader(){ virtual ~FFmaBinLoader(){
fclose(file); if(file) fclose(file);
} }
/** /**
......
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
* Default destructor, simply close the file * Default destructor, simply close the file
*/ */
virtual ~FHLoader(){ virtual ~FHLoader(){
fclose(file); if(file) fclose(file);
} }
/** /**
......
...@@ -195,7 +195,7 @@ public: ...@@ -195,7 +195,7 @@ public:
int maxParticlesInLeaf = 0; int maxParticlesInLeaf = 0;
file.read((char*)&maxParticlesInLeaf, sizeof(int)); file.read((char*)&maxParticlesInLeaf, sizeof(int));
ParticleClass* const particles = new ParticleClass[maxParticlesInLeaf]; ParticleClass* const particles = reinterpret_cast<ParticleClass*>(new char[maxParticlesInLeaf * sizeof(ParticleClass)]);
for(int idxLeaf = 0 ; idxLeaf < nbLeaf ; ++idxLeaf){ for(int idxLeaf = 0 ; idxLeaf < nbLeaf ; ++idxLeaf){
int particlesInLeaf = 0; int particlesInLeaf = 0;
...@@ -206,7 +206,7 @@ public: ...@@ -206,7 +206,7 @@ public:
} }
} }
//delete[] particles; delete[] reinterpret_cast<char*>(particles);
} }
// Start from leal level - 1 // Start from leal level - 1
......
// [--License--] // [--License--]
#include "../Src/Containers/FOctree.hpp" #include "../Src/Containers/FOctree.hpp"
#include "../Src/Containers/FVector.hpp" #include "../Src/Containers/FVector.hpp"
...@@ -18,6 +16,11 @@ ...@@ -18,6 +16,11 @@
#include "FUTester.hpp" #include "FUTester.hpp"
/*
This test compare a previous FMM result with a simulation.
*/
typedef FmbParticle ParticleClass; typedef FmbParticle ParticleClass;
typedef FComputeCell CellClass; typedef FComputeCell CellClass;
typedef FVector<ParticleClass> ContainerClass; typedef FVector<ParticleClass> ContainerClass;
...@@ -38,12 +41,15 @@ class TestFmb : public FUTester<TestFmb> { ...@@ -38,12 +41,15 @@ class TestFmb : public FUTester<TestFmb> {
const int DevP = 12; const int DevP = 12;
FComputeCell::Init(DevP); FComputeCell::Init(DevP);
// Load the particles file
FFmaBinLoader<ParticleClass> loader("../Data/utestFmb.bin.fma"); FFmaBinLoader<ParticleClass> loader("../Data/utestFmb.bin.fma");
if(!loader.isOpen()){ if(!loader.isOpen()){
Print("Cannot open particles file."); Print("Cannot open particles file.");
assert(false);
return; return;
} }
// Create octree
OctreeClass testTree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox()); OctreeClass testTree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
{ {
ParticleClass particleToFill; ParticleClass particleToFill;
...@@ -53,18 +59,20 @@ class TestFmb : public FUTester<TestFmb> { ...@@ -53,18 +59,20 @@ class TestFmb : public FUTester<TestFmb> {
} }
} }
// Run simulation
KernelClass kernels(DevP,NbLevels,loader.getBoxWidth()); KernelClass kernels(DevP,NbLevels,loader.getBoxWidth());
FmmClass algo(&testTree,&kernels); FmmClass algo(&testTree,&kernels);
algo.execute(); algo.execute();
//FTreeIO::Save<OctreeClass, CellClass, ParticleClass, FTreeIO::Copier<CellClass, ParticleClass> >("../Data/utestFmb.data", testTree); // If needed save the result
FTreeIO::Save<OctreeClass, CellClass, ParticleClass, FTreeIO::Copier<CellClass, ParticleClass> >("../Data/utestFmb.data", testTree);
// Load previous result
OctreeClass goodTree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox()); OctreeClass goodTree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
FTreeIO::Load<OctreeClass, CellClass, ParticleClass, FTreeIO::Copier<CellClass, ParticleClass> >("../Data/utestFmb.data", goodTree); FTreeIO::Load<OctreeClass, CellClass, ParticleClass, FTreeIO::Copier<CellClass, ParticleClass> >("../Data/utestFmb.data", goodTree);
// Compare the two simulations
Print("Check the particles..."); Print("Check the particles...");
{ // Check that each particle has been summed with all other { // Check that each particle has been summed with all other
typename OctreeClass::Iterator testOctreeIterator(&testTree); typename OctreeClass::Iterator testOctreeIterator(&testTree);
typename OctreeClass::Iterator goodOctreeIterator(&goodTree); typename OctreeClass::Iterator goodOctreeIterator(&goodTree);
......
...@@ -52,9 +52,11 @@ class TestFmbDirect : public FUTester<TestFmbDirect> { ...@@ -52,9 +52,11 @@ class TestFmbDirect : public FUTester<TestFmbDirect> {
void TestDirect(){ void TestDirect(){
FFmaBinLoader<ParticleClass> loader("../Data/utestFmbDirect.bin.fma"); // Load particles
FFmaBinLoader<ParticleClass> loader("../../Data/utestFmbDirect.bin.fma");
if(!loader.isOpen()){ if(!loader.isOpen()){
Print("Cannot open particles file."); Print("Cannot open particles file.");
assert(false);
return; return;
} }
Print("Number of particles:"); Print("Number of particles:");
...@@ -64,9 +66,9 @@ class TestFmbDirect : public FUTester<TestFmbDirect> { ...@@ -64,9 +66,9 @@ class TestFmbDirect : public FUTester<TestFmbDirect> {
const int SizeSubLevels = 2; const int SizeSubLevels = 2;
const int DevP = 12; const int DevP = 12;
FComputeCell::Init(DevP); FComputeCell::Init(DevP);
OctreeClass tree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
// Create octree
OctreeClass tree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
ParticleClass* const particles = new ParticleClass[loader.getNumberOfParticles()]; ParticleClass* const particles = new ParticleClass[loader.getNumberOfParticles()];
for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){ for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
loader.fillParticle(particles[idxPart]); loader.fillParticle(particles[idxPart]);
...@@ -75,13 +77,14 @@ class TestFmbDirect : public FUTester<TestFmbDirect> { ...@@ -75,13 +77,14 @@ class TestFmbDirect : public FUTester<TestFmbDirect> {
} }
// Run FMM
Print("Fmm..."); Print("Fmm...");
//KernelClass kernels(NbLevels,loader.getBoxWidth()); //KernelClass kernels(NbLevels,loader.getBoxWidth());
KernelClass kernels(DevP,NbLevels,loader.getBoxWidth()); KernelClass kernels(DevP,NbLevels,loader.getBoxWidth());
FmmClass algo(&tree,&kernels); FmmClass algo(&tree,&kernels);
algo.execute(); algo.execute();
// Run direct computation
Print("Direct..."); Print("Direct...");
for(int idxTarget = 0 ; idxTarget < loader.getNumberOfParticles() ; ++idxTarget){ for(int idxTarget = 0 ; idxTarget < loader.getNumberOfParticles() ; ++idxTarget){
for(int idxOther = idxTarget + 1 ; idxOther < loader.getNumberOfParticles() ; ++idxOther){ for(int idxOther = idxTarget + 1 ; idxOther < loader.getNumberOfParticles() ; ++idxOther){
...@@ -90,10 +93,10 @@ class TestFmbDirect : public FUTester<TestFmbDirect> { ...@@ -90,10 +93,10 @@ class TestFmbDirect : public FUTester<TestFmbDirect> {
} }
} }
// Compare
Print("Compute Diff..."); Print("Compute Diff...");
FReal potentialDiff = 0; FReal potentialDiff = 0;
FReal fx = 0, fy = 0, fz = 0; FReal fx = 0, fy = 0, fz = 0;
{ // Check that each particle has been summed with all other { // Check that each particle has been summed with all other
typename OctreeClass::Iterator octreeIterator(&tree); typename OctreeClass::Iterator octreeIterator(&tree);
octreeIterator.gotoBottomLeft(); octreeIterator.gotoBottomLeft();
......
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