Commit 9cb8d8ae authored by berenger-bramas's avatar berenger-bramas

Add a loader that uses scanf (not std::cin)

to get values like FMB.

Also change FMA to Fma to be consistent.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@59 2616d619-271b-44dc-8df4-d4a8f33a7222
parent c31bc7e9
#ifndef FFMAPARTICLE_HPP
#define FFMAPARTICLE_HPP
#ifndef FFmaPARTICLE_HPP
#define FFmaPARTICLE_HPP
// /!\ Please, you must read the license at the bottom of this page
#include "FBasicParticle.hpp"
......@@ -21,6 +21,6 @@ public:
};
#endif //FFMAPARTICLE_HPP
#endif //FFmaPARTICLE_HPP
// [--LICENSE--]
......@@ -16,7 +16,7 @@ class F3DPosition;
* If you want to use a specific file format you then need to inherite from this loader
* and implemente several methods.
*
* Please look at FBasicLoader or FFMALoader to see an example.
* Please look at FBasicLoader or FFmaLoader to see an example.
*
* @warning Inherite from this class when defining a loader class
*/
......
......@@ -11,7 +11,7 @@
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
* @class FFMALoader
* @class FFmaLoader
* Please read the license
*
* Load a file with a format like :
......@@ -19,7 +19,7 @@
* X Y Z // one particle by line
* ....
* <code>
* FFMALoader<FBasicParticle> loader("../FMB++/Tests/particles.basic.txt"); <br>
* FFmaLoader<FBasicParticle> loader("../FMB++/Tests/particles.basic.txt"); <br>
* if(!loader.isValide()){ <br>
* std::cout << "Loader Error\n"; <br>
* return 1; <br>
......@@ -37,7 +37,7 @@
* Particle has to extend {FExtendPhysicalValue,FExtendPosition}
*/
template <class ParticleClass>
class FFMALoader : public FAbstractLoader<ParticleClass> {
class FFmaLoader : public FAbstractLoader<ParticleClass> {
protected:
std::ifstream file; //< The file to read
F3DPosition centerOfBox; //< The center of box read from file
......@@ -50,7 +50,7 @@ public:
* @param filename the name of the file to open
* you can test if file is successfuly open by calling isValide()
*/
FFMALoader(const char* const filename): file(filename,std::ifstream::in){
FFmaLoader(const char* const filename): file(filename,std::ifstream::in){
// test if open
if(this->file.is_open()){
FReal x,y,z;
......@@ -67,7 +67,7 @@ public:
/**
* Default destructor, simply close the file
*/
virtual ~FFMALoader(){
virtual ~FFmaLoader(){
file.close();
}
......@@ -118,6 +118,6 @@ public:
};
#endif //FFMALoader_HPP
#endif //FFmaLoader_HPP
// [--LICENSE--]
#ifndef FFMASCANFLOADER_HPP
#define FFMASCANFLOADER_HPP
// /!\ Please, you must read the license at the bottom of this page
#include <iostream>
#include <fstream>
#include "../Utils/FGlobal.hpp"
#include "FAbstractLoader.hpp"
#include "../Utils/F3DPosition.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
* @class FFmaScanfLoader
* Please read the license
*
* Load a file with a format like :
* NB_particles Box_width Box_X Box_Y Box_Z // init
* X Y Z // one particle by line
* ....
* <code>
* FFmaScanfLoader<FBasicParticle> loader("../FMB++/Tests/particles.basic.txt"); <br>
* if(!loader.isValide()){ <br>
* std::cout << "Loader Error\n"; <br>
* return 1; <br>
* } <br>
* <br>
* FOctree<FBasicParticle, TestCell, FSimpleLeaf, 10, 3> tree(loader.getBoxWidth(),loader.getCenterOfBox()); <br>
* <br>
* for(int idx = 0 ; idx < loader.getNumberOfParticles() ; ++idx){ <br>
* FBasicParticle* const part = new FBasicParticle(); <br>
* loader.fillParticle(part); <br>
* tree.insert(part); <br>
* } <br>
* </code>
*
* Particle has to extend {FExtendPhysicalValue,FExtendPosition}
*/
template <class ParticleClass>
class FFmaScanfLoader : public FAbstractLoader<ParticleClass> {
protected:
FILE* 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 isValide()
*/
FFmaScanfLoader(const char* const filename): file(0){
file = fopen(filename,"r");
// test if open
if(this->file){
float x,y,z, fBoxWidth;
const int nbReadElements = fscanf(file,"%d %f %f %f %f",&this->nbParticles,&fBoxWidth,&x,&y,&z);
if(nbReadElements == 5){
this->boxWidth = fBoxWidth;
this->centerOfBox.setPosition(x,y,z);
this->boxWidth *= 2;
}
else{
fclose(file);
file = NULL;
}
}
else {
this->boxWidth = 0;
this->nbParticles = 0;
}
}
/**
* Default destructor, simply close the file
*/
virtual ~FFmaScanfLoader(){
fclose(file);
}
/**
* To know if file is open and ready to read
* @return true if loader can work
*/
bool isValide() const{
return this->file != NULL;
}
/**
* To get the number of particles from this loader
* @param the number of particles the loader can fill
*/
long getNumberOfParticles() const{
return 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
*/
void fillParticle(ParticleClass* const inParticle){
float x,y,z,data;
const int nbReadElements = fscanf(file,"%f %f %f %f",&x,&y,&z,&data);
if(nbReadElements == 4){
inParticle->setPosition(x,y,z);
inParticle->setPhysicalValue(data);
}
else{
fclose(file);
file = NULL;
}
}
};
#endif //FFMASCANFLOADER_HPP
// [--LICENSE--]
......@@ -11,7 +11,7 @@
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
* @class FFMATsmLoader
* @class FFmaTsmLoader
* Please read the license
*
* Load a file with a format like :
......@@ -19,7 +19,7 @@
* X Y Z // one particle by line
* ....
* <code>
* FFMATsmLoader<FBasicParticle> loader("../FMB++/Tests/particles.basic.txt"); <br>
* FFmaTsmLoader<FBasicParticle> loader("../FMB++/Tests/particles.basic.txt"); <br>
* if(!loader.isValide()){ <br>
* std::cout << "Loader Error\n"; <br>
* return 1; <br>
......@@ -37,7 +37,7 @@
* Particle has to extend {FExtendPhysicalValue,FExtendPosition}
*/
template <class ParticleClass>
class FFMATsmLoader : public FAbstractLoader<ParticleClass> {
class FFmaTsmLoader : public FAbstractLoader<ParticleClass> {
protected:
std::ifstream file; //< The file to read
F3DPosition centerOfBox; //< The center of box read from file
......@@ -50,7 +50,7 @@ public:
* @param filename the name of the file to open
* you can test if file is successfuly open by calling isValide()
*/
FFMATsmLoader(const char* const filename): file(filename,std::ifstream::in){
FFmaTsmLoader(const char* const filename): file(filename,std::ifstream::in){
// test if open
if(this->file.is_open()){
FReal x,y,z;
......@@ -67,7 +67,7 @@ public:
/**
* Default destructor, simply close the file
*/
virtual ~FFMATsmLoader(){
virtual ~FFmaTsmLoader(){
file.close();
}
......
......@@ -347,6 +347,12 @@ protected:
// Compute P_l^m, l >= m+2, using (1) and store it into results_array:
outResults[idxCurrent] = (inCosTheta * ( 2 * idxl - 1 ) * outResults[idxCurrent1m] - ( idxl + idxm - 1 )
* outResults[idxCurrent2m] ) / ( idxl - idxm );
printf("\tres (%.18e) = inCosTheta (%.18e) idxl (%d) outResults 1m (%.18e) idxm (%d) outResults 2m (%.18e)\n",
outResults[idxCurrent],inCosTheta,idxl,outResults[idxCurrent1m],idxm,outResults[idxCurrent2m]);
printf("\t\t temp1 = %.18e temp2 = %.18e temp3 = %.18e\n",
inCosTheta * ( 2 * idxl - 1 ) * outResults[idxCurrent1m],
( idxl + idxm - 1 ) * outResults[idxCurrent2m],
(inCosTheta * ( 2 * idxl - 1 ) * outResults[idxCurrent1m] - ( idxl + idxm - 1 ) * outResults[idxCurrent2m] ));
}
// p_results_array_l_minus_1_m now points on P_{l-1}^{l-1}
......@@ -392,7 +398,7 @@ protected:
legendreFunction(FMB_Info_P,inSphere.cosTheta, inSphere.sinTheta, legendre);
/*printf("FMB_Info_M2L_exp_size=%d\n",FMB_Info_M2L_exp_size);
for(int temp = 0 ; temp < FMB_Info_M2L_exp_size ; ++temp){
printf("%e\n",this->legendre[temp]);
printf("%e\n",legendre[temp]);
}*/
FComplexe* currentResult = outResults;
......@@ -407,8 +413,11 @@ protected:
currentResult->setReal( magnitude * cosSin[idxm].getReal() );
currentResult->setImag( magnitude * cosSin[idxm].getImag() );
//printf("\t\tl = %d m = %d\n",idxl,idxm);
//printf("\t\tmagnitude=%e idxRl=%e sphereHarmoInnerCoef=%e real=%e imag=%e\n",magnitude,idxRl,this->sphereHarmoInnerCoef[idxSphereHarmoCoef],currentResult->getReal(),currentResult->getImag());
/*printf("\t\tl = %d m = %d\n",idxl,idxm);
printf("\t\tmagnitude (%e) = idxRl (%e) * sphereHarmoInnerCoef (%e) * legendre (%e)\n",
magnitude,idxRl,this->sphereHarmoInnerCoef[idxSphereHarmoCoef],legendre[idxLegendre]);
printf("\t\tresult real=%e imag=%e\n",
currentResult->getReal(),currentResult->getImag());*/
}
}
......@@ -620,6 +629,15 @@ protected:
harmonicInner(positionTsmphere(M2MVector),this->transitionM2M[idxLevel][idxChild]);
printf("[M2M_vector]%d/%d = %e/%e/%e\n", idxLevel , idxChild , M2MVector.getX() , M2MVector.getY() , M2MVector.getZ() );
Spherical sphericalM2M = positionTsmphere(M2MVector);
printf("[M2M_vectorSpherical]%d/%d = %e/%e/%e/%e\n",
idxLevel , idxChild , sphericalM2M.r , sphericalM2M.cosTheta , sphericalM2M.sinTheta , sphericalM2M.phi );
for(int idxExpSize = 0 ; idxExpSize < FMB_Info_exp_size ; ++idxExpSize){
printf("transitionM2M[%d][%d][%d]=%e/%e\n", idxLevel , idxChild , idxExpSize , this->transitionM2M[idxLevel][idxChild][idxExpSize].getReal(),this->transitionM2M[idxLevel][idxChild][idxExpSize].getImag());
}
exit(0);//todo remove
const F3DPosition L2LVector (
(treeWidthAtLevel * (1 + (childBox.getX() * 2))) - father.getX(),
(treeWidthAtLevel * (1 + (childBox.getY() * 2))) - father.getY(),
......@@ -628,13 +646,6 @@ protected:
harmonicInner(positionTsmphere(L2LVector),this->transitionL2L[idxLevel][idxChild]);
//printf("[M2M_vector]%d/%d = %e/%e/%e\n", idxLevel , idxChild , M2MVector.getX() , M2MVector.getY() , M2MVector.getZ() );
//Spherical = positionTsmphere(M2MVector);
//printf("[M2M_vectorSpherical]%d/%d = %e/%e/%e/%e\n",
// idxLevel , idxChild , sphericalM2M.r , sphericalM2M.cosTheta , sphericalM2M.sinTheta , sphericalM2M.phi );
//for(int idxExpSize = 0 ; idxExpSize < FMB_Info_exp_size ; ++idxExpSize){
// printf("transitionM2M[%d][%d][%d]=%e/%e\n", idxLevel , idxChild , idxExpSize , this->transitionM2M[idxLevel][idxChild][idxExpSize].getReal(),this->transitionM2M[idxLevel][idxChild][idxExpSize].getImag());
//}
}
}
}
......
......@@ -26,7 +26,7 @@
#include "../Sources/Fmb/FFmbKernels.hpp"
#include "../Sources/Files/FFMALoader.hpp"
#include "../Sources/Files/FFmaLoader.hpp"
// With openmp : g++ testFmbAlgorithm.cpp ../Sources/Utils/FAssertable.cpp ../Sources/Utils/FDebug.cpp ../Sources/Utils/FTrace.cpp -lgomp -fopenmp -O2 -o testFmbAlgorithm.exe
// icpc -openmp -openmp-lib=compat testFmbAlgorithm.cpp ../Sources/Utils/FAssertable.cpp ../Sources/Utils/FDebug.cpp -O2 -o testFmbAlgorithm.exe
......@@ -75,7 +75,7 @@ int main(int argc, char ** argv){
std::cout << "Opening : " << filename << "\n";
}
FFMALoader<FmbParticle> loader(filename);
FFmaLoader<FmbParticle> loader(filename);
if(!loader.isValide()){
std::cout << "Loader Error, " << filename << " is missing\n";
return 1;
......
......@@ -26,7 +26,7 @@
#include "../Sources/Fmb/FFmbKernelsBlas.hpp"
#include "../Sources/Fmb/FFmbKernels.hpp"
#include "../Sources/Files/FFMALoader.hpp"
#include "../Sources/Files/FFmaScanfLoader.hpp"
// With openmp : g++ testFmbBlasAlgorithm.cpp ../Sources/Utils/FAssertable.cpp ../Sources/Utils/FDebug.cpp ../Sources/Utils/FTrace.cpp -lgomp -fopenmp -lcblas -O2 -o testFmbBlasAlgorithm.exe
// icpc -openmp -openmp-lib=compat testFmbAlgorithm.cpp ../Sources/Utils/FAssertable.cpp ../Sources/Utils/FDebug.cpp -O2 -o testFmbAlgorithm.exe
......@@ -78,7 +78,7 @@ int main(int argc, char ** argv){
std::cout << "Opening : " << filename << "\n";
}
FFMALoader<FmbParticle> loader(filename);
FFmaScanfLoader<FmbParticle> loader(filename);
if(!loader.isValide()){
std::cout << "Loader Error, " << filename << " is missing\n";
return 1;
......
......@@ -27,7 +27,7 @@
#include "../Sources/Fmb/FFmbKernels.hpp"
#include "../Sources/Files/FFMATsmLoader.hpp"
#include "../Sources/Files/FFmaTsmLoader.hpp"
// With openmp : g++ testFmbTsmAlgorithm.cpp ../Sources/Utils/FAssertable.cpp ../Sources/Utils/FDebug.cpp ../Sources/Utils/FTrace.cpp -lgomp -fopenmp -O2 -o testFmbTsmAlgorithm.exe
// icpc -openmp -openmp-lib=compat testFmbTsmAlgorithm.cpp ../Sources/Utils/FAssertable.cpp ../Sources/Utils/FDebug.cpp -O2 -o testFmbTsmAlgorithm.exe
......@@ -76,7 +76,7 @@ int main(int argc, char ** argv){
std::cout << "Opening : " << filename << "\n";
}
FFMATsmLoader<FmbParticle> loader(filename);
FFmaTsmLoader<FmbParticle> loader(filename);
if(!loader.isValide()){
std::cout << "Loader Error, " << filename << " is missing\n";
return 1;
......
......@@ -19,7 +19,7 @@
#include "../Sources/Components/FSimpleLeaf.hpp"
#include "../Sources/Files/FFMALoader.hpp"
#include "../Sources/Files/FFmaLoader.hpp"
// Compile by : g++ testLoaderFMA.cpp ../Sources/Utils/FAssertable.cpp -O2 -o testLoaderFMA.exe
......@@ -58,7 +58,7 @@ int main(int argc, char ** argv ){
}
// open basic particles loader
FFMALoader<FFmaParticle> loader(filename);
FFmaLoader<FFmaParticle> loader(filename);
if(!loader.isValide()){
std::cout << "Loader Error, " << filename << "is missing\n";
return 1;
......
......@@ -21,7 +21,7 @@
#include "../Sources/Components/FSimpleLeaf.hpp"
#include "../Sources/Files/FFMATsmLoader.hpp"
#include "../Sources/Files/FFmaTsmLoader.hpp"
// Compile by : g++ testLoaderFMATsm.cpp ../Sources/Utils/FAssertable.cpp -O2 -o testLoaderFMATsm.exe
......@@ -58,7 +58,7 @@ int main(int argc, char ** argv ){
}
// open basic particles loader
FFMATsmLoader<ParticleTsm> loader(filename);
FFmaTsmLoader<ParticleTsm> loader(filename);
if(!loader.isValide()){
std::cout << "Loader Error, " << filename << "is missing\n";
return 1;
......
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