Bug fixes.
This commit is contained in:
@@ -10,8 +10,11 @@
|
||||
|
||||
|
||||
void Simulation::doit() {
|
||||
double MFP_m;
|
||||
blitz::TinyVector <double,3> loc_m;
|
||||
bool insideFlag;
|
||||
|
||||
Particle ScatT2;
|
||||
Interaction IntereT2;
|
||||
|
||||
while ( (numInjectedParticles < numTotalParticles) || (particleQue.size() > 0) ) {
|
||||
if (particleQue.empty()) {
|
||||
@@ -21,37 +24,41 @@ void Simulation::doit() {
|
||||
std::cout<<numInjectedParticles<<"/"<<numTotalParticles<<std::endl;
|
||||
}
|
||||
}
|
||||
ScatT2 = Kat.getT2AverScatPart(particleQue.front().getLoc_m(), &rngUni, &rngNormal);
|
||||
IntereT2 = Interaction(&particleQue.front(),&ScatT2);
|
||||
//Replace with vector containing all Interactions and adapt functions and put particle pointers into Particle class
|
||||
|
||||
MFP_m = getMFP_m(IntereT2);
|
||||
moveParticle(&particleQue.front(),MFP_m); // If moved outside set v = 0,0,0;
|
||||
|
||||
insideFlag = move(&particleQue.front());
|
||||
if (insideFlag) {
|
||||
switch (getInteraction(particleQue.front())) {
|
||||
case 0: // Elastic Scattering
|
||||
particleQue.front().doElaScat(&rngUni);
|
||||
std::cout<<particleQue.front()<<particleQue.front().getKinEnergy_eV()<<std::endl;
|
||||
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;
|
||||
}
|
||||
|
||||
}else {
|
||||
switch (getInteraction(particleQue.front())) {
|
||||
case 0: //Moved Outside
|
||||
case 1: // Elastic Scattering
|
||||
ScatT2 = Kat.getT2ScatPart(particleQue.front().getLoc_m(), &rngUni, &rngNormal);
|
||||
IntereT2 = Interaction(&particleQue.front(),&ScatT2);
|
||||
IntereT2.doElaScat(&rngUni);
|
||||
break;
|
||||
case 2: // Ionization
|
||||
//particleQue.push_back();
|
||||
break;
|
||||
case 3: // Recombination
|
||||
break;
|
||||
default:
|
||||
std::cerr<<"getprocess() returned unknown event"<<std::endl;
|
||||
break;
|
||||
}
|
||||
if (checkTermination (particleQue.front())) {
|
||||
particleQue.pop_front();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Injection
|
||||
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,vAbs_ms,vTheta_rad,vPhi_rad;
|
||||
double Ekin_eV;
|
||||
|
||||
r_m = wgtsRadius_m*sqrt(rngUni.random());
|
||||
phi_rad = rngUni.random()*2*pi;
|
||||
@@ -76,13 +83,7 @@ Particle Simulation::inject() {
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
|
||||
vPhi_rad = 2*pi*rngUni.random();
|
||||
vTheta_rad = pi*rngUni.random();
|
||||
vAbs_ms = calcV_ms(Ekin_eV);
|
||||
speed_ms = sin(vTheta_rad)*cos(vPhi_rad) , sin(vTheta_rad)*sin(vPhi_rad) , cos(vTheta_rad);
|
||||
speed_ms *= vAbs_ms;
|
||||
|
||||
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() {
|
||||
@@ -98,7 +99,6 @@ double Simulation::getBetaDecayEnergyRejection_eV() {
|
||||
} while(eta2*pmax > EnergyDistributionBetaDecay(Ecan_eV));
|
||||
return(Ecan_eV);
|
||||
}
|
||||
|
||||
double Simulation::EnergyDistributionBetaDecay(double Ekin_eV) {
|
||||
if (Ekin_eV>Etridecay_eV) {
|
||||
return (0.);
|
||||
@@ -107,52 +107,82 @@ double Simulation::EnergyDistributionBetaDecay(double Ekin_eV) {
|
||||
return( BetaDecayC * FermiFunction(ZHe3, Ekin_eV) * p_eV*(Ekin_eV+me_eV)*pow(Etridecay_eV-Ekin_eV,2) );
|
||||
}
|
||||
}
|
||||
|
||||
double Simulation::FermiFunction(double Z, double Ekin_eV) {
|
||||
double gamma = 1+ Ekin_eV/me_eV;
|
||||
double beta = sqrt(1 - pow(gamma,-2));
|
||||
double eta =Z/beta/137.;
|
||||
return( 2*pi*eta/(1-exp(-2*pi*eta)) );
|
||||
}
|
||||
|
||||
double Simulation::getEnergyBoltzmann_eV() {
|
||||
double N = rngNormal.random();
|
||||
double beta = N*sqrt(kb_eVK*MBTemp_K/me_eV)*N;
|
||||
double beta = N*sqrt(kb_eVK*MBTemp_K/me_eV);
|
||||
double gamma = 1/sqrt(1-pow(beta,2));
|
||||
return((gamma-1)*me_eV);
|
||||
}
|
||||
bool Simulation::move(Particle *inputParticle) {
|
||||
blitz::TinyVector<double,3> oldLoc_m = inputParticle->getLoc_m();
|
||||
double density_m3 = Kat.getTritiumDensity(oldLoc_m);
|
||||
|
||||
// Moving
|
||||
void Simulation::moveParticle(Particle *movePart, double MFP_m) {
|
||||
blitz::TinyVector<double,3> oldLoc_m = movePart->getLoc_m();
|
||||
blitz::TinyVector<double,3> E_Vm = Kat.getElField(oldLoc_m);
|
||||
blitz::TinyVector<double,3> B_T = Kat.getMagField(oldLoc_m);
|
||||
|
||||
double sigTot_m2 = inputParticle->getSigmaTot_m2();
|
||||
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);
|
||||
if (movedOutside(inputParticle->getLoc_m())) {
|
||||
logParticle(inputParticle,oldLoc_m);
|
||||
return(false);
|
||||
distance += movePart->borisFly_m(E_Vm , B_T , dt_s);
|
||||
if (movedOutside(movePart->getLoc_m())) {
|
||||
logParticle(movePart,oldLoc_m);
|
||||
movePart->setSpeed_ms(zeroVec());
|
||||
return;
|
||||
}
|
||||
}
|
||||
logParticle(inputParticle,oldLoc_m);
|
||||
return(true);
|
||||
logParticle(movePart,oldLoc_m);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int Simulation::getInteraction(Particle inputParticle) {
|
||||
return(0);
|
||||
double Simulation::getMFP_m(Interaction Interaction) {
|
||||
//Rework for inserting vector of Interactions
|
||||
blitz::TinyVector<double,3> loc_m;
|
||||
double sigmaTot_m2, density_m3, MFP_m;
|
||||
loc_m = Interaction.getP1()->getLoc_m();
|
||||
|
||||
sigmaTot_m2 = Interaction.getSigmaTot_m2();
|
||||
density_m3 = Kat.getTritiumDensity(loc_m);
|
||||
MFP_m = 1/(density_m3 * sigmaTot_m2);
|
||||
return(MFP_m);
|
||||
}
|
||||
|
||||
|
||||
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 ) );
|
||||
}
|
||||
|
||||
//Interaction
|
||||
int Simulation::getInteraction(Particle interPart) {
|
||||
// Check Moved Outside
|
||||
if (interPart.getKinEnergy_eV()==0) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
// Termination
|
||||
bool Simulation::checkTermination(Particle termPart) {
|
||||
double EKin_eV, ETemp_eV;
|
||||
EKin_eV = termPart.getKinEnergy_eV();
|
||||
ETemp_eV = 3./2.*kb_eVK*wgtsTemp_K;
|
||||
if (ETemp_eV<0) {
|
||||
std::cerr<<"Simulation::checkTermination: ETemp_eV < 0." <<std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (EKin_eV<ETemp_eV) {
|
||||
return(true);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
// Logging
|
||||
void Simulation::initLogger(void) {
|
||||
// Set zLogValues;
|
||||
zLogValues.clear();
|
||||
@@ -194,10 +224,9 @@ void Simulation::initLogger(void) {
|
||||
for (int i = 0; i < numberZBins; i++)
|
||||
{
|
||||
std::string fileName = dirname + "/z=" + std::to_string(zLogValues[i]) + ".dat";
|
||||
outStream.emplace_back(std::ofstream{fileName});
|
||||
outStream.push_back(std::ofstream(fileName));
|
||||
}
|
||||
}
|
||||
|
||||
std::string Simulation::getTimeString() {
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
@@ -208,21 +237,20 @@ std::string Simulation::getTimeString() {
|
||||
std::string str(buffer);
|
||||
return(str);
|
||||
}
|
||||
|
||||
void Simulation::logParticle(Particle *inputParticle,blitz::TinyVector<double,3> oldLoc_m) {
|
||||
void Simulation::logParticle(Particle *logPart,blitz::TinyVector<double,3> oldLoc_m) {
|
||||
if (!logging) {
|
||||
return;
|
||||
}
|
||||
// Annahme: Ohne Interaction bliebt Bewegung in z-Richtung Konstant.
|
||||
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = inputParticle->getLoc_m()[2];
|
||||
double znew = logPart->getLoc_m()[2];
|
||||
double zmin = std::min(zold,znew);
|
||||
double zmax = std::max(zold,znew);
|
||||
|
||||
for (int i=0;i<numberZBins;i++) {
|
||||
if (zLogValues[i]>=zmin && zLogValues[i]<=zmax) {
|
||||
outStream[i]<<*inputParticle<<std::endl; // Location wrong, because it s the new Location.
|
||||
outStream[i]<<*logPart<<std::endl; // Location wrong, because it s the new Location.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user