Commit 7188a985 authored by berenger-bramas's avatar berenger-bramas

The unit test are now working.

But be aware that utestFmb is using binary mem compare to check result.
Also, when running make test, the exec dir is not Build/ but Build/UTests.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@320 2616d619-271b-44dc-8df4-d4a8f33a7222
parent 093bde30
No preview for this file type
......@@ -17,6 +17,37 @@
*/
class FTreeIO{
public:
class FAbstractSerial {
protected:
template <class TypeClass>
void save(std::ofstream*const stream, const TypeClass& value) const{
stream->write((const char*)&value, sizeof(TypeClass));
}
template <class TypeClass>
TypeClass restore(std::ifstream*const stream) const{
TypeClass value;
stream->read((char*)&value, sizeof(TypeClass));
return value;
}
template <class TypeClass>
void saveArray(std::ofstream*const stream, const TypeClass*const values, const int size) const{
stream->write((const char*)values, sizeof(TypeClass) * size);
}
template <class TypeClass>
void restoreArray(std::ifstream*const stream, TypeClass*const values, const int size) const{
stream->read((char*)values, sizeof(TypeClass) * size);
}
public:
virtual void read(std::ifstream*const stream) = 0;
virtual void write(std::ofstream*const stream) const = 0;
};
/** The serializer class call a method on the particles or cells
* So they have to implement the write/read method
*/
......@@ -28,16 +59,17 @@ public:
}
static void PutParticles(std::ofstream*const stream, const ParticleClass* const particles, const int nbParticles) {
for( int idxParticle = 0 ; idxParticle < nbParticles ; ++idxParticle){
particles[idxParticle]->write(stream);
particles[idxParticle].write(stream);
}
}
static void GetCell(std::ifstream*const stream, CellClass* const cell){
cell->read(stream);
}
static void GetParticles(std::ifstream*const stream, const ParticleClass* const particles, const int nbParticles){
static void GetParticles(std::ifstream*const stream, ParticleClass* const particles, const int nbParticles){
for( int idxParticle = 0 ; idxParticle < nbParticles ; ++idxParticle){
particles[idxParticle]->read(stream);
particles[idxParticle].read(stream);
}
}
};
......@@ -57,7 +89,7 @@ public:
static void GetCell(std::ifstream*const stream, CellClass* const cell){
stream->read((char*)cell, sizeof(CellClass));
}
static void GetParticles(std::ifstream*const stream, const ParticleClass* const particles, const int nbParticles){
static void GetParticles(std::ifstream*const stream, ParticleClass* const particles, const int nbParticles){
stream->read((char*)particles, nbParticles * sizeof(ParticleClass));
}
};
......@@ -195,7 +227,7 @@ public:
int maxParticlesInLeaf = 0;
file.read((char*)&maxParticlesInLeaf, sizeof(int));
ParticleClass* const particles = reinterpret_cast<ParticleClass*>(new char[maxParticlesInLeaf * sizeof(ParticleClass)]);
ParticleClass* const particles = new ParticleClass[maxParticlesInLeaf];
for(int idxLeaf = 0 ; idxLeaf < nbLeaf ; ++idxLeaf){
int particlesInLeaf = 0;
......@@ -206,7 +238,7 @@ public:
}
}
delete[] reinterpret_cast<char*>(particles);
delete[] particles;
}
// Start from leal level - 1
......
......@@ -21,8 +21,50 @@
*/
typedef FmbParticle ParticleClass;
typedef FComputeCell CellClass;
class FmbParticleSerial : public FmbParticle, public FTreeIO::FAbstractSerial {
public:
void write(std::ofstream*const stream) const{
save(stream, getPosition().getX());
save(stream, getPosition().getY());
save(stream, getPosition().getZ());
save(stream, getForces().getX());
save(stream, getForces().getY());
save(stream, getForces().getZ());
save(stream, getPotential());
save(stream, getPhysicalValue());
}
void read(std::ifstream*const stream) {
const FReal posX = restore<FReal>(stream);
const FReal posY = restore<FReal>(stream);
const FReal posZ = restore<FReal>(stream);
setPosition(posX, posY, posZ);
const FReal forceX = restore<FReal>(stream);
const FReal forceY = restore<FReal>(stream);
const FReal forceZ = restore<FReal>(stream);
setForces(forceX, forceY, forceZ);
setPotential(restore<FReal>(stream));
setPhysicalValue(restore<FReal>(stream));
}
};
class ComputeCellSerial : public FComputeCell, public FTreeIO::FAbstractSerial {
public:
void write(std::ofstream*const stream) const{
saveArray(stream, FComputeCell::getMultipole(), FComputeCell::ExpP);
saveArray(stream, FComputeCell::getLocal(), FComputeCell::ExpP);
}
void read(std::ifstream*const stream){
restoreArray(stream, FComputeCell::getMultipole(), FComputeCell::ExpP);
restoreArray(stream, FComputeCell::getLocal(), FComputeCell::ExpP);
}
};
typedef FmbParticleSerial ParticleClass;
typedef ComputeCellSerial CellClass;
typedef FVector<ParticleClass> ContainerClass;
//typedef FFmbKernels<ParticleClass, CellClass, ContainerClass > KernelClass;
......@@ -36,13 +78,18 @@ typedef FFmmAlgorithm<OctreeClass, ParticleClass, CellClass, ContainerClass, Ker
class TestFmb : public FUTester<TestFmb> {
void TestTree(){
// Warning in make test the exec dir it Build/UTests
const char* const DataFile = "../../Data/utestFmb.data";
const char* const ParticleFile = "../../Data/utestFmb.bin.fma";
const int NbLevels = 5;
const int SizeSubLevels = 3;
const int DevP = 12;
FComputeCell::Init(DevP);
// Load the particles file
FFmaBinLoader<ParticleClass> loader("../Data/utestFmb.bin.fma");
FFmaBinLoader<ParticleClass> loader(ParticleFile);
if(!loader.isOpen()){
Print("Cannot open particles file.");
assert(false);
......@@ -65,11 +112,11 @@ class TestFmb : public FUTester<TestFmb> {
algo.execute();
// If needed save the result
FTreeIO::Save<OctreeClass, CellClass, ParticleClass, FTreeIO::Copier<CellClass, ParticleClass> >("../Data/utestFmb.data", testTree);
// FTreeIO::Save<OctreeClass, CellClass, ParticleClass, FTreeIO::Serializer<CellClass, ParticleClass> >(DataFile, testTree);
// Load previous result
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::Serializer<CellClass, ParticleClass> >(DataFile, goodTree);
// Compare the two simulations
Print("Check the particles...");
......
......@@ -52,6 +52,7 @@ class TestFmbDirect : public FUTester<TestFmbDirect> {
void TestDirect(){
// Warning in make test the exec dir it Build/UTests
// Load particles
FFmaBinLoader<ParticleClass> loader("../../Data/utestFmbDirect.bin.fma");
if(!loader.isOpen()){
......
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