Added constants.h: declaring global variables there and passign to parameters, particles. Included Elastic Scattering

This commit is contained in:
Christian
2018-10-11 10:00:30 +02:00
parent 31049551a9
commit ab2bc174af
8 changed files with 286 additions and 278 deletions
+122 -1
View File
@@ -9,6 +9,9 @@
#include "particle.h"
// Overload <<
std::ostream& operator<<(std::ostream& os, const species& SpecOut) {
switch (SpecOut) {
case electron:
@@ -41,7 +44,6 @@ std::ostream& operator<<(std::ostream& os, const species& SpecOut) {
}
return (os);
}
std::ostream& operator<<(std::ostream& os, const Particle& partOut) {
os
<< partOut.Id << ";"
@@ -57,3 +59,122 @@ std::ostream& operator<<(std::ostream& os, const Particle& partOut) {
<< partOut.v_ms[2] << ";";
return os;
}
// Private Functions
double Particle::r_m() {
return ( sqrt( pow(x_m[0],2) + pow(x_m[1],2) ) );
}
double Particle::vAbs_ms() {
return ( sqrt( pow(v_ms[0],2) + pow(v_ms[1],2) + pow(v_ms[2],2)) );
}
double Particle::beta() {
return ( vAbs_ms()/c_ms );
}
double Particle::gamma() {
return ( pow(1- pow(beta(),2),-0.5));
}
double Particle::Ekin_eV() {
return ( (gamma()-1) * m_eV);
}
double Particle::tau() {
return (Ekin_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::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 * vAbs_ms();
this->changeSpeedBoris(E_Vm , B_T , dt_s);
x_m += dt_s/2 * v_ms;
distance_m += dt_s/2 * vAbs_ms();
return(distance_m);
}
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;
double q_C = -1*q_e * e_C;
double m_kg = m_eV*e_C/c_ms/c_ms;
t = q_C*dt_s/(2*m_kg) * B_T;
s = (2*t)/(1+dot(t,t));
vMinus_ms = v_ms + (q_C*E_Vm*dt_s)/(2*m_kg);
vPrime_ms = vMinus_ms + cross(vMinus_ms,t);
vPlus_ms = vMinus_ms + cross(vPrime_ms,s);
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);
}