Added "Population Calculation" Mode, where Particles are not logged and different communication rate between CPUs can be set to calculate equilibrium population densities in the beginning.
This commit is contained in:
@@ -59,6 +59,10 @@ inline void MultiZ_Particle_Logger::create(H5_File *h5_file, species this_specie
|
||||
}
|
||||
|
||||
inline void MultiZ_Particle_Logger::log(const Particle &logPart, const vec3 &oldLoc_m) {
|
||||
if (!logging) {
|
||||
return;
|
||||
}
|
||||
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = logPart.get_x_m()[2];
|
||||
double zmin = std::min(zold,znew);
|
||||
|
||||
@@ -40,7 +40,7 @@ std::string get_species_string(const species &spec) {
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<species> get_all_spieces_vector() {
|
||||
std::vector<species> get_all_species_vector() {
|
||||
std::vector<species> all;
|
||||
all.push_back(electron);
|
||||
all.push_back(tritium);
|
||||
@@ -52,7 +52,7 @@ std::vector<species> get_all_spieces_vector() {
|
||||
};
|
||||
|
||||
species get_species_from_string(const std::string &species_string) {
|
||||
std::vector<species> all = get_all_spieces_vector();
|
||||
std::vector<species> all = get_all_species_vector();
|
||||
for (std::vector<species>::iterator itr = all.begin(); itr!= all.end(); itr++) {
|
||||
if (get_species_string(*itr) == species_string) {
|
||||
return *itr;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
|
||||
enum species{electron, tritium, tritiumI, tritium2I, tritium2, tritium3I};
|
||||
std::vector<species> get_all_spieces_vector();
|
||||
std::vector<species> get_all_species_vector();
|
||||
std::string get_species_string(const species &spec);
|
||||
species get_species_from_string(const std::string &species_string);
|
||||
double get_species_mass(const species &spec);
|
||||
|
||||
@@ -13,9 +13,14 @@
|
||||
#include "process_base.h"
|
||||
|
||||
class Particle_Logger_Base : public Process_Base {
|
||||
protected:
|
||||
bool logging;
|
||||
public:
|
||||
Particle_Logger_Base(species this_species) : Process_Base(this_species) {};
|
||||
virtual void log(const Particle &logPart, const vec3 &oldLoc_m) = 0;
|
||||
void set_logging(const bool &logging) {
|
||||
this->logging = logging;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "particle_looper.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
void Particle_Looper::init_managers() {
|
||||
timer = Timer(&local_decays, &global_decays);
|
||||
@@ -24,7 +26,7 @@ void Particle_Looper::init_managers() {
|
||||
}
|
||||
|
||||
void Particle_Looper::do_loops(int target_decays) {
|
||||
std::queue<Particle> particle_queue;
|
||||
queue<Particle> particle_queue;
|
||||
int number_decays = 0;
|
||||
while ( (number_decays < target_decays) || (!particle_queue.empty()) ) {
|
||||
if (particle_queue.empty()) {
|
||||
@@ -70,3 +72,22 @@ long int Particle_Looper::get_new_id() {
|
||||
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(false);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,11 @@ private:
|
||||
void process_first(std::queue<Particle> *particle_queue);
|
||||
long int get_new_id();
|
||||
|
||||
public:
|
||||
void do_logging_off_loops(int target_decays);
|
||||
private:
|
||||
void set_logging(bool logging);
|
||||
|
||||
public:
|
||||
long int get_number_total_particles() {
|
||||
return ID_counter;
|
||||
|
||||
@@ -38,6 +38,9 @@ inline void SF_Particle_Logger::create(H5_File *h5_file, species this_species) {
|
||||
}
|
||||
|
||||
inline void SF_Particle_Logger::log(const Particle &logPart, const vec3 &oldLoc_m) {
|
||||
if (!logging) {
|
||||
return;
|
||||
}
|
||||
h5tb.write(logPart);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ using namespace std;
|
||||
const long int Simulation::seed = load_parameter("seed");
|
||||
const long int Simulation::numberTotalDecays = load_parameter("numberTotalDecays");
|
||||
const long int Simulation::simulationStepWidth = load_parameter("simulationStepWidth");
|
||||
const long int Simulation::popCalcDecays = load_parameter("popCalcDecays");
|
||||
const long int Simulation::popCalcStep = load_parameter("popCalcStep");
|
||||
|
||||
Simulation::Simulation() {
|
||||
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
|
||||
@@ -25,7 +27,7 @@ Simulation::~Simulation() {
|
||||
}
|
||||
|
||||
void Simulation::init_pop_arrays() {
|
||||
vector<species> all_species = get_all_spieces_vector();
|
||||
vector<species> all_species = get_all_species_vector();
|
||||
number_pop_species = all_species.size();
|
||||
|
||||
pop_species = new species[number_pop_species];
|
||||
@@ -114,29 +116,45 @@ void Simulation::create_out_dir(std::string dirname) {
|
||||
}
|
||||
|
||||
void Simulation::doit() {
|
||||
long int decays_this_cpu = numberTotalDecays/mpi_size;
|
||||
int overflow = numberTotalDecays%mpi_size;
|
||||
do_cycle(popCalcDecays, popCalcStep, false);
|
||||
cout<<"Population calculation done.\n";
|
||||
do_cycle(numberTotalDecays, simulationStepWidth, true);
|
||||
};
|
||||
|
||||
int num_cycles = decays_this_cpu/simulationStepWidth; // Must be same for all CPUs else deadlock!
|
||||
int num_remaining = decays_this_cpu%simulationStepWidth;
|
||||
void Simulation::do_cycle(long int number_total, long int step_size, bool logging) {
|
||||
if (step_size <1) {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::do_cycle: invalid step_size. \n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
long int decays_this_cpu = number_total/mpi_size;
|
||||
int overflow = number_total%mpi_size;
|
||||
|
||||
int num_cycles = decays_this_cpu/step_size; // Must be same for all CPUs else deadlock!
|
||||
int num_remaining = decays_this_cpu%step_size;
|
||||
if (mpi_rank < overflow) { // Split overflows equaly to left over CPUs.
|
||||
num_remaining += 1;
|
||||
}
|
||||
for (int i = 0; i<(num_cycles-1); i++) {
|
||||
do_decays(simulationStepWidth);
|
||||
do_decays(step_size, logging);
|
||||
}
|
||||
if (num_cycles == 0) { // Rather unrealistic case.. maybe find a more elegant solution later.
|
||||
do_decays(num_remaining);
|
||||
do_decays(num_remaining, logging);
|
||||
} else {
|
||||
do_decays(simulationStepWidth + num_remaining);
|
||||
do_decays(step_size + num_remaining, logging);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void Simulation::do_decays(int number_decays) {
|
||||
looper.do_loops(number_decays);
|
||||
void Simulation::do_decays(const long int &number_decays, const bool &logging) {
|
||||
if (logging) {
|
||||
looper.do_loops(number_decays);
|
||||
} else {
|
||||
looper.do_logging_off_loops(number_decays);
|
||||
}
|
||||
number_local_decays += number_decays;
|
||||
sync_cpus();
|
||||
do_statusUpdate();
|
||||
|
||||
}
|
||||
|
||||
void Simulation::sync_cpus() {
|
||||
@@ -146,7 +164,6 @@ void Simulation::sync_cpus() {
|
||||
}
|
||||
|
||||
void Simulation::sync_populations() {
|
||||
|
||||
Population_Manager *populations = looper.get_populations();
|
||||
Population_Base *population;
|
||||
double *global_delta_cumulated_time_s;
|
||||
@@ -189,7 +206,7 @@ void Simulation::sync_populations() {
|
||||
|
||||
void Simulation::do_statusUpdate() {
|
||||
if (mpi_rank == 0) {
|
||||
cout<<"Status: "<<number_global_decays<<"/"<<numberTotalDecays<<endl;
|
||||
cout<<"Status: "<<number_global_decays<<"/"<<(numberTotalDecays+popCalcDecays)<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ class Simulation {
|
||||
static const long int seed;
|
||||
static const long int numberTotalDecays;
|
||||
static const long int simulationStepWidth;
|
||||
static const long int popCalcDecays;
|
||||
static const long int popCalcStep;
|
||||
|
||||
long int numberTotalParticles = 0;
|
||||
long int number_local_decays = 0;
|
||||
@@ -49,7 +51,9 @@ private:
|
||||
public:
|
||||
void doit();
|
||||
private:
|
||||
void do_decays(int number_decays);
|
||||
void do_cycle(long int number_total, long int step_size, bool logging);
|
||||
void do_decays(const long int &number_decays, const bool &logging);
|
||||
|
||||
void sync_cpus();
|
||||
void sync_populations();
|
||||
void do_statusUpdate();
|
||||
|
||||
Reference in New Issue
Block a user