This commit is contained in:
2019-03-14 07:14:38 +01:00
9 changed files with 86 additions and 91 deletions
+1 -3
View File
@@ -118,9 +118,7 @@ void Electron::do_elaKinetics(vec3 speedT2_ms, double thetaLab, double phiLab) {
/*
Ionization:
Following
Differential and total cross sections for ionization of helium and hydrogen by electrons
M. E. Rudd 1991 Physical Review A Volume 44 Number3
Using BED-Model Kim and Rudd 1994
*/
double Electron::get_ionSigma_m2(vec3 speedT2_ms) {
+26 -14
View File
@@ -114,7 +114,7 @@ double Katrin::calc_FermiFunction(double Z, double Ekin_eV) {
return( 2*pi*eta/(1-exp(-2*pi*eta)) );
}
// Move
// Move Electrons
void Katrin::do_BorisPush(Electron *moveElectron) {
double MFP_m = get_MFP_m(moveElectron);
vec3 oldLoc_m = moveElectron->getLoc_m();
@@ -135,29 +135,41 @@ void Katrin::do_BorisPush(Electron *moveElectron) {
void Katrin::do_DriftApproximation(Electron *moveElectron) {
// Drift Approximation: Assume constant B and only movement out in z=0, z=wgtsLength_m...
double MFP_m= get_MFP_m(moveElectron);
double MFP_m = get_MFP_m(moveElectron);
vec3 oldLoc_m = moveElectron->getLoc_m();
vec3 newLoc_m = oldLoc_m;
double z_m = oldLoc_m[2];
double vz_ms = moveElectron->getSpeed_ms()[2];
double vdir = vz_ms < 0 ? -1 : 1;
double znew_m = z_m + vdir*MFP_m;
vec3 v_ms = moveElectron->getSpeed_ms();
if (znew_m < 0) {
znew_m = 0;
} else if (znew_m > wgtsLength_m) {
znew_m = wgtsLength_m;
}
double znew_m = getDrift_znew_m(MFP_m, oldLoc_m[2], v_ms);
newLoc_m[2] = znew_m;
moveElectron->setLoc_m(newLoc_m);
if (movedOutside(newLoc_m)) {
moveElectron->setSpeed_ms(vec3(0,0,0));
return;
}
return;
}
double Katrin::getDrift_znew_m(double MFP_m, double zold_m, vec3 v_ms) {
double vAbs_ms = calc_vecAbs(v_ms);
double vDir = v_ms[2] < 0 ? -1 : 1;
vec3 vPar_ms = vec3(0,0,0);
vPar_ms[2] = v_ms[2];
double vParAbs_ms = calc_vecAbs(vPar_ms);
double deltaZ_m = vDir*vParAbs_ms/vAbs_ms * MFP_m;
double znew_m = zold_m + deltaZ_m;
if (znew_m < 0) {
znew_m = 0;
} else if (znew_m > wgtsLength_m) {
znew_m = 2*wgtsLength_m - znew_m;
}
return (znew_m);
}
double Katrin::get_MFP_m(Electron *moveElectron) {
//Rework for inserting vector of Interactions
vec3 loc_m, speedT2_ms;
@@ -173,10 +185,10 @@ double Katrin::get_MFP_m(Electron *moveElectron) {
bool Katrin::movedOutside(vec3 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 ) );
}
// Termination
// Terminate Electrons
bool Katrin::get_Terminated(Electron termElectron) {
double Ekin_eV, ETemp_eV;
Ekin_eV = termElectron.getKinEnergy_eV();
+5 -2
View File
@@ -32,9 +32,9 @@ public:
vec3 getTempSpeedT2_ms(vec3 loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
// Injection
public:
Electron injectElectron(int newId, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
private:
// Injection
double roll_FermiEnergy_eV(ranlib::Uniform<double> *rngUni);
double calc_FermiDecaySpectrumDensity(double Ekin_eV);
double calc_FermiFunction(double Z, double Ekin_eV);
@@ -43,12 +43,15 @@ private:
public:
void do_BorisPush(Electron *moveElectron);
void do_DriftApproximation(Electron *moveElectron);
private:
double getDrift_znew_m(double MFP_m, double zold_m, vec3 v_ms);
bool movedOutside(blitz::TinyVector<double,3> loc_m);
double get_MFP_m(Electron *moveElectron);
// Terminate Electrons
public:
bool get_Terminated(Electron termElectron);
private:
double get_MFP_m(Electron *moveElectron);
double cutoffEnergy_eV;
void set_cutoffEnergy_eV();
};
+10 -7
View File
@@ -21,11 +21,13 @@ Logger::Logger() {
logging = false;
return;
}
create_outdirName();
set_zLogValues();
set_outStream();
}
void Logger::logElectron(Electron *logElectron, blitz::TinyVector<double,3> oldLoc_m) {
void Logger::log_Electron(Electron *logElectron, blitz::TinyVector<double,3> oldLoc_m) {
if (!logging) {
return;
}
@@ -65,25 +67,23 @@ void Logger::set_zLogValues() {
}
void Logger::set_outStream() {
string dirname = getDirName();
if (numberZBins == -1) {
outStream = new ofstream [1];
stringstream ss;
ss <<dirname << "/all" << ".dat";
ss <<outdirName << "/all" << ".dat";
outStream[0].open(ss.str().c_str());
} else {
outStream = new ofstream [numberZBins];
for (int i = 0; i < numberZBins; i++)
{
stringstream ss;
ss << dirname << "/z=" << zLogValues[i] << ".dat";
ss << outdirName << "/z=" << zLogValues[i] << ".dat";
outStream[i].open(ss.str().c_str());
}
}
}
string Logger::getDirName() {
void Logger::create_outdirName() {
string poub = getenv("parpath");
string pname = getenv("parfile");
int i = 1;
@@ -105,7 +105,8 @@ string Logger::getDirName() {
ss<<"Simulation::initLogger: Could not create folder "<<dirname.str()<<" for Logging.";
throw MyException(ss.str());
}
return(dirname.str());
outdirName = dirname.str();
return;
}
string Logger::getTimeString() {
@@ -118,3 +119,5 @@ string Logger::getTimeString() {
string str(buffer);
return(str);
}
+3 -2
View File
@@ -17,15 +17,16 @@ class Logger : private Parameter {
public:
Logger();
void logElectron(Electron *logElectron,blitz::TinyVector<double,3> oldLoc_m);
void log_Electron(Electron *logElectron,blitz::TinyVector<double,3> oldLoc_m);
private:
bool logging;
std::string outdirName;
std::vector<double> zLogValues;
std::ofstream *outStream;
void set_zLogValues();
void set_outStream();
std::string getDirName();
void create_outdirName();
std::string getTimeString();
};
+3 -8
View File
@@ -14,20 +14,15 @@ using namespace std;
int main(int argc, const char * argv[]) {
//runTests();
clock_t start;
double duration;
start = clock();
clock_t start = clock();
try {
Simulation Sim;
Sim.doit();
} catch (MyException& caught) {
cout<<caught.what()<<endl;
exit(1);
}
duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;
cout<<"Duration: "<< duration <<'\n';
cout<<"Duration: "<< ( clock() - start ) / (double) CLOCKS_PER_SEC <<'\n';
}
+1 -1
View File
@@ -15,7 +15,7 @@ TARGETS = mcelectron
all: $(TARGETS)
mcelectron: main.o parameter.o functions.o constants.o katrin.o logger.o simulation.o \
particle.o electron.o elastic.o ionization.o bedionization.o
particle.o electron.o bedionization.o
$(CXX) -o $@ $^ $(LDFLAGS) $(LOADLIBES)
%.o : %.cpp
+31 -53
View File
@@ -11,6 +11,8 @@
#include "myexeption.h"
#include "fstream"
using namespace std;
@@ -32,7 +34,7 @@ void Simulation::doit() {
status_updater();
oldLoc_m = electronQue.front().getLoc_m();
move_electron(&electronQue.front());
Log.logElectron(&electronQue.front(), oldLoc_m);
Log.log_Electron(&electronQue.front(), oldLoc_m);
do_interaction(&electronQue.front());
if (Kat.get_Terminated (electronQue.front())) {
@@ -41,64 +43,23 @@ void Simulation::doit() {
}
};
/*
void Simulation::doTC6() {
cout<<endl<<"Simulation::doTC6: Doing Testcase 6."<<endl<<endl;
stringstream fileName;
fileName << Log.getDirName() << "/TC6all.dat";
ofstream outTC6;
outTC6.open (fileName.str().c_str());
parameterCheck_TC6();
blitz::TinyVector <double,3> loc_m;
while ( (numberElectrons < numTotalElectrons) || (electronQue.size() > 0) ) {
if (!electronQue.empty()) {
throw MyException("Simulation::doTC6: electronQue should be empty");
}
electronQue.push_back(Kat.injectElectron(numberElectrons, &rngUni, &rngNormal));
numberElectrons++;
if (numberElectrons%100 == 0){
cout<<numberElectrons<<"/"<<numTotalElectrons<<endl;
}
if (propagationMethod==0) {
moveElectronDriftApproximation( &electronQue.front() , getMFP_m(electronQue.front()) );
} else if (propagationMethod==1) {
moveElectronBorisPush(&electronQue.front(),getMFP_m(electronQue.front())); // If moved outside set v = 0,0,0;
} else {
stringstream ss;
ss<<"Simulation::doTC6(): propagationMethod= "<<propagationMethod<<" not valid.";
throw MyException(ss.str());
}
loc_m = electronQue.front().getLoc_m();
switch ( electronQue.front().roll_Interaction(Kat.getFlowSpeedT2_ms(loc_m),&rngUni) ) {
case 0: //Moved Outside
break;
case 1: // Elastic Scattering
throw MyException("Simulation::doTC6(): Elastic Scattering should be turned off.");
break;
case 2: // Ionization
electronQue.push_back( electronQue.front().do_Ionization(Kat.getTotSpeedT2_ms(loc_m, &rngUni, &rngNormal), numberElectrons, &rngUni) );
numberElectrons++;
electronQue.pop_front();
break;
default:
throw MyException("Simulation::doit(): getprocess() returned unknown event");
break;
}
outTC6 << electronQue.front() <<endl;
electronQue.pop_front();
electronQue.push_back(Kat.injectElectron(numberElectrons++, &rngUni, &rngNormal));
do_interaction(&electronQue.front()); //parameter should only allow for ionizations
electronQue.pop_front(); // delete initial electron
Log.log_Electron(&electronQue.front(), vec3(0,0,0)); //should be daugther electron
electronQue.pop_front(); //delete daugther electron
}
outTC6.close();
};
*/
void Simulation::status_updater() {
if (numberElectrons%100 == 0){
if (updater_numberOfPrevious!=numberElectrons) {
@@ -115,14 +76,15 @@ void Simulation::move_electron(Electron *moveElectron) {
Kat.do_BorisPush(moveElectron); // If moved outside set v = 0,0,0;
} else {
stringstream ss;
ss<<"Simulation::doit(): propagationMethod= "<<propagationMethod<<" not valid.";
ss<<"Simulation::move_electron: propagationMethod="<<propagationMethod<<" not valid.";
throw MyException(ss.str());
}
}
void Simulation::do_interaction(Electron *interactElectron) {
vec3 newLoc_m = electronQue.front().getLoc_m();
switch ( interactElectron->roll_Interaction(Kat.getFlowSpeedT2_ms(newLoc_m),&rngUni) ) {
int process = interactElectron->roll_Interaction(Kat.getFlowSpeedT2_ms(newLoc_m),&rngUni);
switch ( process ) {
case 0: //Moved Outside
break;
case 1: // Elastic Scattering
@@ -136,7 +98,23 @@ void Simulation::do_interaction(Electron *interactElectron) {
case 3: // Recombination
break;
default:
throw MyException("Simulation::doit(): getprocess() returned unknown event");
stringstream ss;
ss<<"Simulation::do_interaction: process="<<process<< "not defined.";
throw MyException(ss.str());
break;
}
}
void Simulation::parameterCheck_TC6() {
if (
injectionMethod == 1 &&
elaOn == 0 &&
ionOn == 1 &&
numberZBins == -1
) {
return;
}else {
throw MyException("Simulation::parameterCheck_TC6: Some Parameter is wrong");
}
}
+6 -1
View File
@@ -23,7 +23,7 @@ class Simulation: private Parameter, private Constants {
public:
Simulation();
void doit();
// void doTC6(void);
private:
void status_updater();
@@ -39,6 +39,11 @@ private:
int numberElectrons;
std::deque<Electron> electronQue;
int updater_numberOfPrevious;
public:
void doTC6();
private:
void parameterCheck_TC6();
};
#endif /* simulation_hpp */