Screenshot with working ionization function.

Ionization will be changed to BED model.
This commit is contained in:
Christian
2019-02-22 14:14:14 +01:00
parent dd483c13f2
commit ef33e77184
29 changed files with 15791 additions and 807 deletions
File diff suppressed because it is too large Load Diff
+24 -134
View File
@@ -2,152 +2,42 @@
// constants.cpp
// mc_electron
//
// Created by Christian Reiling on 06.11.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
// Created by Christian Reiling on 09.02.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#include "constants.h"
#include "constants.hpp"
// Natural Constants
const double Constants::pi = 3.1415;
const double Constants::c_nat = 1.;
const double Constants::c_ms = 299792458;
const double Constants::kb_eVK = 8.6173303e-5;
const double Constants::me_eV = 0.511e6;
const double Constants::qe_e = 1;
const double Constants::re_m = 2.817940322719e-15;
const double Constants::e_C = 1.602176462e-19;
const double Constants::rBohr_m = 0.52917721067e-10;
const double Constants::ERyd_eV = 13.605693009;
// Beta Decay
const double Constants::BetaDecayC = 1.2072343416696292e-47;
const double Constants::ZHe3 = 2.;
const double Constants::Etridecay_eV = 18.574e3;
// Tritium
// 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;
// Beta Decay
const double Constants::BetaDecayConst = 1.2072343416696292e-47;
const double Constants::TritiumDecayEndpoint_eV = 18.574e3;
// Conversation
double Constants::calcAbs(blitz::TinyVector<double,3> vec) {
return( sqrt( pow(vec[0],2) + pow(vec[1],2) + pow(vec[2],2)) );
}
double Constants::calcV_msFromEkin_eV(double Ekin_eV, double m_eV) {
double gamma = calcGammaFromEkin_eV(Ekin_eV, m_eV);
double beta = calcBetaFromGamma(gamma);
return(beta * c_ms);
}
double Constants::calcGammaFromEkin_eV(double Ekin_eV, double m_eV) {
return (1. + Ekin_eV/m_eV);
}
double Constants::calcBetaFromGamma(double gamma) {
return( sqrt(1 - pow(gamma,-2)) );
}
double Constants::calcEkin_eVFromVAbs_ms(double vAbs_ms, double m_eV) {
double beta = calcBetaFromVAbs_ms(vAbs_ms);
double gamma = calcGammaFromBeta(beta);
return ( (gamma-1) * m_eV * pow(c_nat,2) );
}
double Constants::calcBetaFromVAbs_ms(double vAbs_ms) {
return(vAbs_ms/c_ms);
}
double Constants::calcGammaFromBeta(double beta) {
return( pow(1 - pow(beta,2),-0.5) ) ;
}
// Help Functions
blitz::TinyVector<double,3> Constants::zeroVec() {
blitz::TinyVector<double,3> zeroVec;
zeroVec = 0,0,0;
return(zeroVec);
}
blitz::TinyVector<double,3> Constants::getRandDir(ranlib::Uniform<double> *rngUni) {
blitz::TinyVector<double,3> dir;
double Phi_rad = 2*pi*rngUni->random();
double Theta_rad = pi*rngUni->random();
dir = sin(Theta_rad)*cos(Phi_rad) , sin(Theta_rad)*sin(Phi_rad) , cos(Theta_rad);
return(dir);
}
blitz::TinyVector<double,3> Constants::getNewDir(blitz::TinyVector<double,3> oldDir, double theta,double phi) {
// Transformation of direction following Plante and Cucinotta
double theta0, phi0, A3, A4, A5, A11, A21, theta1, phi1;
double phi1c [4];
theta0 = acos(oldDir[2]/calcAbs(oldDir));
phi0 = atan2(oldDir[1],oldDir[0]);
// 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};
A3 = sin(theta)*cos(phi);
A4 = A3*cos(theta0) + cos(theta)*sin(theta0);
A5 = sin(theta)*sin(phi);
A11 = A4*cos(phi0) - A5*sin(phi0);
A21 = A4*sin(phi0) + A5*cos(phi0);
theta1 = acos( cos(theta0)*cos(theta)-A3*sin(theta0) );
// Get right phi1, maybe more elegant way later.
int digits = 6;
double fac = pow(10,digits);
phi1 = -1;
phi1c[0] = acos( roundf ( A11/sin(theta1) *fac)/fac );
phi1c[1] = 2*pi - phi1c[0];
phi1c[2] = asin ( roundf ( A21/sin(theta1) *fac)/fac );
phi1c[3] = pi - phi1c[2];
phi1c[2] = (phi1c[2] > 0) ? phi1c[2] : 2*pi + phi1c[2];
for (int i=0;i<3;i++) {
for (int j=i+1;j<4;j++) {
if (phi1c[i]-phi1c[j] < 0.0001) {
phi1 = phi1c[i];
goto endloops;
}
}
}
endloops:
if (phi1 == -1) {
for (int j = 0;j<3;j++) {
cout<<"phi1c["<<j<<"]="<<phi1c[j]<<endl;
}
std::cerr<<"Interaction::getElaNewDir: phi1 not found."<<std::endl;
exit(1);
}
blitz::TinyVector<double,3> newDir;
newDir = sin(theta1)*cos(phi1) , sin(theta1)*sin(phi1) , cos(theta1);
return(newDir);
}
// Random Generators
double Constants::getRandEnergyMaxwell(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *rngNormal) {
double C, beta, N1,N2,N3;
C = kb_eVK*Temp_K/mass_eV;
beta = 0;
N1 = rngNormal->random();
N2 = rngNormal->random();
N3 = rngNormal->random();
beta = sqrt(C*(N1*N1 + N2*N2 + N3*N3));
return((calcGammaFromBeta(beta)-1)*mass_eV);
}
double Constants::doRejectionMethod(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);
}
// 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;
-73
View File
@@ -1,73 +0,0 @@
//
// constants.h
// mc_electron
//
// Created by Christian Reiling on 08.10.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#ifndef constants_h
#define constants_h
#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;
class Constants
{
public:
Constants() {};
static const double pi;
static const double c_nat;
static const double c_ms;
static const double kb_eVK;
static const double me_eV;
static const double qe_e;
static const double re_m;
static const double e_C;
static const double rBohr_m;
static const double ERyd_eV;
// Beta Decay
static const double BetaDecayC;
static const double ZHe3;
static const double Etridecay_eV;
// Tritium
static const double ZT2;
static const double mT2_eV;
// Conversion Functions
double calcAbs(blitz::TinyVector<double,3> vec);
double calcV_msFromEkin_eV(double Ekin_eV, double m_eV);
double calcGammaFromEkin_eV(double Ekin_eV, double m_eV);
double calcBetaFromGamma(double gamma);
double calcEkin_eVFromVAbs_ms(double vAbs_ms, double m_eV);
double calcBetaFromVAbs_ms(double vAbs_ms);
double calcGammaFromBeta(double beta);
// Help Functions
blitz::TinyVector<double,3> zeroVec();
blitz::TinyVector<double,3> getRandDir(ranlib::Uniform<double> *rngUni);
blitz::TinyVector<double,3> getNewDir(blitz::TinyVector<double,3> oldDir, double theta,double phi);
// Random Generators
double getRandEnergyMaxwell(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
+72
View File
@@ -0,0 +1,72 @@
//
// constants.hpp
// mc_electron
//
// Created by Christian Reiling on 08.10.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#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;
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;
// Particle Properties
static const double me_eV;
static const double re_m;
static const double ZT2;
static const double mT2_eV;
// Beta Decay
static const double BetaDecayConst;
static const double 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;
};
#endif /* constants_hpp */
+59 -1
View File
@@ -6,4 +6,62 @@
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#include <stdio.h>
#include "electron.hpp"
/*
Elastic Scattering:
Using Rutherford Model with screening parameter following
Cross-sections for water vapour for the Monte Carlo electron track structure code from 10eV to the MeV region
S Uehara et al 1993 Phys. Med. Biol. 38 1841
*/
void Electron::do_elaScattering (blitz::TinyVector<double,3> speedT2_ms, ranlib::Uniform<double> *rngUni) {
// Here theta and phi are COM-Angles.... prob not correct. For m1 << m2 COM - Angle ~ Lab Angle
double thetaLab = roll_elaTheta(speedT2_ms, rngUni);
double phiLab = rngUni->random() * 2 * pi;
do_elaKinetics(speedT2_ms,thetaLab, phiLab);
}
double Electron::calc_elaSigma_m2(blitz::TinyVector<double,3> speedT2_ms) {
double SigmaEla_m2;
blitz::TinyVector<double,3> 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);
double numerator = pi*ZT2*(ZT2+1)*re_m*re_m * (1-pow(betaLab,2));
double denominator = elaEta * (elaEta+1)*pow(betaLab,4);
SigmaEla_m2 = numerator/denominator;
return ( SigmaEla_m2 );
}
double Electron::calc_elaEta(blitz::TinyVector<double,3> 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);
double elaTau = Ekin_eVLab_eV/m_eV;
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 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);
double theta = acos( pow( rngUni->random()/const1-pow(2*elaEta,-1) , -1 ) +1+2*elaEta);
return(theta);
}
void Electron::do_elaKinetics(blitz::TinyVector<double,3> 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;
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;
//v2New_ms = (-1*mass_eV*calc_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;
}
+46
View File
@@ -7,3 +7,49 @@
//
#include "electron.hpp"
double Electron::calc_SigmaTotal_m2(blitz::TinyVector<double,3> 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++) {
sigmaTot_m2 += *SigmasIt;
}
return(sigmaTot_m2);
}
vector<double> Electron::calc_SigmaVector_m2(blitz::TinyVector<double,3> speedT2_ms) {
vector<double> Sigmas;
if (elaOn == 1) {
Sigmas.push_back(calc_elaSigma_m2(speedT2_ms));
} else {
Sigmas.push_back(0.);
}
if (ionOn == 1) {
Sigmas.push_back(get_ionSigma_m2(speedT2_ms));
} else {
Sigmas.push_back(0.);
}
return(Sigmas);
}
int Electron::roll_Interaction(blitz::TinyVector<double,3> speedT2_ms, ranlib::Uniform<double> *rngUni) {
// Check Moved Outside
if (getKinEnergy_eV()==0) {
return(0);
}
vector<double> Sigmas = calc_SigmaVector_m2(speedT2_ms);
double RandPoint = rngUni->random() * calc_SigmaTotal_m2(speedT2_ms);
double Sum = 0;
for (int i=0; i<Sigmas.size();i++ ) {
Sum += Sigmas[i];
if (RandPoint<Sum) {
return(i+1);
}
}
throw ("Interaction::roll_Interaction: Error in finding Interaction.");
}
-14
View File
@@ -1,14 +0,0 @@
//
// electron.hpp
// mc_electron
//
// Created by Christian Reiling on 15.01.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef electron_hpp
#define electron_hpp
#include <stdio.h>
#endif /* electron_hpp */
+68
View File
@@ -0,0 +1,68 @@
//
// electron.hpp
// mc_electron
//
// Created by Christian Reiling on 15.01.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef electron_hpp
#define electron_hpp
#include "particle.hpp"
class Electron : public Particle {
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) {};
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);
// 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);
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);
// 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);
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);
*/
};
#endif /* electron_hpp */
+147
View File
@@ -0,0 +1,147 @@
//
// functions.cpp
// mc_electron
//
// Created by Christian Reiling on 07.02.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#include "functions.hpp"
double calc_vecAbs(blitz::TinyVector<double,3> vec) {
return( sqrt( pow(vec[0],2) + pow(vec[1],2) + pow(vec[2],2)) );
}
double calc_Ekin_eV_from_speed(double Speed_ms, double mass_eV) {
double beta = Speed_ms/Constants::c_ms;
if (beta>=1) {
stringstream ss;
ss<<"calc_Ekin_eV_from_speed(): Input speed v="<<Speed_ms<<" m/s equal or exeeds speed of light.";
throw (ss.str());
} else if (beta<0) {
stringstream ss;
ss<<"calc_Ekin_eV_from_speed(): Input speed v="<<Speed_ms<<" m/s is expected to be absolute value therfore >0.";
throw (ss.str());
}
double gamma = calc_gamma_from_beta(beta);
return ( (gamma-1) * mass_eV );
}
double calc_gamma_from_beta(double beta) {
if (beta>=1) {
stringstream ss;
ss<<"calc_gamma_from_beta(): Input beta ="<<beta<<" equal or exeeds 1.";
throw (ss.str());
} else if (beta<0) {
stringstream ss;
ss<<"calc_gamma_from_beta(): Input beta ="<<beta<<" negative.";
throw (ss.str());
}
return( pow(1 - pow(beta,2),-0.5) ) ;
}
double calc_Speed_from_Ekin_eV(double Ekin_eV, double mass_eV) {
if (Ekin_eV<0) {
stringstream ss;
ss<<"calc_Speed_from_Ekin_eV(): Input Ekin_eV ="<<Ekin_eV<<" negative.";
throw (ss.str());
}
double gamma = calc_gamma_from_Ekin_eV(Ekin_eV, mass_eV);
double beta = calc_beta_from_gamma(gamma);
return(beta * Constants::c_ms);
}
double calc_gamma_from_Ekin_eV(double Ekin_eV, double mass_eV) {
if (Ekin_eV<0) {
stringstream ss;
ss<<"calc_gamma_from_Ekin_eV(): Input Ekin_eV ="<<Ekin_eV<<" negative.";
throw (ss.str());
}
return (1. + Ekin_eV/mass_eV);
}
double calc_beta_from_gamma(double gamma) {
if (gamma<1) {
stringstream ss;
ss<<"calc_beta_from_gamma(): Input gamma ="<<gamma<<" smaller 1.";
throw (ss.str());
}
return( sqrt(1 - pow(gamma,-2)) );
}
blitz::TinyVector<double,3> calc_Newdirection(blitz::TinyVector<double,3> 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]);
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.
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*Constants::pi - phi_new_candidates[0];
phi_new_candidates[2] = asin ( roundf ( A21/sin(theta_new) *fac)/fac );
phi_new_candidates[3] = Constants::pi - phi_new_candidates[2];
phi_new_candidates[2] = (phi_new_candidates[2] > 0) ? phi_new_candidates[2] : 2*Constants::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];
goto endloops;
}
}
}
endloops:
if (phi_new == -1) {
for (int j = 0;j<3;j++) {
cout<<"phi1c["<<j<<"]="<<phi_new_candidates[j]<<endl;
}
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)));
}
blitz::TinyVector<double,3> roll_uniform_direction(ranlib::Uniform<double> *rngUni) {
blitz::TinyVector<double,3> 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 C = Constants::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);
}
/*
double doRejectionMethod(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);
}
*/
+29
View File
@@ -0,0 +1,29 @@
//
// 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 "constants.hpp"
double calc_vecAbs(blitz::TinyVector<double,3> vec);
double calc_Speed_from_Ekin_eV(double Ekin_eV, double mass_eV);
double calc_gamma_from_Ekin_eV(double Ekin_eV, double mass_eV);
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);
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);
#endif /* functions_hpp */
+203 -1
View File
@@ -6,4 +6,206 @@
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#include <stdio.h>
#include "electron.hpp"
/*
Ionization:
Following
Differential and total cross sections for ionization of helium and hydrogen by electrons
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 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));
}
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;
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
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) {
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 phi1 = rngUni->random()*2*pi;
double phi2 = phi1-pi;
double theta1 = roll_IonTheta1(T_eV, W_eV, rngUni);
double theta2 = roll_IonTheta2(T_eV, W_eV, rngUni);
double v1Absnew_ms = 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 ;
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... .
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;
Wmin_eV = 0;
Wmax_eV = T_eV-ionET2_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);
}
double Electron::roll_IonTheta1(double T_eV, double W_eV, ranlib::Uniform<double> *rngUni) {
double theta1;
if (W_eV > 100) {
double numerator = W_eV/T_eV;
double denominator = (1-W_eV / T_eV)*(T_eV/(2*m_eV)) + 1;
theta1 = asin(sqrt(numerator/denominator));
} else {
theta1 = rngUni->random()*pi/4;
}
return (theta1);
}
double Electron::roll_IonTheta2(double T_eV, double W_eV, ranlib::Uniform<double> *rngUni) {
double theta2;
if (W_eV > 200) {
double numerator = 1- W_eV/T_eV;
double denominator = 1 + W_eV/(2*m_eV);
theta2 = asin(sqrt(numerator/denominator));
} else if (W_eV >= 50) {
double decider = rngUni->random();
if (decider < 0.9) {
theta2 = 1 + rngUni->random() * pi/4 + pi/4;
} else {
theta2 = rngUni->random() * pi;
}
} else {
theta2 = rngUni->random() * pi;
}
return(theta2);
}
/* 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) );
}
*/
+19 -27
View File
@@ -7,50 +7,42 @@
//
#include "katrin.h"
#include "katrin.hpp"
blitz::TinyVector<double,3> Katrin::getMagField(blitz::TinyVector<double,3> loc_m) {
blitz::TinyVector<double,3> Katrin::getMagField_T(blitz::TinyVector<double,3> loc_m) {
blitz::TinyVector<double,3> MagField_T;
MagField_T = 0,0,wgtsMagField_T;
return(MagField_T);
}
blitz::TinyVector<double,3> Katrin::getElField(blitz::TinyVector<double,3> loc_m) {
blitz::TinyVector<double,3> ElField_Vm;
ElField_Vm = 0,0,0;
return (ElField_Vm);
blitz::TinyVector<double,3> Katrin::getElField_Vm(blitz::TinyVector<double,3> loc_m) {
return (blitz::TinyVector<double,3>(0,0,0));
}
double Katrin::getTritiumDensity(blitz::TinyVector<double,3> loc_m) {
return(wgtsT2Density_m3);
double Katrin::getTritiumDensity_m3(blitz::TinyVector<double,3> 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);
}
Particle Katrin::getT2AverScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni) {
blitz::TinyVector<double,3> Katrin::getTotSpeedT2_ms(blitz::TinyVector<double,3> 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;
// Get Linear Flow
double sign = (loc_m[2] < wgtsLength_m/2.) ? -1 : 1;
double flow_ms = sign*wgtsT2FlowSpeed_ms;
speed_ms = 0,0,flow_ms;
Particle ScatPart;
ScatPart = Particle(mT2_eV, ZT2, speed_ms, tritium2);
ScatPart.setLoc_m(loc_m);
return (ScatPart);
return (speed_ms);
}
Particle Katrin::getT2ScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
Particle ScatPart = getT2AverScatPart(loc_m, rngUni);
blitz::TinyVector<double,3> speed_ms, flowOffset_ms, tempOffset_ms;
// Get Linear Flow
flowOffset_ms = ScatPart.getSpeed_ms();
// Get Temperature Motion
double tempOffsetABS_ms = calcV_msFromEkin_eV(getRandEnergyMaxwell(wgtsTemp_K,mT2_eV,rngNormal), mT2_eV);
tempOffset_ms = getRandDir(rngUni)*tempOffsetABS_ms;
speed_ms = flowOffset_ms + tempOffset_ms;
ScatPart.setSpeed_ms(speed_ms);
return (ScatPart);
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;
return(speed_ms);
}
-31
View File
@@ -1,31 +0,0 @@
//
// katrin.h
// mc_electron
//
// Created by Christian Reiling on 20.09.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#ifndef katrin_h
#define katrin_h
#include "../base/parameter.h"
#include "../particle/particle.h"
class Katrin: public Parameter
{
public:
Katrin(){};
virtual ~Katrin(){};
blitz::TinyVector<double,3> getMagField(blitz::TinyVector<double,3> loc_m);
blitz::TinyVector<double,3> getElField(blitz::TinyVector<double,3> loc_m);
double getTritiumDensity(blitz::TinyVector<double,3> loc_m);
Particle getT2AverScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni);
Particle getT2ScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
};
#endif
+31
View File
@@ -0,0 +1,31 @@
//
// katrin.hpp
// mc_electron
//
// Created by Christian Reiling on 20.09.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#ifndef katrin_hpp
#define katrin_hpp
#include "parameter.hpp"
#include "particle.hpp"
class Katrin: public Parameter {
public:
Katrin(){};
virtual ~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);
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);
};
#endif /* katrin_hpp */
+3 -12
View File
@@ -6,21 +6,12 @@
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#include "simulation.h"
#include "tests.h"
#ifdef DEBUG
#define Debug( x ) cout << x << endl;
#else
#define Debug( x )
#endif
#include "simulation.hpp"
//#include "tests.hpp"
using namespace std;
int main(int argc, const char * argv[]) {
Debug("Debug Mode is on.")
//runTests();
clock_t start;
@@ -30,7 +21,7 @@ int main(int argc, const char * argv[]) {
Simulation Sim;
Sim.initLogger();
Sim.doit();
Sim.doTC6();
duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;
cout<<"Duration: "<< duration <<'\n';
+1 -1
View File
@@ -1 +1 @@
include $(HOMEBASE)/src/makeinclude/first.mak
include $(HOMEBASE)/src/makeinclude/first.mak
+8 -3
View File
@@ -1,6 +1,10 @@
include $(HOMEBASE)/src/makeinclude/include.mak
CXXFLAGS = $(X_OFLAGS) -I.. $(X_INC)
SRCS := $(wildcard ../*.cpp)
OBJS := $(patsubst %.cpp,%.o,$(SRCS))
CXXFLAGS = $(X_OFLAGS) -I.. $(X_INC)
LDFLAGS = $(X_LIB)
@@ -10,11 +14,12 @@ TARGETS = mcelectron
all: $(TARGETS)
mcelectron: main.o katrin.o simulation.o particle.o interaction.o tests.o constants.o
mcelectron: main.o functions.o constants.o katrin.o simulation.o \
particle.o electron.o elastic.o ionization.o
$(CXX) -o $@ $^ $(LDFLAGS) $(LOADLIBES)
%.o : %.cpp
$(CXX) -Wno-write-strings -c $< $(CXXFLAGS) -o $@
$(CXX) -c $< $(CXXFLAGS) -o $@
clean:
rm *.o mcelectron
-111
View File
@@ -1,111 +0,0 @@
//
// parameter.h
// mc_electron
//
// Created by Christian Reiling on 20.09.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#ifndef parameter_h
#define parameter_h
#include "constants.h"
class Parameter: protected Constants
{
public:
virtual ~Parameter(){};
Parameter() {
// Simulation Specs
seed = (int)value("seed");
numTotalParticles = (long int)value("numTotalParticles");
dt_s = value("dt_s");
injectionMethod = (int)value("injectionMethod");
deltaKinEnergy_eV = value("deltaKinEnergy_eV");
MBTemp_K = value("MBTemp_K");
// Katrin Specs
wgtsMagField_T = value("wgtsMagField_T");
wgtsLength_m = value("wgtsLength_m");
wgtsRadius_m = value("wgtsRadius_m");
wgtsT2Density_m3 = value("wgtsT2Density_m3");
wgtsTemp_K = value("wgtsTemp_K");
wgtsT2FlowSpeed_ms = value("wgtsT2FlowSpeed_ms");
// Output
numberZBins = value ("numberZBins");
}
private:
double value(string strin, char* ext = (char*)("cat")) {
char* str = strdup(strin.c_str());
double temp;
char dummy[256];
char fname[256],*pname;
FILE *fcat;
if (getenv("poub") == NULL)
{
cerr<<"Parameter::value: Environment variable poub not defined.\n";
exit(1);
}
strcpy(fname, getenv("poub"));
pname = getenv("pname");
if (pname == NULL)
{
cerr<<"Parameter::value: Environment variable pname not defined.\n";
exit(1);
}
if (!ext)
{
ext = (char*)("cat");
}
sprintf(fname,"%s/%s.%s",getenv("poub"),getenv("pname"), ext);
if (!(fcat = fopen(fname, "r")))
{
cerr<<"Parameter::value: Can not open file " <<fname<<".\n";
exit(1);
}
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);
cerr<<"Parameter::value: Variable "<<str<<" not found.\n";
exit(1);
return 0;
}
protected:
//Simulation Specs
int seed;
long int numTotalParticles;
double dt_s;
int injectionMethod;
double deltaKinEnergy_eV;
double MBTemp_K;
//KATRIN Specs
double wgtsMagField_T;
double wgtsLength_m;
double wgtsRadius_m;
double wgtsT2Density_m3;
double wgtsTemp_K;
double wgtsT2FlowSpeed_ms;
// Output
int numberZBins;
};
#endif
+129
View File
@@ -0,0 +1,129 @@
//
// parameter.hpp
// mc_electron
//
// Created by Christian Reiling on 20.09.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#ifndef parameter_hpp
#define parameter_hpp
#include "constants.hpp"
#include "functions.hpp"
class Parameter: protected Constants {
public:
virtual ~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;
long int numTotalElectrons;
double dt_s;
int injectionMethod; // 0 = Beta Decay, 1 = Delta, 2 = Maxwell Boltzmann
double deltaKinEnergy_eV;
double MBTemp_K;
int elaOn;
int ionOn;
int propagationMethod; // 0 = Drift Approximation, 1 = Borispush
// Cutoff
int cutoffMode; // 0 = Energy from Parameter, 1 = WGTSTemperature*cutoffFactor
double cutoffEnergySet_eV;
double cutoffFactor;
//KATRIN Specs
double wgtsMagField_T;
double wgtsLength_m;
double wgtsRadius_m;
double wgtsT2Density_m3;
double wgtsTemp_K;
double wgtsT2FlowSpeed_ms;
// Output
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;
}
};
#endif
-15
View File
@@ -1,15 +0,0 @@
seed = 2342395328
numTotalParticles = 1000
dt_s = 0.0000000001
injectionMethod = 1
deltaKinEnergy_eV = 1
MBTemp_K = 100
numberZBins = 51
wgtsMagField_T = 2.5
wgtsLength_m = 10
wgtsRadius_m = 0.045
wgtsT2Density_m3 = 5e21
wgtsTemp_K = 1.16e2
wgtsT2FlowSpeed_ms = 0
+9 -22
View File
@@ -7,7 +7,7 @@
//
#include "particle.h"
#include "particle.hpp"
// Overload <<
@@ -41,11 +41,11 @@ ostream& operator<<(ostream& os, const species& SpecOut) {
os<<"DT";
break;
default:
cerr<<"unknown species";
exit(1);
os<<"";
}
return (os);
}
ostream& operator<<(ostream& os, const Particle& partOut) {
os
<< partOut.Id << ";"
@@ -58,27 +58,20 @@ ostream& operator<<(ostream& os, const Particle& partOut) {
<< partOut.x_m[2] << ";"
<< partOut.v_ms[0] << ";"
<< partOut.v_ms[1] << ";"
<< partOut.v_ms[2] << ";";
<< partOut.v_ms[2] ;
return os;
}
// Default Constructor
Particle::Particle() {
x_m = zeroVec();
v_ms = zeroVec();
s = undef;
}
Particle::Particle(double mass_eV, double charge_e, blitz::TinyVector<double,3> speed_ms, species spec) {
m_eV = mass_eV;
mass_eV = mass_eV;
Z = charge_e;
x_m = zeroVec();
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) {
m_eV = mass_eV;
mass_eV = mass_eV;
Z = charge_e;
x_m = loc_m;
v_ms = speed_ms;
@@ -90,10 +83,10 @@ Particle::Particle(double mass_eV, double charge_e,blitz::TinyVector<double,3> l
double Particle::borisFly_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s) {
double distance_m;
x_m += dt_s/2 * v_ms;
distance_m = dt_s/2 * getvAbs_ms();
distance_m = dt_s/2 * getSpeedAbs_ms();
this->changeSpeedBoris(E_Vm , B_T , dt_s);
x_m += dt_s/2 * v_ms;
distance_m += dt_s/2 * getvAbs_ms();
distance_m += dt_s/2 * getSpeedAbs_ms();
return(distance_m);
}
@@ -109,9 +102,3 @@ void Particle::changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm , blitz::TinyV
vPlus_ms = vMinus_ms + cross(vPrime_ms,s);
v_ms = vPlus_ms + q_C/m_kg*E_Vm*0.5*dt_s;
}
void Particle::loseEkin_eV(double Eloss_eV) {
double eNew_eV = getKinEnergy_eV() - Eloss_eV;
double vAbsNew_ms = calcV_msFromEkin_eV(eNew_eV, m_eV);
v_ms = v_ms / getvAbs_ms() * vAbsNew_ms;
}
@@ -1,25 +1,22 @@
//
// particle.h
// particle.hpp
// mc_electron
//
// Created by Christian Reiling on 20.09.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#ifndef particle_h
#define particle_h
#ifndef particle_hpp
#define particle_hpp
#include "constants.h"
#include "parameter.hpp"
typedef enum species{undef, electron, positron, proton, tritium, tritium2, helium, deuterium, DT}species;
ostream& operator<<(ostream& os, const species& SpecOut);
class Particle: protected Constants {
class Particle: protected Parameter {
public:
virtual ~Particle() {}
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);
@@ -36,45 +33,31 @@ protected:
public:
// Get Properties Methods
double getMass_eV() { return(m_eV); }
double getCharge_e() { return(Z); }
double getCharge_e() { return(Z); }
blitz::TinyVector<double,3> getLoc_m() { return(x_m); }
blitz::TinyVector<double,3> getSpeed_ms() { return(v_ms); }
species getSpecies() {return(s); }
double getId() { return(Id); }
double getParentId() { return(parentId); }
// Calc Properties
// Get Properties
double getRadius_m() { return ( sqrt( pow(x_m[0],2) + pow(x_m[1],2) ) ); }
double getvAbs_ms() { return ( calcAbs(v_ms) ); }
double getKinEnergy_eV() { return ( (getGamma()-1) * m_eV); }
double getBeta() {return ( getvAbs_ms()/c_ms ); }
double getGamma() {return ( pow(1- pow(getBeta(),2),-0.5)); }
double getSpeedAbs_ms() { return ( calc_vecAbs(v_ms) ); }
double getKinEnergy_eV() { return ( calc_Ekin_eV_from_speed(getSpeedAbs_ms(), m_eV) ); }
// Set Properties Methods
void setLoc_m(blitz::TinyVector<double, 3> xnew_m) {x_m = xnew_m; };
void setSpeed_ms(blitz::TinyVector<double, 3> vnew_ms) {v_ms = vnew_ms; };
/*
Boris Push:
Propagate Flight for one timestep dt_s in E_Vm and B_T and returns distance.
*/
//Boris Push: Propagate Flight for one timestep dt_s in E_Vm and B_T and returns distance.
public:
double borisFly_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s);
protected:
void changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm,blitz::TinyVector<double, 3> B_T , double dt_s);
/*
Interactions
*/
public:
void loseEkin_eV(double Eloss_eV);
// Write Methods
public:
friend ostream& operator<<(ostream& os, const Particle& partOut);
};
#endif
#endif /* particle_hpp */
+156 -96
View File
@@ -6,117 +6,174 @@
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#include "simulation.h"
#include "simulation.hpp"
void Simulation::doit() {
double MFP_m;
blitz::TinyVector <double,3> loc_m;
Particle ScatT2;
Interaction IntereT2;
while ( (numInjectedParticles < numTotalParticles) || (particleQue.size() > 0) ) {
if (particleQue.empty()) {
particleQue.push_back(inject());
numInjectedParticles++;
if (numInjectedParticles%100 == 0){
cout<<numInjectedParticles<<"/"<<numTotalParticles<<endl;
}
while ( (numInjectedElectrons < numTotalElectrons) || (electronQue.size() > 0) ) {
if (electronQue.empty()) {
electronQue.push_back(injectElectron());
numInjectedElectrons++;
}
ScatT2 = Kat.getT2AverScatPart(particleQue.front().getLoc_m(), &rngUni);
IntereT2 = Interaction(&particleQue.front(),&ScatT2);
//Replace with vector containing all Interactions and adapt functions and put particle pointers into Particle class
MFP_m = getMFP_m(IntereT2);
moveParticleDriftApproximation(&particleQue.front(),MFP_m);
//moveParticleBorisPush(&particleQue.front(),MFP_m); // If moved outside set v = 0,0,0;
switch ( IntereT2.getInteraction(&rngUni) ) {
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
ScatT2 = Kat.getT2ScatPart(particleQue.front().getLoc_m(), &rngUni, &rngNormal);
IntereT2 = Interaction(&particleQue.front(),&ScatT2);
IntereT2.doElaScat(&rngUni);
electronQue.front().do_elaScattering(Kat.getTotSpeedT2_ms(loc_m, &rngUni, &rngNormal) , &rngUni);
break;
case 2: // Ionization
particleQue.push_back( IntereT2.doIon(numInjectedParticles, &rngUni) );
numInjectedParticles++;
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:
cerr<<"getprocess() returned unknown event"<<endl;
throw ("Simulation::doit(): getprocess() returned unknown event");
break;
}
if (checkTermination (particleQue.front())) {
particleQue.pop_front();
if (checkTermination (electronQue.front())) {
electronQue.pop_front();
}
}
};
// Injection
Particle Simulation::inject() {
blitz::TinyVector<double,3> loc_m, speed_ms;
double r_m,phi_rad,z_m;
double Ekin_eV;
r_m = wgtsRadius_m*sqrt(rngUni.random());
phi_rad = rngUni.random()*2*pi;
z_m = rngUni.random()*wgtsLength_m;
loc_m = r_m*cos(phi_rad),r_m*sin(phi_rad),z_m;
// Add Code taking in account tritium density
// Add Code for corregtion of direction by tritium direction und Boltzmann distribution
void Simulation::doTC6() {
cout<<endl<<"Simulation::doTC6: Doing Testcase 6."<<endl<<endl;
stringstream fileName;
fileName << getDirName() << "/TC6all.dat";
ofstream outTC6;
outTC6.open (fileName.str().c_str());
blitz::TinyVector <double,3> loc_m;
while ( (numInjectedElectrons < numTotalElectrons) || (electronQue.size() > 0) ) {
if (!electronQue.empty()) {
throw ("Simulation::doTC6: electronQue should be empty");
}
electronQue.push_back(injectElectron());
numInjectedElectrons++;
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::doTC6(): 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
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.pop_front();
break;
default:
throw ("Simulation::doit(): getprocess() returned unknown event");
break;
}
outTC6 << electronQue.front() <<endl;
electronQue.pop_front();
}
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 = getBetaDecayEnergyRejection_eV(); //Implement Later
Ekin_eV = getEkin_eVFermi_eV();
break;
case 1: //Delta
Ekin_eV = deltaKinEnergy_eV;
break;
case 2: //Maxwell Boltzman
Ekin_eV = getRandEnergyMaxwell(MBTemp_K,me_eV, &rngNormal);
Ekin_eV = roll_MB_Energy(MBTemp_K,me_eV, &rngNormal);
break;
default:
cerr<<"Invalid Injection Method./n";
exit(1);
throw ("Simulation::injectElectron: Invalid Injection Method.");
break;
}
speed_ms = getRandDir(&rngUni) * calcV_msFromEkin_eV(Ekin_eV,me_eV);
return (Particle(me_eV,qe_e,loc_m, speed_ms,numInjectedParticles,numInjectedParticles,electron));
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, Etridecay_eV ,1.5e-28, &rngUni));
return (doRejectionMethod(fptr , 1e-15, TritiumDecayEndpoint_eV ,1.5e-28, &rngUni));
}
*/
double Simulation::getBetaDecayEnergyRejection_eV() {
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 = Etridecay_eV;
Emax_eV = TritiumDecayEndpoint_eV;
do {
eta1 = rngUni.random();
eta2 = rngUni.random();
Ecan_eV = Emin_eV + eta1*(Emax_eV - Emin_eV);
} while(eta2*pmax > EnergyDistributionBetaDecay(Ecan_eV));
} while(eta2*pmax > ESpectrumBetaDecay(Ecan_eV));
return(Ecan_eV);
}
double Simulation::EnergyDistributionBetaDecay(double Ekin_eV) {
if (Ekin_eV>Etridecay_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( BetaDecayC * FermiFunction(ZHe3, Ekin_eV) * p_eV*(Ekin_eV+me_eV)*pow(Etridecay_eV-Ekin_eV,2) );
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) {
@@ -128,54 +185,58 @@ double Simulation::FermiFunction(double Z, double Ekin_eV) {
// Moving
void Simulation::moveParticleBorisPush(Particle *movePart, double MFP_m) {
blitz::TinyVector<double,3> oldLoc_m = movePart->getLoc_m();
blitz::TinyVector<double,3> E_Vm = Kat.getElField(oldLoc_m);
blitz::TinyVector<double,3> B_T = Kat.getMagField(oldLoc_m);
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 += movePart->borisFly_m(E_Vm , B_T , dt_s);
if (movedOutside(movePart->getLoc_m())) {
logParticle(movePart,oldLoc_m);
movePart->setSpeed_ms(zeroVec());
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;
}
}
logParticle(movePart,oldLoc_m);
logElectron(moveElectron,oldLoc_m);
return;
}
void Simulation::moveParticleDriftApproximation(Particle *movePart, double MFP_m) {
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 = movePart->getLoc_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 = movePart->getSpeed_ms()[2];
double vz_ms = moveElectron->getSpeed_ms()[2];
double vdir = vz_ms < 0 ? -1 : 1;
double vznew_m = z_m + vdir*MFP_m;
double znew_m = z_m + vdir*MFP_m;
if (vznew_m < 0) {
vznew_m = 0;
movePart->setSpeed_ms(zeroVec());
} else if (vznew_m > wgtsLength_m) {
vznew_m = wgtsLength_m;
movePart->setSpeed_ms(zeroVec());
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));
}
newLoc_m[2] = vznew_m;
movePart->setLoc_m(newLoc_m);
logParticle(movePart,oldLoc_m);
}
double Simulation::getMFP_m(Interaction Interaction) {
double Simulation::getMFP_m(Electron moveElectron) {
//Rework for inserting vector of Interactions
blitz::TinyVector<double,3> loc_m;
blitz::TinyVector<double,3> loc_m, speedT2_ms;
double sigmaTot_m2, density_m3, MFP_m;
loc_m = Interaction.getP1()->getLoc_m();
loc_m = moveElectron.getLoc_m();
speedT2_ms = Kat.getFlowSpeedT2_ms(loc_m);
sigmaTot_m2 = Interaction.getSigmaTot_m2();
density_m3 = Kat.getTritiumDensity(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);
}
@@ -186,16 +247,15 @@ bool Simulation::movedOutside(blitz::TinyVector<double,3> loc_m) {
// Termination
bool Simulation::checkTermination(Particle termPart) {
double EKin_eV, ETemp_eV;
EKin_eV = termPart.getKinEnergy_eV();
ETemp_eV = 3./2.*kb_eVK*wgtsTemp_K;
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) {
cerr<<"Simulation::checkTermination: ETemp_eV < 0." <<endl;
exit(1);
throw ("Simulation::checkTermination: ETemp_eV < 0.");
}
if (EKin_eV<=0.001) {
if (Ekin_eV<=cutoffEnergy_eV) {
return(true);
}
return(false);
@@ -227,8 +287,7 @@ void Simulation::initLogger(void) {
string dirname = getDirName();
if (numberZBins == -1) {
outStream = new ofstream [1
];
outStream = new ofstream [1];
stringstream fileName;
fileName << dirname << "/all" << ".dat";
outStream[0].open(fileName.str().c_str());
@@ -241,8 +300,8 @@ void Simulation::initLogger(void) {
outStream[i].open(fileName.str().c_str());
}
}
}
string Simulation::getDirName() {
string poub = getenv("poub");
string pname = getenv("pname");
@@ -261,8 +320,9 @@ string Simulation::getDirName() {
}
} while ( isDir == 1 );
if (mkdir(dirname.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
cerr<<"Simulation::initLogger: Could not create folder "<<dirname.str()<<" for Logging."<<endl;
exit(1);
stringstream ss;
ss<<"Simulation::initLogger: Could not create folder "<<dirname.str()<<" for Logging.";
throw (ss.str());
}
return(dirname.str());
}
@@ -277,22 +337,22 @@ string Simulation::getTimeString() {
string str(buffer);
return(str);
}
void Simulation::logParticle(Particle *logPart,blitz::TinyVector<double,3> oldLoc_m) {
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]<<*logPart<<endl;
outStream[0]<<*logElectron<<endl;
} else {
double zold = oldLoc_m[2];
double znew = logPart->getLoc_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]<<*logPart<<endl; // Location wrong, because it s the new Location.
outStream[i]<<*logElectron<<endl; // Location wrong, because it s the new Location.
}
}
}
-64
View File
@@ -1,64 +0,0 @@
//
// simulation.h
// mc_electron
//
// Created by Christian Reiling on 20.09.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#ifndef simulation_h
#define simulation_h
#include "parameter.h"
#include "katrin.h"
#include "particle.h"
#include "interaction.h"
class Simulation: public Parameter
{
public:
~Simulation(){};
Simulation() {
numInjectedParticles = 0;
rngUni.seed(seed);
logging = false;
};
void initLogger(void);
void doit(void);
protected:
// Simulation
Katrin Kat;
ranlib::Uniform<double> rngUni;
ranlib::NormalUnit<double> rngNormal;
int numInjectedParticles;
deque<Particle> particleQue;
// Injection
Particle inject();
double getBetaDecayEnergyRejection_eV();
double EnergyDistributionBetaDecay(double Ekin_eV);
double FermiFunction(double Z, double Ekin_eV);
// Moving
void moveParticleBorisPush(Particle *movePart, double MFP_m);
void moveParticleDriftApproximation(Particle *movePart, double MFP_m);
double getMFP_m(Interaction Interaction);
bool movedOutside(blitz::TinyVector<double,3> loc_m);
// Termination
bool checkTermination(Particle termPart);
// Logging
bool logging;
ofstream *outStream;
vector<double> zLogValues;
void logParticle(Particle *logPart,blitz::TinyVector<double,3> oldLoc_m);
string getDirName();
string getTimeString();
};
#endif
+75
View File
@@ -0,0 +1,75 @@
//
// simulation.hpp
// mc_electron
//
// Created by Christian Reiling on 20.09.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#ifndef simulation_hpp
#define simulation_hpp
#include "parameter.hpp"
#include "katrin.hpp"
#include "electron.hpp"
class Simulation: public Parameter {
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);
protected:
// Simulation
Katrin Kat;
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();
};
#endif /* simulation_hpp */
-124
View File
@@ -1,124 +0,0 @@
//
// tests.cpp
// mc_electron
//
// Created by Christian Reiling on 17.10.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#include "tests.h"
void runTests() {
string outputFilePath = "/Users/ChristianReiling/Documents/Masterarbeit/CodeTesting/Data/";
TestSimulation TEST;
TEST.injection (100000, outputFilePath + "injection.dat");
TEST.decaySpectrum(100000, outputFilePath + "decaySpectrum.dat");
TEST.rejectionBetaDecay(100000, outputFilePath + "rejectionBetaDecay.dat");
TEST.maxwellBoltzmann(100000, outputFilePath + "maxwellBoltzmann.dat");
TEST.SigmaTot_m2(10000, outputFilePath + "sigmaTot_m2.dat", -3, 9);
TEST.MFP_m(10000, outputFilePath + "MFP_m.dat", -3, 9);
}
void TestSimulation::injection (int numParticles, string outputFilePath) {
ofstream outFile;
outFile.open (outputFilePath.c_str());
for (int i = 0;i<numParticles;i++) {
outFile << inject() <<endl;
}
outFile.close();
}
void TestSimulation::decaySpectrum (int numPoints,string outputFilePath) {
ofstream outFile;
outFile.open (outputFilePath.c_str());
double x,y;
for (int i = 0;i<numPoints;i++) {
x = i * Etridecay_eV/(numPoints-1);
y = EnergyDistributionBetaDecay(x);
outFile << x <<";"<<y <<endl;
}
outFile.close();
}
void TestSimulation::rejectionBetaDecay(int numDecays, string outputFilePath) {
ofstream outFile;
outFile.open (outputFilePath.c_str());
for (int i = 0;i<numDecays;i++) {
outFile << getBetaDecayEnergyRejection_eV() <<endl;
}
outFile.close();
}
void TestSimulation::maxwellBoltzmann(int numDecays, string outputFilePath) {
ofstream outFile;
outFile.open (outputFilePath.c_str());
for (int i = 0;i<numDecays;i++) {
//outFile << getEnergyBoltzmann_eV() <<endl;
}
outFile.close();
}
void TestSimulation::SigmaTot_m2(int numPointsPerPower, string outputFilePath, int EminPower, int EmaxPower) {
if (EminPower >= EmaxPower) {
cerr<<"TestSimulation::getMFP_m: Power of lower energy bound \">=\" upper energy bound."<<endl;
exit(1);
}
ofstream outFile;
outFile.open (outputFilePath.c_str());
Particle P1 = Particle(me_eV, 1, zeroVec(), electron);
Particle P2 = Particle(mT2_eV, ZT2, zeroVec(), tritium2);
Interaction Inter = Interaction(&P1, &P2);
double distance = 1./double(numPointsPerPower);
int numPoints = (EmaxPower - EminPower) * numPointsPerPower;
double power;
double energy_eV, sigma_m2;
blitz::TinyVector<double,3> speed;
for (int i=0;i<=numPoints;i++) {
power = EminPower + i*distance;
energy_eV = pow(10,power);
speed = 0,0, calcV_msFromEkin_eV(energy_eV, me_eV);
P2.setSpeed_ms(speed);
sigma_m2 = Inter.getSigmaTot_m2();
outFile<<energy_eV<<";"<<sigma_m2<<endl;
}
outFile.close();
}
void TestSimulation::MFP_m(int numPointsPerPower, string outputFilePath, int EminPower, int EmaxPower) {
if (EminPower >= EmaxPower) {
cerr<<"TestSimulation::getMFP_m: Power of lower energy bound \">=\" upper energy bound."<<endl;
exit(1);
}
ofstream outFile;
outFile.open (outputFilePath.c_str());
Particle P1 = Particle(me_eV, 1, zeroVec(), electron);
Particle P2 = Particle(mT2_eV, ZT2, zeroVec(), tritium2);
Interaction Inter = Interaction(&P1, &P2);
double distance = 1./double(numPointsPerPower);
int numPoints = (EmaxPower - EminPower) * numPointsPerPower;
double power;
double energy_eV, MFP_m;
blitz::TinyVector<double,3> speed;
for (int i=0;i<=numPoints;i++) {
power = EminPower + i*distance;
energy_eV = pow(10,power);
speed = 0,0, calcV_msFromEkin_eV(energy_eV, me_eV);
P2.setSpeed_ms(speed);
MFP_m = getMFP_m(Inter);
outFile<<energy_eV<<";"<<MFP_m<<endl;
}
outFile.close();
}
-47
View File
@@ -1,47 +0,0 @@
//
// tests.h
// mc_electron
//
// Created by Christian Reiling on 17.10.18.
// Copyright © 2018 Christian Reiling. All rights reserved.
//
#ifndef tests_h
#define tests_h
#include <stdio.h>
#include "simulation.h"
void runTests();
class TestSimulation: public Simulation {
public:
~TestSimulation(){}
TestSimulation() : Simulation(){};
void injection (int numParticles, string outputFilePath);
void decaySpectrum (int numPoints, string outputFilePath);
void rejectionBetaDecay(int numDecays, string outputFilePath);
void maxwellBoltzmann(int numDecays, string outputFilePath);
void SigmaTot_m2(int numPointsPerPower, string outputFilePath, int EminPower, int EmaxPower);
void MFP_m(int numPointsPerPower, string outputFilePath, int EminPower, int EmaxPower);
};
/*
class TestParticle: public Particle {
public:
~TestParticle(){}
TestParticle() : Particle(){};
TestParticle(double mass_eV, double charge_e, blitz::TinyVector<double,3> speed_ms, species spec) : Particle(mass_eV, charge_e, speed_ms, spec){};
TestParticle(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(mass_eV, charge_e, loc_m, speed_ms, idnum, parentIdnum, spec) {};
};
*/
#endif