Added constants.h: declaring global variables there and passign to parameters, particles. Included Elastic Scattering
This commit is contained in:
+57
-125
@@ -13,64 +13,34 @@ void Simulation::init() {
|
||||
}
|
||||
|
||||
void Simulation::doit() {
|
||||
double energy_eV,sigTot_m2, density_m3,MFP_m;
|
||||
blitz::TinyVector <double,3> oldLoc_m, newLoc_m;
|
||||
blitz::TinyVector <double,3> loc_m;
|
||||
bool insideFlag;
|
||||
|
||||
while (numInjectedParticles < numTotalParticles) {
|
||||
if (particleQueue.size() < 1) {
|
||||
particleQueue.assign(1,inject());
|
||||
while ( (numInjectedParticles < numTotalParticles) || (particleQue.size() > 0) ) {
|
||||
if (particleQue.size() < 1) {
|
||||
particleQue.push_back(inject());
|
||||
numInjectedParticles++;
|
||||
}
|
||||
|
||||
particleQueueIt = particleQueue.begin();
|
||||
while (particleQueueIt != particleQueue.end()) {
|
||||
step = 0;
|
||||
while (true) {
|
||||
energy_eV = particleQueueIt->getKinEnergy_eV();
|
||||
sigTot_m2 = sigmaTot_m2(energy_eV);
|
||||
density_m3 = Kat.getTritiumDensity(particleQueueIt->getLoc_m());
|
||||
MFP_m = 1/ ( density_m3 * sigTot_m2);
|
||||
oldLoc_m = particleQueueIt->getLoc_m();
|
||||
newLoc_m = move(*particleQueueIt ,MFP_m);
|
||||
if (movedOutside(newLoc_m)) {
|
||||
// Reflexion oder Absorbtion? Erstmal Reflexion
|
||||
newLoc_m = moveToLocOfDeath(*particleQueueIt);
|
||||
particleQueueIt->setLoc_m(newLoc_m);
|
||||
|
||||
writeToLogger(*particleQueueIt);
|
||||
goto particleDied;
|
||||
}
|
||||
|
||||
particleQueueIt->setLoc_m(newLoc_m);
|
||||
writeToLogger(*particleQueueIt);
|
||||
|
||||
|
||||
/*
|
||||
switch (getprocess()) {
|
||||
case "ElasticScattering":
|
||||
break;
|
||||
case "Ionization":
|
||||
break;
|
||||
case "Recombination";
|
||||
|
||||
partQueue.erase(partQueue.begin());
|
||||
continue;
|
||||
break;
|
||||
default:
|
||||
cerr<<"getprocess() returned unknown event"<<endl;
|
||||
break;
|
||||
}
|
||||
*/
|
||||
insideFlag = move(&particleQue.front());
|
||||
if (insideFlag) {
|
||||
switch (getInteraction(particleQue.front())) {
|
||||
case 0: // Elastic Scattering
|
||||
particleQue.front().doElaScat(&rngUni);
|
||||
break;
|
||||
case 1: // Ionization
|
||||
//particleQue.push_back();
|
||||
break;
|
||||
case 2: // Recombination
|
||||
particleQue.pop_front();
|
||||
break;
|
||||
default:
|
||||
std::cerr<<"getprocess() returned unknown event"<<std::endl;
|
||||
break;
|
||||
}
|
||||
particleDied:
|
||||
particleQueueIt++;
|
||||
|
||||
}else {
|
||||
particleQue.pop_front();
|
||||
}
|
||||
|
||||
writeToFile(&particleLogger);
|
||||
particleLogger.clear();
|
||||
|
||||
particleQueue = newParticles;
|
||||
newParticles.clear();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -93,15 +63,14 @@ Particle Simulation::inject() {
|
||||
// Add Code for corregtion of direction by tritium direction!!!
|
||||
|
||||
switch(injectionMethod) {
|
||||
case 1: // Fermi
|
||||
Ekin_eV = 1.; //Implement Later
|
||||
case 0: // Fermi
|
||||
Ekin_eV = 100.; //Implement Later
|
||||
break;
|
||||
|
||||
case 2: //Delta
|
||||
case 1: //Delta
|
||||
Ekin_eV = deltaKinEnergy_eV;
|
||||
break;
|
||||
case 3: //Maxwell Boltzman
|
||||
Ekin_eV = 1.; //Implement Later
|
||||
case 2: //Maxwell Boltzman
|
||||
Ekin_eV = 100.; //Implement Later
|
||||
break;
|
||||
default:
|
||||
std::cerr<<"Invalid Injection Method./n";
|
||||
@@ -112,59 +81,47 @@ Particle Simulation::inject() {
|
||||
absSpeed_ms = v_ms(Ekin_eV);
|
||||
speed_ms = absSpeed_ms * speedDir;
|
||||
|
||||
|
||||
return (Particle(me_eV,qe_e,loc_m, speed_ms,numInjectedParticles,NULL,electron));
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> Simulation::move(Particle inputParticle,double distance_m) {
|
||||
//Pseudocode, lineare bewegung
|
||||
blitz::TinyVector<double,3> oldLoc_m = inputParticle.getLoc_m();
|
||||
blitz::TinyVector<double,3> v_ms =inputParticle.getSpeed_ms();
|
||||
blitz::TinyVector<double,3> SpeedDir = pow(dot(v_ms,v_ms),-0.5)*v_ms;
|
||||
return( oldLoc_m + SpeedDir*distance_m);
|
||||
bool Simulation::move(Particle *inputParticle) {
|
||||
blitz::TinyVector<double,3> loc_m = inputParticle->getLoc_m();
|
||||
double density_m3 = Kat.getTritiumDensity(loc_m);
|
||||
blitz::TinyVector<double,3> E_Vm = Kat.getElField(loc_m);
|
||||
blitz::TinyVector<double,3> B_T = Kat.getMagField(loc_m);
|
||||
|
||||
double sigTot_m2 = inputParticle->getSigmaTot();
|
||||
double MFP_m = 1/(density_m3 * sigTot_m2);
|
||||
|
||||
double distance = 0.;
|
||||
while (distance < MFP_m) {
|
||||
distance += inputParticle->borisFly_m(E_Vm , B_T , dt_s);
|
||||
// Log Movment here!!!
|
||||
//std::cout<<*inputParticle<<std::endl;
|
||||
if (movedOutside(inputParticle->getLoc_m())) {
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Simulation::movedOutside(blitz::TinyVector<double,3> loc_m) {
|
||||
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 ) );
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> Simulation::moveToLocOfDeath(Particle inputParticle) {
|
||||
|
||||
// Führe methode 1 step für move ein, die einen einzelnen Schritt in move ausführt und benutze diese, bis an Rand
|
||||
double stepsize = inputParticle.getSpeedAbs_ms()*dt_s;
|
||||
blitz::TinyVector<double,3> loc_m = inputParticle.getLoc_m();
|
||||
blitz::TinyVector<double,2> rVec_m;
|
||||
double r_m;
|
||||
|
||||
// Include saftey calc for too small stepsize
|
||||
|
||||
int countfordebug = 0;
|
||||
while (!movedOutside(loc_m) ) {
|
||||
loc_m = move (inputParticle,stepsize);
|
||||
inputParticle.setLoc_m(loc_m);
|
||||
countfordebug++;
|
||||
}
|
||||
|
||||
if (loc_m(2) < 0) {
|
||||
loc_m(2) = 0;
|
||||
} else if (loc_m(2) > wgtsLength_m) {
|
||||
loc_m(2) = wgtsLength_m;
|
||||
}
|
||||
|
||||
r_m = sqrt(pow(loc_m(0),2)+pow(loc_m(1),2));
|
||||
if (r_m > wgtsRadius_m) {
|
||||
loc_m(0) = wgtsRadius_m/r_m * loc_m(0);
|
||||
loc_m(1) = wgtsRadius_m/r_m * (loc_m(1));
|
||||
}
|
||||
return (loc_m);
|
||||
int Simulation::getInteraction(Particle inputParticle) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
// Logging Methods
|
||||
void Simulation::writeToLogger(Particle inputParticle) {
|
||||
std::string textLine;
|
||||
|
||||
|
||||
|
||||
particleLogger.push_back(textLine);
|
||||
}
|
||||
@@ -180,35 +137,10 @@ void Simulation::writeToFile(std::vector<Particle> *particleLogger) {
|
||||
}
|
||||
outFile.close();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
// Cross Sections
|
||||
double Simulation::sigmaTot_m2(double Ekin_eV) {
|
||||
return(sigmaEla_m2(Ekin_eV));
|
||||
}
|
||||
|
||||
double Simulation::sigmaEla_m2(double Ekin_eV) {
|
||||
// From Plante and S Uehara et al 1998
|
||||
double Z, tau, beta, etac, eta, nenner, zaehler;
|
||||
Z = 1.;
|
||||
tau = Ekin_eV/me_eV;
|
||||
beta = v_ms(Ekin_eV)/c_ms;
|
||||
etac = (Ekin_eV < 50e3)? 1.198 : 1.13+3.76*pow(Z/(137*beta),2); //beta im nenner oder zähler?
|
||||
eta = etac * 1.7e-5 * pow(Z,2./3.) /( tau*(tau+2) );
|
||||
nenner = pi*Z*(Z+1)*re_m*re_m * (1-pow(beta,2));
|
||||
zaehler = eta * (eta+1)*pow(beta,4);
|
||||
return(nenner/zaehler);
|
||||
}
|
||||
|
||||
double Simulation::dSigmaEladOmega_m2 (double Ekin_eV, double Theta_rad, double Phi_rad) {
|
||||
// From Plante and S Uehara et al 1998
|
||||
double Z, tau, beta, etac, eta, nenner, zaehler;
|
||||
Z = 1.;
|
||||
tau = Ekin_eV/me_eV;
|
||||
beta = v_ms(Ekin_eV)/c_ms;
|
||||
etac = (Ekin_eV < 50e3)? 1.198 : 1.13+3.76*pow(Z/(137*beta),2); //beta im nenner oder zähler?
|
||||
eta = etac * 1.7e-5 * pow(Z,2./3.) /( tau*(tau+2) );
|
||||
nenner = Z*(Z+1)*re_m*re_m * (1-pow(beta,2));
|
||||
zaehler = pow(1.-cos(Theta_rad)+2*eta,2) * pow(beta,4);
|
||||
return(nenner/zaehler);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user