Minior Changes on new structure, exported elastic cross section to seperate file.
Please enter the commit message for your changes. Lines starting
This commit is contained in:
@@ -8,81 +8,89 @@
|
||||
|
||||
#include "BED_eT2_ionization.hpp"
|
||||
|
||||
#include "functions.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
#include "constants.h"
|
||||
#include "error_types.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace BED_eT2_Ionization {
|
||||
double get_TCS(double T_eV) {
|
||||
if (T_eV<=0) {
|
||||
stringstream ss;
|
||||
ss<<"get_TCS(double T_eV): Input energy T_eV="<<T_eV<<" eV < 0.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
if (T_eV<=B_eV) {
|
||||
return (0);
|
||||
} else {
|
||||
double t = get_t(T_eV);
|
||||
double fac = S_m2/(t+u+1);
|
||||
double sum1 = get_Dt(t)*log(t);
|
||||
double sum2 = (2-Ni/N)*( (t-1)/t - log(t)/(t+1) );
|
||||
return(fac*(sum1 + sum2) );
|
||||
}
|
||||
const double BED_eT2_Ionization::S_m2 = 5.4721e-20;
|
||||
const double BED_eT2_Ionization::B_eV = EionT2_eV;
|
||||
const double BED_eT2_Ionization::u = 1.664;
|
||||
const double BED_eT2_Ionization::N = 2;
|
||||
const double BED_eT2_Ionization::Ni = 1.173;
|
||||
const double BED_eT2_Ionization::c[4] = {1.1262 , 6.3982 , -7.8055, 2.1449} ;
|
||||
|
||||
|
||||
double BED_eT2_Ionization::calc_TCS(const double &T_eV) {
|
||||
if (T_eV<=0) {
|
||||
stringstream ss;
|
||||
ss<<"calc_TCS(double T_eV): Input energy T_eV="<<T_eV<<" eV < 0.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
double get_SDCS (double T_eV, double W_eV) {
|
||||
if (T_eV<0) {
|
||||
stringstream ss;
|
||||
ss<<"getSDCS(double T_eV, double W_eV): Input energy T_eV="<<T_eV<<" eV < 0.";
|
||||
throw MyException(ss.str());
|
||||
} else if (W_eV<0) {
|
||||
stringstream ss;
|
||||
ss<<"getSDCS(double T_eV, double W_eV): Input energy W_eV="<<W_eV<<" eV < 0.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
if ( (T_eV<=B_eV) ||(W_eV >= (T_eV-B_eV) ) ) {
|
||||
return (0);
|
||||
} else {
|
||||
double t = get_t(T_eV);
|
||||
double w = get_w(W_eV);
|
||||
double fac = S_m2/B_eV/(t+u+1);
|
||||
double sum1 = (Ni/N - 2)/(t+1) * (1/(w+1) + 1/(t-w));
|
||||
double sum2 = (2-Ni/N) * (pow(w+1,-2) + pow(t-w,-2));
|
||||
double sum3 = log(t)/(N*(w+1)) * get_dfdw(w);
|
||||
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;
|
||||
for (int i=0;i<4;i++) {
|
||||
res += c[i]*pow(y,i+3);
|
||||
}
|
||||
return(res);
|
||||
}
|
||||
|
||||
inline double get_Dt(double t) {
|
||||
double yh = 2/(t+1);
|
||||
double res = 0;
|
||||
for (int i=0;i<4;i++) {
|
||||
res += c[i]/(i+3)*(1-pow(yh,i+3));
|
||||
}
|
||||
res = res/N;
|
||||
return(res);
|
||||
if (T_eV<=B_eV) {
|
||||
return (0);
|
||||
} else {
|
||||
double t = calc_t(T_eV);
|
||||
double fac = S_m2/(t+u+1);
|
||||
double sum1 = calc_Dt(t)*log(t);
|
||||
double sum2 = (2-Ni/N)*( (t-1)/t - log(t)/(t+1) );
|
||||
return(fac*(sum1 + sum2) );
|
||||
}
|
||||
}
|
||||
|
||||
double BED_eT2_Ionization::calc_SDCS (const double &T_eV, const double &W_eV) {
|
||||
if (T_eV<0) {
|
||||
stringstream ss;
|
||||
ss<<"getSDCS(double T_eV, double W_eV): Input energy T_eV="<<T_eV<<" eV < 0.";
|
||||
throw MyException(ss.str());
|
||||
} else if (W_eV<0) {
|
||||
stringstream ss;
|
||||
ss<<"getSDCS(double T_eV, double W_eV): Input energy W_eV="<<W_eV<<" eV < 0.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
if ( (T_eV<=B_eV) ||(W_eV >= (T_eV-B_eV) ) ) {
|
||||
return (0);
|
||||
} else {
|
||||
double t = calc_t(T_eV);
|
||||
double w = calc_w(W_eV);
|
||||
double fac = S_m2/B_eV/(t+u+1);
|
||||
double sum1 = (Ni/N - 2)/(t+1) * (1/(w+1) + 1/(t-w));
|
||||
double sum2 = (2-Ni/N) * (pow(w+1,-2) + pow(t-w,-2));
|
||||
double sum3 = log(t)/(N*(w+1)) * calc_dfdw(w);
|
||||
return(fac*(sum1 + sum2 + sum3));
|
||||
}
|
||||
}
|
||||
|
||||
double BED_eT2_Ionization::calc_t(const double &T_eV) {
|
||||
return(T_eV/B_eV);
|
||||
}
|
||||
|
||||
double BED_eT2_Ionization::calc_w(const double &W_eV) {
|
||||
return(W_eV/B_eV);
|
||||
}
|
||||
|
||||
double BED_eT2_Ionization::calc_dfdw(const double &w) {
|
||||
double y = 1/(w+1);
|
||||
double res = 0;
|
||||
for (int i=0;i<4;i++) {
|
||||
res += c[i]*pow(y,i+3);
|
||||
}
|
||||
return(res);
|
||||
}
|
||||
|
||||
double BED_eT2_Ionization::calc_Dt(const double &t) {
|
||||
double yh = 2/(t+1);
|
||||
double res = 0;
|
||||
for (int i=0;i<4;i++) {
|
||||
res += c[i]/(i+3)*(1-pow(yh,i+3));
|
||||
}
|
||||
res = res/N;
|
||||
return(res);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,25 +9,29 @@
|
||||
#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_eT2_Ionization {
|
||||
const double S_m2 = 5.4721e-20;
|
||||
const double B_eV = EionT2_eV;
|
||||
const double u = 1.664;
|
||||
const double N = 2;
|
||||
const double Ni = 1.173;
|
||||
const double c[4] = {1.1262 , 6.3982 , -7.8055, 2.1449} ;
|
||||
class BED_eT2_Ionization {
|
||||
static const double S_m2;
|
||||
static const double B_eV;
|
||||
static const double u;
|
||||
static const double N;
|
||||
static const double Ni;
|
||||
static const double c[4];
|
||||
public:
|
||||
BED_eT2_Ionization(){};
|
||||
|
||||
double get_TCS(double T_eV);
|
||||
double get_SDCS(double T_eV, double W_eV);
|
||||
static double calc_TCS(const double &T_eV);
|
||||
static double calc_SDCS(const double &T_eV, const double &W_eV);
|
||||
|
||||
double get_t(double T);
|
||||
double get_w(double W);
|
||||
private:
|
||||
static double calc_t(const double &T);
|
||||
static double calc_w(const double &W);
|
||||
|
||||
double get_dfdw(double w);
|
||||
double get_Dt(double t);
|
||||
}
|
||||
static double calc_dfdw(const double &w);
|
||||
static double calc_Dt(const double &t);
|
||||
};
|
||||
|
||||
|
||||
#endif /* BED_eT2_ionization_hpp */
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//
|
||||
// constants.hpp
|
||||
// constants.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 08.10.18.
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef constants_hpp
|
||||
#define constants_hpp
|
||||
#ifndef constants_h
|
||||
#define constants_h
|
||||
|
||||
|
||||
typedef const double constant;
|
||||
@@ -32,5 +32,5 @@ constant BetaDecayConst = 1.2072343416696292e-47;
|
||||
constant TritiumDecayEndpoint_eV = 18.574e3;
|
||||
|
||||
|
||||
#endif /* constants_hpp */
|
||||
#endif /* constants_h */
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
#ifndef container_base_functions_h
|
||||
#define container_base_functions_h
|
||||
|
||||
#include "functions.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "error_types.h"
|
||||
#include "read_system.h"
|
||||
#include "constants.h"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
@@ -18,6 +19,10 @@
|
||||
#include <sstream>
|
||||
#include <deque>
|
||||
|
||||
#include "blitz/tinyvec2.h"
|
||||
#include "blitz/array.h"
|
||||
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
typedef std::map<double,double> dim1Map;
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//
|
||||
|
||||
#include "density_container.hpp"
|
||||
|
||||
#include "blitz/tinyvec2.h"
|
||||
|
||||
WGTS_Geo::WGTS_Geo(double z_min_m, double z_max_m, double r_max_m, vec3 zrphi_numBins) {
|
||||
this->z_min_m = z_min_m;
|
||||
|
||||
@@ -8,10 +8,14 @@
|
||||
|
||||
#include "electron_interactions.hpp"
|
||||
|
||||
#include "read_system.h"
|
||||
|
||||
#include "uehara_eT2_elastic.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);
|
||||
double Ekin_eV = interPart.get_EKin_eV();
|
||||
double microSigma_m2 = Uehara_eT2_ElasticScattering::calc_TCS(Ekin_eV);
|
||||
vec3 loc_m = interPart.get_Location_m();
|
||||
double nT2_m3 = Kat->getTritiumDensity_m3(loc_m);
|
||||
return (microSigma_m2*nT2_m3);
|
||||
@@ -22,49 +26,26 @@ InteractionOut e_T2_elasticScattering::do_Interaction (Particle *interPart) cons
|
||||
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 T_eV = calc_Ekin_eV_from_speed(vLab_ms, me_eV);
|
||||
double thetaLab = Uehara_eT2_ElasticScattering::roll_theta(T_eV, rngUni);
|
||||
double phiLab = rngUni->random() * 2 * pi;
|
||||
interPart->set_Speed_ms( get_vNew_ms(v_ms, vT2_ms, thetaLab, phiLab) );
|
||||
interPart->set_Speed_ms( calc_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 {
|
||||
vec3 e_T2_elasticScattering::calc_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;
|
||||
vec3 n0 = calc_newDirection(speedLab_ms, thetaLab, phiLab);
|
||||
vec3 vNew_ms = (mT2_eV*vec3Abs(speedLab_ms)*n0 + me_eV*speedLab_ms)/(me_eV+mT2_eV) + vT2_ms;
|
||||
//vec3 v2New_ms = (-1*mass_eV*vec3Abs(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");
|
||||
Average1D_FuncContainer e_T2_ionization::BED_TCS_average_container=Average1D_FuncContainer( getDataPath() + "BED_average_TCS.dat");
|
||||
Stacked2D_FuncContainer e_T2_ionization::BED_SDCS_stacked_container=Stacked2D_FuncContainer( getDataPath() + "BED_stacked_SDCS.dat");
|
||||
|
||||
|
||||
double e_T2_ionization::get_macroSigma_m2(const Particle &interPart) const {
|
||||
@@ -81,7 +62,7 @@ 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);
|
||||
double T_eV = calc_Ekin_eV_from_speed(v_ms, me_eV);
|
||||
if (T_eV < EionT2_eV) {
|
||||
throw MyException("Electron::do_Ionization: Ekin_eV < EIonT2_eV.");
|
||||
}
|
||||
@@ -95,12 +76,12 @@ InteractionOut e_T2_ionization::do_Interaction (Particle *interPart) const {
|
||||
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);
|
||||
double v1Absnew_ms = calc_Speed_from_Ekin_eV(E1_eV, me_eV);
|
||||
double v2Absnew_ms = calc_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);
|
||||
P1newDir = calc_newDirection(v_ms, theta1, phi1);
|
||||
P2newDir = calc_newDirection(v_ms, theta2, phi2);
|
||||
|
||||
vec3 vOff_ms = vLab_ms - v_ms;
|
||||
v1New_ms = v1Absnew_ms*P1newDir + vOff_ms;
|
||||
@@ -119,9 +100,9 @@ vec3 e_T2_ionization::roll_vLab_ms(const Particle &interPart) const {
|
||||
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);
|
||||
double T_eV = calc_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);
|
||||
T_eV = calc_Ekin_eV_from_speed(v_ms, me_eV);
|
||||
}
|
||||
return (T_eV);
|
||||
}
|
||||
|
||||
@@ -28,10 +28,7 @@ public:
|
||||
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;
|
||||
vec3 calc_vNew_ms(vec3 vOld_ms, vec3 vT2_ms, double thetaLab, double phiLab) const;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -47,7 +44,6 @@ class e_T2_ionization : public Interaction {
|
||||
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;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// error_types.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 30.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef error_types_h
|
||||
#define error_types_h
|
||||
|
||||
/*
|
||||
#include "constants.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
|
||||
#include <blitz/array.h>
|
||||
#include <blitz/tinyvec2.h>
|
||||
#include <random/uniform.h>
|
||||
#include <random/normal.h>
|
||||
*/
|
||||
#include <iostream>
|
||||
|
||||
struct MyException : public std::exception
|
||||
{
|
||||
std::string s;
|
||||
MyException(std::string errorMessage) : s(errorMessage) {}
|
||||
~MyException() throw () {}
|
||||
const char* what() const throw() { return s.c_str(); }
|
||||
};
|
||||
#endif /* error_types_h */
|
||||
@@ -56,7 +56,7 @@ inline double Base_FuncContainer::sampleValue_from_stackedMap (const dim1Map &st
|
||||
|
||||
// Base1D_Container
|
||||
// AddData
|
||||
void Base1D_FuncContainer::fillFromFunction(double (*f)(double), double minKey, double maxKey, int numpointsPerOrder) {
|
||||
void Base1D_FuncContainer::fillFromFunction(double (*f)(const double &), double minKey, double maxKey, int numpointsPerOrder) {
|
||||
int interval = numpointsPerOrder -1;
|
||||
int minI = floor(log10(minKey)*interval);
|
||||
int maxI = ceil(log10(maxKey)*interval);
|
||||
@@ -96,7 +96,7 @@ void Average1D_FuncContainer::set_Map(Edge1D_FuncContainer &edgeContainer) {
|
||||
|
||||
// edge2D_Container
|
||||
|
||||
void Edge2D_FuncContainer::get_Ionization_fromFunction(double (*f)(double,double), double minX, double maxX, int numpointsPerXOrder, int numYpoints) {
|
||||
void Edge2D_FuncContainer::get_Ionization_fromFunction(double (*f)(const double &, const double &), double minX, double maxX, int numpointsPerXOrder, int numYpoints) {
|
||||
int Xinterval = numpointsPerXOrder -1;
|
||||
int minXI = floor(log10(minX)*Xinterval);
|
||||
int maxXI = ceil(log10(maxX)*Xinterval);
|
||||
@@ -125,7 +125,7 @@ void Edge2D_FuncContainer::get_Ionization_fromFunction(double (*f)(double,double
|
||||
}
|
||||
}
|
||||
|
||||
void Edge2D_FuncContainer::get_Elastic_fromFunction(double (*f)(double,double), double minX, double maxX, int numpointsPerXOrder, int numpointsOverY) {
|
||||
void Edge2D_FuncContainer::get_Elastic_fromFunction(double (*f)(const double &, const double &), double minX, double maxX, int numpointsPerXOrder, int numpointsOverY) {
|
||||
int Xinterval = numpointsPerXOrder -1;
|
||||
int minXI = floor(log10(minX)*Xinterval);
|
||||
int maxXI = ceil(log10(maxX)*Xinterval);
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <random/uniform.h>
|
||||
|
||||
|
||||
|
||||
typedef std::map<double,double> dim1Map;
|
||||
typedef std::pair<double,double> dim1Pair;
|
||||
|
||||
@@ -33,7 +32,7 @@ public:
|
||||
Base1D_FuncContainer() {};
|
||||
Base1D_FuncContainer(std::string loadFilePath) {fillFromCSV(loadFilePath);};
|
||||
|
||||
void fillFromFunction(double (*f)(double), double minX, double maxX, int numpointsPerOrder);
|
||||
void fillFromFunction(double (*f)(const double &), double minX, double maxX, int numpointsPerOrder);
|
||||
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});};
|
||||
|
||||
@@ -101,8 +100,8 @@ public:
|
||||
|
||||
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);
|
||||
void get_Ionization_fromFunction(double (*f)(const double &, const double &), double minX, double maxX, int numpointsPerXOrder, int numpointsPerYOrder);
|
||||
void get_Elastic_fromFunction(double (*f)(const double &, const double &), double minX, double maxX, int numpointsPerXOrder, int numpointsOverY);
|
||||
};
|
||||
|
||||
// Average2D_Container:
|
||||
|
||||
@@ -1,270 +0,0 @@
|
||||
//
|
||||
// functions.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 07.02.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#include "functions.hpp"
|
||||
|
||||
#include "constants.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Read Parameters from file
|
||||
double getParameter(string parName) {
|
||||
string parpath = getEnv("parpath");
|
||||
string parfile = getEnv("parfile");
|
||||
if (parpath == "") {
|
||||
throw MyException("Parameter::getParameter: Environment variable parpath not defined.");
|
||||
}
|
||||
if (parfile == "") {
|
||||
throw MyException("Parameter::getParameter: Environment variable parfile not defined.");
|
||||
}
|
||||
parpath = makePath(parpath);
|
||||
string loadFilePath = parpath + parfile;
|
||||
ifstream fileStream(loadFilePath);
|
||||
|
||||
if (!fileStream.good()) {
|
||||
stringstream ss;
|
||||
ss<<"Parameter::getParameter: Could not open file.\n loadFilePath =\t"<<loadFilePath<<endl;
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
string lineFromFile;
|
||||
stringstream ss;
|
||||
string parNameTemp;
|
||||
double parTemp;
|
||||
bool lineReadError = false;
|
||||
|
||||
while (getline(fileStream, lineFromFile)) {
|
||||
removeLeadingWhites(lineFromFile);
|
||||
replaceDelimiter(lineFromFile);
|
||||
if ( checkIgnoreLine(lineFromFile) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ss.clear();
|
||||
ss.str(lineFromFile);
|
||||
|
||||
if (ss>>parNameTemp && ss>>parTemp) {
|
||||
if (parNameTemp == parName) {
|
||||
fileStream.close();
|
||||
return (parTemp);
|
||||
}
|
||||
} else {
|
||||
if (!lineReadError) {
|
||||
cout<<"Parameter::getParameter: Line in parameter file faulty. \n path =\t"<<loadFilePath<<endl;
|
||||
lineReadError = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ss.clear();
|
||||
ss.str("");
|
||||
ss<<"Parameter::getParameter: Parameter not found in file.\n parName =\t"<<parName<<"\n loadFilePath = \t"<<loadFilePath;
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
|
||||
//String Manipulations for Read in from files
|
||||
std::string getEnv (std::string envName) {
|
||||
char * val = getenv( envName.c_str() );
|
||||
return val == NULL ? std::string("") : std::string(val);
|
||||
}
|
||||
|
||||
string makePath (std::string path) {
|
||||
if (path.back() != '/') {
|
||||
path = path + '/';
|
||||
}
|
||||
return (path);
|
||||
}
|
||||
|
||||
bool checkIgnoreLine(std::string lineFromFile) {
|
||||
if (lineFromFile[0] =='#') {
|
||||
return true;
|
||||
} else if ( lineFromFile.empty() ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
void removeLeadingWhites(std::string &lineFromFile) {
|
||||
static const std::string WHITESPACE = " \n\r\t\f\v";
|
||||
size_t start = lineFromFile.find_first_not_of(WHITESPACE);
|
||||
lineFromFile = (start == std::string::npos) ? "" : lineFromFile.substr(start);
|
||||
return;
|
||||
}
|
||||
|
||||
void replaceDelimiter(std::string &lineFromFile) {
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ';', ' ');
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ',', ' ');
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), '=', ' ');
|
||||
return;
|
||||
}
|
||||
|
||||
// System read out
|
||||
string getTimeString() {
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
char buffer[80];
|
||||
time (&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
strftime(buffer,sizeof(buffer),"%Y%m%d",timeinfo);
|
||||
string str(buffer);
|
||||
return(str);
|
||||
}
|
||||
|
||||
string getHomebase() {
|
||||
std::string file = __FILE__;
|
||||
file.erase(file.length()-13);
|
||||
return(file);
|
||||
}
|
||||
|
||||
|
||||
// Calculate Kinematic Relations
|
||||
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.";
|
||||
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.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double gamma = get_gamma_from_beta(beta);
|
||||
return ( (gamma-1) * mass_eV );
|
||||
}
|
||||
|
||||
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.";
|
||||
throw MyException(ss.str());
|
||||
} else if (beta<0) {
|
||||
stringstream ss;
|
||||
ss<<"get_gamma_from_beta(): Input beta ="<<beta<<" negative.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
return( pow(1 - pow(beta,2),-0.5) ) ;
|
||||
}
|
||||
|
||||
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.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
double gamma = get_gamma_from_Ekin_eV(Ekin_eV, mass_eV);
|
||||
double beta = get_beta_from_gamma(gamma);
|
||||
return(beta * c_ms);
|
||||
}
|
||||
|
||||
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.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return (1. + Ekin_eV/mass_eV);
|
||||
}
|
||||
|
||||
double get_beta_from_gamma(const double &gamma) {
|
||||
if (gamma<1) {
|
||||
stringstream ss;
|
||||
ss<<"get_beta_from_gamma(): Input gamma ="<<gamma<<" smaller 1.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return( sqrt(1 - pow(gamma,-2)) );
|
||||
}
|
||||
|
||||
|
||||
// Operations on 3 dimensional Vectors
|
||||
double get_vecAbs(const vec3 &vec) {
|
||||
return( sqrt( pow(vec[0],2) + pow(vec[1],2) + pow(vec[2],2)) );
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
double A3 = sin(theta_change)*cos(phi_change);
|
||||
double A4 = A3*cos(theta_old) + cos(theta_change)*sin(theta_old);
|
||||
double A5 = sin(theta_change)*sin(phi_change);
|
||||
double A11 = A4*cos(phi_old) - A5*sin(phi_old);
|
||||
double A21 = A4*sin(phi_old) + A5*cos(phi_old);
|
||||
double theta_new = acos( cos(theta_old)*cos(theta_change)-A3*sin(theta_old) );
|
||||
|
||||
// Get right phi1, maybe more elegant way later. Problem comes from reverse functions only being on range of pi. So combine both statements to get proper phi over 2pi.
|
||||
int digits = 6;
|
||||
double fac = pow(10,digits);
|
||||
double phi_new = -1;
|
||||
double phi_new_candidates [4];
|
||||
phi_new_candidates[0] = acos( roundf ( A11/sin(theta_new) *fac)/fac );
|
||||
phi_new_candidates[1] = 2*pi - phi_new_candidates[0];
|
||||
phi_new_candidates[2] = asin ( roundf ( A21/sin(theta_new) *fac)/fac );
|
||||
phi_new_candidates[3] = pi - phi_new_candidates[2];
|
||||
phi_new_candidates[2] = (phi_new_candidates[2] > 0) ? phi_new_candidates[2] : 2*pi + phi_new_candidates[2];
|
||||
for (int i=0;i<3;i++) {
|
||||
for (int j=i+1;j<4;j++) {
|
||||
if (phi_new_candidates[i]-phi_new_candidates[j] < 0.0001) {
|
||||
phi_new = phi_new_candidates[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (phi_new == -1) {
|
||||
throw MyException("Interaction::getElaNewDir: phi1 not found.");
|
||||
}
|
||||
return(vec3(sin(theta_new)*cos(phi_new) , sin(theta_new)*sin(phi_new) , cos(theta_new)));
|
||||
}
|
||||
|
||||
|
||||
// Functions for Random Sampling
|
||||
vec3 roll_uniform_direction(ranlib::Uniform<double> *rngUni) {
|
||||
vec3 dir;
|
||||
double phi = 2*pi*rngUni->random();
|
||||
double theta = pi*rngUni->random();
|
||||
dir = sin(theta)*cos(phi) , sin(theta)*sin(phi) , cos(theta);
|
||||
return(dir);
|
||||
}
|
||||
|
||||
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;
|
||||
double sum = 0;
|
||||
for (int i=0;i<3;i++) {
|
||||
sum += pow(rngNormal->random(),2);
|
||||
}
|
||||
beta = sqrt(C*(sum));
|
||||
|
||||
return((get_gamma_from_beta(beta)-1)*mass_eV);
|
||||
}
|
||||
|
||||
double roll_Rejectionmethod(double (*pdf)(double), double xmin, double xmax, double pmax, ranlib::Uniform<double> *rngUni) {
|
||||
// get Energy distribution using Rejection Method
|
||||
double xcan,eta1,eta2;
|
||||
do {
|
||||
eta1 = rngUni->random();
|
||||
eta2 = rngUni->random();
|
||||
xcan = xmin + eta1*(xmax - xmin);
|
||||
} while( eta2*pmax > pdf(xcan) );
|
||||
return(xcan);
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
//
|
||||
// functions.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 07.02.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef functions_hpp
|
||||
#define functions_hpp
|
||||
|
||||
|
||||
#include <iostream>
|
||||
// #include <string>
|
||||
|
||||
#include <blitz/array.h>
|
||||
#include <blitz/tinyvec2.h>
|
||||
#include <random/uniform.h>
|
||||
#include <random/normal.h>
|
||||
|
||||
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
|
||||
{
|
||||
std::string s;
|
||||
MyException(std::string errorMessage) : s(errorMessage) {}
|
||||
~MyException() throw () {}
|
||||
const char* what() const throw() { return s.c_str(); }
|
||||
};
|
||||
|
||||
// Read Parameters from file
|
||||
double getParameter(std::string parName);
|
||||
|
||||
//String Manipulations for Read in from files
|
||||
std::string getEnv (std::string envName); // string version of C function getenv.
|
||||
std::string makePath (std::string path); // append '/' if necessary to path.
|
||||
bool checkIgnoreLine(std::string lineFromFile); // true if line is empty or starts with #
|
||||
void removeLeadingWhites(std::string &lineFromFile);
|
||||
void replaceDelimiter(std::string &lineFromFile); // replaces delimiter (';'',''=') with whitespace
|
||||
|
||||
// System Read out
|
||||
std::string getTimeString();
|
||||
std::string getHomebase();
|
||||
|
||||
// Calculate Kinematic Relations
|
||||
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(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(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);
|
||||
|
||||
|
||||
#endif /* functions_hpp */
|
||||
@@ -39,7 +39,7 @@ Particle Injector::injectElectron (const int &newId) {
|
||||
throw MyException("Katrin::injectElectron: Invalid Injection Method.");
|
||||
break;
|
||||
}
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni) * get_Speed_from_Ekin_eV(Ekin_eV,me_eV);
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni) * calc_Speed_from_Ekin_eV(Ekin_eV,me_eV);
|
||||
return ( PartFac.createElectron(loc_m, speed_ms,newId,newId) );
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
#ifndef injector_hpp
|
||||
#define injector_hpp
|
||||
|
||||
#include "functions.hpp"
|
||||
|
||||
|
||||
#include "katrin.hpp"
|
||||
#include "particle.hpp"
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifndef interaction_base_hpp
|
||||
#define interaction_base_hpp
|
||||
|
||||
#include "functions.hpp"
|
||||
#include "error_types.h"
|
||||
#include "particle.hpp"
|
||||
#include "katrin.hpp"
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
|
||||
#include "interaction_builder.hpp"
|
||||
|
||||
const int InteractionBuilder::elaOn = getParameter("elaOn");
|
||||
const int InteractionBuilder::ionOn = getParameter("ionOn");
|
||||
|
||||
const int InteractionBuilder::eT2elastic = getParameter("eT2elastic");
|
||||
const int InteractionBuilder::eT2ionization = getParameter("eT2ionization");
|
||||
|
||||
InteractionProcessor InteractionBuilder::build_InteractionProcessor() {
|
||||
InteractionProcessor InterProcessor(Kat,rngUni,rngNormal);
|
||||
@@ -19,8 +20,12 @@ InteractionProcessor InteractionBuilder::build_InteractionProcessor() {
|
||||
|
||||
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));
|
||||
if (eT2elastic == 1) {
|
||||
eInteractions->add_Interaction(new e_T2_elasticScattering(Kat, rngUni, rngNormal));
|
||||
}
|
||||
if (eT2ionization == 1) {
|
||||
eInteractions->add_Interaction(new e_T2_ionization(Kat, rngUni, rngNormal));
|
||||
}
|
||||
return(eInteractions);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
|
||||
|
||||
#include "katrin.hpp"
|
||||
#include "functions.hpp"
|
||||
|
||||
|
||||
#include "interaction_processor.hpp"
|
||||
#include "interaction_species.hpp"
|
||||
#include "electron_interactions.hpp"
|
||||
@@ -19,8 +20,8 @@
|
||||
class InteractionBuilder : public RNG_Base {
|
||||
Katrin *Kat;
|
||||
|
||||
static const int ionOn;
|
||||
static const int elaOn;
|
||||
static const int eT2ionization;
|
||||
static const int eT2elastic;
|
||||
|
||||
public:
|
||||
InteractionBuilder(Katrin *Kat, UniRNG *rngUni, NormalRNG *rngNormal) : RNG_Base(rngUni, rngNormal) {
|
||||
@@ -31,7 +32,7 @@ public:
|
||||
|
||||
private:
|
||||
ParticleInteractions* build_eInteractions();
|
||||
ParticleInteractions* build_T2Interactions();
|
||||
//ParticleInteractions* build_T2Interactions();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -16,19 +16,22 @@ InteractionOut InteractionProcessor::do_Interaction(Particle *interPart) const {
|
||||
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 {
|
||||
double macroSigma_m2 = 0;
|
||||
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());
|
||||
if (Itr != ParticleInteractions.end()) {
|
||||
macroSigma_m2 = (*Itr)->get_macroSigma_m2(interPart);
|
||||
} else {
|
||||
cout<<"Warning: No Interaction for Particle of Species"<<Species<<"\n";
|
||||
}
|
||||
return ( (*Itr)->get_macroSigma_m2(interPart) );
|
||||
macroSigma_m2 = macroSigma_m2==0 ? 1e-15 : macroSigma_m2; // Small Value will lead to huge mfp and particle will get out of WGTS
|
||||
return (macroSigma_m2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "katrin.hpp"
|
||||
|
||||
#include "functions.hpp"
|
||||
|
||||
|
||||
#include "sstream"
|
||||
|
||||
@@ -37,7 +37,6 @@ void Katrin::check_Properties() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double Katrin::getTritiumDensity_m3(vec3 loc_m) {
|
||||
double z_wgtsCords_m = loc_m[2] - wgtsStartZ_m; // New Cords, where wgtsStart equals z=0
|
||||
double reductget_ionFactor;
|
||||
@@ -56,14 +55,14 @@ vec3 Katrin::roll_totEqSpeed_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] < wgtsStartZ_m + wgtsLength_m()/2.) ? -1 : 1;
|
||||
double flow_ms = sign*wgtsT2FlowSpeed_ms;
|
||||
speed_ms = 0,0,flow_ms;
|
||||
return (speed_ms);
|
||||
}
|
||||
|
||||
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);
|
||||
double tempOffsetABS_ms = calc_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);
|
||||
}
|
||||
|
||||
@@ -9,14 +9,13 @@
|
||||
#ifndef katrin_hpp
|
||||
#define katrin_hpp
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "constants.h"
|
||||
#include "random_operations.h"
|
||||
|
||||
#include "density_container.hpp"
|
||||
|
||||
#include "blitz/tinyvec2.h"
|
||||
#include "blitz/array.h"
|
||||
#include <random/uniform.h>
|
||||
#include <random/normal.h>
|
||||
|
||||
|
||||
|
||||
@@ -52,7 +51,7 @@ public:
|
||||
private:
|
||||
static const double wgtsMagField_T;
|
||||
|
||||
|
||||
|
||||
//Particle Densities
|
||||
public:
|
||||
double getTritiumDensity_m3(vec3 loc_m);
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
//
|
||||
// kinematics.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 30.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef kinematics_h
|
||||
#define kinematics_h
|
||||
|
||||
|
||||
#include "constants.h"
|
||||
#include "error_types.h"
|
||||
|
||||
#include <blitz/tinyvec2.h>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
|
||||
inline double vec3Abs(const vec3 &vec) {
|
||||
return( sqrt( pow(vec[0],2) + pow(vec[1],2) + pow(vec[2],2)) );
|
||||
}
|
||||
|
||||
inline double calc_gamma_from_beta(const double &beta) {
|
||||
if (beta>=1) {
|
||||
std::stringstream ss;
|
||||
ss<<"calc_gamma_from_beta(): Input beta ="<<beta<<" equal or exeeds 1.";
|
||||
throw MyException(ss.str());
|
||||
} else if (beta<0) {
|
||||
std::stringstream ss;
|
||||
ss<<"calc_gamma_from_beta(): Input beta ="<<beta<<" negative.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
return( pow(1 - pow(beta,2),-0.5) ) ;
|
||||
}
|
||||
|
||||
inline double calc_Ekin_eV_from_speed(const double &speed_ms, const double &mass_eV) {
|
||||
double beta = speed_ms/c_ms;
|
||||
if (beta>=1) {
|
||||
std::stringstream ss;
|
||||
ss<<"calc_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) {
|
||||
std::stringstream ss;
|
||||
ss<<"calc_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 = calc_gamma_from_beta(beta);
|
||||
return ( (gamma-1) * mass_eV );
|
||||
}
|
||||
|
||||
inline double calc_Ekin_eV_from_speed(const vec3 &speed_ms, const double &mass_eV) {
|
||||
return (calc_Ekin_eV_from_speed(vec3Abs(speed_ms), mass_eV));
|
||||
}
|
||||
|
||||
inline double calc_beta_from_gamma(const double &gamma) {
|
||||
if (gamma<1) {
|
||||
std::stringstream ss;
|
||||
ss<<"calc_beta_from_gamma(): Input gamma ="<<gamma<<" smaller 1.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return( sqrt(1 - pow(gamma,-2)) );
|
||||
}
|
||||
|
||||
inline double calc_gamma_from_Ekin_eV(const double &Ekin_eV, const double &mass_eV) {
|
||||
if (Ekin_eV<0) {
|
||||
std::stringstream ss;
|
||||
ss<<"calc_gamma_from_Ekin_eV(): Input Ekin_eV ="<<Ekin_eV<<" negative.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return (1. + Ekin_eV/mass_eV);
|
||||
}
|
||||
|
||||
inline double calc_beta_from_Ekin_eV(const double &Ekin_eV, const double &mass_eV) {
|
||||
return ( calc_beta_from_gamma(calc_gamma_from_Ekin_eV(Ekin_eV, mass_eV)) );
|
||||
}
|
||||
|
||||
inline double calc_Speed_from_Ekin_eV(const double &Ekin_eV, const double &mass_eV) {
|
||||
if (Ekin_eV<0) {
|
||||
std::stringstream ss;
|
||||
ss<<"calc_Speed_from_Ekin_eV(): Input Ekin_eV ="<<Ekin_eV<<" negative.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
double gamma = calc_gamma_from_Ekin_eV(Ekin_eV, mass_eV);
|
||||
double beta = calc_beta_from_gamma(gamma);
|
||||
return(beta * c_ms);
|
||||
}
|
||||
|
||||
inline vec3 calc_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]/vec3Abs(direction_old));
|
||||
double phi_old = atan2(direction_old[1],direction_old[0]);
|
||||
|
||||
double A3 = sin(theta_change)*cos(phi_change);
|
||||
double A4 = A3*cos(theta_old) + cos(theta_change)*sin(theta_old);
|
||||
double A5 = sin(theta_change)*sin(phi_change);
|
||||
double A11 = A4*cos(phi_old) - A5*sin(phi_old);
|
||||
double A21 = A4*sin(phi_old) + A5*cos(phi_old);
|
||||
double theta_new = acos( cos(theta_old)*cos(theta_change)-A3*sin(theta_old) );
|
||||
|
||||
// Get right phi1, maybe more elegant way later. Problem comes from reverse functions only being on range of pi. So combine both statements to get proper phi over 2pi.
|
||||
int digits = 6;
|
||||
double fac = pow(10,digits);
|
||||
double phi_new = -1;
|
||||
double phi_new_candidates [4];
|
||||
phi_new_candidates[0] = acos( roundf ( A11/sin(theta_new) *fac)/fac );
|
||||
phi_new_candidates[1] = 2*pi - phi_new_candidates[0];
|
||||
phi_new_candidates[2] = asin ( roundf ( A21/sin(theta_new) *fac)/fac );
|
||||
phi_new_candidates[3] = pi - phi_new_candidates[2];
|
||||
phi_new_candidates[2] = (phi_new_candidates[2] > 0) ? phi_new_candidates[2] : 2*pi + phi_new_candidates[2];
|
||||
for (int i=0;i<3;i++) {
|
||||
for (int j=i+1;j<4;j++) {
|
||||
if (phi_new_candidates[i]-phi_new_candidates[j] < 0.0001) {
|
||||
phi_new = phi_new_candidates[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (phi_new == -1) {
|
||||
throw MyException("Interaction::getElaNewDir: phi1 not found.");
|
||||
}
|
||||
return(vec3(sin(theta_new)*cos(phi_new) , sin(theta_new)*sin(phi_new) , cos(theta_new)));
|
||||
}
|
||||
|
||||
#endif /* kinematics_h */
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "katrin.hpp"
|
||||
|
||||
#include "hdf5.h"
|
||||
#include <unordered_map>
|
||||
|
||||
typedef struct logParticle {
|
||||
unsigned int Id;
|
||||
|
||||
@@ -15,9 +15,9 @@ using namespace std;
|
||||
|
||||
void createBED_TCS_Func_container() {
|
||||
Edge1D_FuncContainer BED_edge_TCS;
|
||||
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.fillFromFunction(BED_eT2_Ionization::calc_TCS, 15, 20000, 100);
|
||||
BED_edge_TCS.add_ankerpoint(EionT2_eV, BED_eT2_Ionization::calc_TCS(EionT2_eV));
|
||||
BED_edge_TCS.add_ankerpoint(EionT2_eV+1e-4, BED_eT2_Ionization::calc_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;
|
||||
@@ -27,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_eT2_Ionization::get_SDCS, 15, 20000, 50, 10);
|
||||
BED_edge_SDCS.get_Ionization_fromFunction(BED_eT2_Ionization::calc_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_eT2_Ionization::get_SDCS(xmin,ymin));
|
||||
BED_edge_SDCS.add_ankerpoint(xmin, ymin,BED_eT2_Ionization::calc_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;
|
||||
|
||||
@@ -14,9 +14,14 @@ TARGETS = mcelectron
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
mcelectron: main.o simulation.o\
|
||||
functions.o function_container.o katrin.o logger.o \
|
||||
particle.o electron.o bedionization.o
|
||||
mcelectron: main.o \
|
||||
function_container.o density_container.o \
|
||||
simulation.o logger.o \
|
||||
BED_eT2_ionization.o \
|
||||
katrin.o injector.o mover.o terminator.o \
|
||||
interaction_processor.o interaction_species.o interaction_builder.o \
|
||||
electron_interactions.o \
|
||||
particle.o
|
||||
$(CXX) -o $@ $^ $(LDFLAGS) $(LOADLIBES)
|
||||
|
||||
%.o : %.cpp
|
||||
|
||||
@@ -40,8 +40,8 @@ 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 vTotAbs_ms = vec3Abs(v_ms);
|
||||
double vForwardAbs_ms = vec3Abs(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;
|
||||
@@ -95,10 +95,10 @@ double Mover::doBoris_singleStep_m(const vec3 &E_Vm , const vec3 &B_T) {
|
||||
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);
|
||||
distance_m = dt_s/2 * vec3Abs(v_ms);
|
||||
doBoris_speedChange(E_Vm , B_T);
|
||||
x_m += dt_s/2 * v_ms;
|
||||
distance_m += dt_s/2 * get_vecAbs(v_ms);
|
||||
distance_m += dt_s/2 * vec3Abs(v_ms);
|
||||
movePart->set_Location_m(x_m);
|
||||
return(distance_m);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ bool Mover::doBoris_WallInteraction() {
|
||||
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 = (Kat->get_radius_m() * 1.01)/vec3Abs(newLoc_m) * newLoc_m; //1.01 to move Particle slightly out of WGTS
|
||||
newLoc_m[2] = z_m;
|
||||
return (true);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifndef mover_hpp
|
||||
#define mover_hpp
|
||||
|
||||
#include "functions.hpp"
|
||||
#include "kinematics.h"
|
||||
#include "katrin.hpp"
|
||||
#include "particle.hpp"
|
||||
#include "logger.hpp"
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
#ifndef particle_hpp
|
||||
#define particle_hpp
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "functions.hpp"
|
||||
#include "constants.h"
|
||||
#include "kinematics.h"
|
||||
|
||||
#include "iostream"
|
||||
#include "blitz/tinyvec2.h"
|
||||
@@ -47,8 +47,8 @@ public:
|
||||
|
||||
// Get Properties
|
||||
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) ); } ;
|
||||
double get_SpeedAbs_ms() const { return ( vec3Abs(v_ms) ); } ;
|
||||
double get_EKin_eV() const { return ( calc_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; };
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// random_operations.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 30.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef random_operations_h
|
||||
#define random_operations_h
|
||||
|
||||
#include "kinematics.h"
|
||||
|
||||
#include <random/uniform.h>
|
||||
#include <random/normal.h>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
inline vec3 roll_uniform_direction(ranlib::Uniform<double> *rngUni) {
|
||||
vec3 dir;
|
||||
double phi = 2*pi*rngUni->random();
|
||||
double theta = pi*rngUni->random();
|
||||
dir = sin(theta)*cos(phi) , sin(theta)*sin(phi) , cos(theta);
|
||||
return(dir);
|
||||
}
|
||||
|
||||
inline 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;
|
||||
double sum = 0;
|
||||
for (int i=0;i<3;i++) {
|
||||
sum += pow(rngNormal->random(),2);
|
||||
}
|
||||
beta = sqrt(C*(sum));
|
||||
|
||||
return((calc_gamma_from_beta(beta)-1)*mass_eV);
|
||||
}
|
||||
|
||||
inline double roll_Rejectionmethod(double (*pdf)(double), double xmin, double xmax, double pmax, ranlib::Uniform<double> *rngUni) {
|
||||
// get Energy distribution using Rejection Method
|
||||
double xcan,eta1,eta2;
|
||||
do {
|
||||
eta1 = rngUni->random();
|
||||
eta2 = rngUni->random();
|
||||
xcan = xmin + eta1*(xmax - xmin);
|
||||
} while( eta2*pmax > pdf(xcan) );
|
||||
return(xcan);
|
||||
}
|
||||
|
||||
#endif /* random_operations_h */
|
||||
@@ -0,0 +1,168 @@
|
||||
//
|
||||
// read_system.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 30.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef read_system_h
|
||||
#define read_system_h
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
inline double getParameterValue(std::string lineFromFile) {
|
||||
std::stringstream ss;
|
||||
ss.str(lineFromFile);
|
||||
std::string nameDummy;
|
||||
double parValue = NAN;
|
||||
if ( !(ss>>nameDummy && ss>>parValue) ) {
|
||||
std::stringstream sserr;
|
||||
sserr<<"isParameterLine: Could not read line.\n";
|
||||
throw MyException(sserr.str());
|
||||
}
|
||||
return (parValue);
|
||||
}
|
||||
|
||||
inline bool isParameterLine(std::string lineFromFile, const std::string &parName) {
|
||||
std::stringstream ss;
|
||||
ss.str(lineFromFile);
|
||||
std::string parNameTemp;
|
||||
if ( !(ss>>parNameTemp) ) {
|
||||
std::stringstream sserr;
|
||||
sserr<<"isParameterLine: Could not read line.\n";
|
||||
throw MyException(sserr.str());
|
||||
}
|
||||
if (parNameTemp == parName) {
|
||||
return (true);
|
||||
} else {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool isFaulty(std::string lineFromFile) {
|
||||
std::stringstream ss;
|
||||
ss.str(lineFromFile);
|
||||
std::string nameDummy;
|
||||
double valueDummy;
|
||||
if (ss>>nameDummy && ss>>valueDummy) {
|
||||
return (false);
|
||||
} else {
|
||||
return (true);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool checkIgnoreLine(const std::string &lineFromFile) { // true if line is empty or starts with #
|
||||
if (lineFromFile[0] =='#') {
|
||||
return true;
|
||||
} else if ( lineFromFile.empty() ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline void replaceDelimiter(std::string &lineFromFile) { // replaces delimiter (';'',''=') with whitespace
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ';', ' ');
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ',', ' ');
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), '=', ' ');
|
||||
}
|
||||
|
||||
inline void removeLeadingWhites(std::string &lineFromFile) {
|
||||
static const std::string WHITESPACE = " \n\r\t\f\v";
|
||||
size_t start = lineFromFile.find_first_not_of(WHITESPACE);
|
||||
lineFromFile = (start == std::string::npos) ? "" : lineFromFile.substr(start);
|
||||
}
|
||||
|
||||
inline double findParameter(std::ifstream *fileStream, const std::string &parName) {
|
||||
std::string lineFromFile;
|
||||
double parValue = NAN;
|
||||
while (getline(*fileStream, lineFromFile)) {
|
||||
removeLeadingWhites(lineFromFile);
|
||||
replaceDelimiter(lineFromFile);
|
||||
if ( checkIgnoreLine(lineFromFile) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( isFaulty(lineFromFile) ) {
|
||||
std::cout<<"Line in parameter file faulty.\n\tline:\t"<<lineFromFile<<"\n";
|
||||
} else if ( isParameterLine(lineFromFile, parName) ) {
|
||||
parValue = getParameterValue(lineFromFile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (parValue);
|
||||
}
|
||||
|
||||
inline std::string makePath (const std::string &path) { // append '/' if necessary to path.
|
||||
if (path.back() != '/') {
|
||||
return (path + '/');
|
||||
} else {
|
||||
return (path);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string getEnv (const std::string &envName) { // string version of C function getenv.
|
||||
char * val = getenv( envName.c_str() );
|
||||
return val == NULL ? std::string("") : std::string(val);
|
||||
}
|
||||
|
||||
inline std::string getParameterLoadFilePath() {
|
||||
std::string parpath = getEnv("parpath");
|
||||
if (parpath == "") {
|
||||
throw MyException("Parameter::getParameter: Environment variable parpath not defined.");
|
||||
}
|
||||
std::string parfile = getEnv("parfile");
|
||||
if (parfile == "") {
|
||||
throw MyException("Parameter::getParameter: Environment variable parfile not defined.");
|
||||
}
|
||||
|
||||
parpath = makePath(parpath);
|
||||
return (parpath + parfile);
|
||||
}
|
||||
|
||||
inline double getParameter(const std::string &parName) {
|
||||
std::string loadFilePath = getParameterLoadFilePath();
|
||||
|
||||
std::ifstream fileStream(loadFilePath);
|
||||
if (!fileStream.good()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Parameter::getParameter: Could not open file.\n loadFilePath:\t"<<loadFilePath<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double parValue = findParameter(&fileStream, parName);
|
||||
|
||||
if ( isnan(parValue) ) {
|
||||
std::stringstream ss;
|
||||
ss<<"Parameter::getParameter: Parameter not found in file.\n parName:\t"<<parName<<"\n loadFilePath: \t"<<loadFilePath;
|
||||
throw MyException(ss.str());
|
||||
} else {
|
||||
return (parValue);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string getTimeString() {
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
char buffer[80];
|
||||
time (&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
strftime(buffer,sizeof(buffer),"%Y%m%d",timeinfo);
|
||||
std::string str(buffer);
|
||||
return(str);
|
||||
}
|
||||
|
||||
inline std::string getHomebase() {
|
||||
std::string Homebase = getEnv("HOMEBASE");
|
||||
Homebase = makePath(Homebase);
|
||||
return (Homebase);
|
||||
}
|
||||
|
||||
inline std::string getDataPath() {
|
||||
return (getHomebase() + "src/mc_electron/data/");
|
||||
}
|
||||
#endif /* read_system_h */
|
||||
@@ -9,11 +9,6 @@
|
||||
|
||||
#include "simulation.hpp"
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "functions.hpp"
|
||||
|
||||
#include "fstream"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
#include "terminator.hpp"
|
||||
#include "interaction_processor.hpp"
|
||||
#include "interaction_builder.hpp"
|
||||
|
||||
#include "particle.hpp"
|
||||
#include <deque>
|
||||
|
||||
|
||||
|
||||
class Simulation {
|
||||
|
||||
@@ -7,55 +7,43 @@
|
||||
//
|
||||
|
||||
#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);
|
||||
|
||||
#include "constants.h"
|
||||
#include "error_types.h"
|
||||
#include "kinematics.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
double Uehara_eT2_ElasticScattering::calc_TCS(const double &T_eV) {
|
||||
double beta = calc_beta_from_Ekin_eV(T_eV,me_eV);
|
||||
double eta = calc_eta(T_eV);
|
||||
double numerator = pi*ZT2*(ZT2+1)*re_m*re_m * (1-pow(beta,2));
|
||||
double denominator = eta * (eta+1)*pow(beta,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);
|
||||
double Uehara_eT2_ElasticScattering::calc_SDCS(const double &T_eV, const double &theta) {
|
||||
double beta = calc_beta_from_Ekin_eV(T_eV,me_eV);
|
||||
double eta = calc_eta(T_eV);
|
||||
double numerator = ZT2*(ZT2+1)*re_m*re_m * (1-pow(beta,2));
|
||||
double denominator = pow(beta,4)*pow(1-cos(theta)+2*eta, 2);
|
||||
return (numerator/denominator);
|
||||
}
|
||||
|
||||
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 Uehara_eT2_ElasticScattering::roll_theta(const double &T_eV, UniRNG *rngUni) {
|
||||
double beta = calc_beta_from_Ekin_eV(T_eV,me_eV);
|
||||
double elaEta = calc_eta(T_eV);
|
||||
double const1 = 2*pi/calc_TCS(T_eV)*ZT2*(ZT2+1)*re_m*re_m*(1- pow(beta,2) )* pow(beta,-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;
|
||||
double Uehara_eT2_ElasticScattering::calc_eta(const double &T_eV) {
|
||||
double beta = calc_beta_from_Ekin_eV(T_eV, me_eV);
|
||||
double etac = (T_eV < 50e3)? 1.198 : 1.13+3.76*pow(ZT2/(137*beta),2);
|
||||
double elaTau = T_eV/me_eV;
|
||||
return (etac * 1.7e-5 * pow(ZT2,2./3.) /(elaTau*(elaTau+2) ));
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -9,18 +9,20 @@
|
||||
#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);
|
||||
#include "random_operations.h"
|
||||
|
||||
// Cross secton by Uehara 1993: Rutherford CS with screening parameter. Originally for water vapor.
|
||||
class Uehara_eT2_ElasticScattering {
|
||||
|
||||
public:
|
||||
Uehara_eT2_ElasticScattering(){};
|
||||
|
||||
static double calc_TCS(const double &T_eV);
|
||||
static double calc_SDCS(const double &T_eV, const 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) ));
|
||||
}
|
||||
*/
|
||||
static double roll_theta(const double &T_eV, UniRNG *rngUni);
|
||||
private:
|
||||
static double calc_eta(const double &T_eV);
|
||||
};
|
||||
|
||||
#endif /* uehara_eT2_elastic_hpp */
|
||||
|
||||
Reference in New Issue
Block a user