From 5965e3e90a833ef4c5d5be329fbc1243c41085f0 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 22 Jul 2019 10:40:21 +0200 Subject: [PATCH] Reworked logging model: Added T+, T3+. Changes in logging hierarchie: Every species individually logs positions. --- src/mc_electron/h5_file.cpp | 10 +- src/mc_electron/h5_file.hpp | 19 ++-- src/mc_electron/h5_particles.h | 120 ----------------------- src/mc_electron/h5_populations.h | 40 -------- src/mc_electron/logger_builder.cpp | 60 +++++++----- src/mc_electron/logger_builder.hpp | 12 +-- src/mc_electron/main.cpp | 59 +---------- src/mc_electron/multiz_particle_logger.h | 20 ++-- src/mc_electron/population_logger_base.h | 29 ++++-- src/mc_electron/sf_particle_logger.h | 18 ++-- 10 files changed, 105 insertions(+), 282 deletions(-) delete mode 100644 src/mc_electron/h5_particles.h delete mode 100644 src/mc_electron/h5_populations.h diff --git a/src/mc_electron/h5_file.cpp b/src/mc_electron/h5_file.cpp index 3d9a06d..2754093 100644 --- a/src/mc_electron/h5_file.cpp +++ b/src/mc_electron/h5_file.cpp @@ -15,15 +15,15 @@ using namespace std; -H5_File::H5_File(std::string name_extension) { - create(name_extension); - h5part = H5_Particles(&h5_file); - h5pop = H5_Populations(&h5_file); +H5_File::H5_File(std::string output_path) { + create(output_path); } void H5_File::create(std::string output_path) { //const string constH5Name = get_file_name(); - h5_file = H5Fcreate(output_path.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT); + h5f = H5Fcreate(output_path.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT); + h5g_particles = H5Gcreate(h5f, h5g_particles_path.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + h5g_populations = H5Gcreate(h5f, h5g_populations_path.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); } /* diff --git a/src/mc_electron/h5_file.hpp b/src/mc_electron/h5_file.hpp index 3b3803e..a64bb4a 100644 --- a/src/mc_electron/h5_file.hpp +++ b/src/mc_electron/h5_file.hpp @@ -9,19 +9,24 @@ #ifndef h5_file_hpp #define h5_file_hpp -#include "h5_particles.h" -#include "h5_populations.h" +#include "hdf5.h" +#include "hdf5_hl.h" +#include class H5_File { - hid_t h5_file; - H5_Particles h5part; - H5_Populations h5pop; + hid_t h5f; + hid_t h5g_particles; + hid_t h5g_populations; + + std::string h5g_particles_path = "/Particles"; + std::string h5g_populations_path = "/Populations"; public: H5_File() {}; H5_File(std::string output_path); - H5_Particles *get_h5part() {return &h5part;} - H5_Populations *get_h5pop() {return &h5pop;} + hid_t *get_h5f() {return &h5f} + std::string get_h5g_particles_path() {return h5g_particles_path;} + std::string get_h5g_populations_path() {return h5g_populations_path;} private: void create(std::string output_path); //std::string get_file_name(); diff --git a/src/mc_electron/h5_particles.h b/src/mc_electron/h5_particles.h deleted file mode 100644 index 9aa09b1..0000000 --- a/src/mc_electron/h5_particles.h +++ /dev/null @@ -1,120 +0,0 @@ -// -// h5_particles.h -// mc_electron -// -// Created by Christian Reiling on 18.05.19. -// Copyright © 2019 Christian Reiling. All rights reserved. -// - -#ifndef h5_particles_h -#define h5_particles_h - -#include "read_system.h" -#include -#include - -#include "hdf5.h" -#include "hdf5_hl.h" - -#include "katrin_geo.h" - -class H5_Particles { - int numberZBins; - bool logging; - double *zValues; - - - hid_t *h5_file; - hid_t *h5g_particles; - hid_t *h5g_z; - -public: - H5_Particles() {}; - H5_Particles(hid_t *h5_file); - - int get_numberZBins() {return numberZBins;} - bool get_logging() {return logging;} - double *get_zValues() {return zValues;} - hid_t *get_h5g_z() {return h5g_z;} - - -private: - void set_logging(); - void set_zValues(); - void print_logInfo(); - - void create_h5gs(); -}; - -inline H5_Particles::H5_Particles(hid_t *h5_file) { - this->h5_file = h5_file; - numberZBins = load_parameter("numberZBins"); - set_logging(); - set_zValues(); - //print_logInfo(); - - create_h5gs(); -} - - -inline void H5_Particles::set_logging() { - if (numberZBins == 0) { - logging = false; - } else if (numberZBins == -1 || numberZBins > 0){ - logging = true; - } else { - std::stringstream ss; - ss<<"H5_Logger::Parameter numberZBins invalid value.\nnumberZBins:\t"< -#include - -#include "hdf5.h" -#include "hdf5_hl.h" - -#include "katrin_geo.h" - -class H5_Populations { - hid_t *h5_file; - hid_t *h5g_populations; - -public: - H5_Populations() {}; - H5_Populations(hid_t *h5_file); - - hid_t *get_h5g_pop() {return h5g_populations;} - -}; - -inline H5_Populations::H5_Populations(hid_t *h5_file) { - this->h5_file = h5_file; - h5g_populations = new hid_t; - *h5g_populations = H5Gcreate(*h5_file, "/Populations", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); -} - - -#endif /* h5_populations_h */ diff --git a/src/mc_electron/logger_builder.cpp b/src/mc_electron/logger_builder.cpp index a4bafa0..17a0715 100644 --- a/src/mc_electron/logger_builder.cpp +++ b/src/mc_electron/logger_builder.cpp @@ -14,41 +14,53 @@ #include "population_logger_base.h" +const int Particle_Logger_Builder::logging = load_parameter("logging"); +const int Particle_Logger_Builder::numberZBins = load_parameter("numberZBins"); Particle_Logger_Manager Particle_Logger_Builder::build(H5_File *h5f) { Particle_Logger_Manager ParticleLogger; - H5_Particles *h5part = h5f->get_h5part(); - double z_rw = z_RW_m; - ParticleLogger.add(build_eLogger(h5part)); ParticleLogger.add(new Off_Particle_Logger(tritium)); - ParticleLogger.add (new MultiZ_Particle_Logger(tritiumI, 1, &z_rw, h5part->get_h5g_z())); - ParticleLogger.add (new MultiZ_Particle_Logger(tritium2I, 1, &z_rw, h5part->get_h5g_z())); - ParticleLogger.add (new MultiZ_Particle_Logger(tritium3I, 1, &z_rw, h5part->get_h5g_z())); - - /* - ParticleLogger.add(new Off_Particle_Logger(tritiumI)); - ParticleLogger.add(new Off_Particle_Logger(tritium2I)); - ParticleLogger.add(new Off_Particle_Logger(tritium3I)); - */ + + if (logging == 0) { + ParticleLogger.add(new Off_Particle_Logger(electron)); + ParticleLogger.add(new Off_Particle_Logger(tritiumI)); + ParticleLogger.add(new Off_Particle_Logger(tritium2I)); + ParticleLogger.add(new Off_Particle_Logger(tritium3I)); + } else if(numberZBins == -1){ + ParticleLogger.add(new SF_Particle_Logger(electron, h5f)); + ParticleLogger.add(new SF_Particle_Logger(tritiumI, h5f)); + ParticleLogger.add(new SF_Particle_Logger(tritium2I, h5f)); + ParticleLogger.add(new SF_Particle_Logger(tritium3I, h5f)); + } else { + build_MultiZ(&ParticleLogger, h5f); + } return ParticleLogger; } -Particle_Logger_Base *Particle_Logger_Builder::build_eLogger(H5_Particles *h5part) { - Particle_Logger_Base *res; - if (h5part->get_logging() == false) { - res = new Off_Particle_Logger(electron); - } else if(h5part->get_numberZBins() == -1){ - res = new SF_Particle_Logger(electron, h5part->get_h5g_z()); - } else { - res = new MultiZ_Particle_Logger(electron, h5part->get_numberZBins(), h5part->get_zValues(), h5part->get_h5g_z()); +void Population_Logger_Builder::build_MultiZ(Particle_Logger_Manager *ParticleLogger, H5_File *h5f) { + double *zValues = new double[numberZBins]; + double start_m = z_RW_m; + double length_m = z_WGTS_end_m - start_m; + double stepLength_m = length_m/(numberZBins-1); + + double z_m; + for (int i = 0;iadd(new MultiZ_Particle_Logger(electron, h5f, numberZBins, zValues)); + ParticleLogger->add(new MultiZ_Particle_Logger(tritiumI, h5f, numberZBins, zValues)); + ParticleLogger->add(new MultiZ_Particle_Logger(tritium2I, h5f, numberZBins, zValues)); + ParticleLogger->add(new MultiZ_Particle_Logger(tritium3I, h5f, numberZBins, zValues)); + + delete[] zValues; } + Population_Logger_Manager Population_Logger_Builder::build(H5_File *h5f, Population_Manager *populations, Timer *timer) { Population_Logger_Manager Population_Loggers; - hid_t *h5pop = h5f->get_h5pop()->get_h5g_pop(); - Population_Base *T2I_population = populations->find(tritium2I); - Population_Loggers.add (new Population_Logger(T2I_population, timer, h5pop)); + Population_Loggers.add (new Population_Logger(populations->find(tritiumI), timer, h5f)); + Population_Loggers.add (new Population_Logger(populations->find(tritium2I), timer, h5f)); + Population_Loggers.add (new Population_Logger(populations->find(tritium3I), timer, h5f)); return Population_Loggers; } diff --git a/src/mc_electron/logger_builder.hpp b/src/mc_electron/logger_builder.hpp index 8b86ba1..5a13144 100644 --- a/src/mc_electron/logger_builder.hpp +++ b/src/mc_electron/logger_builder.hpp @@ -19,24 +19,22 @@ typedef Manager_Base Particle_Logger_Manager; -class Particle_Logger_Builder { +class Particle_Logger_Builder { + static const int logging; + static const int numberZBins; public: Particle_Logger_Builder() {}; - static Particle_Logger_Manager build(H5_File *h5f); -private: - static Particle_Logger_Base *build_eLogger(H5_Particles *h5part); + static void build_MultiZ(Particle_Logger_Manager *ParticleLogger, H5_File *h5f); }; class Population_Logger_Builder { public: Population_Logger_Builder() {}; - static Population_Logger_Manager build(H5_File *h5f, Population_Manager *populations, Timer *timer); -//private: - //static Population_Logger_Manager *build_Logger(H5_Particles *h5part); + }; diff --git a/src/mc_electron/main.cpp b/src/mc_electron/main.cpp index 1e6b349..ee5de5e 100644 --- a/src/mc_electron/main.cpp +++ b/src/mc_electron/main.cpp @@ -17,7 +17,9 @@ int main(int argc, char *argv[]) { int size, rank; MPI_Comm_size(MPI_COMM_WORLD,&size); MPI_Comm_rank(MPI_COMM_WORLD,&rank); - std::cout <<"CPU " <numberZBins = numberZBins; this->zLogValues = new double[numberZBins]; for (int i = 0; izLogValues[i] = zLogValues[i]; } - create(h5g_z); + create(h5_file, this_species); } ~MultiZ_Particle_Logger() { delete[] zLogValues; } private: - void create(hid_t *h5g_z); + void create(H5_File *h5_file, species this_species); public: void log(const Particle &logPart, const vec3 &oldLoc_m); }; -inline void MultiZ_Particle_Logger::create(hid_t *h5g_z) { - std::string speciesName = get_species_string(get_species()); +inline void MultiZ_Particle_Logger::create(H5_File *h5_file, species this_species) { + std::stringstream ss; + ss<get_h5g_particles_path()<<"/"<get_h5f(), ss.str().c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (numberZBins < 1) { std::stringstream ss; ss<<"MultiZ_Particle_Logger::create: numberZBins < 1.\n"; } + h5tb = new H5TB_Particle_Interface[numberZBins]; + std::string table_name; for (int i = 0; i < numberZBins; i++) { - h5tb[i] = H5TB_Particle_Interface(speciesName, &h5g_z[i]); + table_name = std::to_string(zLogValues[i]); + h5tb[i] = H5TB_Particle_Interface(table_name.c_str(), &h5g_species); } } diff --git a/src/mc_electron/population_logger_base.h b/src/mc_electron/population_logger_base.h index d03f8eb..a169b80 100644 --- a/src/mc_electron/population_logger_base.h +++ b/src/mc_electron/population_logger_base.h @@ -21,12 +21,15 @@ class Population_Logger { H5TB_Population_Interface h5tb; H5TB_Population_Meta_Interface h5tb_meta; + hid_t h5g_species; + public: - Population_Logger(Population_Base *pop, Timer *timer, hid_t *h5g); + Population_Logger(Population_Base *pop, Timer *timer, H5_File *h5f); private: - void create_h5tb_meta(hid_t *h5g); - void create_h5tb(hid_t *h5g); + void create_h5g_species(H5_File *h5_file); + void create_h5tb_meta(); + void create_h5tb(); public: void log(); @@ -34,26 +37,32 @@ private: pop_log_bin transform(pop_bin_content pop_bin); }; -inline Population_Logger::Population_Logger(Population_Base *pop, Timer *timer, hid_t *h5g) { +inline Population_Logger::Population_Logger(Population_Base *pop, Timer *timer, H5_File *h5_file) { this->pop = pop; this->timer = timer; - create_h5tb_meta(h5g); - create_h5tb(h5g); + create_h5g_species(h5_file); + create_h5tb_meta(); + create_h5tb(); }; -inline void Population_Logger::create_h5tb_meta(hid_t *h5g) { +inline void Population_Logger::create_h5g_species(H5_File *h5_file) { + std::string group_name = get_species_string(pop->get_species()); + h5g_species = H5Gcreate(*h5_file->get_h5f(), group_name.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); +} + +inline void Population_Logger::create_h5tb_meta() { std::stringstream ss; ss<get_species())<<"_meta_data"; - h5tb_meta = H5TB_Population_Meta_Interface(ss.str(), h5g); + h5tb_meta = H5TB_Population_Meta_Interface(ss.str(), &h5g_species); meta_vec bins_meta_info = pop->get_bins_meta_info(); for (meta_vec::iterator itr = bins_meta_info.begin(); itr != bins_meta_info.end(); itr++) { h5tb_meta.write(*itr); } } -inline void Population_Logger::create_h5tb(hid_t *h5g) { +inline void Population_Logger::create_h5tb() { std::string species_string = get_species_string(pop->get_species()); - h5tb = H5TB_Population_Interface(species_string, h5g); + h5tb = H5TB_Population_Interface(species_string, &h5g_species); } inline void Population_Logger::log() { diff --git a/src/mc_electron/sf_particle_logger.h b/src/mc_electron/sf_particle_logger.h index 87c3d54..266230a 100644 --- a/src/mc_electron/sf_particle_logger.h +++ b/src/mc_electron/sf_particle_logger.h @@ -10,27 +10,31 @@ #define sf_particle_logger_h #include "particle_logger_base.h" +#include "h5_file.hpp" class SF_Particle_Logger : public Particle_Logger_Base { + hid_t h5g_species; H5TB_Particle_Interface h5tb; + public: - SF_Particle_Logger(species this_species, hid_t *h5g_z) : Particle_Logger_Base(this_species) { - create(h5g_z); + SF_Particle_Logger(species this_species, H5_File *h5_file) : Particle_Logger_Base(this_species) { + create(h5_file, this_species); } private: - void create(hid_t *h5g_z); - + void create(H5_File *h5_file, species this_species); public: void log(const Particle &logPart, const vec3 &oldLoc_m); }; -inline void SF_Particle_Logger::create(hid_t *h5g_z) { - std::string speciesName = get_species_string(get_species()); - h5tb = H5TB_Particle_Interface(speciesName, h5g_z); +inline void SF_Particle_Logger::create(H5_File *h5_file, species this_species) { + std::stringstream ss; + ss<get_h5g_particles_path()<<"/"<get_h5f(), ss.str().c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + h5tb = H5TB_Particle_Interface("all", &h5g_species); } inline void SF_Particle_Logger::log(const Particle &logPart, const vec3 &oldLoc_m) {