This commit is contained in:
2018-10-13 00:24:06 +02:00
10 changed files with 345 additions and 430 deletions
+46
View File
@@ -0,0 +1,46 @@
//
// constants.h
// mc_electron
//
// Created by Christian Reiling on 08.10.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#ifndef constants_h
#define constants_h
class Constants
{
public:
virtual ~Constants(){};
Constants() {};
protected:
const double pi = 3.1415;
const double c_nat = 1.;
const double c_ms = 299792458;
const double me_eV = 0.511e6;
const double qe_e = 1;
const double re_m = 2.817940322719e-15;
const double e_C = 1.602176462e-19;
const double ZT2 = 2.;
const double mT2_eV = 5.61886404234e9;
// Conversion Functions
double v_ms(double Ekin_eV) {
double gamma = 1. + Ekin_eV/me_eV;
double beta = sqrt(1 - pow(gamma,-2));
return(beta * c_ms);
}
double Ekin_eV(double speedAbs_ms) {
double beta = speedAbs_ms/c_ms;
double gamma = pow(1 - pow(beta,2),-0.5);
return ( (gamma-1) * me_eV * pow(c_nat,2) );
}
};
#endif
-36
View File
@@ -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));
}
}
-59
View File
@@ -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
+8 -1
View File
@@ -8,8 +8,15 @@
#include "simulation.h"
#ifdef DEBUG
#define Debug( x ) std::cout << x << std::endl;
#else
#define Debug( x )
#endif
int main(int argc, const char * argv[]) {
Debug("Debug Mode is on.")
Simulation Sim;
Sim.init();
Sim.doit();
}
+7 -22
View File
@@ -12,8 +12,9 @@
#include <iostream>
#include <fstream>
#include "constants.h"
class Parameter
class Parameter: protected Constants
{
public:
virtual ~Parameter(){};
@@ -32,15 +33,10 @@ public:
wgtsLength_m = value("wgtsLength_m");
wgtsRadius_m = value("wgtsRadius_m");
wgtsTritiumDensity_m3 = value("wgtsTritiumDensity_m3");
// Output
numberZBins = value ("numberZBins");
}
// Natural Constants
const double pi = 3.1415;
const double c_nat = 1.;
const double c_ms = 299792458;
const double me_eV = 0.511e6;
const double qe_e = 1;
const double re_m = 2.817940322719e-15;
private:
double value(std::string strin, char* ext = (char*)("cat")) {
@@ -98,7 +94,6 @@ protected:
int injectionMethod;
double deltaKinEnergy_eV;
double MBKinEnergy_eV;
//KATRIN Specs
double wgtsMagField_T;
@@ -106,18 +101,8 @@ protected:
double wgtsRadius_m;
double wgtsTritiumDensity_m3;
// Help Functions
double v_ms(double Ekin_eV) {
double gamma = 1. + Ekin_eV/me_eV;
double beta = sqrt(1 - pow(gamma,-2));
return(beta * c_ms);
}
double Ekin_eV(double speedAbs_ms) {
double beta = speedAbs_ms/c_ms;
double gamma = pow(1 - pow(beta,2),-0.5);
return ( (gamma-1) * me_eV * pow(c_nat,2) );
}
// Output
int numberZBins;
};
-20
View File
@@ -1,20 +0,0 @@
seed = 2342395328
numTotalParticles = 100
dt_s = 0.00000001
injectionMethod = 2
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.
+122 -1
View File
@@ -9,6 +9,9 @@
#include "particle.h"
// Overload <<
std::ostream& operator<<(std::ostream& os, const species& SpecOut) {
switch (SpecOut) {
case electron:
@@ -41,7 +44,6 @@ std::ostream& operator<<(std::ostream& os, const species& SpecOut) {
}
return (os);
}
std::ostream& operator<<(std::ostream& os, const Particle& partOut) {
os
<< partOut.Id << ";"
@@ -57,3 +59,122 @@ std::ostream& operator<<(std::ostream& os, const Particle& partOut) {
<< partOut.v_ms[2] << ";";
return os;
}
// Private Functions
double Particle::r_m() {
return ( sqrt( pow(x_m[0],2) + pow(x_m[1],2) ) );
}
double Particle::vAbs_ms() {
return ( sqrt( pow(v_ms[0],2) + pow(v_ms[1],2) + pow(v_ms[2],2)) );
}
double Particle::beta() {
return ( vAbs_ms()/c_ms );
}
double Particle::gamma() {
return ( pow(1- pow(beta(),2),-0.5));
}
double Particle::Ekin_eV() {
return ( (gamma()-1) * m_eV);
}
double Particle::tau() {
return (Ekin_eV()/me_eV) ;
}
double Particle::eta() {
double etac = (Ekin_eV() < 50e3)? 1.198 : 1.13+3.76*pow(ZT2/(137*beta()),2);
return (etac * 1.7e-5 * pow(ZT2,2./3.) /( tau()*(tau()+2) ));
}
double Particle::borisFly_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s) {
double distance_m;
x_m += dt_s/2 * v_ms;
distance_m = dt_s/2 * vAbs_ms();
this->changeSpeedBoris(E_Vm , B_T , dt_s);
x_m += dt_s/2 * v_ms;
distance_m += dt_s/2 * vAbs_ms();
return(distance_m);
}
void Particle::changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s) {
{
blitz::TinyVector<double, 3> vMinus_ms, vPlus_ms, vPrime_ms, t, s;
double q_C = -1*q_e * e_C;
double m_kg = m_eV*e_C/c_ms/c_ms;
t = q_C*dt_s/(2*m_kg) * B_T;
s = (2*t)/(1+dot(t,t));
vMinus_ms = v_ms + (q_C*E_Vm*dt_s)/(2*m_kg);
vPrime_ms = vMinus_ms + cross(vMinus_ms,t);
vPlus_ms = vMinus_ms + cross(vPrime_ms,s);
v_ms = vPlus_ms + q_C/m_kg*E_Vm*0.5*dt_s;
}
}
double Particle::getSigmaTot() {
return(getSigmaEla());
}
double Particle::getSigmaEla() {
double nenner = pi*ZT2*(ZT2+1)*re_m*re_m * (1-pow(beta(),2));
double zaehler = eta() * (eta()+1)*pow(beta(),4);
return(nenner/zaehler);
}
void Particle::doElaScat(ranlib::Uniform<double> *rngUni) {
// Do Ela Scattering without Tritium Movement
double const1 = 2*pi/getSigmaEla()*ZT2*(ZT2+1)*re_m*re_m*(1- pow(beta(),2) )* pow(beta(),-4);
double theta = acos( pow( rngUni->random()/const1-pow(2*eta(),-1) , -1 ) +1+2*eta());
double phi = rngUni->random() * 2 * pi;
double vAbsNew_ms = sqrt( pow(vAbs_ms(),2)*(1-4*m_eV*mT2_eV*pow(m_eV+mT2_eV,-2)*cos(theta)*cos(theta)) );
// Change of direction following Plante and Cucinotta
double theta0 = acos(v_ms[2]/vAbs_ms());
double phi0 = atan2(v_ms[1],v_ms[0]);
double A3 = sin(theta)*cos(phi);
double A4 =A3*cos(theta0) + cos(theta)*sin(theta0);
double A5 = sin(theta)*sin(phi);
double A11 = A4*cos(phi0) - A5*sin(phi0);
double A21 = A4*sin(phi0) + A5*cos(phi0);
double theta1 = acos( cos(theta0)*cos(theta)-A3*sin(theta0) );
// Get right phi1, maybe more elegant way later.
double phi1c [4];
double phi1 = -1;
phi1c[0] = acos( A11/sin(theta1));
phi1c[1] = 2*pi - phi1c[0];
phi1c[2] = asin (A21/sin(theta1));
phi1c[3] = pi - phi1c[2];
phi1c[2] = (phi1c[2] > 0) ? phi1c[2] : 2*pi + phi1c[2];
for (int i=0;i<3;i++) {
for (int j=i+1;j<4;j++) {
if (phi1c[i]-phi1c[j] < 0.0001) {
phi1 = phi1c[i];
goto endloops;
}
}
}
endloops:
if (phi1 == -1) {
std::cerr<<"Particle::doElaScat: phi1 not found."<<std::endl;
exit(1);
}
blitz::TinyVector<double, 3> vnew_ms;
vnew_ms = sin(theta1)*cos(phi1) , sin(theta1)*sin(phi1) , cos(theta1) ;
vnew_ms = vAbsNew_ms * vnew_ms;
setSpeed_ms(vnew_ms);
}
+34 -111
View File
@@ -16,11 +16,15 @@
#include <fstream>
#include "blitz/array.h"
#include "blitz/tinyvec2.h"
#include <random/uniform.h>
#include "constants.h"
typedef enum species{electron, positron, proton, tritium, tritium2, helium, deuterium, DT}species;
std::ostream& operator<<(std::ostream& os, const species& SpecOut);
class Particle
class Particle: private Constants
{
private:
double m_eV;
@@ -30,6 +34,15 @@ private:
species s;
unsigned long int Id;
unsigned long int parentId;
double r_m();
double vAbs_ms();
double beta();
double gamma();
double Ekin_eV();
double tau();
double eta();
public:
virtual ~Particle() { }
@@ -43,125 +56,35 @@ public:
s = spec;
}
//Particle(Array<double, 1> props); //Create from Array
// Get Properties Methods
double getMass_eV() {
return(m_eV);
}
double getCharge_e() {
return(q_e);
}
blitz::TinyVector<double,3> getLoc_m() {
return(x_m);
}
blitz::TinyVector<double,3> getSpeed_ms() {
return(v_ms);
}
double getId() {
return(Id);
}
double getParentId() {
return(parentId);
}
double getRadius_m() {
return (sqrt( pow(x_m[0],2) + pow(x_m[1],2) ));
}
double getSpeedAbs_ms() {
return (sqrt( pow(v_ms[0],2) + pow(v_ms[1],2) + pow(v_ms[2],2)));
}
double getKinEnergy_eV() {
// Implement Constants here, else Particle::Parameters
const double c_ms = 299792458;
const double me_eV = 0.511e6;
double SpeedAbs_ms = sqrt( pow(v_ms[0],2) + pow(v_ms[1],2) + pow(v_ms[2],2) );
double beta = SpeedAbs_ms/c_ms;
double gamma = pow(1- pow(beta,2),-0.5);
return ( (gamma-1) * me_eV);
}
double getMass_eV() { return(m_eV); }
double getCharge_e() { return(q_e); }
blitz::TinyVector<double,3> getLoc_m() { return(x_m); }
blitz::TinyVector<double,3> getSpeed_ms() { return(v_ms); }
double getId() { return(Id); }
double getParentId() { return(parentId); }
double getRadius_m() { return ( r_m() ); }
double getSpeedAbs_ms() { return (vAbs_ms() ); }
double getKinEnergy_eV() { return (Ekin_eV() ); }
// Set Properties Methods
void setLoc_m(blitz::TinyVector<double, 3> xnew_m) {x_m = xnew_m; };
void setSpeed_ms(blitz::TinyVector<double, 3> vnew_ms) {v_ms = vnew_ms; };
// Boris Push
double borisFly_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s);
void changeLocFly(double dt_s);
void changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s);
// Cross Sections
double getSigmaTot();
double getSigmaEla();
void doElaScat(ranlib::Uniform<double> *rngUni);
// Write Methods
friend std::ostream& operator<<(std::ostream& os, const Particle& partOut);
};
// Some Code, maybe required later
/*
blitz::TinyVector<double,3> locChange(blitz::TinyVector<double, 3> dx, int i, blitz::TinyVector<double, 3> xmin, blitz::TinyVector<double, 3> nx, blitz::TinyVector<double, 3> dvdt);
blitz::TinyVector<double,3> speedChange(blitz::TinyVector<double, 3> dv, int i);
void copyol(particle*);
Array<double,1> prop(Array<double,1>);
virtual Array<double,1> array(); // ********************** warum virtual???? ******************************
//void copyol(particle);
*/
/*
class particle_info : public particle {
private:
TinyVector<double,3> x0,p0;
double id;
double mue0;
public:
particle_info(TinyVector<double,3> anfangsort, TinyVector<double,3> anfangsimpuls, double nummer, double anfangswinkel ):particle()
{
x0 = anfangsort;
p0 = anfangsimpuls;
mue0 = anfangswinkel;
id = nummer;
}
particle_info() { }
~particle_info() { }
TinyVector<double,3> anfangsort() { return(x0); }
TinyVector<double,3> anfangsimpuls() { return(p0); }
double nummer() { return(id); }
double anfangswinkel() { return(mue0); }
// virtual void copyol(particle_info*);
Array<double,1> array () // *********************** auslagern in .cpp **************************
{
Array<double,1> teilchenprop;
TinyVector<int,1> temp;
temp=8;
teilchenprop.resize(temp);
x0 = this->anfangsort();
p0 = this->anfangsimpuls();
id = this->nummer();
mue0 = this->anfangswinkel();
teilchenprop(0) = x0(0);
teilchenprop(1) = x0(1);
teilchenprop(2) = x0(2);
teilchenprop(3) = p0(0);
teilchenprop(4) = p0(1);
teilchenprop(5) = p0(2);
teilchenprop(6) = id;
teilchenprop(7) = mue0;
return(teilchenprop);
}
};
*/
// Other Functions
#endif
+110 -150
View File
@@ -7,75 +7,93 @@
//
#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() {
double energy_eV,sigTot_m2, density_m3,MFP_m;
blitz::TinyVector <double,3> oldLoc_m, newLoc_m;
blitz::TinyVector <double,3> loc_m;
bool insideFlag;
while (numInjectedParticles < numTotalParticles) {
if (particleQueue.size() < 1) {
particleQueue.assign(1,inject());
while ( (numInjectedParticles < numTotalParticles) || (particleQue.size() > 0) ) {
if (particleQue.size() < 1) {
particleQue.push_back(inject());
numInjectedParticles++;
}
particleQueueIt = particleQueue.begin();
while (particleQueueIt != particleQueue.end()) {
step = 0;
while (true) {
energy_eV = particleQueueIt->getKinEnergy_eV();
sigTot_m2 = sigmaTot_m2(energy_eV);
density_m3 = Kat.getTritiumDensity(particleQueueIt->getLoc_m());
MFP_m = 1/ ( density_m3 * sigTot_m2);
oldLoc_m = particleQueueIt->getLoc_m();
newLoc_m = move(*particleQueueIt ,MFP_m);
if (movedOutside(newLoc_m)) {
// Reflexion oder Absorbtion? Erstmal Reflexion
newLoc_m = moveToLocOfDeath(*particleQueueIt);
particleQueueIt->setLoc_m(newLoc_m);
writeToLogger(*particleQueueIt);
goto particleDied;
}
particleQueueIt->setLoc_m(newLoc_m);
writeToLogger(*particleQueueIt);
/*
switch (getprocess()) {
case "ElasticScattering":
break;
case "Ionization":
break;
case "Recombination";
partQueue.erase(partQueue.begin());
continue;
break;
default:
cerr<<"getprocess() returned unknown event"<<endl;
break;
}
*/
insideFlag = move(&particleQue.front());
if (insideFlag) {
switch (getInteraction(particleQue.front())) {
case 0: // Elastic Scattering
particleQue.front().doElaScat(&rngUni);
break;
case 1: // Ionization
//particleQue.push_back();
break;
case 2: // Recombination
particleQue.pop_front();
break;
default:
std::cerr<<"getprocess() returned unknown event"<<std::endl;
break;
}
particleDied:
particleQueueIt++;
}else {
particleQue.pop_front();
}
writeToFile(&particleLogger);
particleLogger.clear();
particleQueue = newParticles;
newParticles.clear();
}
};
// Simulation Methods
Particle Simulation::inject() {
blitz::TinyVector<double,3> loc_m, speed_ms;
double r_m,phi_rad,z_m;
@@ -93,15 +111,14 @@ Particle Simulation::inject() {
// Add Code for corregtion of direction by tritium direction!!!
switch(injectionMethod) {
case 1: // Fermi
Ekin_eV = 1.; //Implement Later
case 0: // Fermi
Ekin_eV = 100.; //Implement Later
break;
case 2: //Delta
case 1: //Delta
Ekin_eV = deltaKinEnergy_eV;
break;
case 3: //Maxwell Boltzman
Ekin_eV = 1.; //Implement Later
case 2: //Maxwell Boltzman
Ekin_eV = 100.; //Implement Later
break;
default:
std::cerr<<"Invalid Injection Method./n";
@@ -112,103 +129,46 @@ Particle Simulation::inject() {
absSpeed_ms = v_ms(Ekin_eV);
speed_ms = absSpeed_ms * speedDir;
return (Particle(me_eV,qe_e,loc_m, speed_ms,numInjectedParticles,NULL,electron));
}
blitz::TinyVector<double,3> Simulation::move(Particle inputParticle,double distance_m) {
//Pseudocode, lineare bewegung
blitz::TinyVector<double,3> oldLoc_m = inputParticle.getLoc_m();
blitz::TinyVector<double,3> v_ms =inputParticle.getSpeed_ms();
blitz::TinyVector<double,3> SpeedDir = pow(dot(v_ms,v_ms),-0.5)*v_ms;
return( oldLoc_m + SpeedDir*distance_m);
bool Simulation::move(Particle *inputParticle) {
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);
double distance = 0.;
while (distance < MFP_m) {
distance += inputParticle->borisFly_m(E_Vm , B_T , dt_s);
if (movedOutside(inputParticle->getLoc_m())) {
logParticle(inputParticle,oldLoc_m);
return(false);
}
}
logParticle(inputParticle,oldLoc_m);
return(true);
}
bool Simulation::movedOutside(blitz::TinyVector<double,3> loc_m) {
double r_m = sqrt( pow(loc_m(0),2) + pow(loc_m(1),2) );
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 ) );
}
blitz::TinyVector<double,3> Simulation::moveToLocOfDeath(Particle inputParticle) {
// Führe methode 1 step für move ein, die einen einzelnen Schritt in move ausführt und benutze diese, bis an Rand
double stepsize = inputParticle.getSpeedAbs_ms()*dt_s;
blitz::TinyVector<double,3> loc_m = inputParticle.getLoc_m();
blitz::TinyVector<double,2> rVec_m;
double r_m;
// Include saftey calc for too small stepsize
int countfordebug = 0;
while (!movedOutside(loc_m) ) {
loc_m = move (inputParticle,stepsize);
inputParticle.setLoc_m(loc_m);
countfordebug++;
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.
}
}
if (loc_m(2) < 0) {
loc_m(2) = 0;
} else if (loc_m(2) > wgtsLength_m) {
loc_m(2) = wgtsLength_m;
}
r_m = sqrt(pow(loc_m(0),2)+pow(loc_m(1),2));
if (r_m > wgtsRadius_m) {
loc_m(0) = wgtsRadius_m/r_m * loc_m(0);
loc_m(1) = wgtsRadius_m/r_m * (loc_m(1));
}
return (loc_m);
}
// 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();
}
// Cross Sections
double Simulation::sigmaTot_m2(double Ekin_eV) {
return(sigmaEla_m2(Ekin_eV));
}
double Simulation::sigmaEla_m2(double Ekin_eV) {
// From Plante and S Uehara et al 1998
double Z, tau, beta, etac, eta, nenner, zaehler;
Z = 1.;
tau = Ekin_eV/me_eV;
beta = v_ms(Ekin_eV)/c_ms;
etac = (Ekin_eV < 50e3)? 1.198 : 1.13+3.76*pow(Z/(137*beta),2); //beta im nenner oder zähler?
eta = etac * 1.7e-5 * pow(Z,2./3.) /( tau*(tau+2) );
nenner = pi*Z*(Z+1)*re_m*re_m * (1-pow(beta,2));
zaehler = eta * (eta+1)*pow(beta,4);
return(nenner/zaehler);
}
double Simulation::dSigmaEladOmega_m2 (double Ekin_eV, double Theta_rad, double Phi_rad) {
// From Plante and S Uehara et al 1998
double Z, tau, beta, etac, eta, nenner, zaehler;
Z = 1.;
tau = Ekin_eV/me_eV;
beta = v_ms(Ekin_eV)/c_ms;
etac = (Ekin_eV < 50e3)? 1.198 : 1.13+3.76*pow(Z/(137*beta),2); //beta im nenner oder zähler?
eta = etac * 1.7e-5 * pow(Z,2./3.) /( tau*(tau+2) );
nenner = Z*(Z+1)*re_m*re_m * (1-pow(beta,2));
zaehler = pow(1.-cos(Theta_rad)+2*eta,2) * pow(beta,4);
return(nenner/zaehler);
int Simulation::getInteraction(Particle inputParticle) {
return(0);
}
+18 -30
View File
@@ -11,9 +11,12 @@
#include <stdio.h>
#include <math.h>
#include <vector>
#include <deque>
#include <iostream>
#include <fstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include "blitz/array.h"
#include "blitz/tinyvec2.h"
#include <random/uniform.h>
@@ -23,6 +26,7 @@
#include "particle.h"
class Simulation: public Parameter
{
public:
@@ -30,51 +34,35 @@ public:
Simulation() {
numInjectedParticles = 0;
rngUni.seed(seed);
particleLogger.clear();
outputName = "TestRun";
// Check OutFile already existing? -no-> Create Outfile_1
// -yes-> Create Outfile_i+1
initLogger();
};
void init(void);
void initLogger(void);
void doit(void);
protected:
// Simulation Objects
// Simulation
Katrin Kat;
ranlib::Uniform<double> rngUni;
int numInjectedParticles;
std::vector<Particle> particleQueue, newParticles;
std::vector<Particle>::iterator particleQueueIt;
std::deque<Particle> particleQue;
// Logging Objects
int step;
std::string outputName;
std::vector<std::string> particleLogger;
std::vector<Particle>::iterator particleLoggerIt;
std::ofstream outFile;
// Simulation Methods
Particle inject();
blitz::TinyVector<double,3> move(Particle inputParticle,double distance_m);
bool move(Particle *inputParticle);
bool movedOutside(blitz::TinyVector<double,3> loc_m);
blitz::TinyVector<double,3> moveToLocOfDeath(Particle inputParticle);
int getInteraction(Particle inPutParticle);
// Logging Methods
void writeToLogger(Particle inputParticle);
void writeToFile(std::vector<Particle> *particleLogger);
// Cross Sections
double sigmaTot_m2(double Ekin_eV);
double sigmaEla_m2(double Ekin_eV);
double dSigmaEladOmega_m2 (double Ekin_eV, double Theta_rad, double Phi_rad);
// Logging
std::vector<std::ofstream> outStream;
std::vector<double> zLogValues;
void logParticle(Particle *inputParticle,blitz::TinyVector<double,3> oldLoc_m);
std::string getTimeString();
};
#endif