Removed std:: and using namespace std
This commit is contained in:
@@ -22,6 +22,9 @@
|
||||
#include <random/uniform.h>
|
||||
#include <random/normal.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
class Constants
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -95,7 +95,7 @@ blitz::TinyVector<double,3> Interaction::getNewDir(double theta,double phi) {
|
||||
}
|
||||
endloops:
|
||||
if (phi1 == -1) {
|
||||
std::cerr<<"Interaction::getNewDir: phi1 not found."<<std::endl;
|
||||
cerr<<"Interaction::getNewDir: phi1 not found."<<endl;
|
||||
exit(1);
|
||||
}
|
||||
blitz::TinyVector<double,3> newDir;
|
||||
|
||||
@@ -10,27 +10,29 @@
|
||||
#include "tests.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define Debug( x ) std::cout << x << std::endl;
|
||||
#define Debug( x ) cout << x << endl;
|
||||
#else
|
||||
#define Debug( x )
|
||||
#endif
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
Debug("Debug Mode is on.")
|
||||
|
||||
//runTests();
|
||||
/*
|
||||
std::clock_t start;
|
||||
clock_t start;
|
||||
double duration;
|
||||
start = std::clock();
|
||||
start = clock();
|
||||
*/
|
||||
|
||||
Simulation Sim;
|
||||
Sim.initLogger();
|
||||
Sim.doit();
|
||||
/*
|
||||
duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
|
||||
std::cout<<"Duration: "<< duration <<'\n';
|
||||
duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;
|
||||
cout<<"Duration: "<< duration <<'\n';
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
double value(std::string strin, char* ext = (char*)("cat")) {
|
||||
double value(string strin, char* ext = (char*)("cat")) {
|
||||
char* str = strdup(strin.c_str());
|
||||
double temp;
|
||||
char dummy[256];
|
||||
@@ -47,14 +47,14 @@ private:
|
||||
|
||||
if (getenv("poub") == NULL)
|
||||
{
|
||||
std::cerr<<"Parameter::value: Environment variable poub not defined.\n";
|
||||
cerr<<"Parameter::value: Environment variable poub not defined.\n";
|
||||
exit(1);
|
||||
}
|
||||
strcpy(fname, getenv("poub"));
|
||||
pname = getenv("pname");
|
||||
if (pname == NULL)
|
||||
{
|
||||
std::cerr<<"Parameter::value: Environment variable pname not defined.\n";
|
||||
cerr<<"Parameter::value: Environment variable pname not defined.\n";
|
||||
exit(1);
|
||||
}
|
||||
if (!ext)
|
||||
@@ -64,7 +64,7 @@ private:
|
||||
sprintf(fname,"%s/%s.%s",getenv("poub"),getenv("pname"), ext);
|
||||
if (!(fcat = fopen(fname, "r")))
|
||||
{
|
||||
std::cerr<<"Parameter::value: Can not open file " <<fname<<".\n";
|
||||
cerr<<"Parameter::value: Can not open file " <<fname<<".\n";
|
||||
exit(1);
|
||||
}
|
||||
while (!feof(fcat))
|
||||
@@ -80,7 +80,7 @@ private:
|
||||
}
|
||||
fclose(fcat);
|
||||
|
||||
std::cerr<<"Parameter::value: Variable "<<str<<" not found.\n";
|
||||
cerr<<"Parameter::value: Variable "<<str<<" not found.\n";
|
||||
exit(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
|
||||
// Overload <<
|
||||
std::ostream& operator<<(std::ostream& os, const species& SpecOut) {
|
||||
ostream& operator<<(ostream& os, const species& SpecOut) {
|
||||
switch (SpecOut) {
|
||||
case undef:
|
||||
os<<"undef";
|
||||
@@ -41,12 +41,12 @@ std::ostream& operator<<(std::ostream& os, const species& SpecOut) {
|
||||
os<<"DT";
|
||||
break;
|
||||
default:
|
||||
std::cerr<<"unknown species";
|
||||
cerr<<"unknown species";
|
||||
exit(1);
|
||||
}
|
||||
return (os);
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, const Particle& partOut) {
|
||||
ostream& operator<<(ostream& os, const Particle& partOut) {
|
||||
os
|
||||
<< partOut.Id << ";"
|
||||
<<partOut.parentId << ";"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "constants.h"
|
||||
|
||||
typedef enum species{undef, electron, positron, proton, tritium, tritium2, helium, deuterium, DT}species;
|
||||
std::ostream& operator<<(std::ostream& os, const species& SpecOut);
|
||||
ostream& operator<<(ostream& os, const species& SpecOut);
|
||||
|
||||
|
||||
class Particle: protected Constants {
|
||||
@@ -65,7 +65,7 @@ protected:
|
||||
|
||||
// Write Methods
|
||||
public:
|
||||
friend std::ostream& operator<<(std::ostream& os, const Particle& partOut);
|
||||
friend ostream& operator<<(ostream& os, const Particle& partOut);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,7 +21,7 @@ void Simulation::doit() {
|
||||
particleQue.push_back(inject());
|
||||
numInjectedParticles++;
|
||||
if (numInjectedParticles%100 == 0){
|
||||
std::cout<<numInjectedParticles<<"/"<<numTotalParticles<<std::endl;
|
||||
cout<<numInjectedParticles<<"/"<<numTotalParticles<<endl;
|
||||
}
|
||||
}
|
||||
ScatT2 = Kat.getT2AverScatPart(particleQue.front().getLoc_m(), &rngUni);
|
||||
@@ -45,7 +45,7 @@ void Simulation::doit() {
|
||||
case 3: // Recombination
|
||||
break;
|
||||
default:
|
||||
std::cerr<<"getprocess() returned unknown event"<<std::endl;
|
||||
cerr<<"getprocess() returned unknown event"<<endl;
|
||||
break;
|
||||
}
|
||||
if (checkTermination (particleQue.front())) {
|
||||
@@ -80,7 +80,7 @@ Particle Simulation::inject() {
|
||||
Ekin_eV = getRandEnergyMaxwell(MBTemp_K,me_eV, &rngNormal);
|
||||
break;
|
||||
default:
|
||||
std::cerr<<"Invalid Injection Method./n";
|
||||
cerr<<"Invalid Injection Method./n";
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
@@ -188,7 +188,7 @@ bool Simulation::checkTermination(Particle termPart) {
|
||||
EKin_eV = termPart.getKinEnergy_eV();
|
||||
ETemp_eV = 3./2.*kb_eVK*wgtsTemp_K;
|
||||
if (ETemp_eV<0) {
|
||||
std::cerr<<"Simulation::checkTermination: ETemp_eV < 0." <<std::endl;
|
||||
cerr<<"Simulation::checkTermination: ETemp_eV < 0." <<endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -205,37 +205,37 @@ void Simulation::initLogger(void) {
|
||||
zLogValues.clear();
|
||||
logging = true;
|
||||
if (numberZBins < 1) {
|
||||
std::cout<<"Logging turned off."<<std::endl;
|
||||
cout<<"Logging turned off."<<endl;
|
||||
logging = false;
|
||||
return;
|
||||
} else if (numberZBins == 1) {
|
||||
std::cout<<"Logging 1 z-Value: "<<wgtsLength_m<<std::endl;
|
||||
cout<<"Logging 1 z-Value: "<<wgtsLength_m<<endl;
|
||||
zLogValues.push_back(wgtsLength_m);
|
||||
} else {
|
||||
for (int i = 0;i<numberZBins;i++) {
|
||||
zLogValues.push_back( i*wgtsLength_m/(numberZBins-1) );
|
||||
}
|
||||
std::cout<<"Logging "<<numberZBins<<" z-Values."<<std::endl;
|
||||
cout<<"Logging "<<numberZBins<<" z-Values."<<endl;
|
||||
}
|
||||
|
||||
std::string dirname = getDirName();
|
||||
outStream = new std::ofstream [numberZBins];
|
||||
string dirname = getDirName();
|
||||
outStream = new ofstream [numberZBins];
|
||||
|
||||
for (int i = 0; i < numberZBins; i++)
|
||||
{
|
||||
std::string fileName = dirname + "/z=" + std::to_string(zLogValues[i]) + ".dat";
|
||||
string fileName = dirname + "/z=" + to_string(zLogValues[i]) + ".dat";
|
||||
outStream[i].open(fileName);
|
||||
}
|
||||
}
|
||||
std::string Simulation::getDirName() {
|
||||
std::string poub = getenv("poub");
|
||||
std::string pname = getenv("pname");
|
||||
string Simulation::getDirName() {
|
||||
string poub = getenv("poub");
|
||||
string pname = getenv("pname");
|
||||
int i = 1;
|
||||
std::string dirname;
|
||||
string dirname;
|
||||
struct stat statbuf;
|
||||
int isDir;
|
||||
do {
|
||||
dirname = poub + "/" + pname + "_" + getTimeString() + "_" + std::to_string(i++);
|
||||
dirname = poub + "/" + pname + "_" + getTimeString() + "_" + to_string(i++);
|
||||
isDir = 0;
|
||||
if (stat(dirname.c_str(), &statbuf) != -1) {
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
@@ -245,20 +245,20 @@ std::string Simulation::getDirName() {
|
||||
} while ( isDir == 1 );
|
||||
|
||||
if (mkdir(dirname.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
|
||||
std::cerr<<"Simulation::initLogger: Could not create folder "<<dirname.c_str()<<" for Logging."<<std::endl;
|
||||
cerr<<"Simulation::initLogger: Could not create folder "<<dirname.c_str()<<" for Logging."<<endl;
|
||||
exit(1);
|
||||
}
|
||||
return(dirname);
|
||||
}
|
||||
|
||||
std::string Simulation::getTimeString() {
|
||||
string Simulation::getTimeString() {
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
char buffer[80];
|
||||
time (&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
strftime(buffer,sizeof(buffer),"%Y%m%d",timeinfo);
|
||||
std::string str(buffer);
|
||||
string str(buffer);
|
||||
return(str);
|
||||
}
|
||||
void Simulation::logParticle(Particle *logPart,blitz::TinyVector<double,3> oldLoc_m) {
|
||||
@@ -269,12 +269,12 @@ void Simulation::logParticle(Particle *logPart,blitz::TinyVector<double,3> oldLo
|
||||
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = logPart->getLoc_m()[2];
|
||||
double zmin = std::min(zold,znew);
|
||||
double zmax = std::max(zold,znew);
|
||||
double zmin = min(zold,znew);
|
||||
double zmax = max(zold,znew);
|
||||
|
||||
for (int i=0;i<numberZBins;i++) {
|
||||
if (zLogValues[i]>=zmin && zLogValues[i]<=zmax) {
|
||||
outStream[i]<<*logPart<<std::endl; // Location wrong, because it s the new Location.
|
||||
outStream[i]<<*logPart<<endl; // Location wrong, because it s the new Location.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ protected:
|
||||
ranlib::Uniform<double> rngUni;
|
||||
ranlib::NormalUnit<double> rngNormal;
|
||||
int numInjectedParticles;
|
||||
std::deque<Particle> particleQue;
|
||||
deque<Particle> particleQue;
|
||||
|
||||
// Injection
|
||||
Particle inject();
|
||||
@@ -56,13 +56,13 @@ protected:
|
||||
|
||||
// Logging
|
||||
bool logging;
|
||||
//std::vector<std::ofstream> outStream;
|
||||
//std::ofstream outStream[];
|
||||
std::ofstream *outStream;
|
||||
std::vector<double> zLogValues;
|
||||
//vector<ofstream> outStream;
|
||||
//ofstream outStream[];
|
||||
ofstream *outStream;
|
||||
vector<double> zLogValues;
|
||||
void logParticle(Particle *logPart,blitz::TinyVector<double,3> oldLoc_m);
|
||||
std::string getDirName();
|
||||
std::string getTimeString();
|
||||
string getDirName();
|
||||
string getTimeString();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+13
-13
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "tests.h"
|
||||
void runTests() {
|
||||
std::string outputFilePath = "/Users/ChristianReiling/Documents/Masterarbeit/CodeTesting/Data/";
|
||||
string outputFilePath = "/Users/ChristianReiling/Documents/Masterarbeit/CodeTesting/Data/";
|
||||
TestSimulation TEST;
|
||||
TEST.injection (100000, outputFilePath + "injection.dat");
|
||||
TEST.decaySpectrum(100000, outputFilePath + "decaySpectrum.dat");
|
||||
@@ -16,43 +16,43 @@ void runTests() {
|
||||
TEST.maxwellBoltzmann(100000, outputFilePath + "maxwellBoltzmann.dat");
|
||||
}
|
||||
|
||||
void TestSimulation::injection (int numParticles, std::string outputFilePath) {
|
||||
std::ofstream outFile;
|
||||
void TestSimulation::injection (int numParticles, string outputFilePath) {
|
||||
ofstream outFile;
|
||||
outFile.open (outputFilePath);
|
||||
for (int i = 0;i<numParticles;i++) {
|
||||
outFile << inject() <<std::endl;
|
||||
outFile << inject() <<endl;
|
||||
}
|
||||
outFile.close();
|
||||
|
||||
}
|
||||
|
||||
void TestSimulation::decaySpectrum (int numPoints,std::string outputFilePath) {
|
||||
std::ofstream outFile;
|
||||
void TestSimulation::decaySpectrum (int numPoints,string outputFilePath) {
|
||||
ofstream outFile;
|
||||
outFile.open (outputFilePath);
|
||||
double x,y;
|
||||
for (int i = 0;i<numPoints;i++) {
|
||||
x = i * Etridecay_eV/(numPoints-1);
|
||||
y = EnergyDistributionBetaDecay(x);
|
||||
outFile << x <<";"<<y <<std::endl;
|
||||
outFile << x <<";"<<y <<endl;
|
||||
}
|
||||
outFile.close();
|
||||
}
|
||||
|
||||
void TestSimulation::rejectionBetaDecay(int numDecays, std::string outputFilePath) {
|
||||
std::ofstream outFile;
|
||||
void TestSimulation::rejectionBetaDecay(int numDecays, string outputFilePath) {
|
||||
ofstream outFile;
|
||||
outFile.open (outputFilePath);
|
||||
for (int i = 0;i<numDecays;i++) {
|
||||
outFile << getBetaDecayEnergyRejection_eV() <<std::endl;
|
||||
outFile << getBetaDecayEnergyRejection_eV() <<endl;
|
||||
}
|
||||
outFile.close();
|
||||
}
|
||||
|
||||
|
||||
void TestSimulation::maxwellBoltzmann(int numDecays, std::string outputFilePath) {
|
||||
std::ofstream outFile;
|
||||
void TestSimulation::maxwellBoltzmann(int numDecays, string outputFilePath) {
|
||||
ofstream outFile;
|
||||
outFile.open (outputFilePath);
|
||||
for (int i = 0;i<numDecays;i++) {
|
||||
//outFile << getEnergyBoltzmann_eV() <<std::endl;
|
||||
//outFile << getEnergyBoltzmann_eV() <<endl;
|
||||
}
|
||||
outFile.close();
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@ public:
|
||||
~TestSimulation(){}
|
||||
TestSimulation() : Simulation(){};
|
||||
|
||||
void injection (int numParticles, std::string outputFilePath);
|
||||
void decaySpectrum (int numPoints, std::string outputFilePath);
|
||||
void rejectionBetaDecay(int numDecays, std::string outputFilePath);
|
||||
void maxwellBoltzmann(int numDecays, std::string outputFilePath);
|
||||
void injection (int numParticles, string outputFilePath);
|
||||
void decaySpectrum (int numPoints, string outputFilePath);
|
||||
void rejectionBetaDecay(int numDecays, string outputFilePath);
|
||||
void maxwellBoltzmann(int numDecays, string outputFilePath);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user