eT2_T2I_Ionization_Janev_(label) 1. non dissoziative labeled as ndiss 2. dissoziative via X2 Sigma^+_g labeled as diss_g 3. dissoziative via B2 Sigma^+_u labeled as diss_u Added more Excitation Channels e + T2 from Janev
229 lines
7.6 KiB
C++
229 lines
7.6 KiB
C++
//
|
|
// 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);
|
|
}
|