Moved serial mode to target mcelecron_serial.
Implemented parallelization with mpi.
This commit is contained in:
@@ -95,7 +95,7 @@ void ASCI_Logger::log_Particle(Particle *logPart, blitz::TinyVector<double,3> ol
|
||||
}
|
||||
|
||||
void ASCI_Logger::set_outdirName() {
|
||||
string parname = get_parameter_filename();
|
||||
string parname = get_parameter_filenamepath();
|
||||
stringstream dirname;
|
||||
int i = 1;
|
||||
do {
|
||||
|
||||
@@ -54,21 +54,21 @@ template <class T_Map>
|
||||
template <typename T>
|
||||
void Average_Container<T_Map>::rec_calcMap(const T &subMap, std::deque<double> Points) {
|
||||
double curVal, nextVal, avgVal;
|
||||
typename T::const_iterator curItr, nextItr;
|
||||
for (nextItr = ++(subMap.cbegin()); nextItr!= subMap.cend(); nextItr++) {
|
||||
curItr = nextItr;
|
||||
--curItr;
|
||||
curVal = curItr->first;
|
||||
nextVal = nextItr->first;
|
||||
typename T::const_iterator curitr, nextitr;
|
||||
for (nextitr = ++(subMap.cbegin()); nextitr!= subMap.cend(); nextitr++) {
|
||||
curitr = nextitr;
|
||||
--curitr;
|
||||
curVal = curitr->first;
|
||||
nextVal = nextitr->first;
|
||||
avgVal = curVal + (nextVal-curVal)/2;
|
||||
Points.push_back(avgVal);
|
||||
rec_calcMap(curItr->second, Points);
|
||||
rec_calcMap(curitr->second, Points);
|
||||
Points.pop_back();
|
||||
}
|
||||
// insert last point as overflow value
|
||||
curItr = (--subMap.cend());
|
||||
Points.push_back(curItr->first);
|
||||
rec_calcMap(curItr->second, Points);
|
||||
curitr = (--subMap.cend());
|
||||
Points.push_back(curitr->first);
|
||||
rec_calcMap(curitr->second, Points);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ protected:
|
||||
private:
|
||||
template <typename T_target> void rec_getSubMap(T_target *subMap, T_target **targetMapPtr, std::deque<double> Points, searchStyle searchMode) ;
|
||||
template <typename T_target, typename T> void rec_getSubMap(T *subMap, T_target **targetMapPtr, std::deque<double> Points, searchStyle searchMode) ;
|
||||
template <class T> typename T::iterator searchItrByStyle(T *subMap, double x, searchStyle searchMode) ;
|
||||
template <class T> typename T::iterator searchitrByStyle(T *subMap, double x, searchStyle searchMode) ;
|
||||
|
||||
protected:
|
||||
void checkEmpty() ;
|
||||
@@ -155,8 +155,8 @@ void Base_Container<T_Map>::addPoint(std::deque<double> pointIn) {
|
||||
if (pointIn.size() != Dim+1) {
|
||||
std::stringstream ss;
|
||||
ss<<"Base_Container::addPoint: deque pointIn dimension missmatch.\n";
|
||||
for (std::deque<double>::iterator Itr = pointIn.begin(); Itr!=pointIn.end(); Itr++) {
|
||||
std::cout<<*Itr<<"\n";
|
||||
for (std::deque<double>::iterator itr = pointIn.begin(); itr!=pointIn.end(); itr++) {
|
||||
std::cout<<*itr<<"\n";
|
||||
}
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
@@ -222,8 +222,8 @@ std::string Base_Container<T_Map>::getExportFileHeader() {
|
||||
|
||||
template <class T_Map>
|
||||
void Base_Container<T_Map>::rec_exportToCSV(const dim1Map &subMap, std::ofstream &exportStream, std::string preset) {
|
||||
for (dim1Map::const_iterator Itr = subMap.cbegin();Itr!=subMap.cend();Itr++) {
|
||||
exportStream<<preset<<Itr->first<<"\t"<<Itr->second<<"\n";
|
||||
for (dim1Map::const_iterator itr = subMap.cbegin();itr!=subMap.cend();itr++) {
|
||||
exportStream<<preset<<itr->first<<"\t"<<itr->second<<"\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,11 +231,11 @@ template <class T_Map>
|
||||
template <typename T>
|
||||
void Base_Container<T_Map>::rec_exportToCSV(const T &subMap, std::ofstream &exportStream, std::string preset) {
|
||||
std::stringstream ss;
|
||||
for (typename T::const_iterator Itr = subMap.cbegin();Itr!=subMap.cend();Itr++) {
|
||||
for (typename T::const_iterator itr = subMap.cbegin();itr!=subMap.cend();itr++) {
|
||||
ss.clear();
|
||||
ss.str("");
|
||||
ss<<preset<<Itr->first<<"\t";
|
||||
rec_exportToCSV(Itr->second, exportStream, ss.str());
|
||||
ss<<preset<<itr->first<<"\t";
|
||||
rec_exportToCSV(itr->second, exportStream, ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,8 +245,8 @@ double Base_Container<T_Map>::get_value(std::deque<double> Points, searchStyle s
|
||||
double x = Points.back();
|
||||
Points.pop_back();
|
||||
dim1Map *subMap = getSubMap<dim1Map>(Points, searchMode);
|
||||
dim1Map::const_iterator Itr = searchItrByStyle(subMap, x, searchMode);
|
||||
return Itr->second;
|
||||
dim1Map::const_iterator itr = searchitrByStyle(subMap, x, searchMode);
|
||||
return itr->second;
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
@@ -269,7 +269,7 @@ template <typename T_target>
|
||||
void Base_Container<T_Map>::rec_getSubMap(T_target *subMap, T_target **targetMapPtr, std::deque<double> Points, searchStyle searchMode) {
|
||||
if (Points.size() != 0) {
|
||||
std::stringstream ss;
|
||||
ss<<"Base_Container::get_subItr: Dimension Missmatch of Points\n";
|
||||
ss<<"Base_Container::get_subitr: Dimension Missmatch of Points\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
*targetMapPtr = subMap;
|
||||
@@ -280,30 +280,30 @@ template <typename T_target, typename T>
|
||||
void Base_Container<T_Map>::rec_getSubMap(T *subMap, T_target **targetMapPtr, std::deque<double> Points, searchStyle searchMode) {
|
||||
double x = Points.front();
|
||||
Points.pop_front();
|
||||
typename T::iterator Itr = searchItrByStyle(subMap, x, searchMode);
|
||||
rec_getSubMap(&(Itr->second), targetMapPtr, Points, searchMode);
|
||||
typename T::iterator itr = searchitrByStyle(subMap, x, searchMode);
|
||||
rec_getSubMap(&(itr->second), targetMapPtr, Points, searchMode);
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
template <class T>
|
||||
typename T::iterator Base_Container<T_Map>::searchItrByStyle(T *subMap, double x, searchStyle searchMode) {
|
||||
typename T::iterator Itr;
|
||||
typename T::iterator Base_Container<T_Map>::searchitrByStyle(T *subMap, double x, searchStyle searchMode) {
|
||||
typename T::iterator itr;
|
||||
if (searchMode == Find) {
|
||||
Itr = subMap->find(x);
|
||||
itr = subMap->find(x);
|
||||
} else if (searchMode == Lower_bound) {
|
||||
Itr = subMap->lower_bound(x);
|
||||
itr = subMap->lower_bound(x);
|
||||
} else if (searchMode == Lower_bound_Over) {
|
||||
Itr = subMap->lower_bound(x);
|
||||
if (Itr == subMap->end()) {
|
||||
--Itr;
|
||||
itr = subMap->lower_bound(x);
|
||||
if (itr == subMap->end()) {
|
||||
--itr;
|
||||
}
|
||||
}
|
||||
if (Itr == subMap->end()) {
|
||||
if (itr == subMap->end()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Base_Container::calcItr: Point is out of bound.\n";
|
||||
ss<<"Base_Container::calcitr: Point is out of bound.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return Itr;
|
||||
return itr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -58,20 +58,20 @@ double Edge_Container<T_Map>::rec_interpolate(const T &subMap, std::deque<double
|
||||
double x = *subPoint.begin();
|
||||
subPoint.pop_front();
|
||||
|
||||
typename T::const_iterator upItr = subMap.lower_bound(x);
|
||||
typename T::const_iterator upitr = subMap.lower_bound(x);
|
||||
|
||||
if (upItr == subMap.cbegin()) {
|
||||
return rec_interpolate(upItr->second, subPoint);
|
||||
if (upitr == subMap.cbegin()) {
|
||||
return rec_interpolate(upitr->second, subPoint);
|
||||
} else {
|
||||
typename T::const_iterator lowItr = upItr;
|
||||
--lowItr;
|
||||
if (upItr == subMap.cend()) {
|
||||
return rec_interpolate(lowItr->second, subPoint);
|
||||
typename T::const_iterator lowitr = upitr;
|
||||
--lowitr;
|
||||
if (upitr == subMap.cend()) {
|
||||
return rec_interpolate(lowitr->second, subPoint);
|
||||
} else {
|
||||
double low_x = lowItr->first;
|
||||
double low_f = rec_interpolate(lowItr->second, subPoint);
|
||||
double up_x = upItr->first;
|
||||
double up_f = rec_interpolate(upItr->second, subPoint);
|
||||
double low_x = lowitr->first;
|
||||
double low_f = rec_interpolate(lowitr->second, subPoint);
|
||||
double up_x = upitr->first;
|
||||
double up_f = rec_interpolate(upitr->second, subPoint);
|
||||
|
||||
double res = low_f + (x-low_x)/(up_x-low_x) * (up_f-low_f);
|
||||
return res;
|
||||
|
||||
@@ -17,11 +17,11 @@ void EnergeticPop_Container::set_Map() {
|
||||
double Ex_max = ceil(log10(E_max_eV));
|
||||
double step = (Ex_max-Ex_min)/Epoints;
|
||||
double x, E_eV;
|
||||
for (vector<vec3>::iterator Itr = bins.begin(); Itr!=bins.end(); Itr++) {
|
||||
for (vector<vec3>::iterator itr = bins.begin(); itr!=bins.end(); itr++) {
|
||||
for (int i = 1; i<=Epoints; i++) {
|
||||
x = Ex_min + step*i;
|
||||
E_eV = pow(10,x);
|
||||
addPoint(deque<double>{(*Itr)[0], (*Itr)[1], (*Itr)[2], E_eV, 0});
|
||||
addPoint(deque<double>{(*itr)[0], (*itr)[1], (*itr)[2], E_eV, 0});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,8 +37,8 @@ double EnergeticPop_Container::getDensity_m3(const vec3 &locXYZ_m, double physTi
|
||||
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++) {
|
||||
cumTime_s +=Itr->second;
|
||||
for (dim1Map::iterator itr = EMap.begin(); itr != EMap.end(); itr++) {
|
||||
cumTime_s +=itr->second;
|
||||
}
|
||||
return cumTime_s;
|
||||
}
|
||||
@@ -62,11 +62,11 @@ void EnergeticPop_Container::upDensity (const Particle &upParticle, const vec3 &
|
||||
double vAbs_ms = upParticle.get_vAbs_ms();
|
||||
double E_eV = upParticle.get_E_eV();
|
||||
|
||||
dim4Map::iterator zItr_min = Map.lower_bound(z_min_m);
|
||||
dim4Map::iterator zItr_max = Map.lower_bound(z_max_m);
|
||||
dim4Map::iterator zitr_min = Map.lower_bound(z_min_m);
|
||||
dim4Map::iterator zitr_max = Map.lower_bound(z_max_m);
|
||||
|
||||
for (dim4Map::iterator Itr = zItr_min;Itr != zItr_max;Itr++) {
|
||||
Itr->second.lower_bound(r_m)->second.lower_bound(phi)->second.lower_bound(E_eV)->second += l_m/vAbs_ms;
|
||||
for (dim4Map::iterator itr = zitr_min;itr != zitr_max;itr++) {
|
||||
itr->second.lower_bound(r_m)->second.lower_bound(phi)->second.lower_bound(E_eV)->second += l_m/vAbs_ms;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,17 +79,17 @@ double EnergeticPop_Container::roll_Energy_eV(const vec3 &locXYZ_m, UniRNG *rngU
|
||||
|
||||
double targetTime_s = rngUni->random() * get_cumulated_time_s(zrphiCords);
|
||||
double summedTime_s = 0;
|
||||
dim1Map::iterator Itr = EMap.begin();
|
||||
dim1Map::iterator itr = EMap.begin();
|
||||
do {
|
||||
summedTime_s += Itr->second;
|
||||
Itr++;
|
||||
summedTime_s += itr->second;
|
||||
itr++;
|
||||
} while(summedTime_s < targetTime_s);
|
||||
Itr--;
|
||||
itr--;
|
||||
|
||||
if (Itr == EMap.begin() ) {
|
||||
return Itr->first;
|
||||
if (itr == EMap.begin() ) {
|
||||
return itr->first;
|
||||
} else {
|
||||
double E_eV = ( (Itr->first) + ((--Itr)->first) )/2;
|
||||
double E_eV = ( (itr->first) + ((--itr)->first) )/2;
|
||||
return E_eV;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,20 +15,22 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
H5_File::H5_File() {
|
||||
create();
|
||||
H5_File::H5_File(std::string name_extension) {
|
||||
create(name_extension);
|
||||
h5part = H5_Particles(&h5_file);
|
||||
h5pop = H5_Populations(&h5_file);
|
||||
}
|
||||
|
||||
void H5_File::create() {
|
||||
const string constH5Name = get_file_name();
|
||||
h5_file = H5Fcreate(constH5Name.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
|
||||
void H5_File::create(std::string output_path) {
|
||||
//const string constH5Name = get_file_name();
|
||||
h5_file = H5Fcreate(output_path.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
|
||||
}
|
||||
|
||||
/*
|
||||
std::string H5_File::get_file_name() {
|
||||
string parname = get_parameter_filename();
|
||||
string parname = get_parameter_filenamepath();
|
||||
stringstream H5name;
|
||||
|
||||
int i = 1;
|
||||
do {
|
||||
H5name.str(std::string());
|
||||
@@ -36,4 +38,4 @@ std::string H5_File::get_file_name() {
|
||||
} while ( is_file(H5name.str()) );
|
||||
return H5name.str();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@@ -18,12 +18,13 @@ class H5_File {
|
||||
H5_Populations h5pop;
|
||||
|
||||
public:
|
||||
H5_File();
|
||||
H5_File() {};
|
||||
H5_File(std::string output_path);
|
||||
H5_Particles *get_h5part() {return &h5part;}
|
||||
H5_Populations *get_h5pop() {return &h5pop;}
|
||||
private:
|
||||
void create();
|
||||
std::string get_file_name();
|
||||
void create(std::string output_path);
|
||||
//std::string get_file_name();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ inline H5_Particles::H5_Particles(hid_t *h5_file) {
|
||||
numberZBins = load_parameter("numberZBins");
|
||||
set_logging();
|
||||
set_zValues();
|
||||
print_logInfo();
|
||||
//print_logInfo();
|
||||
|
||||
create_h5gs();
|
||||
}
|
||||
|
||||
@@ -57,6 +57,11 @@ private:
|
||||
Lin_Scale get_r_scale();
|
||||
Lin_Scale calc_phi_scale();
|
||||
Log_Scale get_E_scale();
|
||||
|
||||
public:
|
||||
int get_array_length();
|
||||
double *get_cumulated_time_s_array();
|
||||
double *get_offset_array();
|
||||
};
|
||||
|
||||
|
||||
@@ -81,18 +86,12 @@ inline double Kinetic_Population::get_density_m3(const vec3 &loc_m) {
|
||||
ss<<"Kinetic_Population::get_density_m3: loc_m outside of Katrin.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double total_cumulated_time_s = cumulated_times_s.get_value_sum(loc_m);
|
||||
double total_annhilated = number_annhilated.get_value_sum(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;
|
||||
double dens_m3 = total_cumulated_time_s/physical_time_s/bin_size_m3 - total_annhilated;
|
||||
dens_m3 = (dens_m3 < 0) ? 0 : dens_m3;
|
||||
return dens_m3;
|
||||
}
|
||||
@@ -119,15 +118,25 @@ inline vec3 Kinetic_Population::roll_v_ms(const vec3 &loc_m) {
|
||||
double physical_time_s = timer->get_physTime_s();
|
||||
double bin_size_m3 = bin_sizes.get_cell_volume_m3(loc_m);
|
||||
|
||||
loc_bins loc_bin = cumulated_times_s.get_loc_bins(loc_m);
|
||||
int z_bin = loc_bin.z_bin;
|
||||
int r_bin = loc_bin.r_bin;
|
||||
int phi_bin = loc_bin.phi_bin;
|
||||
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 cumulated_time_s;
|
||||
double offset;
|
||||
double delta_density_m3;
|
||||
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];
|
||||
for (int E_bin=0; E_bin<num_E_bins; E_bin++) {
|
||||
cumulated_time_s = cumulated_times_s.get_value_by_bin(z_bin, r_bin, phi_bin, E_bin);
|
||||
offset = number_annhilated.get_value_by_bin(z_bin, r_bin, phi_bin, E_bin);
|
||||
delta_density_m3 = cumulated_time_s/physical_time_s/bin_size_m3 - offset;
|
||||
delta_density_m3 = (delta_density_m3<0) ? 0 : delta_density_m3;
|
||||
cum_density_m3 += delta_density_m3;
|
||||
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);
|
||||
double lower = cumulated_times_s.get_lower_E_boarder_eV(E_bin);
|
||||
double upper = cumulated_times_s.get_upper_E_boarder_eV(E_bin);
|
||||
return lower + rngUni->random() * (upper-lower);
|
||||
}
|
||||
}
|
||||
@@ -223,13 +232,13 @@ inline void Kinetic_Population::set_bins(bin_count4 bin_counts, bin_content_vec
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
@@ -255,4 +264,16 @@ inline Log_Scale Kinetic_Population::get_E_scale() {
|
||||
|
||||
}
|
||||
|
||||
inline int Kinetic_Population::get_array_length() {
|
||||
return cumulated_times_s.get_total_data_size();
|
||||
}
|
||||
|
||||
inline double *Kinetic_Population::get_cumulated_time_s_array() {
|
||||
return cumulated_times_s.get_array();
|
||||
}
|
||||
|
||||
inline double *Kinetic_Population::get_offset_array() {
|
||||
return number_annhilated.get_array();
|
||||
}
|
||||
|
||||
#endif /* energetic_base_h */
|
||||
|
||||
@@ -8,13 +8,76 @@
|
||||
|
||||
#include "simulation.hpp"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
clock_t start = clock();
|
||||
int main(int argc, char *argv[]) {
|
||||
MPI_Init(&argc, &argv);
|
||||
|
||||
int size, rank;
|
||||
MPI_Comm_size(MPI_COMM_WORLD,&size);
|
||||
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
|
||||
std::cout <<"CPU " <<rank <<" of " <<size <<endl;
|
||||
Simulation Sim;
|
||||
|
||||
int start_time = MPI_Wtime();
|
||||
Sim.doit();
|
||||
cout<<"Total Time: "<<MPI_Wtime()-start_time<<" s\n";
|
||||
/*
|
||||
clock_t start = clock();
|
||||
|
||||
|
||||
cout<<"Duration: "<< ( clock() - start ) / (double) CLOCKS_PER_SEC <<"\n";
|
||||
*/
|
||||
MPI_Finalize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
int main(int argc, char *argv[]) {
|
||||
MPI_Init(&argc,&argv);
|
||||
|
||||
int size, rank;
|
||||
MPI_Comm_size(MPI_COMM_WORLD,&size);
|
||||
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
|
||||
std::cout <<"CPU " <<rank <<" of " <<size <<endl;
|
||||
|
||||
|
||||
|
||||
|
||||
MPI_Info info;
|
||||
MPI_Info_create(&info);
|
||||
|
||||
hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS);
|
||||
H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, info);
|
||||
|
||||
string filename="/Users/ChristianReiling/Desktop/MPI_test/outfiles/tableout.h5";
|
||||
hid_t file;
|
||||
file = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);
|
||||
|
||||
if(file <0) {
|
||||
cerr << "Unable to create " << filename << "!" <<endl;
|
||||
exit(941);
|
||||
}
|
||||
H5Pclose(plist_id);
|
||||
|
||||
H5TB_Particle_Interface table = H5TB_Particle_Interface("Samples", &file);
|
||||
if (rank == 1) {
|
||||
Particle electron = Particle_Builder::create_e(vec3(1,2,3), vec3 (4,5,6), 7, 8);
|
||||
table.write(electron);
|
||||
}
|
||||
if (rank == 0) {
|
||||
Particle electron = Particle_Builder::create_e(vec3(1,2,3), vec3 (4,5,6), 0, -1);
|
||||
table.write(electron);
|
||||
}
|
||||
H5Fclose(file);
|
||||
|
||||
MPI_Finalize();
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// main_serial.cpp
|
||||
// mc_electron_serial
|
||||
//
|
||||
// Created by Christian Reiling on 17.07.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "simulation_serial.hpp"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
Simulation Sim;
|
||||
clock_t start_time = clock();
|
||||
Sim.doit();
|
||||
|
||||
cout<<"Total Time: "<<(double(clock() - start_time) / CLOCKS_PER_SEC)<<" s\n";
|
||||
}
|
||||
+15
-13
@@ -1,7 +1,15 @@
|
||||
include $(HOMEBASE)/src/makeinclude/include.mak
|
||||
|
||||
SRCS := $(wildcard ../*.cpp)
|
||||
OBJS := $(patsubst %.cpp,%.o,$(SRCS))
|
||||
OBJS := particle_looper.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_fields.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 \
|
||||
interaction_builder.o BED_eT2_ionization.o uehara_eT2_elastic.o rutherford_elastic.o \
|
||||
terminator_builder.o
|
||||
|
||||
|
||||
CXXFLAGS = $(X_OFLAGS) -I.. $(X_INC)
|
||||
@@ -14,21 +22,15 @@ TARGETS = mcelectron
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
mcelectron: main.o simulation.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_fields.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 \
|
||||
interaction_builder.o BED_eT2_ionization.o uehara_eT2_elastic.o rutherford_elastic.o \
|
||||
terminator_builder.o
|
||||
mcelectron: main.o simulation.o $(OBJS)
|
||||
$(MPICXX) -o $@ $^ $(LDFLAGS) $(LOADLIBES)
|
||||
|
||||
mcelectron_serial: main_serial.o simulation_serial.o $(OBJS)
|
||||
$(CXX) -o $@ $^ $(LDFLAGS) $(LOADLIBES)
|
||||
|
||||
%.o : %.cpp
|
||||
$(CXX) -c $< $(CXXFLAGS) -o $@
|
||||
|
||||
clean:
|
||||
rm *.o mcelectron
|
||||
rm *.o mcelectron mcelectron_serial
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ inline void Manager_Base<T>::add(T* 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++) {
|
||||
if ((*Itr)->get_species() == this_species) {
|
||||
for (typename std::vector<T*>::iterator itr = processes.begin(); itr!=processes.end(); itr++) {
|
||||
if ((*itr)->get_species() == this_species) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -50,9 +50,9 @@ 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++) {
|
||||
if ((*Itr)->get_species() == this_species) {
|
||||
return *Itr;
|
||||
for (typename std::vector<T*>::iterator itr = processes.begin(); itr!=processes.end(); itr++) {
|
||||
if ((*itr)->get_species() == this_species) {
|
||||
return *itr;
|
||||
}
|
||||
}
|
||||
std::stringstream ss;
|
||||
|
||||
@@ -42,7 +42,7 @@ std::string get_species_string(const species &spec) {
|
||||
return res;
|
||||
}
|
||||
|
||||
species get_species_from_string(const std::string &species_string) {
|
||||
std::vector<species> get_all_spieces_vector() {
|
||||
std::vector<species> all;
|
||||
all.push_back(electron);
|
||||
all.push_back(tritium);
|
||||
@@ -50,9 +50,14 @@ species get_species_from_string(const std::string &species_string) {
|
||||
all.push_back(tritium2I);
|
||||
all.push_back(tritium2);
|
||||
all.push_back(tritium3I);
|
||||
for (std::vector<species>::iterator Itr = all.begin(); Itr!= all.end(); Itr++) {
|
||||
if (get_species_string(*Itr) == species_string) {
|
||||
return *Itr;
|
||||
return all;
|
||||
};
|
||||
|
||||
species get_species_from_string(const std::string &species_string) {
|
||||
std::vector<species> all = get_all_spieces_vector();
|
||||
for (std::vector<species>::iterator itr = all.begin(); itr!= all.end(); itr++) {
|
||||
if (get_species_string(*itr) == species_string) {
|
||||
return *itr;
|
||||
}
|
||||
}
|
||||
stringstream ss;
|
||||
@@ -60,6 +65,8 @@ species get_species_from_string(const std::string &species_string) {
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
double get_species_mass(const species &spec) {
|
||||
double res;
|
||||
switch (spec) {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
|
||||
enum species{electron, tritium, tritiumI, tritium2I, tritium2, tritium3I};
|
||||
|
||||
std::vector<species> get_all_spieces_vector();
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// particle_looper.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.07.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "particle_looper.hpp"
|
||||
|
||||
|
||||
void Particle_Looper::init_managers() {
|
||||
timer = Timer(&local_decays, &global_decays);
|
||||
part_loggers = Particle_Logger_Builder::build(&h5f);
|
||||
populations = Population_Builder::build(&timer, &rngUni, &rngNormal);
|
||||
|
||||
injector = Injector(&rngUni, &rngNormal);
|
||||
movers = Mover_Builder::build(&part_loggers, &populations);
|
||||
interactions = Interaction_Builder::build(&populations, &rngUni);
|
||||
terminators = Terminator_Builder::build();
|
||||
|
||||
pop_loggers = Population_Logger_Builder::build(&h5f, &populations, &timer);
|
||||
pop_load_saver = Population_Load_Saver(&populations, &timer);
|
||||
}
|
||||
|
||||
void Particle_Looper::do_loops(int target_decays) {
|
||||
std::queue<Particle> particle_queue;
|
||||
int number_decays = 0;
|
||||
while ( (number_decays < target_decays) || (!particle_queue.empty()) ) {
|
||||
if (particle_queue.empty()) {
|
||||
pop_loggers.log();
|
||||
particle_queue.push(injector.injectElectron(get_new_id()));
|
||||
number_decays++;
|
||||
local_decays++;
|
||||
}
|
||||
process_first(&particle_queue);
|
||||
}
|
||||
pop_loggers.log();
|
||||
}
|
||||
|
||||
void Particle_Looper::process_first(std::queue<Particle> *particle_queue) {
|
||||
Particle curPart = particle_queue->front();
|
||||
Mover_Base *moverPtr = movers.find(curPart.get_species());
|
||||
Interaction_Base *interactionPtr = interactions.find(curPart.get_species());
|
||||
Terminator_Base *terminatorPtr = terminators.find(curPart.get_species());
|
||||
|
||||
InteractionOut IntOut;
|
||||
double macroSigma_m2;
|
||||
vec3 oldLoc_m;
|
||||
while (!terminatorPtr->checkTermination(curPart)) {
|
||||
oldLoc_m = curPart.get_x_m();
|
||||
macroSigma_m2 = interactionPtr->get_macroSigma_m2(curPart);
|
||||
moverPtr->move(&curPart, macroSigma_m2);
|
||||
if (!terminatorPtr->checkTermination(curPart)) {
|
||||
IntOut = interactionPtr->do_Interaction(&curPart);
|
||||
for (int i=0; i<IntOut.get_number_new_particles(); i++) {
|
||||
particle_queue->push(IntOut.get_new_particles()[i]);
|
||||
particle_queue->back().set_Id(get_new_id());
|
||||
}
|
||||
if (IntOut.get_delete_current()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
particle_queue->pop();
|
||||
}
|
||||
|
||||
long int Particle_Looper::get_new_id() {
|
||||
long int res = ID_offset + ID_counter;
|
||||
ID_counter++;
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// particle_looper.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.07.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef particle_looper_hpp
|
||||
#define particle_looper_hpp
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "h5_file.hpp"
|
||||
#include "timer.hpp"
|
||||
|
||||
#include "logger_builder.hpp"
|
||||
#include "population_builder.hpp"
|
||||
|
||||
#include "injector.hpp"
|
||||
#include "mover_builder.hpp"
|
||||
#include "interaction_builder.hpp"
|
||||
#include "terminator_builder.hpp"
|
||||
|
||||
#include "population_load_saver.hpp"
|
||||
|
||||
|
||||
class Particle_Looper {
|
||||
UniRNG rngUni;
|
||||
NormalRNG rngNormal;
|
||||
|
||||
H5_File h5f;
|
||||
Timer timer;
|
||||
|
||||
Particle_Logger_Manager part_loggers;
|
||||
Population_Manager populations;
|
||||
|
||||
Injector injector;
|
||||
Mover_Manager movers;
|
||||
Interaction_Manager interactions;
|
||||
Terminator_Manager terminators;
|
||||
|
||||
Population_Logger_Manager pop_loggers;
|
||||
Population_Load_Saver pop_load_saver;
|
||||
|
||||
long int ID_offset;
|
||||
long int ID_counter = 0;
|
||||
long int local_decays = 0;
|
||||
long int global_decays = 0;
|
||||
|
||||
public:
|
||||
Particle_Looper() {};
|
||||
void init(long int seed, long int ID_offset, std::string output_path) {
|
||||
rngUni.seed(seed);
|
||||
rngNormal.seed(seed);
|
||||
this->ID_offset = ID_offset;
|
||||
h5f = H5_File(output_path);
|
||||
init_managers();
|
||||
//pop_load_saver.load();
|
||||
}
|
||||
~Particle_Looper() {
|
||||
//pop_load_saver.save();
|
||||
}
|
||||
private:
|
||||
void init_managers();
|
||||
|
||||
public:
|
||||
void do_loops(int target_decays);
|
||||
private:
|
||||
void process_first(std::queue<Particle> *particle_queue);
|
||||
long int get_new_id();
|
||||
|
||||
public:
|
||||
long int get_number_total_particles() {
|
||||
return ID_counter;
|
||||
}
|
||||
|
||||
void set_global_decays(long int global_decays) {
|
||||
this->global_decays = global_decays;
|
||||
}
|
||||
|
||||
Population_Manager *get_populations() {
|
||||
return &populations;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* particle_looper_hpp */
|
||||
@@ -17,27 +17,13 @@ Pop3_Container::Pop3_Container(int num_z_bins, int num_r_bins, int num_phi_bins)
|
||||
r_scale = Lin_Scale(0,r_WGTS_m, num_r_bins);
|
||||
phi_scale = Lin_Scale(0, 2*pi, num_phi_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] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
r_offset = num_phi_bins;
|
||||
z_offset = r_offset*num_r_bins;
|
||||
total_data_size = num_z_bins*z_offset;
|
||||
data = new double[total_data_size];
|
||||
}
|
||||
|
||||
Pop3_Container::~Pop3_Container() {
|
||||
int z_dimension = z_scale.get_number_bins();
|
||||
int r_dimension = r_scale.get_number_bins();
|
||||
for (int i = 0; i < z_dimension; i++) {
|
||||
for(int j = 0; j < r_dimension; j++) {
|
||||
delete[] data[i][j];
|
||||
}
|
||||
delete[] data[i];
|
||||
}
|
||||
delete[] data;
|
||||
};
|
||||
|
||||
@@ -45,19 +31,12 @@ Pop3_Container::Pop3_Container(const Pop3_Container& other) {
|
||||
z_scale = other.z_scale;
|
||||
r_scale = other.r_scale;
|
||||
phi_scale = other.phi_scale;
|
||||
int z_dimension = z_scale.get_number_bins();
|
||||
int r_dimension = r_scale.get_number_bins();
|
||||
int phi_dimension = phi_scale.get_number_bins();
|
||||
z_offset = other.z_offset;
|
||||
r_offset = other.r_offset;
|
||||
total_data_size = other.total_data_size;
|
||||
|
||||
data = new double **[z_dimension];
|
||||
for (int i = 0; i < z_dimension; i++) {
|
||||
data[i] = new double *[r_dimension];
|
||||
for(int j = 0; j < r_dimension; j++) {
|
||||
data[i][j] = new double[phi_dimension];
|
||||
for (int k = 0; k < phi_dimension; k++) {
|
||||
data[i][j][k] = other.data[i][j][k];
|
||||
}
|
||||
}
|
||||
for (int i=0; i<total_data_size; i++) {
|
||||
data[i] = other.data[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,17 +45,20 @@ Pop3_Container& Pop3_Container::operator=(const Pop3_Container& other) {
|
||||
swap(z_scale, tmp.z_scale);
|
||||
swap(r_scale, tmp.r_scale);
|
||||
swap(phi_scale, tmp.phi_scale);
|
||||
swap(z_offset, tmp.z_offset);
|
||||
swap(r_offset, tmp.r_offset);
|
||||
swap(total_data_size, tmp.total_data_size);
|
||||
swap(data, tmp.data);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void Pop3_Container::increase_value(const double &value, const vec3 &loc_m) {
|
||||
int zbin = z_scale.calc_index(calc_z_m(loc_m));
|
||||
int rbin = r_scale.calc_index(calc_r_m(loc_m));
|
||||
int phibin = phi_scale.calc_index(calc_phi(loc_m));
|
||||
|
||||
data[zbin][rbin][phibin] += value;
|
||||
int z_bin = z_scale.calc_index(calc_z_m(loc_m));
|
||||
int r_bin = r_scale.calc_index(calc_r_m(loc_m));
|
||||
int phi_bin = phi_scale.calc_index(calc_phi(loc_m));
|
||||
int data_bin = calc_data_bin(z_bin, r_bin, phi_bin);
|
||||
data[data_bin] += value;
|
||||
}
|
||||
|
||||
void Pop3_Container::increase_value(const double &value, const vec3 &loc1_m, const vec3 &loc2_m) {
|
||||
@@ -85,23 +67,28 @@ void Pop3_Container::increase_value(const double &value, const vec3 &loc1_m, con
|
||||
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);
|
||||
int min_z_bin = z_scale.calc_index(z_min_m);
|
||||
int max_z_bin = z_scale.calc_index(z_max_m);
|
||||
// No r/phi movement, else need to calculate more exactly
|
||||
double r = calc_r_m(loc1_m);
|
||||
int rbin = r_scale.calc_index(calc_r_m(r));
|
||||
int r_bin = r_scale.calc_index(calc_r_m(r));
|
||||
double phi = calc_phi(loc1_m);
|
||||
int phibin = phi_scale.calc_index(phi);
|
||||
|
||||
for (int i = min_z_index; i<=max_z_index; i++) {
|
||||
data[i][rbin][phibin] += value;
|
||||
int phi_bin = phi_scale.calc_index(phi);
|
||||
int data_bin;
|
||||
for (int z_bin = min_z_bin; z_bin<=max_z_bin; z_bin++) {
|
||||
data_bin = calc_data_bin(z_bin, r_bin, phi_bin);
|
||||
data[data_bin] += value;
|
||||
}
|
||||
}
|
||||
|
||||
double Pop3_Container::get_value (vec3 loc_m) {
|
||||
int zbin = z_scale.calc_index(calc_z_m(loc_m));
|
||||
int rbin = r_scale.calc_index(calc_r_m(loc_m));
|
||||
int phibin = phi_scale.calc_index(calc_phi(loc_m));
|
||||
return data[zbin][rbin][phibin];
|
||||
int z_bin = z_scale.calc_index(calc_z_m(loc_m));
|
||||
int r_bin = r_scale.calc_index(calc_r_m(loc_m));
|
||||
int phi_bin = phi_scale.calc_index(calc_phi(loc_m));
|
||||
int data_bin = calc_data_bin(z_bin, r_bin, phi_bin);
|
||||
return data[data_bin];
|
||||
}
|
||||
|
||||
int Pop3_Container::calc_data_bin(int z_bin, int r_bin, int phi_bin) {
|
||||
return z_offset*z_bin + r_offset*r_bin + phi_bin;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
|
||||
|
||||
class Pop3_Container {
|
||||
double ***data;
|
||||
Lin_Scale z_scale;
|
||||
Lin_Scale r_scale;
|
||||
Lin_Scale phi_scale;
|
||||
double *data;
|
||||
Lin_Scale z_scale, r_scale, phi_scale;
|
||||
int z_offset, r_offset, total_data_size;
|
||||
|
||||
|
||||
public:
|
||||
//Pop3_Container() {};
|
||||
@@ -32,12 +32,21 @@ 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];}
|
||||
void set_value_by_bin(double value, int z_bin, int r_bin, int phi_bin) {data[calc_data_bin(z_bin, r_bin, phi_bin)] = value;}
|
||||
double get_value_by_bin(int z_bin, int r_bin, int phi_bin) {
|
||||
return data[calc_data_bin(z_bin, r_bin, phi_bin)];
|
||||
}
|
||||
|
||||
Lin_Scale get_z_scale(){return z_scale;}
|
||||
Lin_Scale get_r_scale(){return r_scale;}
|
||||
Lin_Scale calc_phi_scale(){return phi_scale;}
|
||||
|
||||
private:
|
||||
int calc_data_bin(int z_bin, int r_bin, int phi_bin);
|
||||
|
||||
public:
|
||||
int get_total_data_size() {return total_data_size;}
|
||||
double *get_array() {return data;}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -18,34 +18,15 @@ Pop4_Container::Pop4_Container(int num_z_bins, int num_r_bins, int num_phi_bins,
|
||||
phi_scale = Lin_Scale(0, 2*pi, num_phi_bins);
|
||||
E_scale = Log_Scale(scale_start, scale_end, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
phi_offset = num_E_bins;
|
||||
r_offset = phi_offset * num_phi_bins;
|
||||
z_offset = r_offset*num_r_bins;
|
||||
total_data_size = num_z_bins*z_offset;
|
||||
|
||||
data = new double[total_data_size];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -54,23 +35,14 @@ Pop4_Container::Pop4_Container(const Pop4_Container& other) {
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
z_offset = other.z_offset;
|
||||
r_offset = other.r_offset;
|
||||
phi_offset = other.phi_offset;
|
||||
total_data_size = other.total_data_size;
|
||||
|
||||
for (int i=0; i<total_data_size; i++) {
|
||||
data[i] = other.data[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,17 +52,21 @@ Pop4_Container& Pop4_Container::operator=(const Pop4_Container& other) {
|
||||
swap(r_scale, tmp.r_scale);
|
||||
swap(phi_scale, tmp.phi_scale);
|
||||
swap(E_scale, tmp.E_scale);
|
||||
swap(z_offset, tmp.z_offset);
|
||||
swap(r_offset, tmp.r_offset);
|
||||
swap(phi_offset, tmp.phi_offset);
|
||||
swap(total_data_size, tmp.total_data_size);
|
||||
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(calc_z_m(loc_m));
|
||||
int rbin = r_scale.calc_index(calc_r_m(loc_m));
|
||||
int phibin = phi_scale.calc_index(calc_phi(loc_m));
|
||||
int z_bin = z_scale.calc_index(calc_z_m(loc_m));
|
||||
int r_bin = r_scale.calc_index(calc_r_m(loc_m));
|
||||
int phi_bin = phi_scale.calc_index(calc_phi(loc_m));
|
||||
int E_bin = E_scale.calc_index(E_eV);
|
||||
|
||||
data[zbin][rbin][phibin][E_bin] += value;
|
||||
data[calc_data_bin(z_bin, r_bin, phi_bin, E_bin)] += value;
|
||||
}
|
||||
|
||||
void Pop4_Container::increase_value(const double &value, const vec3 &loc1_m, const vec3 &loc2_m, const double &E_eV) {
|
||||
@@ -103,27 +79,46 @@ void Pop4_Container::increase_value(const double &value, const vec3 &loc1_m, con
|
||||
int max_z_index = z_scale.calc_index(z_max_m);
|
||||
// No r/phi movement, else need to calculate more exactly
|
||||
double r = calc_r_m(loc1_m);
|
||||
int rbin = r_scale.calc_index(calc_r_m(r));
|
||||
int r_bin = r_scale.calc_index(calc_r_m(r));
|
||||
double phi = calc_phi(loc1_m);
|
||||
int phibin = phi_scale.calc_index(phi);
|
||||
int phi_bin = 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;
|
||||
for (int z_bin = min_z_index; z_bin<=max_z_index; z_bin++) {
|
||||
data[calc_data_bin(z_bin, r_bin, phi_bin, E_bin)] += value;
|
||||
}
|
||||
}
|
||||
|
||||
double Pop4_Container::get_value(const vec3 &loc_m, const double &E_eV) {
|
||||
int zbin = z_scale.calc_index(calc_z_m(loc_m));
|
||||
int rbin = r_scale.calc_index(calc_r_m(loc_m));
|
||||
int phibin = phi_scale.calc_index(calc_phi(loc_m));
|
||||
int z_bin = z_scale.calc_index(calc_z_m(loc_m));
|
||||
int r_bin = r_scale.calc_index(calc_r_m(loc_m));
|
||||
int phi_bin = phi_scale.calc_index(calc_phi(loc_m));
|
||||
int E_bin = E_scale.calc_index(E_eV);
|
||||
return data[zbin][rbin][phibin][E_bin];
|
||||
return data[calc_data_bin(z_bin, r_bin, phi_bin, 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];
|
||||
double Pop4_Container::get_value_sum(const vec3 &loc_m) {
|
||||
int z_bin = z_scale.calc_index(calc_z_m(loc_m));
|
||||
int r_bin = r_scale.calc_index(calc_r_m(loc_m));
|
||||
int phi_bin = phi_scale.calc_index(calc_phi(loc_m));
|
||||
int data_bin_start = calc_data_bin(z_bin, r_bin, phi_bin, 0);
|
||||
int data_bin_end = calc_data_bin(z_bin, r_bin, phi_bin, E_scale.get_number_bins());
|
||||
double sum = 0;
|
||||
for (int data_bin=data_bin_start; data_bin<data_bin_end; data_bin++) {
|
||||
sum += data[data_bin];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
loc_bins Pop4_Container::get_loc_bins(const vec3 &loc_m) {
|
||||
loc_bins res;
|
||||
res.z_bin = z_scale.calc_index(calc_z_m(loc_m));
|
||||
res.r_bin = r_scale.calc_index(calc_r_m(loc_m));
|
||||
res.phi_bin = phi_scale.calc_index(calc_phi(loc_m));
|
||||
return res;
|
||||
}
|
||||
|
||||
int Pop4_Container::calc_data_bin(int z_bin, int r_bin, int phi_bin, int E_bin) {
|
||||
return z_offset*z_bin + r_offset*r_bin + phi_offset*phi_bin + E_bin;
|
||||
}
|
||||
|
||||
@@ -13,14 +13,17 @@
|
||||
#include "katrin_geo.h"
|
||||
#include "timer.hpp"
|
||||
|
||||
struct loc_bins {
|
||||
int z_bin;
|
||||
int r_bin;
|
||||
int phi_bin;
|
||||
};
|
||||
|
||||
class Pop4_Container {
|
||||
double ****data;
|
||||
Lin_Scale z_scale;
|
||||
Lin_Scale r_scale;
|
||||
Lin_Scale phi_scale;
|
||||
double *data;
|
||||
Lin_Scale z_scale, r_scale, phi_scale;
|
||||
Log_Scale E_scale;
|
||||
|
||||
int z_offset, r_offset, phi_offset, total_data_size;
|
||||
public:
|
||||
//Pop4_Container() {};
|
||||
Pop4_Container(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins);
|
||||
@@ -32,19 +35,27 @@ public:
|
||||
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_value_sum(const vec3 &loc_m);
|
||||
|
||||
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];}
|
||||
void set_value_by_bin(double value, int z_bin, int r_bin, int phi_bin, int E_bin) {data[calc_data_bin(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[calc_data_bin(z_bin, r_bin, phi_bin, E_bin)];}
|
||||
|
||||
loc_bins get_loc_bins(const vec3 &loc_m);
|
||||
int get_num_E_bins() {return E_scale.get_number_bins();}
|
||||
|
||||
double get_lower_E_boarder_eV(int E_bin) {return E_scale.get_lower_bin_bound(E_bin);}
|
||||
double get_upper_E_boarder_eV(int E_bin) {return E_scale.get_upper_bin_bound(E_bin);}
|
||||
|
||||
Lin_Scale get_z_scale(){return z_scale;}
|
||||
Lin_Scale get_r_scale(){return r_scale;}
|
||||
Lin_Scale calc_phi_scale(){return phi_scale;}
|
||||
Log_Scale get_E_scale(){return E_scale;}
|
||||
|
||||
int calc_data_bin(int z_bin, int r_bin, int phi_bin, int E_bin);
|
||||
|
||||
public:
|
||||
int get_total_data_size() {return total_data_size;}
|
||||
double *get_array() {return data;}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -65,6 +65,11 @@ public:
|
||||
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;
|
||||
|
||||
virtual int get_array_length() = 0;
|
||||
virtual double *get_cumulated_time_s_array() = 0;
|
||||
virtual double *get_offset_array() = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -19,14 +19,14 @@ void Population_Load_Saver::save() {
|
||||
}
|
||||
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);
|
||||
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();
|
||||
string parameter_name = get_parameter_filenamepath();
|
||||
stringstream save_path;
|
||||
save_path<<parameter_name<<"_save_populations.dat";
|
||||
return save_path.str();
|
||||
@@ -64,13 +64,13 @@ void Population_Load_Saver::write_species(ofstream *save_stream, species this_sp
|
||||
*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";
|
||||
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";
|
||||
}
|
||||
@@ -184,8 +184,8 @@ species Population_Load_Saver::get_species_line(std::ifstream *load_stream) {
|
||||
}
|
||||
|
||||
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) {
|
||||
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());
|
||||
|
||||
@@ -46,8 +46,8 @@ inline void Population_Logger::create_h5tb_meta(hid_t *h5g) {
|
||||
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);
|
||||
for (meta_vec::iterator itr = bins_meta_info.begin(); itr != bins_meta_info.end(); itr++) {
|
||||
h5tb_meta.write(*itr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ inline void Population_Logger::create_h5tb(hid_t *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);
|
||||
for (bin_content_vec::iterator itr = bins_content.begin(); itr != bins_content.end(); itr++) {
|
||||
temp = transform(*itr);
|
||||
h5tb.write(temp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +161,11 @@ inline std::string get_time_string() {
|
||||
|
||||
inline std::string get_homebase() {
|
||||
std::string homebase = get_enviroment_variable("HOMEBASE");
|
||||
if (homebase == "") {
|
||||
std::stringstream ss;
|
||||
ss<<"HOMEBASE not defined!\n.";
|
||||
throw MyException (ss.str());
|
||||
}
|
||||
homebase = make_path(homebase);
|
||||
return homebase;
|
||||
}
|
||||
@@ -177,7 +182,7 @@ inline std::string remove_cat (std::string cat_string) {
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string get_parameter_filename() {
|
||||
inline std::string get_parameter_filenamepath() {
|
||||
std::string parameter_file_path = getenv("parpath");
|
||||
std::string parameter_file_name = remove_cat(getenv("parfile"));
|
||||
return parameter_file_path + "/" + parameter_file_name;
|
||||
|
||||
+160
-125
@@ -10,147 +10,182 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
const long int Simulation::seed = load_parameter("seed");
|
||||
const long int Simulation::numberTotalDecays = load_parameter("numberTotalDecays");
|
||||
const long int Simulation::simulationStepWidth = load_parameter("simulationStepWidth");
|
||||
|
||||
void Simulation::init() {
|
||||
set_RNGs();
|
||||
|
||||
timer = Timer(&numberDecays);
|
||||
part_loggers = Particle_Logger_Builder::build(&h5f);
|
||||
populations = Population_Builder::build(&timer, &rngUni, &rngNormal);
|
||||
|
||||
injector = Injector(&rngUni, &rngNormal);
|
||||
movers = Mover_Builder::build(&part_loggers, &populations);
|
||||
interactions = Interaction_Builder::build(&populations, &rngUni);
|
||||
terminators = Terminator_Builder::build();
|
||||
|
||||
pop_loggers = Population_Logger_Builder::build(&h5f, &populations, &timer);
|
||||
pop_load_saver = Population_Load_Saver(&populations, &timer);
|
||||
|
||||
set_statusUpdater();
|
||||
Simulation::Simulation() {
|
||||
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
|
||||
looper.init(calc_seed(), calc_ID_offset(), calc_outfile_path());
|
||||
init_pop_arrays();
|
||||
}
|
||||
Simulation::~Simulation() {
|
||||
deconstruct_pop_arrays();
|
||||
}
|
||||
|
||||
void Simulation::set_RNGs() {
|
||||
rngUni.seed(seed);
|
||||
rngNormal.seed(seed);
|
||||
void Simulation::init_pop_arrays() {
|
||||
vector<species> all_species = get_all_spieces_vector();
|
||||
number_pop_species = all_species.size();
|
||||
|
||||
pop_species = new species[number_pop_species];
|
||||
pop_array_lengths = new int[number_pop_species];
|
||||
global_cum_time_s = new double *[number_pop_species];
|
||||
global_offset = new double *[number_pop_species];
|
||||
|
||||
Population_Manager *populations = looper.get_populations();
|
||||
Population_Base *population;
|
||||
for (int i = 0; i<number_pop_species; i++) {
|
||||
pop_species[i] = all_species[i];
|
||||
population = populations->find(pop_species[i]);
|
||||
pop_array_lengths[i] = population->get_array_length();
|
||||
global_cum_time_s[i] = new double[pop_array_lengths[i]];
|
||||
global_offset[i] = new double[pop_array_lengths[i]];
|
||||
for (int j = 0; j<pop_array_lengths[i]; j++) {
|
||||
global_cum_time_s[i][j] = 0;
|
||||
global_offset[i][j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::set_statusUpdater() {
|
||||
updater_fraction = numberTotalDecays/100;
|
||||
updater_fraction = updater_fraction==0 ? 1 : updater_fraction;
|
||||
void Simulation::deconstruct_pop_arrays() {
|
||||
delete[] pop_species;
|
||||
delete[] pop_array_lengths;
|
||||
for (int i = 0; i<number_pop_species; i++) {
|
||||
delete[] global_cum_time_s[i];
|
||||
delete[] global_offset[i];
|
||||
}
|
||||
delete[] global_cum_time_s;
|
||||
delete[] global_offset;
|
||||
}
|
||||
|
||||
long int Simulation::calc_ID_offset() {
|
||||
return numberTotalDecays * 1000 * mpi_rank;
|
||||
}
|
||||
|
||||
long int Simulation::calc_seed() {
|
||||
return seed + mpi_rank;
|
||||
}
|
||||
|
||||
std::string Simulation::calc_outfile_path() {
|
||||
int dir_number;
|
||||
std::string dirname;
|
||||
if (mpi_rank == 0) {
|
||||
dir_number = calc_dir_number();
|
||||
dirname = build_dirname(dir_number);
|
||||
create_out_dir(dirname);
|
||||
MPI_Bcast(&dir_number, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
||||
cout<<"Logging to folder "<<dirname<<"\n";
|
||||
} else {
|
||||
MPI_Bcast(&dir_number, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
||||
dirname = build_dirname(dir_number);
|
||||
}
|
||||
MPI_Barrier(MPI_COMM_WORLD);
|
||||
std::stringstream filename;
|
||||
filename<<dirname<<"mc_electron_out_"<<mpi_rank<<".h5";
|
||||
return filename.str();
|
||||
}
|
||||
|
||||
int Simulation::calc_dir_number() {
|
||||
string parname = get_parameter_filenamepath();
|
||||
stringstream dirname;
|
||||
int i = 0;
|
||||
do {
|
||||
dirname.str(std::string());
|
||||
dirname << parname << "_" << get_time_string() << "_" << ++i;
|
||||
} while ( is_dir(dirname.str()) );
|
||||
return i;
|
||||
}
|
||||
|
||||
std::string Simulation::build_dirname(int dir_number) {
|
||||
string parname = get_parameter_filenamepath();
|
||||
stringstream dirname;
|
||||
dirname.str(std::string());
|
||||
dirname << parname << "_" << get_time_string() << "_" << dir_number<<"/";
|
||||
return dirname.str();
|
||||
}
|
||||
|
||||
void Simulation::create_out_dir(std::string dirname) {
|
||||
if (mkdir(dirname.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::create_out_dir: Could not create output directiory.\n outdirName = "<<dirname<<endl;
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::doit() {
|
||||
Mover_Base *moverPtr;
|
||||
Interaction_Base *interactionPtr;
|
||||
Terminator_Base *terminatorPtr;
|
||||
|
||||
InteractionOut IntOut;
|
||||
double macroSigma_m2;
|
||||
std::deque<Particle> partQue;
|
||||
Particle curPart;
|
||||
vec3 oldLoc_m;
|
||||
while ( (numberDecays < numberTotalDecays) || (!partQue.empty()) ) {
|
||||
if (partQue.empty()) {
|
||||
pop_loggers.log();
|
||||
curPart = injector.injectElectron(numberTotalParticles);
|
||||
numberDecays++;
|
||||
numberTotalParticles++;
|
||||
do_statusUpdate();
|
||||
} else {
|
||||
curPart = partQue.front();
|
||||
partQue.pop_front();
|
||||
}
|
||||
moverPtr = movers.find(curPart.get_species());
|
||||
interactionPtr = interactions.find(curPart.get_species());
|
||||
terminatorPtr = terminators.find(curPart.get_species());
|
||||
|
||||
while (!terminatorPtr->checkTermination(curPart)) {
|
||||
oldLoc_m = curPart.get_x_m();
|
||||
macroSigma_m2 = interactionPtr->get_macroSigma_m2(curPart);
|
||||
moverPtr->move(&curPart, macroSigma_m2);
|
||||
if (!terminatorPtr->checkTermination(curPart)) {
|
||||
IntOut = interactionPtr->do_Interaction(&curPart);
|
||||
|
||||
for (int i=0; i<IntOut.get_number_new_particles(); i++) {
|
||||
partQue.push_back(IntOut.get_new_particles()[i]);
|
||||
partQue.back().set_Id(numberTotalParticles++);
|
||||
}
|
||||
if (IntOut.get_delete_current()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
long int decays_this_cpu = numberTotalDecays/mpi_size;
|
||||
int overflow = numberTotalDecays/mpi_size;
|
||||
if (overflow < mpi_rank) { // Split overflows equaly to left over CPUs.
|
||||
decays_this_cpu += 1;
|
||||
}
|
||||
pop_loggers.log();
|
||||
int num_cycles = decays_this_cpu/simulationStepWidth;
|
||||
int num_remaining = decays_this_cpu%simulationStepWidth;
|
||||
|
||||
for (int i = 0; i<(num_cycles-1); i++) {
|
||||
do_decays(simulationStepWidth);
|
||||
}
|
||||
do_decays(simulationStepWidth + num_remaining);
|
||||
};
|
||||
|
||||
void Simulation::do_decays(int number_decays) {
|
||||
looper.do_loops(number_decays);
|
||||
number_local_decays += number_decays;
|
||||
sync_cpus();
|
||||
do_statusUpdate();
|
||||
}
|
||||
|
||||
void Simulation::sync_cpus() {
|
||||
MPI_Allreduce(&number_local_decays, &number_global_decays, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
|
||||
looper.set_global_decays(number_global_decays - number_local_decays);
|
||||
sync_populations();
|
||||
}
|
||||
|
||||
void Simulation::sync_populations() {
|
||||
|
||||
Population_Manager *populations = looper.get_populations();
|
||||
Population_Base *population;
|
||||
double *global_delta_cumulated_time_s;
|
||||
double *global_delta_offset;
|
||||
double *local_delta_cumulated_time_s;
|
||||
double *local_delta_offset;
|
||||
int array_length;
|
||||
for (int i = 0; i<number_pop_species; i++) {
|
||||
population = populations->find(pop_species[i]);
|
||||
array_length = pop_array_lengths[i];
|
||||
if (array_length == 0) {
|
||||
continue;
|
||||
}
|
||||
global_delta_cumulated_time_s = new double[array_length];
|
||||
global_delta_offset = new double[array_length];
|
||||
local_delta_cumulated_time_s = new double[array_length];
|
||||
local_delta_offset = new double[array_length];
|
||||
|
||||
for (int j = 0; j<array_length; j++) {
|
||||
local_delta_cumulated_time_s[j] = population->get_cumulated_time_s_array()[j] - global_cum_time_s[i][j];
|
||||
local_delta_offset[j] = population->get_offset_array()[j] - global_offset[i][j];
|
||||
}
|
||||
|
||||
MPI_Allreduce(local_delta_cumulated_time_s, global_delta_cumulated_time_s, array_length, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
|
||||
MPI_Allreduce(local_delta_offset, global_delta_offset, array_length, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
|
||||
|
||||
for (int j = 0; j<pop_array_lengths[i]; j++) {
|
||||
global_cum_time_s[i][j] += global_delta_cumulated_time_s[j];
|
||||
global_offset[i][j] += global_delta_offset[j];
|
||||
population->get_cumulated_time_s_array()[j] = global_cum_time_s[i][j];
|
||||
population->get_offset_array()[j] = global_offset[i][j];
|
||||
}
|
||||
delete[] global_delta_cumulated_time_s;
|
||||
delete[] global_delta_offset;
|
||||
delete[] local_delta_cumulated_time_s;
|
||||
delete[] local_delta_offset;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Simulation::do_statusUpdate() {
|
||||
if (numberDecays%updater_fraction == 0){
|
||||
cout<<numberDecays<<"/"<<numberTotalDecays<<endl;
|
||||
if (mpi_rank == 0) {
|
||||
cout<<"Status: "<<number_global_decays<<"/"<<numberTotalDecays<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void Simulation::doTC6() {
|
||||
cout<<endl<<"Simulation::doTC6: Doing Testcase 6."<<endl<<endl;
|
||||
parameterCheck_TC6();
|
||||
|
||||
while ( (numberTotalElectrons < numberTotalDecays) || (electronQue.size() > 0) ) {
|
||||
if (!electronQue.empty()) {
|
||||
throw MyException("Simulation::doTC6: electronQue should be empty");
|
||||
}
|
||||
electronQue.push_back(Kat.injectElectron(numberTotalElectrons++, &rngUni, &rngNormal));
|
||||
do_interaction(&electronQue.front()); //parameter should only allow for ionizations
|
||||
electronQue.pop_front(); // delete initial electron
|
||||
Log.log_Electron(&electronQue.front(), vec3(0,0,0)); //should be daugther electron
|
||||
electronQue.pop_front(); //delete daugther electron
|
||||
}
|
||||
};
|
||||
|
||||
void Simulation::do_interaction(Electron *interactElectron) {
|
||||
vec3 newLoc_m = electronQue.front().get_x_m();
|
||||
if (Kat.check_Termination(*interactElectron)) {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::do_interaction: Particle already terminated.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
int process = interactElectron->roll_Interaction(Kat.get_T2_flowSpeed_ms(newLoc_m),&rngUni);
|
||||
switch (process) {
|
||||
case 1: // Elastic Scattering
|
||||
interactElectron->do_elaScattering(Kat.roll_T2_v_ms(newLoc_m, &rngUni, &rngNormal) , &rngUni);
|
||||
break;
|
||||
case 2: // Ionization
|
||||
electronQue.push_back( interactElectron->do_Ionization(Kat.roll_T2_v_ms(newLoc_m, &rngUni, &rngNormal), numberTotalElectrons, &rngUni) );
|
||||
numberTotalElectrons++;
|
||||
// Update Ions...
|
||||
break;
|
||||
case 3: // Recombination
|
||||
break;
|
||||
default:
|
||||
stringstream ss;
|
||||
ss<<"Simulation::do_interaction: process="<<process<< "not defined.";
|
||||
throw MyException(ss.str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Simulation::parameterCheck_TC6() {
|
||||
if (
|
||||
load_parameter("injectionMethod") == 1 &&
|
||||
load_parameter("elaOn") == 0 &&
|
||||
load_parameter("ionOn") == 1 &&
|
||||
load_parameter("numberZBins") == -1
|
||||
) {
|
||||
return;
|
||||
}else {
|
||||
throw MyException("Simulation::parameterCheck_TC6: Some Parameter is wrong");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -9,71 +9,49 @@
|
||||
#ifndef simulation_hpp
|
||||
#define simulation_hpp
|
||||
|
||||
#include "h5_file.hpp"
|
||||
#include "timer.hpp"
|
||||
|
||||
#include "logger_builder.hpp"
|
||||
#include "population_builder.hpp"
|
||||
|
||||
#include "injector.hpp"
|
||||
#include "mover_builder.hpp"
|
||||
#include "interaction_builder.hpp"
|
||||
#include "terminator_builder.hpp"
|
||||
|
||||
#include "population_load_saver.hpp"
|
||||
|
||||
#include "particle_looper.hpp"
|
||||
|
||||
class Simulation {
|
||||
static const long int seed;
|
||||
static const long int numberTotalDecays;
|
||||
static const long int simulationStepWidth;
|
||||
|
||||
UniRNG rngUni;
|
||||
NormalRNG rngNormal;
|
||||
long int numberTotalParticles = 0;
|
||||
long int number_local_decays = 0;
|
||||
long int number_global_decays = 0;
|
||||
|
||||
H5_File h5f;
|
||||
Timer timer;
|
||||
Particle_Looper looper;
|
||||
|
||||
Particle_Logger_Manager part_loggers;
|
||||
Population_Manager populations;
|
||||
int mpi_rank;
|
||||
int mpi_size;
|
||||
|
||||
|
||||
Injector injector;
|
||||
Mover_Manager movers;
|
||||
Interaction_Manager interactions;
|
||||
Terminator_Manager terminators;
|
||||
|
||||
Population_Logger_Manager pop_loggers;
|
||||
Population_Load_Saver pop_load_saver;
|
||||
|
||||
|
||||
int numberTotalParticles = 0;
|
||||
int numberDecays = 0;
|
||||
|
||||
int updater_fraction;
|
||||
int number_pop_species;
|
||||
species *pop_species;
|
||||
int *pop_array_lengths;
|
||||
double **global_cum_time_s, **global_offset;
|
||||
|
||||
public:
|
||||
Simulation() {
|
||||
init();
|
||||
pop_load_saver.load();
|
||||
}
|
||||
~Simulation() {
|
||||
pop_load_saver.save();
|
||||
}
|
||||
|
||||
Simulation();
|
||||
~Simulation();
|
||||
private:
|
||||
void init();
|
||||
void set_RNGs();
|
||||
void set_statusUpdater();
|
||||
void init_pop_arrays();
|
||||
void deconstruct_pop_arrays();
|
||||
|
||||
long int calc_ID_offset();
|
||||
long int calc_seed();
|
||||
|
||||
std::string calc_outfile_path();
|
||||
int calc_dir_number();
|
||||
std::string build_dirname(int dir_number);
|
||||
void create_out_dir(std::string dirname);
|
||||
|
||||
public:
|
||||
void doit();
|
||||
private:
|
||||
void do_decays(int number_decays);
|
||||
void sync_cpus();
|
||||
void sync_populations();
|
||||
void do_statusUpdate();
|
||||
|
||||
public:
|
||||
void doTC6();
|
||||
private:
|
||||
void parameterCheck_TC6();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// simulation_serial.cpp
|
||||
// mc_electron_serial
|
||||
//
|
||||
// Created by Christian Reiling on 17.07.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "simulation_serial.hpp"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
const long int Simulation::seed = load_parameter("seed");
|
||||
const long int Simulation::numberTotalDecays = load_parameter("numberTotalDecays");
|
||||
const long int Simulation::simulationStepWidth = load_parameter("simulationStepWidth");
|
||||
|
||||
std::string Simulation::calc_outfile_path() {
|
||||
string parname = get_parameter_filenamepath();
|
||||
stringstream H5name;
|
||||
int i = 1;
|
||||
do {
|
||||
H5name.str(std::string());
|
||||
H5name << parname << "_" << get_time_string() << "_" << i++<<".h5";
|
||||
} while ( is_file(H5name.str()) );
|
||||
return H5name.str();
|
||||
}
|
||||
|
||||
void Simulation::doit() {
|
||||
int num_cycles = numberTotalDecays/simulationStepWidth;
|
||||
int num_remaining = numberTotalDecays%simulationStepWidth;
|
||||
for (int i = 0; i<(num_cycles-1); i++) {
|
||||
do_decays(simulationStepWidth);
|
||||
}
|
||||
do_decays(simulationStepWidth + num_remaining);
|
||||
cout<<"Total particles: "<<looper.get_number_total_particles()<<"\n";
|
||||
};
|
||||
|
||||
void Simulation::do_decays(int number_decays) {
|
||||
looper.do_loops(number_decays);
|
||||
number_current_decays += number_decays;
|
||||
do_statusUpdate();
|
||||
}
|
||||
|
||||
void Simulation::do_statusUpdate() {
|
||||
cout<<number_current_decays<<"/"<<numberTotalDecays<<endl;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// simulation_serial.hpp
|
||||
// mc_electron_serial
|
||||
//
|
||||
// Created by Christian Reiling on 17.07.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef simulation_serial_hpp
|
||||
#define simulation_serial_hpp
|
||||
|
||||
#include "particle_looper.hpp"
|
||||
|
||||
class Simulation {
|
||||
static const long int seed;
|
||||
static const long int numberTotalDecays;
|
||||
static const long int simulationStepWidth;
|
||||
|
||||
long int number_current_decays = 0;
|
||||
|
||||
Particle_Looper looper;
|
||||
|
||||
public:
|
||||
Simulation() {
|
||||
|
||||
looper.init(seed, 0, calc_outfile_path());
|
||||
}
|
||||
~Simulation() {}
|
||||
|
||||
|
||||
private:
|
||||
std::string calc_outfile_path();
|
||||
|
||||
public:
|
||||
void doit();
|
||||
private:
|
||||
void do_decays(int number_decays);
|
||||
void do_statusUpdate();
|
||||
};
|
||||
|
||||
#endif /* simulation_serial_hpp */
|
||||
@@ -70,15 +70,15 @@ void Stacked_Container<T_Map>::rec_calcMap(const dim1Map &subMap, std::deque<dou
|
||||
Points.pop_back();
|
||||
Points.pop_back();
|
||||
|
||||
dim1Map::const_iterator preItr;
|
||||
for (dim1Map::const_iterator curItr = (++subMap.cbegin()); curItr!=subMap.cend(); curItr++) {
|
||||
preItr = curItr;
|
||||
--preItr;
|
||||
width = curItr->first - preItr->first;
|
||||
heigth = curItr->second/tot;
|
||||
dim1Map::const_iterator preitr;
|
||||
for (dim1Map::const_iterator curitr = (++subMap.cbegin()); curitr!=subMap.cend(); curitr++) {
|
||||
preitr = curitr;
|
||||
--preitr;
|
||||
width = curitr->first - preitr->first;
|
||||
heigth = curitr->second/tot;
|
||||
curVal += width*heigth;
|
||||
Points.push_back(curVal);
|
||||
Points.push_back(curItr->first);
|
||||
Points.push_back(curitr->first);
|
||||
Base_Container<T_Map>::addPoint(Points);
|
||||
Points.pop_back();
|
||||
Points.pop_back();
|
||||
@@ -88,9 +88,9 @@ void Stacked_Container<T_Map>::rec_calcMap(const dim1Map &subMap, std::deque<dou
|
||||
template <class T_Map>
|
||||
template <typename T>
|
||||
void Stacked_Container<T_Map>::rec_calcMap(const T &subMap, std::deque<double> Points) {
|
||||
for (typename T::const_iterator Itr = subMap.cbegin(); Itr!= subMap.cend(); Itr++) {
|
||||
Points.push_back(Itr->first);
|
||||
rec_calcMap(Itr->second, Points);
|
||||
for (typename T::const_iterator itr = subMap.cbegin(); itr!= subMap.cend(); itr++) {
|
||||
Points.push_back(itr->first);
|
||||
rec_calcMap(itr->second, Points);
|
||||
Points.pop_back();
|
||||
}
|
||||
}
|
||||
@@ -103,12 +103,12 @@ double Stacked_Container<T_Map>::calc_tot(const dim1Map &subMap) {
|
||||
width = subMap.begin()->first - lowerEdge;
|
||||
heigth = subMap.begin()->second;
|
||||
tot += width*heigth;
|
||||
dim1Map::const_iterator preItr;
|
||||
for (dim1Map::const_iterator curItr = (++subMap.cbegin()); curItr!=subMap.cend(); curItr++) {
|
||||
preItr = curItr;
|
||||
--preItr;
|
||||
width = curItr->first - preItr->first;
|
||||
heigth = curItr->second;
|
||||
dim1Map::const_iterator preitr;
|
||||
for (dim1Map::const_iterator curitr = (++subMap.cbegin()); curitr!=subMap.cend(); curitr++) {
|
||||
preitr = curitr;
|
||||
--preitr;
|
||||
width = curitr->first - preitr->first;
|
||||
heigth = curitr->second;
|
||||
tot += width*heigth;
|
||||
}
|
||||
return tot;
|
||||
|
||||
@@ -13,8 +13,8 @@ using namespace std;
|
||||
|
||||
void ThermalPop_Container::set_Map() {
|
||||
vector<vec3> bins = get_bins();
|
||||
for (vector<vec3>::iterator Itr = bins.begin(); Itr!=bins.end(); Itr++) {
|
||||
addPoint(ddeque{(*Itr)[0], (*Itr)[1], (*Itr)[2], 0});
|
||||
for (vector<vec3>::iterator itr = bins.begin(); itr!=bins.end(); itr++) {
|
||||
addPoint(ddeque{(*itr)[0], (*itr)[1], (*itr)[2], 0});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,11 +43,11 @@ void ThermalPop_Container::upDensity (const Particle &upParticle, const vec3 &ol
|
||||
double l_m = get_l_m();
|
||||
double vAbs_ms = upParticle.get_vAbs_ms();
|
||||
|
||||
dim3Map::iterator zItr_min = Map.lower_bound(z_min_m);
|
||||
dim3Map::iterator zItr_max = Map.lower_bound(z_max_m);
|
||||
dim3Map::iterator zitr_min = Map.lower_bound(z_min_m);
|
||||
dim3Map::iterator zitr_max = Map.lower_bound(z_max_m);
|
||||
|
||||
for (dim3Map::iterator Itr = zItr_min;Itr != zItr_max;Itr++) {
|
||||
Itr->second.lower_bound(r_m)->second.lower_bound(phi)->second += l_m/vAbs_ms;
|
||||
for (dim3Map::iterator itr = zitr_min;itr != zitr_max;itr++) {
|
||||
itr->second.lower_bound(r_m)->second.lower_bound(phi)->second += l_m/vAbs_ms;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,10 @@ private:
|
||||
Lin_Scale get_r_scale();
|
||||
Lin_Scale calc_phi_scale();
|
||||
|
||||
public:
|
||||
int get_array_length();
|
||||
double *get_cumulated_time_s_array();
|
||||
double *get_offset_array();
|
||||
};
|
||||
|
||||
|
||||
@@ -212,12 +216,12 @@ inline void Thermal_Population::set_bins(bin_count4 bin_counts, bin_content_vec
|
||||
}
|
||||
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;
|
||||
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);
|
||||
}
|
||||
@@ -253,5 +257,15 @@ inline Lin_Scale Thermal_Population::calc_phi_scale() {
|
||||
}
|
||||
}
|
||||
|
||||
inline int Thermal_Population::get_array_length() {
|
||||
return cumulated_times_s.get_total_data_size();
|
||||
}
|
||||
|
||||
inline double *Thermal_Population::get_cumulated_time_s_array() {
|
||||
return cumulated_times_s.get_array();
|
||||
}
|
||||
|
||||
inline double *Thermal_Population::get_offset_array() {
|
||||
return number_annhilated.get_array();
|
||||
}
|
||||
#endif /* Thermal_Population_h */
|
||||
|
||||
@@ -6,16 +6,34 @@
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "timer.hpp"
|
||||
|
||||
#include "read_system.h"
|
||||
|
||||
const double Timer::wgtsT2MaxDensity_m3 = load_parameter("wgtsT2MaxDensity_m3");
|
||||
|
||||
double Timer::get_physTime_s() {
|
||||
return double(*numTotDecays)/T2_activity_s + offset_time_s;
|
||||
const double Timer::wgtsT2MaxDensity_m3 = load_parameter("wgtsT2MaxDensity_m3");
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
Timer::Timer(const Timer& other) {
|
||||
T2_activity_s = other.T2_activity_s;
|
||||
offset_time_s = other.offset_time_s;
|
||||
local_decays = &(*other.local_decays);
|
||||
global_decays = &(*other.global_decays);
|
||||
}
|
||||
|
||||
Timer& Timer::operator=(const Timer& other) {
|
||||
Timer tmp(other);
|
||||
swap(T2_activity_s, tmp.T2_activity_s);
|
||||
swap(offset_time_s, tmp.offset_time_s);
|
||||
local_decays = &(*tmp.local_decays);
|
||||
global_decays = &(*tmp.global_decays);
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
|
||||
void Timer::set_T2_activity_s() {
|
||||
double r_m = r_WGTS_m;
|
||||
double l_m = l_WGTS_m;
|
||||
@@ -24,4 +42,10 @@ void Timer::set_T2_activity_s() {
|
||||
T2_activity_s = NT2*decayConstT2_s;
|
||||
}
|
||||
|
||||
double Timer::get_physTime_s() {
|
||||
return double(calc_total_decays())/T2_activity_s + offset_time_s;
|
||||
}
|
||||
|
||||
long int Timer::calc_total_decays() {
|
||||
return (*local_decays + *global_decays);
|
||||
}
|
||||
|
||||
@@ -16,20 +16,30 @@ class Timer {
|
||||
double T2_activity_s;
|
||||
double offset_time_s;
|
||||
|
||||
int *numTotDecays;
|
||||
long int *local_decays;
|
||||
long int *global_decays;
|
||||
|
||||
public:
|
||||
Timer() {numTotDecays = NULL;}
|
||||
Timer(int *numTotDecays) {
|
||||
this->numTotDecays = numTotDecays;
|
||||
Timer () {};
|
||||
Timer(long int *local_decays, long int *global_decays) {
|
||||
this->local_decays = local_decays;
|
||||
this->global_decays = global_decays;
|
||||
offset_time_s = 0;
|
||||
set_T2_activity_s();
|
||||
}
|
||||
double get_physTime_s();
|
||||
//Timer(const Timer& other);
|
||||
//Timer& operator=(const Timer& other);
|
||||
|
||||
void set_offset_time_s(double new_offset_time_s) {offset_time_s = new_offset_time_s;}
|
||||
|
||||
private:
|
||||
void set_T2_activity_s();
|
||||
|
||||
public:
|
||||
double get_physTime_s();
|
||||
private:
|
||||
long int calc_total_decays();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -51,6 +51,11 @@ public:
|
||||
private:
|
||||
double calc_DensityTriangle(const double &z_m);
|
||||
double interpolate_red(const double &z_m, const double &z_min_m, const double &z_max_m, const double &red_min, const double &red_max);
|
||||
|
||||
public:
|
||||
int get_array_length() {return 0;}
|
||||
double *get_cumulated_time_s_array() {return NULL;}
|
||||
double *get_offset_array() {return NULL;}
|
||||
};
|
||||
|
||||
const double T2_Population::wgtsT2MaxDensity_m3 = load_parameter("wgtsT2MaxDensity_m3");
|
||||
|
||||
Reference in New Issue
Block a user