diff --git a/src/mc_electron/h5_file.cpp b/src/mc_electron/h5_file.cpp index 0c86026..85d4d46 100644 --- a/src/mc_electron/h5_file.cpp +++ b/src/mc_electron/h5_file.cpp @@ -17,7 +17,8 @@ using namespace std; H5_File::H5_File() { create(); - h5p = H5_Particles(&h5_file); + h5part = H5_Particles(&h5_file); + h5pop = H5_Populations(&h5_file); } void H5_File::create() { diff --git a/src/mc_electron/h5_file.hpp b/src/mc_electron/h5_file.hpp index 1184e12..95d46b5 100644 --- a/src/mc_electron/h5_file.hpp +++ b/src/mc_electron/h5_file.hpp @@ -10,15 +10,17 @@ #define h5_file_hpp #include "h5_particles.h" - +#include "h5_populations.h" class H5_File { hid_t h5_file; - H5_Particles h5p; + H5_Particles h5part; + H5_Populations h5pop; public: H5_File(); - H5_Particles *get_h5p() {return(&h5p);} + H5_Particles *get_h5part() {return(&h5part);} + H5_Populations *get_h5pop() {return(&h5pop);} private: void create(); std::string getFileName(); diff --git a/src/mc_electron/h5_populations.h b/src/mc_electron/h5_populations.h new file mode 100644 index 0000000..2be33cb --- /dev/null +++ b/src/mc_electron/h5_populations.h @@ -0,0 +1,40 @@ +// +// h5_populations.h +// mc_electron +// +// Created by Christian Reiling on 28.05.19. +// Copyright © 2019 Christian Reiling. All rights reserved. +// + +#ifndef h5_populations_h +#define h5_populations_h + +#include "read_system.h" +#include +#include + +#include "hdf5.h" +#include "hdf5_hl.h" + +#include "katrin_geo.hpp" + +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/h5tb_interface.cpp b/src/mc_electron/h5tb_particle_interface.cpp similarity index 62% rename from src/mc_electron/h5tb_interface.cpp rename to src/mc_electron/h5tb_particle_interface.cpp index b05ca90..2d944bb 100644 --- a/src/mc_electron/h5tb_interface.cpp +++ b/src/mc_electron/h5tb_particle_interface.cpp @@ -1,5 +1,5 @@ // -// h5tb_interface.cpp +// h5tb_particle_interface.cpp // mc_electron // // Created by Christian Reiling on 19.05.19. @@ -7,14 +7,14 @@ // #include -#include "h5tb_interface.hpp" +#include "h5tb_particle_interface.hpp" using namespace std; logParticle samplelogParticle = {0,0,0,0,0,0,0,0}; -const size_t H5TB_Interface::size = sizeof(logParticle); -const char *H5TB_Interface::fieldNames[8] = { "Id","ParentId", "x_m", "y_m", "z_m", "vx_ms", "vy_ms", "vz_ms" }; -const size_t H5TB_Interface::offset[8] = { +const size_t H5TB_Particle_Interface::size = sizeof(logParticle); +const char *H5TB_Particle_Interface::fieldNames[8] = { "Id","ParentId", "x_m", "y_m", "z_m", "vx_ms", "vy_ms", "vz_ms" }; +const size_t H5TB_Particle_Interface::offset[8] = { HOFFSET(logParticle, Id), HOFFSET(logParticle, parentId), HOFFSET(logParticle, x_m), @@ -23,7 +23,7 @@ const size_t H5TB_Interface::offset[8] = { HOFFSET(logParticle, vx_ms), HOFFSET(logParticle, vy_ms), HOFFSET(logParticle, vz_ms)}; -const hid_t H5TB_Interface::fieldTypes[8] = { +const hid_t H5TB_Particle_Interface::fieldTypes[8] = { H5T_NATIVE_INT, H5T_NATIVE_INT, H5T_NATIVE_DOUBLE, @@ -32,8 +32,8 @@ const hid_t H5TB_Interface::fieldTypes[8] = { H5T_NATIVE_DOUBLE, H5T_NATIVE_DOUBLE, H5T_NATIVE_DOUBLE}; -const hsize_t H5TB_Interface::chunkSize = 4096; -const size_t H5TB_Interface::sizes[8] = { +const hsize_t H5TB_Particle_Interface::chunkSize = 4096; +const size_t H5TB_Particle_Interface::sizes[8] = { sizeof( samplelogParticle.Id), sizeof( samplelogParticle.parentId), sizeof( samplelogParticle.x_m), @@ -44,24 +44,24 @@ const size_t H5TB_Interface::sizes[8] = { sizeof( samplelogParticle.vz_ms)}; -void H5TB_Interface::create() { - herr_t state = H5TBmake_table(tableName.c_str(), *loc_id, tableName.c_str(), 8, 0, +void H5TB_Particle_Interface::create() { + herr_t state = H5TBmake_table(table_name.c_str(), *loc_id, table_name.c_str(), 8, 0, size, fieldNames, offset, fieldTypes, chunkSize, NULL, 0, NULL); if (state < 0) { stringstream ss; - ss<<"H5TB_Interface::create: Error creating.\n"; + ss<<"H5TB_Particle_Interface::create: Error creating.\n"; throw MyException(ss.str()); } } -void H5TB_Interface::write(const Particle &logPart) { +void H5TB_Particle_Interface::write(const Particle &logPart) { logParticle logParticle_buffer = transform(logPart); // Maybe add real buffer here.... - H5TBappend_records(*loc_id, tableName.c_str() , 1, size, offset, sizes, &logParticle_buffer ); + H5TBappend_records(*loc_id, table_name.c_str() , 1, size, offset, sizes, &logParticle_buffer ); } -loggerParticle H5TB_Interface::transform(const Particle &logPart) { +loggerParticle H5TB_Particle_Interface::transform(const Particle &logPart) { logParticle res; res.Id = logPart.get_Id(); res.parentId = logPart.get_ParentId(); diff --git a/src/mc_electron/h5tb_interface.hpp b/src/mc_electron/h5tb_particle_interface.hpp similarity index 69% rename from src/mc_electron/h5tb_interface.hpp rename to src/mc_electron/h5tb_particle_interface.hpp index a1471ee..a913077 100644 --- a/src/mc_electron/h5tb_interface.hpp +++ b/src/mc_electron/h5tb_particle_interface.hpp @@ -1,13 +1,13 @@ // -// h5tb_interface.hpp +// h5tb_particle_interface.hpp // mc_electron // // Created by Christian Reiling on 19.05.19. // Copyright © 2019 Christian Reiling. All rights reserved. // -#ifndef h5tb_interface_hpp -#define h5tb_interface_hpp +#ifndef h5tb_particle_interface_hpp +#define h5tb_particle_interface_hpp #include "hdf5.h" #include "hdf5_hl.h" @@ -26,7 +26,7 @@ typedef struct loggerParticle { } logParticle; -class H5TB_Interface { +class H5TB_Particle_Interface { static const size_t size; static const char *fieldNames[8]; static const size_t offset[8]; @@ -34,13 +34,13 @@ class H5TB_Interface { static const hsize_t chunkSize; static const size_t sizes[8]; - std::string tableName; + std::string table_name; hid_t *loc_id; public: - H5TB_Interface() {}; - H5TB_Interface(const std::string &tableName, hid_t *loc_id) { - this->tableName = tableName; + H5TB_Particle_Interface() {}; + H5TB_Particle_Interface(const std::string &table_name, hid_t *loc_id) { + this->table_name = table_name; this->loc_id = loc_id; create(); } @@ -54,4 +54,4 @@ private: }; -#endif /* h5tb_interface_hpp */ +#endif /* h5tb_particle_interface_hpp */ diff --git a/src/mc_electron/h5tb_population_interface.cpp b/src/mc_electron/h5tb_population_interface.cpp new file mode 100644 index 0000000..2bbf4ea --- /dev/null +++ b/src/mc_electron/h5tb_population_interface.cpp @@ -0,0 +1,68 @@ +// +// h5tb_population_interface.cpp +// mc_electron +// +// Created by Christian Reiling on 28.05.19. +// Copyright © 2019 Christian Reiling. All rights reserved. +// + +#include "h5tb_population_interface.hpp" + +#include + +using namespace std; + + +log_population_bin sample_log_cell = {0,0,0,0,0,0,0}; +const size_t H5TB_Population_Interface::size = sizeof(log_population_bin); +const char *H5TB_Population_Interface::fieldNames[7] = { + "n_decay", + "z_bin", + "r_bin", + "phi_bin", + "E_bin", + "cum_time", + "offset"}; +const size_t H5TB_Population_Interface::offset[7] = { + HOFFSET(log_population_bin, number_decay), + HOFFSET(log_population_bin, z_bin), + HOFFSET(log_population_bin, r_bin), + HOFFSET(log_population_bin, phi_bin), + HOFFSET(log_population_bin, E_bin), + HOFFSET(log_population_bin, cumulative_time), + HOFFSET(log_population_bin, offset)}; +const hid_t H5TB_Population_Interface::fieldTypes[7] = { + H5T_NATIVE_INT, + H5T_NATIVE_INT, + H5T_NATIVE_INT, + H5T_NATIVE_INT, + H5T_NATIVE_INT, + H5T_NATIVE_DOUBLE, + H5T_NATIVE_INT}; +const hsize_t H5TB_Population_Interface::chunkSize = 4096; +const size_t H5TB_Population_Interface::sizes[7] = { + sizeof( sample_log_cell.number_decay), + sizeof( sample_log_cell.z_bin), + sizeof( sample_log_cell.r_bin), + sizeof( sample_log_cell.phi_bin), + sizeof( sample_log_cell.E_bin), + sizeof( sample_log_cell.cumulative_time), + sizeof( sample_log_cell.offset)}; + + +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, NULL, 0, NULL); + if (state < 0) { + stringstream ss; + ss<<"H5TB_Population_Interface::create: Error creating.\n"; + throw MyException(ss.str()); + } +} + +void H5TB_Population_Interface::write(const log_population_bin &log_bin) { + H5TBappend_records(*loc_id, table_name.c_str() , 1, size, offset, sizes, &log_bin); +} + + diff --git a/src/mc_electron/h5tb_population_interface.hpp b/src/mc_electron/h5tb_population_interface.hpp new file mode 100644 index 0000000..7122d60 --- /dev/null +++ b/src/mc_electron/h5tb_population_interface.hpp @@ -0,0 +1,56 @@ +// +// h5tb_population_interface.hpp +// mc_electron +// +// Created by Christian Reiling on 28.05.19. +// Copyright © 2019 Christian Reiling. All rights reserved. +// + +#ifndef h5tb_population_interface_hpp +#define h5tb_population_interface_hpp + +#include "error_types.h" + +#include "hdf5.h" +#include "hdf5_hl.h" + + +typedef struct log_population_bin { + int number_decay; + int z_bin; + int r_bin; + int phi_bin; + int E_bin; + double cumulative_time; + int offset; +} log_population_bin; + + +class H5TB_Population_Interface { + static const size_t size; + static const char *fieldNames[7]; + static const size_t offset[7]; + static const hid_t fieldTypes[7]; + static const hsize_t chunkSize; + static const size_t sizes[7]; + + std::string table_name; + hid_t *loc_id; + +public: + H5TB_Population_Interface() {}; + H5TB_Population_Interface(const std::string &table_name, hid_t *loc_id) { + this->table_name = table_name; + this->loc_id = loc_id; + create(); + } +private: + void create(); + +public: + void write(const log_population_bin &log_bin); + +}; + + +#endif /* h5tb_population_interface_hpp */ diff --git a/src/mc_electron/h5tb_population_meta_interface.cpp b/src/mc_electron/h5tb_population_meta_interface.cpp new file mode 100644 index 0000000..f1f10ae --- /dev/null +++ b/src/mc_electron/h5tb_population_meta_interface.cpp @@ -0,0 +1,88 @@ +// +// h5tb_population_meta_interface.cpp +// mc_electron +// +// Created by Christian Reiling on 03.06.19. +// Copyright © 2019 Christian Reiling. All rights reserved. +// + +#include "h5tb_population_meta_interface.hpp" + +#include + +using namespace std; + + +log_meta_bin sample_bin = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +const size_t H5TB_Population_Meta_Interface::size = sizeof(log_meta_bin); +const char *H5TB_Population_Meta_Interface::fieldNames[12] = { + "z_bin", + "r_bin", + "phi_bin", + "E_bin", + "z_min_m", + "z_max_m", + "r_min_m", + "r_max_m", + "phi_min", + "phi_max", + "E_min_eV", + "E_max_eV"}; +const size_t H5TB_Population_Meta_Interface::offset[12] = { + HOFFSET(log_meta_bin, z_bin), + HOFFSET(log_meta_bin, r_bin), + HOFFSET(log_meta_bin, phi_bin), + HOFFSET(log_meta_bin, E_bin), + HOFFSET(log_meta_bin, z_min_m), + HOFFSET(log_meta_bin, z_max_m), + HOFFSET(log_meta_bin, r_min_m), + HOFFSET(log_meta_bin, r_max_m), + HOFFSET(log_meta_bin, phi_min), + HOFFSET(log_meta_bin, phi_max), + HOFFSET(log_meta_bin, E_min_eV), + HOFFSET(log_meta_bin, E_max_eV)}; + + +const hid_t H5TB_Population_Meta_Interface::fieldTypes[12] = { + H5T_NATIVE_INT, + H5T_NATIVE_INT, + H5T_NATIVE_INT, + H5T_NATIVE_INT, + H5T_NATIVE_DOUBLE, + H5T_NATIVE_DOUBLE, + H5T_NATIVE_DOUBLE, + H5T_NATIVE_DOUBLE, + H5T_NATIVE_DOUBLE, + H5T_NATIVE_DOUBLE, + H5T_NATIVE_DOUBLE, + H5T_NATIVE_DOUBLE}; +const hsize_t H5TB_Population_Meta_Interface::chunkSize = 4096; +const size_t H5TB_Population_Meta_Interface::sizes[12] = { + sizeof( sample_bin.z_bin), + sizeof( sample_bin.r_bin), + sizeof( sample_bin.phi_bin), + sizeof( sample_bin.E_bin), + sizeof( sample_bin.z_min_m), + sizeof( sample_bin.z_max_m), + sizeof( sample_bin.r_min_m), + sizeof( sample_bin.r_max_m), + sizeof( sample_bin.phi_min), + sizeof( sample_bin.phi_max), + sizeof( sample_bin.E_min_eV), + sizeof( sample_bin.E_max_eV)}; + + +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, NULL, 0, NULL); + if (state < 0) { + stringstream ss; + ss<<"H5TB_Population_Meta_Interface::create: Error creating.\n"; + throw MyException(ss.str()); + } +} + +void H5TB_Population_Meta_Interface::write(const log_meta_bin &log_meta) { + H5TBappend_records(*loc_id, table_name.c_str() , 1, size, offset, sizes, &log_meta); +} diff --git a/src/mc_electron/h5tb_population_meta_interface.hpp b/src/mc_electron/h5tb_population_meta_interface.hpp new file mode 100644 index 0000000..77176e8 --- /dev/null +++ b/src/mc_electron/h5tb_population_meta_interface.hpp @@ -0,0 +1,60 @@ +// +// h5tb_population_meta_interface.hpp +// mc_electron +// +// Created by Christian Reiling on 03.06.19. +// Copyright © 2019 Christian Reiling. All rights reserved. +// + +#ifndef h5tb_population_meta_interface_hpp +#define h5tb_population_meta_interface_hpp + +#include "error_types.h" + +#include "hdf5.h" +#include "hdf5_hl.h" + + +typedef struct log_meta_bin { + int z_bin; + int r_bin; + int phi_bin; + int E_bin; + double z_min_m; + double z_max_m; + double r_min_m; + double r_max_m; + double phi_min; + double phi_max; + double E_min_eV; + double E_max_eV; +} log_meta_bin; + + +class H5TB_Population_Meta_Interface { + static const size_t size; + static const char *fieldNames[12]; + static const size_t offset[12]; + static const hid_t fieldTypes[12]; + static const hsize_t chunkSize; + static const size_t sizes[12]; + + std::string table_name; + hid_t *loc_id; + +public: + H5TB_Population_Meta_Interface() {}; + H5TB_Population_Meta_Interface(const std::string &table_name, hid_t *loc_id) { + this->table_name = table_name; + this->loc_id = loc_id; + create(); + } +private: + void create(); + +public: + void write(const log_meta_bin &log_meta); + +}; + +#endif /* h5tb_population_meta_interface_hpp */ diff --git a/src/mc_electron/linScale.h b/src/mc_electron/linScale.h index af835b3..a4123d1 100644 --- a/src/mc_electron/linScale.h +++ b/src/mc_electron/linScale.h @@ -35,6 +35,11 @@ public: delta_x = (max_x - min_x)/number_bins; } + friend bool operator==(const Lin_Scale &scale1, const Lin_Scale &scale2); + + double get_min_val() {return(min_x);} + double get_max_val() {return(max_x);} + int get_max_index() {return(number_bins);} int get_dimension() {return(number_bins + 1);} @@ -61,5 +66,11 @@ public: } }; +inline bool operator==(const Lin_Scale &scale1, const Lin_Scale &scale2) { + return (scale1.min_x== scale2.min_x && + scale1.max_x== scale2.max_x && + scale1.delta_x== scale2.delta_x && + scale1.number_bins== scale2.number_bins); +} #endif /* linScale_h */ diff --git a/src/mc_electron/logger_builder.cpp b/src/mc_electron/logger_builder.cpp index 3032232..b8d1fa3 100644 --- a/src/mc_electron/logger_builder.cpp +++ b/src/mc_electron/logger_builder.cpp @@ -15,22 +15,31 @@ Particle_Logger_Manager Particle_Logger_Builder::build(H5_File *h5f) { Particle_Logger_Manager ParticleLogger; - H5_Particles *h5p = h5f->get_h5p(); + H5_Particles *h5part = h5f->get_h5part(); - ParticleLogger.add(build_eLogger(h5p)); + ParticleLogger.add(build_eLogger(h5part)); ParticleLogger.add(new Off_Particle_Logger(tritiumI)); ParticleLogger.add(new Off_Particle_Logger(tritium2I)); return (ParticleLogger); } -Particle_Logger_Base *Particle_Logger_Builder::build_eLogger(H5_Particles *h5p) { +Particle_Logger_Base *Particle_Logger_Builder::build_eLogger(H5_Particles *h5part) { Particle_Logger_Base *res; - if (h5p->get_logging() == false) { + if (h5part->get_logging() == false) { res = new Off_Particle_Logger(electron); - } else if(h5p->get_numberZBins() == -1){ - res = new SF_Particle_Logger(electron, h5p->get_h5g_z()); + } else if(h5part->get_numberZBins() == -1){ + res = new SF_Particle_Logger(electron, h5part->get_h5g_z()); } else { - res = new MuliZ_Particle_Logger(electron, h5p->get_numberZBins(), h5p->get_zValues(), h5p->get_h5g_z()); + res = new MuliZ_Particle_Logger(electron, h5part->get_numberZBins(), h5part->get_zValues(), h5part->get_h5g_z()); } return (res); } + +Population_Logger_Manager Population_Logger_Builder::build(H5_File *h5f, Population_Manager *populations) { + Population_Logger_Manager Population_Logger; + H5_Populations *h5pop = h5f->get_h5pop(); + Thermal_Base *T2I_population = dynamic_cast(populations->find(tritium2I)); + + Population_Logger.add(new Thermal_Population_Logger(T2I_population, h5pop->get_h5g_pop())); + return (Population_Logger); +} diff --git a/src/mc_electron/logger_builder.hpp b/src/mc_electron/logger_builder.hpp index 7529983..6d52d39 100644 --- a/src/mc_electron/logger_builder.hpp +++ b/src/mc_electron/logger_builder.hpp @@ -12,9 +12,10 @@ #include "h5_file.hpp" #include "manager_base.h" - #include "particle_logger_base.h" +#include "population_builder.hpp" +#include "thermal_population_logger.h" typedef Manager_Base Particle_Logger_Manager; @@ -25,7 +26,19 @@ public: static Particle_Logger_Manager build(H5_File *h5f); private: - static Particle_Logger_Base *build_eLogger(H5_Particles *h5p); + static Particle_Logger_Base *build_eLogger(H5_Particles *h5part); }; + +class Population_Logger_Builder { + +public: + Population_Logger_Builder() {}; + + static Population_Logger_Manager build(H5_File *h5f, Population_Manager *populations); +//private: + //static Population_Logger_Manager *build_Logger(H5_Particles *h5part); +}; + + #endif /* logger_builder_hpp */ diff --git a/src/mc_electron/main.cpp b/src/mc_electron/main.cpp index 0441aa3..4f00e1a 100644 --- a/src/mc_electron/main.cpp +++ b/src/mc_electron/main.cpp @@ -16,5 +16,4 @@ int main(int argc, const char * argv[]) { Simulation Sim; Sim.doit(); cout<<"Duration: "<< ( clock() - start ) / (double) CLOCKS_PER_SEC <<'\n'; - } diff --git a/src/mc_electron/makefile2 b/src/mc_electron/makefile2 index 7877cf5..dc0caf1 100644 --- a/src/mc_electron/makefile2 +++ b/src/mc_electron/makefile2 @@ -18,7 +18,8 @@ mcelectron: main.o simulation.o\ tcs_container.o dcs_container.o population3_container.o size_container.o \ thermalPop_container.o energeticPop_container.o \ particle.o injector.o timer.o katrin_geo.o katrin_fields.o \ - h5_file.o h5tb_interface.o logger_builder.o \ + h5_file.o logger_builder.o \ + h5tb_particle_interface.o h5tb_population_interface.o h5tb_population_meta_interface.o \ population_builder.o \ mover_builder.o \ interaction_builder.o BED_eT2_ionization.o uehara_eT2_elastic.o rutherford_elastic.o \ diff --git a/src/mc_electron/multiz_particle_logger.h b/src/mc_electron/multiz_particle_logger.h index 8083393..1d46717 100644 --- a/src/mc_electron/multiz_particle_logger.h +++ b/src/mc_electron/multiz_particle_logger.h @@ -13,36 +13,34 @@ class MuliZ_Particle_Logger : public Particle_Logger_Base { - H5TB_Interface *h5tb; + H5TB_Particle_Interface *h5tb; int numberZBins; double *zLogValues; - hid_t *h5g_z; public: MuliZ_Particle_Logger(species this_species, const int &numberZBins, double *zLogValues, hid_t *h5g_z) : Particle_Logger_Base(this_species) { this->numberZBins = numberZBins; this->zLogValues = zLogValues; - this->h5g_z = h5g_z; - create(); + create(h5g_z); } private: - void create(); + void create(hid_t *h5g_z); public: void log(const Particle &logPart, const vec3 &oldLoc_m); }; -inline void MuliZ_Particle_Logger::create() { +inline void MuliZ_Particle_Logger::create(hid_t *h5g_z) { std::string speciesName = get_species_string(get_species()); if (numberZBins < 1) { std::stringstream ss; ss<<"MuliZ_Particle_Logger::create: numberZBins < 1.\n"; } - h5tb = new H5TB_Interface[numberZBins]; + h5tb = new H5TB_Particle_Interface[numberZBins]; for (int i = 0; i < numberZBins; i++) { - h5tb[i] = H5TB_Interface(speciesName, &h5g_z[i]); + h5tb[i] = H5TB_Particle_Interface(speciesName, &h5g_z[i]); } } diff --git a/src/mc_electron/particle_logger_base.h b/src/mc_electron/particle_logger_base.h index e82710d..88be570 100644 --- a/src/mc_electron/particle_logger_base.h +++ b/src/mc_electron/particle_logger_base.h @@ -9,7 +9,7 @@ #ifndef particle_logger_base_h #define particle_logger_base_h -#include "h5tb_interface.hpp" +#include "h5tb_particle_interface.hpp" #include "process_base.h" class Particle_Logger_Base : public Process_Base { diff --git a/src/mc_electron/population3_container.cpp b/src/mc_electron/population3_container.cpp index 376ab1e..1d423cb 100644 --- a/src/mc_electron/population3_container.cpp +++ b/src/mc_electron/population3_container.cpp @@ -12,31 +12,70 @@ using namespace std; -Pop3_Container::~Pop3_Container() { - -}; - Pop3_Container::Pop3_Container(int num_z_bins, int num_r_bins, int num_phi_bins) { z_scale = Lin_Scale(Katrin_Geo::get_z_RW_m(), Katrin_Geo::get_z_WGTSend_m(), num_z_bins); r_scale = Lin_Scale(0,Katrin_Geo::get_radius_m(), num_r_bins); phi_scale = Lin_Scale(0, 180, num_phi_bins); + int z_dimension = z_scale.get_dimension(); + int r_dimension = r_scale.get_dimension(); + int phi_dimension = phi_scale.get_dimension(); - data = new double **[num_z_bins+1]; - for (int i = 0; i <= num_z_bins; i++) - { - data[i] = new double *[num_r_bins+1]; - for(int j = 0; j<=num_r_bins; j++) - data[i][j] = new double[num_phi_bins+1]; - } - for (int i = 0; i<=num_z_bins; i++) { - for (int j = 0; j<=num_r_bins; j++) { - for (int k = 0; k<=num_phi_bins; k++) { + data = new double **[z_dimension]; + for (int i = 0; i < z_dimension; i++) { + data[i] = new double *[r_dimension]; + for(int j = 0; j < r_dimension; j++) { + data[i][j] = new double[phi_dimension]; + for (int k = 0; k < phi_dimension; k++) { data[i][j][k] = 0; } } } } +Pop3_Container::~Pop3_Container() { + int z_dimension = z_scale.get_dimension(); + int r_dimension = r_scale.get_dimension(); + for (int i = 0; i < z_dimension; i++) { + for(int j = 0; j < r_dimension; j++) { + delete[] data[i][j]; + } + delete[] data[i]; + } + delete[] data; +}; + + +Pop3_Container::Pop3_Container(const Pop3_Container& other) { + z_scale = other.z_scale; + r_scale = other.r_scale; + phi_scale = other.phi_scale; + int z_dimension = z_scale.get_dimension(); + int r_dimension = r_scale.get_dimension(); + int phi_dimension = phi_scale.get_dimension(); + + data = new double **[z_dimension]; + for (int i = 0; i < z_dimension; i++) { + data[i] = new double *[r_dimension]; + for(int j = 0; j < r_dimension; j++) { + data[i][j] = new double[phi_dimension]; + for (int k = 0; k < phi_dimension; k++) { + data[i][j][k] = other.data[i][j][k]; + } + } + } +} + + +Pop3_Container& Pop3_Container::operator=(const Pop3_Container& other) { + Pop3_Container tmp(other); + swap(z_scale, tmp.z_scale); + swap(z_scale, tmp.z_scale); + swap(z_scale, tmp.z_scale); + swap(data, tmp.data); + return (*this); +} + + void Pop3_Container::increase_value(const double &value, const vec3 &loc_m) { int zbin = z_scale.calc_index(get_z_m(loc_m)); int rbin = r_scale.calc_index(get_r_m(loc_m)); diff --git a/src/mc_electron/population3_container.hpp b/src/mc_electron/population3_container.hpp index e38b7b9..158c799 100644 --- a/src/mc_electron/population3_container.hpp +++ b/src/mc_electron/population3_container.hpp @@ -13,6 +13,7 @@ #include "katrin_geo.hpp" #include "timer.hpp" + class Pop3_Container { double ***data; Lin_Scale z_scale; @@ -20,12 +21,22 @@ class Pop3_Container { Lin_Scale phi_scale; public: - ~Pop3_Container(); Pop3_Container(int num_z_bins, int num_r_bins, int num_phi_bins); + + ~Pop3_Container(); + Pop3_Container(const Pop3_Container& other); + Pop3_Container& operator=(const Pop3_Container& other); + void increase_value(const double &value, const vec3 &loc_m); void increase_value(const double &value, const vec3 &loc1_m, const vec3 &loc2_m); double get_value (vec3 loc_m); + + double get_value_by_bin(int z_bin, int r_bin, int phi_bin) {return (data[z_bin][r_bin][phi_bin]);} + //double ***get_data(){return(data);} + Lin_Scale get_z_scale(){return(z_scale);} + Lin_Scale get_r_scale(){return(r_scale);} + Lin_Scale get_phi_scale(){return(phi_scale);} }; diff --git a/src/mc_electron/population_base.h b/src/mc_electron/population_base.h index 2238d58..019c894 100644 --- a/src/mc_electron/population_base.h +++ b/src/mc_electron/population_base.h @@ -19,6 +19,15 @@ typedef blitz::TinyVector vec3; +typedef struct population_log_info { + double z_m; + double r_m; + double phi; + double E_eV; + double cumulative_time_s; + double offset; +} population_log_info; + class Population_Base : public Process_Base { @@ -33,7 +42,6 @@ public: virtual vec3 roll_speed_ms (const vec3 &loc_m) = 0; - }; diff --git a/src/mc_electron/population_logger_base.h b/src/mc_electron/population_logger_base.h new file mode 100644 index 0000000..bc1fba4 --- /dev/null +++ b/src/mc_electron/population_logger_base.h @@ -0,0 +1,53 @@ +// +// population_logger_base.h +// mc_electron +// +// Created by Christian Reiling on 28.05.19. +// Copyright © 2019 Christian Reiling. All rights reserved. +// + +#ifndef population_logger_base_h +#define population_logger_base_h + +#include "population_base.h" + +class Population_Logger_Base { +public: + Population_Logger_Base() {}; + virtual void log(int number_decay) = 0; +}; + + +class Population_Logger_Manager { + Population_Logger_Base **population_loggers; + int num_loggers = 0; +public: + Population_Logger_Manager() {}; + + void add(Population_Logger_Base *new_population_logger) { + if (num_loggers != 0) { + Population_Logger_Base *tempArray[num_loggers]; + for (int i = 0; i < num_loggers; i++) { + tempArray[i] = population_loggers[i]; + } + delete[] population_loggers; + population_loggers = new Population_Logger_Base *[num_loggers + 1]; + for (int i = 0; i < num_loggers; i++) { + population_loggers[i] = tempArray[i]; + } + } else { + population_loggers = new Population_Logger_Base *[num_loggers + 1]; + } + population_loggers[num_loggers] = new_population_logger; + num_loggers += 1; + } + + void log(const int &numberDecays) { + for (int i=0; ilog(numberDecays); + } + } +}; + + +#endif /* population_logger_base_h */ diff --git a/src/mc_electron/sf_particle_logger.h b/src/mc_electron/sf_particle_logger.h index 7eda802..87c3d54 100644 --- a/src/mc_electron/sf_particle_logger.h +++ b/src/mc_electron/sf_particle_logger.h @@ -13,27 +13,24 @@ class SF_Particle_Logger : public Particle_Logger_Base { - hid_t *h5g_z; - - H5TB_Interface h5tb; + H5TB_Particle_Interface h5tb; public: SF_Particle_Logger(species this_species, hid_t *h5g_z) : Particle_Logger_Base(this_species) { - this->h5g_z = h5g_z; - create(); + create(h5g_z); } private: - void create(); + void create(hid_t *h5g_z); public: void log(const Particle &logPart, const vec3 &oldLoc_m); }; -inline void SF_Particle_Logger::create() { +inline void SF_Particle_Logger::create(hid_t *h5g_z) { std::string speciesName = get_species_string(get_species()); - h5tb = H5TB_Interface(speciesName, h5g_z); + h5tb = H5TB_Particle_Interface(speciesName, h5g_z); } inline void SF_Particle_Logger::log(const Particle &logPart, const vec3 &oldLoc_m) { diff --git a/src/mc_electron/simulation.cpp b/src/mc_electron/simulation.cpp index 8b5d01e..a5687c3 100644 --- a/src/mc_electron/simulation.cpp +++ b/src/mc_electron/simulation.cpp @@ -18,14 +18,16 @@ void Simulation::init() { set_RNGs(); timer = Timer(&numberDecays); - loggers = Particle_Logger_Builder::build(&h5f); + part_loggers = Particle_Logger_Builder::build(&h5f); populations = Population_Builder::build(&timer, &rngUni, &rngNormal); injector = Injector(&rngUni, &rngNormal); - movers = Mover_Builder::build(&loggers, &populations); + 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); + set_statusUpdater(); } @@ -52,6 +54,7 @@ void Simulation::doit() { vec3 oldLoc_m; while ( (numberDecays < numberTotalDecays) || (!partQue.empty()) ) { if (partQue.empty()) { + pop_loggers.log(numberDecays); curPart = injector.injectElectron(numberTotalParticles); numberDecays++; numberTotalParticles++; @@ -84,6 +87,7 @@ void Simulation::doit() { } } } + pop_loggers.log(numberDecays); }; diff --git a/src/mc_electron/simulation.hpp b/src/mc_electron/simulation.hpp index e7879d1..5bac017 100644 --- a/src/mc_electron/simulation.hpp +++ b/src/mc_electron/simulation.hpp @@ -21,8 +21,6 @@ #include "terminator_builder.hpp" - - class Simulation { static const long int seed; static const long int numberTotalDecays; @@ -33,7 +31,7 @@ class Simulation { H5_File h5f; Timer timer; - Particle_Logger_Manager loggers; + Particle_Logger_Manager part_loggers; Population_Manager populations; @@ -42,6 +40,7 @@ class Simulation { Interaction_Manager interactions; Terminator_Manager terminators; + Population_Logger_Manager pop_loggers; int numberTotalParticles = 0; int numberDecays = 0; diff --git a/src/mc_electron/thermal_base.h b/src/mc_electron/thermal_base.h index 63a4a99..8ba8c7a 100644 --- a/src/mc_electron/thermal_base.h +++ b/src/mc_electron/thermal_base.h @@ -19,7 +19,7 @@ class Thermal_Base : public Population_Base, protected RNG_Base{ Pop3_Container cumulated_times_s; - Pop3_Container numbers_annhilated; + Pop3_Container number_annhilated; Size_Container bin_sizes; Timer *timer; @@ -29,7 +29,7 @@ public: Thermal_Base(species this_species, Timer *timer, UniRNG *rngUni, NormalRNG *rngNormal, int num_z_bins, int num_r_bins, int num_phi_bins) : Population_Base(this_species), RNG_Base(rngUni, rngNormal), cumulated_times_s(num_z_bins, num_r_bins, num_phi_bins), - numbers_annhilated(num_z_bins, num_r_bins, num_phi_bins), + number_annhilated(num_z_bins, num_r_bins, num_phi_bins), bin_sizes(num_z_bins, num_r_bins, num_phi_bins) { this->timer = timer; }; @@ -41,13 +41,16 @@ public: virtual vec3 get_average_speed_ms (const vec3 &loc_m) = 0; virtual vec3 roll_speed_ms (const vec3 &loc_m) = 0; + Pop3_Container get_cumulated_time_container () const {return(cumulated_times_s);} + Pop3_Container get_number_annhilated_container () const {return(number_annhilated);} + }; inline double Thermal_Base::get_density_m3(const vec3 &loc_m) { //Katrin_Geo::check_inKatrin(loc_m); double physical_time_s = timer->get_physTime_s(); double cumulative_time_s = cumulated_times_s.get_value(loc_m); - double offset = numbers_annhilated.get_value(loc_m); + double offset = number_annhilated.get_value(loc_m); double bin_size_m3 = bin_sizes.get_cell_volume_m3(loc_m); double dens_m3 = cumulative_time_s/physical_time_s/bin_size_m3 - offset; dens_m3 = (dens_m3 < 0) ? zero : dens_m3; @@ -60,7 +63,7 @@ inline void Thermal_Base::increase_density(const Particle &upPart, const vec3 &o } inline void Thermal_Base::decrease_denisty (const vec3 &loc_m) { - numbers_annhilated.increase_value(1, loc_m); + number_annhilated.increase_value(1, loc_m); } diff --git a/src/mc_electron/thermal_population_logger.h b/src/mc_electron/thermal_population_logger.h new file mode 100644 index 0000000..93ffb79 --- /dev/null +++ b/src/mc_electron/thermal_population_logger.h @@ -0,0 +1,129 @@ +// +// thermal_population_logger.h +// mc_electron +// +// Created by Christian Reiling on 28.05.19. +// Copyright © 2019 Christian Reiling. All rights reserved. +// + +#ifndef thermal_population_logger_h +#define thermal_population_logger_h + +#include "population_logger_base.h" +#include "thermal_base.h" +#include "h5tb_population_interface.hpp" +#include "h5tb_population_meta_interface.hpp" + + +class Thermal_Population_Logger : public Population_Logger_Base { + H5TB_Population_Interface h5tb; + H5TB_Population_Meta_Interface h5tb_meta; + + Thermal_Base *thermal_pop; + Lin_Scale z_scale; + Lin_Scale r_scale; + Lin_Scale phi_scale; + + +public: + Thermal_Population_Logger(Thermal_Base *thermal_pop, hid_t *h5g) : Population_Logger_Base() { + this->thermal_pop = thermal_pop; + create_scales(); + create_h5tb(h5g); + create_h5tb_meta(h5g); + }; +private: + void create_scales(); + void create_h5tb(hid_t *h5g); + void create_h5tb_meta(hid_t *h5g); + void log(int number_decay); +}; + +inline void Thermal_Population_Logger::create_scales() { + Pop3_Container cum_time = thermal_pop->get_cumulated_time_container(); + Pop3_Container anhilated = thermal_pop->get_number_annhilated_container(); + if (cum_time.get_z_scale() == anhilated.get_z_scale()) { + z_scale = cum_time.get_z_scale(); + } else { + std::stringstream ss; + ss<<"Thermal_Population_Logger::create_scales: Missmatch in scales.\n"; + throw MyException(ss.str()); + } + if (cum_time.get_r_scale() == anhilated.get_r_scale()) { + r_scale = cum_time.get_r_scale(); + } else { + std::stringstream ss; + ss<<"Thermal_Population_Logger::create_scales: Missmatch in scales.\n"; + throw MyException(ss.str()); + } + if (cum_time.get_phi_scale() == anhilated.get_phi_scale()) { + phi_scale = cum_time.get_phi_scale(); + } else { + std::stringstream ss; + ss<<"Thermal_Population_Logger::create_scales: Missmatch in scales.\n"; + throw MyException(ss.str()); + } +} + +inline void Thermal_Population_Logger::create_h5tb(hid_t *h5g) { + species Species = thermal_pop->get_species(); + std::string species_string = get_species_string(Species); + h5tb = H5TB_Population_Interface(species_string, h5g); + log(0); +} + +inline void Thermal_Population_Logger::create_h5tb_meta(hid_t *h5g) { + species Species = thermal_pop->get_species(); + std::string species_string = get_species_string(Species); + std::stringstream ss; + ss<get_cumulated_time_container(); + Pop3_Container anhilated = thermal_pop->get_number_annhilated_container(); + pop_bin.number_decay = number_decay; + pop_bin.E_bin = -1; + for (int i_z=0; i_z