Working change, before making some adjustments in classes, structure.

This commit is contained in:
Christian
2019-01-15 09:49:36 +01:00
parent ae5546a3ed
commit 0534f00fbd
12 changed files with 451 additions and 168 deletions
+61 -14
View File
@@ -16,28 +16,20 @@ 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;
// Elastic Scattering
// Tritium
const double Constants::ZT2 = 2.;
const double Constants::mT2_eV = 5.61886404234e9;
// Ionization
const double Constants::rBohr_m = 0.52917721067e-10;
const double Constants::ERydberg_eV = 13.605693009;
const double Constants::EIonizationT2_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::ionG5 = 0.33;
const double Constants::ionBeta = 0.6;
const double Constants::ionGamma = 10;
// Conversation
@@ -88,6 +80,51 @@ blitz::TinyVector<double,3> Constants::getRandDir(ranlib::Uniform<double> *rngUn
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]);
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) {
@@ -103,4 +140,14 @@ double Constants::getRandEnergyMaxwell(double Temp_K,double mass_eV,ranlib::Norm
}
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);
}
+6 -16
View File
@@ -38,29 +38,18 @@ public:
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;
// Elastic Scattering
// Tritium
static const double ZT2;
static const double mT2_eV;
// Ionization
static const double rBohr_m;
static const double ERydberg_eV;
static const double EIonizationT2_eV;
static const double ionA1;
static const double ionA2;
static const double ionA3;
static const double ionN;
static const double ionG5;
static const double ionBeta;
static const double ionGamma;
// Conversion Functions
double calcAbs(blitz::TinyVector<double,3> vec);
double calcV_msFromEkin_eV(double Ekin_eV, double m_eV);
@@ -73,10 +62,11 @@ public:
// 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
+182 -74
View File
@@ -8,17 +8,64 @@
#include "interaction.h"
const double Interaction::ionET2_eV = 13.603;
const double Interaction::ionA1 = 0.74;
const double Interaction::ionA2 = 0.87;
const double Interaction::ionA3 = -0.6;
const double Interaction::ionN = 2.4;
const double Interaction::ionBeta = 0.6;
const double Interaction::ionGamma = 10;
const double Interaction::ionG5 = 0.33;
const double Interaction::iongb = 2.9;
Interaction::Interaction(Particle *InitParticle, Particle *ScatParticle) {
// Check valid Interaction? e+ and T2
// Check valid Interaction? e- and T2
// Check Particle will interact... v1-v2 != 0
P1 = InitParticle;
P2 = ScatParticle;
if (P1->getSpecies()!= electron || P2->getSpecies()!= tritium2) {
cerr<<"Interaction: Interaction not defined between "<<P1->getSpecies()<<" and "<< P2->getSpecies()<<"."<<endl;
exit(1);
}
}
//General
double Interaction::getSigmaTot_m2() {
{ return (getSigmaEla_m2()); }
vector<double> Sigmas = getSigmas_m2();
double sigmaTot_m2 = 0;
for (vector<double>::iterator SigmasIt = Sigmas.begin() ; SigmasIt != Sigmas.end(); SigmasIt++) {
sigmaTot_m2 += *SigmasIt;
}
return(sigmaTot_m2);
}
vector<double> Interaction::getSigmas_m2() {
vector<double> Sigmas;
Sigmas.push_back(getSigmaEla_m2());
Sigmas.push_back(getSigmaIon_m2());
return(Sigmas);
}
int Interaction::getInteraction(ranlib::Uniform<double> *rngUni) {
// Check Moved Outside
if (P1->getKinEnergy_eV()==0) {
return(0);
}
vector<double> Sigmas = getSigmas_m2();
double RandPoint = rngUni->random() * getSigmaTot_m2();
double Sum = 0;
for (int i=0; i<Sigmas.size();i++ ) {
Sum += Sigmas[i];
if (RandPoint<Sum) {
return(i+1);
}
}
cerr<<"Interaction::getInteraction: Error in finding Interaction."<<endl;
exit(1);
}
/*
@@ -27,6 +74,7 @@ double Interaction::getSigmaTot_m2() {
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);
@@ -35,9 +83,9 @@ double Interaction::getSigmaEla_m2() {
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 theta = ranElaTheta(rngUni);
double phi = rngUni->random() * 2 * pi;
doKinElaScat(theta, phi);
doElaKin(theta, phi);
}
double Interaction::elaEta() {
@@ -46,17 +94,17 @@ double Interaction::elaEta() {
return (etac * 1.7e-5 * pow(Z2(),2./3.) /(elaTau*(elaTau+2) ));
}
double Interaction::getRandomTheta( ranlib::Uniform<double> *rngUni) {
double Interaction::ranElaTheta(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) {
void Interaction::doElaKin(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
n0 = getNewDir(vLab_ms(), theta, phi);
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);
@@ -64,45 +112,6 @@ void Interaction::doKinElaScat(double theta, double phi) {
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) {
cerr<<"Interaction::getNewDir: phi1 not found."<<endl;
exit(1);
}
blitz::TinyVector<double,3> newDir;
newDir = sin(theta1)*cos(phi1) , sin(theta1)*sin(phi1) , cos(theta1);
return(newDir);
}
/*
Ionization:
@@ -110,39 +119,138 @@ endloops:
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);
double T = P1->getKinEnergy_eV();
double t = T/ionET2_eV;
double N = 2; //for tritium-molecule
if (T<ionET2_eV) {
return(0);
}
return(ionS_m2(N)*ionF(t)*iong1(t));
}
Particle Interaction::doIon(int newId, ranlib::Uniform<double> *rngUni) {
if (P1->getKinEnergy_eV() < ionET2_eV) {
cerr<<"Interaction::doIon: EKin_eV < EIonT2_eV."<<endl;
exit(1);
}
double Eorg_eV, E1_eV, E2_eV;
Eorg_eV = P1->getKinEnergy_eV();
double W = ranIonW(rngUni);
double theta = ranIonTheta(W, rngUni);
double phi = 2*pi*rngUni->random();
double vAbsnew_ms = calcV_msFromEkin_eV(W, P1->getMass_eV());
double vAbsLoss_ms = calcV_msFromEkin_eV(ionET2_eV, me_eV);
blitz::TinyVector<double,3> P1newDir, vP1new_ms, P2newDir, vP2new_ms ;
P1newDir = getNewDir(P1->getSpeed_ms(), theta, phi);
vP1new_ms = vAbsnew_ms*P1newDir;
vP2new_ms = P1->getSpeed_ms() - vP1new_ms;
cout<<calcEkin_eVFromVAbs_ms(calcAbs(vP2new_ms), me_eV)<<endl;
vP2new_ms = vP2new_ms - vP2new_ms/calcAbs(vP2new_ms)*vAbsLoss_ms;
P1->setSpeed_ms(vP1new_ms);
Particle eNew = Particle(me_eV, qe_e, P2->getLoc_m(), vP2new_ms, newId, P1->getId(), electron);
E1_eV = P1->getKinEnergy_eV();
E2_eV = eNew.getKinEnergy_eV();
cout<<"Ionization: Eorg_eV = "<<Eorg_eV<<", W = "<<W<<", E1_eV = "<<E1_eV<<", E2_eV = "<<E2_eV<<", Ediff_eV = "<<Eorg_eV-E2_eV-E1_eV<<"."<<endl;
// Change tritium to tritium+...
return(eNew);
}
double Interaction::ranIonW(ranlib::Uniform<double> *rngUni) {
double pmax,Emin_eV, Emax_eV, Ecan_eV,eta1,eta2;
double T = P1->getKinEnergy_eV();
//pmax = getSigmaIon_m2(); //
pmax = ionS_m2(2)*1.06*2;
Emin_eV = 0;
Emax_eV = T-ionET2_eV;
do {
eta1 = rngUni->random();
eta2 = rngUni->random();
Ecan_eV = Emin_eV + eta1*(Emax_eV - Emin_eV);
} while(eta2*pmax > getIondSigdW_m2eV(Ecan_eV));
return(Ecan_eV);
}
double Interaction::ranIonTheta(double W, ranlib::Uniform<double> *rngUni) {
double pmax,thetaMin, thetaMax, thetaCan,eta1,eta2;
pmax = getIondSigdW_m2eV(W);
thetaMin = 0;
thetaMax = pi;
do {
eta1 = rngUni->random();
eta2 = rngUni->random();
thetaCan = thetaMin + eta1*(thetaMax - thetaMin);
} while(eta2*pmax > getIondSigdWdTheta_m2eV(W,thetaCan));
return(thetaCan);
}
double Interaction::getIondSigdW_m2eV(double W) {
double T = P1->getKinEnergy_eV();
double t = T/ionET2_eV;
double w = W/ionET2_eV;
double N = 2;
return(ionS_m2(N)*ionF(t)*ionf1(w,t)/ionET2_eV);
}
double Interaction::getIondSigdWdTheta_m2eV(double W, double theta) {
double T = P1->getKinEnergy_eV();
double t = T/ionET2_eV;
double w = W/ionET2_eV;
double N = 2;
return( ionG1(t, w, theta, N)*( ionfbe(t,w,theta)+ionG4(t,w)*ionfb(theta) ) );
}
double Interaction::ionS_m2(double N) {
return (4*pi*N*pow(rBohr_m*ERyd_eV/ionET2_eV,2));
}
double Interaction::ionf1(double t, double w) {
return ( pow(w+1,-ionN) + pow(t-w,-ionN)-pow((w+1)*(t-w),-ionN/2) );
}
double Interaction::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 Interaction::ionF(double t) {
return ((ionA1*log(t) + ionA2 + ionA3/t)/t);
}
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::ionG1(double t, double w, double theta,double N) {
double numerator = ionS_m2(N)*ionF(t)*ionf1(t,w)/ionET2_eV;
double denominator = iongbe(t,w)+ionG4(t,w)*iongb;
return (numerator/denominator);
}
double Interaction::ionG2(double t, double w) {
return( pow(w+1/t,0.5) );
}
double Interaction::ionG3(double t, double w) {
return ( ionBeta*sqrt((1-pow(ionG2(t,w),2))/w) );
}
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);
double Interaction::ionG4(double t, double w) {
return ( ionGamma*pow(1-w/t,3)/t/(w+1) );
}
*/
double Interaction::ionfbe(double t, double w, double theta) {
double a = pow( (cos(theta)-ionG2(t,w))/ionG3(t,w) , 2 );
return ( 1/(1+ a) );
}
double Interaction::ionfb(double theta) {
double a = pow( (cos(theta)+1)/ionG5 , 2 );
return ( 1/(1+ a) );
}
double Interaction::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) );
}
+48 -11
View File
@@ -11,14 +11,29 @@
#include "particle.h"
// Interaction only implemented for electron on T2 background
class Interaction : protected Constants {
protected:
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;
public:
virtual ~Interaction() {};
Interaction() {};
Interaction(Particle *InitParticle, Particle *ScatParticle);
Particle *getP1(){return(P1);}
//Particle *getP2(){return(P2);}
Particle *getP2(){return(P2);}
protected:
Particle *P1;
@@ -37,8 +52,11 @@ protected:
}
double betaLab() {return(calcAbs(vLab_ms())/c_ms); }
// General
public:
double getSigmaTot_m2() ;
double getSigmaTot_m2();
vector<double> getSigmas_m2();
int getInteraction(ranlib::Uniform<double> *rngUni);
// Elastic Scattering
public:
@@ -46,21 +64,40 @@ public:
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);
double ranElaTheta(ranlib::Uniform<double> *rngUni);
void doElaKin(double theta, double phi);
// Ionization
/*
// sigma and dSigma/dW
public:
double getSigmaIon_m2();
void doIon (ranlib::Uniform<double> *rngUni);
double getSigmaIon_m2();
Particle doIon(int newId, ranlib::Uniform<double> *rngUni);
protected:
double dSigmaIondW_m2eV(double W);
double ranIonW(ranlib::Uniform<double> *rngUni);
double ranIonTheta(double W, ranlib::Uniform<double> *rngUni);
public:
double getIondSigdW_m2eV(double W);
protected:
double ionS_m2 (double N);
double ionf1(double t, double w);
double iong1(double t);
double ionF(double t);
// dSigma/dWdTheta
public:
double getIondSigdWdTheta_m2eV(double t, double theta);
protected:
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);
*/
};
+1 -1
View File
@@ -34,7 +34,7 @@ Particle Katrin::getT2AverScatPart(blitz::TinyVector<double,3> loc_m, ranlib::Un
double flow_ms = sign*wgtsT2FlowSpeed_ms;
speed_ms = 0,0,flow_ms;
Particle ScatPart;
ScatPart = Particle(mT2_eV, ZT2, speed_ms);
ScatPart = Particle(mT2_eV, ZT2, speed_ms, tritium2);
ScatPart.setLoc_m(loc_m);
return (ScatPart);
}
+4 -4
View File
@@ -22,17 +22,17 @@ int main(int argc, const char * argv[]) {
Debug("Debug Mode is on.")
//runTests();
/*
clock_t start;
double duration;
start = clock();
*/
Simulation Sim;
Sim.initLogger();
Sim.doit();
/*
duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;
cout<<"Duration: "<< duration <<'\n';
*/
}
+7 -8
View File
@@ -64,23 +64,17 @@ ostream& operator<<(ostream& os, const Particle& partOut) {
// Default Constructor
Particle::Particle() {
m_eV = NAN;
Z = NAN;
x_m = zeroVec();
v_ms = zeroVec();
Id = NAN;
parentId = NAN;
s = undef;
}
Particle::Particle(double mass_eV, double charge_e, blitz::TinyVector<double,3> speed_ms) {
Particle::Particle(double mass_eV, double charge_e, blitz::TinyVector<double,3> speed_ms, species spec) {
m_eV = mass_eV;
Z = charge_e;
x_m = zeroVec();
v_ms = speed_ms;
Id = NAN;
parentId = NAN;
s = undef;
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) {
@@ -118,3 +112,8 @@ void Particle::changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm , blitz::TinyV
}
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;
}
+10 -1
View File
@@ -20,7 +20,7 @@ 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> 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);
protected:
@@ -39,6 +39,7 @@ public:
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); }
@@ -63,6 +64,14 @@ public:
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);
+51 -34
View File
@@ -29,9 +29,10 @@ void Simulation::doit() {
//Replace with vector containing all Interactions and adapt functions and put particle pointers into Particle class
MFP_m = getMFP_m(IntereT2);
moveParticleBorisPush(&particleQue.front(),MFP_m); // If moved outside set v = 0,0,0;
moveParticleDriftApproximation(&particleQue.front(),MFP_m);
//moveParticleBorisPush(&particleQue.front(),MFP_m); // If moved outside set v = 0,0,0;
switch (getInteraction(particleQue.front())) {
switch ( IntereT2.getInteraction(&rngUni) ) {
case 0: //Moved Outside
break;
case 1: // Elastic Scattering
@@ -40,7 +41,10 @@ void Simulation::doit() {
IntereT2.doElaScat(&rngUni);
break;
case 2: // Ionization
//particleQue.push_back();
particleQue.push_back( IntereT2.doIon(numInjectedParticles, &rngUni) );
numInjectedParticles++;
// Update Ions...
break;
case 3: // Recombination
break;
@@ -58,9 +62,7 @@ void Simulation::doit() {
Particle Simulation::inject() {
blitz::TinyVector<double,3> loc_m, speed_ms;
double r_m,phi_rad,z_m;
blitz::TinyVector<double,3> speedDir;
double Ekin_eV;
r_m = wgtsRadius_m*sqrt(rngUni.random());
phi_rad = rngUni.random()*2*pi;
z_m = rngUni.random()*wgtsLength_m;
@@ -87,19 +89,28 @@ Particle Simulation::inject() {
speed_ms = getRandDir(&rngUni) * calcV_msFromEkin_eV(Ekin_eV,me_eV);
return (Particle(me_eV,qe_e,loc_m, speed_ms,numInjectedParticles,numInjectedParticles,electron));
}
/*
double Simulation::getBetaDecayEnergyRejection_eV() {
double (Simulation::*fptr) (double) = &Simulation::EnergyDistributionBetaDecay;
return (doRejectionMethod(fptr , 1e-15, Etridecay_eV ,1.5e-28, &rngUni));
}
*/
double Simulation::getBetaDecayEnergyRejection_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;
do {
pmax = 1.5e-28; // From Plotting EnergyDistributionBetaDecay
Emin_eV = 1e-15;
Emax_eV = Etridecay_eV;
eta1 = rngUni.random();
eta2 = rngUni.random();
Ecan_eV = Emin_eV + eta1*(Emax_eV - Emin_eV);
} while(eta2*pmax > EnergyDistributionBetaDecay(Ecan_eV));
return(Ecan_eV);
}
double Simulation::EnergyDistributionBetaDecay(double Ekin_eV) {
if (Ekin_eV>Etridecay_eV) {
return (0.);
@@ -173,14 +184,6 @@ bool Simulation::movedOutside(blitz::TinyVector<double,3> loc_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) {
@@ -192,7 +195,7 @@ bool Simulation::checkTermination(Particle termPart) {
exit(1);
}
if (EKin_eV<=0.00001) {
if (EKin_eV<=0.001) {
return(true);
}
return(false);
@@ -204,10 +207,12 @@ void Simulation::initLogger(void) {
// Set zLogValues;
zLogValues.clear();
logging = true;
if (numberZBins < 1) {
if (numberZBins == 0) {
cout<<"Logging turned off."<<endl;
logging = false;
return;
} else if (numberZBins == -1) {
cout<<"Logging everything to one file."<<endl;
} else if (numberZBins == 1) {
cout<<"Logging 1 z-Value: "<<wgtsLength_m<<endl;
zLogValues.push_back(wgtsLength_m);
@@ -218,15 +223,25 @@ void Simulation::initLogger(void) {
cout<<"Logging "<<numberZBins<<" z-Values."<<endl;
}
string dirname = getDirName();
outStream = new ofstream [numberZBins];
for (int i = 0; i < numberZBins; i++)
{
if (numberZBins == -1) {
outStream = new ofstream [1
];
stringstream fileName;
fileName << dirname << "/z=" << zLogValues[i] << ".dat";
outStream[i].open(fileName.str().c_str());
fileName << dirname << "/all" << ".dat";
outStream[0].open(fileName.str().c_str());
} else {
outStream = new ofstream [numberZBins];
for (int i = 0; i < numberZBins; i++)
{
stringstream fileName;
fileName << dirname << "/z=" << zLogValues[i] << ".dat";
outStream[i].open(fileName.str().c_str());
}
}
}
string Simulation::getDirName() {
string poub = getenv("poub");
@@ -236,7 +251,7 @@ string Simulation::getDirName() {
struct stat statbuf;
int isDir;
do {
dirname.clear();
dirname.str(std::string());
dirname << poub << "/" << pname << "_" << getTimeString() << "_" << i++;
isDir = 0;
if (stat(dirname.str().c_str(), &statbuf) != -1) {
@@ -245,7 +260,6 @@ 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);
@@ -268,15 +282,18 @@ void Simulation::logParticle(Particle *logPart,blitz::TinyVector<double,3> oldLo
return;
}
// Annahme: Ohne Interaction bliebt Bewegung in z-Richtung Konstant.
double zold = oldLoc_m[2];
double znew = logPart->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.
if (numberZBins == -1) {
outStream[0]<<*logPart<<endl;
} else {
double zold = oldLoc_m[2];
double znew = logPart->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.
}
}
}
}
+1 -5
View File
@@ -48,16 +48,12 @@ protected:
double getMFP_m(Interaction Interaction);
bool movedOutside(blitz::TinyVector<double,3> loc_m);
// Interaction
int getInteraction(Particle interPart);
// Termination
bool checkTermination(Particle termPart);
// Logging
bool logging;
//vector<ofstream> outStream;
//ofstream outStream[];
ofstream *outStream;
vector<double> zLogValues;
void logParticle(Particle *logPart,blitz::TinyVector<double,3> oldLoc_m);
+65
View File
@@ -14,6 +14,9 @@ void runTests() {
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) {
@@ -57,3 +60,65 @@ void TestSimulation::maxwellBoltzmann(int numDecays, string outputFilePath) {
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();
}
+15
View File
@@ -26,7 +26,22 @@ public:
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