Changed Population Container -> more precice calculation of time in cells.

This commit is contained in:
Christian
2019-08-05 17:51:32 +02:00
parent 34a569552a
commit 0d38ed659a
36 changed files with 655 additions and 1204 deletions
+88 -56
View File
@@ -12,13 +12,22 @@ using namespace std;
void Population_Load_Saver::save() {
ofstream save_stream(get_save_path());
write_overhead(&save_stream);
vector<species> all_species = get_all_species_vector();
for (vector<species>::iterator itr = all_species.begin(); itr!= all_species.end(); itr++) {
if (populations->find(*itr)->access_container() != nullptr) {
write_species(&save_stream, *itr);
}
}
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);
}
@@ -34,9 +43,9 @@ string Population_Load_Saver::get_save_path() {
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<<calc_number()<<"\t # Number of Populations \n";
*save_stream<<timer->get_physTime_s()<<"\t # Offset Time in seconds \n";
*save_stream<<timer->get_time_s()<<"\t # Offset Time in seconds \n";
*save_stream<<z_RW_m<<"\t";
*save_stream<<z_WGTS_start_m<<"\t";
@@ -54,41 +63,64 @@ void Population_Load_Saver::write_overhead(ofstream *save_stream) {
}
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();
Population_Container *cont = populations->find(this_species)->access_container();
*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<<cont->scales.z.get_number_bins()<<"\t";
*save_stream<<cont->scales.r.get_number_bins()<<"\t";
*save_stream<<cont->scales.phi.get_number_bins()<<"\t";
*save_stream<<cont->E_scale.get_number_bins()<<"\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 (int i_z = 0; i_z<cont->scales.z.get_number_bins(); i_z++) {
for (int i_r = 0; i_z<cont->scales.r.get_number_bins(); i_z++) {
for (int i_phi = 0; i_z<cont->scales.phi.get_number_bins(); i_z++) {
for (int i_E = 0; i_z<cont->E_scale.get_number_bins(); i_z++) {
int bin = cont->calc_data_bin(Bins{i_z, i_r, i_phi}, i_E);
*save_stream<<i_z<<"\t"<<i_r<<"\t"<<i_phi<<"\t"<<i_E<<"\t";
*save_stream<<cont->cum_times_s[bin]<<"\t";
*save_stream<<cont->offsets[bin]<<"\n";
}
}
}
}
*save_stream<<"end_of_species \n";
}
int Population_Load_Saver::calc_number() {
int num = 0;
vector<species> all_species = get_all_species_vector();
for (vector<species>::iterator itr = all_species.begin(); itr!= all_species.end(); itr++) {
if (populations->find(*itr)->access_container() != nullptr) {
num += 1 ;
}
}
return num;
}
void Population_Load_Saver::load() {
// Maybe change whole system to h5, therefore allowing sloppy style
string load_path = get_enviroment_variable("pop_load_path");
if (load_path.empty()) {
cout<<"No File specified for Population default loading.\n";
cout<<"No File specified for loading Population start values.\n";
return;
}
std::ifstream load_stream(load_path);
ifstream load_stream(load_path);
if (!load_stream.good()) {
std::stringstream ss;
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);
if (number_populations != calc_number()) {
stringstream ss;
ss<<"Population_Load_Saver::load: Number Population missmatch.\n";
throw MyException(ss.str());
}
double offset_time_s = get_offset_time_line(&load_stream);
timer->set_offset_time_s(offset_time_s);
check_katrin_geo_line(&load_stream);
@@ -108,7 +140,7 @@ void Population_Load_Saver::load() {
}
void Population_Load_Saver::goto_nextline(ifstream *load_stream) {
load_stream->ignore(std::numeric_limits<streamsize>::max(), '\n');
load_stream->ignore(numeric_limits<streamsize>::max(), '\n');
}
int Population_Load_Saver::get_num_populations_line(ifstream *load_stream) {
@@ -116,50 +148,50 @@ int Population_Load_Saver::get_num_populations_line(ifstream *load_stream) {
*load_stream>>num_populations;
goto_nextline(load_stream);
if (num_populations < 1) {
std::stringstream ss;
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 Population_Load_Saver::get_offset_time_line(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) {
void Population_Load_Saver::check_katrin_geo_line(ifstream *load_stream) {
double z_RW_m, z_WGTSstart_m, z_WGTSend_m, radius_m;
*load_stream>>z_RW_m;
if ( z_RW_m != z_RW_m) {
std::stringstream ss;
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 != z_WGTS_start_m) {
std::stringstream ss;
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 != z_WGTS_end_m) {
std::stringstream ss;
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 != r_WGTS_m) {
std::stringstream ss;
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) {
void Population_Load_Saver::check_katrin_T2_line(ifstream *load_stream) {
double wgtsT2MaxDensity_m3, wgtsTemp_K, wgtsT2FlowSpeed_ms;
*load_stream>>wgtsT2MaxDensity_m3;
if ( wgtsT2MaxDensity_m3 != load_parameter("wgtsT2MaxDensity_m3")) {
@@ -176,17 +208,17 @@ void Population_Load_Saver::check_katrin_T2_line(std::ifstream *load_stream) {
goto_nextline(load_stream);
}
species Population_Load_Saver::get_species_line(std::ifstream *load_stream) {
species Population_Load_Saver::get_species_line(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++) {
void Population_Load_Saver::append_check_vector(vector<species> *check_vector, species add_species) {
for (vector<species>::iterator itr=check_vector->begin(); itr!=check_vector->end(); itr++) {
if (*itr == add_species) {
std::stringstream ss;
stringstream ss;
ss<<"Population_Load_Saver::append_check_vector: species already loaded.\n";
throw MyException(ss.str());
}
@@ -194,35 +226,35 @@ void Population_Load_Saver::append_check_vector(std::vector<species> *check_vect
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];
void Population_Load_Saver::load_species(ifstream *load_stream, species add_species) {
Population_Container *cont = populations->find(add_species)->access_container();
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);
int num_z_bins, num_r_bins, num_phi_bins, num_E_bins;
*load_stream>>num_z_bins>>num_r_bins>>num_phi_bins>>num_E_bins;
if ( (num_z_bins != cont->scales.z.get_number_bins())
|| (num_r_bins != cont->scales.r.get_number_bins())
|| (num_phi_bins != cont->scales.phi.get_number_bins())
|| (num_E_bins != cont->E_scale.get_number_bins()) ) {
stringstream ss;
ss<<"Population_Load_Saver::load_species: Number bins in scales missmatch.\n";
throw MyException(ss.str());
}
int z_bin, r_bin, phi_bin, E_bin;
for (int i = 0; i< cont->data_size; i++) {
*load_stream>>z_bin>>r_bin>>phi_bin>>E_bin;
if (i != cont->calc_data_bin(Bins{}, E_bin)) {
stringstream ss;
ss<<"Population_Load_Saver::load_species: Input Data bin missmatch.\n";
throw MyException(ss.str());
}
*load_stream>>cont->cum_times_s[i]>>cont->offsets[i];
}
string end_of_species;
*load_stream>>end_of_species;
if (end_of_species!="end_of_species") {
std::stringstream ss;
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);
}