Changes to Interaction Processor, making possible to add infinite Interactions for all kind of Particles
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
//
|
||||
// bedionization.cpp
|
||||
// BED_eT2_ionization.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 22.02.19.
|
||||
// Created by Christian Reiling on 29.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#include "bedionization.hpp"
|
||||
#include "BED_eT2_ionization.hpp"
|
||||
|
||||
#include "functions.hpp"
|
||||
#include "constants.hpp"
|
||||
@@ -16,7 +15,8 @@
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
namespace BED_Ionization {
|
||||
|
||||
namespace BED_eT2_Ionization {
|
||||
double get_TCS(double T_eV) {
|
||||
if (T_eV<=0) {
|
||||
stringstream ss;
|
||||
@@ -34,7 +34,7 @@ namespace BED_Ionization {
|
||||
return(fac*(sum1 + sum2) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double get_SDCS (double T_eV, double W_eV) {
|
||||
if (T_eV<0) {
|
||||
stringstream ss;
|
||||
@@ -58,15 +58,15 @@ namespace BED_Ionization {
|
||||
return(fac*(sum1 + sum2 + sum3));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline double get_t(double T_eV) {
|
||||
return(T_eV/B_eV);
|
||||
}
|
||||
|
||||
|
||||
inline double get_w(double W_eV) {
|
||||
return(W_eV/B_eV);
|
||||
}
|
||||
|
||||
|
||||
inline double get_dfdw(double w) {
|
||||
double y = 1/(w+1);
|
||||
double res = 0;
|
||||
@@ -75,7 +75,7 @@ namespace BED_Ionization {
|
||||
}
|
||||
return(res);
|
||||
}
|
||||
|
||||
|
||||
inline double get_Dt(double t) {
|
||||
double yh = 2/(t+1);
|
||||
double res = 0;
|
||||
@@ -1,18 +1,18 @@
|
||||
//
|
||||
// bedionization.hpp
|
||||
// BED_eT2_ionization.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 22.02.19.
|
||||
// Created by Christian Reiling on 29.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef bedionization_hpp
|
||||
#define bedionization_hpp
|
||||
#ifndef BED_eT2_ionization_hpp
|
||||
#define BED_eT2_ionization_hpp
|
||||
|
||||
#include "constants.hpp"
|
||||
|
||||
// BED Ionization model from Kim, Y.-K. and Rudd, M. E. 1994
|
||||
namespace BED_Ionization {
|
||||
namespace BED_eT2_Ionization {
|
||||
const double S_m2 = 5.4721e-20;
|
||||
const double B_eV = EionT2_eV;
|
||||
const double u = 1.664;
|
||||
@@ -22,7 +22,7 @@ namespace BED_Ionization {
|
||||
|
||||
double get_TCS(double T_eV);
|
||||
double get_SDCS(double T_eV, double W_eV);
|
||||
|
||||
|
||||
double get_t(double T);
|
||||
double get_w(double W);
|
||||
|
||||
@@ -30,6 +30,4 @@ namespace BED_Ionization {
|
||||
double get_Dt(double t);
|
||||
}
|
||||
|
||||
#endif /* bedionization_hpp */
|
||||
|
||||
|
||||
#endif /* BED_eT2_ionization_hpp */
|
||||
@@ -203,7 +203,7 @@ namespace container_base {
|
||||
}
|
||||
|
||||
|
||||
inline void set_Itr(dim1Map &Map, deque<double> Cord, dim1Map::iterator &Itr) {
|
||||
inline void set_Itr(dim1Map Map, deque<double> Cord, dim1Map::iterator &Itr) {
|
||||
if (Cord.size()!=1) {
|
||||
stringstream ss;
|
||||
ss<<"set_Itr: Length of Cord and &Map do not map.";
|
||||
@@ -219,7 +219,7 @@ namespace container_base {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void set_Itr(T &Map, deque<double> Cord, dim1Map::iterator &Itr) {
|
||||
inline void set_Itr(T Map, deque<double> Cord, dim1Map::iterator &Itr) {
|
||||
double x = *Cord.begin();
|
||||
Cord.pop_front();
|
||||
if (x>Map.rbegin()->first) {
|
||||
|
||||
@@ -40,7 +40,7 @@ void WGTS_Geo::init_bin_maps() {
|
||||
|
||||
}
|
||||
|
||||
double WGTS_Geo::get_Bin_l_m (double z_m) {
|
||||
double WGTS_Geo::get_Bin_l_m (double z_m) const {
|
||||
if (check_z_outside(z_m)) {
|
||||
stringstream ss;
|
||||
ss<<"WGTS_Geo_Container::get_Bin_l_m: z_m not in Container.";
|
||||
@@ -49,7 +49,7 @@ double WGTS_Geo::get_Bin_l_m (double z_m) {
|
||||
return (bin_l_m.lower_bound(z_m)->second);
|
||||
}
|
||||
|
||||
double WGTS_Geo::get_Bin_V_m3(double r_m) {
|
||||
double WGTS_Geo::get_Bin_V_m3(double r_m) const {
|
||||
if (check_r_outside(r_m)) {
|
||||
stringstream ss;
|
||||
ss<<"WGTS_Geo_Container::get_Bin_V_m3: r_m not in Container.";
|
||||
@@ -58,11 +58,11 @@ double WGTS_Geo::get_Bin_V_m3(double r_m) {
|
||||
return (bin_V_m3.lower_bound(r_m)->second);
|
||||
}
|
||||
|
||||
bool WGTS_Geo::outside_Container(vec3 Cords, cordStyle cordStyleIn) {
|
||||
bool WGTS_Geo::outside_Container(vec3 Cords, cordStyle cordStyleIn) const {
|
||||
Cords = zrphiCords(Cords, cordStyleIn);
|
||||
return (check_z_outside (Cords[0]) || check_r_outside(Cords[1]));
|
||||
}
|
||||
bool WGTS_Geo::check_z_outside (double z_m) {
|
||||
bool WGTS_Geo::check_z_outside (double z_m) const {
|
||||
if (z_m<z_min_m) {
|
||||
return (true);
|
||||
}
|
||||
@@ -71,13 +71,13 @@ bool WGTS_Geo::check_z_outside (double z_m) {
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
bool WGTS_Geo::check_r_outside (double r_m) {
|
||||
bool WGTS_Geo::check_r_outside (double r_m) const {
|
||||
if (r_m>r_max_m) {
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
vec3 WGTS_Geo::zrphiCords(vec3 Cords, cordStyle cordStyleIn) {
|
||||
vec3 WGTS_Geo::zrphiCords(vec3 Cords, cordStyle cordStyleIn) const {
|
||||
if (cordStyleIn == zrphi) {
|
||||
return (Cords);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ void WGTS3D_ParticleTime_s_Container::init_Map() {
|
||||
}
|
||||
}
|
||||
|
||||
double WGTS3D_ParticleTime_s_Container::getDensity(vec3 loc_m, double simTime_s, cordStyle cordStyleIn) {
|
||||
double WGTS3D_ParticleTime_s_Container::getDensity(vec3 loc_m, double simTime_s, cordStyle cordStyleIn) const {
|
||||
if (outside_Container(loc_m, cordStyleIn)) {
|
||||
stringstream ss;
|
||||
ss<<"WGTS3D_ParticleTime_s_Container::getDensity: loc_old or loc_new not in Container.";
|
||||
|
||||
@@ -31,9 +31,9 @@ public:
|
||||
void fillFromCSV(std::string loadFilePath){container_base::add_From_Csv(&Map, 3, loadFilePath);};
|
||||
void add_ankerpoint(double x, double y, double z, double fxyz){container_base::add_To_Map(&Map, deque<double> {x,y,z,fxyz});};
|
||||
|
||||
void exportToFile(std::string exportFilePath){container_base::export_To_Csv(Map, exportFilePath);};
|
||||
void exportToFile(std::string exportFilePath) const {container_base::export_To_Csv(Map, exportFilePath);};
|
||||
|
||||
dim3Map get_Map() {return (Map);}
|
||||
dim3Map get_Map() const {return (Map);}
|
||||
protected:
|
||||
dim3Map Map;
|
||||
};
|
||||
@@ -46,13 +46,13 @@ public:
|
||||
protected:
|
||||
void init_bin_maps();
|
||||
|
||||
double get_Bin_l_m (double z_m);
|
||||
double get_Bin_V_m3(double r_m);
|
||||
double get_Bin_l_m (double z_m) const ;
|
||||
double get_Bin_V_m3(double r_m) const;
|
||||
|
||||
bool outside_Container(vec3 Cords, cordStyle cordStyleIn = xyz);
|
||||
bool check_z_outside (double z_m);
|
||||
bool check_r_outside (double r_m);
|
||||
vec3 zrphiCords(vec3 Cords, cordStyle cordStyleIn = xyz);
|
||||
bool outside_Container(vec3 Cords, cordStyle cordStyleIn = xyz) const;
|
||||
bool check_z_outside (double z_m) const;
|
||||
bool check_r_outside (double r_m) const;
|
||||
vec3 zrphiCords(vec3 Cords, cordStyle cordStyleIn = xyz) const;
|
||||
|
||||
double z_min_m;
|
||||
double z_max_m;
|
||||
@@ -73,12 +73,12 @@ protected:
|
||||
using Base3D_FuncContainer::fillFromCSV;
|
||||
|
||||
public:
|
||||
double getDensity(vec3 loc_m, double simTime_s, cordStyle cordStyleIn = xyz);
|
||||
double getDensity(vec3 loc_m, double simTime_s, cordStyle cordStyleIn = xyz) const;
|
||||
void upDensity(double vAbs_ms, vec3 loc_old, vec3 loc_new, cordStyle cordStyleIn = xyz) {up_DriftApprox_Density(vAbs_ms, loc_old, loc_new, cordStyleIn);};
|
||||
|
||||
protected:
|
||||
void up_DriftApprox_Density(double vAbs_ms, vec3 loc_old, vec3 loc_new, cordStyle cordStyleIn = xyz);
|
||||
dim1Map::iterator findBin(vec3 zrPhiCords) {return (container_base::get_Itr(Map,deque<double> {zrPhiCords[0],zrPhiCords[1],zrPhiCords[2]}));};
|
||||
dim1Map::iterator findBin(vec3 zrPhiCords) const {return (container_base::get_Itr(Map,deque<double> {zrPhiCords[0],zrPhiCords[1],zrPhiCords[2]}));};
|
||||
};
|
||||
// Add option to load default from file...
|
||||
//Part3D_WGTS_Container(std::string loadFilePath, double z_min_m, double z_max_m, double r_max_m, vec3 zrphi_numBins);
|
||||
|
||||
@@ -1,229 +0,0 @@
|
||||
//
|
||||
// electron.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 15.01.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "electron.hpp"
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int Electron::ionOn = getParameter("ionOn");
|
||||
const int Electron::elaOn = getParameter("elaOn");
|
||||
|
||||
|
||||
|
||||
Average1D_FuncContainer Electron::BED_TCS_average_container=Average1D_FuncContainer(getHomebase() + "data/BED_average_TCS.dat");
|
||||
Stacked2D_FuncContainer Electron::BED_SDCS_stacked_container=Stacked2D_FuncContainer(getHomebase() + "data/BED_stacked_SDCS.dat");
|
||||
|
||||
|
||||
|
||||
double Electron::get_SigmaTotal_m2(vec3 speedT2_ms) {
|
||||
vector<double> Sigmas = get_SigmaVector_m2(speedT2_ms);
|
||||
double sigmaTot_m2 = 0;
|
||||
for (vector<double>::iterator SigmasIt = Sigmas.begin() ; SigmasIt != Sigmas.end(); SigmasIt++) {
|
||||
sigmaTot_m2 += *SigmasIt;
|
||||
}
|
||||
return(sigmaTot_m2);
|
||||
}
|
||||
|
||||
vector<double> Electron::get_SigmaVector_m2(vec3 speedT2_ms) {
|
||||
vector<double> Sigmas;
|
||||
if (elaOn == 1) {
|
||||
Sigmas.push_back(get_elaSigma_m2(speedT2_ms));
|
||||
} else {
|
||||
Sigmas.push_back(0.);
|
||||
}
|
||||
|
||||
if (ionOn == 1) {
|
||||
Sigmas.push_back(get_ionSigma_m2(speedT2_ms));
|
||||
} else {
|
||||
Sigmas.push_back(0.);
|
||||
}
|
||||
return(Sigmas);
|
||||
}
|
||||
|
||||
int Electron::roll_Interaction(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni) {
|
||||
vector<double> Sigmas = get_SigmaVector_m2(speedT2_ms);
|
||||
double RandPoint = rngUni->random() * get_SigmaTotal_m2(speedT2_ms);
|
||||
double Sum = 0;
|
||||
|
||||
for (int i=0; i<Sigmas.size();i++ ) {
|
||||
Sum += Sigmas[i];
|
||||
if (RandPoint<Sum) {
|
||||
return(i+1);
|
||||
}
|
||||
}
|
||||
throw MyException("Electron::roll_Interaction(): Error in finding Interaction.");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Elastic Scattering:
|
||||
Using Rutherford Model with screening parameter following
|
||||
Cross-sections for water vapour for the Monte Carlo electron track structure code from 10eV to the MeV region
|
||||
S Uehara et al 1993 Phys. Med. Biol. 38 1841
|
||||
*/
|
||||
|
||||
void Electron::do_elaScattering (vec3 speedT2_ms, ranlib::Uniform<double> *rngUni) {
|
||||
// Here theta and phi are COM-Angles.... prob not correct. For m1 << m2 COM - Angle ~ Lab Angle
|
||||
double thetaLab = roll_elaTheta(speedT2_ms, rngUni);
|
||||
double phiLab = rngUni->random() * 2 * pi;
|
||||
do_elaKinetics(speedT2_ms,thetaLab, phiLab);
|
||||
}
|
||||
|
||||
|
||||
double Electron::get_elaSigma_m2(vec3 speedT2_ms) {
|
||||
double SigmaEla_m2;
|
||||
vec3 speedLab_ms = v_ms - speedT2_ms;
|
||||
double betaLab = get_vecAbs(speedLab_ms)/c_ms;
|
||||
//double EkinLab_eV = get_Ekin_eV_from_speed(speedLab_ms, m_eV);
|
||||
double elaEta = get_elaEta(speedLab_ms);
|
||||
double numerator = pi*ZT2*(ZT2+1)*re_m*re_m * (1-pow(betaLab,2));
|
||||
double denominator = elaEta * (elaEta+1)*pow(betaLab,4);
|
||||
SigmaEla_m2 = numerator/denominator;
|
||||
return ( SigmaEla_m2 );
|
||||
}
|
||||
|
||||
|
||||
double Electron::get_elaEta(vec3 speedLab_ms) {
|
||||
double Ekin_eVLab_eV = get_Ekin_eV_from_speed(get_vecAbs(speedLab_ms), m_eV);
|
||||
double betaLab = get_vecAbs(speedLab_ms)/c_ms;
|
||||
double etac = (Ekin_eVLab_eV < 50e3)? 1.198 : 1.13+3.76*pow(ZT2/(137*betaLab),2);
|
||||
double elaTau = Ekin_eVLab_eV/m_eV;
|
||||
return (etac * 1.7e-5 * pow(ZT2,2./3.) /(elaTau*(elaTau+2) ));
|
||||
}
|
||||
|
||||
double Electron::roll_elaTheta(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni) {
|
||||
vec3 speedLab_ms = v_ms - speedT2_ms;
|
||||
double betaLab = get_vecAbs(speedLab_ms)/c_ms;
|
||||
double elaEta = get_elaEta(speedLab_ms);
|
||||
double const1 = 2*pi/get_elaSigma_m2(speedT2_ms)*ZT2*(ZT2+1)*re_m*re_m*(1- pow(betaLab,2) )* pow(betaLab,-4);
|
||||
double fac = pow( rngUni->random()/const1-pow(2*elaEta,-1) , -1 ) +1+2*elaEta;
|
||||
double theta = acos( fac);
|
||||
|
||||
return(theta);
|
||||
}
|
||||
|
||||
|
||||
void Electron::do_elaKinetics(vec3 speedT2_ms, double thetaLab, double phiLab) {
|
||||
// Following Landau Lifschitz I Chapter 4 Paragraph 17
|
||||
vec3 n0, speedLab_ms, v1New_ms, v2New_ms;
|
||||
speedLab_ms = v_ms - speedT2_ms;
|
||||
n0 = get_Newdirection(speedLab_ms, thetaLab, phiLab);
|
||||
v1New_ms = (mT2_eV*get_vecAbs(speedLab_ms)*n0 + m_eV*speedLab_ms)/(m_eV+mT2_eV) + speedT2_ms;
|
||||
//v2New_ms = (-1*mass_eV*get_vecAbs(speedLab_ms)*n0 + mass_eV*speedLab_ms)/(mass_eV+mT2_eV()) + speedT2_ms;
|
||||
v_ms = v1New_ms; // In "Real frame": both particles moving
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
Ionization:
|
||||
Using BED-Model Kim and Rudd 1994
|
||||
*/
|
||||
|
||||
double Electron::get_ionSigma_m2(vec3 speedT2_ms) {
|
||||
vec3 speedLab_ms = v_ms - speedT2_ms;
|
||||
double T_eV = get_Ekin_eV_from_speed(get_vecAbs(speedLab_ms), m_eV);
|
||||
//return (ionTCS_container.interpolate(T_eV));
|
||||
//return (BED_Ionization::get_TCS(T_eV));
|
||||
return (BED_TCS_average_container.get_Value(T_eV));
|
||||
}
|
||||
|
||||
Electron Electron::do_Ionization(vec3 speedT2_ms, int newId, ranlib::Uniform<double> *rngUni) {
|
||||
vec3 speedOffset_ms = speedT2_ms;
|
||||
vec3 speedLab_ms = v_ms - speedOffset_ms;
|
||||
double T_eV = get_Ekin_eV_from_speed(get_vecAbs(speedLab_ms), m_eV);
|
||||
|
||||
if (T_eV < EionT2_eV) { // Deviation, since Interaction-Process sample using v=0, but Interaction uses v!=0
|
||||
speedOffset_ms = 0;
|
||||
speedLab_ms = v_ms - speedOffset_ms;
|
||||
T_eV = get_Ekin_eV_from_speed(get_SpeedAbs_ms(), m_eV);
|
||||
}
|
||||
|
||||
if (T_eV < EionT2_eV) {
|
||||
throw MyException("Electron::do_Ionization: Ekin_eV < EIonT2_eV.");
|
||||
}
|
||||
|
||||
//double W_eV = roll_ionW_eV(T_eV, rngUni);
|
||||
double W_eV = BED_SDCS_stacked_container.sample_Value(T_eV, rngUni);
|
||||
double E1_eV = T_eV-EionT2_eV - W_eV;
|
||||
|
||||
double phi1 = rngUni->random()*2*pi;
|
||||
double phi2 = phi1-pi;
|
||||
|
||||
double theta1 = roll_IonTheta1(T_eV, W_eV, rngUni);
|
||||
double theta2 = roll_IonTheta2(T_eV, W_eV, rngUni);
|
||||
|
||||
double v1Absnew_ms = get_Speed_from_Ekin_eV(E1_eV, m_eV);
|
||||
double v2Absnew_ms = get_Speed_from_Ekin_eV(W_eV, m_eV);
|
||||
|
||||
vec3 P1newDir, P2newDir, v1New_ms, v2New_ms ;
|
||||
P1newDir = get_Newdirection(v_ms, theta1, phi1);
|
||||
P2newDir = get_Newdirection(v_ms, theta2, phi2);
|
||||
|
||||
v1New_ms = v1Absnew_ms*P1newDir + speedOffset_ms;
|
||||
v2New_ms = v2Absnew_ms*P2newDir + speedOffset_ms;
|
||||
|
||||
set_Speed_ms(v1New_ms);
|
||||
Electron eNew = Electron(x_m, v2New_ms, newId, get_Id());
|
||||
|
||||
// Update Ion matrix here
|
||||
return(eNew);
|
||||
}
|
||||
|
||||
|
||||
double Electron::roll_ionW_eV(double T_eV, ranlib::Uniform<double> *rngUni) {
|
||||
double pmax, Wmin_eV, Wmax_eV, Wcan_eV,eta1,eta2;
|
||||
|
||||
//pmax = ionTCS_container.interpolate(T_eV);
|
||||
pmax = BED_Ionization::get_TCS(T_eV);
|
||||
Wmin_eV = 0;
|
||||
Wmax_eV = T_eV-EionT2_eV;
|
||||
do {
|
||||
eta1 = rngUni->random();
|
||||
eta2 = rngUni->random();
|
||||
Wcan_eV = Wmin_eV + eta1*(Wmax_eV - Wmin_eV);
|
||||
} while(eta2*pmax > BED_Ionization::get_SDCS(T_eV, Wcan_eV));
|
||||
//} while(eta2*pmax > ionSDCS_container.interpolate(T_eV, Wcan_eV));
|
||||
double W_eV = (Wcan_eV< (T_eV-EionT2_eV)/2 ) ? Wcan_eV : (T_eV-EionT2_eV) - Wcan_eV;
|
||||
return(W_eV);
|
||||
}
|
||||
|
||||
double Electron::roll_IonTheta1(double T_eV, double W_eV, ranlib::Uniform<double> *rngUni) {
|
||||
double theta1;
|
||||
if (W_eV > 100) {
|
||||
double numerator = W_eV/T_eV;
|
||||
double denominator = (1-W_eV / T_eV)*(T_eV/(2*m_eV)) + 1;
|
||||
theta1 = asin(sqrt(numerator/denominator));
|
||||
} else {
|
||||
theta1 = rngUni->random()*pi/4;
|
||||
}
|
||||
return (theta1);
|
||||
}
|
||||
|
||||
double Electron::roll_IonTheta2(double T_eV, double W_eV, ranlib::Uniform<double> *rngUni) {
|
||||
double theta2;
|
||||
if (W_eV > 200) {
|
||||
double numerator = 1- W_eV/T_eV;
|
||||
double denominator = 1 + W_eV/(2*m_eV);
|
||||
theta2 = asin(sqrt(numerator/denominator));
|
||||
} else if (W_eV >= 50) {
|
||||
double decider = rngUni->random();
|
||||
if (decider < 0.9) {
|
||||
theta2 = 1 + rngUni->random() * pi/4 + pi/4;
|
||||
} else {
|
||||
theta2 = rngUni->random() * pi;
|
||||
}
|
||||
} else {
|
||||
theta2 = rngUni->random() * pi;
|
||||
}
|
||||
return(theta2);
|
||||
}
|
||||
|
||||
|
||||
//Edge1D_Container Electron::ionTCS_container= Edge1D_Container("/Users/ChristianReiling/Documents/Masterarbeit/katrin-plasma/src/mc_electron/data/BED_ionization_TCS.dat");
|
||||
//Edge2D_Container Electron::ionSDCS_container= Edge2D_Container("/Users/ChristianReiling/Documents/Masterarbeit/katrin-plasma/src/mc_electron/data/BED_ionization_SDCS.dat");
|
||||
@@ -1,83 +0,0 @@
|
||||
//
|
||||
// electron.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 15.01.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef electron_hpp
|
||||
#define electron_hpp
|
||||
|
||||
#include "particle.hpp"
|
||||
#include "bedionization.hpp"
|
||||
#include "function_container.hpp"
|
||||
//#include "katrin.hpp"
|
||||
|
||||
class Electron : public Particle {
|
||||
public:
|
||||
Electron(vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum) : Particle(me_eV, -1 , loc_m, speed_ms, idnum, parentIdnum, electron) {};
|
||||
|
||||
// Interactions
|
||||
public:
|
||||
double get_SigmaTotal_m2(vec3 speedT2_ms);
|
||||
std::vector<double> get_SigmaVector_m2(vec3 speedT2_ms);
|
||||
int roll_Interaction(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
private:
|
||||
static const int ionOn;
|
||||
static const int elaOn;
|
||||
|
||||
// Elastic Scattering
|
||||
public:
|
||||
void do_elaScattering (vec3 speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
double get_elaSigma_m2(vec3 speedT2_ms);
|
||||
protected:
|
||||
double get_elaEta(vec3 speedLab_ms);
|
||||
double roll_elaTheta(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
void do_elaKinetics(vec3 speedT2_ms, double theta, double phi);
|
||||
|
||||
// Ionization
|
||||
public:
|
||||
double get_ionSigma_m2(vec3 speedT2_ms);
|
||||
Electron do_Ionization(vec3 speedT2_ms, int newId, ranlib::Uniform<double> *rngUni);
|
||||
protected:
|
||||
double roll_ionW_eV(double T_eV, ranlib::Uniform<double> *rngUni);
|
||||
|
||||
double roll_IonTheta1(double T_eV, double W_eV, ranlib::Uniform<double> *rngUni);
|
||||
double roll_IonTheta2(double T_eV, double W_eV, ranlib::Uniform<double> *rngUni);
|
||||
|
||||
|
||||
// Testing Container
|
||||
//static Edge1D_Container ionTCS_container;
|
||||
//static Edge2D_Container ionSDCS_container;
|
||||
static Average1D_FuncContainer BED_TCS_average_container;
|
||||
static Stacked2D_FuncContainer BED_SDCS_stacked_container;
|
||||
};
|
||||
|
||||
/*
|
||||
typedef enum e_InterKind{e_T2_elastcis, e_T2_ion} e_InterKind;
|
||||
|
||||
class Inter_Output {
|
||||
public:
|
||||
Inter_Output();
|
||||
private:
|
||||
bool deleteCur;
|
||||
Electron *NewElectrons;
|
||||
|
||||
};
|
||||
|
||||
class Electron_Interactions {
|
||||
public:
|
||||
Electron_Interactions();
|
||||
e_InterKind roll_Interaction();
|
||||
Inter_Output do_Interaction(e_InterKind InterKind);
|
||||
|
||||
|
||||
private:
|
||||
Katrin *Kat;
|
||||
};
|
||||
*/
|
||||
|
||||
#endif /* electron_hpp */
|
||||
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
//
|
||||
// electron_interactions.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "electron_interactions.hpp"
|
||||
|
||||
|
||||
double e_T2_elasticScattering::get_macroSigma_m2(const Particle &interPart) const {
|
||||
vec3 v_ms = interPart.get_Speed_ms();
|
||||
double microSigma_m2 = get_elaSigma_m2(v_ms);
|
||||
vec3 loc_m = interPart.get_Location_m();
|
||||
double nT2_m3 = Kat->getTritiumDensity_m3(loc_m);
|
||||
return (microSigma_m2*nT2_m3);
|
||||
}
|
||||
|
||||
InteractionOut e_T2_elasticScattering::do_Interaction (Particle *interPart) const {
|
||||
// Here theta and phi are COM-Angles.... prob not correct. For m1 << m2 COM - Angle ~ Lab Angle
|
||||
vec3 v_ms = interPart->get_Speed_ms();
|
||||
vec3 vT2_ms = Kat->roll_totEqSpeed_ms(interPart->get_Location_m());
|
||||
vec3 vLab_ms = v_ms - vT2_ms;
|
||||
double thetaLab = roll_elaTheta(vLab_ms);
|
||||
double phiLab = rngUni->random() * 2 * pi;
|
||||
interPart->set_Speed_ms( get_vNew_ms(v_ms, vT2_ms, thetaLab, phiLab) );
|
||||
return (InteractionOut());
|
||||
}
|
||||
|
||||
double e_T2_elasticScattering::get_elaSigma_m2(vec3 vLab_ms) const {
|
||||
double betaLab = get_vecAbs(vLab_ms)/c_ms;
|
||||
double elaEta = get_elaEta(vLab_ms);
|
||||
double numerator = pi*ZT2*(ZT2+1)*re_m*re_m * (1-pow(betaLab,2));
|
||||
double denominator = elaEta * (elaEta+1)*pow(betaLab,4);
|
||||
return (numerator/denominator);
|
||||
}
|
||||
|
||||
double e_T2_elasticScattering::get_elaEta(vec3 vLab_ms) const {
|
||||
double Ekin_eVLab_eV = get_Ekin_eV_from_speed(vLab_ms, me_eV);
|
||||
double betaLab = get_vecAbs(vLab_ms)/c_ms;
|
||||
double etac = (Ekin_eVLab_eV < 50e3)? 1.198 : 1.13+3.76*pow(ZT2/(137*betaLab),2);
|
||||
double elaTau = Ekin_eVLab_eV/me_eV;
|
||||
return (etac * 1.7e-5 * pow(ZT2,2./3.) /(elaTau*(elaTau+2) ));
|
||||
}
|
||||
|
||||
double e_T2_elasticScattering::roll_elaTheta(vec3 vLab_ms) const {
|
||||
double betaLab = get_vecAbs(vLab_ms)/c_ms;
|
||||
double elaEta = get_elaEta(vLab_ms);
|
||||
double const1 = 2*pi/get_elaSigma_m2(vLab_ms)*ZT2*(ZT2+1)*re_m*re_m*(1- pow(betaLab,2) )* pow(betaLab,-4);
|
||||
double fac = pow( rngUni->random()/const1-pow(2*elaEta,-1) , -1 ) +1+2*elaEta;
|
||||
double theta = acos(fac);
|
||||
return(theta);
|
||||
}
|
||||
|
||||
vec3 e_T2_elasticScattering::get_vNew_ms(vec3 vOld_ms, vec3 vT2_ms, double thetaLab, double phiLab) const {
|
||||
// Following Landau Lifschitz I Chapter 4 Paragraph 17
|
||||
vec3 speedLab_ms = vOld_ms - vT2_ms;
|
||||
vec3 n0 = get_Newdirection(speedLab_ms, thetaLab, phiLab);
|
||||
vec3 vNew_ms = (mT2_eV*get_vecAbs(speedLab_ms)*n0 + me_eV*speedLab_ms)/(me_eV+mT2_eV) + vT2_ms;
|
||||
//vec3 v2New_ms = (-1*mass_eV*get_vecAbs(speedLab_ms)*n0 + mass_eV*speedLab_ms)/(mass_eV+mT2_eV()) + speedT2_ms;
|
||||
return (vNew_ms);
|
||||
}
|
||||
|
||||
|
||||
Average1D_FuncContainer e_T2_ionization::BED_TCS_average_container=Average1D_FuncContainer(getHomebase() + "data/BED_average_TCS.dat");
|
||||
Stacked2D_FuncContainer e_T2_ionization::BED_SDCS_stacked_container=Stacked2D_FuncContainer(getHomebase() + "data/BED_stacked_SDCS.dat");
|
||||
|
||||
|
||||
double e_T2_ionization::get_macroSigma_m2(const Particle &interPart) const {
|
||||
double T_eV = interPart.get_EKin_eV();
|
||||
double microSigma_m2 = BED_TCS_average_container.get_Value(T_eV);
|
||||
vec3 loc_m = interPart.get_Location_m();
|
||||
double nT2_m3 = Kat->getTritiumDensity_m3(loc_m);
|
||||
return (microSigma_m2*nT2_m3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
InteractionOut e_T2_ionization::do_Interaction (Particle *interPart) const {
|
||||
vec3 vLab_ms = roll_vLab_ms(*interPart);
|
||||
vec3 v_ms = interPart->get_Speed_ms();
|
||||
|
||||
double T_eV = get_Ekin_eV_from_speed(v_ms, me_eV);
|
||||
if (T_eV < EionT2_eV) {
|
||||
throw MyException("Electron::do_Ionization: Ekin_eV < EIonT2_eV.");
|
||||
}
|
||||
double W_eV = roll_ionW_eV(T_eV);
|
||||
|
||||
double E1_eV = T_eV-EionT2_eV - W_eV;
|
||||
|
||||
double phi1 = rngUni->random()*2*pi;
|
||||
double phi2 = phi1-pi;
|
||||
|
||||
double theta1 = roll_IonTheta1(T_eV, W_eV);
|
||||
double theta2 = roll_IonTheta2(T_eV, W_eV);
|
||||
|
||||
double v1Absnew_ms = get_Speed_from_Ekin_eV(E1_eV, me_eV);
|
||||
double v2Absnew_ms = get_Speed_from_Ekin_eV(W_eV, me_eV);
|
||||
|
||||
vec3 P1newDir, P2newDir, v1New_ms, v2New_ms ;
|
||||
P1newDir = get_Newdirection(v_ms, theta1, phi1);
|
||||
P2newDir = get_Newdirection(v_ms, theta2, phi2);
|
||||
|
||||
vec3 vOff_ms = vLab_ms - v_ms;
|
||||
v1New_ms = v1Absnew_ms*P1newDir + vOff_ms;
|
||||
v2New_ms = v2Absnew_ms*P2newDir + vOff_ms;
|
||||
|
||||
interPart->set_Speed_ms(v1New_ms);
|
||||
Particle eNew = PartBuilder.createElectron(interPart->get_Location_m(), v2New_ms, -1, interPart->get_Id());
|
||||
InteractionOut InterOut;
|
||||
InterOut.add_newParticle(eNew);
|
||||
|
||||
return(InterOut);
|
||||
}
|
||||
|
||||
vec3 e_T2_ionization::roll_vLab_ms(const Particle &interPart) const {
|
||||
vec3 v_ms = interPart.get_Speed_ms();
|
||||
vec3 vT2_ms = Kat->roll_totEqSpeed_ms(interPart.get_Location_m());
|
||||
vec3 vOff_ms = vT2_ms;
|
||||
vec3 vLab_ms = v_ms - vOff_ms;
|
||||
double T_eV = get_Ekin_eV_from_speed(vLab_ms, me_eV);
|
||||
if (T_eV < EionT2_eV) { // Set Tritium Speed to 0 if unlucky roll
|
||||
T_eV = get_Ekin_eV_from_speed(v_ms, me_eV);
|
||||
}
|
||||
return (T_eV);
|
||||
}
|
||||
|
||||
double e_T2_ionization::roll_ionW_eV(double T_eV) const {
|
||||
return (BED_SDCS_stacked_container.sample_Value(T_eV, rngUni));
|
||||
/*
|
||||
double pmax, Wmin_eV, Wmax_eV, Wcan_eV,eta1,eta2;
|
||||
|
||||
//pmax = ionTCS_container.interpolate(T_eV);
|
||||
pmax = BED_eT2_Ionization::get_TCS(T_eV);
|
||||
Wmin_eV = 0;
|
||||
Wmax_eV = T_eV-EionT2_eV;
|
||||
do {
|
||||
eta1 = rngUni->random();
|
||||
eta2 = rngUni->random();
|
||||
Wcan_eV = Wmin_eV + eta1*(Wmax_eV - Wmin_eV);
|
||||
} while(eta2*pmax > BED_eT2_Ionization::get_SDCS(T_eV, Wcan_eV));
|
||||
//} while(eta2*pmax > ionSDCS_container.interpolate(T_eV, Wcan_eV));
|
||||
double W_eV = (Wcan_eV< (T_eV-EionT2_eV)/2 ) ? Wcan_eV : (T_eV-EionT2_eV) - Wcan_eV;
|
||||
return(W_eV);
|
||||
*/
|
||||
}
|
||||
|
||||
double e_T2_ionization::roll_IonTheta1(double T_eV, double W_eV) const {
|
||||
double theta1;
|
||||
if (W_eV > 100) {
|
||||
double numerator = W_eV/T_eV;
|
||||
double denominator = (1-W_eV / T_eV)*(T_eV/(2*me_eV)) + 1;
|
||||
theta1 = asin(sqrt(numerator/denominator));
|
||||
} else {
|
||||
theta1 = rngUni->random()*pi/4;
|
||||
}
|
||||
return (theta1);
|
||||
}
|
||||
|
||||
double e_T2_ionization::roll_IonTheta2(double T_eV, double W_eV) const {
|
||||
double theta2;
|
||||
if (W_eV > 200) {
|
||||
double numerator = 1- W_eV/T_eV;
|
||||
double denominator = 1 + W_eV/(2*me_eV);
|
||||
theta2 = asin(sqrt(numerator/denominator));
|
||||
} else if (W_eV >= 50) {
|
||||
double decider = rngUni->random();
|
||||
if (decider < 0.9) {
|
||||
theta2 = 1 + rngUni->random() * pi/4 + pi/4;
|
||||
} else {
|
||||
theta2 = rngUni->random() * pi;
|
||||
}
|
||||
} else {
|
||||
theta2 = rngUni->random() * pi;
|
||||
}
|
||||
return(theta2);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// electron_interactions.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef electron_interactions_hpp
|
||||
#define electron_interactions_hpp
|
||||
|
||||
#include "interaction_species.hpp"
|
||||
#include "function_container.hpp"
|
||||
|
||||
/*
|
||||
Elastic Scattering:
|
||||
Using Rutherford Model with screening parameter following
|
||||
Cross-sections for water vapour for the Monte Carlo electron track structure code from 10eV to the MeV region
|
||||
S Uehara et al 1993 Phys. Med. Biol. 38 1841
|
||||
*/
|
||||
class e_T2_elasticScattering : public Interaction {
|
||||
public:
|
||||
e_T2_elasticScattering(Katrin *Kat, UniRNG *rngUni, NormalRNG *rngNormal) : Interaction(Kat, rngUni, rngNormal) {};
|
||||
|
||||
species get_Species() const {return(electron);}
|
||||
|
||||
double get_macroSigma_m2(const Particle &interPart) const;
|
||||
InteractionOut do_Interaction (Particle *interPart) const;
|
||||
|
||||
private:
|
||||
double get_elaSigma_m2(vec3 vLab_ms) const;
|
||||
double get_elaEta(vec3 vLab_ms) const;
|
||||
double roll_elaTheta(vec3 vLab_ms) const;
|
||||
vec3 get_vNew_ms(vec3 vOld_ms, vec3 vT2_ms, double thetaLab, double phiLab) const;
|
||||
};
|
||||
|
||||
/*
|
||||
Ionization:
|
||||
Using BED-Model Kim and Rudd 1994
|
||||
*/
|
||||
class e_T2_ionization : public Interaction {
|
||||
static Average1D_FuncContainer BED_TCS_average_container;
|
||||
static Stacked2D_FuncContainer BED_SDCS_stacked_container;
|
||||
|
||||
ParticleBuilder PartBuilder;
|
||||
|
||||
public:
|
||||
e_T2_ionization(Katrin *Kat, UniRNG *rngUni, NormalRNG *rngNormal) : Interaction(Kat, rngUni, rngNormal) {};
|
||||
|
||||
|
||||
species get_Species() const {return(electron);}
|
||||
|
||||
double get_macroSigma_m2(const Particle &interPart) const;
|
||||
InteractionOut do_Interaction (Particle *interPart) const;
|
||||
private:
|
||||
vec3 roll_vLab_ms(const Particle &interPart) const;
|
||||
double roll_ionW_eV(double T_eV) const;
|
||||
double roll_IonTheta1(double T_eV, double W_eV) const;
|
||||
double roll_IonTheta2(double T_eV, double W_eV) const;
|
||||
};
|
||||
|
||||
|
||||
#endif /* electron_interactions_hpp */
|
||||
@@ -50,8 +50,8 @@ inline void Base_FuncContainer::stackedMap_from_averageMap (dim1Map *stackedMap,
|
||||
}
|
||||
}
|
||||
|
||||
inline double Base_FuncContainer::sampleValue_from_stackedMap (dim1Map *stackedMap, ranlib::Uniform<double> *rngUni) {
|
||||
return (stackedMap->lower_bound(rngUni->random())->second);
|
||||
inline double Base_FuncContainer::sampleValue_from_stackedMap (const dim1Map &stackedMap, ranlib::Uniform<double> *rngUni) const {
|
||||
return (stackedMap.lower_bound(rngUni->random())->second);
|
||||
}
|
||||
|
||||
// Base1D_Container
|
||||
@@ -180,10 +180,10 @@ void Stacked2D_FuncContainer::set_Map(Average2D_FuncContainer &averageContainer)
|
||||
set_Map(averageMap);
|
||||
}
|
||||
|
||||
double Stacked2D_FuncContainer::sample_Value(double x, ranlib::Uniform<double> *rngUni) {
|
||||
double Stacked2D_FuncContainer::sample_Value(double x, ranlib::Uniform<double> *rngUni) const {
|
||||
if (Map.rbegin()->first < x) {
|
||||
return (sampleValue_from_stackedMap (&Map.rbegin()->second, rngUni));
|
||||
return (sampleValue_from_stackedMap (Map.rbegin()->second, rngUni));
|
||||
} else {
|
||||
return (sampleValue_from_stackedMap (&Map.lower_bound(x)->second, rngUni));
|
||||
return (sampleValue_from_stackedMap (Map.lower_bound(x)->second, rngUni));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ typedef std::pair<double,double> dim1Pair;
|
||||
// Base_FuncContainer: Provide Operation on dim1Maps.
|
||||
class Base_FuncContainer {
|
||||
protected:
|
||||
double interpolateFrom_Map (dim1Map &Map, double x);
|
||||
double interpolateFrom_Map (dim1Map &Map, double x) const;
|
||||
void averageMap_from_edgeMap (dim1Map *averageMap, dim1Map &edgeMap);
|
||||
void stackedMap_from_averageMap (dim1Map *stackedMap, dim1Map &averageMap, double lowerEdge = 0);
|
||||
double sampleValue_from_stackedMap (dim1Map *stackedMap, ranlib::Uniform<double> *rngUni);
|
||||
double sampleValue_from_stackedMap (const dim1Map &stackedMap, ranlib::Uniform<double> *rngUni) const;
|
||||
};
|
||||
|
||||
// Base1D_Container: Provide Map and input output methods of the map.
|
||||
@@ -37,9 +37,9 @@ public:
|
||||
void fillFromCSV(std::string loadFilePath) {container_base::add_From_Csv (&Map, 1, loadFilePath);};
|
||||
void add_ankerpoint(double x, double fx) {container_base::add_To_Map(&Map, deque<double> {x,fx});};
|
||||
|
||||
void exportToFile(std::string exportFilePath) {container_base::export_To_Csv(Map, exportFilePath);};
|
||||
void exportToFile(std::string exportFilePath) const {container_base::export_To_Csv(Map, exportFilePath);};
|
||||
|
||||
dim1Map get_Map() {return (Map);}
|
||||
dim1Map get_Map() const {return (Map);}
|
||||
protected:
|
||||
dim1Map Map;
|
||||
} ;
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
Edge1D_FuncContainer() : Base1D_FuncContainer() {};
|
||||
Edge1D_FuncContainer(std::string loadFilePath) : Base1D_FuncContainer(loadFilePath){};
|
||||
|
||||
double interpolate(double x) {return (container_base::interpolate_Value(Map,deque<double>{x}));};
|
||||
double interpolate(double x) const {return (container_base::interpolate_Value(Map,deque<double>{x}));};
|
||||
};
|
||||
|
||||
// Average1D_Container: Calculates new edges, so values from edge bin correspond to mean value.
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
void set_Map(dim1Map &edgeMap);
|
||||
void set_Map(Edge1D_FuncContainer &edgeContainer);
|
||||
|
||||
double get_Value(double x){return ( container_base::get_Value(Map, deque<double> {x}) );};
|
||||
double get_Value(double x) const {return ( container_base::get_Value(Map, deque<double> {x}) );};
|
||||
};
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
|
||||
void exportToFile(std::string exportFilePath) {container_base::export_To_Csv(Map, exportFilePath);};
|
||||
|
||||
dim2Map get_Map() {return (Map);}
|
||||
dim2Map get_Map() const {return (Map);}
|
||||
protected:
|
||||
dim2Map Map;
|
||||
|
||||
@@ -99,7 +99,7 @@ public:
|
||||
Edge2D_FuncContainer() : Base2D_FuncContainer() {};
|
||||
Edge2D_FuncContainer(std::string loadFilePath) : Base2D_FuncContainer(loadFilePath) {};
|
||||
|
||||
double interpolate(double x, double y) {return (container_base::interpolate_Value(Map,deque<double>{x,y}));};
|
||||
double interpolate(double x, double y) const {return (container_base::interpolate_Value(Map,deque<double>{x,y}));};
|
||||
|
||||
void get_Ionization_fromFunction(double (*f)(double,double), double minX, double maxX, int numpointsPerXOrder, int numpointsPerYOrder);
|
||||
void get_Elastic_fromFunction(double (*f)(double,double), double minX, double maxX, int numpointsPerXOrder, int numpointsOverY);
|
||||
@@ -117,7 +117,7 @@ public:
|
||||
|
||||
void set_Map(dim2Map &edgeMap);
|
||||
void set_Map(Edge2D_FuncContainer &edgeContainer);
|
||||
double get_Value(double x, double y){return ( container_base::get_Value(Map, deque<double> {x,y}) );};
|
||||
double get_Value(double x, double y) const {return ( container_base::get_Value(Map, deque<double> {x,y}) );};
|
||||
};
|
||||
|
||||
// Stacked2D_Container:
|
||||
@@ -132,7 +132,7 @@ public:
|
||||
void set_Map(dim2Map &averageMap);
|
||||
void set_Map(Average2D_FuncContainer &averageContainer);
|
||||
|
||||
double sample_Value(double x, ranlib::Uniform<double> *rngUni);
|
||||
double sample_Value(double x, ranlib::Uniform<double> *rngUni) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -130,22 +130,26 @@ string getHomebase() {
|
||||
|
||||
|
||||
// Calculate Kinematic Relations
|
||||
double get_Ekin_eV_from_speed(double Speed_ms, double mass_eV) {
|
||||
double beta = Speed_ms/c_ms;
|
||||
double get_Ekin_eV_from_speed(const vec3 &speed_ms, const double &mass_eV) {
|
||||
return (get_Ekin_eV_from_speed(get_vecAbs(speed_ms), mass_eV));
|
||||
}
|
||||
|
||||
double get_Ekin_eV_from_speed(const double &speed_ms, const double &mass_eV) {
|
||||
double beta = speed_ms/c_ms;
|
||||
if (beta>=1) {
|
||||
stringstream ss;
|
||||
ss<<"get_Ekin_eV_from_speed(): Input speed v="<<Speed_ms<<" m/s equal or exeeds speed of light.";
|
||||
ss<<"get_Ekin_eV_from_speed(): Input speed v="<<speed_ms<<" m/s equal or exeeds speed of light.";
|
||||
throw MyException(ss.str());
|
||||
} else if (beta<0) {
|
||||
stringstream ss;
|
||||
ss<<"get_Ekin_eV_from_speed(): Input speed v="<<Speed_ms<<" m/s is expected to be absolute value therfore >0.";
|
||||
ss<<"get_Ekin_eV_from_speed(): Input speed v="<<speed_ms<<" m/s is expected to be absolute value therfore >0.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double gamma = get_gamma_from_beta(beta);
|
||||
return ( (gamma-1) * mass_eV );
|
||||
}
|
||||
|
||||
double get_gamma_from_beta(double beta) {
|
||||
double get_gamma_from_beta(const double &beta) {
|
||||
if (beta>=1) {
|
||||
stringstream ss;
|
||||
ss<<"get_gamma_from_beta(): Input beta ="<<beta<<" equal or exeeds 1.";
|
||||
@@ -159,7 +163,7 @@ double get_gamma_from_beta(double beta) {
|
||||
return( pow(1 - pow(beta,2),-0.5) ) ;
|
||||
}
|
||||
|
||||
double get_Speed_from_Ekin_eV(double Ekin_eV, double mass_eV) {
|
||||
double get_Speed_from_Ekin_eV(const double &Ekin_eV, const double &mass_eV) {
|
||||
if (Ekin_eV<0) {
|
||||
stringstream ss;
|
||||
ss<<"get_Speed_from_Ekin_eV(): Input Ekin_eV ="<<Ekin_eV<<" negative.";
|
||||
@@ -171,7 +175,7 @@ double get_Speed_from_Ekin_eV(double Ekin_eV, double mass_eV) {
|
||||
return(beta * c_ms);
|
||||
}
|
||||
|
||||
double get_gamma_from_Ekin_eV(double Ekin_eV, double mass_eV) {
|
||||
double get_gamma_from_Ekin_eV(const double &Ekin_eV, const double &mass_eV) {
|
||||
if (Ekin_eV<0) {
|
||||
stringstream ss;
|
||||
ss<<"get_gamma_from_Ekin_eV(): Input Ekin_eV ="<<Ekin_eV<<" negative.";
|
||||
@@ -180,7 +184,7 @@ double get_gamma_from_Ekin_eV(double Ekin_eV, double mass_eV) {
|
||||
return (1. + Ekin_eV/mass_eV);
|
||||
}
|
||||
|
||||
double get_beta_from_gamma(double gamma) {
|
||||
double get_beta_from_gamma(const double &gamma) {
|
||||
if (gamma<1) {
|
||||
stringstream ss;
|
||||
ss<<"get_beta_from_gamma(): Input gamma ="<<gamma<<" smaller 1.";
|
||||
@@ -191,11 +195,11 @@ double get_beta_from_gamma(double gamma) {
|
||||
|
||||
|
||||
// Operations on 3 dimensional Vectors
|
||||
double get_vecAbs(vec3 vec) {
|
||||
double get_vecAbs(const vec3 &vec) {
|
||||
return( sqrt( pow(vec[0],2) + pow(vec[1],2) + pow(vec[2],2)) );
|
||||
}
|
||||
|
||||
vec3 get_Newdirection(vec3 direction_old, double theta_change,double phi_change) {
|
||||
vec3 get_Newdirection(const vec3 &direction_old, const double &theta_change, const double &phi_change) {
|
||||
// Transformation of direction following Plante and Cucinotta
|
||||
double theta_old = acos(direction_old[2]/get_vecAbs(direction_old));
|
||||
double phi_old = atan2(direction_old[1],direction_old[0]);
|
||||
@@ -240,7 +244,7 @@ vec3 roll_uniform_direction(ranlib::Uniform<double> *rngUni) {
|
||||
return(dir);
|
||||
}
|
||||
|
||||
double roll_MBEnergy(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *rngNormal) {
|
||||
double roll_MBEnergy(const double &Temp_K, const double &mass_eV,ranlib::NormalUnit<double> *rngNormal) {
|
||||
|
||||
double C = kb_eVK*Temp_K/mass_eV;
|
||||
double beta = 0;
|
||||
|
||||
@@ -20,6 +20,20 @@
|
||||
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
|
||||
typedef ranlib::Uniform<double> UniRNG;
|
||||
typedef ranlib::NormalUnit<double> NormalRNG;
|
||||
|
||||
class RNG_Base {
|
||||
public:
|
||||
RNG_Base(UniRNG *rngUni, NormalRNG *rngNormal) {
|
||||
this->rngUni = rngUni;
|
||||
this->rngNormal = rngNormal;
|
||||
};
|
||||
protected:
|
||||
UniRNG *rngUni;
|
||||
NormalRNG *rngNormal;
|
||||
};
|
||||
|
||||
|
||||
// Custom Error Type
|
||||
struct MyException : public std::exception
|
||||
@@ -45,19 +59,20 @@ std::string getTimeString();
|
||||
std::string getHomebase();
|
||||
|
||||
// Calculate Kinematic Relations
|
||||
double get_Speed_from_Ekin_eV(double Ekin_eV, double mass_eV);
|
||||
double get_gamma_from_Ekin_eV(double Ekin_eV, double mass_eV);
|
||||
double get_beta_from_gamma(double gamma);
|
||||
double get_Ekin_eV_from_speed(double Speed, double mass_eV);
|
||||
double get_gamma_from_beta(double beta);
|
||||
double get_Speed_from_Ekin_eV(const double &Ekin_eV, const double &mass_eV);
|
||||
double get_gamma_from_Ekin_eV(const double &Ekin_eV, const double &mass_eV);
|
||||
double get_beta_from_gamma(const double &gamma);
|
||||
double get_Ekin_eV_from_speed(const vec3 &speed_ms, const double &mass_eV);
|
||||
double get_Ekin_eV_from_speed(const double &speed_ms, const double &mass_eV);
|
||||
double get_gamma_from_beta(const double &beta);
|
||||
|
||||
// Operations on 3 dimensional Vectors
|
||||
double get_vecAbs(vec3 vec);
|
||||
vec3 get_Newdirection(vec3 oldDir, double theta,double phi); // Calculates new Direction after Interaction with (theta, phi)
|
||||
double get_vecAbs(const vec3 &vec);
|
||||
vec3 get_Newdirection(const vec3 &oldDir, const double &theta, const double &phi); // Calculates new Direction after Interaction with (theta, phi)
|
||||
|
||||
// Functions for Random Sampling
|
||||
vec3 roll_uniform_direction(ranlib::Uniform<double> *rngUni);
|
||||
double roll_MBEnergy(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *rngNormal);
|
||||
double roll_MBEnergy(const double &Temp_K, const double &mass_eV,ranlib::NormalUnit<double> *rngNormal);
|
||||
double doRejectionMethod(double pdf(double), double xmin, double xmax, double pmax, ranlib::Uniform<double> *rngUni);
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// injector.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "injector.hpp"
|
||||
|
||||
const int Injector::injectionMethod = getParameter("injectionMethod");
|
||||
const double Injector::injectionEnergy_eV = getParameter("injectionEnergy_eV");
|
||||
|
||||
Particle Injector::injectElectron (const int &newId) {
|
||||
double r_m = Kat->get_radius_m()*sqrt(rngUni->random());
|
||||
double phi = rngUni->random()*2*pi;
|
||||
|
||||
double z_WGTSstart_m = Kat->get_z_WGTSstart_m();
|
||||
double z_WGTSend_m = Kat->get_z_WGTSend_m();
|
||||
double wgtsLength_m = z_WGTSend_m - z_WGTSstart_m;
|
||||
|
||||
double z_WGTS_start_to_half_pos_m = sqrt(rngUni->random())*wgtsLength_m/2;
|
||||
double z_m = (rngUni->random()<0.5) ? z_WGTS_start_to_half_pos_m : wgtsLength_m - z_WGTS_start_to_half_pos_m;
|
||||
z_m += z_WGTSstart_m;
|
||||
|
||||
vec3 loc_m = vec3 (r_m*cos(phi),r_m*sin(phi),z_m);
|
||||
double Ekin_eV;
|
||||
switch(injectionMethod) {
|
||||
case 0: // Fermi
|
||||
Ekin_eV = roll_FermiEnergy_eV();
|
||||
break;
|
||||
case 1: //Delta
|
||||
Ekin_eV = injectionEnergy_eV;
|
||||
break;
|
||||
case 2: //Maxwell Boltzman
|
||||
Ekin_eV = roll_MBEnergy(injectionEnergy_eV/kb_eVK,me_eV, rngNormal);
|
||||
break;
|
||||
default:
|
||||
throw MyException("Katrin::injectElectron: Invalid Injection Method.");
|
||||
break;
|
||||
}
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni) * get_Speed_from_Ekin_eV(Ekin_eV,me_eV);
|
||||
return ( PartFac.createElectron(loc_m, speed_ms,newId,newId) );
|
||||
}
|
||||
|
||||
double Injector::roll_FermiEnergy_eV() {
|
||||
// get Energy distribution using Rejection Method
|
||||
double pmax,Emin_eV, Emax_eV, Ecan_eV,eta1,eta2;
|
||||
pmax = 1.5e-28; // From Plotting EnergyDistributionBetaDecay
|
||||
Emin_eV = 1e-15;
|
||||
Emax_eV = TritiumDecayEndpoint_eV;
|
||||
do {
|
||||
eta1 = rngUni->random();
|
||||
eta2 = rngUni->random();
|
||||
Ecan_eV = Emin_eV + eta1*(Emax_eV - Emin_eV);
|
||||
} while(eta2*pmax > get_FermiDecaySpectrumDensity(Ecan_eV));
|
||||
return(Ecan_eV);
|
||||
}
|
||||
|
||||
double Injector::get_FermiDecaySpectrumDensity(const double &Ekin_eV) {
|
||||
if (Ekin_eV>TritiumDecayEndpoint_eV) {
|
||||
return (0.);
|
||||
} else{
|
||||
double p_eV = sqrt(Ekin_eV*Ekin_eV + 2 * Ekin_eV * me_eV);
|
||||
return( BetaDecayConst * get_FermiFunction(2, Ekin_eV) * p_eV*(Ekin_eV+me_eV)*pow(TritiumDecayEndpoint_eV-Ekin_eV,2) );
|
||||
}
|
||||
}
|
||||
|
||||
double Injector::get_FermiFunction(const double &Z, const double &Ekin_eV) {
|
||||
double gamma = 1+ Ekin_eV/me_eV;
|
||||
double beta = sqrt(1 - pow(gamma,-2));
|
||||
double eta =Z/beta/137.;
|
||||
return( 2*pi*eta/(1-exp(-2*pi*eta)) );
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// injector.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef injector_hpp
|
||||
#define injector_hpp
|
||||
|
||||
#include "functions.hpp"
|
||||
#include "katrin.hpp"
|
||||
#include "particle.hpp"
|
||||
|
||||
|
||||
class Injector : RNG_Base {
|
||||
public:
|
||||
Injector(Katrin *Kat, UniRNG *rngUni, NormalRNG *rngNormal) : RNG_Base(rngUni, rngNormal){
|
||||
this->Kat = Kat;
|
||||
};
|
||||
|
||||
Particle injectElectron (const int &newId);
|
||||
private:
|
||||
double roll_FermiEnergy_eV();
|
||||
double get_FermiDecaySpectrumDensity(const double &Ekin_eV);
|
||||
double get_FermiFunction(const double &Z, const double &Ekin_eV);
|
||||
|
||||
Katrin *Kat;
|
||||
ParticleBuilder PartFac;
|
||||
|
||||
static const int injectionMethod;
|
||||
static const double injectionEnergy_eV;
|
||||
};
|
||||
#endif /* injector_hpp */
|
||||
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// interaction_base.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 24.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef interaction_base_hpp
|
||||
#define interaction_base_hpp
|
||||
|
||||
#include "functions.hpp"
|
||||
#include "particle.hpp"
|
||||
#include "katrin.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
class InteractionOut {
|
||||
bool deleteCur;
|
||||
deque <Particle> newParticles;
|
||||
|
||||
public:
|
||||
InteractionOut() {reset();};
|
||||
|
||||
void reset() {
|
||||
deleteCur = false;
|
||||
newParticles.empty();
|
||||
}
|
||||
|
||||
void set_deleteCur(const bool &deleteCur) {this->deleteCur = deleteCur;}
|
||||
void set_newParticles(const deque<Particle> &newParticles) {this->newParticles = newParticles;}
|
||||
void add_newParticle(const Particle &newParticle) {newParticles.push_back(newParticle);}
|
||||
|
||||
bool get_deleteCur() const {return(deleteCur);};
|
||||
deque<Particle> get_newParticles() const {return(newParticles);};
|
||||
};
|
||||
|
||||
|
||||
class Interaction : public RNG_Base {
|
||||
protected:
|
||||
Katrin *Kat;
|
||||
|
||||
public:
|
||||
Interaction(Katrin *Kat, UniRNG *rngUni, NormalRNG *rngNormal) : RNG_Base(rngUni, rngNormal) {
|
||||
this->Kat = Kat;
|
||||
};
|
||||
|
||||
virtual species get_Species() const = 0;
|
||||
|
||||
virtual double get_macroSigma_m2(const Particle &interPart) const = 0;
|
||||
virtual InteractionOut do_Interaction (Particle *interPart) const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* interaction_base_h */
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// interaction_builder.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 29.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "interaction_builder.hpp"
|
||||
|
||||
const int InteractionBuilder::elaOn = getParameter("elaOn");
|
||||
const int InteractionBuilder::ionOn = getParameter("ionOn");
|
||||
|
||||
InteractionProcessor InteractionBuilder::build_InteractionProcessor() {
|
||||
InteractionProcessor InterProcessor(Kat,rngUni,rngNormal);
|
||||
InterProcessor.add_ParticleInteraction(build_eInteractions());
|
||||
return(InterProcessor);
|
||||
}
|
||||
|
||||
ParticleInteractions* InteractionBuilder::build_eInteractions() {
|
||||
ParticleInteractions* eInteractions = new ParticleInteractions(Kat, rngUni, rngNormal, electron);
|
||||
eInteractions->add_Interaction(new e_T2_elasticScattering(Kat, rngUni, rngNormal));
|
||||
eInteractions->add_Interaction(new e_T2_ionization(Kat, rngUni, rngNormal));
|
||||
return(eInteractions);
|
||||
}
|
||||
|
||||
/*
|
||||
ParticleInteractions InteractionBuilder::build_T2Interactions() {
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// interaction_builder.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 29.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef interaction_builder_hpp
|
||||
#define interaction_builder_hpp
|
||||
|
||||
|
||||
#include "katrin.hpp"
|
||||
#include "functions.hpp"
|
||||
#include "interaction_processor.hpp"
|
||||
#include "interaction_species.hpp"
|
||||
#include "electron_interactions.hpp"
|
||||
|
||||
class InteractionBuilder : public RNG_Base {
|
||||
Katrin *Kat;
|
||||
|
||||
static const int ionOn;
|
||||
static const int elaOn;
|
||||
|
||||
public:
|
||||
InteractionBuilder(Katrin *Kat, UniRNG *rngUni, NormalRNG *rngNormal) : RNG_Base(rngUni, rngNormal) {
|
||||
this->Kat = Kat;
|
||||
}
|
||||
InteractionProcessor build_InteractionProcessor();
|
||||
|
||||
|
||||
private:
|
||||
ParticleInteractions* build_eInteractions();
|
||||
ParticleInteractions* build_T2Interactions();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* interaction_builder_hpp */
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// interaction_processor.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "interaction_processor.hpp"
|
||||
|
||||
|
||||
InteractionOut InteractionProcessor::do_Interaction(Particle *interPart) const {
|
||||
species Species = interPart->get_Species();
|
||||
ParticleInteractionsVec::const_iterator Itr = find_ParticleInteraction(Species);
|
||||
if (Itr == ParticleInteractions.end()) {
|
||||
stringstream ss;
|
||||
ss<<"InteractionProcessor::do_Interaction: No Interaction declare for Particles of Species:\n"<<Species<<"\n";
|
||||
throw MyException (ss.str());
|
||||
}
|
||||
return ( (*Itr)->do_Interaction(interPart) );
|
||||
}
|
||||
|
||||
double InteractionProcessor::get_macroSigma_m2(const Particle &interPart) const {
|
||||
species Species = interPart.get_Species();
|
||||
ParticleInteractionsVec::const_iterator Itr = find_ParticleInteraction(Species);
|
||||
if (Itr == ParticleInteractions.end()) {
|
||||
stringstream ss;
|
||||
ss<<"InteractionProcessor::get_macroSigma_m2: No Interaction declare for Particles of Species:\n"<<Species<<"\n";
|
||||
throw MyException (ss.str());
|
||||
}
|
||||
return ( (*Itr)->get_macroSigma_m2(interPart) );
|
||||
}
|
||||
|
||||
|
||||
void InteractionProcessor::add_ParticleInteraction(class ParticleInteractions* particleInteraction) {
|
||||
if (empty()) {
|
||||
} else if (find_ParticleInteraction(particleInteraction->get_Species()) != ParticleInteractions.end()) {
|
||||
stringstream ss;
|
||||
ss<<"InteractionProcessor::add_ParticleInteraction: Species already exists.\nSpecies:\t"<<particleInteraction->get_Species()<<"\n";
|
||||
throw MyException (ss.str());
|
||||
}
|
||||
ParticleInteractions.push_back(particleInteraction);
|
||||
}
|
||||
|
||||
ParticleInteractionsVec::const_iterator InteractionProcessor::find_ParticleInteraction (species findSpec) const {
|
||||
ParticleInteractionsVec::const_iterator Itr;
|
||||
if (empty()) {
|
||||
Itr = ParticleInteractions.cend();
|
||||
} else {
|
||||
Itr = ParticleInteractions.cbegin();
|
||||
while (Itr != ParticleInteractions.end()) {
|
||||
if ((*Itr)->get_Species() == findSpec) {
|
||||
break;
|
||||
}
|
||||
Itr++;
|
||||
}
|
||||
}
|
||||
return (Itr);
|
||||
}
|
||||
|
||||
ParticleInteractionsVec::iterator InteractionProcessor::find_ParticleInteraction (species findSpec) {
|
||||
ParticleInteractionsVec::iterator Itr;
|
||||
if (empty()) {
|
||||
Itr = ParticleInteractions.end();
|
||||
} else {
|
||||
Itr = ParticleInteractions.begin();
|
||||
while (Itr != ParticleInteractions.end() || (*Itr)->get_Species() == findSpec) {
|
||||
Itr++;
|
||||
}
|
||||
}
|
||||
return (Itr);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// interaction_processor.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef interaction_processor_hpp
|
||||
#define interaction_processor_hpp
|
||||
|
||||
#include "interaction_species.hpp"
|
||||
|
||||
|
||||
|
||||
typedef std::vector <ParticleInteractions*> ParticleInteractionsVec;
|
||||
|
||||
class InteractionProcessor : public RNG_Base {
|
||||
Katrin *Kat;
|
||||
ParticleInteractionsVec ParticleInteractions;
|
||||
|
||||
public:
|
||||
InteractionProcessor(Katrin *Kat, UniRNG *rngUni, NormalRNG *rngNormal) : RNG_Base(rngUni, rngNormal){
|
||||
this->Kat = Kat;
|
||||
};
|
||||
|
||||
InteractionOut do_Interaction(Particle *interPart) const;
|
||||
double get_macroSigma_m2(const Particle &interPart) const;
|
||||
|
||||
public:
|
||||
void add_ParticleInteraction(class ParticleInteractions* particleInteraction);
|
||||
|
||||
bool empty() const {return (ParticleInteractions.size()==0 ? true : false);}
|
||||
private:
|
||||
ParticleInteractionsVec::const_iterator find_ParticleInteraction (species findSpec) const;
|
||||
ParticleInteractionsVec::iterator find_ParticleInteraction (species findSpec);
|
||||
};
|
||||
|
||||
#endif /* interaction_processor_hpp */
|
||||
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// interaction_species.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 27.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "interaction_species.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
InteractionOut ParticleInteractions::do_Interaction(Particle *interPart) const {
|
||||
double macroSigma_m2 = get_macroSigma_m2(*interPart);
|
||||
if (macroSigma_m2 == 0) {
|
||||
stringstream ss;
|
||||
ss<<"ParticleInteractions::do_Interaction: Interaction Cross Section = 0 for particle of Species "<<get_Species()<<".\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double currentStackedSigma = 0;
|
||||
double targetStackedSigma = rngUni->random() * macroSigma_m2;
|
||||
InteractionsVec::const_iterator Itr = Interactions.cbegin();
|
||||
do {
|
||||
currentStackedSigma += (*Itr)->get_macroSigma_m2(*interPart);
|
||||
Itr++;
|
||||
} while(currentStackedSigma < targetStackedSigma);
|
||||
Itr--;
|
||||
return ((*Itr)->do_Interaction(interPart));
|
||||
}
|
||||
|
||||
double ParticleInteractions::get_macroSigma_m2(const Particle &interPart) const {
|
||||
double macroSigma_m2 = 0;
|
||||
if (empty()) {
|
||||
cout<<"Warning: No Interaction for Particle of Type "<<get_Species()<<"\n";
|
||||
} else {
|
||||
for (InteractionsVec::const_iterator Itr = Interactions.begin();Itr!=Interactions.end();Itr++) {
|
||||
macroSigma_m2 += (*Itr)->get_macroSigma_m2(interPart);
|
||||
}
|
||||
}
|
||||
return(macroSigma_m2);
|
||||
}
|
||||
|
||||
void ParticleInteractions::add_Interaction(Interaction* addInteraction) {
|
||||
if (Interactions.size()>0) {
|
||||
for (InteractionsVec::iterator Itr = Interactions.begin();Itr!=Interactions.end();Itr++) {
|
||||
if ( typeid(addInteraction) == typeid(Itr)) {
|
||||
stringstream ss;
|
||||
ss<<"ParticleInteractions::add_Interaction: Interactions already exists.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (addInteraction->get_Species() != get_Species()) {
|
||||
stringstream ss;
|
||||
ss<<"ParticleInteractions::add_Interaction: Species of adding Interaction missmatches this ParticleInteractions species: \nThis Species:\t"<<get_Species()<<"\nadding Species:\t"<<addInteraction->get_Species()<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
Interactions.push_back(addInteraction);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// interaction_species.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 27.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef interaction_species_hpp
|
||||
#define interaction_species_hpp
|
||||
|
||||
#include "interaction_base.h"
|
||||
|
||||
typedef std::vector<Interaction*> InteractionsVec;
|
||||
|
||||
class ParticleInteractions : public RNG_Base {
|
||||
Katrin *Kat;
|
||||
species Species;
|
||||
InteractionsVec Interactions;
|
||||
|
||||
public:
|
||||
ParticleInteractions(Katrin *Kat, UniRNG *rngUni, NormalRNG *rngNormal, species Species) : RNG_Base(rngUni, rngNormal) {
|
||||
this->Kat = Kat;
|
||||
this->Species = Species;
|
||||
};
|
||||
|
||||
InteractionOut do_Interaction(Particle *interPart) const;
|
||||
double get_macroSigma_m2(const Particle &interPart) const;
|
||||
|
||||
void add_Interaction(Interaction* addInteraction);
|
||||
|
||||
species get_Species() const {return (Species);};
|
||||
bool empty() const {return (Interactions.size()==0 ? true : false);}
|
||||
};
|
||||
|
||||
#endif /* interaction_species_hpp */
|
||||
+27
-236
@@ -16,263 +16,54 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
const double Katrin::wgtsMagField_T = getParameter("wgtsMagField_T");
|
||||
const double Katrin::wgtsLength_m = getParameter("wgtsLength_m");
|
||||
const double Katrin::rearwallZ_m = getParameter("rearwallZ_m");
|
||||
const double Katrin::wgtsStartZ_m = getParameter("wgtsStartZ_m");
|
||||
const double Katrin::wgtsEndZ_m = getParameter("wgtsEndZ_m");
|
||||
const double Katrin::wgtsRadius_m = getParameter("wgtsRadius_m");
|
||||
|
||||
const double Katrin::wgtsMagField_T = getParameter("wgtsMagField_T");
|
||||
|
||||
const double Katrin::wgtsT2MaxDensity_m3 = getParameter("wgtsT2MaxDensity_m3");
|
||||
const double Katrin::wgtsTemp_K = getParameter("wgtsTemp_K");
|
||||
const double Katrin::wgtsT2FlowSpeed_ms = getParameter("wgtsT2FlowSpeed_ms");
|
||||
|
||||
const int Katrin::injectionMethod = getParameter("injectionMethod");
|
||||
const double Katrin::injectionEnergy_eV = getParameter("injectionEnergy_eV");
|
||||
|
||||
const double Katrin::dt_s = getParameter("dt_s");
|
||||
|
||||
const double Katrin::cutoffEnergy_eV = getParameter("cutoffEnergy_eV");
|
||||
|
||||
vec3 Katrin::getMagField_T(vec3 loc_m) {
|
||||
vec3 MagField_T;
|
||||
MagField_T = 0,0,wgtsMagField_T;
|
||||
return(MagField_T);
|
||||
void Katrin::check_Properties() {
|
||||
// Geometrics
|
||||
stringstream ss;
|
||||
ss<<"Katrin::check_Properties: ";
|
||||
if (rearwallZ_m>wgtsStartZ_m) {
|
||||
ss<<"rearwallZ_m>wgtsStartZ_m"<<endl;
|
||||
MyException (ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
vec3 Katrin::getElField_Vm(vec3 loc_m) {
|
||||
return (vec3(0,0,0));
|
||||
}
|
||||
|
||||
double Katrin::getTritiumDensity_m3(vec3 loc_m) {
|
||||
double mid_m = wgtsLength_m/2;
|
||||
double zProjection_m = (loc_m[2] < mid_m) ? loc_m[2] : wgtsLength_m - loc_m[2] ;
|
||||
double reductget_ionFactor = zProjection_m/mid_m;
|
||||
double z_wgtsCords_m = loc_m[2] - wgtsStartZ_m; // New Cords, where wgtsStart equals z=0
|
||||
double reductget_ionFactor;
|
||||
if (z_wgtsCords_m<0) { //outside of tank
|
||||
reductget_ionFactor = 1e-9;
|
||||
} else {
|
||||
double zProjection_m = (z_wgtsCords_m < wgtsLength_m()/2) ? z_wgtsCords_m : wgtsLength_m() - z_wgtsCords_m;
|
||||
reductget_ionFactor = zProjection_m/wgtsLength_m()*2; //Correction since reflection
|
||||
}
|
||||
return(reductget_ionFactor * wgtsT2MaxDensity_m3);
|
||||
}
|
||||
|
||||
vec3 Katrin::getTotSpeedT2_ms(vec3 loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
||||
return ( getFlowSpeedT2_ms(loc_m) + getTempSpeedT2_ms(loc_m, rngUni, rngNormal) );
|
||||
vec3 Katrin::roll_totEqSpeed_ms(vec3 loc_m) {
|
||||
return ( get_flowEqSpeed_ms(loc_m) + roll_thermEqSpeed_ms(loc_m) );
|
||||
}
|
||||
|
||||
vec3 Katrin::getFlowSpeedT2_ms(vec3 loc_m) {
|
||||
vec3 Katrin::get_flowEqSpeed_ms(vec3 loc_m) {
|
||||
vec3 speed_ms;
|
||||
double sign = (loc_m[2] < wgtsLength_m/2.) ? -1 : 1;
|
||||
double sign = (loc_m[2] < wgtsLength_m()/2.) ? -1 : 1;
|
||||
double flow_ms = sign*wgtsT2FlowSpeed_ms;
|
||||
speed_ms = 0,0,flow_ms;
|
||||
return (speed_ms);
|
||||
}
|
||||
|
||||
vec3 Katrin::getTempSpeedT2_ms(vec3 loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
||||
vec3 Katrin::roll_thermEqSpeed_ms(vec3 loc_m) {
|
||||
double tempOffsetABS_ms = get_Speed_from_Ekin_eV(roll_MBEnergy(wgtsTemp_K,mT2_eV,rngNormal), mT2_eV);
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni)*tempOffsetABS_ms;
|
||||
return(speed_ms);
|
||||
}
|
||||
|
||||
Electron Katrin::injectElectron(int newId, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
||||
double r_m = wgtsRadius_m*sqrt(rngUni->random());
|
||||
double phi = rngUni->random()*2*pi;
|
||||
|
||||
double z_0tohalf_m = sqrt(rngUni->random())*wgtsLength_m/2;
|
||||
double z_m = (rngUni->random()<0.5)? z_0tohalf_m : wgtsLength_m - z_0tohalf_m;
|
||||
|
||||
vec3 loc_m = vec3 (r_m*cos(phi),r_m*sin(phi),z_m);
|
||||
double Ekin_eV;
|
||||
switch(injectionMethod) {
|
||||
case 0: // Fermi
|
||||
Ekin_eV = roll_FermiEnergy_eV(rngUni);
|
||||
break;
|
||||
case 1: //Delta
|
||||
Ekin_eV = injectionEnergy_eV;
|
||||
break;
|
||||
case 2: //Maxwell Boltzman
|
||||
Ekin_eV = roll_MBEnergy(injectionEnergy_eV/kb_eVK,me_eV, rngNormal);
|
||||
break;
|
||||
default:
|
||||
throw MyException("Katrin::injectElectron: Invalid Injection Method.");
|
||||
break;
|
||||
}
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni) * get_Speed_from_Ekin_eV(Ekin_eV,me_eV);
|
||||
return (Electron(loc_m, speed_ms,newId,newId));
|
||||
}
|
||||
|
||||
double Katrin::roll_FermiEnergy_eV(ranlib::Uniform<double> *rngUni) {
|
||||
// get Energy distribution using Rejection Method
|
||||
double pmax,Emin_eV, Emax_eV, Ecan_eV,eta1,eta2;
|
||||
pmax = 1.5e-28; // From Plotting EnergyDistributionBetaDecay
|
||||
Emin_eV = 1e-15;
|
||||
Emax_eV = TritiumDecayEndpoint_eV;
|
||||
do {
|
||||
eta1 = rngUni->random();
|
||||
eta2 = rngUni->random();
|
||||
Ecan_eV = Emin_eV + eta1*(Emax_eV - Emin_eV);
|
||||
} while(eta2*pmax > get_FermiDecaySpectrumDensity(Ecan_eV));
|
||||
return(Ecan_eV);
|
||||
}
|
||||
|
||||
double Katrin::get_FermiDecaySpectrumDensity(double Ekin_eV) {
|
||||
if (Ekin_eV>TritiumDecayEndpoint_eV) {
|
||||
return (0.);
|
||||
} else{
|
||||
double p_eV = sqrt(Ekin_eV*Ekin_eV + 2 * Ekin_eV * me_eV);
|
||||
return( BetaDecayConst * get_FermiFunction(2, Ekin_eV) * p_eV*(Ekin_eV+me_eV)*pow(TritiumDecayEndpoint_eV-Ekin_eV,2) );
|
||||
}
|
||||
}
|
||||
|
||||
double Katrin::get_FermiFunction(double Z, double Ekin_eV) {
|
||||
double gamma = 1+ Ekin_eV/me_eV;
|
||||
double beta = sqrt(1 - pow(gamma,-2));
|
||||
double eta =Z/beta/137.;
|
||||
return( 2*pi*eta/(1-exp(-2*pi*eta)) );
|
||||
}
|
||||
|
||||
// Move Electrons and Log
|
||||
void Katrin::do_BorisPushMovement(Electron *moveElectron, double distance_m, H5_Logger *Log) {
|
||||
// Rework, with Logging and Reflection at wall
|
||||
vec3 loc_m;
|
||||
|
||||
double oldzDir = moveElectron->get_Speed_ms()[2] < 0 ? -1 : 1;
|
||||
vec3 oldLoc_m = moveElectron->get_Location_m();
|
||||
|
||||
double traveledDistance_m = 0;
|
||||
|
||||
while (traveledDistance_m < distance_m) {
|
||||
loc_m = moveElectron->get_Location_m();
|
||||
|
||||
traveledDistance_m += moveElectron->do_BorisStep_m(getElField_Vm(loc_m) , getMagField_T(loc_m) , dt_s);
|
||||
|
||||
doBoris_WallInteraction(moveElectron);
|
||||
|
||||
if (check_WallTermination(*moveElectron) == 0) {
|
||||
Log->log_Electron(moveElectron, oldLoc_m);
|
||||
return;
|
||||
}
|
||||
doBoris_LogzDirChange(moveElectron, &oldzDir, &oldLoc_m, Log);
|
||||
|
||||
}
|
||||
Log->log_Electron(moveElectron, oldLoc_m);
|
||||
return;
|
||||
}
|
||||
|
||||
void Katrin::doBoris_WallInteraction(Electron *moveElectron) {
|
||||
vec3 loc_m = moveElectron->get_Location_m();
|
||||
double r_m = moveElectron->get_Radius_m();
|
||||
if (loc_m[2]<=0) { // Rear Wall Termination
|
||||
vec3 newLoc_m = moveElectron->get_Location_m();
|
||||
newLoc_m[2] = 0;
|
||||
moveElectron->set_Location_m(newLoc_m);
|
||||
} else if (r_m>=wgtsRadius_m) { // WGTS Wall Termination
|
||||
vec3 newLoc_m = moveElectron->get_Location_m();
|
||||
double z_m = newLoc_m[2];
|
||||
newLoc_m[2] = 0;
|
||||
newLoc_m = (wgtsRadius_m * 1.01)/get_vecAbs(newLoc_m) * newLoc_m; //1.01 to move Electron slightly out of WGTS
|
||||
newLoc_m[2] = z_m;
|
||||
} else if (loc_m[2]>=wgtsLength_m) { // Spectrometer Reflection
|
||||
moveElectron->set_Speed_ms( -1*(moveElectron->get_Speed_ms()) );
|
||||
}
|
||||
}
|
||||
|
||||
void Katrin::doBoris_LogzDirChange(Electron *moveElectron, double *oldzDir, vec3 *oldLoc_m, H5_Logger *Log) {
|
||||
double zDir = moveElectron->get_Speed_ms()[2] < 0 ? -1 : 1;
|
||||
if (*oldzDir != zDir) {
|
||||
Log->log_Electron(moveElectron, *oldLoc_m);
|
||||
*oldzDir = zDir;
|
||||
*oldLoc_m = moveElectron->get_Location_m();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void Katrin::do_DriftApproximationMovement(Electron *moveElectron, double distance_m, H5_Logger *Log) {
|
||||
// Drift Approximation: Assume constant B and only movement out in z=0, z=wgtsLength_m...
|
||||
vec3 oldLoc_m = moveElectron->get_Location_m();
|
||||
vec3 newLoc_m = oldLoc_m;
|
||||
|
||||
double znew_m = getDrift_znew_m(distance_m, moveElectron);
|
||||
doDrift_WallInteraction(&oldLoc_m, &znew_m, moveElectron, Log);
|
||||
newLoc_m[2] = znew_m;
|
||||
|
||||
moveElectron->set_Location_m(newLoc_m);
|
||||
Log->log_Electron(moveElectron, oldLoc_m);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
double Katrin::getDrift_znew_m(double distance_m, Electron *moveElectron) {
|
||||
double zold_m = moveElectron->get_Location_m()[2];
|
||||
|
||||
vec3 v_ms = moveElectron->get_Speed_ms();
|
||||
double vTotAbs_ms = get_vecAbs(v_ms);
|
||||
double vForwardAbs_ms = get_vecAbs(vec3(0,0,v_ms[2]));
|
||||
double zDir = v_ms[2] < 0 ? -1 : 1;
|
||||
|
||||
double znew_m = zold_m + zDir*vForwardAbs_ms/vTotAbs_ms * distance_m;
|
||||
return (znew_m);
|
||||
}
|
||||
|
||||
void Katrin::doDrift_WallInteraction(vec3 *oldLoc_m, double *znew_m, Electron *moveElectron, H5_Logger *Log) {
|
||||
if (*znew_m >= wgtsLength_m) { // Moveing into Spectrometer and reversing Speed.
|
||||
vec3 reverseLoc_m = *oldLoc_m;
|
||||
reverseLoc_m[2] = wgtsLength_m;
|
||||
moveElectron->set_Location_m(reverseLoc_m);
|
||||
|
||||
Log->log_Electron(moveElectron, *oldLoc_m);
|
||||
|
||||
*oldLoc_m = reverseLoc_m;
|
||||
*znew_m = 2*wgtsLength_m - *znew_m;
|
||||
|
||||
moveElectron->set_Speed_ms( -1*(moveElectron->get_Speed_ms()) );
|
||||
}
|
||||
if (*znew_m <= 0) {
|
||||
*znew_m = 0;
|
||||
}
|
||||
}
|
||||
|
||||
double Katrin::get_MFP_m(Electron *moveElectron) {
|
||||
//Rework for inserting vector of Interactions
|
||||
vec3 loc_m, speedT2_ms;
|
||||
double sigmaTot_m2, density_m3, MFP_m;
|
||||
loc_m = moveElectron->get_Location_m();
|
||||
speedT2_ms = getFlowSpeedT2_ms(loc_m);
|
||||
|
||||
sigmaTot_m2 = moveElectron->get_SigmaTotal_m2(speedT2_ms);
|
||||
density_m3 = getTritiumDensity_m3(loc_m);
|
||||
MFP_m = 1/(density_m3 * sigmaTot_m2);
|
||||
return(MFP_m);
|
||||
}
|
||||
|
||||
// Terminate Electrons
|
||||
bool Katrin::check_Termination(Electron checkElectron) {
|
||||
return ( check_EnergyTermination(checkElectron) || check_WallTermination(checkElectron) );
|
||||
}
|
||||
|
||||
bool Katrin::check_EnergyTermination(double Ekin_eV) {
|
||||
double ETemp_eV = kb_eVK*wgtsTemp_K;
|
||||
if (ETemp_eV<0) {
|
||||
throw MyException("Katrin::checkTermination: ETemp_eV < 0.");
|
||||
}
|
||||
|
||||
if (Ekin_eV<=cutoffEnergy_eV) {
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
bool Katrin::check_EnergyTermination(Electron checkElectron) {
|
||||
double Ekin_eV = checkElectron.get_EKin_eV();
|
||||
return (check_EnergyTermination(Ekin_eV));
|
||||
}
|
||||
|
||||
bool Katrin::check_WallTermination(vec3 loc_m) {
|
||||
double z_m = loc_m[2];
|
||||
double r_m = sqrt( pow(loc_m[0],2) + pow(loc_m[1],2) );
|
||||
if (z_m <=0) {
|
||||
return (true);
|
||||
} else if (r_m >= wgtsRadius_m) {
|
||||
return (true);
|
||||
} else {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
bool Katrin::check_WallTermination(Electron checkElectron) {
|
||||
vec3 loc_m = checkElectron.get_Location_m();
|
||||
return (check_WallTermination(loc_m));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+42
-52
@@ -10,8 +10,7 @@
|
||||
#define katrin_hpp
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "electron.hpp"
|
||||
|
||||
#include "density_container.hpp"
|
||||
|
||||
#include "blitz/tinyvec2.h"
|
||||
@@ -20,68 +19,59 @@
|
||||
#include <random/normal.h>
|
||||
|
||||
|
||||
class Katrin {
|
||||
|
||||
class Katrin : public RNG_Base{
|
||||
public:
|
||||
Katrin() {};
|
||||
Katrin(UniRNG *rngUni, NormalRNG *rngNormal) : RNG_Base(rngUni, rngNormal) {
|
||||
check_Properties ();
|
||||
};
|
||||
|
||||
// Katrin Properties
|
||||
private:
|
||||
void check_Properties();
|
||||
// Geometrics
|
||||
public:
|
||||
vec3 getMagField_T(vec3 loc_m);
|
||||
vec3 getElField_Vm(vec3 loc_m);
|
||||
double getTritiumDensity_m3(vec3 loc_m);
|
||||
double get_z_RW_m() const {return(rearwallZ_m);};
|
||||
double get_z_WGTSstart_m() const {return(wgtsStartZ_m);};
|
||||
double get_z_WGTSend_m() const {return(wgtsEndZ_m);};
|
||||
double get_radius_m() const {return(wgtsRadius_m);};
|
||||
|
||||
vec3 getTotSpeedT2_ms(vec3 loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
||||
vec3 getFlowSpeedT2_ms(vec3 loc_m);
|
||||
vec3 getTempSpeedT2_ms(vec3 loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
||||
bool outside(vec3 loc_m) const;
|
||||
private:
|
||||
double wgtsLength_m() const {return (get_z_WGTSend_m() - get_z_WGTSstart_m());};
|
||||
|
||||
static const double rearwallZ_m;
|
||||
static const double wgtsStartZ_m;
|
||||
static const double wgtsEndZ_m;
|
||||
static const double wgtsRadius_m;
|
||||
|
||||
|
||||
// EM-Fields
|
||||
public:
|
||||
vec3 getMagField_T(vec3 loc_m) const { return (vec3(0,0,wgtsMagField_T)); };
|
||||
vec3 getElField_Vm(vec3 loc_m) const {return (vec3(0,0,0));};
|
||||
private:
|
||||
static const double wgtsMagField_T;
|
||||
static const double wgtsLength_m;
|
||||
static const double wgtsRadius_m;
|
||||
|
||||
|
||||
//Particle Densities
|
||||
public:
|
||||
double getTritiumDensity_m3(vec3 loc_m);
|
||||
|
||||
// Maxwell Boltzmann Part
|
||||
public:
|
||||
vec3 roll_totEqSpeed_ms(vec3 loc_m);
|
||||
vec3 get_flowEqSpeed_ms(vec3 loc_m);
|
||||
vec3 roll_thermEqSpeed_ms(vec3 loc_m);
|
||||
private:
|
||||
static const double wgtsT2MaxDensity_m3;
|
||||
static const double wgtsTemp_K;
|
||||
static const double wgtsT2FlowSpeed_ms;
|
||||
|
||||
// Electron Injection
|
||||
public:
|
||||
Electron injectElectron(int newId, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
||||
private:
|
||||
double roll_FermiEnergy_eV(ranlib::Uniform<double> *rngUni);
|
||||
double get_FermiDecaySpectrumDensity(double Ekin_eV);
|
||||
double get_FermiFunction(double Z, double Ekin_eV);
|
||||
|
||||
static const int injectionMethod;
|
||||
static const double injectionEnergy_eV;
|
||||
|
||||
// Move Electrons
|
||||
public:
|
||||
double get_MFP_m(Electron *moveElectron);
|
||||
void do_BorisPushMovement(Electron *moveElectron, double distance_m, H5_Logger *Log);
|
||||
void do_DriftApproximationMovement(Electron *moveElectron, double distance_m, H5_Logger *Log);
|
||||
private:
|
||||
double getDrift_znew_m(double MFP_m, Electron *moveElectron);
|
||||
void doDrift_WallInteraction(vec3 *oldLoc_m, double *znew_m, Electron *moveElectron, H5_Logger *Log);
|
||||
void doBoris_WallInteraction(Electron *moveElectron);
|
||||
void doBoris_LogzDirChange(Electron *moveElectron, double *oldzDir, vec3 *oldLoc_m, H5_Logger *Log);
|
||||
|
||||
static const double dt_s;
|
||||
|
||||
|
||||
// Terminate Electrons
|
||||
public:
|
||||
bool check_Termination(Electron checkElectron);
|
||||
private:
|
||||
bool check_EnergyTermination(double Ekin_eV);
|
||||
bool check_EnergyTermination(Electron checkElectron);
|
||||
bool check_WallTermination(vec3 loc_m);
|
||||
bool check_WallTermination(Electron checkElectron);
|
||||
|
||||
static const double cutoffEnergy_eV;
|
||||
|
||||
|
||||
// Ions
|
||||
public:
|
||||
private:
|
||||
//Skalar_WGTS_Container Ion_Container = Skalar_WGTS_Container(0, wgtsLength_m, wgtsRadius_m, vec3(10,10,12));
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* katrin_hpp */
|
||||
|
||||
+183
-150
@@ -19,10 +19,10 @@ using namespace std;
|
||||
|
||||
|
||||
const int Base_Logger::numberZBins = getParameter("numberZBins");
|
||||
const double Base_Logger::wgtsLength_m = getParameter("wgtsLength_m");
|
||||
|
||||
// Base_Logger
|
||||
Base_Logger::Base_Logger() {
|
||||
Base_Logger::Base_Logger(Katrin *Kat) {
|
||||
this->Kat = Kat;
|
||||
if (numberZBins == 0) {
|
||||
cout<<"Logging turned off."<<endl;
|
||||
logging = false;
|
||||
@@ -37,11 +37,15 @@ void Base_Logger::set_zLogValues() {
|
||||
if (numberZBins == -1) {
|
||||
cout<<"Logging everything to one file."<<endl;
|
||||
} else if (numberZBins == 1) {
|
||||
cout<<"Logging 1 z-Value: "<<wgtsLength_m<<endl;
|
||||
zLogValues.push_back(wgtsLength_m);
|
||||
cout<<"Logging 1 z-Value: "<<Kat->get_z_WGTSend_m()<<endl;
|
||||
zLogValues.push_back(Kat->get_z_WGTSend_m());
|
||||
} else {
|
||||
double z_m;
|
||||
double length_m = Kat->get_z_WGTSend_m() - Kat->get_z_RW_m();
|
||||
double stepLength_m = length_m/(numberZBins-1);
|
||||
for (int i = 0;i<numberZBins;i++) {
|
||||
zLogValues.push_back( i*wgtsLength_m/(numberZBins-1) );
|
||||
z_m = Kat->get_z_RW_m() + stepLength_m*i;
|
||||
zLogValues.push_back(z_m);
|
||||
}
|
||||
cout<<"Logging "<<numberZBins<<" z-Values."<<endl;
|
||||
}
|
||||
@@ -77,170 +81,33 @@ bool Base_Logger::isDir(std::string dirPath) {
|
||||
return (false);
|
||||
}
|
||||
|
||||
// H5_Logger
|
||||
H5_Logger::H5_Logger() : Base_Logger() {
|
||||
set_outH5FName();
|
||||
create_outH5F();
|
||||
create_H5Gs();
|
||||
create_particle_electronH5TBs();
|
||||
//set_outStream();
|
||||
}
|
||||
|
||||
// File
|
||||
void H5_Logger::set_outH5FName() {
|
||||
string parname = getparName();
|
||||
stringstream H5name;
|
||||
int i = 1;
|
||||
do {
|
||||
H5name.str(std::string());
|
||||
H5name << parname << "_" << getTimeString() << "_" << i++<<".h5";
|
||||
} while ( isFile(H5name.str()) );
|
||||
outH5FName = H5name.str();
|
||||
return;
|
||||
}
|
||||
|
||||
void H5_Logger::create_outH5F() {
|
||||
const string consth5Name = outH5FName;
|
||||
outH5F = H5Fcreate(consth5Name.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
|
||||
}
|
||||
|
||||
// Groups
|
||||
void H5_Logger::create_H5Gs() {
|
||||
particleH5G = H5Gcreate2(outH5F, "/Particles", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
if (numberZBins == -1) {
|
||||
particle_zH5G = new hid_t[1];
|
||||
particle_zH5G[0] = H5Gcreate2(outH5F, "/Particles/z=all", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
} else {
|
||||
particle_zH5G = new hid_t [numberZBins];
|
||||
for (int i = 0; i < numberZBins; i++)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "/Particles/z=" << zLogValues[i];
|
||||
particle_zH5G[i] = H5Gcreate2(outH5F, ss.str().c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Electrons
|
||||
const size_t H5_Logger::particle_electronH5TB_size = sizeof(logElectron);
|
||||
const char *H5_Logger::particle_electronH5TB_fieldNames[8] = { "Id","ParentId", "x_m", "y_m", "z_m", "vx_ms", "vy_ms", "vz_ms" };
|
||||
const size_t H5_Logger::particle_electronH5TB_offset[8] = {
|
||||
HOFFSET(logElectron, Id),
|
||||
HOFFSET(logElectron, parentId),
|
||||
HOFFSET(logElectron, x_m),
|
||||
HOFFSET(logElectron, y_m),
|
||||
HOFFSET(logElectron, z_m),
|
||||
HOFFSET(logElectron, vx_ms),
|
||||
HOFFSET(logElectron, vy_ms),
|
||||
HOFFSET(logElectron, vz_ms)};
|
||||
const hid_t H5_Logger::particle_electronH5TB_fieldTypes[8] = {
|
||||
H5T_NATIVE_INT,
|
||||
H5T_NATIVE_INT,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE};
|
||||
const hsize_t H5_Logger::particle_electronH5TB_chunkSize = 4096;
|
||||
|
||||
logElectron sampleLogElectron = {0,0,0,0,0,0,0,0};
|
||||
const size_t H5_Logger::particle_electronH5TB_sizes[8] = {
|
||||
sizeof( sampleLogElectron.Id),
|
||||
sizeof( sampleLogElectron.parentId),
|
||||
sizeof( sampleLogElectron.x_m),
|
||||
sizeof( sampleLogElectron.y_m),
|
||||
sizeof( sampleLogElectron.z_m),
|
||||
sizeof( sampleLogElectron.vx_ms),
|
||||
sizeof( sampleLogElectron.vy_ms),
|
||||
sizeof( sampleLogElectron.vz_ms)};
|
||||
|
||||
void H5_Logger::test_log() {
|
||||
Electron testElectron = Electron(vec3(1,2,3), vec3(4,5,6), 7, 8);
|
||||
log_Electron(&testElectron, vec3(9,10,7));
|
||||
return;
|
||||
}
|
||||
|
||||
void H5_Logger::log_Electron(Electron *inElectron,blitz::TinyVector<double,3> oldLoc_m) {
|
||||
if (!logging) {
|
||||
return;
|
||||
}
|
||||
logElectron logElectron_buffer = Electron_to_logElectron(inElectron);
|
||||
// Assumption: no change of sign in v_z
|
||||
if (numberZBins == -1) {
|
||||
H5TBappend_records(particle_zH5G[0], "electrons", 1, particle_electronH5TB_size, particle_electronH5TB_offset, particle_electronH5TB_sizes, &logElectron_buffer );
|
||||
} else {
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = inElectron->get_Location_m()[2];
|
||||
double zmin = min(zold,znew);
|
||||
double zmax = max(zold,znew);
|
||||
|
||||
for (int i=0;i<numberZBins;i++) {
|
||||
if (zLogValues[i]>=zmin && zLogValues[i]<=zmax) {
|
||||
H5TBappend_records(particle_zH5G[i], "electrons", 1, particle_electronH5TB_size, particle_electronH5TB_offset, particle_electronH5TB_sizes, &logElectron_buffer ); // Location wrong, because it s the new Location.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void H5_Logger::create_particle_electronH5TBs() {
|
||||
if (numberZBins == -1) {
|
||||
particle_electronH5T = new hid_t[1];
|
||||
particle_electronH5T[0] = H5TBmake_table( "Electron Table", particle_zH5G[0], "electrons", 8, 0,
|
||||
particle_electronH5TB_size, particle_electronH5TB_fieldNames, particle_electronH5TB_offset, particle_electronH5TB_fieldTypes,
|
||||
particle_electronH5TB_chunkSize, NULL, 0, NULL);
|
||||
} else {
|
||||
particle_electronH5T = new hid_t[numberZBins];
|
||||
for (int i = 0; i < numberZBins; i++)
|
||||
{
|
||||
particle_electronH5T[i] = H5TBmake_table( "Electron Table", particle_zH5G[i], "electrons",8,0,
|
||||
particle_electronH5TB_size, particle_electronH5TB_fieldNames, particle_electronH5TB_offset, particle_electronH5TB_fieldTypes,
|
||||
particle_electronH5TB_chunkSize, NULL, 0, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logElectron H5_Logger::Electron_to_logElectron(Electron *inElectron) {
|
||||
logElectron res;
|
||||
res.Id = inElectron->get_Id();
|
||||
res.parentId = inElectron->get_ParentId();
|
||||
res.x_m = inElectron->get_Location_m()[0];
|
||||
res.y_m = inElectron->get_Location_m()[1];
|
||||
res.z_m = inElectron->get_Location_m()[2];
|
||||
res.vx_ms = inElectron->get_Speed_ms()[0];
|
||||
res.vy_ms = inElectron->get_Speed_ms()[1];
|
||||
res.vz_ms = inElectron->get_Speed_ms()[2];
|
||||
return (res);
|
||||
}
|
||||
|
||||
// ASCI_Logger
|
||||
ASCI_Logger::ASCI_Logger() : Base_Logger() {
|
||||
ASCI_Logger::ASCI_Logger(Katrin *Kat) : Base_Logger(Kat) {
|
||||
set_outdirName();
|
||||
create_outdir();
|
||||
set_outStream();
|
||||
}
|
||||
|
||||
void ASCI_Logger::log_Electron(Electron *inElectron, blitz::TinyVector<double,3> oldLoc_m) {
|
||||
void ASCI_Logger::log_Particle(Particle *logPart, blitz::TinyVector<double,3> oldLoc_m) {
|
||||
if (!logging) {
|
||||
return;
|
||||
}
|
||||
if (logPart->get_Species() != electron) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Assumption: no change of sign in v_z
|
||||
if (numberZBins == -1) {
|
||||
outStream[0]<<*inElectron<<endl;
|
||||
outStream[0]<<*logPart<<endl;
|
||||
} else {
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = inElectron->get_Location_m()[2];
|
||||
double znew = logPart->get_Location_m()[2];
|
||||
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]<<*inElectron<<endl; // Location wrong, because it s the new Location.
|
||||
outStream[i]<<*logPart<<endl; // Location wrong, because it s the new Location.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,3 +150,169 @@ void ASCI_Logger::set_outStream() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ParticleH5TB_Properties
|
||||
const size_t ParticleH5TB_Properties::size = sizeof(logParticle);
|
||||
const char *ParticleH5TB_Properties::fieldNames[8] = { "Id","ParentId", "x_m", "y_m", "z_m", "vx_ms", "vy_ms", "vz_ms" };
|
||||
const size_t ParticleH5TB_Properties::offset[8] = {
|
||||
HOFFSET(logParticle, Id),
|
||||
HOFFSET(logParticle, parentId),
|
||||
HOFFSET(logParticle, x_m),
|
||||
HOFFSET(logParticle, y_m),
|
||||
HOFFSET(logParticle, z_m),
|
||||
HOFFSET(logParticle, vx_ms),
|
||||
HOFFSET(logParticle, vy_ms),
|
||||
HOFFSET(logParticle, vz_ms)};
|
||||
const hid_t ParticleH5TB_Properties::fieldTypes[8] = {
|
||||
H5T_NATIVE_INT,
|
||||
H5T_NATIVE_INT,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE};
|
||||
const hsize_t ParticleH5TB_Properties::chunkSize = 4096;
|
||||
|
||||
logParticle samplelogParticle = {0,0,0,0,0,0,0,0};
|
||||
const size_t ParticleH5TB_Properties::sizes[8] = {
|
||||
sizeof( samplelogParticle.Id),
|
||||
sizeof( samplelogParticle.parentId),
|
||||
sizeof( samplelogParticle.x_m),
|
||||
sizeof( samplelogParticle.y_m),
|
||||
sizeof( samplelogParticle.z_m),
|
||||
sizeof( samplelogParticle.vx_ms),
|
||||
sizeof( samplelogParticle.vy_ms),
|
||||
sizeof( samplelogParticle.vz_ms)};
|
||||
|
||||
|
||||
// ParticleLogger
|
||||
void ParticleLogger::create_particle_H5TBs() {
|
||||
if (numberZBins == -1) {
|
||||
particle_H5TB = new hid_t[1];
|
||||
particle_H5TB[0] = H5TBmake_table(speciesIdentifier.c_str(), particle_zH5G[0], speciesIdentifier.c_str(), 8, 0,
|
||||
size, fieldNames, offset, fieldTypes,
|
||||
chunkSize, NULL, 0, NULL);
|
||||
} else {
|
||||
particle_H5TB = new hid_t[numberZBins];
|
||||
for (int i = 0; i < numberZBins; i++)
|
||||
{
|
||||
particle_H5TB[i] = H5TBmake_table( speciesIdentifier.c_str(), particle_zH5G[i], speciesIdentifier.c_str(),8,0,
|
||||
size, fieldNames, offset, fieldTypes,
|
||||
chunkSize, NULL, 0, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleLogger::log_Particle(const Particle &logPart, const vec3 &oldLoc_m) {
|
||||
check_Species(logPart);
|
||||
|
||||
logParticle logParticle_buffer = transformTo_logParticle(logPart);
|
||||
// Assumption: no change of sign in v_z
|
||||
if (singleFile) {
|
||||
H5TBappend_records(particle_zH5G[0], speciesIdentifier.c_str() , 1, size, offset, sizes, &logParticle_buffer );
|
||||
} else {
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = logPart.get_Location_m()[2];
|
||||
double zmin = min(zold,znew);
|
||||
double zmax = max(zold,znew);
|
||||
|
||||
for (int i=0;i<numberZBins;i++) {
|
||||
if (zLogValues[i]>=zmin && zLogValues[i]<=zmax) {
|
||||
H5TBappend_records(particle_zH5G[i], speciesIdentifier.c_str(), 1, size, offset, sizes, &logParticle_buffer ); // Location wrong, because it s the new Location.
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void ParticleLogger::check_Species(const Particle &logPart) {
|
||||
if (logPart.get_Species() != Species) {
|
||||
stringstream ss;
|
||||
ss<<"ParticleLogger::check_Species: Wrong Species\nExpected:\t"<<Species<<"\nInput:\t"<<logPart.get_Species()<<"\n";
|
||||
throw MyException (ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
logParticle ParticleLogger::transformTo_logParticle(const Particle &logPart) {
|
||||
logParticle res;
|
||||
res.Id = logPart.get_Id();
|
||||
res.parentId = logPart.get_ParentId();
|
||||
res.x_m = logPart.get_Location_m()[0];
|
||||
res.y_m = logPart.get_Location_m()[1];
|
||||
res.z_m = logPart.get_Location_m()[2];
|
||||
res.vx_ms = logPart.get_Speed_ms()[0];
|
||||
res.vy_ms = logPart.get_Speed_ms()[1];
|
||||
res.vz_ms = logPart.get_Speed_ms()[2];
|
||||
return (res);
|
||||
}
|
||||
|
||||
|
||||
// H5_Logger
|
||||
void H5_Logger::create_outH5F() {
|
||||
const string constH5Name = get_outH5F_fullPath();
|
||||
outH5F = H5Fcreate(constH5Name.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
|
||||
}
|
||||
|
||||
string H5_Logger::get_outH5F_fullPath() {
|
||||
string parname = getparName();
|
||||
stringstream H5name;
|
||||
int i = 1;
|
||||
do {
|
||||
H5name.str(std::string());
|
||||
H5name << parname << "_" << getTimeString() << "_" << i++<<".h5";
|
||||
} while ( isFile(H5name.str()) );
|
||||
return (H5name.str());
|
||||
}
|
||||
|
||||
void H5_Logger::create_particleH5G() {
|
||||
particleH5G = H5Gcreate2(outH5F, "/Particles", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
}
|
||||
|
||||
void H5_Logger::create_particle_zH5G() {
|
||||
if (numberZBins == -1) {
|
||||
particle_zH5G = new hid_t[1];
|
||||
particle_zH5G[0] = H5Gcreate2(particleH5G, "/z=all", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
} else {
|
||||
particle_zH5G = new hid_t [numberZBins];
|
||||
for (int i = 0; i < numberZBins; i++)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "/z=" << zLogValues[i];
|
||||
particle_zH5G[i] = H5Gcreate2(particleH5G, ss.str().c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void H5_Logger::add_ParticleLogger(ParticleLogger* addParticleLogger){
|
||||
if (find_ParticleLogger(addParticleLogger->get_Species()) != ParticleLoggers.end()) {
|
||||
stringstream ss;
|
||||
ss<<"H5_Logger::add_ParticleLogger: Species already exists.\nSpecies:\t"<<addParticleLogger->get_Species()<<"\n";
|
||||
throw MyException (ss.str());
|
||||
}
|
||||
ParticleLoggers.push_back(addParticleLogger);
|
||||
}
|
||||
|
||||
ParticleLoggerVec::iterator H5_Logger::find_ParticleLogger (species findSpec) {
|
||||
if (ParticleLoggers.size() == 0) {
|
||||
return (ParticleLoggers.end());
|
||||
}
|
||||
ParticleLoggerVec::iterator Itr;
|
||||
Itr = ParticleLoggers.begin();
|
||||
while (Itr != ParticleLoggers.end()) {
|
||||
if ((*Itr)->get_Species() == findSpec ) {
|
||||
return (Itr);
|
||||
}
|
||||
Itr++;
|
||||
}
|
||||
return (Itr);
|
||||
}
|
||||
|
||||
void H5_Logger::log_Particle(const Particle &logPart, vec3 oldLoc_m) {
|
||||
ParticleLoggerVec::iterator Itr;
|
||||
Itr = find_ParticleLogger(logPart.get_Species());
|
||||
if (Itr!= ParticleLoggers.end()) {
|
||||
(*Itr)->log_Particle(logPart, oldLoc_m);
|
||||
}
|
||||
}
|
||||
|
||||
+94
-48
@@ -9,11 +9,13 @@
|
||||
#ifndef logger_hpp
|
||||
#define logger_hpp
|
||||
|
||||
#include "electron.hpp"
|
||||
#include "particle.hpp"
|
||||
#include "katrin.hpp"
|
||||
|
||||
#include "hdf5.h"
|
||||
#include <unordered_map>
|
||||
|
||||
typedef struct logElectron {
|
||||
typedef struct logParticle {
|
||||
unsigned int Id;
|
||||
unsigned int parentId;
|
||||
double x_m;
|
||||
@@ -22,17 +24,16 @@ typedef struct logElectron {
|
||||
double vx_ms;
|
||||
double vy_ms;
|
||||
double vz_ms;
|
||||
} logElectron;
|
||||
} logParticle;
|
||||
|
||||
|
||||
// Base_Logger: Base_Class for all Logger: Reading Paramter and calculating z-Barrieres.
|
||||
class Base_Logger {
|
||||
public:
|
||||
Base_Logger();
|
||||
Base_Logger(Katrin *Kat);
|
||||
|
||||
protected:
|
||||
static const int numberZBins;
|
||||
static const double wgtsLength_m;
|
||||
|
||||
bool logging;
|
||||
std::vector<double> zLogValues;
|
||||
@@ -43,55 +44,17 @@ protected:
|
||||
std::string remove_catEnding (std::string inString);
|
||||
bool isFile(std::string fileName);
|
||||
bool isDir(std::string dirPath);
|
||||
|
||||
Katrin *Kat;
|
||||
};
|
||||
|
||||
// H5_Logger: Logging to HDF5 file format.
|
||||
class H5_Logger : private Base_Logger {
|
||||
|
||||
|
||||
public:
|
||||
H5_Logger();
|
||||
|
||||
|
||||
private:
|
||||
// File
|
||||
std::string outH5FName;
|
||||
hid_t outH5F;
|
||||
|
||||
void set_outH5FName();
|
||||
void create_outH5F();
|
||||
|
||||
// Groups
|
||||
hid_t particleH5G;
|
||||
hid_t *particle_zH5G;
|
||||
|
||||
void create_H5Gs();
|
||||
|
||||
// Electrons
|
||||
public:
|
||||
void test_log();
|
||||
void log_Electron(Electron *inElectron,blitz::TinyVector<double,3> oldLoc_m);
|
||||
private:
|
||||
static const size_t particle_electronH5TB_size;
|
||||
static const char *particle_electronH5TB_fieldNames[8];
|
||||
static const size_t particle_electronH5TB_offset[8];
|
||||
static const hid_t particle_electronH5TB_fieldTypes[8];
|
||||
static const hsize_t particle_electronH5TB_chunkSize;
|
||||
static const size_t particle_electronH5TB_sizes[8];
|
||||
|
||||
hid_t *particle_electronH5T;
|
||||
|
||||
void create_particle_electronH5TBs();
|
||||
|
||||
logElectron Electron_to_logElectron(Electron *inElectron);
|
||||
};
|
||||
|
||||
// ASCI_Logger: Log to ASCI-File. Only Electron Logger. Not very efficient.
|
||||
class ASCI_Logger : private Base_Logger {
|
||||
class ASCI_Logger : public Base_Logger {
|
||||
public:
|
||||
ASCI_Logger();
|
||||
ASCI_Logger(Katrin *Kat);
|
||||
|
||||
void log_Electron(Electron *inElectron,blitz::TinyVector<double,3> oldLoc_m);
|
||||
void log_Particle(Particle *inPart , vec3 oldLoc_m);
|
||||
private:
|
||||
std::string outdirName;
|
||||
std::ofstream *outStream;
|
||||
@@ -102,4 +65,87 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class ParticleH5TB_Properties {
|
||||
public:
|
||||
ParticleH5TB_Properties() {};
|
||||
protected:
|
||||
static const size_t size;
|
||||
static const char *fieldNames[8];
|
||||
static const size_t offset[8];
|
||||
static const hid_t fieldTypes[8];
|
||||
static const hsize_t chunkSize;
|
||||
static const size_t sizes[8];
|
||||
};
|
||||
|
||||
|
||||
class ParticleLogger : ParticleH5TB_Properties{
|
||||
public:
|
||||
ParticleLogger(species Species, hid_t *particle_zH5G, std::vector<double> zLogValues) {
|
||||
this->Species = Species;
|
||||
this->particle_zH5G = particle_zH5G;
|
||||
this->zLogValues = zLogValues;
|
||||
numberZBins = zLogValues.size();
|
||||
singleFile = (numberZBins == 1) ? true : false;
|
||||
stringstream ss;
|
||||
ss<<Species;
|
||||
speciesIdentifier = ss.str();
|
||||
create_particle_H5TBs();
|
||||
};
|
||||
private:
|
||||
void create_particle_H5TBs();
|
||||
|
||||
private:
|
||||
hid_t *particle_zH5G;
|
||||
std::vector<double> zLogValues;
|
||||
hid_t *particle_H5TB;
|
||||
species Species;
|
||||
|
||||
int numberZBins;
|
||||
bool singleFile;
|
||||
std::string speciesIdentifier;
|
||||
public:
|
||||
void log_Particle(const Particle &logPart, const vec3 &oldLoc_m);
|
||||
private:
|
||||
logParticle transformTo_logParticle(const Particle &logPart);
|
||||
public:
|
||||
species get_Species() const {return(Species);};
|
||||
private:
|
||||
void check_Species(const Particle &logPart);
|
||||
};
|
||||
|
||||
|
||||
typedef std::vector<ParticleLogger*> ParticleLoggerVec;
|
||||
|
||||
class H5_Logger : private Base_Logger {
|
||||
public:
|
||||
H5_Logger(Katrin *Kat) : Base_Logger(Kat) {
|
||||
create_outH5F();
|
||||
create_particleH5G();
|
||||
create_particle_zH5G();
|
||||
add_ParticleLogger(new ParticleLogger(electron, particle_zH5G,zLogValues));
|
||||
};
|
||||
|
||||
private:
|
||||
hid_t outH5F;
|
||||
hid_t particleH5G;
|
||||
hid_t *particle_zH5G;
|
||||
|
||||
ParticleLoggerVec ParticleLoggers;
|
||||
|
||||
private:
|
||||
void create_outH5F();
|
||||
std::string get_outH5F_fullPath();
|
||||
void create_particleH5G();
|
||||
void create_particle_zH5G();
|
||||
|
||||
public:
|
||||
void add_ParticleLogger(ParticleLogger* addParticleLogger);
|
||||
private:
|
||||
ParticleLoggerVec::iterator find_ParticleLogger (species findSpec);
|
||||
|
||||
public:
|
||||
void log_Particle(const Particle &logPart, vec3 oldLoc_m);
|
||||
};
|
||||
|
||||
|
||||
#endif /* logger_hpp */
|
||||
|
||||
@@ -7,16 +7,17 @@
|
||||
//
|
||||
|
||||
#include "simulation.hpp"
|
||||
|
||||
#include "BED_eT2_ionization.hpp"
|
||||
#include "function_container.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
void createBED_TCS_Func_container() {
|
||||
Edge1D_FuncContainer BED_edge_TCS;
|
||||
BED_edge_TCS.fillFromFunction(BED_Ionization::get_TCS, 15, 20000, 100);
|
||||
BED_edge_TCS.add_ankerpoint(EionT2_eV, BED_Ionization::get_TCS(EionT2_eV));
|
||||
BED_edge_TCS.add_ankerpoint(EionT2_eV+1e-4, BED_Ionization::get_TCS(EionT2_eV+1e-4));
|
||||
BED_edge_TCS.fillFromFunction(BED_eT2_Ionization::get_TCS, 15, 20000, 100);
|
||||
BED_edge_TCS.add_ankerpoint(EionT2_eV, BED_eT2_Ionization::get_TCS(EionT2_eV));
|
||||
BED_edge_TCS.add_ankerpoint(EionT2_eV+1e-4, BED_eT2_Ionization::get_TCS(EionT2_eV+1e-4));
|
||||
BED_edge_TCS.exportToFile("/Users/ChristianReiling/Documents/Masterarbeit/katrin-plasma/src/mc_electron/data/BED_edge_TCS.dat");
|
||||
|
||||
Average1D_FuncContainer BED_average_TCS;
|
||||
@@ -26,11 +27,11 @@ void createBED_TCS_Func_container() {
|
||||
|
||||
void createBED_SDCS_Func2D_container() {
|
||||
Edge2D_FuncContainer BED_edge_SDCS;
|
||||
BED_edge_SDCS.get_Ionization_fromFunction(BED_Ionization::get_SDCS, 15, 20000, 50, 10);
|
||||
BED_edge_SDCS.get_Ionization_fromFunction(BED_eT2_Ionization::get_SDCS, 15, 20000, 50, 10);
|
||||
BED_edge_SDCS.add_ankerpoint(EionT2_eV, 0,0);
|
||||
double xmin =EionT2_eV+1e-4;
|
||||
double ymin = (xmin-EionT2_eV)/2;
|
||||
BED_edge_SDCS.add_ankerpoint(xmin, ymin,BED_Ionization::get_SDCS(xmin,ymin));
|
||||
BED_edge_SDCS.add_ankerpoint(xmin, ymin,BED_eT2_Ionization::get_SDCS(xmin,ymin));
|
||||
BED_edge_SDCS.exportToFile("/Users/ChristianReiling/Documents/Masterarbeit/katrin-plasma/src/mc_electron/data/BED_edge_SDCS.dat");
|
||||
|
||||
Average2D_FuncContainer BED_average_SDCS;
|
||||
@@ -44,14 +45,6 @@ void createBED_SDCS_Func2D_container() {
|
||||
|
||||
}
|
||||
|
||||
static Katrin Kat;
|
||||
double tritiumDens(vec3 cordszrphi) {
|
||||
double x = cordszrphi[1] * cos(cordszrphi[2]);
|
||||
double y = cordszrphi[1] * sin(cordszrphi[2]);
|
||||
double z = cordszrphi[0];
|
||||
return (Kat.getTritiumDensity_m3(vec3(x,y,z)));
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
|
||||
clock_t start = clock();
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
//
|
||||
// mover.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "mover.hpp"
|
||||
|
||||
const int Mover::propagationMethod = getParameter("propagationMethod");
|
||||
const double Mover::dt_s = getParameter("dt_s");
|
||||
|
||||
void Mover::moveParticle(Particle *movePart, const double &distance_m) {
|
||||
this->movePart = movePart;
|
||||
if (propagationMethod==0) {
|
||||
do_DriftApproximationMovement(distance_m);
|
||||
} else if (propagationMethod==1) {
|
||||
do_BorisPushMovement(distance_m);
|
||||
} else {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::move_electron: propagationMethod="<<propagationMethod<<" not valid.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
// Drift Approximation: Assume constant B and only movement out in z=0, z=wgtsLength_m...
|
||||
void Mover::do_DriftApproximationMovement(const double &distance_m) {
|
||||
vec3 oldLoc_m = movePart->get_Location_m();
|
||||
vec3 newLoc_m = oldLoc_m;
|
||||
|
||||
double znew_m = getDrift_znew_m(distance_m);
|
||||
doDrift_WallInteraction(&oldLoc_m, &znew_m);
|
||||
newLoc_m[2] = znew_m;
|
||||
|
||||
movePart->set_Location_m(newLoc_m);
|
||||
Log->log_Particle(*movePart,oldLoc_m);
|
||||
}
|
||||
double Mover::getDrift_znew_m(const double &distance_m) {
|
||||
double zold_m = movePart->get_Location_m()[2];
|
||||
|
||||
vec3 v_ms = movePart->get_Speed_ms();
|
||||
double vTotAbs_ms = get_vecAbs(v_ms);
|
||||
double vForwardAbs_ms = get_vecAbs(vec3(0,0,v_ms[2]));
|
||||
double zDir = v_ms[2] < 0 ? -1 : 1;
|
||||
|
||||
double znew_m = zold_m + zDir*vForwardAbs_ms/vTotAbs_ms * distance_m;
|
||||
return (znew_m);
|
||||
}
|
||||
|
||||
void Mover::doDrift_WallInteraction(vec3 *oldLoc_m, double *znew_m) {
|
||||
if (*znew_m >= Kat->get_z_WGTSend_m()) { // Moveing into Spectrometer and reversing Speed.
|
||||
vec3 reverseLoc_m = *oldLoc_m;
|
||||
|
||||
// Log Movement before Reflection
|
||||
reverseLoc_m[2] = Kat->get_z_WGTSend_m();
|
||||
movePart->set_Location_m(reverseLoc_m);
|
||||
Log->log_Particle(*movePart,*oldLoc_m);
|
||||
|
||||
// Final Movement
|
||||
*oldLoc_m = reverseLoc_m;
|
||||
*znew_m = Kat->get_z_WGTSend_m() - (*znew_m - Kat->get_z_WGTSend_m());
|
||||
movePart->set_Speed_ms( -1*(movePart->get_Speed_ms()) );
|
||||
}
|
||||
if (*znew_m <= Kat->get_z_RW_m()) {
|
||||
*znew_m = Kat->get_z_RW_m();
|
||||
}
|
||||
}
|
||||
|
||||
void Mover::do_BorisPushMovement(const double &distance_m) {
|
||||
vec3 loc_m, E_Vm ,B_T;
|
||||
// Prepare detection for change of z direction for logging
|
||||
double oldzDir = movePart->get_Speed_ms()[2] < 0 ? -1 : 1;
|
||||
vec3 oldLoc_m = movePart->get_Location_m();
|
||||
|
||||
double traveledDistance_m = 0;
|
||||
while (traveledDistance_m < distance_m) {
|
||||
loc_m = movePart->get_Location_m();
|
||||
E_Vm = Kat->getElField_Vm(loc_m);
|
||||
B_T = Kat->getMagField_T(loc_m);
|
||||
|
||||
traveledDistance_m += doBoris_singleStep_m(E_Vm, B_T);
|
||||
if (doBoris_WallInteraction() == true) {
|
||||
Log->log_Particle(*movePart, oldLoc_m);
|
||||
return;
|
||||
}
|
||||
doBoris_LogzDirChange(&oldzDir, &oldLoc_m); // Log if z direction changes, and adapt quantities
|
||||
}
|
||||
Log->log_Particle(*movePart, oldLoc_m);
|
||||
return;
|
||||
}
|
||||
|
||||
double Mover::doBoris_singleStep_m(const vec3 &E_Vm , const vec3 &B_T) {
|
||||
double distance_m;
|
||||
vec3 x_m = movePart->get_Location_m();
|
||||
vec3 v_ms = movePart->get_Speed_ms();
|
||||
x_m += dt_s/2 * v_ms;
|
||||
distance_m = dt_s/2 * get_vecAbs(v_ms);
|
||||
doBoris_speedChange(E_Vm , B_T);
|
||||
x_m += dt_s/2 * v_ms;
|
||||
distance_m += dt_s/2 * get_vecAbs(v_ms);
|
||||
movePart->set_Location_m(x_m);
|
||||
return(distance_m);
|
||||
}
|
||||
|
||||
void Mover::doBoris_speedChange(const vec3 &E_Vm, const vec3 &B_T) {
|
||||
double q_C = movePart->get_Charge_nat() * e_C;
|
||||
double m_kg = movePart->get_Mass_eV() * e_C/c_ms/c_ms;
|
||||
vec3 v_ms = movePart->get_Speed_ms();
|
||||
|
||||
vec3 t = q_C*dt_s/(2*m_kg) * B_T;
|
||||
vec3 s = (2*t)/(1+dot(t,t));
|
||||
vec3 vMinus_ms = v_ms + (q_C*E_Vm*dt_s)/(2*m_kg);
|
||||
vec3 vPrime_ms = vMinus_ms + cross(vMinus_ms,t);
|
||||
vec3 vPlus_ms = vMinus_ms + cross(vPrime_ms,s);
|
||||
v_ms = vPlus_ms + q_C/m_kg*E_Vm*0.5*dt_s;
|
||||
movePart->set_Speed_ms(v_ms);
|
||||
}
|
||||
|
||||
bool Mover::doBoris_WallInteraction() {
|
||||
vec3 loc_m = movePart->get_Location_m();
|
||||
double r_m = movePart->get_Radius_m();
|
||||
if (loc_m[2]<=Kat->get_z_RW_m()) { // Rear Wall Termination
|
||||
vec3 newLoc_m = movePart->get_Location_m();
|
||||
newLoc_m[2] = 0;
|
||||
movePart->set_Location_m(newLoc_m);
|
||||
return (true);
|
||||
}
|
||||
if (r_m>=Kat->get_radius_m()) { // WGTS Wall Termination
|
||||
vec3 newLoc_m = movePart->get_Location_m();
|
||||
double z_m = newLoc_m[2];
|
||||
newLoc_m[2] = 0;
|
||||
newLoc_m = (Kat->get_radius_m() * 1.01)/get_vecAbs(newLoc_m) * newLoc_m; //1.01 to move Particle slightly out of WGTS
|
||||
newLoc_m[2] = z_m;
|
||||
return (true);
|
||||
}
|
||||
if (loc_m[2]>=Kat->get_z_WGTSend_m()) { // Spectrometer Reflection
|
||||
movePart->set_Speed_ms( -1*(movePart->get_Speed_ms()) );
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
void Mover::doBoris_LogzDirChange(double *oldzDir, vec3 *oldLoc_m) {
|
||||
double zDir = movePart->get_Speed_ms()[2] < 0 ? -1 : 1;
|
||||
if (*oldzDir != zDir) {
|
||||
Log->log_Particle(*movePart, *oldLoc_m);
|
||||
*oldzDir = zDir;
|
||||
*oldLoc_m = movePart->get_Location_m();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// mover.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef mover_hpp
|
||||
#define mover_hpp
|
||||
|
||||
#include "functions.hpp"
|
||||
#include "katrin.hpp"
|
||||
#include "particle.hpp"
|
||||
#include "logger.hpp"
|
||||
|
||||
// Mover: Moves Particles within WGTS using parameter propagationMethod to determine Method.
|
||||
// Also Logging during movement
|
||||
class Mover {
|
||||
public:
|
||||
Mover(Katrin *Kat, H5_Logger *Log) {
|
||||
this->Kat = Kat;
|
||||
this->Log = Log;
|
||||
};
|
||||
|
||||
void moveParticle(Particle *movePart, const double &distance_m);
|
||||
|
||||
private:
|
||||
void do_DriftApproximationMovement(const double &distance_m);
|
||||
double getDrift_znew_m(const double &distance_m);
|
||||
void doDrift_WallInteraction(vec3 *oldLoc_m, double *znew_m);
|
||||
|
||||
void do_BorisPushMovement(const double &distance_m);
|
||||
double doBoris_singleStep_m(const vec3 &E_Vm , const vec3 &B_T);
|
||||
void doBoris_speedChange(const vec3 &E_Vm, const vec3 &B_T);
|
||||
bool doBoris_WallInteraction();
|
||||
void doBoris_LogzDirChange(double *oldzDir, vec3 *oldLoc_m);
|
||||
|
||||
static const int propagationMethod;
|
||||
static const double dt_s;
|
||||
|
||||
Particle *movePart;
|
||||
|
||||
Katrin *Kat;
|
||||
H5_Logger *Log;
|
||||
};
|
||||
#endif /* mover_hpp */
|
||||
@@ -74,25 +74,4 @@ Particle::Particle(double mass_eV, double charge_e,vec3 loc_m, vec3 speed_ms, do
|
||||
s = spec;
|
||||
}
|
||||
|
||||
double Particle::do_BorisStep_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 * get_SpeedAbs_ms();
|
||||
this->doBoris_SpeedChange(E_Vm , B_T , dt_s);
|
||||
x_m += dt_s/2 * v_ms;
|
||||
distance_m += dt_s/2 * get_SpeedAbs_ms();
|
||||
return(distance_m);
|
||||
}
|
||||
|
||||
void Particle::doBoris_SpeedChange(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*Z * 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;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ std::ostream& operator<<(std::ostream& os, const species& SpecOut);
|
||||
|
||||
class Particle {
|
||||
public:
|
||||
Particle() {};
|
||||
Particle(double mass_eV, double charge_e,vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum, species spec);
|
||||
|
||||
protected:
|
||||
@@ -34,35 +35,39 @@ protected:
|
||||
unsigned int Id;
|
||||
unsigned int parentId;
|
||||
|
||||
|
||||
public:
|
||||
// Get Properties Methods
|
||||
double get_Mass_eV() { return(m_eV); }
|
||||
double get_Charge_e() { return(Z); }
|
||||
vec3 get_Location_m() { return(x_m); }
|
||||
vec3 get_Speed_ms() { return(v_ms); }
|
||||
species get_Species() {return(s); }
|
||||
double get_Id() { return(Id); }
|
||||
double get_ParentId() { return(parentId); }
|
||||
double get_Mass_eV() { return(m_eV); };
|
||||
double get_Charge_nat() { return(Z); };
|
||||
vec3 get_Location_m() const { return(x_m); };
|
||||
vec3 get_Speed_ms() const { return(v_ms); };
|
||||
species get_Species() const {return(s); };
|
||||
double get_Id() const { return(Id); };
|
||||
double get_ParentId() const { return(parentId); };
|
||||
|
||||
// Get Properties
|
||||
double get_Radius_m() { return ( sqrt( pow(x_m[0],2) + pow(x_m[1],2) ) ); }
|
||||
double get_SpeedAbs_ms() { return ( get_vecAbs(v_ms) ); }
|
||||
double get_EKin_eV() { return ( get_Ekin_eV_from_speed(get_SpeedAbs_ms(), m_eV) ); }
|
||||
double get_Radius_m() { return ( sqrt( pow(x_m[0],2) + pow(x_m[1],2) ) ); } ;
|
||||
double get_SpeedAbs_ms() const { return ( get_vecAbs(v_ms) ); } ;
|
||||
double get_EKin_eV() const { return ( get_Ekin_eV_from_speed(v_ms, m_eV) ); } ;
|
||||
|
||||
// Set Properties Methods
|
||||
void set_Location_m(blitz::TinyVector<double, 3> xnew_m) {x_m = xnew_m; };
|
||||
void set_Speed_ms(blitz::TinyVector<double, 3> vnew_ms) {v_ms = vnew_ms; };
|
||||
|
||||
//Boris Push: Propagate Flight for one timestep dt_s in E_Vm and B_T and returns distance.
|
||||
public:
|
||||
double do_BorisStep_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s);
|
||||
protected:
|
||||
void doBoris_SpeedChange(blitz::TinyVector<double, 3> E_Vm,blitz::TinyVector<double, 3> B_T , double dt_s);
|
||||
|
||||
|
||||
public:
|
||||
friend std::ostream& operator<<(std::ostream& os, const Particle& partOut);
|
||||
};
|
||||
|
||||
class ParticleBuilder {
|
||||
public:
|
||||
ParticleBuilder() {};
|
||||
|
||||
Particle createElectron(vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum) const {
|
||||
return ( Particle(me_eV, -1 , loc_m, speed_ms, idnum, parentIdnum, electron));
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* particle_hpp */
|
||||
|
||||
@@ -19,60 +19,42 @@ using namespace std;
|
||||
|
||||
const long int Simulation::seed = getParameter("seed");
|
||||
const long int Simulation::numberTotalDecays = getParameter("numberTotalDecays");
|
||||
const int Simulation::propagationMethod = getParameter("propagationMethod");
|
||||
const int Simulation::maxInteractions = getParameter("maxInteractions");
|
||||
|
||||
Simulation::Simulation() {
|
||||
rngUni.seed(seed);
|
||||
updater_fraction = numberTotalDecays/100;
|
||||
}
|
||||
|
||||
void Simulation::doit() {
|
||||
while ( (numberDecays < numberTotalDecays) || (!electronQue.empty()) || (!tritiumIonQue.empty()) ) {
|
||||
if (electronQue.empty() && tritiumIonQue.empty()) {
|
||||
electronQue.push_back(Kat.injectElectron(numberTotalElectrons++, &rngUni, &rngNormal));
|
||||
InteractionOut IntOut;
|
||||
while ( (numberDecays < numberTotalDecays) || (!partQue.empty()) ) {
|
||||
if (partQue.empty()) {
|
||||
curPart = Inj.injectElectron(numberTotalElectrons);
|
||||
numberDecays++;
|
||||
}
|
||||
do_statusUpdate();
|
||||
if (!electronQue.empty()) {
|
||||
process_firstElectron();
|
||||
numberTotalElectrons++;
|
||||
do_statusUpdate();
|
||||
} else {
|
||||
process_firstTIon();
|
||||
curPart = partQue.front();
|
||||
partQue.pop_front();
|
||||
}
|
||||
while (!Term.check_Termination(curPart)) {
|
||||
mfp = 1/Inter.get_macroSigma_m2(curPart);
|
||||
Mov.moveParticle(&curPart, mfp);
|
||||
if (!Term.check_Termination(curPart)) {
|
||||
IntOut = Inter.do_Interaction(&curPart);
|
||||
//appy_Inter_Output(IntOut);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void Simulation::process_firstElectron() {
|
||||
int numberInteractionsThisElectron = 0;
|
||||
actionElectronPtr = &electronQue.front();
|
||||
while (!Kat.check_Termination (*actionElectronPtr) && !check_NumberInteractions(numberInteractionsThisElectron)) {
|
||||
move_electron(actionElectronPtr, &Log);
|
||||
if (!Kat.check_Termination (*actionElectronPtr) ) {
|
||||
do_interaction(actionElectronPtr);
|
||||
void Simulation::do_statusUpdate() {
|
||||
if (numberDecays%updater_fraction == 0){
|
||||
if (updater_numberOfPrevious!=numberDecays) {
|
||||
cout<<numberDecays<<"/"<<numberTotalDecays<<endl;
|
||||
}
|
||||
}
|
||||
electronQue.pop_front();
|
||||
}
|
||||
|
||||
void Simulation::process_firstTIon() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool Simulation::check_NumberInteractions(int &numberInteractionsThisElectron) {
|
||||
if (maxInteractions == 0) {
|
||||
return(false);
|
||||
}
|
||||
|
||||
if (numberInteractionsThisElectron < maxInteractions) {
|
||||
numberInteractionsThisElectron++;
|
||||
return(false);
|
||||
} else {
|
||||
return(true);
|
||||
updater_numberOfPrevious = numberDecays;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void Simulation::doTC6() {
|
||||
cout<<endl<<"Simulation::doTC6: Doing Testcase 6."<<endl<<endl;
|
||||
parameterCheck_TC6();
|
||||
@@ -89,28 +71,6 @@ void Simulation::doTC6() {
|
||||
}
|
||||
};
|
||||
|
||||
void Simulation::do_statusUpdate() {
|
||||
if (numberDecays%updater_fraction == 0){
|
||||
if (updater_numberOfPrevious!=numberDecays) {
|
||||
cout<<numberDecays<<"/"<<numberTotalDecays<<endl;
|
||||
}
|
||||
updater_numberOfPrevious = numberDecays;
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::move_electron(Electron *moveElectron, H5_Logger *Log) {
|
||||
double MFP_m = Kat.get_MFP_m(&electronQue.front());
|
||||
if (propagationMethod==0) {
|
||||
Kat.do_DriftApproximationMovement(moveElectron, MFP_m, Log);
|
||||
} else if (propagationMethod==1) {
|
||||
Kat.do_BorisPushMovement(moveElectron, MFP_m, Log); // If moved outside set v = 0,0,0;
|
||||
} else {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::move_electron: propagationMethod="<<propagationMethod<<" not valid.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::do_interaction(Electron *interactElectron) {
|
||||
vec3 newLoc_m = electronQue.front().get_Location_m();
|
||||
if (Kat.check_Termination(*interactElectron)) {
|
||||
@@ -118,13 +78,13 @@ void Simulation::do_interaction(Electron *interactElectron) {
|
||||
ss<<"Simulation::do_interaction: Particle already terminated.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
int process = interactElectron->roll_Interaction(Kat.getFlowSpeedT2_ms(newLoc_m),&rngUni);
|
||||
int process = interactElectron->roll_Interaction(Kat.get_T2_flowSpeed_ms(newLoc_m),&rngUni);
|
||||
switch (process) {
|
||||
case 1: // Elastic Scattering
|
||||
interactElectron->do_elaScattering(Kat.getTotSpeedT2_ms(newLoc_m, &rngUni, &rngNormal) , &rngUni);
|
||||
interactElectron->do_elaScattering(Kat.roll_T2_speed_ms(newLoc_m, &rngUni, &rngNormal) , &rngUni);
|
||||
break;
|
||||
case 2: // Ionization
|
||||
electronQue.push_back( interactElectron->do_Ionization(Kat.getTotSpeedT2_ms(newLoc_m, &rngUni, &rngNormal), numberTotalElectrons, &rngUni) );
|
||||
electronQue.push_back( interactElectron->do_Ionization(Kat.roll_T2_speed_ms(newLoc_m, &rngUni, &rngNormal), numberTotalElectrons, &rngUni) );
|
||||
numberTotalElectrons++;
|
||||
// Update Ions...
|
||||
break;
|
||||
@@ -151,3 +111,4 @@ void Simulation::parameterCheck_TC6() {
|
||||
throw MyException("Simulation::parameterCheck_TC6: Some Parameter is wrong");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -11,43 +11,55 @@
|
||||
|
||||
|
||||
#include "katrin.hpp"
|
||||
#include "electron.hpp"
|
||||
#include "tritiumion.hpp"
|
||||
#include "injector.hpp"
|
||||
#include "mover.hpp"
|
||||
#include "terminator.hpp"
|
||||
#include "interaction_processor.hpp"
|
||||
#include "interaction_builder.hpp"
|
||||
|
||||
#include "particle.hpp"
|
||||
#include <deque>
|
||||
|
||||
|
||||
class Simulation {
|
||||
public:
|
||||
Simulation();
|
||||
|
||||
Simulation() : Kat(&rngUni, &rngNormal),
|
||||
Inj(&Kat, &rngUni, &rngNormal),
|
||||
Log(&Kat),
|
||||
Mov(&Kat, &Log),
|
||||
Inter(&Kat, &rngUni, &rngNormal),
|
||||
Term(&Kat) {
|
||||
rngUni.seed(seed);
|
||||
rngNormal.seed(seed);
|
||||
updater_fraction = numberTotalDecays/100;
|
||||
updater_fraction = updater_fraction==0 ? 1 : updater_fraction;
|
||||
InteractionBuilder InterBuilder(&Kat, &rngUni, &rngNormal);
|
||||
Inter = InterBuilder.build_InteractionProcessor();
|
||||
}
|
||||
void doit();
|
||||
private:
|
||||
void process_firstElectron();
|
||||
void process_firstTIon();
|
||||
|
||||
|
||||
void do_statusUpdate();
|
||||
void move_electron(Electron *moveElectron, H5_Logger *Log);
|
||||
void do_interaction(Electron *interactElectron);
|
||||
bool check_NumberInteractions(int &numberInteractionsThisElectron);
|
||||
|
||||
Katrin Kat;
|
||||
Injector Inj;
|
||||
H5_Logger Log;
|
||||
Mover Mov;
|
||||
InteractionProcessor Inter;
|
||||
Terminator Term;
|
||||
|
||||
ranlib::Uniform<double> rngUni;
|
||||
ranlib::NormalUnit<double> rngNormal;
|
||||
|
||||
// Electrons
|
||||
double mfp;
|
||||
std::deque<Particle> partQue;
|
||||
Particle curPart;
|
||||
//InterOutput IntOut;
|
||||
|
||||
int numberTotalElectrons = 0;
|
||||
int numberDecays = 0;
|
||||
std::deque<Electron> electronQue;
|
||||
Electron *actionElectronPtr;
|
||||
|
||||
// Ions
|
||||
int numberTotalIons = 0;
|
||||
std::deque<TritiumIon> tritiumIonQue;
|
||||
|
||||
// Updater
|
||||
int updater_numberOfPrevious = 0;
|
||||
int updater_fraction;
|
||||
|
||||
@@ -55,7 +67,6 @@ private:
|
||||
static const long int seed;
|
||||
static const long int numberTotalDecays;
|
||||
|
||||
static const int propagationMethod;
|
||||
static const int maxInteractions;
|
||||
public:
|
||||
void doTC6();
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// terminator.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "terminator.hpp"
|
||||
|
||||
const double Terminator::cutoffEnergy_eV = getParameter("cutoffEnergy_eV");
|
||||
|
||||
bool Terminator::check_Termination(const Particle &checkPart) {
|
||||
double Ekin_eV = checkPart.get_EKin_eV();
|
||||
vec3 loc_m = checkPart.get_Location_m();
|
||||
bool E_check = check_EnergyTermination(Ekin_eV);
|
||||
bool loc_check = check_WallTermination(loc_m);
|
||||
return(E_check || loc_check);
|
||||
}
|
||||
|
||||
bool Terminator::check_EnergyTermination(const double &Ekin_eV) {
|
||||
if (Ekin_eV<=cutoffEnergy_eV) {
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
bool Terminator::check_WallTermination(const vec3 &loc_m) {
|
||||
double z_m = loc_m[2];
|
||||
double r_m = sqrt( pow(loc_m[0],2) + pow(loc_m[1],2) );
|
||||
if (z_m <=Kat->get_z_RW_m()) {
|
||||
return (true);
|
||||
}
|
||||
if (r_m >= Kat->get_radius_m()) {
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// terminator.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef terminator_hpp
|
||||
#define terminator_hpp
|
||||
|
||||
#include "katrin.hpp"
|
||||
#include "particle.hpp"
|
||||
|
||||
// Terminate Electrons
|
||||
class Terminator {
|
||||
public:
|
||||
Terminator(Katrin *Kat) {
|
||||
this->Kat = Kat;
|
||||
}
|
||||
|
||||
bool check_Termination(const Particle &checkPart);
|
||||
private:
|
||||
bool check_EnergyTermination(const double &Ekin_eV);
|
||||
bool check_WallTermination(const vec3 &loc_m);
|
||||
|
||||
|
||||
static const double cutoffEnergy_eV;
|
||||
|
||||
Katrin *Kat;
|
||||
};
|
||||
|
||||
#endif /* terminator_hpp */
|
||||
@@ -0,0 +1,9 @@
|
||||
//
|
||||
// tritium_interactions.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "tritium_interactions.hpp"
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// tritium_interactions.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef tritium_interactions_hpp
|
||||
#define tritium_interactions_hpp
|
||||
|
||||
#include "interaction_species.hpp"
|
||||
|
||||
/*
|
||||
class TIon_InteractionProcessor : public Base_ParticleInteractionsProcessors {
|
||||
public:
|
||||
TIon_InteractionProcessor(Katrin *Kat, UniRNG *rngUni, NormalRNG *rngNormal) : Base_ParticleInteractionsProcessors(Kat, rngUni, rngNormal) {};
|
||||
|
||||
InterOutput do_Interaction(Particle *interPart);
|
||||
private:
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
#endif /* tritium_interactions_hpp */
|
||||
@@ -1,9 +0,0 @@
|
||||
//
|
||||
// tritiumion.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 11.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "tritiumion.hpp"
|
||||
@@ -1,40 +0,0 @@
|
||||
//
|
||||
// tritiumion.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 11.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef tritiumion_hpp
|
||||
#define tritiumion_hpp
|
||||
|
||||
#include "particle.hpp"
|
||||
#include "function_container.hpp"
|
||||
|
||||
class TritiumIon : public Particle {
|
||||
public:
|
||||
TritiumIon(vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum) : Particle(mT2_eV, 1 , loc_m, speed_ms, idnum, parentIdnum, electron) {};
|
||||
|
||||
// Interactions
|
||||
public:
|
||||
double get_SigmaTotal_m2(vec3 speedT2_ms);
|
||||
std::vector<double> get_SigmaVector_m2(vec3 speedT2_ms);
|
||||
int roll_Interaction(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
private:
|
||||
static const int ionOn;
|
||||
static const int elaOn;
|
||||
|
||||
// Elastic Scattering
|
||||
public:
|
||||
void do_elaScattering (vec3 speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
double get_elaSigma_m2(vec3 speedT2_ms);
|
||||
protected:
|
||||
double get_elaEta(vec3 speedLab_ms);
|
||||
double roll_elaTheta(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
void do_elaKinetics(vec3 speedT2_ms, double theta, double phi);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* tritiumion_hpp */
|
||||
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// uehara_eT2_elastic.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 29.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "uehara_eT2_elastic.hpp"
|
||||
/*
|
||||
double e_T2_elasticScattering::get_macroSigma_m2(const Particle &interPart) const {
|
||||
vec3 speedLab_ms = get_speedLab_ms(interPart);
|
||||
double betaLab = get_vecAbs(speedLab_ms)/c_ms;
|
||||
double elaEta = get_elaEta(speedLab_ms);
|
||||
double numerator = pi*ZT2*(ZT2+1)*re_m*re_m * (1-pow(betaLab,2));
|
||||
double denominator = elaEta * (elaEta+1)*pow(betaLab,4);
|
||||
return (numerator/denominator);
|
||||
}
|
||||
|
||||
InteractionOut e_T2_elasticScattering::do_Interaction (Particle *interPart) const {
|
||||
// Here theta and phi are COM-Angles.... prob not correct. For m1 << m2 COM - Angle ~ Lab Angle
|
||||
speedT2_ms
|
||||
double thetaLab = roll_elaTheta(speedLab_ms, rngUni);
|
||||
double phiLab = rngUni->random() * 2 * pi;
|
||||
do_elaKinetics(speedT2_ms, thetaLab, phiLab);
|
||||
}
|
||||
|
||||
vec3 e_T2_elasticScattering::get_speedLab_ms(const Particle &interPart) const {
|
||||
vec3 v_ms = interPart.get_Speed_ms();
|
||||
vec3 speedT2_ms = Kat->roll_totEqSpeed_ms(interPart.get_Location_m(),rngUni,rngNormal);
|
||||
vec3 speedLab_ms = v_ms - speedT2_ms;
|
||||
}
|
||||
|
||||
double e_T2_elasticScattering::get_elaEta(vec3 speedLab_ms) const {
|
||||
double Ekin_eVLab_eV = get_Ekin_eV_from_speed(speedLab_ms, me_eV);
|
||||
double betaLab = get_vecAbs(speedLab_ms)/c_ms;
|
||||
double etac = (Ekin_eVLab_eV < 50e3)? 1.198 : 1.13+3.76*pow(ZT2/(137*betaLab),2);
|
||||
double elaTau = Ekin_eVLab_eV/me_eV;
|
||||
return (etac * 1.7e-5 * pow(ZT2,2./3.) /(elaTau*(elaTau+2) ));
|
||||
}
|
||||
|
||||
double e_T2_elasticScattering::roll_elaTheta(vec3 speedLab_ms) const {
|
||||
double betaLab = get_vecAbs(speedLab_ms)/c_ms;
|
||||
double elaEta = get_elaEta(speedLab_ms);
|
||||
double const1 = 2*pi/get_elaSigma_m2(speedT2_ms)*ZT2*(ZT2+1)*re_m*re_m*(1- pow(betaLab,2) )* pow(betaLab,-4);
|
||||
double fac = pow( rngUni->random()/const1-pow(2*elaEta,-1) , -1 ) +1+2*elaEta;
|
||||
double theta = acos(fac);
|
||||
return(theta);
|
||||
}
|
||||
|
||||
void e_T2_elasticScattering::do_elaKinetics(vec3 speedT2_ms, double theta, double phi) const {
|
||||
// Following Landau Lifschitz I Chapter 4 Paragraph 17
|
||||
vec3 n0, speedLab_ms, v1New_ms, v2New_ms;
|
||||
speedLab_ms = v_ms - speedT2_ms;
|
||||
n0 = get_Newdirection(speedLab_ms, thetaLab, phiLab);
|
||||
v1New_ms = (mT2_eV*get_vecAbs(speedLab_ms)*n0 + m_eV*speedLab_ms)/(m_eV+mT2_eV) + speedT2_ms;
|
||||
//v2New_ms = (-1*mass_eV*get_vecAbs(speedLab_ms)*n0 + mass_eV*speedLab_ms)/(mass_eV+mT2_eV()) + speedT2_ms;
|
||||
v_ms = v1New_ms; // In "Real frame": both particles moving
|
||||
return;
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// uehara_eT2_elastic.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 29.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef uehara_eT2_elastic_hpp
|
||||
#define uehara_eT2_elastic_hpp
|
||||
|
||||
/*
|
||||
namespace Uehara_eT2_Elastic {
|
||||
double get_TCS(double Ekin_eV);
|
||||
double get_SDCS(double Ekin_eV, double theta);
|
||||
|
||||
|
||||
double get_elaEta(vec3 speedLab_ms) const {
|
||||
double Ekin_eVLab_eV = get_Ekin_eV_from_speed(speedLab_ms, me_eV);
|
||||
double betaLab = get_vecAbs(speedLab_ms)/c_ms;
|
||||
double etac = (Ekin_eVLab_eV < 50e3)? 1.198 : 1.13+3.76*pow(ZT2/(137*betaLab),2);
|
||||
double elaTau = Ekin_eVLab_eV/me_eV;
|
||||
return (etac * 1.7e-5 * pow(ZT2,2./3.) /(elaTau*(elaTau+2) ));
|
||||
}
|
||||
*/
|
||||
#endif /* uehara_eT2_elastic_hpp */
|
||||
Reference in New Issue
Block a user