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
+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.
}
}
}
}