154 lines
4.4 KiB
C++
154 lines
4.4 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 "constants.hpp"
|
|
#include "functions.hpp"
|
|
|
|
#include "fstream"
|
|
|
|
using namespace std;
|
|
|
|
|
|
const long int Simulation::seed = getParameter("seed");
|
|
const long int Simulation::numberTotalDecays = getParameter("numberTotalDecays");
|
|
const int Simulation::propagationMethod = getParameter("propagationMethod");
|
|
const int Simulation::maxInteractions = getParameter("maxInteractions");
|
|
|
|
Simulation::Simulation() {
|
|
rngUni.seed(seed);
|
|
updater_fraction = numberTotalDecays/100;
|
|
}
|
|
|
|
void Simulation::doit() {
|
|
while ( (numberDecays < numberTotalDecays) || (!electronQue.empty()) || (!tritiumIonQue.empty()) ) {
|
|
if (electronQue.empty() && tritiumIonQue.empty()) {
|
|
electronQue.push_back(Kat.injectElectron(numberTotalElectrons++, &rngUni, &rngNormal));
|
|
numberDecays++;
|
|
}
|
|
do_statusUpdate();
|
|
if (!electronQue.empty()) {
|
|
process_firstElectron();
|
|
} else {
|
|
process_firstTIon();
|
|
}
|
|
|
|
}
|
|
};
|
|
|
|
void Simulation::process_firstElectron() {
|
|
int numberInteractionsThisElectron = 0;
|
|
actionElectronPtr = &electronQue.front();
|
|
while (!Kat.check_Termination (*actionElectronPtr) && !check_NumberInteractions(numberInteractionsThisElectron)) {
|
|
move_electron(actionElectronPtr, &Log);
|
|
if (!Kat.check_Termination (*actionElectronPtr) ) {
|
|
do_interaction(actionElectronPtr);
|
|
}
|
|
}
|
|
electronQue.pop_front();
|
|
}
|
|
|
|
void Simulation::process_firstTIon() {
|
|
|
|
}
|
|
|
|
|
|
bool Simulation::check_NumberInteractions(int &numberInteractionsThisElectron) {
|
|
if (maxInteractions == 0) {
|
|
return(false);
|
|
}
|
|
|
|
if (numberInteractionsThisElectron < maxInteractions) {
|
|
numberInteractionsThisElectron++;
|
|
return(false);
|
|
} else {
|
|
return(true);
|
|
}
|
|
}
|
|
|
|
void Simulation::doTC6() {
|
|
cout<<endl<<"Simulation::doTC6: Doing Testcase 6."<<endl<<endl;
|
|
parameterCheck_TC6();
|
|
|
|
while ( (numberTotalElectrons < numberTotalDecays) || (electronQue.size() > 0) ) {
|
|
if (!electronQue.empty()) {
|
|
throw MyException("Simulation::doTC6: electronQue should be empty");
|
|
}
|
|
electronQue.push_back(Kat.injectElectron(numberTotalElectrons++, &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::do_statusUpdate() {
|
|
if (numberDecays%updater_fraction == 0){
|
|
if (updater_numberOfPrevious!=numberDecays) {
|
|
cout<<numberDecays<<"/"<<numberTotalDecays<<endl;
|
|
}
|
|
updater_numberOfPrevious = numberDecays;
|
|
}
|
|
}
|
|
|
|
void Simulation::move_electron(Electron *moveElectron, H5_Logger *Log) {
|
|
double MFP_m = Kat.get_MFP_m(&electronQue.front());
|
|
if (propagationMethod==0) {
|
|
Kat.do_DriftApproximationMovement(moveElectron, MFP_m, Log);
|
|
} else if (propagationMethod==1) {
|
|
Kat.do_BorisPushMovement(moveElectron, MFP_m, Log); // 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().get_Location_m();
|
|
if (Kat.check_Termination(*interactElectron)) {
|
|
stringstream ss;
|
|
ss<<"Simulation::do_interaction: Particle already terminated.";
|
|
throw MyException(ss.str());
|
|
}
|
|
int process = interactElectron->roll_Interaction(Kat.getFlowSpeedT2_ms(newLoc_m),&rngUni);
|
|
switch (process) {
|
|
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), numberTotalElectrons, &rngUni) );
|
|
numberTotalElectrons++;
|
|
// 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 (
|
|
getParameter("injectionMethod") == 1 &&
|
|
getParameter("elaOn") == 0 &&
|
|
getParameter("ionOn") == 1 &&
|
|
getParameter("numberZBins") == -1
|
|
) {
|
|
return;
|
|
}else {
|
|
throw MyException("Simulation::parameterCheck_TC6: Some Parameter is wrong");
|
|
}
|
|
}
|