From cc24fd0a99c28236736370bac1e184dcce4ffeba Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 5 Aug 2019 19:15:38 +0200 Subject: [PATCH] Fixed bug in programm. --- src/mc_electron/h5tb_population_interface.cpp | 2 +- .../h5tb_population_meta_interface.cpp | 2 +- src/mc_electron/main.cpp | 11 ++++-- src/mc_electron/makefile2 | 2 +- src/mc_electron/particle.hpp | 2 +- src/mc_electron/population_load_saver.cpp | 14 ++++---- src/mc_electron/population_load_saver.hpp | 2 +- src/mc_electron/simulation.cpp | 35 ++++++++++++------- 8 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/mc_electron/h5tb_population_interface.cpp b/src/mc_electron/h5tb_population_interface.cpp index 63c1082..fa35d96 100644 --- a/src/mc_electron/h5tb_population_interface.cpp +++ b/src/mc_electron/h5tb_population_interface.cpp @@ -53,7 +53,7 @@ const size_t H5TB_Population_Interface::sizes[7] = { void H5TB_Population_Interface::create() { herr_t state = H5TBmake_table(table_name.c_str(), *loc_id, table_name.c_str(), 7, 0, size, fieldNames, offset, fieldTypes, - chunkSize, nullptr, 0, nullptr); + chunkSize, NULL, 0, NULL); if (state < 0) { stringstream ss; ss<<"H5TB_Population_Interface::create: Error creating.\n"; diff --git a/src/mc_electron/h5tb_population_meta_interface.cpp b/src/mc_electron/h5tb_population_meta_interface.cpp index f0cbf1f..c91a4cf 100644 --- a/src/mc_electron/h5tb_population_meta_interface.cpp +++ b/src/mc_electron/h5tb_population_meta_interface.cpp @@ -75,7 +75,7 @@ const size_t H5TB_Population_Meta_Interface::sizes[12] = { void H5TB_Population_Meta_Interface::create() { herr_t state = H5TBmake_table(table_name.c_str(), *loc_id, table_name.c_str(), 12, 0, size, fieldNames, offset, fieldTypes, - chunkSize, nullptr, 0, nullptr); + chunkSize, NULL, 0, NULL); if (state < 0) { stringstream ss; ss<<"H5TB_Population_Meta_Interface::create: Error creating.\n"; diff --git a/src/mc_electron/main.cpp b/src/mc_electron/main.cpp index d18f132..0b45560 100644 --- a/src/mc_electron/main.cpp +++ b/src/mc_electron/main.cpp @@ -7,7 +7,8 @@ // #include "simulation.hpp" - +#include +#include using namespace std; @@ -20,6 +21,13 @@ int main(int argc, char *argv[]) { if (rank==0) { cout<<"Number CPUs: "< 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); - +int get_number_with_container (); std::ostream& operator<<(std::ostream& os, const species& spec); diff --git a/src/mc_electron/population_load_saver.cpp b/src/mc_electron/population_load_saver.cpp index a3783ae..66814fc 100644 --- a/src/mc_electron/population_load_saver.cpp +++ b/src/mc_electron/population_load_saver.cpp @@ -43,7 +43,8 @@ string Population_Load_Saver::get_save_path() { void Population_Load_Saver::write_overhead(ofstream *save_stream) { *save_stream<<"# File is automatically created. File contains Populations Density. To be loaded as start offset.\n"; - *save_stream<get_time_s()<<"\t # Offset Time in seconds \n"; @@ -88,18 +89,17 @@ void Population_Load_Saver::write_species(ofstream *save_stream, species this_sp *save_stream<<"end_of_species \n"; } -int Population_Load_Saver::calc_number() { - int num = 0; +int Population_Load_Saver::calc_number_pops() { + int num_species = 0; vector all_species = get_all_species_vector(); for (vector::iterator itr = all_species.begin(); itr!= all_species.end(); itr++) { if (populations->find(*itr)->access_container() != nullptr) { - num += 1 ; + num_species += 1 ; } } - return num; + return num_species; } - void Population_Load_Saver::load() { // Maybe change whole system to h5, therefore allowing sloppy style string load_path = get_enviroment_variable("pop_load_path"); @@ -115,7 +115,7 @@ void Population_Load_Saver::load() { } goto_nextline(&load_stream); //ignore first line int number_populations = get_num_populations_line(&load_stream); - if (number_populations != calc_number()) { + if (number_populations != calc_number_pops()) { stringstream ss; ss<<"Population_Load_Saver::load: Number Population missmatch.\n"; throw MyException(ss.str()); diff --git a/src/mc_electron/population_load_saver.hpp b/src/mc_electron/population_load_saver.hpp index 216e4f5..15ca889 100644 --- a/src/mc_electron/population_load_saver.hpp +++ b/src/mc_electron/population_load_saver.hpp @@ -27,7 +27,7 @@ private: std::string get_save_path(); void write_overhead(std::ofstream *save_stream); void write_species(std::ofstream *save_stream, species this_species); - int calc_number(); + int calc_number_pops(); public: void load(); diff --git a/src/mc_electron/simulation.cpp b/src/mc_electron/simulation.cpp index 505a9e1..6c7da49 100644 --- a/src/mc_electron/simulation.cpp +++ b/src/mc_electron/simulation.cpp @@ -29,26 +29,37 @@ Simulation::~Simulation() { } void Simulation::init_pop_arrays() { + Population_Manager *populations = looper.get_populations(); + + int number_pop_species = 0; vector all_species = get_all_species_vector(); - number_pop_species = all_species.size(); + for (vector::iterator itr = all_species.begin(); itr!= all_species.end(); itr++) { + if (populations->find(*itr)->access_container() != nullptr) { + number_pop_species += 1 ; + } + } pop_species = new species[number_pop_species]; pop_array_lengths = new int[number_pop_species]; global_cum_time_s = new double *[number_pop_species]; global_offset = new double *[number_pop_species]; - Population_Manager *populations = looper.get_populations(); Population_Base *population; - for (int i = 0; ifind(pop_species[i]); - - pop_array_lengths[i] = population->access_container()->data_size; - global_cum_time_s[i] = new double[pop_array_lengths[i]]; - global_offset[i] = new double[pop_array_lengths[i]]; - for (int j = 0; j::iterator itr = all_species.begin(); itr!= all_species.end(); itr++) { + if (populations->find(*itr)->access_container() != nullptr) { + pop_species[i] = *itr; + population = populations->find(*itr); + + pop_array_lengths[i] = population->access_container()->data_size; + global_cum_time_s[i] = new double[pop_array_lengths[i]]; + global_offset[i] = new double[pop_array_lengths[i]]; + for (int j = 0; j