Bug fixes.
This commit is contained in:
@@ -38,3 +38,52 @@ const double Constants::ionN = 2.4;
|
|||||||
const double Constants::ionG5 = 0.33;
|
const double Constants::ionG5 = 0.33;
|
||||||
const double Constants::ionBeta = 0.6;
|
const double Constants::ionBeta = 0.6;
|
||||||
const double Constants::ionGamma = 10;
|
const double Constants::ionGamma = 10;
|
||||||
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|||||||
+22
-11
@@ -9,7 +9,18 @@
|
|||||||
#ifndef constants_h
|
#ifndef constants_h
|
||||||
#define constants_h
|
#define constants_h
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <deque>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include "blitz/array.h"
|
||||||
|
#include "blitz/tinyvec2.h"
|
||||||
|
#include <random/uniform.h>
|
||||||
|
#include <random/normal.h>
|
||||||
|
|
||||||
class Constants
|
class Constants
|
||||||
{
|
{
|
||||||
@@ -46,18 +57,18 @@ public:
|
|||||||
static const double ionBeta;
|
static const double ionBeta;
|
||||||
static const double ionGamma;
|
static const double ionGamma;
|
||||||
|
|
||||||
|
|
||||||
// Conversion Functions
|
// Conversion Functions
|
||||||
double calcV_ms(double Ekin_eV) {
|
double calcAbs(blitz::TinyVector<double,3> vec);
|
||||||
double gamma = 1. + Ekin_eV/me_eV;
|
double calcV_msFromEkin_eV(double Ekin_eV, double m_eV);
|
||||||
double beta = sqrt(1 - pow(gamma,-2));
|
double calcGammaFromEkin_eV(double Ekin_eV, double m_eV);
|
||||||
return(beta * c_ms);
|
double calcBetaFromGamma(double gamma);
|
||||||
}
|
double calcEkin_eVFromVAbs_ms(double vAbs_ms, double m_eV);
|
||||||
double calcEkin_eV(double speedAbs_ms) {
|
double calcBetaFromVAbs_ms(double vAbs_ms);
|
||||||
double beta = speedAbs_ms/c_ms;
|
double calcGammaFromBeta(double beta);
|
||||||
double gamma = pow(1 - pow(beta,2),-0.5);
|
|
||||||
return ( (gamma-1) * me_eV * pow(c_nat,2) );
|
// Help Functions
|
||||||
}
|
blitz::TinyVector<double,3> zeroVec();
|
||||||
|
blitz::TinyVector<double,3> getRandDir(ranlib::Uniform<double> *rngUni);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,149 @@
|
|||||||
|
//
|
||||||
|
// interaction.cpp
|
||||||
|
// mc_electron
|
||||||
|
//
|
||||||
|
// Created by Christian Reiling on 13.11.18.
|
||||||
|
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "interaction.h"
|
||||||
|
|
||||||
|
|
||||||
|
Interaction::Interaction(Particle *InitParticle, Particle *ScatParticle) {
|
||||||
|
// Check valid Interaction? e+ and T2
|
||||||
|
// Check Particle will interact... v1-v2 != 0
|
||||||
|
P1 = InitParticle;
|
||||||
|
P2 = ScatParticle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double Interaction::getSigmaTot_m2() {
|
||||||
|
{ return (getSigmaEla_m2()); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
double Interaction::getSigmaEla_m2() {
|
||||||
|
double numerator = pi*Z2()*(Z2()+1)*re_m*re_m * (1-pow(betaLab(),2));
|
||||||
|
double denominator = elaEta() * (elaEta()+1)*pow(betaLab(),4);
|
||||||
|
return(numerator/denominator);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Interaction::doElaScat (ranlib::Uniform<double> *rngUni) {
|
||||||
|
// Here theta and phi are COM - Angles.... prob not correct :( For m1 << m2 fine.
|
||||||
|
|
||||||
|
double theta = getRandomTheta(rngUni);
|
||||||
|
double phi = rngUni->random() * 2 * pi;
|
||||||
|
doKinElaScat(theta, phi);
|
||||||
|
}
|
||||||
|
|
||||||
|
double Interaction::elaEta() {
|
||||||
|
double etac = (EkinLab_eV() < 50e3)? 1.198 : 1.13+3.76*pow(Z2()/(137*betaLab()),2);
|
||||||
|
double elaTau = EkinLab_eV()/m1_eV();
|
||||||
|
return (etac * 1.7e-5 * pow(Z2(),2./3.) /(elaTau*(elaTau+2) ));
|
||||||
|
}
|
||||||
|
|
||||||
|
double Interaction::getRandomTheta( ranlib::Uniform<double> *rngUni) {
|
||||||
|
double const1 = 2*pi/getSigmaEla_m2()*Z2()*(Z2()+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 Interaction::doKinElaScat(double theta, double phi) {
|
||||||
|
// Following Landau Lifschitz I Chapter 4 Paragraph 17
|
||||||
|
blitz::TinyVector<double,3> n0, v1New_ms, v2New_ms;
|
||||||
|
n0 = getNewDir(theta,phi); //New direction in Lab Frame
|
||||||
|
v1New_ms = (m2_eV()*calcAbs(vLab_ms())*n0 + m1_eV()*vLab_ms())/(m1_eV()+m2_eV()) + v2_ms();
|
||||||
|
v2New_ms = (-1*m1_eV()*calcAbs(vLab_ms())*n0 + m1_eV()*vLab_ms())/(m1_eV()+m2_eV()) + v2_ms();
|
||||||
|
P1->setSpeed_ms(v1New_ms);
|
||||||
|
P2->setSpeed_ms(v2New_ms);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
blitz::TinyVector<double,3> Interaction::getNewDir(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(vLab_ms()[2]/calcAbs(vLab_ms()));
|
||||||
|
phi0 = atan2(vLab_ms()[1],vLab_ms()[0]);
|
||||||
|
|
||||||
|
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.
|
||||||
|
phi1 = -1;
|
||||||
|
phi1c[0] = acos( A11/sin(theta1));
|
||||||
|
phi1c[1] = 2*pi - phi1c[0];
|
||||||
|
phi1c[2] = asin (A21/sin(theta1));
|
||||||
|
phi1c[3] = pi - phi1c[2];
|
||||||
|
phi1c[2] = (phi1c[2] > 0) ? phi1c[2] : 2*pi + phi1c[2];
|
||||||
|
for (int i=0;i<3;i++) {
|
||||||
|
for (int j=i+1;j<4;j++) {
|
||||||
|
if (phi1c[i]-phi1c[j] < 0.0001) {
|
||||||
|
phi1 = phi1c[i];
|
||||||
|
goto endloops;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endloops:
|
||||||
|
if (phi1 == -1) {
|
||||||
|
std::cerr<<"Interaction::getNewDir: 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 Interaction::getSigmaIon_m2() {
|
||||||
|
double N, t, S_m2,F,g1;
|
||||||
|
N = 1;
|
||||||
|
t = getKinEnergy_eV()/EIonizationT2_eV;
|
||||||
|
S_m2 = 4*pi*N*pow(rBohr_m*ERydberg_eV/EIonizationT2_eV,2);
|
||||||
|
F = (ionA1*log(t) + ionA2 + ionA3/t)/t;
|
||||||
|
g1 = (1-pow(t,1-ionN))/(ionN-1) - pow(2/(t+1),ionN/2)*(1-pow(t,1-ionN/2))/(ionN-2);
|
||||||
|
return(S_m2*F*g1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Interaction::doIon(ranlib::Uniform<double> *rngUni) {
|
||||||
|
// Get Energy after Interaction
|
||||||
|
|
||||||
|
// Get Scattering Angle
|
||||||
|
|
||||||
|
// Do Elastic Scattering with a resting electron
|
||||||
|
// Energy Initial from First Part, Secondary Electron:
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double Interaction::dSigmaIondW_m2eV(double W) {
|
||||||
|
double N, w, t, S_m2,F,f1;
|
||||||
|
N = 1;
|
||||||
|
w = W/EIonizationT2_eV;
|
||||||
|
t = getKinEnergy_eV()/EIonizationT2_eV;
|
||||||
|
S_m2 = 4*pi*N*pow(rBohr_m*ERydberg_eV/EIonizationT2_eV,2);
|
||||||
|
F = (ionA1*log(t) + ionA2 + ionA3/t)/t;
|
||||||
|
f1 = pow(w+1,-ionN) + pow(t-w,-ionN)-pow((w+1)*(t-w),-ionN/2);
|
||||||
|
return(S_m2*F*f1/EIonizationT2_eV);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
//
|
||||||
|
// interaction.h
|
||||||
|
// mc_electron
|
||||||
|
//
|
||||||
|
// Created by Christian Reiling on 13.11.18.
|
||||||
|
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef interaction_h
|
||||||
|
#define interaction_h
|
||||||
|
|
||||||
|
#include "particle.h"
|
||||||
|
|
||||||
|
class Interaction : protected Constants {
|
||||||
|
public:
|
||||||
|
virtual ~Interaction() {};
|
||||||
|
Interaction() {};
|
||||||
|
Interaction(Particle *InitParticle, Particle *ScatParticle);
|
||||||
|
|
||||||
|
Particle *getP1(){return(P1);}
|
||||||
|
//Particle *getP2(){return(P2);}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Particle *P1;
|
||||||
|
Particle *P2;
|
||||||
|
blitz::TinyVector<double,3> v1_ms() {return(P1->getSpeed_ms()); }
|
||||||
|
blitz::TinyVector<double,3> v2_ms() {return(P2->getSpeed_ms()); }
|
||||||
|
blitz::TinyVector<double,3> vLab_ms() {return(v1_ms()-v2_ms()); }
|
||||||
|
|
||||||
|
double m1_eV() {return(P1->getMass_eV()); }
|
||||||
|
double m2_eV() {return(P2->getMass_eV()); }
|
||||||
|
double Z1() {return(P1->getCharge_e()); }
|
||||||
|
double Z2() {return(P2->getCharge_e()); }
|
||||||
|
|
||||||
|
double EkinLab_eV() {
|
||||||
|
return(calcEkin_eVFromVAbs_ms(calcAbs(vLab_ms()), m1_eV()));
|
||||||
|
}
|
||||||
|
double betaLab() {return(calcAbs(vLab_ms())/c_ms); }
|
||||||
|
|
||||||
|
public:
|
||||||
|
double getSigmaTot_m2() ;
|
||||||
|
|
||||||
|
// Elastic Scattering
|
||||||
|
public:
|
||||||
|
double getSigmaEla_m2();
|
||||||
|
void doElaScat (ranlib::Uniform<double> *rngUni);
|
||||||
|
protected:
|
||||||
|
double elaEta();
|
||||||
|
double getRandomTheta(ranlib::Uniform<double> *rngUni);
|
||||||
|
void doKinElaScat(double theta, double phi);
|
||||||
|
blitz::TinyVector<double,3> getNewDir(double theta,double phi);
|
||||||
|
|
||||||
|
// Ionization
|
||||||
|
/*
|
||||||
|
public:
|
||||||
|
double getSigmaIon_m2();
|
||||||
|
void doIon (ranlib::Uniform<double> *rngUni);
|
||||||
|
protected:
|
||||||
|
double dSigmaIondW_m2eV(double W);
|
||||||
|
protected:
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* interaction_h */
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
//
|
|
||||||
// interactions.cpp
|
|
||||||
// mc_electron
|
|
||||||
//
|
|
||||||
// Created by Christian Reiling on 22.10.18.
|
|
||||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "particle.h"
|
|
||||||
|
|
||||||
void Particle::elasticKinematicClassical(Particle *P2, double theta, double phi) {
|
|
||||||
// Following Landau Lifschitz I Chapter 4 Paragraph 17
|
|
||||||
blitz::TinyVector<double,3> n0, v_ms, v1I_ms, v2I_ms, v1O_ms, v2O_ms;
|
|
||||||
double m1_eV, m2_eV, vAbs_ms;
|
|
||||||
v1I_ms = getSpeed_ms();
|
|
||||||
v2I_ms = P2->getSpeed_ms();
|
|
||||||
m1_eV = getMass_eV();
|
|
||||||
m2_eV = P2->getMass_eV();
|
|
||||||
n0 = getNewDir(theta,phi,v1I_ms);
|
|
||||||
v_ms = v1I_ms-v2I_ms;
|
|
||||||
vAbs_ms = sqrt(dot(v_ms,v_ms));
|
|
||||||
v1O_ms = ( m2_eV*vAbs_ms*n0 + (m1_eV*v1I_ms+m2_eV*v2I_ms) )/(m1_eV+m2_eV);
|
|
||||||
v2O_ms = ( -1*m1_eV*vAbs_ms*n0 + (m1_eV*v1I_ms+m2_eV*v2I_ms) )/(m1_eV+m2_eV);
|
|
||||||
setSpeed_ms(v1O_ms);
|
|
||||||
P2->setSpeed_ms(v2O_ms);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
blitz::TinyVector<double,3> Particle::getNewDir(double theta,double phi,blitz::TinyVector<double,3> oldDir) {
|
|
||||||
// Change of direction following Plante and Cucinotta
|
|
||||||
double oldDirAbs, theta0, phi0, A3, A4, A5, A11, A21, theta1, phi1;
|
|
||||||
double phi1c [4];
|
|
||||||
oldDirAbs = sqrt( dot(oldDir,oldDir) );
|
|
||||||
theta0 = acos(oldDir[2]/oldDirAbs);
|
|
||||||
phi0 = atan2(oldDir[1],oldDir[0]);
|
|
||||||
|
|
||||||
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.
|
|
||||||
phi1 = -1;
|
|
||||||
phi1c[0] = acos( A11/sin(theta1));
|
|
||||||
phi1c[1] = 2*pi - phi1c[0];
|
|
||||||
phi1c[2] = asin (A21/sin(theta1));
|
|
||||||
phi1c[3] = pi - phi1c[2];
|
|
||||||
phi1c[2] = (phi1c[2] > 0) ? phi1c[2] : 2*pi + phi1c[2];
|
|
||||||
for (int i=0;i<3;i++) {
|
|
||||||
for (int j=i+1;j<4;j++) {
|
|
||||||
if (phi1c[i]-phi1c[j] < 0.0001) {
|
|
||||||
phi1 = phi1c[i];
|
|
||||||
goto endloops;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
endloops:
|
|
||||||
if (phi1 == -1) {
|
|
||||||
std::cerr<<"Particle::doElaScat: phi1 not found."<<std::endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
blitz::TinyVector<double,3> newDir;
|
|
||||||
newDir = sin(theta1)*cos(phi1) , sin(theta1)*sin(phi1) , cos(theta1);
|
|
||||||
return(newDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
double Particle::getSigmaEla_m2() {
|
|
||||||
double numerator = pi*ZT2*(ZT2+1)*re_m*re_m * (1-pow(beta(),2));
|
|
||||||
double denominator = elaEta() * (elaEta()+1)*pow(beta(),4);
|
|
||||||
return(numerator/denominator);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Particle::doElaScat (ranlib::Uniform<double> *rngUni) {
|
|
||||||
// Compute Scattering Angle
|
|
||||||
double theta = getRandomTheta(rngUni);
|
|
||||||
double phi = rngUni->random() * 2 * pi;
|
|
||||||
|
|
||||||
// Compute Interaction Partner
|
|
||||||
blitz::TinyVector<double,3> speed;
|
|
||||||
speed = 0,0,0;
|
|
||||||
Particle P2 = Particle(mT2_eV,speed);
|
|
||||||
elasticKinematicClassical(&P2, theta, phi);
|
|
||||||
}
|
|
||||||
|
|
||||||
double Particle::getRandomTheta(ranlib::Uniform<double> *rngUni) {
|
|
||||||
double const1 = 2*pi/getSigmaEla_m2()*ZT2*(ZT2+1)*re_m*re_m*(1- pow(beta(),2) )* pow(beta(),-4);
|
|
||||||
double theta = acos( pow( rngUni->random()/const1-pow(2*elaEta(),-1) , -1 ) +1+2*elaEta());
|
|
||||||
return(theta);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
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 Particle::getSigmaIon_m2() {
|
|
||||||
double N, t, S_m2,F,g1;
|
|
||||||
N = 1;
|
|
||||||
t = getKinEnergy_eV()/EIonizationT2_eV;
|
|
||||||
S_m2 = 4*pi*N*pow(rBohr_m*ERydberg_eV/EIonizationT2_eV,2);
|
|
||||||
F = (ionA1*log(t) + ionA2 + ionA3/t)/t;
|
|
||||||
g1 = (1-pow(t,1-ionN))/(ionN-1) - pow(2/(t+1),ionN/2)*(1-pow(t,1-ionN/2))/(ionN-2);
|
|
||||||
return(S_m2*F*g1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Particle::doIon(ranlib::Uniform<double> *rngUni) {
|
|
||||||
// Get Energy after Interaction
|
|
||||||
|
|
||||||
// Get Scattering Angle
|
|
||||||
|
|
||||||
// Do Elastic Scattering with a resting electron
|
|
||||||
// Energy Initial from First Part, Secondary Electron:
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -24,6 +24,33 @@ blitz::TinyVector<double,3> Katrin::getElField(blitz::TinyVector<double,3> loc_m
|
|||||||
}
|
}
|
||||||
|
|
||||||
double Katrin::getTritiumDensity(blitz::TinyVector<double,3> loc_m) {
|
double Katrin::getTritiumDensity(blitz::TinyVector<double,3> loc_m) {
|
||||||
return(wgtsTritiumDensity_m3);
|
return(wgtsT2Density_m3);
|
||||||
|
}
|
||||||
|
|
||||||
|
Particle Katrin::getT2AverScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
||||||
|
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);
|
||||||
|
ScatPart.setLoc_m(loc_m);
|
||||||
|
return (ScatPart);
|
||||||
|
}
|
||||||
|
|
||||||
|
Particle Katrin::getT2ScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
||||||
|
Particle ScatPart = getT2AverScatPart(loc_m, rngUni, rngNormal);
|
||||||
|
blitz::TinyVector<double,3> speed_ms, flowOffset_ms, tempOffset_ms;
|
||||||
|
// Get Linear Flow
|
||||||
|
flowOffset_ms = ScatPart.getSpeed_ms();
|
||||||
|
|
||||||
|
// Get Temperature Motion
|
||||||
|
double tempOffsetABS_ms = rngNormal->random()*sqrt(kb_eVK*wgtsTemp_K/mT2_eV)*c_ms;
|
||||||
|
tempOffset_ms = getRandDir(rngUni)*tempOffsetABS_ms;
|
||||||
|
|
||||||
|
speed_ms = flowOffset_ms + tempOffset_ms;
|
||||||
|
ScatPart.setSpeed_ms(speed_ms);
|
||||||
|
return (ScatPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,15 +9,8 @@
|
|||||||
#ifndef katrin_h
|
#ifndef katrin_h
|
||||||
#define katrin_h
|
#define katrin_h
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include "blitz/array.h"
|
|
||||||
#include "blitz/tinyvec2.h"
|
|
||||||
|
|
||||||
#include "parameter.h"
|
#include "parameter.h"
|
||||||
|
#include "particle.h"
|
||||||
|
|
||||||
class Katrin: public Parameter
|
class Katrin: public Parameter
|
||||||
{
|
{
|
||||||
@@ -25,10 +18,14 @@ public:
|
|||||||
Katrin(){};
|
Katrin(){};
|
||||||
virtual ~Katrin(){};
|
virtual ~Katrin(){};
|
||||||
|
|
||||||
|
|
||||||
blitz::TinyVector<double,3> getMagField(blitz::TinyVector<double,3> loc_m);
|
blitz::TinyVector<double,3> getMagField(blitz::TinyVector<double,3> loc_m);
|
||||||
blitz::TinyVector<double,3> getElField(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);
|
double getTritiumDensity(blitz::TinyVector<double,3> loc_m);
|
||||||
|
|
||||||
|
Particle getT2AverScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
||||||
|
Particle getT2ScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -19,8 +19,8 @@
|
|||||||
int main(int argc, const char * argv[]) {
|
int main(int argc, const char * argv[]) {
|
||||||
Debug("Debug Mode is on.")
|
Debug("Debug Mode is on.")
|
||||||
|
|
||||||
runTests();
|
//runTests();
|
||||||
/*
|
|
||||||
std::clock_t start;
|
std::clock_t start;
|
||||||
double duration;
|
double duration;
|
||||||
start = std::clock();
|
start = std::clock();
|
||||||
@@ -31,5 +31,5 @@ int main(int argc, const char * argv[]) {
|
|||||||
|
|
||||||
duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
|
duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
|
||||||
std::cout<<"Duration: "<< duration <<'\n';
|
std::cout<<"Duration: "<< duration <<'\n';
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ TARGETS = mcelectron
|
|||||||
|
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
|
|
||||||
mcelectron: main.o katrin.o simulation.o particle.o interactions.o tests.o
|
mcelectron: main.o katrin.o simulation.o particle.o interaction.o tests.o
|
||||||
$(CXX) -o $@ $^ $(LDFLAGS) $(LOADLIBES)
|
$(CXX) -o $@ $^ $(LDFLAGS) $(LOADLIBES)
|
||||||
|
|
||||||
%.o : %.cpp
|
%.o : %.cpp
|
||||||
|
|||||||
@@ -9,9 +9,6 @@
|
|||||||
#ifndef parameter_h
|
#ifndef parameter_h
|
||||||
#define parameter_h
|
#define parameter_h
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
|
||||||
class Parameter: protected Constants
|
class Parameter: protected Constants
|
||||||
@@ -32,7 +29,9 @@ public:
|
|||||||
wgtsMagField_T = value("wgtsMagField_T");
|
wgtsMagField_T = value("wgtsMagField_T");
|
||||||
wgtsLength_m = value("wgtsLength_m");
|
wgtsLength_m = value("wgtsLength_m");
|
||||||
wgtsRadius_m = value("wgtsRadius_m");
|
wgtsRadius_m = value("wgtsRadius_m");
|
||||||
wgtsTritiumDensity_m3 = value("wgtsTritiumDensity_m3");
|
wgtsT2Density_m3 = value("wgtsT2Density_m3");
|
||||||
|
wgtsTemp_K = value("wgtsTemp_K");
|
||||||
|
wgtsT2FlowSpeed_ms = value("wgtsT2FlowSpeed_ms");
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
numberZBins = value ("numberZBins");
|
numberZBins = value ("numberZBins");
|
||||||
@@ -99,7 +98,9 @@ protected:
|
|||||||
double wgtsMagField_T;
|
double wgtsMagField_T;
|
||||||
double wgtsLength_m;
|
double wgtsLength_m;
|
||||||
double wgtsRadius_m;
|
double wgtsRadius_m;
|
||||||
double wgtsTritiumDensity_m3;
|
double wgtsT2Density_m3;
|
||||||
|
double wgtsTemp_K;
|
||||||
|
double wgtsT2FlowSpeed_ms;
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
int numberZBins;
|
int numberZBins;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ std::ostream& operator<<(std::ostream& os, const Particle& partOut) {
|
|||||||
<<partOut.parentId << ";"
|
<<partOut.parentId << ";"
|
||||||
<<partOut.s << ";"
|
<<partOut.s << ";"
|
||||||
<<partOut.m_eV << ";"
|
<<partOut.m_eV << ";"
|
||||||
<< partOut.q_e << ";"
|
<< partOut.Z << ";"
|
||||||
<< partOut.x_m[0] << ";"
|
<< partOut.x_m[0] << ";"
|
||||||
<< partOut.x_m[1] << ";"
|
<< partOut.x_m[1] << ";"
|
||||||
<< partOut.x_m[2] << ";"
|
<< partOut.x_m[2] << ";"
|
||||||
@@ -62,53 +62,53 @@ std::ostream& operator<<(std::ostream& os, const Particle& partOut) {
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default Constructor
|
||||||
|
Particle::Particle() {
|
||||||
|
m_eV = NULL;
|
||||||
// Private Functions
|
Z = NULL;
|
||||||
double Particle::r_m() {
|
x_m = zeroVec();
|
||||||
return ( sqrt( pow(x_m[0],2) + pow(x_m[1],2) ) );
|
v_ms = zeroVec();
|
||||||
|
Id = NULL;
|
||||||
|
parentId = NULL;
|
||||||
|
s = undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Particle::vAbs_ms() {
|
Particle::Particle(double mass_eV, double charge_e, blitz::TinyVector<double,3> speed_ms) {
|
||||||
return ( sqrt( pow(v_ms[0],2) + pow(v_ms[1],2) + pow(v_ms[2],2)) );
|
m_eV = mass_eV;
|
||||||
|
Z = charge_e;
|
||||||
|
x_m = zeroVec();
|
||||||
|
v_ms = speed_ms;
|
||||||
|
Id = NULL;
|
||||||
|
parentId = NULL;
|
||||||
|
s = undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Particle::beta() {
|
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) {
|
||||||
return ( vAbs_ms()/c_ms );
|
m_eV = mass_eV;
|
||||||
|
Z = charge_e;
|
||||||
|
x_m = loc_m;
|
||||||
|
v_ms = speed_ms;
|
||||||
|
Id = idnum;
|
||||||
|
parentId = parentIdnum;
|
||||||
|
s = spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Particle::gamma() {
|
|
||||||
return ( pow(1- pow(beta(),2),-0.5));
|
|
||||||
}
|
|
||||||
|
|
||||||
double Particle::calcEkin_eV() {
|
|
||||||
return ( (gamma()-1) * m_eV);
|
|
||||||
}
|
|
||||||
|
|
||||||
double Particle::elaTau() {
|
|
||||||
return (calcEkin_eV()/me_eV) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
double Particle::elaEta() {
|
|
||||||
double etac = (calcEkin_eV() < 50e3)? 1.198 : 1.13+3.76*pow(ZT2/(137*beta()),2);
|
|
||||||
return (etac * 1.7e-5 * pow(ZT2,2./3.) /( elaTau()*(elaTau()+2) ));
|
|
||||||
}
|
|
||||||
|
|
||||||
double Particle::borisFly_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s) {
|
double Particle::borisFly_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s) {
|
||||||
double distance_m;
|
double distance_m;
|
||||||
x_m += dt_s/2 * v_ms;
|
x_m += dt_s/2 * v_ms;
|
||||||
distance_m = dt_s/2 * vAbs_ms();
|
distance_m = dt_s/2 * getvAbs_ms();
|
||||||
this->changeSpeedBoris(E_Vm , B_T , dt_s);
|
this->changeSpeedBoris(E_Vm , B_T , dt_s);
|
||||||
x_m += dt_s/2 * v_ms;
|
x_m += dt_s/2 * v_ms;
|
||||||
distance_m += dt_s/2 * vAbs_ms();
|
distance_m += dt_s/2 * getvAbs_ms();
|
||||||
return(distance_m);
|
return(distance_m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Particle::changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s) {
|
void Particle::changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s) {
|
||||||
{
|
{
|
||||||
blitz::TinyVector<double, 3> vMinus_ms, vPlus_ms, vPrime_ms, t, s;
|
blitz::TinyVector<double, 3> vMinus_ms, vPlus_ms, vPrime_ms, t, s;
|
||||||
double q_C = -1*q_e * e_C;
|
double q_C = -1*Z * e_C;
|
||||||
double m_kg = m_eV*e_C/c_ms/c_ms;
|
double m_kg = m_eV*e_C/c_ms/c_ms;
|
||||||
|
|
||||||
t = q_C*dt_s/(2*m_kg) * B_T;
|
t = q_C*dt_s/(2*m_kg) * B_T;
|
||||||
|
|||||||
+24
-74
@@ -6,17 +6,8 @@
|
|||||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef particle_hpp
|
#ifndef particle_h
|
||||||
#define particle_hpp
|
#define particle_h
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include "blitz/array.h"
|
|
||||||
#include "blitz/tinyvec2.h"
|
|
||||||
#include <random/uniform.h>
|
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
|
||||||
@@ -24,99 +15,58 @@ typedef enum species{undef, electron, positron, proton, tritium, tritium2, heliu
|
|||||||
std::ostream& operator<<(std::ostream& os, const species& SpecOut);
|
std::ostream& operator<<(std::ostream& os, const species& SpecOut);
|
||||||
|
|
||||||
|
|
||||||
class Particle: protected Constants
|
class Particle: protected Constants {
|
||||||
{
|
|
||||||
|
public:
|
||||||
|
virtual ~Particle() {}
|
||||||
|
Particle();
|
||||||
|
Particle(double mass_eV, double charge_e, blitz::TinyVector<double,3> speed_ms);
|
||||||
|
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);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double m_eV;
|
double m_eV;
|
||||||
double q_e;
|
double Z;
|
||||||
blitz::TinyVector<double,3> x_m;
|
blitz::TinyVector<double,3> x_m;
|
||||||
blitz::TinyVector<double,3> v_ms;
|
blitz::TinyVector<double,3> v_ms;
|
||||||
species s;
|
species s;
|
||||||
unsigned long int Id;
|
unsigned long int Id;
|
||||||
unsigned long int parentId;
|
unsigned long int parentId;
|
||||||
|
|
||||||
double r_m();
|
|
||||||
double vAbs_ms();
|
|
||||||
double beta();
|
|
||||||
double gamma();
|
|
||||||
double calcEkin_eV();
|
|
||||||
double elaTau();
|
|
||||||
double elaEta();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Particle() {}
|
|
||||||
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;
|
|
||||||
q_e = charge_e;
|
|
||||||
x_m = loc_m;
|
|
||||||
v_ms = speed_ms;
|
|
||||||
Id = idnum;
|
|
||||||
parentId = parentIdnum;
|
|
||||||
s = spec;
|
|
||||||
}
|
|
||||||
|
|
||||||
Particle(double mass_eV,blitz::TinyVector<double,3> speed_ms) { //Resting dummy for elastic scattering
|
|
||||||
blitz::TinyVector<double,3> zero;
|
|
||||||
zero = 0,0,0;
|
|
||||||
m_eV = mass_eV;
|
|
||||||
q_e = 0;
|
|
||||||
x_m = zero;
|
|
||||||
v_ms = speed_ms;
|
|
||||||
Id = 0;
|
|
||||||
parentId = 0;
|
|
||||||
s = undef;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Get Properties Methods
|
// Get Properties Methods
|
||||||
double getMass_eV() { return(m_eV); }
|
double getMass_eV() { return(m_eV); }
|
||||||
double getCharge_e() { return(q_e); }
|
double getCharge_e() { return(Z); }
|
||||||
blitz::TinyVector<double,3> getLoc_m() { return(x_m); }
|
blitz::TinyVector<double,3> getLoc_m() { return(x_m); }
|
||||||
blitz::TinyVector<double,3> getSpeed_ms() { return(v_ms); }
|
blitz::TinyVector<double,3> getSpeed_ms() { return(v_ms); }
|
||||||
double getId() { return(Id); }
|
double getId() { return(Id); }
|
||||||
double getParentId() { return(parentId); }
|
double getParentId() { return(parentId); }
|
||||||
double getRadius_m() { return ( r_m() ); }
|
|
||||||
double getSpeedAbs_ms() { return (vAbs_ms() ); }
|
// Calc Properties
|
||||||
double getKinEnergy_eV() { return (calcEkin_eV() ); }
|
|
||||||
|
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)); }
|
||||||
|
|
||||||
// Set Properties Methods
|
// Set Properties Methods
|
||||||
void setLoc_m(blitz::TinyVector<double, 3> xnew_m) {x_m = xnew_m; };
|
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; };
|
void setSpeed_ms(blitz::TinyVector<double, 3> vnew_ms) {v_ms = vnew_ms; };
|
||||||
|
|
||||||
// Boris Push
|
/*
|
||||||
|
Boris Push:
|
||||||
|
Propagate Flight for one timestep dt_s in E_Vm and B_T and returns distance.
|
||||||
|
*/
|
||||||
public:
|
public:
|
||||||
double borisFly_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s);
|
double borisFly_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s);
|
||||||
protected:
|
protected:
|
||||||
void changeLocFly(double dt_s);
|
void changeLocFly(double dt_s);
|
||||||
void changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s);
|
void changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s);
|
||||||
|
|
||||||
// Interactions
|
|
||||||
public:
|
|
||||||
double getSigmaTot_m2() { return (getSigmaEla_m2()+getSigmaIon_m2()); }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void elasticKinematicClassical(Particle *P2, double theta, double phi);
|
|
||||||
blitz::TinyVector<double,3> getNewDir(double theta,double phi,blitz::TinyVector<double,3> oldDir);
|
|
||||||
|
|
||||||
// Elastic Scattering
|
|
||||||
public:
|
|
||||||
double getSigmaEla_m2();
|
|
||||||
void doElaScat (ranlib::Uniform<double> *rngUni);
|
|
||||||
protected:
|
|
||||||
double getRandomTheta(ranlib::Uniform<double> *rngUni);
|
|
||||||
// Ionization
|
|
||||||
public:
|
|
||||||
double getSigmaIon_m2();
|
|
||||||
void doIon (ranlib::Uniform<double> *rngUni);
|
|
||||||
|
|
||||||
|
|
||||||
// Write Methods
|
// Write Methods
|
||||||
public:
|
public:
|
||||||
friend std::ostream& operator<<(std::ostream& os, const Particle& partOut);
|
friend std::ostream& operator<<(std::ostream& os, const Particle& partOut);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -10,8 +10,11 @@
|
|||||||
|
|
||||||
|
|
||||||
void Simulation::doit() {
|
void Simulation::doit() {
|
||||||
|
double MFP_m;
|
||||||
blitz::TinyVector <double,3> loc_m;
|
blitz::TinyVector <double,3> loc_m;
|
||||||
bool insideFlag;
|
|
||||||
|
Particle ScatT2;
|
||||||
|
Interaction IntereT2;
|
||||||
|
|
||||||
while ( (numInjectedParticles < numTotalParticles) || (particleQue.size() > 0) ) {
|
while ( (numInjectedParticles < numTotalParticles) || (particleQue.size() > 0) ) {
|
||||||
if (particleQue.empty()) {
|
if (particleQue.empty()) {
|
||||||
@@ -21,37 +24,41 @@ void Simulation::doit() {
|
|||||||
std::cout<<numInjectedParticles<<"/"<<numTotalParticles<<std::endl;
|
std::cout<<numInjectedParticles<<"/"<<numTotalParticles<<std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ScatT2 = Kat.getT2AverScatPart(particleQue.front().getLoc_m(), &rngUni, &rngNormal);
|
||||||
|
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);
|
||||||
|
moveParticle(&particleQue.front(),MFP_m); // If moved outside set v = 0,0,0;
|
||||||
|
|
||||||
insideFlag = move(&particleQue.front());
|
switch (getInteraction(particleQue.front())) {
|
||||||
if (insideFlag) {
|
case 0: //Moved Outside
|
||||||
switch (getInteraction(particleQue.front())) {
|
case 1: // Elastic Scattering
|
||||||
case 0: // Elastic Scattering
|
ScatT2 = Kat.getT2ScatPart(particleQue.front().getLoc_m(), &rngUni, &rngNormal);
|
||||||
particleQue.front().doElaScat(&rngUni);
|
IntereT2 = Interaction(&particleQue.front(),&ScatT2);
|
||||||
std::cout<<particleQue.front()<<particleQue.front().getKinEnergy_eV()<<std::endl;
|
IntereT2.doElaScat(&rngUni);
|
||||||
break;
|
break;
|
||||||
case 1: // Ionization
|
case 2: // Ionization
|
||||||
//particleQue.push_back();
|
//particleQue.push_back();
|
||||||
break;
|
break;
|
||||||
case 2: // Recombination
|
case 3: // Recombination
|
||||||
particleQue.pop_front();
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
std::cerr<<"getprocess() returned unknown event"<<std::endl;
|
||||||
std::cerr<<"getprocess() returned unknown event"<<std::endl;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
if (checkTermination (particleQue.front())) {
|
||||||
|
|
||||||
}else {
|
|
||||||
particleQue.pop_front();
|
particleQue.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Injection
|
||||||
Particle Simulation::inject() {
|
Particle Simulation::inject() {
|
||||||
blitz::TinyVector<double,3> loc_m, speed_ms;
|
blitz::TinyVector<double,3> loc_m, speed_ms;
|
||||||
double r_m,phi_rad,z_m;
|
double r_m,phi_rad,z_m;
|
||||||
blitz::TinyVector<double,3> speedDir;
|
blitz::TinyVector<double,3> speedDir;
|
||||||
double Ekin_eV,vAbs_ms,vTheta_rad,vPhi_rad;
|
double Ekin_eV;
|
||||||
|
|
||||||
r_m = wgtsRadius_m*sqrt(rngUni.random());
|
r_m = wgtsRadius_m*sqrt(rngUni.random());
|
||||||
phi_rad = rngUni.random()*2*pi;
|
phi_rad = rngUni.random()*2*pi;
|
||||||
@@ -76,13 +83,7 @@ Particle Simulation::inject() {
|
|||||||
exit(1);
|
exit(1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
speed_ms = getRandDir(&rngUni) * calcV_msFromEkin_eV(Ekin_eV,me_eV);
|
||||||
vPhi_rad = 2*pi*rngUni.random();
|
|
||||||
vTheta_rad = pi*rngUni.random();
|
|
||||||
vAbs_ms = calcV_ms(Ekin_eV);
|
|
||||||
speed_ms = sin(vTheta_rad)*cos(vPhi_rad) , sin(vTheta_rad)*sin(vPhi_rad) , cos(vTheta_rad);
|
|
||||||
speed_ms *= vAbs_ms;
|
|
||||||
|
|
||||||
return (Particle(me_eV,qe_e,loc_m, speed_ms,numInjectedParticles,numInjectedParticles,electron));
|
return (Particle(me_eV,qe_e,loc_m, speed_ms,numInjectedParticles,numInjectedParticles,electron));
|
||||||
}
|
}
|
||||||
double Simulation::getBetaDecayEnergyRejection_eV() {
|
double Simulation::getBetaDecayEnergyRejection_eV() {
|
||||||
@@ -98,7 +99,6 @@ double Simulation::getBetaDecayEnergyRejection_eV() {
|
|||||||
} while(eta2*pmax > EnergyDistributionBetaDecay(Ecan_eV));
|
} while(eta2*pmax > EnergyDistributionBetaDecay(Ecan_eV));
|
||||||
return(Ecan_eV);
|
return(Ecan_eV);
|
||||||
}
|
}
|
||||||
|
|
||||||
double Simulation::EnergyDistributionBetaDecay(double Ekin_eV) {
|
double Simulation::EnergyDistributionBetaDecay(double Ekin_eV) {
|
||||||
if (Ekin_eV>Etridecay_eV) {
|
if (Ekin_eV>Etridecay_eV) {
|
||||||
return (0.);
|
return (0.);
|
||||||
@@ -107,52 +107,82 @@ double Simulation::EnergyDistributionBetaDecay(double Ekin_eV) {
|
|||||||
return( BetaDecayC * FermiFunction(ZHe3, Ekin_eV) * p_eV*(Ekin_eV+me_eV)*pow(Etridecay_eV-Ekin_eV,2) );
|
return( BetaDecayC * FermiFunction(ZHe3, Ekin_eV) * p_eV*(Ekin_eV+me_eV)*pow(Etridecay_eV-Ekin_eV,2) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double Simulation::FermiFunction(double Z, double Ekin_eV) {
|
double Simulation::FermiFunction(double Z, double Ekin_eV) {
|
||||||
double gamma = 1+ Ekin_eV/me_eV;
|
double gamma = 1+ Ekin_eV/me_eV;
|
||||||
double beta = sqrt(1 - pow(gamma,-2));
|
double beta = sqrt(1 - pow(gamma,-2));
|
||||||
double eta =Z/beta/137.;
|
double eta =Z/beta/137.;
|
||||||
return( 2*pi*eta/(1-exp(-2*pi*eta)) );
|
return( 2*pi*eta/(1-exp(-2*pi*eta)) );
|
||||||
}
|
}
|
||||||
|
|
||||||
double Simulation::getEnergyBoltzmann_eV() {
|
double Simulation::getEnergyBoltzmann_eV() {
|
||||||
double N = rngNormal.random();
|
double N = rngNormal.random();
|
||||||
double beta = N*sqrt(kb_eVK*MBTemp_K/me_eV)*N;
|
double beta = N*sqrt(kb_eVK*MBTemp_K/me_eV);
|
||||||
double gamma = 1/sqrt(1-pow(beta,2));
|
double gamma = 1/sqrt(1-pow(beta,2));
|
||||||
return((gamma-1)*me_eV);
|
return((gamma-1)*me_eV);
|
||||||
}
|
}
|
||||||
bool Simulation::move(Particle *inputParticle) {
|
|
||||||
blitz::TinyVector<double,3> oldLoc_m = inputParticle->getLoc_m();
|
// Moving
|
||||||
double density_m3 = Kat.getTritiumDensity(oldLoc_m);
|
void Simulation::moveParticle(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> E_Vm = Kat.getElField(oldLoc_m);
|
||||||
blitz::TinyVector<double,3> B_T = Kat.getMagField(oldLoc_m);
|
blitz::TinyVector<double,3> B_T = Kat.getMagField(oldLoc_m);
|
||||||
|
|
||||||
double sigTot_m2 = inputParticle->getSigmaTot_m2();
|
|
||||||
double MFP_m = 1/(density_m3 * sigTot_m2);
|
|
||||||
|
|
||||||
double distance = 0.;
|
double distance = 0.;
|
||||||
while (distance < MFP_m) {
|
while (distance < MFP_m) {
|
||||||
distance += inputParticle->borisFly_m(E_Vm , B_T , dt_s);
|
distance += movePart->borisFly_m(E_Vm , B_T , dt_s);
|
||||||
if (movedOutside(inputParticle->getLoc_m())) {
|
if (movedOutside(movePart->getLoc_m())) {
|
||||||
logParticle(inputParticle,oldLoc_m);
|
logParticle(movePart,oldLoc_m);
|
||||||
return(false);
|
movePart->setSpeed_ms(zeroVec());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logParticle(inputParticle,oldLoc_m);
|
logParticle(movePart,oldLoc_m);
|
||||||
return(true);
|
return;
|
||||||
}
|
}
|
||||||
|
double Simulation::getMFP_m(Interaction Interaction) {
|
||||||
|
//Rework for inserting vector of Interactions
|
||||||
|
blitz::TinyVector<double,3> loc_m;
|
||||||
|
double sigmaTot_m2, density_m3, MFP_m;
|
||||||
|
loc_m = Interaction.getP1()->getLoc_m();
|
||||||
|
|
||||||
|
sigmaTot_m2 = Interaction.getSigmaTot_m2();
|
||||||
int Simulation::getInteraction(Particle inputParticle) {
|
density_m3 = Kat.getTritiumDensity(loc_m);
|
||||||
return(0);
|
MFP_m = 1/(density_m3 * sigmaTot_m2);
|
||||||
|
return(MFP_m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Simulation::movedOutside(blitz::TinyVector<double,3> loc_m) {
|
bool Simulation::movedOutside(blitz::TinyVector<double,3> loc_m) {
|
||||||
double r_m = sqrt( pow(loc_m(0),2) + pow(loc_m(1),2) );
|
double r_m = sqrt( pow(loc_m(0),2) + pow(loc_m(1),2) );
|
||||||
return ( ! (loc_m[2]>0 && loc_m[2]<wgtsLength_m && r_m<wgtsRadius_m ) );
|
return ( ! (loc_m[2]>0 && loc_m[2]<wgtsLength_m && r_m<wgtsRadius_m ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Interaction
|
||||||
|
int Simulation::getInteraction(Particle interPart) {
|
||||||
|
// Check Moved Outside
|
||||||
|
if (interPart.getKinEnergy_eV()==0) {
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Termination
|
||||||
|
bool Simulation::checkTermination(Particle termPart) {
|
||||||
|
double EKin_eV, ETemp_eV;
|
||||||
|
EKin_eV = termPart.getKinEnergy_eV();
|
||||||
|
ETemp_eV = 3./2.*kb_eVK*wgtsTemp_K;
|
||||||
|
if (ETemp_eV<0) {
|
||||||
|
std::cerr<<"Simulation::checkTermination: ETemp_eV < 0." <<std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EKin_eV<ETemp_eV) {
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logging
|
||||||
void Simulation::initLogger(void) {
|
void Simulation::initLogger(void) {
|
||||||
// Set zLogValues;
|
// Set zLogValues;
|
||||||
zLogValues.clear();
|
zLogValues.clear();
|
||||||
@@ -194,10 +224,9 @@ void Simulation::initLogger(void) {
|
|||||||
for (int i = 0; i < numberZBins; i++)
|
for (int i = 0; i < numberZBins; i++)
|
||||||
{
|
{
|
||||||
std::string fileName = dirname + "/z=" + std::to_string(zLogValues[i]) + ".dat";
|
std::string fileName = dirname + "/z=" + std::to_string(zLogValues[i]) + ".dat";
|
||||||
outStream.emplace_back(std::ofstream{fileName});
|
outStream.push_back(std::ofstream(fileName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Simulation::getTimeString() {
|
std::string Simulation::getTimeString() {
|
||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
struct tm * timeinfo;
|
struct tm * timeinfo;
|
||||||
@@ -208,21 +237,20 @@ std::string Simulation::getTimeString() {
|
|||||||
std::string str(buffer);
|
std::string str(buffer);
|
||||||
return(str);
|
return(str);
|
||||||
}
|
}
|
||||||
|
void Simulation::logParticle(Particle *logPart,blitz::TinyVector<double,3> oldLoc_m) {
|
||||||
void Simulation::logParticle(Particle *inputParticle,blitz::TinyVector<double,3> oldLoc_m) {
|
|
||||||
if (!logging) {
|
if (!logging) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Annahme: Ohne Interaction bliebt Bewegung in z-Richtung Konstant.
|
// Annahme: Ohne Interaction bliebt Bewegung in z-Richtung Konstant.
|
||||||
|
|
||||||
double zold = oldLoc_m[2];
|
double zold = oldLoc_m[2];
|
||||||
double znew = inputParticle->getLoc_m()[2];
|
double znew = logPart->getLoc_m()[2];
|
||||||
double zmin = std::min(zold,znew);
|
double zmin = std::min(zold,znew);
|
||||||
double zmax = std::max(zold,znew);
|
double zmax = std::max(zold,znew);
|
||||||
|
|
||||||
for (int i=0;i<numberZBins;i++) {
|
for (int i=0;i<numberZBins;i++) {
|
||||||
if (zLogValues[i]>=zmin && zLogValues[i]<=zmax) {
|
if (zLogValues[i]>=zmin && zLogValues[i]<=zmax) {
|
||||||
outStream[i]<<*inputParticle<<std::endl; // Location wrong, because it s the new Location.
|
outStream[i]<<*logPart<<std::endl; // Location wrong, because it s the new Location.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,23 +9,10 @@
|
|||||||
#ifndef simulation_h
|
#ifndef simulation_h
|
||||||
#define simulation_h
|
#define simulation_h
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <deque>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include "blitz/array.h"
|
|
||||||
#include "blitz/tinyvec2.h"
|
|
||||||
#include <random/uniform.h>
|
|
||||||
#include <random/normal.h>
|
|
||||||
|
|
||||||
#include "parameter.h"
|
#include "parameter.h"
|
||||||
#include "katrin.h"
|
#include "katrin.h"
|
||||||
#include "particle.h"
|
#include "particle.h"
|
||||||
|
#include "interaction.h"
|
||||||
|
|
||||||
|
|
||||||
class Simulation: public Parameter
|
class Simulation: public Parameter
|
||||||
@@ -49,23 +36,29 @@ protected:
|
|||||||
int numInjectedParticles;
|
int numInjectedParticles;
|
||||||
std::deque<Particle> particleQue;
|
std::deque<Particle> particleQue;
|
||||||
|
|
||||||
|
// Injection
|
||||||
Particle inject();
|
Particle inject();
|
||||||
double getBetaDecayEnergyRejection_eV();
|
double getBetaDecayEnergyRejection_eV();
|
||||||
double EnergyDistributionBetaDecay(double Ekin_eV);
|
double EnergyDistributionBetaDecay(double Ekin_eV);
|
||||||
double FermiFunction(double Z, double Ekin_eV);
|
double FermiFunction(double Z, double Ekin_eV);
|
||||||
double getEnergyBoltzmann_eV();
|
double getEnergyBoltzmann_eV();
|
||||||
|
|
||||||
bool move(Particle *inputParticle);
|
// Moving
|
||||||
|
void moveParticle(Particle *movePart, double MFP_m);
|
||||||
|
double getMFP_m(Interaction Interaction);
|
||||||
bool movedOutside(blitz::TinyVector<double,3> loc_m);
|
bool movedOutside(blitz::TinyVector<double,3> loc_m);
|
||||||
int getInteraction(Particle inPutParticle);
|
|
||||||
|
|
||||||
|
// Interaction
|
||||||
|
int getInteraction(Particle interPart);
|
||||||
|
|
||||||
|
// Termination
|
||||||
|
bool checkTermination(Particle termPart);
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
bool logging;
|
bool logging;
|
||||||
std::vector<std::ofstream> outStream;
|
std::vector<std::ofstream> outStream;
|
||||||
std::vector<double> zLogValues;
|
std::vector<double> zLogValues;
|
||||||
void logParticle(Particle *inputParticle,blitz::TinyVector<double,3> oldLoc_m);
|
void logParticle(Particle *logPart,blitz::TinyVector<double,3> oldLoc_m);
|
||||||
std::string getTimeString();
|
std::string getTimeString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,15 +14,8 @@ void runTests() {
|
|||||||
TEST.decaySpectrum(100000, outputFilePath + "decaySpectrum.dat");
|
TEST.decaySpectrum(100000, outputFilePath + "decaySpectrum.dat");
|
||||||
TEST.rejectionBetaDecay(100000, outputFilePath + "rejectionBetaDecay.dat");
|
TEST.rejectionBetaDecay(100000, outputFilePath + "rejectionBetaDecay.dat");
|
||||||
TEST.maxwellBoltzmann(100000, outputFilePath + "maxwellBoltzmann.dat");
|
TEST.maxwellBoltzmann(100000, outputFilePath + "maxwellBoltzmann.dat");
|
||||||
|
|
||||||
TestParticle TESTPART;
|
|
||||||
TESTPART.sigmaEla_m2 (0, 20e3, 100000, outputFilePath + "sigmaEla_m2.dat");
|
|
||||||
TESTPART.randomTheta (18.6e3, 100000, outputFilePath + "randomTheta.dat");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void TestSimulation::injection (int numParticles, std::string outputFilePath) {
|
void TestSimulation::injection (int numParticles, std::string outputFilePath) {
|
||||||
std::ofstream outFile;
|
std::ofstream outFile;
|
||||||
outFile.open (outputFilePath);
|
outFile.open (outputFilePath);
|
||||||
@@ -54,6 +47,7 @@ void TestSimulation::rejectionBetaDecay(int numDecays, std::string outputFilePat
|
|||||||
outFile.close();
|
outFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestSimulation::maxwellBoltzmann(int numDecays, std::string outputFilePath) {
|
void TestSimulation::maxwellBoltzmann(int numDecays, std::string outputFilePath) {
|
||||||
std::ofstream outFile;
|
std::ofstream outFile;
|
||||||
outFile.open (outputFilePath);
|
outFile.open (outputFilePath);
|
||||||
@@ -63,30 +57,3 @@ void TestSimulation::maxwellBoltzmann(int numDecays, std::string outputFilePath)
|
|||||||
outFile.close();
|
outFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestParticle::sigmaEla_m2 (double Emin_eV, double Emax_eV, int numpoints, std::string outputFilePath) {
|
|
||||||
double E_eV,Estep_eV;
|
|
||||||
Estep_eV = Emax_eV/(numpoints-1);
|
|
||||||
m_eV = me_eV;
|
|
||||||
std::ofstream outFile;
|
|
||||||
outFile.open (outputFilePath);
|
|
||||||
|
|
||||||
for (int i = 0;i<numpoints;i++) {
|
|
||||||
E_eV = i*Estep_eV;
|
|
||||||
v_ms = calcV_ms(E_eV) , 0 , 0;
|
|
||||||
outFile << E_eV<<";"<<getSigmaEla_m2() <<std::endl;
|
|
||||||
}
|
|
||||||
outFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestParticle::randomTheta (double E_eV, int numCalculations, std::string outputFilePath) {
|
|
||||||
std::ofstream outFile;
|
|
||||||
m_eV = me_eV;
|
|
||||||
v_ms = calcV_ms(E_eV) , 0 , 0;
|
|
||||||
ranlib::Uniform<double> rngUni;
|
|
||||||
rngUni.seed(2342395328);
|
|
||||||
outFile.open (outputFilePath);
|
|
||||||
for (int i = 0;i<numCalculations;i++) {
|
|
||||||
outFile << getRandomTheta(&rngUni) <<std::endl;
|
|
||||||
}
|
|
||||||
outFile.close();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -28,16 +28,5 @@ public:
|
|||||||
void maxwellBoltzmann(int numDecays, std::string outputFilePath);
|
void maxwellBoltzmann(int numDecays, std::string outputFilePath);
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestParticle: public Particle {
|
|
||||||
public:
|
|
||||||
~TestParticle(){}
|
|
||||||
TestParticle(){};
|
|
||||||
|
|
||||||
void sigmaEla_m2 (double Emin, double Emax, int numpoints, std::string outputFilePath);
|
|
||||||
void randomTheta (double E_eV, int numCalculations, std::string outputFilePath);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user