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