Added buffer for HDF5 output.

Added E-Field container.
This commit is contained in:
Christian
2019-09-03 16:35:55 +02:00
parent 794bfb2b98
commit 1978039630
15 changed files with 1000185 additions and 69 deletions
@@ -49,8 +49,7 @@ Therefore $\upbeta$-electrons are injected by $\upbeta$-decay and then simulated
\section*{Simulation Algorithm}
\begin{figure}[tbp]
\centering
\includestandalone[width=0.8\textwidth]{single_core}% without .tex extension
% or use \input{mytikz}
\includestandalone[width=0.8\textwidth]{single_core}
\caption{Flowchart of the Simulation Algorithm. The left part of the chart shows the processing of the current particle (CP).}
\label{fig:flowchart}
\end{figure}
@@ -90,9 +89,8 @@ Secondary particles have much lower energies and usually thermalize. Therefore t
\section*{Parallelization Strategy}
\begin{figure}[tb]
\centering
\includestandalone[width=0.8\textwidth]{parallel}% without .tex extension
% or use \input{mytikz}
\caption{Flowchart of the Parallelization strategy.}
\includestandalone[width=0.8\textwidth]{parallel}
\caption{Flowchart of parallelization strategy.}
\label{fig:parallel}
\end{figure}
@@ -105,52 +103,4 @@ Averaging after fix number of $\upbeta$-decays can slow down the simulation if t
The IO-strategy is rather simple as output is written to HDF5 files per core and the files are merged in the postprocessing.
\begin{comment}
\newpage
\section*{Simulation Strategy}
The Windowless Gaseous Tritium Source (WGTS) of the KATRIN experiment is implemented as \SI{16}{\meter} long tube with \SI{90}{\milli \meter} diameter. The molecular tritium $\mathrm{T}_2$ density profile and velocity distribution are implemented as constants in time as variations are neglible. For each relevant particle species a numeric density field is implemented for which the WGTS is sliced into cells.
The initial densities are set to zero and calulated within the simulation as discussed in the next subsections.
The final electron energy distribution can be extracted from the density field at the end of the simulation. For more precise resolution "logging barriers" are implemented where passing electrons are logged with their exact energy. These passing electron can be calculated to a high precision electron energy distrubtion.
\subsection*{Parallelization strategy}
Plain Monte Carlo simulations can be operated without communicating between the cores by combining the output in the postprocessing.
For this simulation it is important to synchronize the density fields across all cores. Therefore the density fields are averaged over all cores using standard MPI\_ALLGATHER average operations after a given number of $\upbeta$-decays.
As scaling effects are still being investigated a shift to a more efficient strategy might be required.
Averaging after fix number of $\upbeta$-decays can slow down the simulation if the duration on the cores varies largly. A sufficient strategy can be averaging after fixed simulation time.
The IO-strategy is rather simple as output is written to HDF5 files per core and the files are merged in the postprocessing.
\subsection*{Single core strategy}
In order to properly process secondary particles a "particle queue" is implemented where particles are held.
If the "particle queue" is not empty the first particle of the queue is being processed.
During processing further new particles can be created. Details on the Single particle processing will be discussed in the subsequent subsection.
When the particle queue is empty new primary $\upbeta$-electrons are injecting using standard Monte Carlo simulation methods.
The location is sampled from the $\mathrm{T}_2$ density profile and the energy from the $\upbeta$-decay energy distribution.
The process of either processing the first particle or injecting a new $\upbeta$-electron is repeated until the target number of $\upbeta$-decays is met.
After processing each particle the particle densities are being logged to the outputfile for anayslis purposes.
\subsection*{Single particle processing}
Each particles is simulated until leaving the WGTS, disintegration through physical processes or when reaching thermal equilibrium with the tritium molecules.
Processing starts with propagation by one free mean path length (MFP).
The MFP is calculated from the interaction probabilty with relevant interaction partners at the inital position. The particle is then moved using Drift Approximation or Boris Push depending on user preference. Drift Approximation is more cost efficient but does not resolve the electric and magnetic fields as good as Boris Push.
During propagation the numeric density field is updated.
For electrons it is checked whether a "logging barrier" is crossed and if so the electron's properties are being logged to the output file.
After propagation the particle interacts.
Therefore interaction partner and process is rolled at the final position.
The rolled interaction is then performed using standard Monte Carlo methods and changing the properties of the initial particle.
Particles created by the interaction are appended to the "particle queue" and if interaction partners are annhilated the corresponding density field is being updated.
If the current particle is not annhilated in the process or another terminalization condition is met the particle reruns the loop of moving and interacting again and so forth.
Primary $\upbeta$-electrons usually loop $\mathcal{O}(10^2)$ times though the loop.
Secondary particles have much lower energies and usually thermalize. Therefore they loop $\mathcal{O}(10^6)$ times.
\end{comment}
\end{document}
File diff suppressed because it is too large Load Diff
+10 -4
View File
@@ -32,7 +32,7 @@ const hid_t H5TB_Particle_Interface::fieldTypes[8] = {
H5T_NATIVE_DOUBLE,
H5T_NATIVE_DOUBLE,
H5T_NATIVE_DOUBLE};
const hsize_t H5TB_Particle_Interface::chunkSize = 4096;
const hsize_t H5TB_Particle_Interface::chunkSize = 145;
const size_t H5TB_Particle_Interface::sizes[8] = {
sizeof( samplelogParticle.Id),
sizeof( samplelogParticle.parentId),
@@ -56,9 +56,15 @@ void H5TB_Particle_Interface::create() {
}
void H5TB_Particle_Interface::write(const Particle &logPart) {
logParticle logParticle_buffer = transform(logPart);
// Maybe add real buffer here....
H5TBappend_records(*loc_id, table_name.c_str() , 1, size, offset, sizes, &logParticle_buffer );
buffer[buffer_count] = transform(logPart);
buffer_count = buffer_count + 1;
if (buffer_count == buffer_size) {
H5TBappend_records(*loc_id, table_name.c_str() , buffer_size, size, offset, sizes, &buffer);
buffer_count = 0;
}
}
H5TB_Particle_Interface::~H5TB_Particle_Interface() {
H5TBappend_records(*loc_id, table_name.c_str() , buffer_count, size, offset, sizes, &buffer);
}
loggerParticle H5TB_Particle_Interface::transform(const Particle &logPart) {
@@ -34,11 +34,16 @@ class H5TB_Particle_Interface {
static const hsize_t chunkSize;
static const size_t sizes[8];
int buffer_size = 145;
loggerParticle buffer[145];
int buffer_count = 0;
std::string table_name;
hid_t *loc_id;
public:
H5TB_Particle_Interface() {};
~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;
+10 -3
View File
@@ -39,7 +39,7 @@ const hid_t H5TB_Population_Interface::fieldTypes[7] = {
H5T_NATIVE_INT,
H5T_NATIVE_DOUBLE,
H5T_NATIVE_INT};
const hsize_t H5TB_Population_Interface::chunkSize = 4096;
const hsize_t H5TB_Population_Interface::chunkSize = 225;
const size_t H5TB_Population_Interface::sizes[7] = {
sizeof( sample_log_cell.phys_time_s),
sizeof( sample_log_cell.z_bin),
@@ -62,7 +62,14 @@ void H5TB_Population_Interface::create() {
}
void H5TB_Population_Interface::write(const pop_bin &log_bin) {
H5TBappend_records(*loc_id, table_name.c_str() , 1, size, offset, sizes, &log_bin);
buffer[buffer_count] = log_bin;
buffer_count = buffer_count + 1;
if (buffer_count == buffer_size) {
H5TBappend_records(*loc_id, table_name.c_str() , buffer_size, size, offset, sizes, &buffer);
buffer_count = 0;
}
}
H5TB_Population_Interface::~H5TB_Population_Interface() {
H5TBappend_records(*loc_id, table_name.c_str() , buffer_count, size, offset, sizes, &buffer);
}
@@ -35,11 +35,16 @@ class H5TB_Population_Interface {
static const hsize_t chunkSize;
static const size_t sizes[7];
int buffer_size = 225;
pop_bin buffer[225];
int buffer_count = 0;
std::string table_name;
hid_t *loc_id;
public:
H5TB_Population_Interface() {};
~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;
@@ -56,7 +56,7 @@ const hid_t H5TB_Population_Meta_Interface::fieldTypes[12] = {
H5T_NATIVE_DOUBLE,
H5T_NATIVE_DOUBLE,
H5T_NATIVE_DOUBLE};
const hsize_t H5TB_Population_Meta_Interface::chunkSize = 4096;
const hsize_t H5TB_Population_Meta_Interface::chunkSize = 100;
const size_t H5TB_Population_Meta_Interface::sizes[12] = {
sizeof( sample_bin.z_bin),
sizeof( sample_bin.r_bin),
@@ -84,5 +84,14 @@ void H5TB_Population_Meta_Interface::create() {
}
void H5TB_Population_Meta_Interface::write(const pop_bin_meta_info &log_meta_bin) {
H5TBappend_records(*loc_id, table_name.c_str() , 1, size, offset, sizes, &log_meta_bin);
buffer[buffer_count] = log_meta_bin;
buffer_count = buffer_count + 1;
if (buffer_count == buffer_size) {
H5TBappend_records(*loc_id, table_name.c_str() , buffer_size, size, offset, sizes, &buffer);
buffer_count = 0;
}
}
H5TB_Population_Meta_Interface::~H5TB_Population_Meta_Interface() {
H5TBappend_records(*loc_id, table_name.c_str() , buffer_count, size, offset, sizes, &buffer);
}
@@ -42,11 +42,16 @@ class H5TB_Population_Meta_Interface {
static const hsize_t chunkSize;
static const size_t sizes[12];
int buffer_size = 100;
pop_bin_meta_info buffer[100];
int buffer_count = 0;
std::string table_name;
hid_t *loc_id;
public:
H5TB_Population_Meta_Interface() {};
~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;
+1
View File
@@ -12,3 +12,4 @@
const double Katrin_Fields::wgtsMagField_T = load_parameter("wgtsMagField_T");
Vec3_Container Katrin_Fields::e_field(1000, 50, 20, get_data_path() + "e_field.dat");
+6 -1
View File
@@ -11,10 +11,13 @@
#include "error_types.h"
#include "katrin_geo.h"
#include "read_system.h"
#include "vec3_container.hpp"
class Katrin_Fields {
static const double wgtsMagField_T;
static Vec3_Container e_field;
public:
Katrin_Fields() {};
@@ -27,13 +30,15 @@ public:
}
return vec3(0,0,wgtsMagField_T);
}
static vec3 getElField_Vm(vec3 loc_m) {
if (!in_Katrin(loc_m)) {
std::stringstream ss;
ss<<"Katrin_Fields::getElField_Vm: loc_m outside of Katrin.\n";
throw MyException(ss.str());
}
return vec3(0,0,0);
return e_field.get_data (loc_m);
//return vec3(0,0,0);
}
};
+1 -1
View File
@@ -2,7 +2,7 @@ include $(HOMEBASE)/src/makeinclude/include.mak
OBJS := particle_looper.o \
tcs_container.o dcs_theta_container.o dcs_ionization_container.o \
population_container.o velocity_container.o \
population_container.o velocity_container.o vec3_container.o \
thermalPop_container.o energeticPop_container.o \
particle.o injector.o timer.o katrin_fields.o \
h5_file.o logger_builder.o population_load_saver.o \
+1 -5
View File
@@ -19,11 +19,7 @@ struct Bins {
int r;
int phi;
inline bool operator==(Bins other) {
if (z == other.z && r == other.r && phi == other.phi) {
return true;
} else {
return false;
}
return z == other.z && r == other.r && phi == other.phi;
}
};
+89
View File
@@ -0,0 +1,89 @@
//
// vec3_container.cpp
// mc_electron
//
// Created by Christian Reiling on 02.09.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#include "vec3_container.hpp"
#include "read_system.h"
Vec3_Container::Vec3_Container(int num_z_bins, int num_r_bins, int num_phi_bins, std::string load_path) {
z_scale = Lin_Scale(z_WGTS_start_m, z_WGTS_end_m, num_z_bins);
r_scale = Lin_Scale(0, r_WGTS_m, num_r_bins);
phi_scale = Lin_Scale(0, 180, num_phi_bins);
int num_tot_bins = num_z_bins * num_r_bins * num_phi_bins;
data = new vec3[num_tot_bins];
load_data(load_path);
}
Vec3_Container::~Vec3_Container() {
delete[] data;
}
void Vec3_Container::load_data(std::string load_path) {
int num_tot_bins = z_scale.get_number_bins() * r_scale.get_number_bins() * phi_scale.get_number_bins();
bool *check_array = new bool[num_tot_bins];
for (int i = 0; i< num_tot_bins; i++) {
check_array[i] = false;
}
std::ifstream importStream(load_path);
if (!importStream.good()) {
std::stringstream ss;
ss<<"Vec3_Container::load_data: Could not open file. \n loadFilePath= "<<load_path<<"\n";
throw MyException(ss.str());
}
std::string csv_line;
getline(importStream, csv_line); // ignore first line = header.
while (getline(importStream, csv_line)) {
remove_leading_whites(csv_line);
replace_delimiter(csv_line);
if ( check_ignore_line(csv_line) ) {
continue;
}
read_line(csv_line, check_array);
}
importStream.close();
for (int i = 0; i< num_tot_bins; i++) {
if (!check_array[i]) {
std::stringstream ss;
ss<<"Vec3_Container::load_data: Not all bins loaded.";
throw MyException(ss.str());
}
}
delete[] check_array;
}
void Vec3_Container::read_line(std::string csv_line, bool *check_array) {
std::stringstream ss;
ss.str(csv_line);
int temp_bin;
double temp_x, temp_y, temp_z;
if ((ss>>temp_bin && ss>>temp_x) && (ss>>temp_y && ss>>temp_z)) {
data[temp_bin] = vec3(temp_x, temp_y, temp_z);
check_array[temp_bin] = true;
} else {
std::cout<<"Vec3_Container::load_data: Warning could not read line in inputFile. \nloadFilePath\t"<<csv_line<<"\n";
}
}
vec3 Vec3_Container::get_data (const vec3 &loc_m) {
int bin = calc_data_bin(loc_m);
return data[bin];
}
int Vec3_Container::calc_data_bin(const vec3 &loc_m) {
double z_m = calc_z_m(loc_m);
double r_m = calc_r_m(loc_m);
double phi = calc_phi(loc_m);
int z_bin = z_scale.calc_index(z_m);
int r_bin = r_scale.calc_index(r_m);
int phi_bin = phi_scale.calc_index(phi);
return z_bin * r_scale.get_number_bins() * phi_scale.get_number_bins() + r_bin * phi_scale.get_number_bins() + phi_bin;
};
+36
View File
@@ -0,0 +1,36 @@
//
// vec3_container.hpp
// mc_electron
//
// Created by Christian Reiling on 02.09.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef vec3_container_hpp
#define vec3_container_hpp
#include "lin_scale.h"
#include "kinematics.h"
#include "constants.h"
class Vec3_Container {
vec3 *data;
Lin_Scale z_scale, r_scale, phi_scale;
public:
Vec3_Container(int num_z_bins, int num_r_bins, int num_phi_bins, std::string load_path);
~Vec3_Container();
Vec3_Container(const Vec3_Container& other);
Vec3_Container& operator=(const Vec3_Container& other);
private:
void load_data(std::string load_path);
void read_line(std::string csv_line, bool *check_array);
public:
vec3 get_data (const vec3 &loc_m);
private:
int calc_data_bin(const vec3 &loc_m);
};
#endif /* vec3_container_hpp */
+1
View File
@@ -14,6 +14,7 @@
#include "constants.h"
// Bit sloppy since only works for velocity.dat which must have exact bins as specified in z_bins and r_bins here!!!
// But velocities should be a constant of the simulation, therefore fine.
class Velocity_Container {