Moved serial mode to target mcelecron_serial.

Implemented parallelization with mpi.
This commit is contained in:
Christian
2019-07-18 14:02:19 +02:00
parent fd131afdd3
commit 578d673b65
35 changed files with 916 additions and 469 deletions
+72
View File
@@ -0,0 +1,72 @@
//
// particle_looper.cpp
// mc_electron
//
// Created by Christian Reiling on 16.07.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#include "particle_looper.hpp"
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) {
std::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;
}