Loading proper velocity from gas flow simulation into the simulation.
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// velocity_container.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 30.07.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "velocity_container.hpp"
|
||||
|
||||
#include "read_system.h"
|
||||
|
||||
Velocity_Container::Velocity_Container(std::string load_path) {
|
||||
z_scale = Lin_Scale(z_WGTS_start_m, z_WGTS_end_m, num_z_bins);
|
||||
r_scale = Lin_Scale(0, r_WGTS_m, num_r_bins);
|
||||
int num_tot_bins = num_z_bins * num_r_bins;
|
||||
vz_data = new double[num_tot_bins];
|
||||
vr_data = new double[num_tot_bins];
|
||||
load_data(load_path);
|
||||
}
|
||||
|
||||
Velocity_Container::~Velocity_Container() {
|
||||
delete[] vz_data;
|
||||
delete[] vr_data;
|
||||
}
|
||||
|
||||
void Velocity_Container::load_data(std::string load_path) {
|
||||
int num_tot_bins = num_z_bins * num_r_bins;
|
||||
bool *check_array = new bool[num_tot_bins];
|
||||
for (int i = 0; i< num_tot_bins; i++) {
|
||||
check_array[i] = false;
|
||||
}
|
||||
|
||||
std::ifstream importStream(load_path);
|
||||
if (!importStream.good()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Velocity_Container::load_data: Could not open file. \n loadFilePath= "<<load_path<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
std::string csv_line;
|
||||
while (getline(importStream, csv_line)) {
|
||||
remove_leading_whites(csv_line);
|
||||
replace_delimiter(csv_line);
|
||||
if ( check_ignore_line(csv_line) ) {
|
||||
continue;
|
||||
}
|
||||
read_line(csv_line, check_array);
|
||||
}
|
||||
importStream.close();
|
||||
|
||||
for (int i = 0; i< num_tot_bins; i++) {
|
||||
if (!check_array[i]) {
|
||||
std::stringstream ss;
|
||||
ss<<"Velocity_Container::load_data: Not all bins loaded.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
delete[] check_array;
|
||||
}
|
||||
|
||||
void Velocity_Container::read_line(std::string csv_line, bool *check_array) {
|
||||
std::stringstream ss;
|
||||
ss.str(csv_line);
|
||||
int temp_bin;
|
||||
double temp_vz, temp_vr;
|
||||
if (ss>>temp_bin && ss>>temp_vz && ss>>temp_vr) {
|
||||
vz_data[temp_bin] = temp_vz;
|
||||
vr_data[temp_bin] = temp_vr;
|
||||
check_array[temp_bin] = true;
|
||||
} else {
|
||||
std::cout<<"Velocity_Container::load_data: Warning could not read line in inputFile. \nloadFilePath\t"<<csv_line<<"\n";
|
||||
}
|
||||
}
|
||||
vec3 Velocity_Container::get_v_ms (const vec3 &loc_m) {
|
||||
int bin =calc_data_bin(loc_m);
|
||||
double phi = calc_phi(loc_m);
|
||||
return vec3(cos(phi)*vr_data[bin], sin(phi)*vr_data[bin], vz_data[bin]);
|
||||
}
|
||||
|
||||
int Velocity_Container::calc_data_bin(const vec3 &loc_m) {
|
||||
double z_m = calc_z_m(loc_m);
|
||||
double r_m = calc_r_m(loc_m);
|
||||
int z_bin = z_scale.calc_index(z_m);
|
||||
int r_bin = r_scale.calc_index(r_m);
|
||||
return z_bin * num_r_bins + r_bin;
|
||||
};
|
||||
Reference in New Issue
Block a user