Aktuelle Stand
This commit is contained in:
+157
-94
@@ -7,76 +7,85 @@
|
||||
//
|
||||
|
||||
#include "simulation.h"
|
||||
|
||||
//
|
||||
void Simulation::init() {
|
||||
|
||||
}
|
||||
|
||||
void Simulation::doit() {
|
||||
double MFP;
|
||||
blitz::TinyVector <double,3> oldLoc, newLoc;
|
||||
// Iterator nicht mit push_back möglich
|
||||
// Laufe vorderstes Teilchen bis zum Tod durch, entferne es dann aus der Liste
|
||||
double energy_eV,sigTot_m2, density_m3,MFP_m;
|
||||
blitz::TinyVector <double,3> oldLoc_m, newLoc_m;
|
||||
|
||||
while (numInjectedParticles < numTotalParticles) {
|
||||
inject();
|
||||
|
||||
while (particleQueue.size()>0) {
|
||||
// Run Code for first particle in Queue
|
||||
|
||||
MFP = calcMFP();
|
||||
oldLoc = particleQueue[0].getLoc();
|
||||
|
||||
std::cout << "Before move: " <<particleQueue[0]<<std::endl;
|
||||
|
||||
move (MFP,0);
|
||||
|
||||
|
||||
std::cout << "After move: " <<particleQueue[0]<<std::endl;
|
||||
|
||||
|
||||
if (movedOutside(0)) {
|
||||
moveToLocOfDeath(oldLoc,0);
|
||||
// updateDensity(oldLoc, partQueue[0].getEnergy());
|
||||
std::cout << "Death position: " <<particleQueue[0]<<std::endl;
|
||||
particleQueue.erase(particleQueue.begin());
|
||||
continue;
|
||||
} else {
|
||||
//newLoc = partQueue[0];
|
||||
//updateDensity(oldLoc,newLoc,partQueue[0].getEnergy());
|
||||
}
|
||||
/*
|
||||
switch (getprocess()) {
|
||||
case "ElasticScattering":
|
||||
break;
|
||||
case "Ionization":
|
||||
break;
|
||||
case "Recombination";
|
||||
|
||||
partQueue.erase(partQueue.begin());
|
||||
continue
|
||||
break;
|
||||
default:
|
||||
cerr<<"getprocess() returned unknown event"<<endl;
|
||||
break;
|
||||
}
|
||||
*/
|
||||
//particleQueue.erase(particleQueue.begin());
|
||||
if (particleQueue.size() < 1) {
|
||||
particleQueue.assign(1,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;
|
||||
}
|
||||
*/
|
||||
}
|
||||
particleDied:
|
||||
particleQueueIt++;
|
||||
}
|
||||
|
||||
writeToFile(&particleLogger);
|
||||
particleLogger.clear();
|
||||
|
||||
particleQueue = newParticles;
|
||||
newParticles.clear();
|
||||
}
|
||||
};
|
||||
|
||||
void Simulation::inject() {
|
||||
blitz::TinyVector<double,3> loc, speed;
|
||||
double r,phi,z;
|
||||
|
||||
// Simulation Methods
|
||||
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,absSpeed;
|
||||
double Ekin_eV,absSpeed_ms;
|
||||
|
||||
r = rngUni.random()*wgtsDiameter;
|
||||
phi = rngUni.random()*2*constPi;
|
||||
z = rngUni.random()*wgtsLength;
|
||||
loc = r*cos(phi),r*sin(phi),z;
|
||||
r_m = rngUni.random()*wgtsRadius_m;
|
||||
phi_rad = rngUni.random()*2*pi;
|
||||
z_m = rngUni.random()*wgtsLength_m;
|
||||
loc_m = r_m*cos(phi_rad),r_m*sin(phi_rad),z_m;
|
||||
// Add Code taking in account tritium density
|
||||
|
||||
speedDir = rngUni.random(),rngUni.random(),rngUni.random();
|
||||
@@ -85,67 +94,121 @@ void Simulation::inject() {
|
||||
|
||||
switch(injectionMethod) {
|
||||
case 1: // Fermi
|
||||
Ekin = 1.; //Implement Later
|
||||
Ekin_eV = 1.; //Implement Later
|
||||
break;
|
||||
|
||||
case 2: //Delta
|
||||
Ekin = deltaKinEnergy;
|
||||
Ekin_eV = deltaKinEnergy_eV;
|
||||
break;
|
||||
case 3: //Maxwell Boltzman
|
||||
Ekin = 1.; //Implement Later
|
||||
Ekin_eV = 1.; //Implement Later
|
||||
break;
|
||||
default:
|
||||
std::cerr<<"Invalid Injection Method./n";
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
|
||||
absSpeed = sqrt( pow(constc,2) - ( pow(constme,2)*pow(constc,6) ) / pow( Ekin + constme*pow(constc,2) , 2 ) );
|
||||
speed = absSpeed * speedDir;
|
||||
|
||||
absSpeed_ms = v_ms(Ekin_eV);
|
||||
speed_ms = absSpeed_ms * speedDir;
|
||||
|
||||
|
||||
particleQueue.assign(1,Particle(constme,constqe,loc, speed,numInjectedParticles,NULL,electron));
|
||||
numInjectedParticles++;
|
||||
return (Particle(me_eV,qe_e,loc_m, speed_ms,numInjectedParticles,NULL,electron));
|
||||
}
|
||||
|
||||
void Simulation::move(double MFP,int queueNum) {
|
||||
if (queueNum > particleQueue.size()-1) {
|
||||
std::cerr<<"queueNum outside of size"<<std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> Simulation::move(Particle inputParticle,double distance_m) {
|
||||
//Pseudocode, lineare bewegung
|
||||
blitz::TinyVector<double,3> SpeedDir;
|
||||
SpeedDir = 1./sqrt(dot(particleQueue[queueNum].getSpeed(),particleQueue[queueNum].getSpeed()))*particleQueue[queueNum].getSpeed();
|
||||
particleQueue[queueNum].setLoc(particleQueue[queueNum].getLoc() + SpeedDir*MFP);
|
||||
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::movedOutside(int queueNum) {
|
||||
if (queueNum > particleQueue.size()-1) {
|
||||
std::cerr<<"queueNum outside of size"<<std::endl;
|
||||
exit(1);
|
||||
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 ) );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> loc = particleQueue[queueNum].getLoc();
|
||||
double r = particleQueue[queueNum].getRadius();
|
||||
return (!(loc[2]>0 && loc[2]<wgtsLength && r<(wgtsDiameter/2) ));
|
||||
}
|
||||
|
||||
void Simulation::moveToLocOfDeath(blitz::TinyVector<double,3> oldLoc, int queueNum) {
|
||||
double stepsize = particleQueue[queueNum].getSpeedAbs()*dt;
|
||||
particleQueue[queueNum].setLoc(oldLoc);
|
||||
while (!movedOutside(queueNum) ) {
|
||||
move (stepsize,queueNum);
|
||||
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));
|
||||
}
|
||||
if (particleQueue[queueNum].getLoc()(2)<0) {
|
||||
particleQueue[queueNum].getLoc()(2) = 0;
|
||||
} else if (particleQueue[queueNum].getLoc()(2)>wgtsLength) {
|
||||
particleQueue[queueNum].getLoc()(2) = wgtsLength;
|
||||
return (loc_m);
|
||||
}
|
||||
|
||||
|
||||
// Logging Methods
|
||||
void Simulation::writeToLogger(Particle inputParticle) {
|
||||
std::string textLine;
|
||||
|
||||
|
||||
particleLogger.push_back(textLine);
|
||||
}
|
||||
|
||||
|
||||
void Simulation::writeToFile(std::vector<Particle> *particleLogger) {
|
||||
// Write all electrons to one file, just append them, ID for identification
|
||||
// Writing after every particle is very time intense.... Buffer and write only once every...
|
||||
|
||||
outFile.open (outputName,std::ios::app);
|
||||
for (particleLoggerIt = particleLogger->begin() ; particleLoggerIt != particleLogger->end() ; particleLoggerIt++) {
|
||||
outFile << *particleLoggerIt<<std::endl;
|
||||
}
|
||||
// Runde Position auf Rand
|
||||
outFile.close();
|
||||
}
|
||||
|
||||
|
||||
double Simulation::calcMFP() {
|
||||
return(1);
|
||||
// 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