84 lines
2.2 KiB
C++
84 lines
2.2 KiB
C++
//
|
|
// multiz_particle_logger.h
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 19.05.19.
|
|
// Copyright © 2019 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
#ifndef multiz_particle_logger_h
|
|
#define multiz_particle_logger_h
|
|
|
|
#include "particle_logger_base.h"
|
|
#include "h5_file.hpp"
|
|
|
|
|
|
class MultiZ_Particle_Logger : public Particle_Logger_Base {
|
|
hid_t h5g_species;
|
|
H5TB_Particle_Interface *h5tb;
|
|
|
|
int numberZBins;
|
|
double *zLogValues;
|
|
|
|
public:
|
|
MultiZ_Particle_Logger(species this_species, H5_File *h5_file, const int &numberZBins, double *zLogValues) : Particle_Logger_Base(this_species) {
|
|
this->numberZBins = numberZBins;
|
|
this->zLogValues = new double[numberZBins];
|
|
for (int i = 0; i<numberZBins; i++) {
|
|
this->zLogValues[i] = zLogValues[i];
|
|
}
|
|
create(h5_file, this_species);
|
|
}
|
|
~MultiZ_Particle_Logger() {
|
|
delete[] zLogValues;
|
|
delete[] h5tb;
|
|
}
|
|
private:
|
|
void create(H5_File *h5_file, species this_species);
|
|
|
|
public:
|
|
void log(const Particle &logPart, const vec3 &oldLoc_m);
|
|
void flush();
|
|
};
|
|
|
|
|
|
inline void MultiZ_Particle_Logger::create(H5_File *h5_file, species this_species) {
|
|
std::stringstream ss;
|
|
ss<<h5_file->get_h5g_particles_path()<<"/"<<get_species_string(this_species);
|
|
h5g_species = H5Gcreate(*h5_file->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++) {
|
|
table_name = std::to_string(zLogValues[i]);
|
|
h5tb[i] = H5TB_Particle_Interface(table_name.c_str(), &h5g_species);
|
|
}
|
|
}
|
|
|
|
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);
|
|
double zmax = std::max(zold, znew);
|
|
for (int i=0;i<numberZBins;i++) {
|
|
if (zLogValues[i]>=zmin && zLogValues[i]<=zmax) {
|
|
h5tb[i].write(logPart); // Location wrong, because set to new Location, instead of logging location.
|
|
}
|
|
}
|
|
}
|
|
|
|
inline void MultiZ_Particle_Logger::flush() {
|
|
for (int i = 0; i < numberZBins; i++) {
|
|
h5tb[i].flush();
|
|
}
|
|
}
|
|
#endif /* multiz_particle_logger_h */
|