94 lines
2.8 KiB
C++
94 lines
2.8 KiB
C++
//
|
|
// particle_looper.cpp
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 16.07.19.
|
|
// Copyright © 2019 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
#include "particle_looper.hpp"
|
|
|
|
using namespace std;
|
|
|
|
|
|
void Particle_Looper::init_managers() {
|
|
timer = Timer(&local_decays, &global_decays);
|
|
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);
|
|
}
|
|
|
|
void Particle_Looper::do_loops(int target_decays) {
|
|
queue<Particle> particle_queue;
|
|
int number_decays = 0;
|
|
while ( (number_decays < target_decays) || (!particle_queue.empty()) ) {
|
|
if (particle_queue.empty()) {
|
|
pop_loggers.log();
|
|
particle_queue.push(injector.injectElectron(get_new_id()));
|
|
number_decays++;
|
|
local_decays++;
|
|
}
|
|
process_first(&particle_queue);
|
|
}
|
|
pop_loggers.log();
|
|
}
|
|
|
|
void Particle_Looper::process_first(std::queue<Particle> *particle_queue) {
|
|
Particle curPart = particle_queue->front();
|
|
Mover_Base *moverPtr = movers.find(curPart.get_species());
|
|
Interaction_Base *interactionPtr = interactions.find(curPart.get_species());
|
|
Terminator_Base *terminatorPtr = terminators.find(curPart.get_species());
|
|
|
|
InteractionOut IntOut;
|
|
double macroSigma_m2;
|
|
vec3 oldLoc_m;
|
|
while (!terminatorPtr->checkTermination(curPart)) {
|
|
oldLoc_m = curPart.get_x_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++) {
|
|
particle_queue->push(IntOut.get_new_particles()[i]);
|
|
particle_queue->back().set_Id(get_new_id());
|
|
}
|
|
if (IntOut.get_delete_current()) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
particle_queue->pop();
|
|
}
|
|
|
|
long int Particle_Looper::get_new_id() {
|
|
long int res = ID_offset + ID_counter;
|
|
ID_counter++;
|
|
return res;
|
|
}
|
|
|
|
void Particle_Looper::do_logging_off_loops(int target_decays) {
|
|
int prev_ID_counter = ID_counter;
|
|
set_logging(false);
|
|
do_loops(target_decays);
|
|
set_logging(true);
|
|
ID_counter = prev_ID_counter;
|
|
}
|
|
|
|
void Particle_Looper::set_logging(bool logging) {
|
|
vector<species> all_species = get_all_species_vector();
|
|
species current_species;
|
|
for (vector<species>::iterator itr = all_species.begin(); itr != all_species.end(); itr++) {
|
|
current_species = *itr;
|
|
if (part_loggers.exists(current_species)) {
|
|
part_loggers.find(current_species)->set_logging(logging);
|
|
}
|
|
}
|
|
}
|