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