Rotational J=0->2 Vibrational v=0->1 Electrical various (7 in total, see Paper from Janev 2008 for details)
162 lines
4.7 KiB
C++
162 lines
4.7 KiB
C++
//
|
|
// simulation.cpp
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 20.09.18.
|
|
// Copyright © 2018 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
#include "simulation.hpp"
|
|
|
|
using namespace std;
|
|
|
|
|
|
const long int Simulation::seed = load_parameter("seed");
|
|
const long int Simulation::numberTotalDecays = load_parameter("numberTotalDecays");
|
|
|
|
void Simulation::init() {
|
|
set_RNGs();
|
|
|
|
timer = Timer(&numberDecays);
|
|
part_loggers = Particle_Logger_Builder::build(&h5f);
|
|
populations = Population_Builder::build(&timer, &rngUni, &rngNormal);
|
|
|
|
injector = Injector(&rngUni, &rngNormal);
|
|
movers = Mover_Builder::build(&part_loggers, &populations);
|
|
interactions = Interaction_Builder::build(&populations, &rngUni);
|
|
terminators = Terminator_Builder::build();
|
|
|
|
pop_loggers = Population_Logger_Builder::build(&h5f, &populations, &timer);
|
|
pop_load_saver = Population_Load_Saver(&populations, &timer);
|
|
|
|
set_statusUpdater();
|
|
}
|
|
|
|
void Simulation::set_RNGs() {
|
|
rngUni.seed(seed);
|
|
rngNormal.seed(seed);
|
|
}
|
|
|
|
void Simulation::set_statusUpdater() {
|
|
updater_fraction = numberTotalDecays/100;
|
|
updater_fraction = updater_fraction==0 ? 1 : updater_fraction;
|
|
}
|
|
|
|
void Simulation::doit() {
|
|
Mover_Base *moverPtr;
|
|
Interaction_Base *interactionPtr;
|
|
Terminator_Base *terminatorPtr;
|
|
|
|
InteractionOut IntOut;
|
|
double macroSigma_m2;
|
|
std::deque<Particle> partQue;
|
|
Particle curPart;
|
|
vec3 oldLoc_m;
|
|
while ( (numberDecays < numberTotalDecays) || (!partQue.empty()) ) {
|
|
if (partQue.empty()) {
|
|
pop_loggers.log();
|
|
curPart = injector.injectElectron(numberTotalParticles);
|
|
numberDecays++;
|
|
numberTotalParticles++;
|
|
do_statusUpdate();
|
|
} else {
|
|
curPart = partQue.front();
|
|
partQue.pop_front();
|
|
}
|
|
moverPtr = movers.find(curPart.get_species());
|
|
interactionPtr = interactions.find(curPart.get_species());
|
|
terminatorPtr = terminators.find(curPart.get_species());
|
|
|
|
while (!terminatorPtr->checkTermination(curPart)) {
|
|
oldLoc_m = curPart.get_Location_m();
|
|
macroSigma_m2 = interactionPtr->get_macroSigma_m2(curPart);
|
|
moverPtr->move(&curPart, macroSigma_m2);
|
|
if (!terminatorPtr->checkTermination(curPart)) {
|
|
IntOut = interactionPtr->do_Interaction(&curPart);
|
|
for (int i=0; i<IntOut.get_number_new_particles(); i++) {
|
|
partQue.push_back(IntOut.get_new_particles()[i]);
|
|
partQue.back().set_Id(numberTotalParticles++);
|
|
}
|
|
if (IntOut.get_decrease_population()) {
|
|
populations.find(IntOut.get_decrease_species())->decrease_denisty(IntOut.get_decrease_location(), IntOut.get_decrease_energy_eV());
|
|
}
|
|
if (IntOut.get_delete_current()) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
pop_loggers.log();
|
|
};
|
|
|
|
|
|
|
|
void Simulation::do_statusUpdate() {
|
|
if (numberDecays%updater_fraction == 0){
|
|
if (updater_numberOfPrevious!=numberDecays) {
|
|
cout<<numberDecays<<"/"<<numberTotalDecays<<endl;
|
|
}
|
|
updater_numberOfPrevious = numberDecays;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
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_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.get_T2_flowSpeed_ms(newLoc_m),&rngUni);
|
|
switch (process) {
|
|
case 1: // Elastic Scattering
|
|
interactElectron->do_elaScattering(Kat.roll_T2_speed_ms(newLoc_m, &rngUni, &rngNormal) , &rngUni);
|
|
break;
|
|
case 2: // Ionization
|
|
electronQue.push_back( interactElectron->do_Ionization(Kat.roll_T2_speed_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 (
|
|
load_parameter("injectionMethod") == 1 &&
|
|
load_parameter("elaOn") == 0 &&
|
|
load_parameter("ionOn") == 1 &&
|
|
load_parameter("numberZBins") == -1
|
|
) {
|
|
return;
|
|
}else {
|
|
throw MyException("Simulation::parameterCheck_TC6: Some Parameter is wrong");
|
|
}
|
|
}
|
|
*/
|