Minor Changes
This commit is contained in:
@@ -6,4 +6,87 @@
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#include "bedionization.hpp"
|
||||
|
||||
#include "constants.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const double BED_Ionization::S_m2 = 5.4721e-20;
|
||||
const double BED_Ionization::B_eV = Constants().EionT2_eV;
|
||||
const double BED_Ionization::u = 1.664;
|
||||
const double BED_Ionization::N = 2;
|
||||
const double BED_Ionization::Ni = 1.173;
|
||||
const double BED_Ionization::c[4] = {1.1262 , 6.3982 , -7.8055, 2.1449} ;
|
||||
|
||||
double BED_Ionization::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 (ss.str());
|
||||
}
|
||||
|
||||
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_Ionization::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 (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 (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_Ionization::calc_t(double T_eV) {
|
||||
return(T_eV/B_eV);
|
||||
}
|
||||
double BED_Ionization::calc_w(double W_eV) {
|
||||
return(W_eV/B_eV);
|
||||
}
|
||||
|
||||
double BED_Ionization::calc_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);
|
||||
}
|
||||
|
||||
double BED_Ionization::calc_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);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,30 @@
|
||||
#ifndef bedionization_hpp
|
||||
#define bedionization_hpp
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// BED Ionization model from Kim, Y.-K. and Rudd, M. E. 1994
|
||||
|
||||
class BED_Ionization {
|
||||
public:
|
||||
BED_Ionization(){};
|
||||
double get_TCS(double T_eV);
|
||||
double get_SDCS(double T_eV, double W_eV);
|
||||
protected:
|
||||
static const double S_m2;
|
||||
private:
|
||||
static const double B_eV;
|
||||
static const double u;
|
||||
static const double N,Ni;
|
||||
static const double c[4];
|
||||
|
||||
double calc_t(double T);
|
||||
double calc_w(double W);
|
||||
|
||||
double calc_dfdw(double w);
|
||||
double calc_Dt(double t);
|
||||
} ;
|
||||
|
||||
|
||||
#endif /* bedionization_hpp */
|
||||
|
||||
|
||||
|
||||
@@ -6,38 +6,26 @@
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#include "constants.hpp"
|
||||
|
||||
|
||||
// Natural Constants
|
||||
const double Constants::pi = 3.1415;
|
||||
const double Constants::c_ms = 299792458;
|
||||
const double Constants::kb_eVK = 8.6173303e-5;
|
||||
const double Constants::e_C = 1.602176462e-19;
|
||||
const double Constants::rBohr_m = 0.52917721067e-10;
|
||||
const double Constants::ERyd_eV = 13.605693009;
|
||||
constant Constants::pi = 3.1415;
|
||||
constant Constants::c_ms = 299792458;
|
||||
constant Constants::kb_eVK = 8.6173303e-5;
|
||||
constant Constants::e_C = 1.602176462e-19;
|
||||
constant Constants::rBohr_m = 0.52917721067e-10;
|
||||
constant Constants::ERyd_eV = 13.605693009;
|
||||
|
||||
// Particle Properties
|
||||
const double Constants::me_eV = 0.511e6;
|
||||
const double Constants::re_m = 2.817940322719e-15;
|
||||
const double Constants::ZT2 = 2.;
|
||||
const double Constants::mT2_eV = 5.61886404234e9;
|
||||
constant Constants::me_eV = 0.511e6;
|
||||
constant Constants::re_m = 2.817940322719e-15;
|
||||
constant Constants::ZT2 = 2.;
|
||||
constant Constants::mT2_eV = 5.61886404234e9;
|
||||
constant Constants::EionT2_eV = 15.43;
|
||||
|
||||
// Beta Decay
|
||||
const double Constants::BetaDecayConst = 1.2072343416696292e-47;
|
||||
const double Constants::TritiumDecayEndpoint_eV = 18.574e3;
|
||||
constant Constants::BetaDecayConst = 1.2072343416696292e-47;
|
||||
constant Constants::TritiumDecayEndpoint_eV = 18.574e3;
|
||||
|
||||
// Elastic Scattering
|
||||
const double Constants::elaBeta[5] = {7.51525,-0.419122,7.2017e-3,-4.646e-5,1.02897e-7};
|
||||
const double Constants::elaDelta[5] = {2.9612,-0.26376,4.307e-3,-2.6895e-5,5.83505e-8};
|
||||
const double Constants::elaGamma[14] = {1.7013,-1.484284,0.6331,-0.10911,8.358e-3,-2.388e-4,-3.32517, 0.10996,-4.5255e-3,5.8372e-5,-2.4659e-7,2.4775e-2,-2.96264e-5,-1.20655e-7};
|
||||
|
||||
// Ionization
|
||||
const double Constants::ionET2_eV = 13.603;
|
||||
const double Constants::ionA1 = 0.74;
|
||||
const double Constants::ionA2 = 0.87;
|
||||
const double Constants::ionA3 = -0.6;
|
||||
const double Constants::ionN = 2.4;
|
||||
const double Constants::ionBeta = 0.6;
|
||||
const double Constants::ionGamma = 10;
|
||||
const double Constants::ionG5 = 0.33;
|
||||
const double Constants::iongb = 2.9;
|
||||
|
||||
@@ -9,62 +9,31 @@
|
||||
#ifndef constants_hpp
|
||||
#define constants_hpp
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include "blitz/array.h"
|
||||
#include "blitz/tinyvec2.h"
|
||||
#include <random/uniform.h>
|
||||
#include <random/normal.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
typedef const double constant;
|
||||
|
||||
class Constants {
|
||||
public:
|
||||
Constants() {};
|
||||
|
||||
// Natural Constants
|
||||
static const double pi;
|
||||
static const double c_ms;
|
||||
static const double kb_eVK;
|
||||
static const double e_C;
|
||||
static const double rBohr_m;
|
||||
static const double ERyd_eV;
|
||||
static constant pi;
|
||||
static constant c_ms;
|
||||
static constant kb_eVK;
|
||||
static constant e_C;
|
||||
static constant rBohr_m;
|
||||
static constant ERyd_eV;
|
||||
|
||||
// Particle Properties
|
||||
static const double me_eV;
|
||||
static const double re_m;
|
||||
static const double ZT2;
|
||||
static const double mT2_eV;
|
||||
static constant me_eV;
|
||||
static constant re_m;
|
||||
static constant ZT2;
|
||||
static constant mT2_eV;
|
||||
static constant EionT2_eV;
|
||||
|
||||
// Beta Decay
|
||||
static const double BetaDecayConst;
|
||||
static const double TritiumDecayEndpoint_eV;
|
||||
static constant BetaDecayConst;
|
||||
static constant TritiumDecayEndpoint_eV;
|
||||
|
||||
|
||||
// Elastic Scattering
|
||||
static const double elaBeta[5];
|
||||
static const double elaDelta[5];
|
||||
static const double elaGamma[14];
|
||||
|
||||
// Ionization
|
||||
static const double ionET2_eV;
|
||||
static const double ionA1;
|
||||
static const double ionA2;
|
||||
static const double ionA3;
|
||||
static const double ionN;
|
||||
static const double ionG5;
|
||||
static const double iongb;
|
||||
static const double ionBeta;
|
||||
static const double ionGamma;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
S Uehara et al 1993 Phys. Med. Biol. 38 1841
|
||||
*/
|
||||
|
||||
void Electron::do_elaScattering (blitz::TinyVector<double,3> speedT2_ms, ranlib::Uniform<double> *rngUni) {
|
||||
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;
|
||||
@@ -24,9 +24,9 @@ void Electron::do_elaScattering (blitz::TinyVector<double,3> speedT2_ms, ranlib:
|
||||
}
|
||||
|
||||
|
||||
double Electron::calc_elaSigma_m2(blitz::TinyVector<double,3> speedT2_ms) {
|
||||
double Electron::calc_elaSigma_m2(vec3 speedT2_ms) {
|
||||
double SigmaEla_m2;
|
||||
blitz::TinyVector<double,3> speedLab_ms = v_ms - speedT2_ms;
|
||||
vec3 speedLab_ms = v_ms - speedT2_ms;
|
||||
double betaLab = calc_vecAbs(speedLab_ms)/c_ms;
|
||||
//double EkinLab_eV = calc_Ekin_eV_from_speed(speedLab_ms, m_eV);
|
||||
double elaEta = calc_elaEta(speedLab_ms);
|
||||
@@ -37,7 +37,7 @@ double Electron::calc_elaSigma_m2(blitz::TinyVector<double,3> speedT2_ms) {
|
||||
}
|
||||
|
||||
|
||||
double Electron::calc_elaEta(blitz::TinyVector<double,3> speedLab_ms) {
|
||||
double Electron::calc_elaEta(vec3 speedLab_ms) {
|
||||
double Ekin_eVLab_eV = calc_Ekin_eV_from_speed(calc_vecAbs(speedLab_ms), m_eV);
|
||||
double betaLab = calc_vecAbs(speedLab_ms)/c_ms;
|
||||
double etac = (Ekin_eVLab_eV < 50e3)? 1.198 : 1.13+3.76*pow(ZT2/(137*betaLab),2);
|
||||
@@ -45,8 +45,8 @@ double Electron::calc_elaEta(blitz::TinyVector<double,3> speedLab_ms) {
|
||||
return (etac * 1.7e-5 * pow(ZT2,2./3.) /(elaTau*(elaTau+2) ));
|
||||
}
|
||||
|
||||
double Electron::roll_elaTheta(blitz::TinyVector<double,3> speedT2_ms, ranlib::Uniform<double> *rngUni) {
|
||||
blitz::TinyVector<double,3> speedLab_ms = v_ms - speedT2_ms;
|
||||
double Electron::roll_elaTheta(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni) {
|
||||
vec3 speedLab_ms = v_ms - speedT2_ms;
|
||||
double betaLab = calc_vecAbs(speedLab_ms)/c_ms;
|
||||
double elaEta = calc_elaEta(speedLab_ms);
|
||||
double const1 = 2*pi/calc_elaSigma_m2(speedT2_ms)*ZT2*(ZT2+1)*re_m*re_m*(1- pow(betaLab,2) )* pow(betaLab,-4);
|
||||
@@ -55,9 +55,9 @@ double Electron::roll_elaTheta(blitz::TinyVector<double,3> speedT2_ms, ranlib::U
|
||||
}
|
||||
|
||||
|
||||
void Electron::do_elaKinetics(blitz::TinyVector<double,3> speedT2_ms, double thetaLab, double phiLab) {
|
||||
void Electron::do_elaKinetics(vec3 speedT2_ms, double thetaLab, double phiLab) {
|
||||
// Following Landau Lifschitz I Chapter 4 Paragraph 17
|
||||
blitz::TinyVector<double,3> n0, speedLab_ms, v1New_ms, v2New_ms;
|
||||
vec3 n0, speedLab_ms, v1New_ms, v2New_ms;
|
||||
speedLab_ms = v_ms - speedT2_ms;
|
||||
n0 = calc_Newdirection(speedLab_ms, thetaLab, phiLab);
|
||||
v1New_ms = (mT2_eV*calc_vecAbs(speedLab_ms)*n0 + m_eV*speedLab_ms)/(m_eV+mT2_eV) + speedT2_ms;
|
||||
|
||||
@@ -8,8 +8,10 @@
|
||||
|
||||
#include "electron.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
double Electron::calc_SigmaTotal_m2(blitz::TinyVector<double,3> speedT2_ms) {
|
||||
|
||||
double Electron::calc_SigmaTotal_m2(vec3 speedT2_ms) {
|
||||
vector<double> Sigmas = calc_SigmaVector_m2(speedT2_ms);
|
||||
double sigmaTot_m2 = 0;
|
||||
for (vector<double>::iterator SigmasIt = Sigmas.begin() ; SigmasIt != Sigmas.end(); SigmasIt++) {
|
||||
@@ -18,15 +20,15 @@ double Electron::calc_SigmaTotal_m2(blitz::TinyVector<double,3> speedT2_ms) {
|
||||
return(sigmaTot_m2);
|
||||
}
|
||||
|
||||
vector<double> Electron::calc_SigmaVector_m2(blitz::TinyVector<double,3> speedT2_ms) {
|
||||
vector<double> Electron::calc_SigmaVector_m2(vec3 speedT2_ms) {
|
||||
vector<double> Sigmas;
|
||||
if (elaOn == 1) {
|
||||
if (Particle::elaOn == 1) {
|
||||
Sigmas.push_back(calc_elaSigma_m2(speedT2_ms));
|
||||
} else {
|
||||
Sigmas.push_back(0.);
|
||||
}
|
||||
|
||||
if (ionOn == 1) {
|
||||
if (Particle::ionOn == 1) {
|
||||
Sigmas.push_back(get_ionSigma_m2(speedT2_ms));
|
||||
} else {
|
||||
Sigmas.push_back(0.);
|
||||
@@ -34,7 +36,7 @@ vector<double> Electron::calc_SigmaVector_m2(blitz::TinyVector<double,3> speedT2
|
||||
return(Sigmas);
|
||||
}
|
||||
|
||||
int Electron::roll_Interaction(blitz::TinyVector<double,3> speedT2_ms, ranlib::Uniform<double> *rngUni) {
|
||||
int Electron::roll_Interaction(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni) {
|
||||
// Check Moved Outside
|
||||
if (getKinEnergy_eV()==0) {
|
||||
return(0);
|
||||
|
||||
@@ -10,56 +10,40 @@
|
||||
#define electron_hpp
|
||||
|
||||
#include "particle.hpp"
|
||||
#include "bedionization.hpp"
|
||||
|
||||
class Electron : public Particle {
|
||||
|
||||
class Electron : public Particle, private BED_Ionization {
|
||||
public:
|
||||
virtual ~Electron() {}
|
||||
Electron(blitz::TinyVector<double,3> loc_m, blitz::TinyVector<double,3> speed_ms, double idnum, double parentIdnum) : Particle::Particle(me_eV, 1 , loc_m, speed_ms, idnum, parentIdnum, electron) {};
|
||||
Electron(vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum) : Particle::Particle(me_eV, 1 , loc_m, speed_ms, idnum, parentIdnum, electron) {};
|
||||
public:
|
||||
double calc_SigmaTotal_m2(blitz::TinyVector<double,3> speedT2_ms);
|
||||
vector<double> calc_SigmaVector_m2(blitz::TinyVector<double,3> speedT2_ms);
|
||||
int roll_Interaction(blitz::TinyVector<double,3> speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
double calc_SigmaTotal_m2(vec3 speedT2_ms);
|
||||
std::vector<double> calc_SigmaVector_m2(vec3 speedT2_ms);
|
||||
int roll_Interaction(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
|
||||
// Elastic Scattering
|
||||
public:
|
||||
void do_elaScattering (blitz::TinyVector<double,3> speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
double calc_elaSigma_m2(blitz::TinyVector<double,3> speedT2_ms);
|
||||
void do_elaScattering (vec3 speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
double calc_elaSigma_m2(vec3 speedT2_ms);
|
||||
protected:
|
||||
double calc_elaEta(blitz::TinyVector<double,3> speedLab_ms);
|
||||
double roll_elaTheta(blitz::TinyVector<double,3> speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
void do_elaKinetics(blitz::TinyVector<double,3> speedT2_ms, double theta, double phi);
|
||||
double calc_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(blitz::TinyVector<double,3> speedT2_ms);
|
||||
Electron do_Ionization(blitz::TinyVector<double,3> speedT2_ms, int newId, ranlib::Uniform<double> *rngUni);
|
||||
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 calc_ionSDCS_m2eV(double T_eV, double W_eV);
|
||||
double calc_ionS_m2 (double N);
|
||||
double calc_ionf1(double t, double w);
|
||||
double calc_iong1(double t);
|
||||
double calc_ionF(double t);
|
||||
|
||||
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);
|
||||
/* DDCS
|
||||
double ranIonTheta(double T_eV, double W_eV, ranlib::Uniform<double> *rngUni);
|
||||
double ionSigmadWdTheta_m2eV(double T_eV, double W_eV, double theta);
|
||||
double ionG1(double t, double w, double theta, double N);
|
||||
double ionG2(double t, double w);
|
||||
double ionG3(double t, double w);
|
||||
double ionG4(double t, double w);
|
||||
|
||||
double ionfbe(double t, double w, double theta);
|
||||
double ionfb(double theta);
|
||||
double iongbe(double t, double w);
|
||||
*/
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -6,10 +6,15 @@
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#include "functions.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
double calc_vecAbs(blitz::TinyVector<double,3> vec) {
|
||||
using namespace std;
|
||||
|
||||
|
||||
double calc_vecAbs(vec3 vec) {
|
||||
return( sqrt( pow(vec[0],2) + pow(vec[1],2) + pow(vec[2],2)) );
|
||||
}
|
||||
|
||||
@@ -72,7 +77,7 @@ double calc_beta_from_gamma(double gamma) {
|
||||
return( sqrt(1 - pow(gamma,-2)) );
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> calc_Newdirection(blitz::TinyVector<double,3> direction_old, double theta_change,double phi_change) {
|
||||
vec3 calc_Newdirection(vec3 direction_old, double theta_change,double phi_change) {
|
||||
// Transformation of direction following Plante and Cucinotta
|
||||
double theta_old = acos(direction_old[2]/calc_vecAbs(direction_old));
|
||||
double phi_old = atan2(direction_old[1],direction_old[0]);
|
||||
@@ -109,18 +114,18 @@ endloops:
|
||||
}
|
||||
throw ("Interaction::getElaNewDir: phi1 not found.");
|
||||
}
|
||||
return(blitz::TinyVector<double,3>(sin(theta_new)*cos(phi_new) , sin(theta_new)*sin(phi_new) , cos(theta_new)));
|
||||
return(vec3(sin(theta_new)*cos(phi_new) , sin(theta_new)*sin(phi_new) , cos(theta_new)));
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> roll_uniform_direction(ranlib::Uniform<double> *rngUni) {
|
||||
blitz::TinyVector<double,3> dir;
|
||||
vec3 roll_uniform_direction(ranlib::Uniform<double> *rngUni) {
|
||||
vec3 dir;
|
||||
double phi = 2*Constants::pi*rngUni->random();
|
||||
double theta = Constants::pi*rngUni->random();
|
||||
dir = sin(theta)*cos(phi) , sin(theta)*sin(phi) , cos(theta);
|
||||
return(dir);
|
||||
}
|
||||
|
||||
double roll_MB_Energy(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *rngNormal) {
|
||||
double roll_MBEnergy(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *rngNormal) {
|
||||
|
||||
double C = Constants::kb_eVK*Temp_K/mass_eV;
|
||||
double beta = 0;
|
||||
@@ -133,8 +138,8 @@ double roll_MB_Energy(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *r
|
||||
return((calc_gamma_from_beta(beta)-1)*mass_eV);
|
||||
}
|
||||
|
||||
/*
|
||||
double doRejectionMethod(double (*pdf)(double), double xmin, double xmax, double pmax, ranlib::Uniform<double> *rngUni) {
|
||||
|
||||
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 {
|
||||
@@ -144,4 +149,4 @@ double doRejectionMethod(double (*pdf)(double), double xmin, double xmax, double
|
||||
} while( eta2*pmax > pdf(xcan) );
|
||||
return(xcan);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@@ -9,8 +9,16 @@
|
||||
#ifndef functions_hpp
|
||||
#define functions_hpp
|
||||
|
||||
|
||||
#include "constants.hpp"
|
||||
|
||||
#include "blitz/array.h"
|
||||
#include "blitz/tinyvec2.h"
|
||||
#include <random/uniform.h>
|
||||
#include <random/normal.h>
|
||||
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
|
||||
|
||||
double calc_vecAbs(blitz::TinyVector<double,3> vec);
|
||||
double calc_Speed_from_Ekin_eV(double Ekin_eV, double mass_eV);
|
||||
@@ -19,11 +27,11 @@ double calc_beta_from_gamma(double gamma);
|
||||
double calc_Ekin_eV_from_speed(double Speed, double mass_eV);
|
||||
double calc_gamma_from_beta(double beta);
|
||||
|
||||
blitz::TinyVector<double,3> calc_Newdirection(blitz::TinyVector<double,3> oldDir, double theta,double phi);
|
||||
vec3 calc_Newdirection(vec3 oldDir, double theta,double phi);
|
||||
|
||||
blitz::TinyVector<double,3> roll_uniform_direction(ranlib::Uniform<double> *rngUni);
|
||||
double roll_MB_Energy(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *rngNormal);
|
||||
//double doRejectionMethod(double pdf(double), double xmin, double xmax, double pmax, ranlib::Uniform<double> *rngUni);
|
||||
vec3 roll_uniform_direction(ranlib::Uniform<double> *rngUni);
|
||||
double roll_MBEnergy(double Temp_K,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 */
|
||||
|
||||
+18
-118
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "electron.hpp"
|
||||
|
||||
|
||||
/*
|
||||
Ionization:
|
||||
Following
|
||||
@@ -15,36 +16,29 @@
|
||||
M. E. Rudd 1991 Physical Review A Volume 44 Number3
|
||||
*/
|
||||
|
||||
double Electron::get_ionSigma_m2(blitz::TinyVector<double,3> speedT2_ms) {
|
||||
blitz::TinyVector<double,3> speedLab_ms = v_ms - speedT2_ms;
|
||||
double Electron::get_ionSigma_m2(vec3 speedT2_ms) {
|
||||
vec3 speedLab_ms = v_ms - speedT2_ms;
|
||||
double T_eV = calc_Ekin_eV_from_speed(calc_vecAbs(speedLab_ms), m_eV);
|
||||
double t = T_eV/ionET2_eV;
|
||||
double N = ZT2; //for tritium-molecule
|
||||
if (T_eV<ionET2_eV) {
|
||||
return(0);
|
||||
}
|
||||
return(calc_ionS_m2(N)*calc_ionF(t)*calc_iong1(t));
|
||||
return (BED_Ionization::get_TCS(T_eV));
|
||||
}
|
||||
|
||||
Electron Electron::do_Ionization(blitz::TinyVector<double,3> speedT2_ms, int newId, ranlib::Uniform<double> *rngUni) {
|
||||
blitz::TinyVector<double,3> speedOffset_ms = speedT2_ms;
|
||||
blitz::TinyVector<double,3> speedLab_ms = v_ms - speedOffset_ms;
|
||||
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 = calc_Ekin_eV_from_speed(calc_vecAbs(speedLab_ms), m_eV);
|
||||
|
||||
|
||||
if (T_eV < ionET2_eV) {
|
||||
// Problem when calculating interaction probability and interaction with different speeds, if unlucky, cut off speedT2_ms
|
||||
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 = calc_Ekin_eV_from_speed(calc_vecAbs(v_ms), m_eV);
|
||||
}
|
||||
|
||||
if (T_eV < ionET2_eV) {
|
||||
if (T_eV < EionT2_eV) {
|
||||
throw ("Electron::do_Ionization: Ekin_eV < EIonT2_eV.");
|
||||
}
|
||||
|
||||
double W_eV = roll_ionW_eV(T_eV, rngUni);
|
||||
double E1_eV = T_eV-ionET2_eV - W_eV;
|
||||
double E1_eV = T_eV-EionT2_eV - W_eV;
|
||||
|
||||
double phi1 = rngUni->random()*2*pi;
|
||||
double phi2 = phi1-pi;
|
||||
@@ -52,70 +46,37 @@ Electron Electron::do_Ionization(blitz::TinyVector<double,3> speedT2_ms, int new
|
||||
double theta1 = roll_IonTheta1(T_eV, W_eV, rngUni);
|
||||
double theta2 = roll_IonTheta2(T_eV, W_eV, rngUni);
|
||||
|
||||
|
||||
double v1Absnew_ms = calc_Speed_from_Ekin_eV(E1_eV, m_eV);
|
||||
double v2Absnew_ms = calc_Speed_from_Ekin_eV(W_eV, m_eV);
|
||||
|
||||
|
||||
blitz::TinyVector<double,3> P1newDir, P2newDir, v1New_ms, v2New_ms ;
|
||||
vec3 P1newDir, P2newDir, v1New_ms, v2New_ms ;
|
||||
P1newDir = calc_Newdirection(v_ms, theta1, phi1);
|
||||
P2newDir = calc_Newdirection(v_ms, theta2, phi2);
|
||||
|
||||
v1New_ms = v1Absnew_ms*P1newDir + speedOffset_ms;
|
||||
v2New_ms = v2Absnew_ms*P2newDir + speedOffset_ms;
|
||||
|
||||
|
||||
setSpeed_ms(v1New_ms);
|
||||
Electron eNew = Electron(x_m, v2New_ms, newId, getId());
|
||||
|
||||
// Follow Ions... .
|
||||
// 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 = get_ionSigma_m2(); //
|
||||
pmax = calc_ionS_m2(2)*1.06*2;
|
||||
pmax = BED_Ionization::get_TCS(T_eV);
|
||||
Wmin_eV = 0;
|
||||
Wmax_eV = T_eV-ionET2_eV;
|
||||
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 > calc_ionSDCS_m2eV(T_eV, Wcan_eV));
|
||||
|
||||
|
||||
if (Wcan_eV < (T_eV-ionET2_eV)/2) {
|
||||
return(Wcan_eV);
|
||||
} else {
|
||||
return((T_eV-ionET2_eV) - Wcan_eV);
|
||||
}
|
||||
|
||||
return(Wcan_eV);
|
||||
}
|
||||
|
||||
|
||||
double Electron::calc_ionSDCS_m2eV(double T_eV, double W_eV) {
|
||||
double t = T_eV/ionET2_eV;
|
||||
double w = W_eV/ionET2_eV;
|
||||
double N = 2;
|
||||
return(calc_ionS_m2(N)*calc_ionF(t)*calc_ionf1(w,t)/ionET2_eV);
|
||||
}
|
||||
|
||||
double Electron::calc_ionS_m2(double N) {
|
||||
return (4*pi*N*pow(rBohr_m*ERyd_eV/ionET2_eV,2));
|
||||
}
|
||||
|
||||
double Electron::calc_ionf1(double t, double w) {
|
||||
return ( pow(w+1,-ionN) + pow(t-w,-ionN)-pow((w+1)*(t-w),-ionN/2) );
|
||||
}
|
||||
|
||||
double Electron::calc_iong1(double t) {
|
||||
return ( (1-pow(t,1-ionN))/(ionN-1) - pow(2/(t+1),ionN/2)*(1-pow(t,1-ionN/2))/(ionN-2) );
|
||||
}
|
||||
|
||||
double Electron::calc_ionF(double t) {
|
||||
return ((ionA1*log(t) + ionA2 + ionA3/t)/t);
|
||||
} while(eta2*pmax > BED_Ionization::get_SDCS(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) {
|
||||
@@ -130,7 +91,6 @@ double Electron::roll_IonTheta1(double T_eV, double W_eV, ranlib::Uniform<double
|
||||
return (theta1);
|
||||
}
|
||||
|
||||
|
||||
double Electron::roll_IonTheta2(double T_eV, double W_eV, ranlib::Uniform<double> *rngUni) {
|
||||
double theta2;
|
||||
if (W_eV > 200) {
|
||||
@@ -149,63 +109,3 @@ double Electron::roll_IonTheta2(double T_eV, double W_eV, ranlib::Uniform<double
|
||||
}
|
||||
return(theta2);
|
||||
}
|
||||
|
||||
|
||||
/* DDCS
|
||||
double Electron::ranIonTheta(double T_eV, double W_eV, ranlib::Uniform<double> *rngUni) {
|
||||
double pmax,thetaMin, thetaMax, thetaCan,eta1,eta2;
|
||||
pmax = ionSigmadW_m2eV(T_eV, W_eV);
|
||||
thetaMin = 0;
|
||||
thetaMax = pi;
|
||||
do {
|
||||
eta1 = rngUni->random();
|
||||
eta2 = rngUni->random();
|
||||
thetaCan = thetaMin + eta1*(thetaMax - thetaMin);
|
||||
} while(eta2*pmax > ionSigmadWdTheta_m2eV(T_eV, W_eV, thetaCan));
|
||||
return(thetaCan);
|
||||
}
|
||||
|
||||
double Electron::ionSigmadWdTheta_m2eV(double T_eV, double W_eV, double theta) {
|
||||
double t = T_eV/ionET2_eV;
|
||||
double w = W_eV/ionET2_eV;
|
||||
double N = 2;
|
||||
return( ionG1(t, w, theta, N)*( ionfbe(t,w,theta)+ionG4(t,w)*ionfb(theta) ) );
|
||||
}
|
||||
|
||||
double Electron::ionG1(double t, double w, double theta,double N) {
|
||||
double numerator = calc_ionS_m2(N)*calc_ionF(t)*calc_ionf1(t,w)/ionET2_eV;
|
||||
double denominator = iongbe(t,w)+ionG4(t,w)*iongb;
|
||||
return (numerator/denominator);
|
||||
}
|
||||
|
||||
double Electron::ionG2(double t, double w) {
|
||||
return( pow(w+1/t,0.5) );
|
||||
}
|
||||
|
||||
double Electron::ionG3(double t, double w) {
|
||||
return ( ionBeta*sqrt((1-pow(ionG2(t,w),2))/w) );
|
||||
}
|
||||
|
||||
double Electron::ionG4(double t, double w) {
|
||||
return ( ionGamma*pow(1-w/t,3)/t/(w+1) );
|
||||
}
|
||||
|
||||
double Electron::ionfbe(double t, double w, double theta) {
|
||||
double a = pow( (cos(theta)-ionG2(t,w))/ionG3(t,w) , 2 );
|
||||
return ( 1/(1+ a) );
|
||||
}
|
||||
|
||||
double Electron::ionfb(double theta) {
|
||||
double a = pow( (cos(theta)+1)/ionG5 , 2 );
|
||||
return ( 1/(1+ a) );
|
||||
}
|
||||
|
||||
double Electron::iongbe(double t, double w) {
|
||||
double atan1, atan2;
|
||||
atan1 = atan( (1-ionG2(t,w))/ionG3(t,w) );
|
||||
atan2 = atan( (1+ionG2(t,w))/ionG3(t,w) );
|
||||
return( 2*pi*ionG3(t,w)*(atan1 + atan2) );
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+165
-11
@@ -9,40 +9,194 @@
|
||||
|
||||
#include "katrin.hpp"
|
||||
|
||||
#include "functions.hpp"
|
||||
#include "sstream"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
blitz::TinyVector<double,3> Katrin::getMagField_T(blitz::TinyVector<double,3> loc_m) {
|
||||
blitz::TinyVector<double,3> MagField_T;
|
||||
Katrin::Katrin() {
|
||||
set_cutoffEnergy_eV();
|
||||
}
|
||||
|
||||
vec3 Katrin::getMagField_T(vec3 loc_m) {
|
||||
vec3 MagField_T;
|
||||
MagField_T = 0,0,wgtsMagField_T;
|
||||
return(MagField_T);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> Katrin::getElField_Vm(blitz::TinyVector<double,3> loc_m) {
|
||||
return (blitz::TinyVector<double,3>(0,0,0));
|
||||
vec3 Katrin::getElField_Vm(vec3 loc_m) {
|
||||
return (vec3(0,0,0));
|
||||
}
|
||||
|
||||
double Katrin::getTritiumDensity_m3(blitz::TinyVector<double,3> loc_m) {
|
||||
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 reductcalc_ionFactor = zProjection_m/mid_m;
|
||||
return(reductcalc_ionFactor * wgtsT2Density_m3);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> Katrin::getTotSpeedT2_ms(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
||||
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) );
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> Katrin::getFlowSpeedT2_ms(blitz::TinyVector<double,3> loc_m) {
|
||||
blitz::TinyVector<double,3> speed_ms;
|
||||
vec3 Katrin::getFlowSpeedT2_ms(vec3 loc_m) {
|
||||
vec3 speed_ms;
|
||||
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);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> Katrin::getTempSpeedT2_ms(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
||||
double tempOffsetABS_ms = calc_Speed_from_Ekin_eV(roll_MB_Energy(wgtsTemp_K,mT2_eV,rngNormal), mT2_eV);
|
||||
blitz::TinyVector<double,3> speed_ms = roll_uniform_direction(rngUni)*tempOffsetABS_ms;
|
||||
vec3 Katrin::getTempSpeedT2_ms(vec3 loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
||||
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);
|
||||
}
|
||||
|
||||
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 = deltaKinEnergy_eV;
|
||||
break;
|
||||
case 2: //Maxwell Boltzman
|
||||
Ekin_eV = roll_MBEnergy(MBTemp_K,me_eV, rngNormal);
|
||||
break;
|
||||
default:
|
||||
throw ("Simulation::injectElectron: Invalid Injection Method.");
|
||||
break;
|
||||
}
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni) * calc_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 > calc_FermiDecaySpectrumDensity(Ecan_eV));
|
||||
return(Ecan_eV);
|
||||
}
|
||||
|
||||
double Katrin::calc_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 * calc_FermiFunction(2, Ekin_eV) * p_eV*(Ekin_eV+me_eV)*pow(TritiumDecayEndpoint_eV-Ekin_eV,2) );
|
||||
}
|
||||
}
|
||||
|
||||
double Katrin::calc_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
|
||||
void Katrin::do_BorisPush(Electron *moveElectron) {
|
||||
double MFP_m = get_MFP_m(moveElectron);
|
||||
vec3 oldLoc_m = moveElectron->getLoc_m();
|
||||
vec3 E_Vm, B_T;
|
||||
|
||||
double distance = 0.;
|
||||
while (distance < MFP_m) {
|
||||
E_Vm = getElField_Vm(oldLoc_m);
|
||||
B_T = getMagField_T(oldLoc_m);
|
||||
distance += moveElectron->borisFly_m(E_Vm , B_T , dt_s);
|
||||
if (movedOutside(moveElectron->getLoc_m())) {
|
||||
moveElectron->setSpeed_ms(vec3(0,0,0));
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void Katrin::do_DriftApproximation(Electron *moveElectron) {
|
||||
// Drift Approximation: Assume constant B and only movement out in z=0, z=wgtsLength_m...
|
||||
double MFP_m= get_MFP_m(moveElectron);
|
||||
vec3 oldLoc_m = moveElectron->getLoc_m();
|
||||
vec3 newLoc_m = oldLoc_m;
|
||||
double z_m = oldLoc_m[2];
|
||||
double vz_ms = moveElectron->getSpeed_ms()[2];
|
||||
double vdir = vz_ms < 0 ? -1 : 1;
|
||||
double znew_m = z_m + vdir*MFP_m;
|
||||
|
||||
if (znew_m < 0) {
|
||||
znew_m = 0;
|
||||
} else if (znew_m > wgtsLength_m) {
|
||||
znew_m = wgtsLength_m;
|
||||
}
|
||||
|
||||
newLoc_m[2] = znew_m;
|
||||
moveElectron->setLoc_m(newLoc_m);
|
||||
if (movedOutside(newLoc_m)) {
|
||||
moveElectron->setSpeed_ms(vec3(0,0,0));
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
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->getLoc_m();
|
||||
speedT2_ms = getFlowSpeedT2_ms(loc_m);
|
||||
|
||||
sigmaTot_m2 = moveElectron->calc_SigmaTotal_m2(speedT2_ms);
|
||||
density_m3 = getTritiumDensity_m3(loc_m);
|
||||
MFP_m = 1/(density_m3 * sigmaTot_m2);
|
||||
return(MFP_m);
|
||||
}
|
||||
|
||||
bool Katrin::movedOutside(vec3 loc_m) {
|
||||
double r_m = sqrt( pow(loc_m(0),2) + pow(loc_m(1),2) );
|
||||
return ( ! (loc_m[2]>0 && loc_m[2]<wgtsLength_m && r_m<wgtsRadius_m ) );
|
||||
}
|
||||
|
||||
// Termination
|
||||
bool Katrin::get_Terminated(Electron termElectron) {
|
||||
double Ekin_eV, ETemp_eV;
|
||||
Ekin_eV = termElectron.getKinEnergy_eV();
|
||||
ETemp_eV = kb_eVK*wgtsTemp_K;
|
||||
if (ETemp_eV<0) {
|
||||
throw ("Simulation::checkTermination: ETemp_eV < 0.");
|
||||
}
|
||||
|
||||
if (Ekin_eV<=cutoffEnergy_eV) {
|
||||
return(true);
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
void Katrin::set_cutoffEnergy_eV() {
|
||||
if (cutoffMode==0) {
|
||||
cutoffEnergy_eV = cutoffEnergySet_eV;
|
||||
} else if (cutoffMode==1) {
|
||||
cutoffEnergy_eV = kb_eVK*wgtsTemp_K*cutoffFactor;
|
||||
} else {
|
||||
stringstream ss;
|
||||
ss<<"Mover::Mover(): cutoffMode= "<<cutoffMode<<" not defined.";
|
||||
throw (ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
+35
-10
@@ -10,22 +10,47 @@
|
||||
#define katrin_hpp
|
||||
|
||||
#include "parameter.hpp"
|
||||
#include "particle.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "electron.hpp"
|
||||
|
||||
class Katrin: public Parameter {
|
||||
#include "blitz/tinyvec2.h"
|
||||
#include "blitz/array.h"
|
||||
#include <random/uniform.h>
|
||||
#include <random/normal.h>
|
||||
|
||||
|
||||
class Katrin: private Parameter, private Constants {
|
||||
public:
|
||||
Katrin(){};
|
||||
virtual ~Katrin(){};
|
||||
Katrin();
|
||||
|
||||
blitz::TinyVector<double,3> getMagField_T(blitz::TinyVector<double,3> loc_m);
|
||||
blitz::TinyVector<double,3> getElField_Vm(blitz::TinyVector<double,3> loc_m);
|
||||
double getTritiumDensity_m3(blitz::TinyVector<double,3> loc_m);
|
||||
vec3 getMagField_T(vec3 loc_m);
|
||||
vec3 getElField_Vm(vec3 loc_m);
|
||||
double getTritiumDensity_m3(vec3 loc_m);
|
||||
|
||||
blitz::TinyVector<double,3> getTotSpeedT2_ms(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
||||
blitz::TinyVector<double,3> getFlowSpeedT2_ms(blitz::TinyVector<double,3> loc_m);
|
||||
blitz::TinyVector<double,3> getTempSpeedT2_ms(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
||||
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);
|
||||
|
||||
// Injection
|
||||
Electron injectElectron(int newId, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
||||
private:
|
||||
// Injection
|
||||
double roll_FermiEnergy_eV(ranlib::Uniform<double> *rngUni);
|
||||
double calc_FermiDecaySpectrumDensity(double Ekin_eV);
|
||||
double calc_FermiFunction(double Z, double Ekin_eV);
|
||||
|
||||
// Move Electrons
|
||||
public:
|
||||
void do_BorisPush(Electron *moveElectron);
|
||||
void do_DriftApproximation(Electron *moveElectron);
|
||||
bool movedOutside(blitz::TinyVector<double,3> loc_m);
|
||||
|
||||
// Terminate Electrons
|
||||
bool get_Terminated(Electron termElectron);
|
||||
private:
|
||||
double get_MFP_m(Electron *moveElectron);
|
||||
double cutoffEnergy_eV;
|
||||
void set_cutoffEnergy_eV();
|
||||
};
|
||||
|
||||
#endif /* katrin_hpp */
|
||||
|
||||
@@ -7,3 +7,112 @@
|
||||
//
|
||||
|
||||
#include "logger.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
Logger::Logger() {
|
||||
if (numberZBins == 0) {
|
||||
cout<<"Logging turned off."<<endl;
|
||||
logging = false;
|
||||
return;
|
||||
}
|
||||
set_zLogValues();
|
||||
set_outStream();
|
||||
}
|
||||
|
||||
void Logger::logElectron(Electron *logElectron, blitz::TinyVector<double,3> oldLoc_m) {
|
||||
if (!logging) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Assumption: no change of sign in v_z
|
||||
if (numberZBins == -1) {
|
||||
outStream[0]<<*logElectron<<endl;
|
||||
} else {
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = logElectron->getLoc_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]<<*logElectron<<endl; // Location wrong, because it s the new Location.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::set_zLogValues() {
|
||||
zLogValues.clear();
|
||||
logging = true;
|
||||
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);
|
||||
} else {
|
||||
for (int i = 0;i<numberZBins;i++) {
|
||||
zLogValues.push_back( i*wgtsLength_m/(numberZBins-1) );
|
||||
}
|
||||
cout<<"Logging "<<numberZBins<<" z-Values."<<endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void Logger::set_outStream() {
|
||||
string dirname = getDirName();
|
||||
|
||||
if (numberZBins == -1) {
|
||||
outStream = new ofstream [1];
|
||||
stringstream ss;
|
||||
ss <<dirname << "/all" << ".dat";
|
||||
outStream[0].open(ss.str().c_str());
|
||||
} else {
|
||||
outStream = new ofstream [numberZBins];
|
||||
for (int i = 0; i < numberZBins; i++)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << dirname << "/z=" << zLogValues[i] << ".dat";
|
||||
outStream[i].open(ss.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string Logger::getDirName() {
|
||||
string poub = getenv("parpath");
|
||||
string pname = getenv("parfile");
|
||||
int i = 1;
|
||||
stringstream dirname;
|
||||
struct stat statbuf;
|
||||
int isDir;
|
||||
do {
|
||||
dirname.str(std::string());
|
||||
dirname << poub << "/" << pname << "_" << getTimeString() << "_" << i++;
|
||||
isDir = 0;
|
||||
if (stat(dirname.str().c_str(), &statbuf) != -1) {
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
isDir = 1;
|
||||
}
|
||||
}
|
||||
} while ( isDir == 1 );
|
||||
if (mkdir(dirname.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::initLogger: Could not create folder "<<dirname.str()<<" for Logging.";
|
||||
throw (ss.str());
|
||||
}
|
||||
return(dirname.str());
|
||||
}
|
||||
|
||||
string Logger::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);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,25 @@
|
||||
#ifndef logger_hpp
|
||||
#define logger_hpp
|
||||
|
||||
#include <stdio.h>
|
||||
#include "parameter.hpp"
|
||||
#include "electron.hpp"
|
||||
|
||||
|
||||
class Logger : private Parameter {
|
||||
public:
|
||||
Logger();
|
||||
|
||||
void logElectron(Electron *logElectron,blitz::TinyVector<double,3> oldLoc_m);
|
||||
private:
|
||||
bool logging;
|
||||
std::vector<double> zLogValues;
|
||||
std::ofstream *outStream;
|
||||
|
||||
void set_zLogValues();
|
||||
void set_outStream();
|
||||
std::string getDirName();
|
||||
std::string getTimeString();
|
||||
};
|
||||
|
||||
|
||||
#endif /* logger_hpp */
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
//
|
||||
|
||||
#include "simulation.hpp"
|
||||
//#include "tests.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
//runTests();
|
||||
|
||||
@@ -20,8 +20,7 @@ int main(int argc, const char * argv[]) {
|
||||
|
||||
|
||||
Simulation Sim;
|
||||
Sim.initLogger();
|
||||
Sim.doTC6();
|
||||
Sim.doit();
|
||||
|
||||
duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;
|
||||
cout<<"Duration: "<< duration <<'\n';
|
||||
|
||||
@@ -14,8 +14,8 @@ TARGETS = mcelectron
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
mcelectron: main.o functions.o constants.o katrin.o simulation.o \
|
||||
particle.o electron.o elastic.o ionization.o
|
||||
mcelectron: main.o parameter.o functions.o constants.o katrin.o logger.o simulation.o \
|
||||
particle.o electron.o elastic.o ionization.o bedionization.o
|
||||
$(CXX) -o $@ $^ $(LDFLAGS) $(LOADLIBES)
|
||||
|
||||
%.o : %.cpp
|
||||
|
||||
@@ -6,4 +6,90 @@
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "parameter.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
Parameter::Parameter() {
|
||||
// Simulation Specs
|
||||
seed = (int)getValue("seed");
|
||||
numTotalElectrons = (long int)getValue("numTotalElectrons");
|
||||
dt_s = getValue("dt_s");
|
||||
injectionMethod = (int)getValue("injectionMethod");
|
||||
deltaKinEnergy_eV = getValue("deltaKinEnergy_eV");
|
||||
MBTemp_K = getValue("MBTemp_K");
|
||||
elaOn = (int)getValue("elaOn");
|
||||
ionOn = (int)getValue("ionOn");
|
||||
propagationMethod = (int)getValue("propagationMethod");
|
||||
|
||||
// Cutoff
|
||||
cutoffMode = (int)getValue("cutoffMode");
|
||||
cutoffEnergySet_eV = getValue("cutoffEnergySet_eV");
|
||||
cutoffFactor = getValue("cutoffFactor");
|
||||
|
||||
// Katrin Specs
|
||||
wgtsMagField_T = getValue("wgtsMagField_T");
|
||||
wgtsLength_m = getValue("wgtsLength_m");
|
||||
wgtsRadius_m = getValue("wgtsRadius_m");
|
||||
wgtsT2Density_m3 = getValue("wgtsT2Density_m3");
|
||||
wgtsTemp_K = getValue("wgtsTemp_K");
|
||||
wgtsT2FlowSpeed_ms = getValue("wgtsT2FlowSpeed_ms");
|
||||
|
||||
// Output
|
||||
numberZBins = getValue ("numberZBins");
|
||||
}
|
||||
|
||||
|
||||
double Parameter::getValue(std::string varName) {
|
||||
char* ext = (char*)("cat");
|
||||
char* str = strdup(varName.c_str());
|
||||
double temp;
|
||||
char dummy[256];
|
||||
char fname[256],*parfile;
|
||||
FILE *fcat;
|
||||
|
||||
if (getenv("parpath") == NULL)
|
||||
{
|
||||
throw ("Parameter::value: Environment variable parpath not defined.");
|
||||
}
|
||||
strcpy(fname, getenv("parpath"));
|
||||
parfile = getenv("parfile");
|
||||
if (parfile == NULL)
|
||||
{
|
||||
throw ("Parameter::value: Environment variable parfile not defined.");
|
||||
}
|
||||
if (!ext)
|
||||
{
|
||||
ext = (char*)("cat");
|
||||
}
|
||||
sprintf(fname,"%s/%s.%s",getenv("parpath"),getenv("parfile"), ext);
|
||||
if (!(fcat = fopen(fname, "r")))
|
||||
{
|
||||
stringstream ss;
|
||||
ss<<"Parameter::value: Can not open file " <<fname<<".";
|
||||
throw (ss.str());
|
||||
}
|
||||
while (!feof(fcat))
|
||||
{
|
||||
// fscanf(fcat, "'%s%*[^']'%F%*[^']",dummy,&temp); 1
|
||||
fscanf(fcat, "%s = %lf", dummy, &temp);
|
||||
// if (strncmp(dummy, str,strlen(str)) == 0) {
|
||||
if (strcmp(dummy, str) == 0)
|
||||
{
|
||||
fclose(fcat);
|
||||
return(temp);
|
||||
}
|
||||
}
|
||||
fclose(fcat);
|
||||
|
||||
stringstream ss;
|
||||
ss<<"Parameter::value: Variable "<<str<<" not found.";
|
||||
throw (ss.str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,44 +9,12 @@
|
||||
#ifndef parameter_hpp
|
||||
#define parameter_hpp
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "functions.hpp"
|
||||
#include "string"
|
||||
|
||||
|
||||
class Parameter: protected Constants {
|
||||
class Parameter {
|
||||
public:
|
||||
virtual ~Parameter(){};
|
||||
Parameter();
|
||||
|
||||
Parameter() {
|
||||
// Simulation Specs
|
||||
seed = (int)getValue("seed");
|
||||
numTotalElectrons = (long int)getValue("numTotalElectrons");
|
||||
dt_s = getValue("dt_s");
|
||||
injectionMethod = (int)getValue("injectionMethod");
|
||||
deltaKinEnergy_eV = getValue("deltaKinEnergy_eV");
|
||||
MBTemp_K = getValue("MBTemp_K");
|
||||
elaOn = (int)getValue("elaOn");
|
||||
ionOn = (int)getValue("ionOn");
|
||||
propagationMethod = (int)getValue("propagationMethod");
|
||||
|
||||
// Cutoff
|
||||
cutoffMode = (int)getValue("cutoffMode");
|
||||
cutoffEnergySet_eV = getValue("cutoffEnergySet_eV");
|
||||
cutoffFactor = getValue("cutoffFactor");
|
||||
|
||||
// Katrin Specs
|
||||
wgtsMagField_T = getValue("wgtsMagField_T");
|
||||
wgtsLength_m = getValue("wgtsLength_m");
|
||||
wgtsRadius_m = getValue("wgtsRadius_m");
|
||||
wgtsT2Density_m3 = getValue("wgtsT2Density_m3");
|
||||
wgtsTemp_K = getValue("wgtsTemp_K");
|
||||
wgtsT2FlowSpeed_ms = getValue("wgtsT2FlowSpeed_ms");
|
||||
|
||||
// Output
|
||||
numberZBins = getValue ("numberZBins");
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
//Simulation Specs
|
||||
int seed;
|
||||
@@ -76,53 +44,7 @@ protected:
|
||||
int numberZBins;
|
||||
|
||||
private:
|
||||
double getValue(string varName, char* ext = (char*)("cat")) {
|
||||
char* str = strdup(varName.c_str());
|
||||
double temp;
|
||||
char dummy[256];
|
||||
char fname[256],*pname;
|
||||
FILE *fcat;
|
||||
|
||||
if (getenv("poub") == NULL)
|
||||
{
|
||||
throw ("Parameter::value: Environment variable poub not defined.");
|
||||
}
|
||||
strcpy(fname, getenv("poub"));
|
||||
pname = getenv("pname");
|
||||
if (pname == NULL)
|
||||
{
|
||||
throw ("Parameter::value: Environment variable pname not defined.");
|
||||
}
|
||||
if (!ext)
|
||||
{
|
||||
ext = (char*)("cat");
|
||||
}
|
||||
sprintf(fname,"%s/%s.%s",getenv("poub"),getenv("pname"), ext);
|
||||
if (!(fcat = fopen(fname, "r")))
|
||||
{
|
||||
stringstream ss;
|
||||
ss<<"Parameter::value: Can not open file " <<fname<<".";
|
||||
throw (ss.str());
|
||||
}
|
||||
while (!feof(fcat))
|
||||
{
|
||||
// fscanf(fcat, "'%s%*[^']'%F%*[^']",dummy,&temp); 1
|
||||
fscanf(fcat, "%s = %lf", dummy, &temp);
|
||||
// if (strncmp(dummy, str,strlen(str)) == 0) {
|
||||
if (strcmp(dummy, str) == 0)
|
||||
{
|
||||
fclose(fcat);
|
||||
return(temp);
|
||||
}
|
||||
}
|
||||
fclose(fcat);
|
||||
|
||||
stringstream ss;
|
||||
ss<<"Parameter::value: Variable "<<str<<" not found.";
|
||||
throw (ss.str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
double getValue(std::string varName);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#include "particle.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
// Overload <<
|
||||
ostream& operator<<(ostream& os, const species& SpecOut) {
|
||||
@@ -62,16 +64,8 @@ ostream& operator<<(ostream& os, const Particle& partOut) {
|
||||
return os;
|
||||
}
|
||||
|
||||
Particle::Particle(double mass_eV, double charge_e, blitz::TinyVector<double,3> speed_ms, species spec) {
|
||||
mass_eV = mass_eV;
|
||||
Z = charge_e;
|
||||
x_m = blitz::TinyVector<double,3>(0,0,0);
|
||||
v_ms = speed_ms;
|
||||
s = spec;
|
||||
}
|
||||
|
||||
Particle::Particle(double mass_eV, double charge_e,blitz::TinyVector<double,3> loc_m, blitz::TinyVector<double,3> speed_ms, double idnum, double parentIdnum, species spec) {
|
||||
mass_eV = mass_eV;
|
||||
Particle::Particle(double mass_eV, double charge_e,vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum, species spec) {
|
||||
m_eV = mass_eV;
|
||||
Z = charge_e;
|
||||
x_m = loc_m;
|
||||
v_ms = speed_ms;
|
||||
|
||||
@@ -10,21 +10,27 @@
|
||||
#define particle_hpp
|
||||
|
||||
#include "parameter.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "functions.hpp"
|
||||
|
||||
#include "iostream"
|
||||
#include "blitz/tinyvec2.h"
|
||||
#include "blitz/array.h"
|
||||
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
typedef enum species{undef, electron, positron, proton, tritium, tritium2, helium, deuterium, DT}species;
|
||||
ostream& operator<<(ostream& os, const species& SpecOut);
|
||||
std::ostream& operator<<(std::ostream& os, const species& SpecOut);
|
||||
|
||||
class Particle: protected Parameter {
|
||||
|
||||
class Particle: protected Parameter, protected Constants{
|
||||
public:
|
||||
virtual ~Particle() {}
|
||||
Particle(double mass_eV, double charge_e, blitz::TinyVector<double,3> speed_ms, species spec);
|
||||
Particle(double mass_eV, double charge_e,blitz::TinyVector<double,3> loc_m, blitz::TinyVector<double,3> speed_ms, double idnum, double parentIdnum, species spec);
|
||||
Particle(double mass_eV, double charge_e,vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum, species spec);
|
||||
|
||||
protected:
|
||||
double m_eV;
|
||||
double Z;
|
||||
blitz::TinyVector<double,3> x_m;
|
||||
blitz::TinyVector<double,3> v_ms;
|
||||
vec3 x_m;
|
||||
vec3 v_ms;
|
||||
species s;
|
||||
unsigned long int Id;
|
||||
unsigned long int parentId;
|
||||
@@ -34,8 +40,8 @@ public:
|
||||
// Get Properties Methods
|
||||
double getMass_eV() { return(m_eV); }
|
||||
double getCharge_e() { return(Z); }
|
||||
blitz::TinyVector<double,3> getLoc_m() { return(x_m); }
|
||||
blitz::TinyVector<double,3> getSpeed_ms() { return(v_ms); }
|
||||
vec3 getLoc_m() { return(x_m); }
|
||||
vec3 getSpeed_ms() { return(v_ms); }
|
||||
species getSpecies() {return(s); }
|
||||
double getId() { return(Id); }
|
||||
double getParentId() { return(parentId); }
|
||||
@@ -56,7 +62,7 @@ protected:
|
||||
void changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm,blitz::TinyVector<double, 3> B_T , double dt_s);
|
||||
|
||||
public:
|
||||
friend ostream& operator<<(ostream& os, const Particle& partOut);
|
||||
friend std::ostream& operator<<(std::ostream& os, const Particle& partOut);
|
||||
};
|
||||
|
||||
|
||||
|
||||
+60
-278
@@ -6,78 +6,60 @@
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#include "simulation.hpp"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
Simulation::Simulation() {
|
||||
numberElectrons = 0;
|
||||
rngUni.seed(seed);
|
||||
updater_numberOfPrevious = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Simulation::doit() {
|
||||
blitz::TinyVector <double,3> loc_m;
|
||||
while ( (numInjectedElectrons < numTotalElectrons) || (electronQue.size() > 0) ) {
|
||||
vec3 oldLoc_m;
|
||||
while ( (numberElectrons < numTotalElectrons) || (electronQue.size() > 0) ) {
|
||||
if (electronQue.empty()) {
|
||||
electronQue.push_back(injectElectron());
|
||||
numInjectedElectrons++;
|
||||
electronQue.push_back(Kat.injectElectron(numberElectrons++, &rngUni, &rngNormal));
|
||||
}
|
||||
|
||||
if (numInjectedElectrons%100 == 0){
|
||||
cout<<numInjectedElectrons<<"/"<<numTotalElectrons<<endl;
|
||||
}
|
||||
|
||||
if (propagationMethod==0) {
|
||||
moveElectronDriftApproximation( &electronQue.front() , getMFP_m(electronQue.front()) );
|
||||
} else if (propagationMethod==1) {
|
||||
moveElectronBorisPush(&electronQue.front(),getMFP_m(electronQue.front())); // If moved outside set v = 0,0,0;
|
||||
} else {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::doit(): propagationMethod= "<<propagationMethod<<" not valid.";
|
||||
throw (ss.str());
|
||||
}
|
||||
|
||||
|
||||
loc_m = electronQue.front().getLoc_m();
|
||||
switch ( electronQue.front().roll_Interaction(Kat.getFlowSpeedT2_ms(loc_m),&rngUni) ) {
|
||||
case 0: //Moved Outside
|
||||
break;
|
||||
case 1: // Elastic Scattering
|
||||
electronQue.front().do_elaScattering(Kat.getTotSpeedT2_ms(loc_m, &rngUni, &rngNormal) , &rngUni);
|
||||
break;
|
||||
case 2: // Ionization
|
||||
electronQue.push_back( electronQue.front().do_Ionization(Kat.getTotSpeedT2_ms(loc_m, &rngUni, &rngNormal), numInjectedElectrons, &rngUni) );
|
||||
numInjectedElectrons++;
|
||||
|
||||
// Update Ions...
|
||||
break;
|
||||
case 3: // Recombination
|
||||
break;
|
||||
default:
|
||||
throw ("Simulation::doit(): getprocess() returned unknown event");
|
||||
break;
|
||||
}
|
||||
if (checkTermination (electronQue.front())) {
|
||||
status_updater();
|
||||
oldLoc_m = electronQue.front().getLoc_m();
|
||||
move_electron(&electronQue.front());
|
||||
Log.logElectron(&electronQue.front(), oldLoc_m);
|
||||
do_interaction(&electronQue.front());
|
||||
|
||||
if (Kat.get_Terminated (electronQue.front())) {
|
||||
electronQue.pop_front();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
void Simulation::doTC6() {
|
||||
cout<<endl<<"Simulation::doTC6: Doing Testcase 6."<<endl<<endl;
|
||||
stringstream fileName;
|
||||
fileName << getDirName() << "/TC6all.dat";
|
||||
fileName << Log.getDirName() << "/TC6all.dat";
|
||||
|
||||
ofstream outTC6;
|
||||
outTC6.open (fileName.str().c_str());
|
||||
|
||||
blitz::TinyVector <double,3> loc_m;
|
||||
while ( (numInjectedElectrons < numTotalElectrons) || (electronQue.size() > 0) ) {
|
||||
while ( (numberElectrons < numTotalElectrons) || (electronQue.size() > 0) ) {
|
||||
if (!electronQue.empty()) {
|
||||
throw ("Simulation::doTC6: electronQue should be empty");
|
||||
}
|
||||
|
||||
electronQue.push_back(injectElectron());
|
||||
numInjectedElectrons++;
|
||||
electronQue.push_back(Kat.injectElectron(numberElectrons, &rngUni, &rngNormal));
|
||||
numberElectrons++;
|
||||
|
||||
|
||||
if (numInjectedElectrons%100 == 0){
|
||||
cout<<numInjectedElectrons<<"/"<<numTotalElectrons<<endl;
|
||||
if (numberElectrons%100 == 0){
|
||||
cout<<numberElectrons<<"/"<<numTotalElectrons<<endl;
|
||||
}
|
||||
|
||||
if (propagationMethod==0) {
|
||||
@@ -99,8 +81,8 @@ void Simulation::doTC6() {
|
||||
throw ("Simulation::doTC6(): Elastic Scattering should be turned off.");
|
||||
break;
|
||||
case 2: // Ionization
|
||||
electronQue.push_back( electronQue.front().do_Ionization(Kat.getTotSpeedT2_ms(loc_m, &rngUni, &rngNormal), numInjectedElectrons, &rngUni) );
|
||||
numInjectedElectrons++;
|
||||
electronQue.push_back( electronQue.front().do_Ionization(Kat.getTotSpeedT2_ms(loc_m, &rngUni, &rngNormal), numberElectrons, &rngUni) );
|
||||
numberElectrons++;
|
||||
electronQue.pop_front();
|
||||
break;
|
||||
default:
|
||||
@@ -115,245 +97,45 @@ void Simulation::doTC6() {
|
||||
}
|
||||
outTC6.close();
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Injection
|
||||
Electron Simulation::injectElectron() {
|
||||
|
||||
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;
|
||||
|
||||
blitz::TinyVector<double,3> loc_m = blitz::TinyVector<double,3> (r_m*cos(phi),r_m*sin(phi),z_m);
|
||||
double Ekin_eV;
|
||||
switch(injectionMethod) {
|
||||
case 0: // Fermi
|
||||
Ekin_eV = getEkin_eVFermi_eV();
|
||||
break;
|
||||
case 1: //Delta
|
||||
Ekin_eV = deltaKinEnergy_eV;
|
||||
break;
|
||||
case 2: //Maxwell Boltzman
|
||||
Ekin_eV = roll_MB_Energy(MBTemp_K,me_eV, &rngNormal);
|
||||
break;
|
||||
default:
|
||||
throw ("Simulation::injectElectron: Invalid Injection Method.");
|
||||
break;
|
||||
}
|
||||
blitz::TinyVector<double,3> speed_ms = roll_uniform_direction(&rngUni) * calc_Speed_from_Ekin_eV(Ekin_eV,me_eV);
|
||||
return (Electron(loc_m, speed_ms,numInjectedElectrons,numInjectedElectrons));
|
||||
}
|
||||
|
||||
/*
|
||||
double Simulation::getBetaDecayEnergyRejection_eV() {
|
||||
double (Simulation::*fptr) (double) = &Simulation::EnergyDistributionBetaDecay;
|
||||
return (doRejectionMethod(fptr , 1e-15, TritiumDecayEndpoint_eV ,1.5e-28, &rngUni));
|
||||
}
|
||||
*/
|
||||
|
||||
double Simulation::getEkin_eVFermi_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 > ESpectrumBetaDecay(Ecan_eV));
|
||||
return(Ecan_eV);
|
||||
}
|
||||
|
||||
double Simulation::ESpectrumBetaDecay(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 * FermiFunction(2, Ekin_eV) * p_eV*(Ekin_eV+me_eV)*pow(TritiumDecayEndpoint_eV-Ekin_eV,2) );
|
||||
}
|
||||
}
|
||||
double Simulation::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)) );
|
||||
}
|
||||
|
||||
|
||||
// Moving
|
||||
void Simulation::moveElectronBorisPush(Electron *moveElectron, double MFP_m) {
|
||||
blitz::TinyVector<double,3> oldLoc_m = moveElectron->getLoc_m();
|
||||
blitz::TinyVector<double,3> E_Vm = Kat.getElField_Vm(oldLoc_m);
|
||||
blitz::TinyVector<double,3> B_T = Kat.getMagField_T(oldLoc_m);
|
||||
|
||||
double distance = 0.;
|
||||
while (distance < MFP_m) {
|
||||
distance += moveElectron->borisFly_m(E_Vm , B_T , dt_s);
|
||||
if (movedOutside(moveElectron->getLoc_m())) {
|
||||
logElectron(moveElectron,oldLoc_m);
|
||||
moveElectron->setSpeed_ms(blitz::TinyVector<double,3>(0,0,0));
|
||||
return;
|
||||
void Simulation::status_updater() {
|
||||
if (numberElectrons%100 == 0){
|
||||
if (updater_numberOfPrevious!=numberElectrons) {
|
||||
cout<<numberElectrons<<"/"<<numTotalElectrons<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
logElectron(moveElectron,oldLoc_m);
|
||||
return;
|
||||
}
|
||||
|
||||
void Simulation::moveElectronDriftApproximation(Electron *moveElectron, double MFP_m) {
|
||||
// Drift Approximation: Assume constant B and only movement out in z=0, z=wgtsLength_m...
|
||||
blitz::TinyVector<double,3> oldLoc_m = moveElectron->getLoc_m();
|
||||
blitz::TinyVector<double,3> newLoc_m = oldLoc_m;
|
||||
double z_m = oldLoc_m[2];
|
||||
double vz_ms = moveElectron->getSpeed_ms()[2];
|
||||
double vdir = vz_ms < 0 ? -1 : 1;
|
||||
double znew_m = z_m + vdir*MFP_m;
|
||||
|
||||
if (znew_m < 0) {
|
||||
znew_m = 0;
|
||||
} else if (znew_m > wgtsLength_m) {
|
||||
znew_m = wgtsLength_m;
|
||||
}
|
||||
|
||||
newLoc_m[2] = znew_m;
|
||||
moveElectron->setLoc_m(newLoc_m);
|
||||
logElectron(moveElectron,oldLoc_m);
|
||||
|
||||
if (znew_m==0 || znew_m==wgtsLength_m) {
|
||||
moveElectron->setSpeed_ms(blitz::TinyVector<double,3>(0,0,0));
|
||||
updater_numberOfPrevious = numberElectrons;
|
||||
}
|
||||
}
|
||||
|
||||
double Simulation::getMFP_m(Electron moveElectron) {
|
||||
//Rework for inserting vector of Interactions
|
||||
blitz::TinyVector<double,3> loc_m, speedT2_ms;
|
||||
double sigmaTot_m2, density_m3, MFP_m;
|
||||
loc_m = moveElectron.getLoc_m();
|
||||
speedT2_ms = Kat.getFlowSpeedT2_ms(loc_m);
|
||||
|
||||
sigmaTot_m2 = moveElectron.calc_SigmaTotal_m2(speedT2_ms);
|
||||
density_m3 = Kat.getTritiumDensity_m3(loc_m);
|
||||
MFP_m = 1/(density_m3 * sigmaTot_m2);
|
||||
return(MFP_m);
|
||||
}
|
||||
bool Simulation::movedOutside(blitz::TinyVector<double,3> loc_m) {
|
||||
double r_m = sqrt( pow(loc_m(0),2) + pow(loc_m(1),2) );
|
||||
return ( ! (loc_m[2]>0 && loc_m[2]<wgtsLength_m && r_m<wgtsRadius_m ) );
|
||||
}
|
||||
|
||||
|
||||
// Termination
|
||||
bool Simulation::checkTermination(Electron termElectron) {
|
||||
double Ekin_eV, ETemp_eV;
|
||||
Ekin_eV = termElectron.getKinEnergy_eV();
|
||||
ETemp_eV = kb_eVK*wgtsTemp_K;
|
||||
if (ETemp_eV<0) {
|
||||
throw ("Simulation::checkTermination: ETemp_eV < 0.");
|
||||
}
|
||||
|
||||
if (Ekin_eV<=cutoffEnergy_eV) {
|
||||
return(true);
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
// Logging
|
||||
void Simulation::initLogger(void) {
|
||||
// Set zLogValues;
|
||||
zLogValues.clear();
|
||||
logging = true;
|
||||
if (numberZBins == 0) {
|
||||
cout<<"Logging turned off."<<endl;
|
||||
logging = false;
|
||||
return;
|
||||
} else 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);
|
||||
void Simulation::move_electron(Electron *moveElectron) {
|
||||
if (propagationMethod==0) {
|
||||
Kat.do_DriftApproximation(moveElectron);
|
||||
} else if (propagationMethod==1) {
|
||||
Kat.do_BorisPush(moveElectron); // If moved outside set v = 0,0,0;
|
||||
} else {
|
||||
for (int i = 0;i<numberZBins;i++) {
|
||||
zLogValues.push_back( i*wgtsLength_m/(numberZBins-1) );
|
||||
}
|
||||
cout<<"Logging "<<numberZBins<<" z-Values."<<endl;
|
||||
}
|
||||
|
||||
|
||||
string dirname = getDirName();
|
||||
|
||||
if (numberZBins == -1) {
|
||||
outStream = new ofstream [1];
|
||||
stringstream fileName;
|
||||
fileName << dirname << "/all" << ".dat";
|
||||
outStream[0].open(fileName.str().c_str());
|
||||
} else {
|
||||
outStream = new ofstream [numberZBins];
|
||||
for (int i = 0; i < numberZBins; i++)
|
||||
{
|
||||
stringstream fileName;
|
||||
fileName << dirname << "/z=" << zLogValues[i] << ".dat";
|
||||
outStream[i].open(fileName.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string Simulation::getDirName() {
|
||||
string poub = getenv("poub");
|
||||
string pname = getenv("pname");
|
||||
int i = 1;
|
||||
stringstream dirname;
|
||||
struct stat statbuf;
|
||||
int isDir;
|
||||
do {
|
||||
dirname.str(std::string());
|
||||
dirname << poub << "/" << pname << "_" << getTimeString() << "_" << i++;
|
||||
isDir = 0;
|
||||
if (stat(dirname.str().c_str(), &statbuf) != -1) {
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
isDir = 1;
|
||||
}
|
||||
}
|
||||
} while ( isDir == 1 );
|
||||
if (mkdir(dirname.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::initLogger: Could not create folder "<<dirname.str()<<" for Logging.";
|
||||
ss<<"Simulation::doit(): propagationMethod= "<<propagationMethod<<" not valid.";
|
||||
throw (ss.str());
|
||||
}
|
||||
return(dirname.str());
|
||||
}
|
||||
|
||||
string Simulation::getTimeString() {
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
char buffer[80];
|
||||
time (&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
strftime(buffer,sizeof(buffer),"%Y%m%d",timeinfo);
|
||||
string str(buffer);
|
||||
return(str);
|
||||
}
|
||||
void Simulation::logElectron(Electron *logElectron, blitz::TinyVector<double,3> oldLoc_m) {
|
||||
if (!logging) {
|
||||
return;
|
||||
}
|
||||
// Annahme: Ohne Interaction bliebt Bewegung in z-Richtung Konstant.
|
||||
if (numberZBins == -1) {
|
||||
outStream[0]<<*logElectron<<endl;
|
||||
} else {
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = logElectron->getLoc_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]<<*logElectron<<endl; // Location wrong, because it s the new Location.
|
||||
}
|
||||
}
|
||||
void Simulation::do_interaction(Electron *interactElectron) {
|
||||
vec3 newLoc_m = electronQue.front().getLoc_m();
|
||||
switch ( interactElectron->roll_Interaction(Kat.getFlowSpeedT2_ms(newLoc_m),&rngUni) ) {
|
||||
case 0: //Moved Outside
|
||||
break;
|
||||
case 1: // Elastic Scattering
|
||||
interactElectron->do_elaScattering(Kat.getTotSpeedT2_ms(newLoc_m, &rngUni, &rngNormal) , &rngUni);
|
||||
break;
|
||||
case 2: // Ionization
|
||||
electronQue.push_back( interactElectron->do_Ionization(Kat.getTotSpeedT2_ms(newLoc_m, &rngUni, &rngNormal), numberElectrons, &rngUni) );
|
||||
numberElectrons++;
|
||||
// Update Ions...
|
||||
break;
|
||||
case 3: // Recombination
|
||||
break;
|
||||
default:
|
||||
throw ("Simulation::doit(): getprocess() returned unknown event");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,67 +9,36 @@
|
||||
#ifndef simulation_hpp
|
||||
#define simulation_hpp
|
||||
|
||||
|
||||
#include "parameter.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "katrin.hpp"
|
||||
#include "electron.hpp"
|
||||
#include "logger.hpp"
|
||||
|
||||
#include <deque>
|
||||
|
||||
|
||||
class Simulation: public Parameter {
|
||||
class Simulation: private Parameter, private Constants {
|
||||
public:
|
||||
~Simulation(){};
|
||||
Simulation() {
|
||||
numInjectedElectrons = 0;
|
||||
rngUni.seed(seed);
|
||||
logging = false;
|
||||
if (cutoffMode==0) {
|
||||
cutoffEnergy_eV = cutoffEnergySet_eV;
|
||||
} else if (cutoffMode==1) {
|
||||
cutoffEnergy_eV = kb_eVK*wgtsTemp_K*cutoffFactor;
|
||||
} else {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::Simulation: cutoffMode= "<<cutoffMode<<" not defined.";
|
||||
throw (ss.str());
|
||||
}
|
||||
|
||||
};
|
||||
void initLogger(void);
|
||||
void doit(void);
|
||||
void doTC6(void);
|
||||
Simulation();
|
||||
void doit();
|
||||
// void doTC6(void);
|
||||
|
||||
private:
|
||||
void status_updater();
|
||||
void move_electron(Electron *moveElectron);
|
||||
void do_interaction(Electron *interactElectron);
|
||||
|
||||
|
||||
protected:
|
||||
// Simulation
|
||||
Katrin Kat;
|
||||
Logger Log;
|
||||
ranlib::Uniform<double> rngUni;
|
||||
ranlib::NormalUnit<double> rngNormal;
|
||||
int numInjectedElectrons;
|
||||
deque<Electron> electronQue;
|
||||
|
||||
|
||||
// Injection
|
||||
Electron injectElectron();
|
||||
double getEkin_eVFermi_eV();
|
||||
double ESpectrumBetaDecay(double Ekin_eV);
|
||||
double FermiFunction(double Z, double Ekin_eV);
|
||||
|
||||
// Moving
|
||||
void moveElectronBorisPush(Electron *moveElectron, double MFP_m);
|
||||
void moveElectronDriftApproximation(Electron *moveElectron, double MFP_m);
|
||||
double getMFP_m(Electron moveElectron);
|
||||
bool movedOutside(blitz::TinyVector<double,3> loc_m);
|
||||
|
||||
// Termination
|
||||
bool checkTermination(Electron termElectron);
|
||||
double cutoffEnergy_eV;
|
||||
|
||||
// Logging
|
||||
bool logging;
|
||||
|
||||
ofstream *outStream;
|
||||
vector<double> zLogValues;
|
||||
void logElectron(Electron *logElectron,blitz::TinyVector<double,3> oldLoc_m);
|
||||
string getDirName();
|
||||
string getTimeString();
|
||||
int numberElectrons;
|
||||
std::deque<Electron> electronQue;
|
||||
int updater_numberOfPrevious;
|
||||
};
|
||||
|
||||
|
||||
#endif /* simulation_hpp */
|
||||
|
||||
Reference in New Issue
Block a user