Added new test class, reworked some code

Started Implementing Ionization
This commit is contained in:
Christian
2018-11-07 12:11:24 +01:00
parent cf7ac857d2
commit 15851a540a
14 changed files with 559 additions and 222 deletions
+9 -68
View File
@@ -10,10 +10,12 @@
#include "particle.h"
// Overload <<
std::ostream& operator<<(std::ostream& os, const species& SpecOut) {
switch (SpecOut) {
case undef:
os<<"undef";
break;
case electron:
os<<"e-";
break;
@@ -80,22 +82,19 @@ double Particle::gamma() {
return ( pow(1- pow(beta(),2),-0.5));
}
double Particle::Ekin_eV() {
double Particle::calcEkin_eV() {
return ( (gamma()-1) * m_eV);
}
double Particle::tau() {
return (Ekin_eV()/me_eV) ;
double Particle::elaTau() {
return (calcEkin_eV()/me_eV) ;
}
double Particle::eta() {
double etac = (Ekin_eV() < 50e3)? 1.198 : 1.13+3.76*pow(ZT2/(137*beta()),2);
return (etac * 1.7e-5 * pow(ZT2,2./3.) /( tau()*(tau()+2) ));
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 distance_m;
x_m += dt_s/2 * v_ms;
@@ -120,61 +119,3 @@ void Particle::changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm , blitz::TinyV
v_ms = vPlus_ms + q_C/m_kg*E_Vm*0.5*dt_s;
}
}
double Particle::getSigmaTot() {
return(getSigmaEla());
}
double Particle::getSigmaEla() {
double nenner = pi*ZT2*(ZT2+1)*re_m*re_m * (1-pow(beta(),2));
double zaehler = eta() * (eta()+1)*pow(beta(),4);
return(nenner/zaehler);
}
void Particle::doElaScat(ranlib::Uniform<double> *rngUni) {
// Do Ela Scattering without Tritium Movement
double const1 = 2*pi/getSigmaEla()*ZT2*(ZT2+1)*re_m*re_m*(1- pow(beta(),2) )* pow(beta(),-4);
double theta = acos( pow( rngUni->random()/const1-pow(2*eta(),-1) , -1 ) +1+2*eta());
double phi = rngUni->random() * 2 * pi;
double vAbsNew_ms = sqrt( pow(vAbs_ms(),2)*(1-4*m_eV*mT2_eV*pow(m_eV+mT2_eV,-2)*cos(theta)*cos(theta)) );
// Change of direction following Plante and Cucinotta
double theta0 = acos(v_ms[2]/vAbs_ms());
double phi0 = atan2(v_ms[1],v_ms[0]);
double A3 = sin(theta)*cos(phi);
double A4 =A3*cos(theta0) + cos(theta)*sin(theta0);
double A5 = sin(theta)*sin(phi);
double A11 = A4*cos(phi0) - A5*sin(phi0);
double A21 = A4*sin(phi0) + A5*cos(phi0);
double theta1 = acos( cos(theta0)*cos(theta)-A3*sin(theta0) );
// Get right phi1, maybe more elegant way later.
double phi1c [4];
double 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> vnew_ms;
vnew_ms = sin(theta1)*cos(phi1) , sin(theta1)*sin(phi1) , cos(theta1) ;
vnew_ms = vAbsNew_ms * vnew_ms;
setSpeed_ms(vnew_ms);
}