Maj terminée. Pour consulter la release notes associée voici le lien :
https://about.gitlab.com/releases/2021/07/07/critical-security-release-gitlab-14-0-4-released/

DirectComputation.cpp 8.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
// ===================================================================================
// ===================================================================================
// 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/FParameters.hpp"

#include "Files/FFmaGenericLoader.hpp"
#include "Kernels/P2P/FP2P.hpp"


COULAUD Olivier's avatar
COULAUD Olivier committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47
//
/// \file  DirectComputation.cpp
//!
//! \brief DirectComputation: Driver to compute direct interaction between N particles for 1/r kernel.
//!
//! DirectComputation: Driver to compute direct interaction between N particles for 1/r kernel.
//! the particles are read from file given by -fin argument and potential, forces are stored in FMA format.
//!  <b> General arguments:</b>
//!     \param   -help (-h)      to see the parameters available in this driver
//!     \param   -fin name:  file name  to convert (with extension .fma (ascii) or bfma (binary).
//!                             Only our FMA (.bma, .bfma) is allowed "
//!     \param    -fout filenameOUT   output file  with extension (default output.bfma)
//!      \param   -verbose : print index x y z Q V fx fy fz
//!
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

// 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);

	}

	//////////////////////////////////////////////////////////////

COULAUD Olivier's avatar
COULAUD Olivier committed
68 69
	const std::string defaultFile(/*SCALFMMDataPath+*/"../Data/unitCubeXYZQ20k.fma");
	const std::string filenameIn(FParameters::getStr(argc,argv,"-fin",  defaultFile.c_str()));
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
	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;
	//
COULAUD Olivier's avatar
COULAUD Olivier committed
98
//	int nbDataToRead = particles[0].getReadDataNumber();
99 100
	for(int idx = 0 ; idx<nbParticles ; ++idx){
		//
101
	    loader.fillParticle(particles[idx].getPtrFirstData(), particles[idx].getReadDataNumber());
102 103
		//	loader.fillParticle(particles[idx].getPtrFirstData(), nbDataToRead);    // OK
		//  loader.fillParticle(particles[idx]); // OK
COULAUD Olivier's avatar
COULAUD Olivier committed
104 105
	//    std::cout << idx <<"  "<<  particles[idx].getPosition() << " "<<particles[idx].getPhysicalValue() << " "<<particles[idx].getPotential()
	//			<<"  " << particles[idx].getForces()[0]<<"  " <<particles[idx].getForces()[1]<<"  " <<particles[idx].getForces()[2]<<"  " <<std::endl;
106
		//
107
	    totalCharge += particles[idx].getPhysicalValue() ;
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
	}

	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(
140 141 142 143 144 145
								particles[idxOther].getPosition().getX(), particles[idxOther].getPosition().getY(),
								particles[idxOther].getPosition().getZ(),particles[idxOther].getPhysicalValue(),
								particles[idxTarget].getPosition().getX(), particles[idxTarget].getPosition().getY(),
								particles[idxTarget].getPosition().getZ(),particles[idxTarget].getPhysicalValue(),
								&particles[idxTarget].setForces()[0],&particles[idxTarget].setForces()[1],
								&particles[idxTarget].setForces()[2],particles[idxTarget].setPotential());
146 147 148 149 150 151
					}
				}
			} // end for
			// Compute the energy
#pragma omp  for reduction(+:denergy)
			for(int idx = 0 ; idx < nbParticles ; ++idx){
152
			    denergy +=  particles[idx].getPotential()*(particles[idx].getPhysicalValue()) ;
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
			}
		} // 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;
190 191 192
			std::cout << " x   " << particles[idx].getPosition().getX() << " y  " << particles[idx].getPosition().getY() << " z  " << particles[idx].getPosition().getZ() << std::endl;
			std::cout << " Q   " << particles[idx].getPhysicalValue()   << " V  " << particles[idx].getPotential() << std::endl;
			std::cout << " fx  " << particles[idx].getForces()[0]       << " fy " << particles[idx].getForces()[1]       << " fz " << particles[idx].getForces()[2] << std::endl;
193
			std::cout << "\n";
194
			denergy +=  particles[idx].getPotential()*particles[idx].getPhysicalValue() ;
195 196 197 198 199 200 201 202 203 204
		}
	}
	std::cout << " ENERGY " << denergy << std::endl;
	//
	delete[] particles;
	return 0;
}