Commit ff60ca7b authored by COULAUD Olivier's avatar COULAUD Olivier

Remove direct computation in utest

parent 0d2dee44
// ===================================================================================
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Berenger Bramas, Matthias Messner
// olivier.coulaud@inria.fr, berenger.bramas@inria.fr
// This software is a computer program whose purpose is to compute the FMM.
//
// This software is governed by the CeCILL-C and LGPL licenses and
// abiding by the rules of distribution of free software.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info".
// "http://www.gnu.org/licenses".
// ===================================================================================
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include "ScalFmmConfig.h"
#include "Utils/FTic.hpp"
//#include "Utils/FMath.hpp"
#include "Utils/FParameters.hpp"
//#include "Utils/FIOVtk.hpp"
//#include "Containers/FVector.hpp"
#include "Files/FFmaGenericLoader.hpp"
#include "Kernels/P2P/FP2P.hpp"
// Simply create particles and try the kernels
int main(int argc, char ** argv){
//
///////////////////////What we do/////////////////////////////
if( FParameters::existParameter(argc, argv, "-help" ) || argc < 4){
std::cout << ">> This executable has to be used to compute interaction either for periodic or non periodic system.\n";
std::cout << ">> Example -fin filenameIN.{fma or bfma) -fout filenameOUT{fma or bfma) \n";
std::cout << ">> Default input file : ../Data/unitCubeXYZQ20k.fma\n";
std::cout << " Options " << std::endl;
std::cout << " -verbose : print index x y z Q V fx fy fz " << std::endl;
std::cout << " -fin filename. Extension specifies if the file is binary or not. " << std::endl;
std::cout << " Only our FMA (.bma, .bfma) is allowed " << std::endl;
std::cout << " -fout filenameOUT output file with extension (default output.bfma)" << std::endl;
exit(-1);
}
//////////////////////////////////////////////////////////////
const std::string filenameIn(FParameters::getStr(argc,argv,"-fin", "../Data/unitCubeXYZQ20k.fma"));
const std::string filenameOut(FParameters::getStr(argc,argv,"-fout", "output.bfma"));
//
FTic counter;
// -----------------------------------------------------
// LOADER
// -----------------------------------------------------
// ---------------------------------------------------------------------------------
// Read particles in the Octree
// ---------------------------------------------------------------------------------
std::cout << "Opening : " << filenameIn << "\n";
//
FFmaGenericLoader loader(filenameIn);
//
int nbParticles = static_cast<int>(loader.getNumberOfParticles());
std::cout << "Read " << nbParticles << " particles ..." << std::endl;
double BoxWith=loader.getBoxWidth();
FPoint Centre(loader.getCenterOfBox().getX(), loader.getCenterOfBox().getY() , loader.getCenterOfBox().getZ());
std::cout << "\tWidth : " <<BoxWith << " \t center x : " << loader.getCenterOfBox().getX()
<< " y : " << loader.getCenterOfBox().getY() << " z : " << loader.getCenterOfBox().getZ() << std::endl;
counter.tic();
//
FmaRParticle * particles = new FmaRParticle[nbParticles];
memset(particles, 0, sizeof(FmaRParticle) * nbParticles) ;
//
double totalCharge = 0.0;
//
int nbDataToRead = particles[0].getReadDataNumber();
for(int idx = 0 ; idx<nbParticles ; ++idx){
//
loader.fillParticle(&particles[idx].position, &particles[idx].physicalValue);
// loader.fillParticle(particles[idx].getPtrFirstData(), nbDataToRead); // OK
// loader.fillParticle(particles[idx]); // OK
std::cout << idx <<" "<< particles[idx].position << " "<<particles[idx].physicalValue << " "<<particles[idx].potential
<<" " << particles[idx].forces[0]<<" " <<particles[idx].forces[1]<<" " <<particles[idx].forces[2]<<" " <<std::endl;
//
totalCharge += particles[idx].physicalValue ;
}
counter.tac();
std::cout << std::endl;
std::cout << "Total Charge = "<< totalCharge <<std::endl;
std::cout << std::endl;
std::cout << "Done " << "(@ reading Particles " << counter.elapsed() << " s)." << std::endl;
//
// ----------------------------------------------------------------------------------------------------------
// COMPUTATION
// ----------------------------------------------------------------------------------------------------------
FReal denergy = 0.0;
//
// computation
//
{
printf("Compute :\n");
counter.tic();
#pragma omp parallel shared(nbParticles, particles,denergy)
{
#pragma omp for
for(int idxTarget = 0 ; idxTarget < nbParticles ; ++idxTarget){
//
// compute with all other except itself
//
// Compute force and potential between particles[idxTarget] and particles inside the box
//
for(int idxOther = 0; idxOther < nbParticles ; ++idxOther){
if( idxOther != idxTarget ){
FP2P::NonMutualParticles(
particles[idxOther].position.getX(), particles[idxOther].position.getY(),
particles[idxOther].position.getZ(),particles[idxOther].physicalValue,
particles[idxTarget].position.getX(), particles[idxTarget].position.getY(),
particles[idxTarget].position.getZ(),particles[idxTarget].physicalValue,
&particles[idxTarget].forces[0],&particles[idxTarget].forces[1],
&particles[idxTarget].forces[2],&particles[idxTarget].potential);
}
}
} // end for
// Compute the energy
#pragma omp for reduction(+:denergy)
for(int idx = 0 ; idx < nbParticles ; ++idx){
denergy += particles[idx].potential*particles[idx].physicalValue ;
}
} // end pragma parallel
//
denergy *= 0.5 ;
counter.tac();
//
printf("Energy = %.14e\n",denergy);
//
std::cout << "Done " << "(@ Direct computation done = " << counter.elapsed() << " s)." << std::endl;
std::cout << "\n"<< "END "
<< "-------------------------------------------------------------------------"
<< std::endl << std::endl ;
} // END
//
// ----------------------------------------------------------------
// Save computation in binary format
//
//
std::cout << "Generate " << filenameOut <<" for output file" << std::endl;
//
std::cout << " nbParticles: " << nbParticles <<" " << sizeof(nbParticles) <<std::endl;
std::cout << " denergy: " << denergy <<" " << sizeof(denergy) <<std::endl;
std::cout << " Box size: " << loader.getBoxWidth() << " " << sizeof(loader.getBoxWidth())<<std::endl;
//
FFmaGenericWriter writer(filenameOut) ;
writer.writeHeader(Centre,BoxWith, nbParticles,*particles) ;
writer.writeArrayOfParticles(particles, nbParticles);
//
// end generate
// -----------------------------------------------------
//
if(FParameters::existParameter(argc, argv, "-verbose")){
denergy = 0 ;
for(int idx = 0 ; idx < nbParticles ; ++idx){
std::cout << ">> index " << idx << std::endl;
std::cout << " x " << particles[idx].position.getX() << " y " << particles[idx].position.getY() << " z " << particles[idx].position.getZ() << std::endl;
std::cout << " Q " << particles[idx].physicalValue << " V " << particles[idx].potential << std::endl;
std::cout << " fx " << particles[idx].forces[0] << " fy " << particles[idx].forces[1] << " fz " << particles[idx].forces[2] << std::endl;
std::cout << "\n";
denergy += particles[idx].potential*particles[idx].physicalValue ;
}
}
std::cout << " ENERGY " << denergy << std::endl;
//
delete[] particles;
return 0;
}
......@@ -42,7 +42,7 @@
class FmaBasicParticle {
public:
FPoint position; ///< position of the particle
// FReal x,y,z; ///< position of the particle
// FReal x,y,z; ///< position of the particle
FReal physicalValue; ///< its physical value
/**
* return a pointer on the first value of the structure
......@@ -128,6 +128,10 @@ public:
int getReadDataNumber()
{ return 8;}
};
typedef FmaBasicParticle FmaR4W4Particle ;
typedef FmaRParticle FmaR4W8Particle ;
typedef FmaParticle FmaR8W8Particle ;
//
//! \class FFmaGenericLoader
//!
......@@ -345,11 +349,11 @@ public:
*/
template <class dataPart>
void fillParticle(dataPart &dataToRead){
int otherDataToRead = typeData[1] - dataToRead.getReadDataNumber() ;
if(binaryFile){
int otherDataRead = typeData[1] - dataToRead.getReadDataNumber() ;
if(binaryFile){
file->read((char*)(dataToRead.getPtrFirstData()), sizeof(FReal)*(dataToRead.getReadDataNumber()));
if( otherDataToRead > 0){
file->read((char*)(this->tmpVal), sizeof(FReal)*(otherDataToRead));
if( otherDataRead > 0){
file->read((char*)(this->tmpVal), sizeof(FReal)*(otherDataRead));
}
}
else{
......@@ -358,9 +362,9 @@ public:
(*this->file) >>*val;
++val;
}
if( otherDataToRead > 0){
if( otherDataRead > 0){
FReal x;
for (int i = 0 ; i <otherDataToRead ;++i){
for (int i = 0 ; i <otherDataRead ;++i){
(*this->file) >>x;
}
}
......@@ -374,8 +378,8 @@ public:
*/
template <class dataPart>
void fillParticle(dataPart *dataToRead, const int N){
int otherDataToRead = typeData[1] - (*dataToRead).getReadDataNumber() ;
if(binaryFile && otherDataToRead == 0 ){
int otherDataRead = typeData[1] - (*dataToRead).getReadDataNumber() ;
if(binaryFile && otherDataRead == 0 ){
file->read((char*)((*dataToRead).getPtrFirstData()), sizeof(FReal)*(N*(*dataToRead).getReadDataNumber()));
}
else {
......@@ -638,7 +642,8 @@ public:
}
else{ // ASCII part
const int ndata = dataToWrite[0].getWriteDataNumber();
std::cout << "typeData "<< sizeof(FReal) << " "<<ndata << std::endl;
// std::cout << "typeData "<< sizeof(FReal) << " "<<ndata << std::endl;
this->file->precision(10);
for (int i = 0 ; i <N ; ++i){
const FReal * val = dataToWrite[i].getPtrFirstData() ;
......@@ -673,6 +678,7 @@ public:
file->write((char*)(dataToWrite), N*nbData*sizeof(FReal));
}
else{
this->file->precision(10);
// std::cout << "N "<< N << " nbData "<< nbData<<std::endl;
// exit(-1);
int k = 0;
......@@ -691,6 +697,7 @@ public:
private:
void writerAscciHeader( const FPoint &centerOfBox,const FReal &boxWidth,
const FSize &nbParticles, const unsigned int *typeFReal) {
this->file->precision(10);
(*this->file) << typeFReal[0] <<" "<<typeFReal[1]<<std::endl;
(*this->file) << nbParticles << " "<< boxWidth << " "
<< centerOfBox.getX() << " " << centerOfBox.getY() << " "<<centerOfBox.getZ()
......
This diff is collapsed.
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