Reworked Populations Loggers.
Added Save and Load Option for Population Data.
This commit is contained in:
@@ -18,7 +18,7 @@ using namespace std;
|
||||
|
||||
|
||||
// Redundant Code with h5, but ASCI Logger is kept in code as relict.
|
||||
const int ASCI_Logger::numberZBins = getParameter("numberZBins");
|
||||
const int ASCI_Logger::numberZBins = load_parameter("numberZBins");
|
||||
|
||||
ASCI_Logger::ASCI_Logger() {
|
||||
if (numberZBins == 0) {
|
||||
@@ -95,13 +95,13 @@ void ASCI_Logger::log_Particle(Particle *logPart, blitz::TinyVector<double,3> ol
|
||||
}
|
||||
|
||||
void ASCI_Logger::set_outdirName() {
|
||||
string parname = getparName();
|
||||
string parname = get_parameter_filename();
|
||||
stringstream dirname;
|
||||
int i = 1;
|
||||
do {
|
||||
dirname.str(std::string());
|
||||
dirname << parname << "_" << getTimeString() << "_" << i++;
|
||||
} while ( isDir(dirname.str()) );
|
||||
dirname << parname << "_" << get_time_string() << "_" << i++;
|
||||
} while ( is_dir(dirname.str()) );
|
||||
outdirName = dirname.str();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ private:
|
||||
public:
|
||||
void importFromCSV(std::string load_path);
|
||||
private:
|
||||
void addPointFromLine(const std::string &lineFromFile);
|
||||
void addPointFromLine(const std::string &csv_line);
|
||||
|
||||
public:
|
||||
void addPoint(std::deque<double> pointIn);
|
||||
@@ -120,30 +120,30 @@ void Base_Container<T_Map>::importFromCSV(std::string load_path) {
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
std::string lineFromFile;
|
||||
while (getline(importStream, lineFromFile)) {
|
||||
removeLeadingWhites(lineFromFile);
|
||||
replaceDelimiter(lineFromFile);
|
||||
if ( checkIgnoreLine(lineFromFile) ) {
|
||||
std::string csv_line;
|
||||
while (getline(importStream, csv_line)) {
|
||||
remove_leading_whites(csv_line);
|
||||
replace_delimiter(csv_line);
|
||||
if ( check_ignore_line(csv_line) ) {
|
||||
continue;
|
||||
}
|
||||
addPointFromLine(lineFromFile);
|
||||
addPointFromLine(csv_line);
|
||||
}
|
||||
importStream.close();
|
||||
}
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
void Base_Container<T_Map>::addPointFromLine(const std::string &lineFromFile) {
|
||||
void Base_Container<T_Map>::addPointFromLine(const std::string &csv_line) {
|
||||
std::stringstream ss;
|
||||
ss.str(lineFromFile);
|
||||
ss.str(csv_line);
|
||||
std::deque<double> dequeTemp;
|
||||
double tempVal;
|
||||
for (int i = 0;i<=Dim;i++) {
|
||||
if (ss>>tempVal) {
|
||||
dequeTemp.push_back(tempVal);
|
||||
} else {
|
||||
std::cout<<"Base_Container::addPointFromFile: Warning could not read line in inputFile. \nloadFilePath\t"<<lineFromFile<<"\n";
|
||||
std::cout<<"Base_Container::addPointFromFile: Warning could not read line in inputFile. \nloadFilePath\t"<<csv_line<<"\n";
|
||||
}
|
||||
}
|
||||
addPoint(dequeTemp);
|
||||
@@ -215,7 +215,7 @@ template <class T_Map>
|
||||
std::string Base_Container<T_Map>::getExportFileHeader() {
|
||||
std::stringstream ss;
|
||||
ss<<"# Automatically generated Data of Function2D_Container class by exportToFile().\n";
|
||||
ss<<"# Generated on "<<getTimeString()<<".\n";
|
||||
ss<<"# Generated on "<<get_time_string()<<".\n";
|
||||
ss<<"#key1 (usually Energy)\tkey2 (angluar distribution or secondary energy)\tparameter (usually SDCS)\n";
|
||||
return(ss.str());
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -23,8 +23,8 @@ class eT2_Elastic : public Sub_Interaction_Base {
|
||||
|
||||
public:
|
||||
eT2_Elastic(Population_Base *T2Population, UniRNG *rngUni) : Sub_Interaction_Base(T2Population, rngUni),
|
||||
tcs_data(zero, 2e4, 1e3, getDataPath() + "eT2_ela_TCS.dat"),
|
||||
dcs_data(zero, 2e4, 1e3, 200, getDataPath() + "eT2_ela_DCS.dat"),
|
||||
tcs_data(zero, 2e4, 1e3, get_data_path() + "eT2_ela_TCS.dat"),
|
||||
dcs_data(zero, 2e4, 1e3, 200, get_data_path() + "eT2_ela_DCS.dat"),
|
||||
kinematics(me_eV, mT2_eV) {}
|
||||
|
||||
double get_macroSigma_m2(const Particle &interPart);
|
||||
|
||||
@@ -161,8 +161,8 @@ class eT2_T2I_Ionization_Container : public eT2_T2I_Ionization_Base {
|
||||
public:
|
||||
eT2_T2I_Ionization_Container(Population_Base *T2Population, UniRNG *rngUni) :
|
||||
eT2_T2I_Ionization_Base(T2Population, rngUni),
|
||||
tcs_data(zero, 2e4, 100, (getDataPath() + "eT2_ion_TCS.dat")),
|
||||
dcs_data(zero, 2e4, 100, 50, (getDataPath() + "eT2_ion_DCS.dat"))
|
||||
tcs_data(zero, 2e4, 100, (get_data_path() + "eT2_ion_TCS.dat")),
|
||||
dcs_data(zero, 2e4, 100, 50, (get_data_path() + "eT2_ion_DCS.dat"))
|
||||
{};
|
||||
|
||||
protected:
|
||||
|
||||
@@ -35,7 +35,7 @@ inline double eT2I_Recombination::get_macroSigma_m2(const Particle &interPart) {
|
||||
inline InteractionOut eT2I_Recombination::do_Interaction (Particle *interPart) {
|
||||
InteractionOut res;
|
||||
res.set_delete_current(true);
|
||||
res.set_decrease_location(tritium2I, interPart->get_Location_m());
|
||||
res.set_decrease(tritium2I, interPart->get_Location_m(), 0); // 0 is dummy parameter, since thermal population
|
||||
// Maybe add the 2 T atoms.
|
||||
return(res);
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
//
|
||||
// electron_population.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 17.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef electron_population_h
|
||||
#define electron_population_h
|
||||
|
||||
|
||||
#include "energeticPop_container.hpp"
|
||||
#include "katrin_geo.hpp"
|
||||
|
||||
#include "population_base.h"
|
||||
#include "constants.h"
|
||||
|
||||
|
||||
class E_Population : public Population_Base, public RNG_Base {
|
||||
EnergeticPop_Container e_Container;
|
||||
Timer *Tim;
|
||||
|
||||
public:
|
||||
E_Population(Timer *Tim, UniRNG *rngUni, NormalRNG *rngNormal) : Population_Base(electron), RNG_Base(rngUni, rngNormal), e_Container(vec3(10,10,10), 2e4, 20) {
|
||||
this->Tim = Tim;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
double get_density_m3 (const vec3 &loc_m);
|
||||
void increase_density (const Particle &upPart, const vec3 &oldLoc_m);
|
||||
void decrease_denisty (const vec3 &oldLoc_m) {};
|
||||
|
||||
vec3 get_average_speed_ms (const vec3 &loc_m);
|
||||
vec3 roll_speed_ms (const vec3 &loc_m);
|
||||
};
|
||||
|
||||
|
||||
inline double E_Population::get_density_m3(const vec3 &loc_m) {
|
||||
Katrin_Geo::check_inKatrin(loc_m);
|
||||
double physTime_s = Tim->get_physTime_s();
|
||||
double dens = e_Container.getDensity_m3(loc_m, physTime_s);
|
||||
return(dens);
|
||||
}
|
||||
|
||||
inline void E_Population::increase_density(const Particle &upPart, const vec3 &oldLoc_m) {
|
||||
e_Container.upDensity(upPart, oldLoc_m);
|
||||
}
|
||||
|
||||
|
||||
inline vec3 E_Population::get_average_speed_ms(const vec3 &loc_m) {
|
||||
return (vec3(0,0,0));
|
||||
}
|
||||
|
||||
inline vec3 E_Population::roll_speed_ms(const vec3 &loc_m) {
|
||||
Katrin_Geo::check_inKatrin(loc_m);
|
||||
double E_eV = e_Container.roll_Energy_eV(loc_m, rngUni);
|
||||
double vAbs_ms = calc_Speed_from_Ekin_eV(E_eV, me_eV);
|
||||
vec3 v_ms = roll_uniform_direction(rngUni) * vAbs_ms;
|
||||
return(v_ms);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* electron_population_h */
|
||||
@@ -30,11 +30,11 @@ double EnergeticPop_Container::getDensity_m3(const vec3 &locXYZ_m, double physTi
|
||||
check_In_Container(locXYZ_m, xyz);
|
||||
vec3 zrphiCords = transformTo_zrphiCords(locXYZ_m, xyz);
|
||||
double V_m3 = get_V_m3(zrphiCords[1]);
|
||||
double cumTime_s = get_cumulativeTime_s(zrphiCords);
|
||||
double cumTime_s = get_cumulated_time_s(zrphiCords);
|
||||
return (cumTime_s/physTime_s/V_m3);
|
||||
}
|
||||
|
||||
double EnergeticPop_Container::get_cumulativeTime_s(vec3 zrphiCords) {
|
||||
double EnergeticPop_Container::get_cumulated_time_s(vec3 zrphiCords) {
|
||||
dim1Map EMap = *getSubMap<dim1Map>(ddeque{zrphiCords[0], zrphiCords[1], zrphiCords[2]}, Lower_bound);
|
||||
double cumTime_s = 0;
|
||||
for (dim1Map::iterator Itr = EMap.begin(); Itr != EMap.end(); Itr++) {
|
||||
@@ -77,7 +77,7 @@ double EnergeticPop_Container::roll_Energy_eV(const vec3 &locXYZ_m, UniRNG *rngU
|
||||
vec3 zrphiCords = transformTo_zrphiCords(locXYZ_m, xyz);
|
||||
dim1Map EMap = *getSubMap<dim1Map>(ddeque{locXYZ_m[0], locXYZ_m[1], locXYZ_m[2]}, Lower_bound);
|
||||
|
||||
double targetTime_s = rngUni->random() * get_cumulativeTime_s(zrphiCords);
|
||||
double targetTime_s = rngUni->random() * get_cumulated_time_s(zrphiCords);
|
||||
double summedTime_s = 0;
|
||||
dim1Map::iterator Itr = EMap.begin();
|
||||
do {
|
||||
|
||||
@@ -29,7 +29,7 @@ private:
|
||||
public:
|
||||
double getDensity_m3(const vec3 &locXYZ_m, double physTime_s) ;
|
||||
private:
|
||||
double get_cumulativeTime_s(vec3 zrphiCords);
|
||||
double get_cumulated_time_s(vec3 zrphiCords);
|
||||
|
||||
public:
|
||||
void upDensity (const Particle &upParticle, const vec3 &oldLocXYZ_m) ;
|
||||
|
||||
@@ -22,18 +22,18 @@ H5_File::H5_File() {
|
||||
}
|
||||
|
||||
void H5_File::create() {
|
||||
const string constH5Name = getFileName();
|
||||
const string constH5Name = get_file_name();
|
||||
h5_file = H5Fcreate(constH5Name.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
|
||||
}
|
||||
|
||||
std::string H5_File::getFileName() {
|
||||
string parname = getparName();
|
||||
std::string H5_File::get_file_name() {
|
||||
string parname = get_parameter_filename();
|
||||
stringstream H5name;
|
||||
int i = 1;
|
||||
do {
|
||||
H5name.str(std::string());
|
||||
H5name << parname << "_" << getTimeString() << "_" << i++<<".h5";
|
||||
} while ( isFile(H5name.str()) );
|
||||
H5name << parname << "_" << get_time_string() << "_" << i++<<".h5";
|
||||
} while ( is_file(H5name.str()) );
|
||||
return (H5name.str());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
H5_Populations *get_h5pop() {return(&h5pop);}
|
||||
private:
|
||||
void create();
|
||||
std::string getFileName();
|
||||
std::string get_file_name();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ private:
|
||||
|
||||
inline H5_Particles::H5_Particles(hid_t *h5_file) {
|
||||
this->h5_file = h5_file;
|
||||
numberZBins = getParameter("numberZBins");
|
||||
numberZBins = load_parameter("numberZBins");
|
||||
set_logging();
|
||||
set_zValues();
|
||||
print_logInfo();
|
||||
@@ -85,7 +85,6 @@ inline void H5_Particles::set_zValues() {
|
||||
|
||||
inline void H5_Particles::print_logInfo() {
|
||||
std::stringstream ss;
|
||||
ss<<"Logger\t ";
|
||||
if (!logging) {
|
||||
ss<<"Logging disabled.\n";
|
||||
} else if (numberZBins == -1) {
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
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);
|
||||
pop_log_bin sample_log_cell = {0,0,0,0,0,0,0};
|
||||
const size_t H5TB_Population_Interface::size = sizeof(pop_log_bin);
|
||||
const char *H5TB_Population_Interface::fieldNames[7] = {
|
||||
"n_decay",
|
||||
"phys_time_s",
|
||||
"z_bin",
|
||||
"r_bin",
|
||||
"phi_bin",
|
||||
@@ -24,15 +24,15 @@ const char *H5TB_Population_Interface::fieldNames[7] = {
|
||||
"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)};
|
||||
HOFFSET(pop_log_bin, phys_time_s),
|
||||
HOFFSET(pop_log_bin, z_bin),
|
||||
HOFFSET(pop_log_bin, r_bin),
|
||||
HOFFSET(pop_log_bin, phi_bin),
|
||||
HOFFSET(pop_log_bin, E_bin),
|
||||
HOFFSET(pop_log_bin, cumulated_time_s),
|
||||
HOFFSET(pop_log_bin, offset)};
|
||||
const hid_t H5TB_Population_Interface::fieldTypes[7] = {
|
||||
H5T_NATIVE_INT,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_INT,
|
||||
H5T_NATIVE_INT,
|
||||
H5T_NATIVE_INT,
|
||||
@@ -41,12 +41,12 @@ const hid_t H5TB_Population_Interface::fieldTypes[7] = {
|
||||
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.phys_time_s),
|
||||
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.cumulated_time_s),
|
||||
sizeof( sample_log_cell.offset)};
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ void H5TB_Population_Interface::create() {
|
||||
}
|
||||
}
|
||||
|
||||
void H5TB_Population_Interface::write(const log_population_bin &log_bin) {
|
||||
void H5TB_Population_Interface::write(const pop_log_bin &log_bin) {
|
||||
H5TBappend_records(*loc_id, table_name.c_str() , 1, size, offset, sizes, &log_bin);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,19 +11,20 @@
|
||||
|
||||
#include "error_types.h"
|
||||
|
||||
//#include "population_base.h"
|
||||
|
||||
#include "hdf5.h"
|
||||
#include "hdf5_hl.h"
|
||||
|
||||
|
||||
typedef struct log_population_bin {
|
||||
int number_decay;
|
||||
typedef struct pop_log_bin {
|
||||
double phys_time_s;
|
||||
int z_bin;
|
||||
int r_bin;
|
||||
int phi_bin;
|
||||
int E_bin;
|
||||
double cumulative_time;
|
||||
double cumulated_time_s;
|
||||
int offset;
|
||||
} log_population_bin;
|
||||
} pop_log_bin;
|
||||
|
||||
|
||||
class H5TB_Population_Interface {
|
||||
@@ -48,7 +49,7 @@ private:
|
||||
void create();
|
||||
|
||||
public:
|
||||
void write(const log_population_bin &log_bin);
|
||||
void write(const pop_log_bin &log_bin);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
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);
|
||||
pop_bin_meta_info sample_bin = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
const size_t H5TB_Population_Meta_Interface::size = sizeof(pop_bin_meta_info);
|
||||
const char *H5TB_Population_Meta_Interface::fieldNames[12] = {
|
||||
"z_bin",
|
||||
"r_bin",
|
||||
@@ -29,18 +29,18 @@ const char *H5TB_Population_Meta_Interface::fieldNames[12] = {
|
||||
"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)};
|
||||
HOFFSET(pop_bin_meta_info, z_bin),
|
||||
HOFFSET(pop_bin_meta_info, r_bin),
|
||||
HOFFSET(pop_bin_meta_info, phi_bin),
|
||||
HOFFSET(pop_bin_meta_info, E_bin),
|
||||
HOFFSET(pop_bin_meta_info, z_min_m),
|
||||
HOFFSET(pop_bin_meta_info, z_max_m),
|
||||
HOFFSET(pop_bin_meta_info, r_min_m),
|
||||
HOFFSET(pop_bin_meta_info, r_max_m),
|
||||
HOFFSET(pop_bin_meta_info, phi_min),
|
||||
HOFFSET(pop_bin_meta_info, phi_max),
|
||||
HOFFSET(pop_bin_meta_info, E_min_eV),
|
||||
HOFFSET(pop_bin_meta_info, E_max_eV)};
|
||||
|
||||
|
||||
const hid_t H5TB_Population_Meta_Interface::fieldTypes[12] = {
|
||||
@@ -83,6 +83,6 @@ void H5TB_Population_Meta_Interface::create() {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -11,26 +11,12 @@
|
||||
|
||||
#include "error_types.h"
|
||||
|
||||
#include "population_base.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];
|
||||
@@ -53,7 +39,7 @@ private:
|
||||
void create();
|
||||
|
||||
public:
|
||||
void write(const log_meta_bin &log_meta);
|
||||
void write(const pop_bin_meta_info &log_meta_bin);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include "injector.hpp"
|
||||
#include "katrin_geo.hpp"
|
||||
|
||||
const int Injector::injectionMethod = getParameter("injectionMethod");
|
||||
const double Injector::injectionEnergy_eV = getParameter("injectionEnergy_eV");
|
||||
const int Injector::injectionMethod = load_parameter("injectionMethod");
|
||||
const double Injector::injectionEnergy_eV = load_parameter("injectionEnergy_eV");
|
||||
|
||||
Particle Injector::injectElectron (const int &newId) {
|
||||
double r_m = Katrin_Geo::get_radius_m()*sqrt(rngUni->random());
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
#include "TT2_elastic.h"
|
||||
|
||||
const int Interaction_Builder::eT2elastic = getParameter("eT2elastic");
|
||||
const int Interaction_Builder::eT2ionization = getParameter("eT2ionization");
|
||||
const int Interaction_Builder::eT2elastic = load_parameter("eT2elastic");
|
||||
const int Interaction_Builder::eT2ionization = load_parameter("eT2ionization");
|
||||
|
||||
|
||||
Interaction_Manager Interaction_Builder::build(Population_Manager *Populations, UniRNG *rngUni) {
|
||||
|
||||
@@ -11,4 +11,4 @@
|
||||
#include "read_system.h"
|
||||
|
||||
|
||||
const double Katrin_Fields::wgtsMagField_T = getParameter("wgtsMagField_T");
|
||||
const double Katrin_Fields::wgtsMagField_T = load_parameter("wgtsMagField_T");
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
const double Katrin_Geo::rearwallZ_m = getParameter("rearwallZ_m");
|
||||
const double Katrin_Geo::wgtsStartZ_m = getParameter("wgtsStartZ_m");
|
||||
const double Katrin_Geo::wgtsEndZ_m = getParameter("wgtsEndZ_m");
|
||||
const double Katrin_Geo::wgtsRadius_m = getParameter("wgtsRadius_m");
|
||||
const double Katrin_Geo::rearwallZ_m = load_parameter("rearwallZ_m");
|
||||
const double Katrin_Geo::wgtsStartZ_m = load_parameter("wgtsStartZ_m");
|
||||
const double Katrin_Geo::wgtsEndZ_m = load_parameter("wgtsEndZ_m");
|
||||
const double Katrin_Geo::wgtsRadius_m = load_parameter("wgtsRadius_m");
|
||||
|
||||
void Katrin_Geo::check_inWGTS(vec3 loc_m) {
|
||||
if (!inWGTS(loc_m)) {
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
//
|
||||
// energetic_base.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 11.06.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef energetic_base_h
|
||||
#define energetic_base_h
|
||||
|
||||
|
||||
#include "katrin_geo.hpp"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "population4_container.hpp"
|
||||
#include "size_container.hpp"
|
||||
#include "lin_scale.h"
|
||||
|
||||
#include "population_base.h"
|
||||
|
||||
|
||||
class Kinetic_Population : public Population_Base, protected RNG_Base{
|
||||
Pop4_Container cumulated_times_s;
|
||||
Pop4_Container number_annhilated;
|
||||
|
||||
Size_Container bin_sizes;
|
||||
|
||||
Timer *timer;
|
||||
|
||||
double m_eV;
|
||||
|
||||
public:
|
||||
Kinetic_Population(species this_species, Timer *timer, UniRNG *rngUni, NormalRNG *rngNormal, int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins);
|
||||
private:
|
||||
void init_containers(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins);
|
||||
|
||||
public:
|
||||
double get_density_m3 (const vec3 &loc_m);
|
||||
void increase_density (const Particle &upPart, const vec3 &oldLoc_m);
|
||||
void decrease_denisty (const vec3 &loc_m, const double &energy_eV);
|
||||
|
||||
public:
|
||||
vec3 get_average_speed_ms (const vec3 &loc_m);
|
||||
vec3 roll_speed_ms (const vec3 &loc_m);
|
||||
private:
|
||||
vec3 roll_thermSpeed_ms(const vec3 &loc_m);
|
||||
|
||||
public:
|
||||
meta_vec get_bins_meta_info();
|
||||
bin_content_vec get_bins_content();
|
||||
bin_count4 get_bin_count4();
|
||||
void set_bins(bin_count4 bin_counts, bin_content_vec bin_contents);
|
||||
private:
|
||||
Lin_Scale get_z_scale();
|
||||
Lin_Scale get_r_scale();
|
||||
Lin_Scale get_phi_scale();
|
||||
Log_Scale get_E_scale();
|
||||
};
|
||||
|
||||
|
||||
inline Kinetic_Population::Kinetic_Population(species this_species, Timer *timer, UniRNG *rngUni, NormalRNG *rngNormal, int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins) : Population_Base(this_species), RNG_Base(rngUni, rngNormal) {
|
||||
this->timer = timer;
|
||||
init_containers(num_z_bins, num_r_bins, num_phi_bins, num_E_bins);
|
||||
m_eV = get_species_mass(this_species);
|
||||
};
|
||||
|
||||
void Kinetic_Population::init_containers(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins) {
|
||||
cumulated_times_s = Pop4_Container(num_z_bins, num_r_bins, num_phi_bins, num_E_bins);
|
||||
number_annhilated = Pop4_Container(num_z_bins, num_r_bins, num_phi_bins, num_E_bins);
|
||||
bin_sizes = Size_Container(num_z_bins, num_r_bins, num_phi_bins);
|
||||
}
|
||||
|
||||
inline double Kinetic_Population::get_density_m3(const vec3 &loc_m) {
|
||||
//Katrin_Geo::check_inKatrin(loc_m);
|
||||
double physical_time_s = timer->get_physTime_s();
|
||||
int num_E_bins = cumulated_times_s.get_num_E_bins();
|
||||
double *cumulated_time_s = cumulated_times_s.get_E_bins(loc_m);
|
||||
double *offset = number_annhilated.get_E_bins(loc_m);
|
||||
double total_cumulated_time_s = 0;
|
||||
double total_offset = 0;
|
||||
for (int i=0; i<num_E_bins; i++) {
|
||||
total_cumulated_time_s += cumulated_time_s[i];
|
||||
total_offset += offset[i];
|
||||
}
|
||||
double bin_size_m3 = bin_sizes.get_cell_volume_m3(loc_m);
|
||||
double dens_m3 = total_cumulated_time_s/physical_time_s/bin_size_m3 - total_offset;
|
||||
dens_m3 = (dens_m3 < 0) ? zero : dens_m3;
|
||||
return(dens_m3);
|
||||
}
|
||||
|
||||
inline void Kinetic_Population::increase_density(const Particle &upPart, const vec3 &oldLoc_m) {
|
||||
double cell_time_s = bin_sizes.get_cell_length_m()/upPart.get_SpeedAbs_ms();
|
||||
double energy_eV = upPart.get_EKin_eV();
|
||||
cumulated_times_s.increase_value(cell_time_s, upPart.get_Location_m(), oldLoc_m, energy_eV);
|
||||
}
|
||||
|
||||
inline void Kinetic_Population::decrease_denisty (const vec3 &loc_m, const double &energy_eV) {
|
||||
number_annhilated.increase_value(1, loc_m, energy_eV);
|
||||
}
|
||||
|
||||
|
||||
inline vec3 Kinetic_Population::get_average_speed_ms(const vec3 &loc_m) {
|
||||
return (vec3(0,0,0));
|
||||
}
|
||||
|
||||
inline vec3 Kinetic_Population::roll_speed_ms(const vec3 &loc_m) {
|
||||
double total = get_density_m3(loc_m);
|
||||
double target = rngUni->random() * total;
|
||||
|
||||
double physical_time_s = timer->get_physTime_s();
|
||||
double bin_size_m3 = bin_sizes.get_cell_volume_m3(loc_m);
|
||||
|
||||
int num_E_bins = cumulated_times_s.get_num_E_bins();
|
||||
double *cumulated_time_s = cumulated_times_s.get_E_bins(loc_m);
|
||||
double *offset = number_annhilated.get_E_bins(loc_m);
|
||||
double cum_density_m3 = 0;
|
||||
for (int i=0; i<num_E_bins; i++) {
|
||||
cum_density_m3 += cumulated_time_s[i]/physical_time_s/bin_size_m3 - offset[i];
|
||||
if (cum_density_m3>target) {
|
||||
double lower = cumulated_times_s.get_corresponding_E_lower_eV(i);
|
||||
double upper = cumulated_times_s.get_corresponding_E_upper_eV(i);
|
||||
return lower + rngUni->random() * (upper-lower);
|
||||
}
|
||||
}
|
||||
std::stringstream ss;
|
||||
ss<<"Kinetic_Population::roll_speed_ms: Overflow.\n";
|
||||
throw MyException (ss.str());
|
||||
}
|
||||
|
||||
|
||||
inline meta_vec Kinetic_Population::get_bins_meta_info() {
|
||||
Lin_Scale z_scale = get_z_scale();
|
||||
Lin_Scale r_scale = get_r_scale();
|
||||
Lin_Scale phi_scale = get_phi_scale();
|
||||
Log_Scale E_scale = get_E_scale();
|
||||
|
||||
meta_vec res;
|
||||
pop_bin_meta_info temp_bin = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
temp_bin.z_min_m = z_scale.get_lower_scale_end();
|
||||
for (int i_z=0; i_z<z_scale.get_number_bins(); i_z++) {
|
||||
temp_bin.z_bin = i_z;
|
||||
temp_bin.z_max_m = z_scale.get_upper_bin_bound(i_z);
|
||||
temp_bin.r_min_m = r_scale.get_lower_scale_end();
|
||||
for (int i_r=0; i_r<r_scale.get_number_bins(); i_r++) {
|
||||
temp_bin.r_bin = i_r;
|
||||
temp_bin.r_max_m = r_scale.get_upper_bin_bound(i_r);
|
||||
temp_bin.phi_min = phi_scale.get_lower_scale_end();
|
||||
for (int i_phi=0; i_phi<phi_scale.get_number_bins(); i_phi++) {
|
||||
temp_bin.phi_bin = i_phi;
|
||||
temp_bin.phi_max = phi_scale.get_upper_bin_bound(i_phi);
|
||||
temp_bin.E_min_eV = E_scale.get_lower_scale_end();
|
||||
for (int i_E=0; i_E<E_scale.get_number_bins(); i_E++) {
|
||||
temp_bin.E_bin = i_E;
|
||||
temp_bin.E_max_eV = E_scale.get_upper_bin_bound(i_E);
|
||||
res.push_back(temp_bin);
|
||||
temp_bin.E_min_eV = temp_bin.E_max_eV;
|
||||
}
|
||||
temp_bin.phi_min = temp_bin.phi_max;
|
||||
}
|
||||
temp_bin.r_min_m = temp_bin.r_max_m;
|
||||
}
|
||||
temp_bin.z_min_m = temp_bin.z_max_m;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
inline bin_content_vec Kinetic_Population::get_bins_content() {
|
||||
Lin_Scale z_scale = get_z_scale();
|
||||
Lin_Scale r_scale = get_r_scale();
|
||||
Lin_Scale phi_scale = get_phi_scale();
|
||||
Log_Scale E_scale = get_E_scale();
|
||||
|
||||
bin_content_vec res;
|
||||
pop_bin_content temp_bin = {0, 0, 0, 0, 0, 0};
|
||||
|
||||
for (int i_z=0; i_z < z_scale.get_number_bins(); i_z++) {
|
||||
temp_bin.z_bin = i_z;
|
||||
for (int i_r=0; i_r < r_scale.get_number_bins(); i_r++) {
|
||||
temp_bin.r_bin = i_r;
|
||||
for (int i_phi=0; i_phi < phi_scale.get_number_bins(); i_phi++) {
|
||||
temp_bin.phi_bin = i_phi;
|
||||
for (int i_E=0; i_E < E_scale.get_number_bins(); i_E++) {
|
||||
temp_bin.E_bin = i_E;
|
||||
temp_bin.cumulated_time_s = cumulated_times_s.get_value_by_bin(i_z, i_r, i_phi, i_E);
|
||||
temp_bin.offset = number_annhilated.get_value_by_bin(i_z, i_r, i_phi, i_E);
|
||||
res.push_back(temp_bin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
inline bin_count4 Kinetic_Population::get_bin_count4() {
|
||||
bin_count4 res;
|
||||
res[0] = get_z_scale().get_number_bins();
|
||||
res[1] = get_r_scale().get_number_bins();
|
||||
res[2] = get_phi_scale().get_number_bins();
|
||||
res[3] = get_E_scale().get_number_bins();
|
||||
return(res);
|
||||
}
|
||||
|
||||
inline void Kinetic_Population::set_bins(bin_count4 bin_counts, bin_content_vec bin_contents) {
|
||||
int num_z_bins = bin_counts[0];
|
||||
int num_r_bins = bin_counts[1];
|
||||
int num_phi_bins = bin_counts[2];
|
||||
int num_E_bins = bin_counts[3];
|
||||
init_containers(num_z_bins, num_r_bins, num_phi_bins, num_E_bins);
|
||||
|
||||
int z_bin, r_bin, phi_bin, E_bin;
|
||||
double cumulated_time_s, offset;
|
||||
for(bin_content_vec::iterator Itr = bin_contents.begin(); Itr != bin_contents.end(); Itr++) {
|
||||
z_bin = (*Itr).z_bin;
|
||||
r_bin = (*Itr).r_bin;
|
||||
phi_bin = (*Itr).phi_bin;
|
||||
E_bin = (*Itr).E_bin;
|
||||
cumulated_time_s = (*Itr).cumulated_time_s;
|
||||
offset = (*Itr).offset;
|
||||
cumulated_times_s.set_value_by_bin(cumulated_time_s, z_bin, r_bin, phi_bin, E_bin);
|
||||
number_annhilated.set_value_by_bin(offset, z_bin, r_bin, phi_bin, E_bin);
|
||||
}
|
||||
}
|
||||
|
||||
inline Lin_Scale Kinetic_Population::get_z_scale() {
|
||||
return (cumulated_times_s.get_z_scale());
|
||||
|
||||
}
|
||||
|
||||
inline Lin_Scale Kinetic_Population::get_r_scale() {
|
||||
return (cumulated_times_s.get_r_scale());
|
||||
|
||||
}
|
||||
|
||||
inline Lin_Scale Kinetic_Population::get_phi_scale() {
|
||||
return (cumulated_times_s.get_phi_scale());
|
||||
|
||||
}
|
||||
|
||||
inline Log_Scale Kinetic_Population::get_E_scale() {
|
||||
return (cumulated_times_s.get_E_scale());
|
||||
|
||||
}
|
||||
|
||||
#endif /* energetic_base_h */
|
||||
@@ -22,7 +22,7 @@ class Lin_Scale : public Scale {
|
||||
double delta_x;
|
||||
int number_bins;
|
||||
public:
|
||||
Lin_Scale() {};
|
||||
Lin_Scale() {number_bins=0;};
|
||||
Lin_Scale(const double &min_x, const double &max_x, const int &number_bins);
|
||||
~Lin_Scale() {};
|
||||
Scale *clone() {return new Lin_Scale(*this);}
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "sf_particle_logger.h"
|
||||
#include "off_particle_logger.h"
|
||||
|
||||
#include "population_logger_base.h"
|
||||
|
||||
|
||||
Particle_Logger_Manager Particle_Logger_Builder::build(H5_File *h5f) {
|
||||
Particle_Logger_Manager ParticleLogger;
|
||||
@@ -35,11 +37,10 @@ Particle_Logger_Base *Particle_Logger_Builder::build_eLogger(H5_Particles *h5par
|
||||
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 = static_cast<Thermal_Base*>(populations->find(tritium2I));
|
||||
|
||||
Population_Logger.add(new Thermal_Population_Logger(T2I_population, h5pop->get_h5g_pop()));
|
||||
return (Population_Logger);
|
||||
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));
|
||||
return (Population_Loggers);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "particle_logger_base.h"
|
||||
|
||||
#include "population_builder.hpp"
|
||||
#include "thermal_population_logger.h"
|
||||
#include "population_logger_base.h"
|
||||
|
||||
typedef Manager_Base<Particle_Logger_Base> Particle_Logger_Manager;
|
||||
|
||||
@@ -31,11 +31,10 @@ private:
|
||||
|
||||
|
||||
class Population_Logger_Builder {
|
||||
|
||||
public:
|
||||
Population_Logger_Builder() {};
|
||||
|
||||
static Population_Logger_Manager build(H5_File *h5f, Population_Manager *populations);
|
||||
static Population_Logger_Manager build(H5_File *h5f, Population_Manager *populations, Timer *timer);
|
||||
//private:
|
||||
//static Population_Logger_Manager *build_Logger(H5_Particles *h5part);
|
||||
};
|
||||
|
||||
@@ -11,9 +11,8 @@ using namespace std;
|
||||
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
|
||||
clock_t start = clock();
|
||||
Simulation Sim;
|
||||
Sim.doit();
|
||||
cout<<"Duration: "<< ( clock() - start ) / (double) CLOCKS_PER_SEC <<'\n';
|
||||
cout<<"Duration: "<< ( clock() - start ) / (double) CLOCKS_PER_SEC <<"\n";
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ TARGETS = mcelectron
|
||||
all: $(TARGETS)
|
||||
|
||||
mcelectron: main.o simulation.o\
|
||||
tcs_container.o dcs_theta_container.o dcs_ionization_container.o population3_container.o size_container.o \
|
||||
tcs_container.o dcs_theta_container.o dcs_ionization_container.o population3_container.o population4_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 logger_builder.o \
|
||||
h5_file.o logger_builder.o population_load_saver.o \
|
||||
h5tb_particle_interface.o h5tb_population_interface.o h5tb_population_meta_interface.o \
|
||||
population_builder.o \
|
||||
mover_builder.o \
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
template <class T>
|
||||
class Manager_Base {
|
||||
private:
|
||||
std::vector<T*> Processes;
|
||||
std::vector<T*> processes;
|
||||
|
||||
public:
|
||||
Manager_Base() {};
|
||||
@@ -35,12 +35,12 @@ inline void Manager_Base<T>::add(T* add) {
|
||||
ss<<"Manager_Base::add_Process: Dublicate Insert of Process for this Species.";
|
||||
throw MyException (ss.str());
|
||||
}
|
||||
Processes.push_back(add);
|
||||
processes.push_back(add);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool Manager_Base<T>::exists(species this_species) {
|
||||
for (typename std::vector<T*>::iterator Itr = Processes.begin(); Itr!=Processes.end(); Itr++) {
|
||||
for (typename std::vector<T*>::iterator Itr = processes.begin(); Itr!=processes.end(); Itr++) {
|
||||
if ((*Itr)->get_species() == this_species) {
|
||||
return (true);
|
||||
}
|
||||
@@ -50,7 +50,7 @@ inline bool Manager_Base<T>::exists(species this_species) {
|
||||
|
||||
template <class T>
|
||||
inline T* Manager_Base<T>::find(species this_species) {
|
||||
for (typename std::vector<T*>::iterator Itr = Processes.begin(); Itr!=Processes.end(); Itr++) {
|
||||
for (typename std::vector<T*>::iterator Itr = processes.begin(); Itr!=processes.end(); Itr++) {
|
||||
if ((*Itr)->get_species() == this_species) {
|
||||
return (*Itr);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
#include "tritium2I_drift.h"
|
||||
|
||||
|
||||
const int Mover_Builder::propagationMethod = getParameter("propagationMethod");
|
||||
const double Mover_Builder::dt_s = getParameter("dt_s");
|
||||
const int Mover_Builder::propagationMethod = load_parameter("propagationMethod");
|
||||
const double Mover_Builder::dt_s = load_parameter("dt_s");
|
||||
|
||||
Mover_Manager Mover_Builder::build(Particle_Logger_Manager *Loggers, Population_Manager *Populations) {
|
||||
Mover_Manager Movers;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "particle.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
@@ -34,6 +36,22 @@ std::string get_species_string(const species &spec) {
|
||||
return (res);
|
||||
}
|
||||
|
||||
species get_species_from_string(const std::string &species_string) {
|
||||
std::vector<species> all;
|
||||
all.push_back(electron);
|
||||
all.push_back(tritiumI);
|
||||
all.push_back(tritium2I);
|
||||
all.push_back(tritium2);
|
||||
for (std::vector<species>::iterator Itr = all.begin(); Itr!= all.end(); Itr++) {
|
||||
if (get_species_string(*Itr) == species_string) {
|
||||
return (*Itr);
|
||||
}
|
||||
}
|
||||
stringstream ss;
|
||||
ss<<"get_species_from_string: Species not defined\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
double get_species_mass(const species &spec) {
|
||||
double res;
|
||||
switch (spec) {
|
||||
@@ -57,6 +75,7 @@ double get_species_mass(const species &spec) {
|
||||
return (res);
|
||||
}
|
||||
|
||||
|
||||
ostream& operator<<(ostream& os, const species& spec) {
|
||||
os<<get_species_string(spec);
|
||||
return (os);
|
||||
|
||||
@@ -20,8 +20,11 @@
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
|
||||
typedef enum species{electron, tritiumI, tritium2I, tritium2} species;
|
||||
double get_species_mass(const species &spec);
|
||||
|
||||
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);
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const species& spec);
|
||||
|
||||
|
||||
|
||||
@@ -16,16 +16,13 @@ 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, 2*pi, num_phi_bins);
|
||||
int z_dimension = z_scale.get_number_bins();
|
||||
int r_dimension = r_scale.get_number_bins();
|
||||
int phi_dimension = phi_scale.get_number_bins();
|
||||
|
||||
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 = new double **[num_z_bins];
|
||||
for (int i = 0; i < num_z_bins; i++) {
|
||||
data[i] = new double *[num_r_bins];
|
||||
for(int j = 0; j < num_r_bins; j++) {
|
||||
data[i][j] = new double[num_phi_bins];
|
||||
for (int k = 0; k < num_phi_bins; k++) {
|
||||
data[i][j][k] = 0;
|
||||
}
|
||||
}
|
||||
@@ -68,8 +65,8 @@ Pop3_Container::Pop3_Container(const Pop3_Container& other) {
|
||||
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(r_scale, tmp.r_scale);
|
||||
swap(phi_scale, tmp.phi_scale);
|
||||
swap(data, tmp.data);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
#include "lin_scale.h"
|
||||
#include "katrin_geo.hpp"
|
||||
#include "timer.hpp"
|
||||
|
||||
|
||||
class Pop3_Container {
|
||||
@@ -21,6 +20,7 @@ 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();
|
||||
@@ -31,29 +31,12 @@ public:
|
||||
void increase_value(const double &value, const vec3 &loc1_m, const vec3 &loc2_m);
|
||||
double get_value (vec3 loc_m);
|
||||
|
||||
|
||||
void set_value_by_bin(double value, int z_bin, int r_bin, int phi_bin) {data[z_bin][r_bin][phi_bin] = value;}
|
||||
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);}
|
||||
|
||||
void debug() {
|
||||
int z_dimension = z_scale.get_number_bins();
|
||||
int r_dimension = r_scale.get_number_bins();
|
||||
int phi_dimension = phi_scale.get_number_bins();
|
||||
|
||||
for (int i = 0; i < z_dimension; i++) {
|
||||
for(int j = 0; j < r_dimension; j++) {
|
||||
std::cout<<i<<"\t"<<j<<"\t-\t";
|
||||
for (int k = 0; k < phi_dimension; k++) {
|
||||
std::cout<<data[i][j][k]<<"\t";
|
||||
}
|
||||
std::cout<<"\n";
|
||||
}
|
||||
}
|
||||
std::cout<<"\n";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
//
|
||||
// population4_container.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 11.06.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "population4_container.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
Pop4_Container::Pop4_Container(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_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, 2*pi, num_phi_bins);
|
||||
E_scale = Log_Scale(zero, 2e4, num_E_bins);
|
||||
|
||||
data = new double ***[num_z_bins];
|
||||
for (int i = 0; i < num_z_bins; i++) {
|
||||
data[i] = new double **[num_r_bins];
|
||||
for(int j = 0; j < num_r_bins; j++) {
|
||||
data[i][j] = new double *[num_phi_bins];
|
||||
for (int k = 0; k < num_phi_bins; k++) {
|
||||
data[i][j][k] = new double [num_E_bins];
|
||||
for (int l = 0; l< num_E_bins; l++) {
|
||||
data[i][j][k][l] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Pop4_Container::~Pop4_Container() {
|
||||
int num_z_bins = z_scale.get_number_bins();
|
||||
int num_r_bins = r_scale.get_number_bins();
|
||||
int num_phi_bins = phi_scale.get_number_bins();
|
||||
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++) {
|
||||
delete[] data[i][j][k];
|
||||
}
|
||||
delete[] data[i][j];
|
||||
}
|
||||
delete[] data[i];
|
||||
}
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
Pop4_Container::Pop4_Container(const Pop4_Container& other) {
|
||||
z_scale = other.z_scale;
|
||||
r_scale = other.r_scale;
|
||||
phi_scale = other.phi_scale;
|
||||
E_scale = other.E_scale;
|
||||
int num_z_bins = z_scale.get_number_bins();
|
||||
int num_r_bins = r_scale.get_number_bins();
|
||||
int num_phi_bins = phi_scale.get_number_bins();
|
||||
int num_E_bins = E_scale.get_number_bins();
|
||||
|
||||
data = new double ***[num_z_bins];
|
||||
for (int i = 0; i < num_z_bins; i++) {
|
||||
data[i] = new double **[num_r_bins];
|
||||
for(int j = 0; j < num_r_bins; j++) {
|
||||
data[i][j] = new double *[num_phi_bins];
|
||||
for (int k = 0; k < num_phi_bins; k++) {
|
||||
data[i][j][k] = new double [num_E_bins];
|
||||
for (int l = 0; l < num_E_bins; l++) {
|
||||
data[i][j][k][l] = other.data[i][j][k][l];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Pop4_Container& Pop4_Container::operator=(const Pop4_Container& other) {
|
||||
Pop4_Container tmp(other);
|
||||
swap(z_scale, tmp.z_scale);
|
||||
swap(r_scale, tmp.r_scale);
|
||||
swap(phi_scale, tmp.phi_scale);
|
||||
swap(E_scale, tmp.E_scale);
|
||||
swap(data, tmp.data);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void Pop4_Container::increase_value(const double &value, const vec3 &loc_m, const double &E_eV) {
|
||||
int zbin = z_scale.calc_index(get_z_m(loc_m));
|
||||
int rbin = r_scale.calc_index(get_r_m(loc_m));
|
||||
int phibin = phi_scale.calc_index(get_phi(loc_m));
|
||||
int E_bin = E_scale.calc_index(E_eV);
|
||||
|
||||
data[zbin][rbin][phibin][E_bin] += value;
|
||||
}
|
||||
|
||||
void Pop4_Container::increase_value(const double &value, const vec3 &loc1_m, const vec3 &loc2_m, const double &E_eV) {
|
||||
double z_min_m = get_z_m(loc1_m);
|
||||
double z_max_m = get_z_m(loc2_m);
|
||||
if (z_max_m < z_min_m) {
|
||||
swap(z_min_m, z_max_m);
|
||||
}
|
||||
int min_z_index = z_scale.calc_index(z_min_m);
|
||||
int max_z_index = z_scale.calc_index(z_max_m);
|
||||
// No r/phi movement, else need to calculate more exactly
|
||||
double r = get_r_m(loc1_m);
|
||||
int rbin = r_scale.calc_index(get_r_m(r));
|
||||
double phi = get_phi(loc1_m);
|
||||
int phibin = phi_scale.calc_index(phi);
|
||||
int E_bin = E_scale.calc_index(E_eV);
|
||||
|
||||
for (int i = min_z_index; i<=max_z_index; i++) {
|
||||
data[i][rbin][phibin][E_bin] += value;
|
||||
}
|
||||
}
|
||||
|
||||
double Pop4_Container::get_value(const vec3 &loc_m, const double &E_eV) {
|
||||
int zbin = z_scale.calc_index(get_z_m(loc_m));
|
||||
int rbin = r_scale.calc_index(get_r_m(loc_m));
|
||||
int phibin = phi_scale.calc_index(get_phi(loc_m));
|
||||
int E_bin = E_scale.calc_index(E_eV);
|
||||
return (data[zbin][rbin][phibin][E_bin]);
|
||||
}
|
||||
|
||||
double *Pop4_Container::get_E_bins (const vec3 &loc_m) {
|
||||
int z_bin = z_scale.calc_index(loc_m[0]);
|
||||
int r_bin = r_scale.calc_index(loc_m[1]);
|
||||
int phi_bin = phi_scale.calc_index(loc_m[2]);
|
||||
return data[z_bin][r_bin][phi_bin];
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// population4_container.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 11.06.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef population4_container_hpp
|
||||
#define population4_container_hpp
|
||||
|
||||
#include "log_scale.h"
|
||||
#include "katrin_geo.hpp"
|
||||
#include "timer.hpp"
|
||||
|
||||
|
||||
class Pop4_Container {
|
||||
double ****data;
|
||||
Lin_Scale z_scale;
|
||||
Lin_Scale r_scale;
|
||||
Lin_Scale phi_scale;
|
||||
Log_Scale E_scale;
|
||||
|
||||
public:
|
||||
Pop4_Container() {};
|
||||
Pop4_Container(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins);
|
||||
|
||||
~Pop4_Container();
|
||||
Pop4_Container(const Pop4_Container& other);
|
||||
Pop4_Container& operator=(const Pop4_Container& other);
|
||||
|
||||
void increase_value(const double &value, const vec3 &loc_m, const double &E_eV);
|
||||
void increase_value(const double &value, const vec3 &loc1_m, const vec3 &loc2_m, const double &E_eV);
|
||||
double get_value(const vec3 &loc_m, const double &E_eV);
|
||||
|
||||
double *get_E_bins (const vec3 &loc_m);
|
||||
int get_num_E_bins(){return(E_scale.get_number_bins());}
|
||||
double get_corresponding_E_lower_eV(int E_bin){return E_scale.get_lower_bin_bound(E_bin);}
|
||||
double get_corresponding_E_upper_eV(int E_bin){return E_scale.get_upper_bin_bound(E_bin);}
|
||||
|
||||
void set_value_by_bin(double value, int z_bin, int r_bin, int phi_bin, int E_bin) {data[z_bin][r_bin][phi_bin][E_bin] = value;}
|
||||
double get_value_by_bin(int z_bin, int r_bin, int phi_bin, int E_bin) {return (data[z_bin][r_bin][phi_bin][E_bin]);}
|
||||
|
||||
Lin_Scale get_z_scale(){return(z_scale);}
|
||||
Lin_Scale get_r_scale(){return(r_scale);}
|
||||
Lin_Scale get_phi_scale(){return(phi_scale);}
|
||||
Log_Scale get_E_scale(){return(E_scale);}
|
||||
};
|
||||
|
||||
|
||||
#endif /* population4_container_hpp */
|
||||
@@ -18,15 +18,35 @@
|
||||
#include "process_base.h"
|
||||
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
typedef blitz::TinyVector<int,3> bin_count3;
|
||||
typedef blitz::TinyVector<int,4> bin_count4;
|
||||
|
||||
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;
|
||||
typedef struct pop_bin_meta_info {
|
||||
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;
|
||||
} pop_bin_meta;
|
||||
|
||||
typedef struct pop_bin_content {
|
||||
int z_bin;
|
||||
int r_bin;
|
||||
int phi_bin;
|
||||
int E_bin;
|
||||
double cumulated_time_s;
|
||||
int offset;
|
||||
} pop_log_bins;
|
||||
|
||||
typedef std::vector<pop_bin_meta_info> meta_vec;
|
||||
typedef std::vector<pop_bin_content> bin_content_vec;
|
||||
|
||||
|
||||
class Population_Base : public Process_Base {
|
||||
@@ -36,12 +56,15 @@ public:
|
||||
|
||||
virtual double get_density_m3 (const vec3 &loc_m) = 0;
|
||||
virtual void increase_density (const Particle &upPart, const vec3 &oldLoc_m) = 0;
|
||||
virtual void decrease_denisty (const vec3 &oldLoc_m) = 0;
|
||||
virtual void decrease_denisty (const vec3 &oldLoc_m, const double &energy_eV) = 0;
|
||||
|
||||
virtual vec3 get_average_speed_ms (const vec3 &loc_m) = 0;
|
||||
virtual vec3 roll_speed_ms (const vec3 &loc_m) = 0;
|
||||
|
||||
|
||||
|
||||
virtual meta_vec get_bins_meta_info() = 0;
|
||||
virtual bin_content_vec get_bins_content() = 0;
|
||||
virtual bin_count4 get_bin_count4() = 0;
|
||||
virtual void set_bins(bin_count4 bin_counts, bin_content_vec bin_contents) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
|
||||
#include "population_builder.hpp"
|
||||
|
||||
#include "electron_population.h"
|
||||
#include "thermal_katrin_base.h"
|
||||
#include "thermal_population.h"
|
||||
#include "kinetic_population.h"
|
||||
|
||||
#include "tritium2_population.h"
|
||||
|
||||
|
||||
@@ -18,10 +19,11 @@ Population_Manager Population_Builder::build(Timer *timer,UniRNG *rngUni, Normal
|
||||
int num_z_bins = 10;
|
||||
int num_r_bins = 10;
|
||||
int num_phi_bins = 20;
|
||||
//Populations.add(new E_Population(timer, rngUni, rngNormal));
|
||||
Populations.add(new Thermal_Katrin_Base(electron, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins));
|
||||
Populations.add(new Thermal_Katrin_Base(tritiumI, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins));
|
||||
Populations.add(new Thermal_Katrin_Base(tritium2I, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins));
|
||||
int num_E_bins = 20;
|
||||
|
||||
Populations.add(new Kinetic_Population(electron, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins, num_E_bins));
|
||||
Populations.add(new Thermal_Population(tritiumI, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins));
|
||||
Populations.add(new Thermal_Population(tritium2I, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins));
|
||||
Populations.add(new T2_Population(rngUni, rngNormal));
|
||||
|
||||
return (Populations);
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
//
|
||||
// population_load_saver.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 11.06.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "population_load_saver.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
void Population_Load_Saver::save() {
|
||||
if (all_species.size()<1) {
|
||||
stringstream ss;
|
||||
ss<<"Population_Load_Saver::save: No Populations to save. \n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
ofstream save_stream(get_save_path());
|
||||
write_overhead(&save_stream);
|
||||
for (vector<species>::iterator Itr = all_species.begin(); Itr!= all_species.end(); Itr++) {
|
||||
write_species(&save_stream, *Itr);
|
||||
}
|
||||
save_stream.close();
|
||||
}
|
||||
|
||||
string Population_Load_Saver::get_save_path() {
|
||||
string parameter_name = get_parameter_filename();
|
||||
stringstream save_path;
|
||||
save_path<<parameter_name<<"_save_populations.dat";
|
||||
return(save_path.str());
|
||||
}
|
||||
|
||||
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<<all_species.size()<<"\t # Number of Populations \n";
|
||||
|
||||
*save_stream<<timer->get_physTime_s()<<"\t # Offset Time in seconds \n";
|
||||
|
||||
*save_stream<<Katrin_Geo::get_z_RW_m()<<"\t";
|
||||
*save_stream<<Katrin_Geo::get_z_WGTSstart_m()<<"\t";
|
||||
*save_stream<<Katrin_Geo::get_z_WGTSend_m()<<"\t";
|
||||
*save_stream<<Katrin_Geo::get_radius_m()<<"\t";
|
||||
*save_stream<<" # 1. rear wall pos 2. WGTS start pos 3. WGTS end pos 4. WGTS radius all pos in m \n";
|
||||
|
||||
*save_stream<<load_parameter("wgtsT2MaxDensity_m3")<<"\t";
|
||||
*save_stream<<load_parameter("wgtsTemp_K")<<"\t";
|
||||
*save_stream<<load_parameter("wgtsT2FlowSpeed_ms")<<"\t";
|
||||
*save_stream<<" #1. wgtsT2MaxDensity_m3 2. wgtsTemp_K 3. wgtsT2FlowSpeed_ms \n";
|
||||
|
||||
*save_stream<<"# Start of populations data \n";
|
||||
*save_stream<<"# z_bin \t r_bin \t phi_bin \t E_bin \t cumulated_times_s \t number_annhilated \n";
|
||||
}
|
||||
|
||||
void Population_Load_Saver::write_species(ofstream *save_stream, species this_species) {
|
||||
Population_Base *pop = populations->find(this_species);
|
||||
bin_count4 number_bins = pop->get_bin_count4();
|
||||
bin_content_vec bins = pop->get_bins_content();
|
||||
|
||||
*save_stream<<get_species_string(this_species)<<"\t #species name \n";
|
||||
|
||||
for (int i = 0; i<4; i++) {
|
||||
*save_stream<<number_bins[i]<<"\t";
|
||||
}
|
||||
*save_stream<<"#number_bins of 1. z_scale 2. r_scale 3. phi_scale 4. E_scale \n";
|
||||
for (bin_content_vec::iterator Itr = bins.begin(); Itr != bins.end(); Itr++) {
|
||||
*save_stream<<Itr->z_bin<<"\t";
|
||||
*save_stream<<Itr->r_bin<<"\t";
|
||||
*save_stream<<Itr->phi_bin<<"\t";
|
||||
*save_stream<<Itr->E_bin<<"\t";
|
||||
*save_stream<<Itr->cumulated_time_s<<"\t";
|
||||
*save_stream<<Itr->offset<<"\n";
|
||||
}
|
||||
*save_stream<<"end_of_species \n";
|
||||
}
|
||||
|
||||
void Population_Load_Saver::load() {
|
||||
string load_path = get_enviroment_variable("pop_load_path");
|
||||
if (load_path.empty()) {
|
||||
cout<<"No File specified for Population default loading.\n";
|
||||
return;
|
||||
}
|
||||
std::ifstream load_stream(load_path);
|
||||
if (!load_stream.good()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Population_Load_Saver::load: Could not open file.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
goto_nextline(&load_stream); //ignore first line
|
||||
int number_populations = get_num_populations_line(&load_stream);
|
||||
double offset_time_s = get_offset_time_line(&load_stream);
|
||||
timer->set_offset_time_s(offset_time_s);
|
||||
check_katrin_geo_line(&load_stream);
|
||||
check_katrin_T2_line(&load_stream);
|
||||
goto_nextline(&load_stream);
|
||||
goto_nextline(&load_stream);
|
||||
|
||||
vector<species> check_vector;
|
||||
species current_species;
|
||||
for (int i = 0; i< number_populations; i++) {
|
||||
current_species = get_species_line(&load_stream);
|
||||
append_check_vector(&check_vector, current_species);
|
||||
load_species(&load_stream, current_species);
|
||||
}
|
||||
load_stream.close();
|
||||
cout<<"Loading Offset Values for Populations sucessful.\n";
|
||||
}
|
||||
|
||||
void Population_Load_Saver::goto_nextline(ifstream *load_stream) {
|
||||
load_stream->ignore(std::numeric_limits<streamsize>::max(), '\n');
|
||||
}
|
||||
|
||||
int Population_Load_Saver::get_num_populations_line(ifstream *load_stream) {
|
||||
int num_populations;
|
||||
*load_stream>>num_populations;
|
||||
goto_nextline(load_stream);
|
||||
if (num_populations < 1) {
|
||||
std::stringstream ss;
|
||||
ss<<"Population_Load_Saver::get_num_populations_line: num_populations < 1.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return (num_populations);
|
||||
}
|
||||
|
||||
double Population_Load_Saver::get_offset_time_line(std::ifstream *load_stream) {
|
||||
double offset_time_s;
|
||||
*load_stream>>offset_time_s;
|
||||
goto_nextline(load_stream);
|
||||
return (offset_time_s);
|
||||
}
|
||||
|
||||
void Population_Load_Saver::check_katrin_geo_line(std::ifstream *load_stream) {
|
||||
double z_RW_m, z_WGTSstart_m, z_WGTSend_m, radius_m;
|
||||
*load_stream>>z_RW_m;
|
||||
if ( z_RW_m != Katrin_Geo::get_z_RW_m()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Population_Load_Saver::check_katrin_geo_line: z_RW missmatch.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
*load_stream>>z_WGTSstart_m;
|
||||
if ( z_WGTSstart_m != Katrin_Geo::get_z_WGTSstart_m()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Population_Load_Saver::check_katrin_geo_line: z_WGTSstart missmatch.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
*load_stream>>z_WGTSend_m;
|
||||
if ( z_WGTSend_m != Katrin_Geo::get_z_WGTSend_m()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Population_Load_Saver::check_katrin_geo_line: z_WGTSend missmatch.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
*load_stream>>radius_m;
|
||||
if ( radius_m != Katrin_Geo::get_radius_m()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Population_Load_Saver::check_katrin_geo_line: radius missmatch.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
goto_nextline(load_stream);
|
||||
}
|
||||
|
||||
void Population_Load_Saver::check_katrin_T2_line(std::ifstream *load_stream) {
|
||||
double wgtsT2MaxDensity_m3, wgtsTemp_K, wgtsT2FlowSpeed_ms;
|
||||
*load_stream>>wgtsT2MaxDensity_m3;
|
||||
if ( wgtsT2MaxDensity_m3 != load_parameter("wgtsT2MaxDensity_m3")) {
|
||||
cout<<"Warning while loading populations: wgtsT2MaxDensity_m3 missmatch.\n";
|
||||
}
|
||||
*load_stream>>wgtsTemp_K;
|
||||
if ( wgtsTemp_K != load_parameter("wgtsTemp_K")) {
|
||||
cout<<"Warning while loading populations: wgtsTemp_K missmatch.\n";
|
||||
}
|
||||
*load_stream>>wgtsT2FlowSpeed_ms;
|
||||
if ( wgtsT2FlowSpeed_ms != load_parameter("wgtsT2FlowSpeed_ms")) {
|
||||
cout<<"Warning while loading populations: wgtsT2FlowSpeed_ms missmatch.\n";
|
||||
}
|
||||
goto_nextline(load_stream);
|
||||
}
|
||||
|
||||
species Population_Load_Saver::get_species_line(std::ifstream *load_stream) {
|
||||
string species_string;
|
||||
*load_stream>>species_string;
|
||||
goto_nextline(load_stream);
|
||||
return get_species_from_string(species_string);
|
||||
}
|
||||
|
||||
void Population_Load_Saver::append_check_vector(std::vector<species> *check_vector, species add_species) {
|
||||
for (std::vector<species>::iterator Itr=check_vector->begin(); Itr!=check_vector->end(); Itr++) {
|
||||
if (*Itr == add_species) {
|
||||
std::stringstream ss;
|
||||
ss<<"Population_Load_Saver::append_check_vector: species already loaded.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
check_vector->push_back(add_species);
|
||||
}
|
||||
|
||||
void Population_Load_Saver::load_species(std::ifstream *load_stream, species add_species) {
|
||||
bin_count4 bin_counts;
|
||||
*load_stream>>bin_counts[0];
|
||||
*load_stream>>bin_counts[1];
|
||||
*load_stream>>bin_counts[2];
|
||||
*load_stream>>bin_counts[3];
|
||||
|
||||
int number_content_lines = 1;
|
||||
for (int i = 0; i<4;i++) {
|
||||
number_content_lines *= (bin_counts[i]+1);
|
||||
}
|
||||
bin_content_vec bin_contents;
|
||||
pop_bin_content temp;
|
||||
for (int i = 0; i<number_content_lines; i++) {
|
||||
*load_stream>>temp.z_bin;
|
||||
*load_stream>>temp.r_bin;
|
||||
*load_stream>>temp.phi_bin;
|
||||
*load_stream>>temp.E_bin;
|
||||
*load_stream>>temp.cumulated_time_s;
|
||||
*load_stream>>temp.offset;
|
||||
goto_nextline(load_stream);
|
||||
bin_contents.push_back(temp);
|
||||
}
|
||||
string end_of_species;
|
||||
*load_stream>>end_of_species;
|
||||
if (end_of_species!="end_of_species") {
|
||||
std::stringstream ss;
|
||||
ss<<"Population_Load_Saver::load_species: Missmatch in number of lines..\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
populations->find(add_species)->set_bins(bin_counts, bin_contents);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// population_load_saver.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 11.06.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef population_load_saver_hpp
|
||||
#define population_load_saver_hpp
|
||||
|
||||
#include "population_builder.hpp"
|
||||
|
||||
class Population_Load_Saver {
|
||||
std::vector <species> all_species;
|
||||
Population_Manager *populations;
|
||||
Timer *timer;
|
||||
|
||||
public:
|
||||
Population_Load_Saver() {};
|
||||
Population_Load_Saver(Population_Manager *populations, Timer *timer) {
|
||||
this->populations = populations;
|
||||
this->timer = timer;
|
||||
|
||||
all_species.push_back(electron);
|
||||
all_species.push_back(tritiumI);
|
||||
all_species.push_back(tritium2I);
|
||||
}
|
||||
|
||||
void save();
|
||||
private:
|
||||
std::string get_save_path();
|
||||
void write_overhead(std::ofstream *save_stream);
|
||||
void write_species(std::ofstream *save_stream, species this_species);
|
||||
|
||||
|
||||
public:
|
||||
void load();
|
||||
private:
|
||||
void goto_nextline(std::ifstream *load_stream);
|
||||
int get_num_populations_line(std::ifstream *load_stream);
|
||||
double get_offset_time_line(std::ifstream *load_stream);
|
||||
void check_katrin_geo_line(std::ifstream *load_stream);
|
||||
void check_katrin_T2_line(std::ifstream *load_stream);
|
||||
species get_species_line(std::ifstream *load_stream);
|
||||
void append_check_vector(std::vector<species> *check_vector, species add_species);
|
||||
void load_species(std::ifstream *load_stream, species add_species);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* population_load_saver_hpp */
|
||||
@@ -1,53 +1,116 @@
|
||||
//
|
||||
// population_logger_base.h
|
||||
// Population_Logger.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
|
||||
#ifndef Population_Logger_h
|
||||
#define Population_Logger_h
|
||||
|
||||
#include "population_base.h"
|
||||
#include "timer.hpp"
|
||||
|
||||
class Population_Logger_Base {
|
||||
#include "h5tb_population_interface.hpp"
|
||||
#include "h5tb_population_meta_interface.hpp"
|
||||
|
||||
class Population_Logger {
|
||||
Population_Base *pop;
|
||||
Timer *timer;
|
||||
H5TB_Population_Interface h5tb;
|
||||
H5TB_Population_Meta_Interface h5tb_meta;
|
||||
|
||||
public:
|
||||
Population_Logger_Base() {};
|
||||
virtual void log(int number_decay) = 0;
|
||||
Population_Logger(Population_Base *pop, Timer *timer, hid_t *h5g);
|
||||
|
||||
private:
|
||||
void create_h5tb_meta(hid_t *h5g);
|
||||
void create_h5tb(hid_t *h5g);
|
||||
|
||||
public:
|
||||
void log();
|
||||
private:
|
||||
pop_log_bin transform(pop_bin_content pop_bin);
|
||||
};
|
||||
|
||||
inline Population_Logger::Population_Logger(Population_Base *pop, Timer *timer, hid_t *h5g) {
|
||||
this->pop = pop;
|
||||
this->timer = timer;
|
||||
create_h5tb_meta(h5g);
|
||||
create_h5tb(h5g);
|
||||
};
|
||||
|
||||
inline void Population_Logger::create_h5tb_meta(hid_t *h5g) {
|
||||
std::stringstream ss;
|
||||
ss<<get_species_string(pop->get_species())<<"_meta_data";
|
||||
h5tb_meta = H5TB_Population_Meta_Interface(ss.str(), h5g);
|
||||
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) {
|
||||
std::string species_string = get_species_string(pop->get_species());
|
||||
h5tb = H5TB_Population_Interface(species_string, h5g);
|
||||
}
|
||||
|
||||
inline void Population_Logger::log() {
|
||||
bin_content_vec bins_content = pop->get_bins_content();
|
||||
pop_log_bin temp;
|
||||
for (bin_content_vec::iterator Itr = bins_content.begin(); Itr != bins_content.end(); Itr++) {
|
||||
temp = transform(*Itr);
|
||||
h5tb.write(temp);
|
||||
}
|
||||
}
|
||||
|
||||
inline pop_log_bin Population_Logger::transform(pop_bin_content pop_bin) {
|
||||
pop_log_bin res;
|
||||
res.phys_time_s = timer->get_physTime_s();
|
||||
res.z_bin = pop_bin.z_bin;
|
||||
res.z_bin = pop_bin.r_bin;
|
||||
res.z_bin = pop_bin.phi_bin;
|
||||
res.z_bin = pop_bin.E_bin;
|
||||
res.z_bin = pop_bin.cumulated_time_s;
|
||||
res.z_bin = pop_bin.offset;
|
||||
return res;
|
||||
}
|
||||
|
||||
class Population_Logger_Manager {
|
||||
Population_Logger_Base **population_loggers;
|
||||
Population_Logger **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; i<num_loggers; i++) {
|
||||
population_loggers[i]->log(numberDecays);
|
||||
}
|
||||
}
|
||||
void add(Population_Logger *new_population_logger);
|
||||
void log();
|
||||
};
|
||||
|
||||
inline void Population_Logger_Manager::add(Population_Logger *new_population_logger) {
|
||||
if (num_loggers != 0) {
|
||||
Population_Logger *tempArray[num_loggers];
|
||||
for (int i = 0; i < num_loggers; i++) {
|
||||
tempArray[i] = population_loggers[i];
|
||||
}
|
||||
delete[] population_loggers;
|
||||
population_loggers = new Population_Logger *[num_loggers + 1];
|
||||
for (int i = 0; i < num_loggers; i++) {
|
||||
population_loggers[i] = tempArray[i];
|
||||
}
|
||||
} else {
|
||||
population_loggers = new Population_Logger *[num_loggers + 1];
|
||||
}
|
||||
population_loggers[num_loggers] = new_population_logger;
|
||||
num_loggers += 1;
|
||||
}
|
||||
|
||||
#endif /* population_logger_base_h */
|
||||
inline void Population_Logger_Manager::log() {
|
||||
for (int i=0; i<num_loggers; i++) {
|
||||
population_loggers[i]->log();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* Population_Logger_h */
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
|
||||
species get_species() {return(this_species); }
|
||||
|
||||
void check (const species &check_species) {
|
||||
void check(const species &check_species) {
|
||||
if (check_species != this_species) {
|
||||
std::stringstream ss;
|
||||
ss<<"Process_Base::check this_species missmatch.\n";
|
||||
|
||||
@@ -19,90 +19,90 @@
|
||||
#include "error_types.h"
|
||||
|
||||
|
||||
inline double getParameterValue(std::string lineFromFile) {
|
||||
inline double get_parameter_value(std::string csv_line) {
|
||||
std::stringstream ss;
|
||||
ss.str(lineFromFile);
|
||||
std::string nameDummy;
|
||||
double parValue = NAN;
|
||||
if ( !(ss>>nameDummy && ss>>parValue) ) {
|
||||
std::stringstream sserr;
|
||||
sserr<<"isParameterLine: Could not read line.\n";
|
||||
throw MyException(sserr.str());
|
||||
ss.str(csv_line);
|
||||
std::string dummy;
|
||||
double parameter_value = NAN;
|
||||
if ( !(ss>>dummy && ss>>parameter_value) ) {
|
||||
std::stringstream ss_err;
|
||||
ss_err<<"get_parameter_value: Could not read line.\n";
|
||||
throw MyException(ss_err.str());
|
||||
}
|
||||
return (parValue);
|
||||
return (parameter_value);
|
||||
}
|
||||
|
||||
inline bool isParameterLine(std::string lineFromFile, const std::string &parName) {
|
||||
inline bool is_parameter_line(std::string csv_line, const std::string ¶meter_name) {
|
||||
std::stringstream ss;
|
||||
ss.str(lineFromFile);
|
||||
std::string parNameTemp;
|
||||
if ( !(ss>>parNameTemp) ) {
|
||||
std::stringstream sserr;
|
||||
sserr<<"isParameterLine: Could not read line.\n";
|
||||
throw MyException(sserr.str());
|
||||
ss.str(csv_line);
|
||||
std::string temp;
|
||||
if ( !(ss>>temp) ) {
|
||||
std::stringstream ss_err;
|
||||
ss_err<<"is_parameter_line: Could not read line.\n";
|
||||
throw MyException(ss_err.str());
|
||||
}
|
||||
if (parNameTemp == parName) {
|
||||
if (temp == parameter_name) {
|
||||
return (true);
|
||||
} else {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool isFaulty(std::string lineFromFile) {
|
||||
inline bool is_faulty(std::string csv_line) {
|
||||
std::stringstream ss;
|
||||
ss.str(lineFromFile);
|
||||
std::string nameDummy;
|
||||
double valueDummy;
|
||||
if (ss>>nameDummy && ss>>valueDummy) {
|
||||
ss.str(csv_line);
|
||||
std::string name_dummy;
|
||||
double value_dummy;
|
||||
if (ss>>name_dummy && ss>>value_dummy) {
|
||||
return (false);
|
||||
} else {
|
||||
return (true);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool checkIgnoreLine(const std::string &lineFromFile) { // true if line is empty or starts with #
|
||||
if (lineFromFile[0] =='#') {
|
||||
inline bool check_ignore_line(const std::string &csv_line) { // true if line is empty or starts with #
|
||||
if (csv_line[0] =='#') {
|
||||
return true;
|
||||
} else if ( lineFromFile.empty() ) {
|
||||
} else if ( csv_line.empty() ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline void replaceDelimiter(std::string &lineFromFile) { // replaces delimiter (';'',''=') with whitespace
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ';', ' ');
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ',', ' ');
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), '=', ' ');
|
||||
inline void replace_delimiter(std::string &csv_line) { // replaces delimiter (';'',''=') with whitespace
|
||||
replace(csv_line.begin(), csv_line.end(), ';', ' ');
|
||||
replace(csv_line.begin(), csv_line.end(), ',', ' ');
|
||||
replace(csv_line.begin(), csv_line.end(), '=', ' ');
|
||||
}
|
||||
|
||||
inline void removeLeadingWhites(std::string &lineFromFile) {
|
||||
static const std::string WHITESPACE = " \n\r\t\f\v";
|
||||
size_t start = lineFromFile.find_first_not_of(WHITESPACE);
|
||||
lineFromFile = (start == std::string::npos) ? "" : lineFromFile.substr(start);
|
||||
inline void remove_leading_whites(std::string &csv_line) {
|
||||
static const std::string whitespaces = " \n\r\t\f\v";
|
||||
size_t start = csv_line.find_first_not_of(whitespaces);
|
||||
csv_line = (start == std::string::npos) ? "" : csv_line.substr(start);
|
||||
}
|
||||
|
||||
inline double findParameter(std::ifstream *fileStream, const std::string &parName) {
|
||||
std::string lineFromFile;
|
||||
double parValue = NAN;
|
||||
while (getline(*fileStream, lineFromFile)) {
|
||||
removeLeadingWhites(lineFromFile);
|
||||
replaceDelimiter(lineFromFile);
|
||||
if ( checkIgnoreLine(lineFromFile) ) {
|
||||
inline double find_parameter(std::ifstream *parameter_file_stream, const std::string ¶meter_name) {
|
||||
std::string csv_line;
|
||||
double parameter_value = NAN;
|
||||
while (getline(*parameter_file_stream, csv_line)) {
|
||||
remove_leading_whites(csv_line);
|
||||
replace_delimiter(csv_line);
|
||||
if ( check_ignore_line(csv_line) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( isFaulty(lineFromFile) ) {
|
||||
std::cout<<"Line in parameter file faulty.\n\tline:\t"<<lineFromFile<<"\n";
|
||||
} else if ( isParameterLine(lineFromFile, parName) ) {
|
||||
parValue = getParameterValue(lineFromFile);
|
||||
if ( is_faulty(csv_line) ) {
|
||||
std::cout<<"Line in parameter file faulty.\n\tline:\t"<<csv_line<<"\n";
|
||||
} else if ( is_parameter_line(csv_line, parameter_name) ) {
|
||||
parameter_value = get_parameter_value(csv_line);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (parValue);
|
||||
return (parameter_value);
|
||||
}
|
||||
|
||||
inline std::string makePath (const std::string &path) { // append '/' if necessary to path.
|
||||
inline std::string make_path (const std::string &path) { // append '/' if necessary to path.
|
||||
if (path.back() != '/') {
|
||||
return (path + '/');
|
||||
} else {
|
||||
@@ -110,45 +110,45 @@ inline std::string makePath (const std::string &path) { // append '/' if necessa
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string getEnv (const std::string &envName) { // string version of C function getenv.
|
||||
inline std::string get_enviroment_variable (const std::string &envName) { // string version of C function getenv.
|
||||
char * val = getenv( envName.c_str() );
|
||||
return val == NULL ? std::string("") : std::string(val);
|
||||
}
|
||||
|
||||
inline std::string getParameterLoadFilePath() {
|
||||
std::string parpath = getEnv("parpath");
|
||||
if (parpath == "") {
|
||||
inline std::string get_parameter_file_path() {
|
||||
std::string parameter_file_path = get_enviroment_variable("parpath");
|
||||
if (parameter_file_path == "") {
|
||||
throw MyException("Parameter::getParameter: Environment variable parpath not defined.");
|
||||
}
|
||||
std::string parfile = getEnv("parfile");
|
||||
if (parfile == "") {
|
||||
std::string parameter_file_name = get_enviroment_variable("parfile");
|
||||
if (parameter_file_name == "") {
|
||||
throw MyException("Parameter::getParameter: Environment variable parfile not defined.");
|
||||
}
|
||||
|
||||
parpath = makePath(parpath);
|
||||
return (parpath + parfile);
|
||||
parameter_file_path = make_path(parameter_file_path);
|
||||
return (parameter_file_path + parameter_file_name);
|
||||
}
|
||||
|
||||
inline double getParameter(const std::string &parName) {
|
||||
std::string loadFilePath = getParameterLoadFilePath();
|
||||
std::ifstream fileStream(loadFilePath);
|
||||
if (!fileStream.good()) {
|
||||
inline double load_parameter(const std::string ¶meter_name) {
|
||||
std::string parameter_file_path = get_parameter_file_path();
|
||||
std::ifstream parameter_file_stream(parameter_file_path);
|
||||
if (!parameter_file_stream.good()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Parameter::getParameter: Could not open file.\n loadFilePath:\t"<<loadFilePath<<"\n";
|
||||
ss<<"Parameter::getParameter: Could not open file.\n loadFilePath:\t"<<parameter_file_path<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double parValue = findParameter(&fileStream, parName);
|
||||
double parameter_value = find_parameter(¶meter_file_stream, parameter_name);
|
||||
|
||||
if ( isnan(parValue) ) {
|
||||
if ( isnan(parameter_value) ) {
|
||||
std::stringstream ss;
|
||||
ss<<"Parameter::getParameter: Parameter not found in file.\n parName:\t"<<parName<<"\n loadFilePath: \t"<<loadFilePath;
|
||||
ss<<"Parameter::getParameter: Parameter not found in file.\n parameter_name:\t"<<parameter_name<<"\n loadFilePath: \t"<<parameter_file_path;
|
||||
throw MyException(ss.str());
|
||||
} else {
|
||||
return (parValue);
|
||||
return (parameter_value);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string getTimeString() {
|
||||
inline std::string get_time_string() {
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
char buffer[80];
|
||||
@@ -159,38 +159,38 @@ inline std::string getTimeString() {
|
||||
return(str);
|
||||
}
|
||||
|
||||
inline std::string getHomebase() {
|
||||
std::string Homebase = getEnv("HOMEBASE");
|
||||
Homebase = makePath(Homebase);
|
||||
inline std::string get_homebase() {
|
||||
std::string Homebase = get_enviroment_variable("HOMEBASE");
|
||||
Homebase = make_path(Homebase);
|
||||
return (Homebase);
|
||||
}
|
||||
|
||||
inline std::string getDataPath() {
|
||||
return (getHomebase() + "src/mc_electron/data/");
|
||||
inline std::string get_data_path() {
|
||||
return (get_homebase() + "src/mc_electron/data/");
|
||||
}
|
||||
|
||||
inline std::string remove_catEnding (std::string inString) {
|
||||
if ( inString.substr(inString.size()-4, 4) == ".cat" ){
|
||||
return (inString.substr(0, inString.size()-4) );
|
||||
inline std::string remove_cat (std::string cat_string) {
|
||||
if ( cat_string.substr(cat_string.size()-4, 4) == ".cat" ){
|
||||
return (cat_string.substr(0, cat_string.size()-4) );
|
||||
} else {
|
||||
return (inString);
|
||||
return (cat_string);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string getparName() {
|
||||
std::string parpath = getenv("parpath");
|
||||
std::string parfile = remove_catEnding(getenv("parfile"));
|
||||
return (parpath + "/" + parfile);
|
||||
inline std::string get_parameter_filename() {
|
||||
std::string parameter_file_path = getenv("parpath");
|
||||
std::string parameter_file_name = remove_cat(getenv("parfile"));
|
||||
return (parameter_file_path + "/" + parameter_file_name);
|
||||
}
|
||||
|
||||
inline bool isFile(std::string fileName) {
|
||||
inline bool is_file(std::string file_path) {
|
||||
struct stat buffer;
|
||||
return (stat (fileName.c_str(), &buffer) == 0);
|
||||
return (stat (file_path.c_str(), &buffer) == 0);
|
||||
}
|
||||
|
||||
inline bool isDir(std::string dirPath) {
|
||||
inline bool is_dir(std::string dir_path) {
|
||||
struct stat info;
|
||||
if( stat( dirPath.c_str(), &info ) != 0 )
|
||||
if( stat( dir_path.c_str(), &info ) != 0 )
|
||||
return (false);
|
||||
else if( info.st_mode & S_IFDIR ) // S_ISDIR() doesn't exist on my windows
|
||||
return (true);
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
const long int Simulation::seed = getParameter("seed");
|
||||
const long int Simulation::numberTotalDecays = getParameter("numberTotalDecays");
|
||||
const long int Simulation::seed = load_parameter("seed");
|
||||
const long int Simulation::numberTotalDecays = load_parameter("numberTotalDecays");
|
||||
|
||||
void Simulation::init() {
|
||||
set_RNGs();
|
||||
@@ -26,7 +26,8 @@ void Simulation::init() {
|
||||
interactions = Interaction_Builder::build(&populations, &rngUni);
|
||||
terminators = Terminator_Builder::build();
|
||||
|
||||
pop_loggers = Population_Logger_Builder::build(&h5f, &populations);
|
||||
pop_loggers = Population_Logger_Builder::build(&h5f, &populations, &timer);
|
||||
pop_load_saver = Population_Load_Saver(&populations, &timer);
|
||||
|
||||
set_statusUpdater();
|
||||
}
|
||||
@@ -53,7 +54,7 @@ void Simulation::doit() {
|
||||
vec3 oldLoc_m;
|
||||
while ( (numberDecays < numberTotalDecays) || (!partQue.empty()) ) {
|
||||
if (partQue.empty()) {
|
||||
pop_loggers.log(numberDecays);
|
||||
pop_loggers.log();
|
||||
curPart = injector.injectElectron(numberTotalParticles);
|
||||
numberDecays++;
|
||||
numberTotalParticles++;
|
||||
@@ -78,7 +79,7 @@ void Simulation::doit() {
|
||||
partQue.back().set_Id(numberTotalParticles++);
|
||||
}
|
||||
if (IntOut.get_decrease_population()) {
|
||||
populations.find(IntOut.get_decrease_species())->decrease_denisty(IntOut.get_decrease_location());
|
||||
populations.find(IntOut.get_decrease_species())->decrease_denisty(IntOut.get_decrease_location(), IntOut.get_decrease_energy_eV());
|
||||
}
|
||||
if (IntOut.get_delete_current()) {
|
||||
break;
|
||||
@@ -86,7 +87,7 @@ void Simulation::doit() {
|
||||
}
|
||||
}
|
||||
}
|
||||
pop_loggers.log(numberDecays);
|
||||
pop_loggers.log();
|
||||
};
|
||||
|
||||
|
||||
@@ -148,10 +149,10 @@ void Simulation::do_interaction(Electron *interactElectron) {
|
||||
|
||||
void Simulation::parameterCheck_TC6() {
|
||||
if (
|
||||
getParameter("injectionMethod") == 1 &&
|
||||
getParameter("elaOn") == 0 &&
|
||||
getParameter("ionOn") == 1 &&
|
||||
getParameter("numberZBins") == -1
|
||||
load_parameter("injectionMethod") == 1 &&
|
||||
load_parameter("elaOn") == 0 &&
|
||||
load_parameter("ionOn") == 1 &&
|
||||
load_parameter("numberZBins") == -1
|
||||
) {
|
||||
return;
|
||||
}else {
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include "interaction_builder.hpp"
|
||||
#include "terminator_builder.hpp"
|
||||
|
||||
#include "population_load_saver.hpp"
|
||||
|
||||
|
||||
class Simulation {
|
||||
static const long int seed;
|
||||
@@ -41,6 +43,9 @@ class Simulation {
|
||||
Terminator_Manager terminators;
|
||||
|
||||
Population_Logger_Manager pop_loggers;
|
||||
Population_Load_Saver pop_load_saver;
|
||||
|
||||
|
||||
int numberTotalParticles = 0;
|
||||
int numberDecays = 0;
|
||||
|
||||
@@ -50,7 +55,12 @@ class Simulation {
|
||||
public:
|
||||
Simulation() {
|
||||
init();
|
||||
pop_load_saver.load();
|
||||
}
|
||||
~Simulation() {
|
||||
pop_load_saver.save();
|
||||
}
|
||||
|
||||
private:
|
||||
void init();
|
||||
void set_RNGs();
|
||||
|
||||
@@ -7,3 +7,63 @@
|
||||
//
|
||||
|
||||
#include "size_container.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
Size_Container::Size_Container(int num_z_bins, int num_r_bins, int num_phi_bins) {
|
||||
r_scale = Lin_Scale(0, Katrin_Geo::get_radius_m(), num_r_bins);
|
||||
cell_length_m = (Katrin_Geo::get_z_WGTSend_m()-Katrin_Geo::get_z_RW_m()) / (num_z_bins);
|
||||
|
||||
data = new double[num_r_bins];
|
||||
for (int i = 0; i<num_r_bins; i++) {
|
||||
data[i] = cell_length_m * calc_disc_surface_m2(i)/num_phi_bins;
|
||||
}
|
||||
}
|
||||
|
||||
Size_Container::~Size_Container() {
|
||||
delete[] data;
|
||||
};
|
||||
|
||||
Size_Container::Size_Container(const Size_Container& other) {
|
||||
r_scale = other.r_scale;
|
||||
cell_length_m = other.cell_length_m;
|
||||
int number_bins = r_scale.get_number_bins();
|
||||
data = new double [number_bins];
|
||||
for (int i = 0; i < number_bins; i++) {
|
||||
data[i] = other.data[i];
|
||||
}
|
||||
}
|
||||
|
||||
Size_Container& Size_Container::operator=(const Size_Container& other) {
|
||||
Size_Container tmp(other);
|
||||
swap(r_scale, tmp.r_scale);
|
||||
swap(cell_length_m, tmp.cell_length_m);
|
||||
swap(data, tmp.data);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
|
||||
double Size_Container::calc_disc_surface_m2 (const int &r_bin) {
|
||||
double previous_r_m = r_scale.get_lower_bin_bound(r_bin);
|
||||
double this_r_m = r_scale.get_upper_bin_bound(r_bin);
|
||||
double A_m2 = pi * (this_r_m * this_r_m - previous_r_m * previous_r_m);
|
||||
return(A_m2);
|
||||
}
|
||||
|
||||
double Size_Container::get_cell_volume_m3(const double &r_m) {
|
||||
int r_bin = r_scale.calc_index(r_m);
|
||||
return (data[r_bin]);
|
||||
}
|
||||
|
||||
double Size_Container::get_cell_volume_m3(const vec3 &loc_m) {
|
||||
double r_m = get_r_m(loc_m);
|
||||
return (get_cell_volume_m3(r_m));
|
||||
}
|
||||
|
||||
double Size_Container::get_cell_length_m() {
|
||||
return (cell_length_m);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,41 +19,17 @@ class Size_Container {
|
||||
double cell_length_m;
|
||||
|
||||
public:
|
||||
~Size_Container() {
|
||||
delete[] data;
|
||||
};
|
||||
|
||||
Size_Container(int num_z_bins, int num_r_bins, int num_phi_bins) {
|
||||
r_scale = Lin_Scale(0, Katrin_Geo::get_radius_m(), num_r_bins);
|
||||
cell_length_m = (Katrin_Geo::get_z_WGTSend_m()-Katrin_Geo::get_z_RW_m()) / (num_z_bins);
|
||||
|
||||
data = new double[num_r_bins];
|
||||
for (int i = 0; i<num_r_bins; i++) {
|
||||
data[i] = cell_length_m * calc_disc_surface_m2(i)/num_phi_bins;
|
||||
}
|
||||
}
|
||||
|
||||
double calc_disc_surface_m2 (const int &r_bin) {
|
||||
double previous_r_m = r_scale.get_lower_bin_bound(r_bin);
|
||||
double this_r_m = r_scale.get_upper_bin_bound(r_bin);
|
||||
double A_m2 = pi * (this_r_m * this_r_m - previous_r_m * previous_r_m);
|
||||
return(A_m2);
|
||||
}
|
||||
Size_Container() {};
|
||||
Size_Container(int num_z_bins, int num_r_bins, int num_phi_bins);
|
||||
~Size_Container();
|
||||
Size_Container(const Size_Container& other);
|
||||
Size_Container& operator=(const Size_Container& other);
|
||||
|
||||
double get_cell_volume_m3(const double &r_m) {
|
||||
int r_bin = r_scale.calc_index(r_m);
|
||||
return (data[r_bin]);
|
||||
}
|
||||
|
||||
double get_cell_volume_m3(const vec3 &loc_m) {
|
||||
double r_m = get_r_m(loc_m);
|
||||
return (get_cell_volume_m3(r_m));
|
||||
}
|
||||
|
||||
double get_cell_length_m() {
|
||||
return (cell_length_m);
|
||||
}
|
||||
|
||||
double calc_disc_surface_m2 (const int &r_bin);
|
||||
double get_cell_volume_m3(const double &r_m);
|
||||
double get_cell_volume_m3(const vec3 &loc_m);
|
||||
double get_cell_length_m();
|
||||
};
|
||||
|
||||
#endif /* size_container_hpp */
|
||||
|
||||
@@ -27,6 +27,7 @@ class InteractionOut {
|
||||
bool decrease_population;
|
||||
species decrease_species;
|
||||
vec3 decrease_location;
|
||||
double decrease_energy_eV;
|
||||
|
||||
public:
|
||||
InteractionOut() {reset();};
|
||||
@@ -47,16 +48,18 @@ public:
|
||||
int get_number_new_particles() {return(number_new_particles);}
|
||||
Particle *get_new_particles() {return(new_particles);}
|
||||
|
||||
void set_decrease_location (const species &decrease_species, const vec3 &decrease_location) {
|
||||
void set_decrease (const species &decrease_species, const vec3 &decrease_location, const double &decrease_energy_eV) {
|
||||
this->decrease_population = true;
|
||||
this->decrease_species = decrease_species;
|
||||
this->decrease_location = decrease_location;
|
||||
this->decrease_energy_eV = decrease_energy_eV;
|
||||
}
|
||||
|
||||
|
||||
bool get_decrease_population() {return decrease_population;}
|
||||
species get_decrease_species() {return decrease_species;}
|
||||
vec3 get_decrease_location() {return decrease_location;}
|
||||
double get_decrease_energy_eV() {return decrease_energy_eV;}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
#include "read_system.h"
|
||||
|
||||
const int Terminator_Builder::maxInteractions = getParameter("maxInteractions");
|
||||
const double Terminator_Builder::cutoffEnergy_eV = getParameter("cutoffEnergy_eV");
|
||||
const int Terminator_Builder::maxInteractions = load_parameter("maxInteractions");
|
||||
const double Terminator_Builder::cutoffEnergy_eV = load_parameter("cutoffEnergy_eV");
|
||||
|
||||
|
||||
Terminator_Manager Terminator_Builder::build() {
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
//
|
||||
// thermal_base.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 25.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef thermal_base_h
|
||||
#define thermal_base_h
|
||||
|
||||
#include "katrin_geo.hpp"
|
||||
|
||||
#include "population3_container.hpp"
|
||||
#include "size_container.hpp"
|
||||
|
||||
#include "population_base.h"
|
||||
|
||||
|
||||
class Thermal_Base : public Population_Base, protected RNG_Base{
|
||||
Pop3_Container cumulated_times_s;
|
||||
Pop3_Container number_annhilated;
|
||||
Size_Container bin_sizes;
|
||||
|
||||
Timer *timer;
|
||||
|
||||
|
||||
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),
|
||||
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;
|
||||
};
|
||||
Thermal_Base* get_thermal_base_ptr() {
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
double get_density_m3 (const vec3 &loc_m);
|
||||
void increase_density (const Particle &upPart, const vec3 &oldLoc_m);
|
||||
void decrease_denisty (const vec3 &loc_m);
|
||||
|
||||
|
||||
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 () {
|
||||
return(cumulated_times_s);}
|
||||
Pop3_Container get_number_annhilated_container () {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 = 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;
|
||||
return(dens_m3);
|
||||
}
|
||||
|
||||
inline void Thermal_Base::increase_density(const Particle &upPart, const vec3 &oldLoc_m) {
|
||||
double cell_time_s = bin_sizes.get_cell_length_m()/upPart.get_SpeedAbs_ms();
|
||||
cumulated_times_s.increase_value(cell_time_s, upPart.get_Location_m(), oldLoc_m);
|
||||
}
|
||||
|
||||
inline void Thermal_Base::decrease_denisty (const vec3 &loc_m) {
|
||||
number_annhilated.increase_value(1, loc_m);
|
||||
}
|
||||
|
||||
|
||||
#endif /* thermal_base_h */
|
||||
@@ -1,62 +0,0 @@
|
||||
//
|
||||
// thermal_katrin_base.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 27.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef thermal_katrin_base_h
|
||||
#define thermal_katrin_base_h
|
||||
|
||||
#include "thermal_base.h"
|
||||
|
||||
|
||||
class Thermal_Katrin_Base : public Thermal_Base {
|
||||
static const double wgtsTemp_K;
|
||||
static const double wgtsT2FlowSpeed_ms;
|
||||
|
||||
double m_eV;
|
||||
|
||||
public:
|
||||
Thermal_Katrin_Base(species this_species, Timer *timer, UniRNG *rngUni, NormalRNG *rngNormal, int num_z_bins, int num_r_bins, int num_phi_bins) : Thermal_Base(this_species, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins) {
|
||||
m_eV = get_species_mass(this_species);
|
||||
};
|
||||
|
||||
vec3 get_average_speed_ms(const vec3 &loc_m);
|
||||
vec3 roll_speed_ms(const vec3 &loc_m);
|
||||
private:
|
||||
vec3 roll_thermSpeed_ms(const vec3 &loc_m);
|
||||
};
|
||||
|
||||
|
||||
const double Thermal_Katrin_Base::wgtsTemp_K = getParameter("wgtsTemp_K");
|
||||
const double Thermal_Katrin_Base::wgtsT2FlowSpeed_ms = getParameter("wgtsT2FlowSpeed_ms");
|
||||
|
||||
inline vec3 Thermal_Katrin_Base::get_average_speed_ms(const vec3 &loc_m) {
|
||||
if (Katrin_Geo::inWGTS(loc_m)) {
|
||||
double z_wgtsHalf_m = Katrin_Geo::get_z_WGTSstart_m() + (Katrin_Geo::get_z_WGTSend_m() - Katrin_Geo::get_z_WGTSstart_m())/2;
|
||||
double sign = (loc_m[2] < z_wgtsHalf_m) ? -1 : 1;
|
||||
double zSpeed_ms = sign*wgtsT2FlowSpeed_ms;
|
||||
return ( vec3(0,0,zSpeed_ms) );
|
||||
} else {
|
||||
return (vec3(0,0,0));
|
||||
}
|
||||
}
|
||||
|
||||
inline vec3 Thermal_Katrin_Base::roll_speed_ms(const vec3 &loc_m) {
|
||||
Katrin_Geo::check_inKatrin(loc_m);
|
||||
return (get_average_speed_ms(loc_m) + roll_thermSpeed_ms(loc_m));
|
||||
}
|
||||
|
||||
|
||||
inline vec3 Thermal_Katrin_Base::roll_thermSpeed_ms(const vec3 &loc_m) {
|
||||
double E_eV = roll_MBEnergy(wgtsTemp_K, m_eV, rngNormal);
|
||||
double abs_speed_ms = calc_Speed_from_Ekin_eV(E_eV, m_eV);
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni)*abs_speed_ms;
|
||||
return(speed_ms);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* thermal_katrin_base_h */
|
||||
@@ -0,0 +1,243 @@
|
||||
//
|
||||
// Thermal_Population.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 25.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Thermal_Population_h
|
||||
#define Thermal_Population_h
|
||||
|
||||
#include "katrin_geo.hpp"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "population3_container.hpp"
|
||||
#include "size_container.hpp"
|
||||
#include "lin_scale.h"
|
||||
|
||||
#include "population_base.h"
|
||||
|
||||
|
||||
class Thermal_Population : public Population_Base, protected RNG_Base{
|
||||
Pop3_Container cumulated_times_s;
|
||||
Pop3_Container number_annhilated;
|
||||
|
||||
Size_Container bin_sizes;
|
||||
|
||||
Timer *timer;
|
||||
|
||||
static const double wgtsTemp_K;
|
||||
static const double wgtsT2FlowSpeed_ms;
|
||||
|
||||
double m_eV;
|
||||
|
||||
public:
|
||||
Thermal_Population(species this_species, Timer *timer, UniRNG *rngUni, NormalRNG *rngNormal, int num_z_bins, int num_r_bins, int num_phi_bins);
|
||||
private:
|
||||
void init_containers(int num_z_bins, int num_r_bins, int num_phi_bins);
|
||||
|
||||
public:
|
||||
double get_density_m3 (const vec3 &loc_m);
|
||||
void increase_density (const Particle &upPart, const vec3 &oldLoc_m);
|
||||
void decrease_denisty (const vec3 &loc_m, const double &energy_eV);
|
||||
|
||||
public:
|
||||
vec3 get_average_speed_ms (const vec3 &loc_m);
|
||||
vec3 roll_speed_ms (const vec3 &loc_m);
|
||||
private:
|
||||
vec3 roll_thermSpeed_ms(const vec3 &loc_m);
|
||||
|
||||
public:
|
||||
meta_vec get_bins_meta_info();
|
||||
bin_content_vec get_bins_content();
|
||||
bin_count4 get_bin_count4();
|
||||
void set_bins(bin_count4 bin_counts, bin_content_vec bin_contents);
|
||||
private:
|
||||
Lin_Scale get_z_scale();
|
||||
Lin_Scale get_r_scale();
|
||||
Lin_Scale get_phi_scale();
|
||||
|
||||
};
|
||||
|
||||
|
||||
const double Thermal_Population::wgtsTemp_K = load_parameter("wgtsTemp_K");
|
||||
const double Thermal_Population::wgtsT2FlowSpeed_ms = load_parameter("wgtsT2FlowSpeed_ms");
|
||||
|
||||
inline Thermal_Population::Thermal_Population(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) {
|
||||
this->timer = timer;
|
||||
init_containers(num_z_bins, num_r_bins, num_phi_bins);
|
||||
m_eV = get_species_mass(this_species);
|
||||
};
|
||||
|
||||
void Thermal_Population::init_containers(int num_z_bins, int num_r_bins, int num_phi_bins) {
|
||||
cumulated_times_s = Pop3_Container(num_z_bins, num_r_bins, num_phi_bins);
|
||||
number_annhilated = Pop3_Container(num_z_bins, num_r_bins, num_phi_bins);
|
||||
bin_sizes = Size_Container(num_z_bins, num_r_bins, num_phi_bins);
|
||||
}
|
||||
|
||||
inline double Thermal_Population::get_density_m3(const vec3 &loc_m) {
|
||||
//Katrin_Geo::check_inKatrin(loc_m);
|
||||
double physical_time_s = timer->get_physTime_s();
|
||||
double cumulated_time_s_s = cumulated_times_s.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 = cumulated_time_s_s/physical_time_s/bin_size_m3 - offset;
|
||||
dens_m3 = (dens_m3 < 0) ? zero : dens_m3;
|
||||
return(dens_m3);
|
||||
}
|
||||
|
||||
inline void Thermal_Population::increase_density(const Particle &upPart, const vec3 &oldLoc_m) {
|
||||
double cell_time_s = bin_sizes.get_cell_length_m()/upPart.get_SpeedAbs_ms();
|
||||
cumulated_times_s.increase_value(cell_time_s, upPart.get_Location_m(), oldLoc_m);
|
||||
}
|
||||
|
||||
inline void Thermal_Population::decrease_denisty (const vec3 &loc_m, const double &energy_eV) {
|
||||
number_annhilated.increase_value(1, loc_m);
|
||||
}
|
||||
|
||||
|
||||
inline vec3 Thermal_Population::get_average_speed_ms(const vec3 &loc_m) {
|
||||
if (Katrin_Geo::inWGTS(loc_m)) {
|
||||
double z_wgtsHalf_m = Katrin_Geo::get_z_WGTSstart_m() + (Katrin_Geo::get_z_WGTSend_m() - Katrin_Geo::get_z_WGTSstart_m())/2;
|
||||
double sign = (loc_m[2] < z_wgtsHalf_m) ? -1 : 1;
|
||||
double zSpeed_ms = sign*wgtsT2FlowSpeed_ms;
|
||||
return ( vec3(0,0,zSpeed_ms) );
|
||||
} else {
|
||||
return (vec3(0,0,0));
|
||||
}
|
||||
}
|
||||
|
||||
inline vec3 Thermal_Population::roll_speed_ms(const vec3 &loc_m) {
|
||||
Katrin_Geo::check_inKatrin(loc_m);
|
||||
return (get_average_speed_ms(loc_m) + roll_thermSpeed_ms(loc_m));
|
||||
}
|
||||
|
||||
inline vec3 Thermal_Population::roll_thermSpeed_ms(const vec3 &loc_m) {
|
||||
double E_eV = roll_MBEnergy(wgtsTemp_K, m_eV, rngNormal);
|
||||
double abs_speed_ms = calc_Speed_from_Ekin_eV(E_eV, m_eV);
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni)*abs_speed_ms;
|
||||
return(speed_ms);
|
||||
}
|
||||
|
||||
|
||||
inline meta_vec Thermal_Population::get_bins_meta_info() {
|
||||
Lin_Scale z_scale = get_z_scale();
|
||||
Lin_Scale r_scale = get_r_scale();
|
||||
Lin_Scale phi_scale = get_phi_scale();
|
||||
|
||||
meta_vec res;
|
||||
pop_bin_meta_info temp_bin = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
temp_bin.E_bin = 0;
|
||||
temp_bin.E_min_eV = NAN;
|
||||
temp_bin.E_max_eV = NAN;
|
||||
temp_bin.z_min_m = z_scale.get_lower_scale_end();
|
||||
for (int i_z=0; i_z<z_scale.get_number_bins(); i_z++) {
|
||||
temp_bin.z_bin = i_z;
|
||||
temp_bin.z_max_m = z_scale.get_upper_bin_bound(i_z);
|
||||
temp_bin.r_min_m = r_scale.get_lower_scale_end();
|
||||
for (int i_r=0; i_r<r_scale.get_number_bins(); i_r++) {
|
||||
temp_bin.r_bin = i_r;
|
||||
temp_bin.r_max_m = r_scale.get_upper_bin_bound(i_r);
|
||||
temp_bin.phi_min = phi_scale.get_lower_scale_end();
|
||||
for (int i_phi=0; i_phi<phi_scale.get_number_bins(); i_phi++) {
|
||||
temp_bin.phi_bin = i_phi;
|
||||
temp_bin.phi_max = phi_scale.get_upper_bin_bound(i_phi);
|
||||
res.push_back(temp_bin);
|
||||
temp_bin.phi_min = temp_bin.phi_max;
|
||||
}
|
||||
temp_bin.r_min_m = temp_bin.r_max_m;
|
||||
}
|
||||
temp_bin.z_min_m = temp_bin.z_max_m;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
inline bin_content_vec Thermal_Population::get_bins_content() {
|
||||
Lin_Scale z_scale = get_z_scale();
|
||||
Lin_Scale r_scale = get_r_scale();
|
||||
Lin_Scale phi_scale = get_phi_scale();
|
||||
|
||||
bin_content_vec res;
|
||||
pop_bin_content temp_bin = {0, 0, 0, 0, 0, 0};
|
||||
temp_bin.E_bin = -1;
|
||||
for (int i_z=0; i_z < z_scale.get_number_bins(); i_z++) {
|
||||
temp_bin.z_bin = i_z;
|
||||
for (int i_r=0; i_r < r_scale.get_number_bins(); i_r++) {
|
||||
temp_bin.r_bin = i_r;
|
||||
for (int i_phi=0; i_phi < phi_scale.get_number_bins(); i_phi++) {
|
||||
temp_bin.phi_bin = i_phi;
|
||||
temp_bin.cumulated_time_s = cumulated_times_s.get_value_by_bin(i_z, i_r, i_phi);
|
||||
temp_bin.offset = number_annhilated.get_value_by_bin(i_z, i_r, i_phi);
|
||||
res.push_back(temp_bin);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
inline bin_count4 Thermal_Population::get_bin_count4() {
|
||||
bin_count4 res;
|
||||
res[0] = get_z_scale().get_number_bins();
|
||||
res[1] = get_r_scale().get_number_bins();
|
||||
res[2] = get_phi_scale().get_number_bins();
|
||||
res[3] = 0;
|
||||
return(res);
|
||||
}
|
||||
|
||||
inline void Thermal_Population::set_bins(bin_count4 bin_counts, bin_content_vec bin_contents) {
|
||||
int num_z_bins = bin_counts[0];
|
||||
int num_r_bins = bin_counts[1];
|
||||
int num_phi_bins = bin_counts[2];
|
||||
init_containers(num_z_bins, num_r_bins, num_phi_bins);
|
||||
if (bin_counts[3]!=0) {
|
||||
std::stringstream ss;
|
||||
ss<<"Thermal_Population::set_bins: E_bins != 0.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
int z_bin, r_bin, phi_bin;
|
||||
double cumulated_time_s, offset;
|
||||
for(bin_content_vec::iterator Itr = bin_contents.begin(); Itr != bin_contents.end(); Itr++) {
|
||||
z_bin = (*Itr).z_bin;
|
||||
r_bin = (*Itr).r_bin;
|
||||
phi_bin = (*Itr).phi_bin;
|
||||
cumulated_time_s = (*Itr).cumulated_time_s;
|
||||
offset = (*Itr).offset;
|
||||
cumulated_times_s.set_value_by_bin(cumulated_time_s, z_bin, r_bin, phi_bin);
|
||||
number_annhilated.set_value_by_bin(offset, z_bin, r_bin, phi_bin);
|
||||
}
|
||||
}
|
||||
|
||||
inline Lin_Scale Thermal_Population::get_z_scale() {
|
||||
if (cumulated_times_s.get_z_scale() == number_annhilated.get_z_scale()) {
|
||||
return (cumulated_times_s.get_z_scale());
|
||||
} else {
|
||||
std::stringstream ss;
|
||||
ss<<"Thermal_Population::get_z_scale: Missmatch in scales.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
inline Lin_Scale Thermal_Population::get_r_scale() {
|
||||
if (cumulated_times_s.get_r_scale() == number_annhilated.get_r_scale()) {
|
||||
return (cumulated_times_s.get_r_scale());
|
||||
} else {
|
||||
std::stringstream ss;
|
||||
ss<<"Thermal_Population::get_r_scale: Missmatch in scales.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
inline Lin_Scale Thermal_Population::get_phi_scale() {
|
||||
if (cumulated_times_s.get_phi_scale() == number_annhilated.get_phi_scale()) {
|
||||
return (cumulated_times_s.get_phi_scale());
|
||||
} else {
|
||||
std::stringstream ss;
|
||||
ss<<"Thermal_Population::get_phi_scale: Missmatch in scales.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* Thermal_Population_h */
|
||||
@@ -1,129 +0,0 @@
|
||||
//
|
||||
// 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<<species_string;
|
||||
ss<<"_meta_data";
|
||||
h5tb_meta = H5TB_Population_Meta_Interface(ss.str(), h5g);
|
||||
|
||||
log_meta_bin meta_bin = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
meta_bin.E_bin = 0;
|
||||
meta_bin.E_min_eV = NAN;
|
||||
meta_bin.E_max_eV = NAN;
|
||||
meta_bin.z_min_m = z_scale.get_lower_scale_end();
|
||||
for (int i_z=0; i_z<z_scale.get_number_bins(); i_z++) {
|
||||
meta_bin.z_bin = i_z;
|
||||
meta_bin.z_max_m = z_scale.get_upper_bin_bound(i_z);
|
||||
meta_bin.r_min_m = r_scale.get_lower_scale_end();
|
||||
for (int i_r=0; i_r<r_scale.get_number_bins(); i_r++) {
|
||||
meta_bin.r_bin = i_r;
|
||||
meta_bin.r_max_m = r_scale.get_upper_bin_bound(i_r);
|
||||
meta_bin.phi_min = phi_scale.get_lower_scale_end();
|
||||
for (int i_phi=0; i_phi<phi_scale.get_number_bins(); i_phi++) {
|
||||
meta_bin.phi_bin = i_phi;
|
||||
meta_bin.phi_max = phi_scale.get_upper_bin_bound(i_phi);
|
||||
h5tb_meta.write(meta_bin);
|
||||
meta_bin.phi_min = meta_bin.phi_max;
|
||||
}
|
||||
meta_bin.r_min_m = meta_bin.r_max_m;
|
||||
}
|
||||
meta_bin.z_min_m = meta_bin.z_max_m;
|
||||
}
|
||||
}
|
||||
|
||||
inline void Thermal_Population_Logger::log(int number_decay) {
|
||||
log_population_bin pop_bin = {0, 0, 0, 0, 0, 0, 0};
|
||||
Pop3_Container cum_time = thermal_pop->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<z_scale.get_number_bins(); i_z++) {
|
||||
pop_bin.z_bin = i_z;
|
||||
for (int i_r=0; i_r<r_scale.get_number_bins(); i_r++) {
|
||||
pop_bin.r_bin = i_r;
|
||||
for (int i_phi=0; i_phi<phi_scale.get_number_bins(); i_phi++) {
|
||||
pop_bin.phi_bin = i_phi;
|
||||
pop_bin.cumulative_time = cum_time.get_value_by_bin(i_z, i_r, i_phi);
|
||||
pop_bin.offset = anhilated.get_value_by_bin(i_z, i_r, i_phi);
|
||||
h5tb.write(pop_bin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* thermal_population_logger_h */
|
||||
@@ -10,10 +10,10 @@
|
||||
|
||||
#include "read_system.h"
|
||||
|
||||
const double Timer::wgtsT2MaxDensity_m3 = getParameter("wgtsT2MaxDensity_m3");
|
||||
const double Timer::wgtsT2MaxDensity_m3 = load_parameter("wgtsT2MaxDensity_m3");
|
||||
|
||||
double Timer::get_physTime_s() {
|
||||
return ( double(*numTotDecays)/T2_activity_s );
|
||||
return double(*numTotDecays)/T2_activity_s + offset_time_s;
|
||||
}
|
||||
|
||||
void Timer::set_T2_activity_s() {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
class Timer {
|
||||
static const double wgtsT2MaxDensity_m3;
|
||||
double T2_activity_s;
|
||||
double offset_time_s;
|
||||
|
||||
int *numTotDecays;
|
||||
|
||||
@@ -20,13 +21,14 @@ public:
|
||||
Timer() {numTotDecays = NULL;}
|
||||
Timer(int *numTotDecays) {
|
||||
this->numTotDecays = numTotDecays;
|
||||
offset_time_s = 0;
|
||||
set_T2_activity_s();
|
||||
}
|
||||
double get_physTime_s();
|
||||
void set_offset_time_s(double new_offset_time_s) {offset_time_s = new_offset_time_s;}
|
||||
|
||||
private:
|
||||
void set_T2_activity_s();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -20,24 +20,29 @@ public:
|
||||
|
||||
double get_density_m3 (const vec3 &loc_m);
|
||||
void increase_density (const Particle &upPart, const vec3 &oldLoc_m) {};
|
||||
void decrease_denisty (const vec3 &oldLoc_m) {};
|
||||
void decrease_denisty (const vec3 &oldLoc_m, const double &energy_eV) {};
|
||||
|
||||
vec3 get_average_speed_ms (const vec3 &loc_m);
|
||||
vec3 roll_speed_ms (const vec3 &loc_m);
|
||||
|
||||
|
||||
meta_vec get_bins_meta_info();
|
||||
bin_content_vec get_bins_content();
|
||||
bin_count4 get_bin_count4();
|
||||
void set_bins(bin_count4 bin_counts, bin_content_vec bin_contents) {};
|
||||
private:
|
||||
double calc_DensityTriangle(const double &z_m);
|
||||
|
||||
private:
|
||||
vec3 roll_thermSpeed_ms(const vec3 &loc_m);
|
||||
|
||||
};
|
||||
|
||||
|
||||
const double T2_Population::wgtsT2MaxDensity_m3 = getParameter("wgtsT2MaxDensity_m3");
|
||||
const double T2_Population::wgtsTemp_K = getParameter("wgtsTemp_K");
|
||||
const double T2_Population::wgtsT2FlowSpeed_ms = getParameter("wgtsT2FlowSpeed_ms");
|
||||
|
||||
|
||||
|
||||
|
||||
const double T2_Population::wgtsT2MaxDensity_m3 = load_parameter("wgtsT2MaxDensity_m3");
|
||||
const double T2_Population::wgtsTemp_K = load_parameter("wgtsTemp_K");
|
||||
const double T2_Population::wgtsT2FlowSpeed_ms = load_parameter("wgtsT2FlowSpeed_ms");
|
||||
|
||||
inline double T2_Population::get_density_m3(const vec3 &loc_m) {
|
||||
Katrin_Geo::check_inKatrin(loc_m);
|
||||
@@ -62,6 +67,24 @@ inline vec3 T2_Population::roll_speed_ms(const vec3 &loc_m) {
|
||||
return (get_average_speed_ms(loc_m) + roll_thermSpeed_ms(loc_m));
|
||||
}
|
||||
|
||||
inline meta_vec T2_Population::get_bins_meta_info() {
|
||||
std::stringstream ss;
|
||||
ss<<"T2_Population::get_bins_meta_info: Not implemented \n";
|
||||
throw MyException (ss.str());
|
||||
}
|
||||
|
||||
inline bin_content_vec T2_Population::get_bins_content() {
|
||||
std::stringstream ss;
|
||||
ss<<"T2_Population::get_bins_content: Not implemented \n";
|
||||
throw MyException (ss.str());
|
||||
}
|
||||
|
||||
inline bin_count4 T2_Population::get_bin_count4() {
|
||||
std::stringstream ss;
|
||||
ss<<"T2_Population::get_bin_count4: Not implemented \n";
|
||||
throw MyException (ss.str());
|
||||
}
|
||||
|
||||
inline vec3 T2_Population::get_average_speed_ms(const vec3 &loc_m) {
|
||||
if (Katrin_Geo::inWGTS(loc_m)) {
|
||||
double z_wgtsHalf_m = Katrin_Geo::get_z_WGTSstart_m() + (Katrin_Geo::get_z_WGTSend_m() - Katrin_Geo::get_z_WGTSstart_m())/2;
|
||||
|
||||
@@ -15,8 +15,8 @@ using namespace std;
|
||||
int main() {
|
||||
clock_t start;
|
||||
UniRNG rngUni;
|
||||
TCS_Container tcs_data = TCS_Container(1e-5, 2e4, 1e3, getDataPath() + "eT2_TCS_ela_concat.dat");
|
||||
DCS_Theta_Container dcs_data = DCS_Theta_Container(1e-5, 2e4, 1e3, 200, getDataPath() + "eT2_DCS_ela_concat.dat");
|
||||
TCS_Container tcs_data = TCS_Container(1e-5, 2e4, 1e3, get_data_path() + "eT2_TCS_ela_concat.dat");
|
||||
DCS_Theta_Container dcs_data = DCS_Theta_Container(1e-5, 2e4, 1e3, 200, get_data_path() + "eT2_DCS_ela_concat.dat");
|
||||
|
||||
//tcs_data.debug();
|
||||
std::cout<<tcs_data.get_value(0)<<"\n";
|
||||
|
||||
Reference in New Issue
Block a user