Files
katrin-plasma/src/mc_electron/population4_container.cpp
T
Christian 578d673b65 Moved serial mode to target mcelecron_serial.
Implemented parallelization with mpi.
2019-07-18 14:02:19 +02:00

125 lines
3.8 KiB
C++

//
// population4_container.cpp
// mc_electron
//
// Created by Christian Reiling on 11.06.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#include "population4_container.hpp"
#include <algorithm>
using namespace std;
Pop4_Container::Pop4_Container(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins) {
z_scale = Lin_Scale(z_RW_m, z_WGTS_end_m, num_z_bins);
r_scale = Lin_Scale(0,r_WGTS_m, num_r_bins);
phi_scale = Lin_Scale(0, 2*pi, num_phi_bins);
E_scale = Log_Scale(scale_start, scale_end, num_E_bins);
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() {
delete[] data;
}
Pop4_Container::Pop4_Container(const Pop4_Container& other) {
z_scale = other.z_scale;
r_scale = other.r_scale;
phi_scale = other.phi_scale;
E_scale = other.E_scale;
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];
}
}
Pop4_Container& Pop4_Container::operator=(const Pop4_Container& other) {
Pop4_Container tmp(other);
swap(z_scale, tmp.z_scale);
swap(r_scale, tmp.r_scale);
swap(phi_scale, tmp.phi_scale);
swap(E_scale, tmp.E_scale);
swap(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 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[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) {
double z_min_m = calc_z_m(loc1_m);
double z_max_m = calc_z_m(loc2_m);
if (z_max_m < z_min_m) {
swap(z_min_m, z_max_m);
}
int min_z_index = z_scale.calc_index(z_min_m);
int max_z_index = z_scale.calc_index(z_max_m);
// No r/phi movement, else need to calculate more exactly
double r = calc_r_m(loc1_m);
int r_bin = r_scale.calc_index(calc_r_m(r));
double phi = calc_phi(loc1_m);
int phi_bin = phi_scale.calc_index(phi);
int E_bin = E_scale.calc_index(E_eV);
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 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[calc_data_bin(z_bin, r_bin, phi_bin, E_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;
}