Commit 269d82bb authored by berenger-bramas's avatar berenger-bramas

Add a test based on a REVCON/EWAL example,

a loader can now load the data.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@286 2616d619-271b-44dc-8df4-d4a8f33a7222
parent 0228393d
This diff is collapsed.
#ifndef FFMALOADER_HPP
#define FFMALOADER_HPP
// [--License--]
#include <iostream>
#include <fstream>
#include <limits>
#include "../Utils/FGlobal.hpp"
#include "FAbstractLoader.hpp"
#include "../Utils/F3DPosition.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
* @class FEwalLoader
* Please read the license
* Particle has to extend {FExtendPhysicalValue,FExtendPosition}
*/
template <class ParticleClass>
class FEwalLoader : public FAbstractLoader<ParticleClass> {
protected:
std::ifstream file; //< The file to read
F3DPosition centerOfBox; //< The center of box read from file
FReal boxWidth; //< the box width read from file
int nbParticles; //< the number of particles read from file
public:
/**
* The constructor need the file name
* @param filename the name of the file to open
* you can test if file is successfuly open by calling hasNotFinished()
Box SPC water from DLPOLY TEST17
2 1 417 -591626.141968
17.200000000000 0.000000000000 0.000000000000
0.000000000000 17.200000000000 0.000000000000
0.000000000000 0.000000000000 17.200000000000
*/
FEwalLoader(const char* const filename): file(filename,std::ifstream::in){
// test if open
if(this->file.is_open()){
const int bufferSize = 512;
char buffer[bufferSize];
file.getline(buffer, bufferSize);
int tempi(0);
FReal tempf(0);
file >> tempi >> tempi >> this->nbParticles >> tempf;
FReal x,y,z;
file >> x >> tempf >> tempf;
file >> tempf >> y >> tempf;
file >> tempf >> tempf >> z;
this->centerOfBox.setPosition(x,y,z);
this->boxWidth *= 2;
}
else {
this->boxWidth = 0;
this->nbParticles = 0;
}
}
/**
* Default destructor, simply close the file
*/
virtual ~FEwalLoader(){
file.close();
}
/**
* To know if file is open and ready to read
* @return true if loader can work
*/
bool isOpen() const{
return this->file.is_open() && !this->file.eof();
}
/**
* To get the number of particles from this loader
* @param the number of particles the loader can fill
*/
FSize getNumberOfParticles() const{
return FSize(this->nbParticles);
}
/**
* The center of the box from the simulation file opened by the loader
* @return box center
*/
F3DPosition getCenterOfBox() const{
return this->centerOfBox;
}
/**
* The box width from the simulation file opened by the loader
* @return box width
*/
FReal getBoxWidth() const{
return this->boxWidth;
}
/**
* Fill a particle
* @warning to work with the loader, particles has to expose a setPosition method
* @param the particle to fill
OW 1
5.447823189 -0.4124521286 -3.845403447
7.64746800518 -1.34490700206 -2.81036521708
-4406.48579000 6815.52906417 10340.2577024
*/
void fillParticle(ParticleClass& inParticle){
FReal x, y, z, fx, fy, fz, vx, vy, vz;
int index;
char type[2];
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
file.read(type, 2);
file >> index;
file >> x >> y >> z;
file >> vx >> vy >> vz;
file >> fx >> fy >> fz;
inParticle.setPosition(x,y,z);
inParticle.setForces(fx,fy,fz);
inParticle.setIndex(index);
if( strncmp(type, "OW", 2) == 0){
inParticle.setPhysicalValue(FReal(-0.82));
inParticle.setType(ParticleClass::OW);
}
else{
inParticle.setPhysicalValue(FReal(0.41));
inParticle.setType(ParticleClass::HW);
}
}
};
#endif //FEwalLoader_HPP
// [--END--]
// [--License--]
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include "../Src/Utils/FTic.hpp"
#include "../Src/Utils/FParameters.hpp"
#include "../Src/Containers/FOctree.hpp"
#include "../Src/Containers/FVector.hpp"
#include "../Src/Core/FFmmAlgorithmPeriodic.hpp"
#include "../Src/Components/FBasicKernels.hpp"
#include "../Src/Fmb/FFmbKernels.hpp"
#include "../Src/Fmb/FFmbComponents.hpp"
#include "../Src/Files/FEwalLoader.hpp"
class EwalParticle : public FmbParticle {
public:
enum Type{
OW,
HW,
Undefined,
};
private:
Type type;
int index;
public:
EwalParticle() : type(Undefined), index(-1) {
}
Type getType() const{
return type;
}
void setType(const Type inType) {
type = inType;
}
int getIndex() const{
return index;
}
void setIndex( const int inIndex ){
index = inIndex;
}
};
// Simply create particles and try the kernels
int main(int argc, char ** argv){
typedef EwalParticle ParticleClass;
typedef FmbCell CellClass;
typedef FVector<ParticleClass> ContainerClass;
typedef FSimpleLeaf<ParticleClass, ContainerClass > LeafClass;
typedef FOctree<ParticleClass, CellClass, ContainerClass , LeafClass > OctreeClass;
typedef FBasicKernels<ParticleClass, CellClass, ContainerClass > KernelClass;
typedef FFmmAlgorithmPeriodic<OctreeClass, ParticleClass, CellClass, ContainerClass, KernelClass, LeafClass > FmmClass;
///////////////////////What we do/////////////////////////////
std::cout << ">> This executable has to be used to test fmb algorithm.\n";
//////////////////////////////////////////////////////////////
const int NbLevels = FParameters::getValue(argc,argv,"-h", 3);
const int SizeSubLevels = FParameters::getValue(argc,argv,"-sh", 2);
FTic counter;
const char* const defaultFilename = "../Data/testEwal417.dt";
const char* filename;
if(argc == 1){
std::cout << "You have to give a .fma file in argument.\n";
std::cout << "The program will try a default file : " << defaultFilename << "\n";
filename = defaultFilename;
}
else{
filename = argv[1];
std::cout << "Opening : " << filename << "\n";
}
FEwalLoader<ParticleClass> loader(filename);
if(!loader.isOpen()){
std::cout << "Loader Error, " << filename << " is missing\n";
return 1;
}
// -----------------------------------------------------
OctreeClass tree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
// -----------------------------------------------------
std::cout << "Creating & Inserting " << loader.getNumberOfParticles() << " particles ..." << std::endl;
std::cout << "\tWidth : " << loader.getBoxWidth() << " \t center x : " << loader.getCenterOfBox().getX()
<< " y : " << loader.getCenterOfBox().getY() << " z : " << loader.getCenterOfBox().getZ()
<< std::endl;
std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SizeSubLevels << std::endl;
counter.tic();
ParticleClass * const particles = new ParticleClass[loader.getNumberOfParticles()];
for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
loader.fillParticle(particles[idxPart]);
tree.insert(particles[idxPart]);
}
counter.tac();
std::cout << "Done " << "(@Creating and Inserting Particles = " << counter.elapsed() << "s)." << std::endl;
// -----------------------------------------------------
std::cout << "Working on particles ..." << std::endl;
counter.tic();
//KernelClass kernels(NbLevels,loader.getBoxWidth());
KernelClass kernels;
FmmClass algo(&tree,&kernels);
algo.execute();
counter.tac();
std::cout << "Done " << "(@Algorithm = " << counter.elapsed() << "s)." << std::endl;
{
typename OctreeClass::Iterator octreeIterator(&tree);
octreeIterator.gotoBottomLeft();
do{
typename ContainerClass::ConstBasicIterator iter(*octreeIterator.getCurrentListTargets());
while( iter.hasNotFinished() ){
///potential += iter.data().getPotential() * iter.data().getPhysicalValue();
///forces += iter.data().getForces();
std::cout << "index " << iter.data().getIndex() << " type " << iter.data().getType() << std::endl;
std::cout << "x " << iter.data().getPosition().getX() << " y " << iter.data().getPosition().getY() << " z " << iter.data().getPosition().getZ() << std::endl;
std::cout << "fx " << iter.data().getForces().getX() << " fy " << iter.data().getForces().getY() << " fz " << iter.data().getForces().getZ() << std::endl;
std::cout << "potential " << iter.data().getPhysicalValue() << std::endl;
iter.gotoNext();
}
} while(octreeIterator.moveRight());
}
// -----------------------------------------------------
delete[] particles;
return 0;
}
// [--END--]
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