File Tracking Added.
This commit is contained in:
@@ -1,36 +0,0 @@
|
|||||||
//
|
|
||||||
// energyhisto.cpp
|
|
||||||
// mc_electron
|
|
||||||
//
|
|
||||||
// Created by Christian Reiling on 20.09.18.
|
|
||||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "energyhisto.h"
|
|
||||||
|
|
||||||
|
|
||||||
void Energyhisto::addContent(double z1_m, double z2_m, double Energy_eV) {
|
|
||||||
int zLowBin = std::min(getZBin(z1_m),getZBin(z2_m));
|
|
||||||
int zUpBin = std::max(getZBin(z1_m),getZBin(z2_m));
|
|
||||||
int EBin = getEBin(Energy_eV);
|
|
||||||
data(blitz::Range(zLowBin,zUpBin),EBin) += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Energyhisto::getZBin(double z_m) {
|
|
||||||
if (z_m<0 || z_m>wgtsLength_m) {
|
|
||||||
std::cerr<<"Energyhisto::getZBin: z = "<<z_m<<" outside out dimensions \n";
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return(floor(z_m/ZBinWidth));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Energyhisto::getEBin(double E_eV) {
|
|
||||||
if (E_eV<minEBin) {
|
|
||||||
return (0);
|
|
||||||
} else if (E_eV > maxEBin) {
|
|
||||||
return(numberEBins + 1);
|
|
||||||
} else {
|
|
||||||
return(floor((E_eV-minEBin)/EBinWidth));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
//
|
|
||||||
// energyhisto.h
|
|
||||||
// mc_electron
|
|
||||||
//
|
|
||||||
// Created by Christian Reiling on 20.09.18.
|
|
||||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef energyhisto_h
|
|
||||||
#define energyhisto_h
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include "blitz/array.h"
|
|
||||||
#include "blitz/tinyvec2.h"
|
|
||||||
|
|
||||||
#include "parameter.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Energyhisto: public Parameter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~Energyhisto(){};
|
|
||||||
Energyhisto(){
|
|
||||||
data.resize(numberZBins,numberEBins+2); // Under and Overflow Bins
|
|
||||||
data = 0;
|
|
||||||
|
|
||||||
ZBinWidth = wgtsLength_m/numberZBins;
|
|
||||||
EBinWidth = (maxEBin-minEBin)/numberEBins;
|
|
||||||
|
|
||||||
ZBinBoarders_m.resize(numberZBins+1);
|
|
||||||
for (int i=0;i<numberZBins+1;i++) {
|
|
||||||
ZBinBoarders_m[i] = ZBinWidth*i; //More fancy with blitz functions?
|
|
||||||
}
|
|
||||||
|
|
||||||
EBinBoarders_eV.resize(numberEBins+3);
|
|
||||||
for (int i=0;i<numberEBins+1;i++) {
|
|
||||||
EBinBoarders_eV[i+1] = minEBin + i*EBinWidth; //More fancy with blitz functions?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int getZBin(double z_m);
|
|
||||||
|
|
||||||
int getEBin(double E_eV);
|
|
||||||
|
|
||||||
void addContent(double zLow_m, double zUp_m, double Energy_eV);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
double ZBinWidth, EBinWidth;
|
|
||||||
blitz::Array <double,1> ZBinBoarders_m, EBinBoarders_eV;
|
|
||||||
|
|
||||||
blitz::Array<int,2> data;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -18,6 +18,5 @@
|
|||||||
int main(int argc, const char * argv[]) {
|
int main(int argc, const char * argv[]) {
|
||||||
Debug("Debug Mode is on.")
|
Debug("Debug Mode is on.")
|
||||||
Simulation Sim;
|
Simulation Sim;
|
||||||
Sim.init();
|
|
||||||
Sim.doit();
|
Sim.doit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ public:
|
|||||||
wgtsLength_m = value("wgtsLength_m");
|
wgtsLength_m = value("wgtsLength_m");
|
||||||
wgtsRadius_m = value("wgtsRadius_m");
|
wgtsRadius_m = value("wgtsRadius_m");
|
||||||
wgtsTritiumDensity_m3 = value("wgtsTritiumDensity_m3");
|
wgtsTritiumDensity_m3 = value("wgtsTritiumDensity_m3");
|
||||||
|
|
||||||
|
// Output
|
||||||
|
numberZBins = value ("numberZBins");
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -91,14 +94,15 @@ protected:
|
|||||||
int injectionMethod;
|
int injectionMethod;
|
||||||
double deltaKinEnergy_eV;
|
double deltaKinEnergy_eV;
|
||||||
double MBKinEnergy_eV;
|
double MBKinEnergy_eV;
|
||||||
|
|
||||||
|
|
||||||
//KATRIN Specs
|
//KATRIN Specs
|
||||||
double wgtsMagField_T;
|
double wgtsMagField_T;
|
||||||
double wgtsLength_m;
|
double wgtsLength_m;
|
||||||
double wgtsRadius_m;
|
double wgtsRadius_m;
|
||||||
double wgtsTritiumDensity_m3;
|
double wgtsTritiumDensity_m3;
|
||||||
|
|
||||||
|
// Output
|
||||||
|
int numberZBins;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
seed = 2342395328
|
|
||||||
numTotalParticles = 1
|
|
||||||
dt_s = 0.0000000001
|
|
||||||
injectionMethod = 1
|
|
||||||
deltaKinEnergy_eV = 100
|
|
||||||
MBKinEnergy_eV = 100
|
|
||||||
|
|
||||||
numberZBins = 10
|
|
||||||
minEBin = 0
|
|
||||||
maxEBin = 10
|
|
||||||
numberEBins = 10
|
|
||||||
|
|
||||||
|
|
||||||
wgtsMagField_T = 2.5
|
|
||||||
wgtsLength_m = 10
|
|
||||||
wgtsRadius_m = 0.045
|
|
||||||
wgtsTritiumDensity_m3 = 5e21
|
|
||||||
wgtsTemp_K = 27.
|
|
||||||
|
|
||||||
|
|
||||||
@@ -7,9 +7,59 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "simulation.h"
|
#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() {
|
void Simulation::doit() {
|
||||||
@@ -44,8 +94,6 @@ void Simulation::doit() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Simulation Methods
|
|
||||||
Particle Simulation::inject() {
|
Particle Simulation::inject() {
|
||||||
blitz::TinyVector<double,3> loc_m, speed_ms;
|
blitz::TinyVector<double,3> loc_m, speed_ms;
|
||||||
double r_m,phi_rad,z_m;
|
double r_m,phi_rad,z_m;
|
||||||
@@ -85,10 +133,10 @@ Particle Simulation::inject() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Simulation::move(Particle *inputParticle) {
|
bool Simulation::move(Particle *inputParticle) {
|
||||||
blitz::TinyVector<double,3> loc_m = inputParticle->getLoc_m();
|
blitz::TinyVector<double,3> oldLoc_m = inputParticle->getLoc_m();
|
||||||
double density_m3 = Kat.getTritiumDensity(loc_m);
|
double density_m3 = Kat.getTritiumDensity(oldLoc_m);
|
||||||
blitz::TinyVector<double,3> E_Vm = Kat.getElField(loc_m);
|
blitz::TinyVector<double,3> E_Vm = Kat.getElField(oldLoc_m);
|
||||||
blitz::TinyVector<double,3> B_T = Kat.getMagField(loc_m);
|
blitz::TinyVector<double,3> B_T = Kat.getMagField(oldLoc_m);
|
||||||
|
|
||||||
double sigTot_m2 = inputParticle->getSigmaTot();
|
double sigTot_m2 = inputParticle->getSigmaTot();
|
||||||
double MFP_m = 1/(density_m3 * sigTot_m2);
|
double MFP_m = 1/(density_m3 * sigTot_m2);
|
||||||
@@ -96,12 +144,12 @@ bool Simulation::move(Particle *inputParticle) {
|
|||||||
double distance = 0.;
|
double distance = 0.;
|
||||||
while (distance < MFP_m) {
|
while (distance < MFP_m) {
|
||||||
distance += inputParticle->borisFly_m(E_Vm , B_T , dt_s);
|
distance += inputParticle->borisFly_m(E_Vm , B_T , dt_s);
|
||||||
// Log Movment here!!!
|
|
||||||
//std::cout<<*inputParticle<<std::endl;
|
|
||||||
if (movedOutside(inputParticle->getLoc_m())) {
|
if (movedOutside(inputParticle->getLoc_m())) {
|
||||||
|
logParticle(inputParticle,oldLoc_m);
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logParticle(inputParticle,oldLoc_m);
|
||||||
return(true);
|
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 ) );
|
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) {
|
int Simulation::getInteraction(Particle inputParticle) {
|
||||||
return(0);
|
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();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,9 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <dirent.h>
|
||||||
#include "blitz/array.h"
|
#include "blitz/array.h"
|
||||||
#include "blitz/tinyvec2.h"
|
#include "blitz/tinyvec2.h"
|
||||||
#include <random/uniform.h>
|
#include <random/uniform.h>
|
||||||
@@ -23,6 +26,7 @@
|
|||||||
#include "particle.h"
|
#include "particle.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Simulation: public Parameter
|
class Simulation: public Parameter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -30,46 +34,33 @@ public:
|
|||||||
Simulation() {
|
Simulation() {
|
||||||
numInjectedParticles = 0;
|
numInjectedParticles = 0;
|
||||||
rngUni.seed(seed);
|
rngUni.seed(seed);
|
||||||
|
initLogger();
|
||||||
|
|
||||||
// Check OutFile already existing? -no-> Create Outfile_1
|
|
||||||
// -yes-> Create Outfile_i+1
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void initLogger(void);
|
||||||
void init(void);
|
|
||||||
void doit(void);
|
void doit(void);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Simulation Objects
|
// Simulation
|
||||||
Katrin Kat;
|
Katrin Kat;
|
||||||
ranlib::Uniform<double> rngUni;
|
ranlib::Uniform<double> rngUni;
|
||||||
int numInjectedParticles;
|
int numInjectedParticles;
|
||||||
std::deque<Particle> particleQue;
|
std::deque<Particle> particleQue;
|
||||||
|
|
||||||
// Simulation Methods
|
|
||||||
Particle inject();
|
Particle inject();
|
||||||
bool move(Particle *inputParticle);
|
bool move(Particle *inputParticle);
|
||||||
bool movedOutside(blitz::TinyVector<double,3> loc_m);
|
bool movedOutside(blitz::TinyVector<double,3> loc_m);
|
||||||
|
|
||||||
int getInteraction(Particle inPutParticle);
|
int getInteraction(Particle inPutParticle);
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Logging Objects
|
|
||||||
int step;
|
|
||||||
std::string outputName;
|
|
||||||
std::vector<std::string> particleLogger;
|
|
||||||
std::vector<Particle>::iterator particleLoggerIt;
|
|
||||||
std::ofstream outFile;
|
|
||||||
|
|
||||||
|
// Logging
|
||||||
// Logging Methods
|
std::vector<std::ofstream> outStream;
|
||||||
void writeToLogger(Particle inputParticle);
|
std::vector<double> zLogValues;
|
||||||
void writeToFile(std::vector<Particle> *particleLogger);
|
void logParticle(Particle *inputParticle,blitz::TinyVector<double,3> oldLoc_m);
|
||||||
*/
|
std::string getTimeString();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user