File Tracking Added.
This commit is contained in:
@@ -7,9 +7,59 @@
|
||||
//
|
||||
|
||||
#include "simulation.h"
|
||||
//
|
||||
void Simulation::init() {
|
||||
|
||||
|
||||
void Simulation::initLogger(void) {
|
||||
// Set zLogValues;
|
||||
zLogValues.clear();
|
||||
if (numberZBins < 1) {
|
||||
std::cout<<"No Logging Selected"<<std::endl;
|
||||
} else if (numberZBins == 1) {
|
||||
std::cout<<"Logging 1 z-Value: "<<wgtsLength_m<<std::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;
|
||||
}
|
||||
|
||||
std::string poub = getenv("poub");
|
||||
std::string pname = getenv("pname");
|
||||
int i = 1;
|
||||
std::string dirname;
|
||||
struct stat statbuf;
|
||||
int isDir;
|
||||
do {
|
||||
dirname = poub + "/" + pname + "_" + getTimeString() + "_" + std::to_string(i++);
|
||||
isDir = 0;
|
||||
if (stat(dirname.c_str(), &statbuf) != -1) {
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
isDir = 1;
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
exit(1);
|
||||
}
|
||||
for (int i = 0; i < numberZBins; i++)
|
||||
{
|
||||
std::string fileName = dirname + "/z=" + std::to_string(zLogValues[i]) + ".dat";
|
||||
outStream.emplace_back(std::ofstream{fileName});
|
||||
}
|
||||
}
|
||||
|
||||
std::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);
|
||||
return(str);
|
||||
}
|
||||
|
||||
void Simulation::doit() {
|
||||
@@ -44,8 +94,6 @@ void Simulation::doit() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Simulation Methods
|
||||
Particle Simulation::inject() {
|
||||
blitz::TinyVector<double,3> loc_m, speed_ms;
|
||||
double r_m,phi_rad,z_m;
|
||||
@@ -85,10 +133,10 @@ Particle Simulation::inject() {
|
||||
}
|
||||
|
||||
bool Simulation::move(Particle *inputParticle) {
|
||||
blitz::TinyVector<double,3> loc_m = inputParticle->getLoc_m();
|
||||
double density_m3 = Kat.getTritiumDensity(loc_m);
|
||||
blitz::TinyVector<double,3> E_Vm = Kat.getElField(loc_m);
|
||||
blitz::TinyVector<double,3> B_T = Kat.getMagField(loc_m);
|
||||
blitz::TinyVector<double,3> oldLoc_m = inputParticle->getLoc_m();
|
||||
double density_m3 = Kat.getTritiumDensity(oldLoc_m);
|
||||
blitz::TinyVector<double,3> E_Vm = Kat.getElField(oldLoc_m);
|
||||
blitz::TinyVector<double,3> B_T = Kat.getMagField(oldLoc_m);
|
||||
|
||||
double sigTot_m2 = inputParticle->getSigmaTot();
|
||||
double MFP_m = 1/(density_m3 * sigTot_m2);
|
||||
@@ -96,12 +144,12 @@ bool Simulation::move(Particle *inputParticle) {
|
||||
double distance = 0.;
|
||||
while (distance < MFP_m) {
|
||||
distance += inputParticle->borisFly_m(E_Vm , B_T , dt_s);
|
||||
// Log Movment here!!!
|
||||
//std::cout<<*inputParticle<<std::endl;
|
||||
if (movedOutside(inputParticle->getLoc_m())) {
|
||||
logParticle(inputParticle,oldLoc_m);
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
logParticle(inputParticle,oldLoc_m);
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -110,37 +158,17 @@ bool Simulation::movedOutside(blitz::TinyVector<double,3> loc_m) {
|
||||
return ( ! (loc_m[2]>0 && loc_m[2]<wgtsLength_m && r_m<wgtsRadius_m ) );
|
||||
}
|
||||
|
||||
void Simulation::logParticle(Particle *inputParticle,blitz::TinyVector<double,3> oldLoc_m) {
|
||||
// Annahme: Ohne Interaction bliebt Bewegung in z-Richtung Konstant.
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = inputParticle->getLoc_m()[2];
|
||||
for (int i=0;i<numberZBins;i++) {
|
||||
if (zLogValues[i]>=zold && zLogValues[i]<=znew) {
|
||||
outStream[i]<<*inputParticle<<std::endl; // Location wrong, because it s the new Location.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Simulation::getInteraction(Particle inputParticle) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
// Logging Methods
|
||||
void Simulation::writeToLogger(Particle inputParticle) {
|
||||
std::string textLine;
|
||||
|
||||
|
||||
particleLogger.push_back(textLine);
|
||||
}
|
||||
|
||||
|
||||
void Simulation::writeToFile(std::vector<Particle> *particleLogger) {
|
||||
// Write all electrons to one file, just append them, ID for identification
|
||||
// Writing after every particle is very time intense.... Buffer and write only once every...
|
||||
|
||||
outFile.open (outputName,std::ios::app);
|
||||
for (particleLoggerIt = particleLogger->begin() ; particleLoggerIt != particleLogger->end() ; particleLoggerIt++) {
|
||||
outFile << *particleLoggerIt<<std::endl;
|
||||
}
|
||||
outFile.close();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user