1) Spectrometer will reflect electrons. 2) Taking into account radial movement leading to smaller delta z.
121 lines
3.1 KiB
C++
121 lines
3.1 KiB
C++
//
|
|
// simulation.cpp
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 20.09.18.
|
|
// Copyright © 2018 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
|
|
#include "simulation.hpp"
|
|
|
|
#include "myexeption.h"
|
|
|
|
#include "fstream"
|
|
|
|
using namespace std;
|
|
|
|
|
|
Simulation::Simulation() {
|
|
numberElectrons = 0;
|
|
rngUni.seed(seed);
|
|
updater_numberOfPrevious = 0;
|
|
|
|
}
|
|
|
|
|
|
void Simulation::doit() {
|
|
vec3 oldLoc_m;
|
|
while ( (numberElectrons < numTotalElectrons) || (electronQue.size() > 0) ) {
|
|
if (electronQue.empty()) {
|
|
electronQue.push_back(Kat.injectElectron(numberElectrons++, &rngUni, &rngNormal));
|
|
}
|
|
|
|
status_updater();
|
|
oldLoc_m = electronQue.front().getLoc_m();
|
|
move_electron(&electronQue.front());
|
|
Log.log_Electron(&electronQue.front(), oldLoc_m);
|
|
do_interaction(&electronQue.front());
|
|
|
|
if (Kat.get_Terminated (electronQue.front())) {
|
|
electronQue.pop_front();
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
void Simulation::doTC6() {
|
|
cout<<endl<<"Simulation::doTC6: Doing Testcase 6."<<endl<<endl;
|
|
parameterCheck_TC6();
|
|
|
|
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));
|
|
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
|
|
}
|
|
};
|
|
|
|
void Simulation::status_updater() {
|
|
if (numberElectrons%100 == 0){
|
|
if (updater_numberOfPrevious!=numberElectrons) {
|
|
cout<<numberElectrons<<"/"<<numTotalElectrons<<endl;
|
|
}
|
|
updater_numberOfPrevious = numberElectrons;
|
|
}
|
|
}
|
|
|
|
void Simulation::move_electron(Electron *moveElectron) {
|
|
if (propagationMethod==0) {
|
|
Kat.do_DriftApproximation(moveElectron);
|
|
} else if (propagationMethod==1) {
|
|
Kat.do_BorisPush(moveElectron); // If moved outside set v = 0,0,0;
|
|
} else {
|
|
stringstream ss;
|
|
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();
|
|
int process = interactElectron->roll_Interaction(Kat.getFlowSpeedT2_ms(newLoc_m),&rngUni);
|
|
switch ( process ) {
|
|
case 0: //Moved Outside
|
|
break;
|
|
case 1: // Elastic Scattering
|
|
interactElectron->do_elaScattering(Kat.getTotSpeedT2_ms(newLoc_m, &rngUni, &rngNormal) , &rngUni);
|
|
break;
|
|
case 2: // Ionization
|
|
electronQue.push_back( interactElectron->do_Ionization(Kat.getTotSpeedT2_ms(newLoc_m, &rngUni, &rngNormal), numberElectrons, &rngUni) );
|
|
numberElectrons++;
|
|
// Update Ions...
|
|
break;
|
|
case 3: // Recombination
|
|
break;
|
|
default:
|
|
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");
|
|
}
|
|
}
|