Readded density reduction by interaction for test

This commit is contained in:
Christian
2019-11-08 15:59:13 +01:00
parent f5d65959c3
commit 490bfd2cc6
18 changed files with 56 additions and 17 deletions
@@ -55,8 +55,8 @@
% the presentation starts here
\title[KARL]{The KARL Code}
\subtitle{\textbf{KARL} - \textbf{KA}trin wgts elect\textbf{R}on and ion spectrum monte car\textbf{L}o simulation}
\title[KERL]{The KERL Code}
\subtitle{\textbf{KERL} - \textbf{K}atrin wgts \textbf{E}lectron and ion spect\textbf{R}um monte car\textbf{L}o simulation}
\author{Christian Reiling}
\institute{ETP}
+2 -1
View File
@@ -30,7 +30,8 @@ inline InteractionOut T2Ie_DissExc::do_Interaction (Particle *interPart) {
vec3 vTI_ms = interPart->get_v_ms();
Particle TI = Particle_Builder::create_TI(loc_m, vTI_ms, -1, interPart->get_Id());
res.add_new_particle(TI);
double E_eV = calc_E_eV_from_v_ms(Population->roll_v_ms(interPart->get_x_m()), me_eV); // should be computed properly using chances.
Population->decrease_denisty(interPart->get_x_m(), E_eV);
//maybe add T Atom
return res;
}
+2 -2
View File
@@ -23,8 +23,8 @@ public:
inline InteractionOut T2Ie_Recombination::do_Interaction (Particle *interPart) {
InteractionOut res;
res.set_delete_current(true);
//double E_eV = calc_E_eV_from_v_ms(Population->roll_v_ms(interPart->get_x_m()), me_eV); // should be computed properly using chances.
//Population->decrease_denisty(interPart->get_x_m(), E_eV);
double E_eV = calc_E_eV_from_v_ms(Population->roll_v_ms(interPart->get_x_m()), me_eV); // should be computed properly using chances.
Population->decrease_denisty(interPart->get_x_m(), E_eV);
// Maybe add the 2 T atoms.
return res;
+2 -1
View File
@@ -29,7 +29,8 @@ inline InteractionOut T3Ie_DissExc::do_Interaction (Particle *interPart) {
vec3 vTI_ms = interPart->get_v_ms();
Particle TI = Particle_Builder::create_TI(loc_m, vTI_ms, -1, interPart->get_Id());
res.add_new_particle(TI);
double E_eV = calc_E_eV_from_v_ms(Population->roll_v_ms(interPart->get_x_m()), me_eV); // should be computed properly using chances.
Population->decrease_denisty(interPart->get_x_m(), E_eV);
//maybe add T Atom
return res;
}
+1 -1
View File
@@ -24,7 +24,7 @@ inline InteractionOut T3Ie_Recombination::do_Interaction (Particle *interPart) {
InteractionOut res;
res.set_delete_current(true);
double E_eV = calc_E_eV_from_v_ms(Population->roll_v_ms(interPart->get_x_m()), me_eV); // should be computed properly using chances.
//Population->decrease_denisty(interPart->get_x_m(), E_eV);
Population->decrease_denisty(interPart->get_x_m(), E_eV);
// Maybe add the 3 T atoms.
return res;
+2 -2
View File
@@ -28,8 +28,8 @@ public:
inline InteractionOut T5Ie_Recombination::do_Interaction (Particle *interPart) {
InteractionOut res;
res.set_delete_current(true);
//double E_eV = calc_E_eV_from_v_ms(Population->roll_v_ms(interPart->get_x_m()), me_eV); // should be computed properly using chances.
//Population->decrease_denisty(interPart->get_x_m(), E_eV);
double E_eV = calc_E_eV_from_v_ms(Population->roll_v_ms(interPart->get_x_m()), me_eV); // should be computed properly using chances.
Population->decrease_denisty(interPart->get_x_m(), E_eV);
// Maybe add the 5 T atoms.
return res;
+1 -1
View File
@@ -25,7 +25,7 @@ inline InteractionOut eT2I_DissExc::do_Interaction (Particle *interPart) {
InteractionOut res = Excitation_Base::do_Interaction(interPart);
vec3 loc_m = interPart->get_x_m();
//Population->decrease_denisty(interPart->get_x_m(), 0); // dummy since thermal population
Population->decrease_denisty(interPart->get_x_m(), 0); // dummy since thermal population
vec3 vTI_ms = Population->roll_v_ms(loc_m);
Particle TI = Particle_Builder::create_TI(loc_m, vTI_ms, -1, interPart->get_Id());
+1 -1
View File
@@ -24,7 +24,7 @@ public:
inline InteractionOut eT2I_Recombination::do_Interaction (Particle *interPart) {
InteractionOut res;
res.set_delete_current(true);
//Population->decrease_denisty(interPart->get_x_m(), 0);
Population->decrease_denisty(interPart->get_x_m(), 0);
// Maybe add the 2 T atoms.
return res;
+5
View File
@@ -28,6 +28,7 @@ public:
Kinetic_Population(species this_species, Timer *timer, UniRNG *rngUni, NormalRNG *rngNormal, int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins);
void increase_density (const Particle &upPart, const vec3 &oldLoc_m);
void decrease_denisty (const vec3 &loc_m, const double &E_eV);
double get_density_m3(const vec3 &loc_m);
Content get_density_m3(const int &E_bin, const Bins &loc_bins);
@@ -48,6 +49,10 @@ inline void Kinetic_Population::increase_density (const Particle &upPart, const
container.increase_cum_time_s(oldLoc_m, upPart.get_x_m(), calc_vec3_abs(upPart.get_v_ms()), upPart.get_E_eV());
}
inline void Kinetic_Population::decrease_denisty (const vec3 &loc_m, const double &E_eV) {
container.increase_offset(loc_m, E_eV);
}
inline double Kinetic_Population::get_density_m3(const vec3 &loc_m) {
std::stringstream ss;
ss<<"Kinetic_Population::get_density_m3: method for non kinetic populations.\n";
+1
View File
@@ -26,6 +26,7 @@ public:
Population_Base(species this_species) : Process_Base(this_species) {};
virtual void increase_density (const Particle &upPart, const vec3 &oldLoc_m) = 0;
virtual void decrease_denisty (const vec3 &loc_m, const double &E_eV) = 0;
virtual double get_density_m3(const vec3 &loc_m) = 0;
virtual Content get_density_m3(const int &E_bin, const Bins &loc_bins) = 0;
+16 -2
View File
@@ -22,10 +22,11 @@ Population_Container::Population_Container(int num_z_bins, int num_r_bins, int n
Population_Container::~Population_Container() {
delete[] cum_times_s;
delete[] offsets;
delete[] size_data_m3;
}
Population_Container::Population_Container(const Population_Container& other) : cum_times_s(nullptr), size_data_m3(nullptr) {
Population_Container::Population_Container(const Population_Container& other) : cum_times_s(nullptr), offsets(nullptr), size_data_m3(nullptr) {
*this = other;
}
@@ -36,9 +37,12 @@ Population_Container &Population_Container::operator=(const Population_Container
data_size = other.data_size;
delete[] cum_times_s;
delete[] offsets;
cum_times_s = new double[data_size];
offsets = new double[data_size];
for (int i = 0; i<data_size; i++) {
cum_times_s[i] = other.cum_times_s[i];
offsets[i] = other.offsets[i];
}
delete[] size_data_m3;
@@ -62,8 +66,10 @@ void Population_Container::init_bin_offsets() {
void Population_Container::init_content_arrays() {
cum_times_s = new double[data_size];
offsets = new double[data_size];
for (int i = 0; i<data_size; i++) {
cum_times_s[i] = 0;
offsets[i] = 0;
}
}
@@ -112,6 +118,13 @@ void Population_Container::increase_cum_time_s(const vec3 &loc1_m, const vec3 &l
}
}
void Population_Container::increase_offset(const vec3 &loc_m, const double &E_eV) {
int E_bin = E_scale.calc_index(E_eV);
Bins loc_bins = calc_loc_bin(loc_m);
int bin = calc_data_bin(loc_bins, E_bin);
offsets[bin] += 1;
}
double Population_Container::get_density_m3(const vec3 &loc_m, const double &E_eV, const double &time_s) {
Bins loc_bins = calc_loc_bin(loc_m);
int E_bin = E_scale.calc_index(E_eV);
@@ -121,9 +134,10 @@ double Population_Container::get_density_m3(const vec3 &loc_m, const double &E_e
Content Population_Container::get_density_m3(const int &E_bin, const Bins &loc_bins, const double &time_s) {
int data_bin = calc_data_bin(loc_bins, E_bin);
double cum_time_s = cum_times_s[data_bin];
int offset = offsets[data_bin];
double V_m3 = size_data_m3[loc_bins.r];
double n_m3 = cum_time_s/time_s/V_m3;
double n_m3 = cum_time_s/time_s/V_m3 - offset;
if (n_m3<0) {
n_m3 = 0;
}
+2
View File
@@ -48,6 +48,7 @@ class Population_Container {
Log_Scale E_scale;
double *cum_times_s;
double *offsets;
Bins bin_offsets;
int data_size;
@@ -66,6 +67,7 @@ private:
public:
void increase_cum_time_s(const vec3 &loc1_m, const vec3 &loc2_m, const double &v_ms, const double &E_eV);
void increase_offset(const vec3 &loc_m, const double &E_eV);
public:
double get_density_m3(const vec3 &loc_m, const double &E_eV, const double &time_s);
+3 -2
View File
@@ -79,7 +79,8 @@ void Population_Load_Saver::write_species(ofstream *save_stream, species this_sp
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]<<"\n";
*save_stream<<cont->cum_times_s[bin]<<"\t";
*save_stream<<cont->offsets[bin]<<"\n";
}
}
}
@@ -242,7 +243,7 @@ void Population_Load_Saver::load_species(ifstream *load_stream, species add_spec
ss<<"Population_Load_Saver::load_species: Input Data bin missmatch.\n";
throw MyException(ss.str());
}
*load_stream>>cont->cum_times_s[i];
*load_stream>>cont->cum_times_s[i]>>cont->offsets[i];
}
string end_of_species;
*load_stream>>end_of_species;
+1 -1
View File
@@ -106,7 +106,7 @@ inline void Population_Logger::log() {
temp_bin.E_bin = i_E;
bin = container->calc_data_bin(Bins{i_z, i_r, i_phi}, i_E);
temp_bin.cumulated_time_s = container->cum_times_s[bin];
temp_bin.offset = 0;
temp_bin.offset = container->offsets[bin];
h5tb.write(temp_bin);
}
}
+10
View File
@@ -195,7 +195,9 @@ void Simulation::sync_populations() { // Sync new densities for each species and
Population_Manager *populations = looper.get_populations();
Population_Container *container;
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++) {
container = populations->find(pop_species[i])->access_container();
@@ -204,20 +206,28 @@ void Simulation::sync_populations() { // Sync new densities for each species and
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] = container->cum_times_s[j] - global_cum_time_s[i][j];
local_delta_offset[j] = container->offsets[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<array_length; j++) {
global_cum_time_s[i][j] += global_delta_cumulated_time_s[j];
global_offset[i][j] += global_delta_offset[j];
container->cum_times_s[j] = global_cum_time_s[i][j];
container->offsets[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;
}
}
+1 -1
View File
@@ -32,7 +32,7 @@ class Simulation {
int number_pop_species;
species *pop_species;
int *pop_array_lengths;
double **global_cum_time_s;
double **global_cum_time_s, **global_offset;
public:
Simulation();
+3
View File
@@ -31,6 +31,9 @@ public:
void increase_density (const Particle &upPart, const vec3 &oldLoc_m) {
container.increase_cum_time_s(oldLoc_m, upPart.get_x_m(), calc_vec3_abs(upPart.get_v_ms()), upPart.get_E_eV());
}
void decrease_denisty (const vec3 &loc_m, const double &E_eV) {
container.increase_offset(loc_m, E_eV);
}
double get_density_m3(const vec3 &loc_m) {
return container.get_density_m3(loc_m, 0, timer->get_time_s());
+1
View File
@@ -35,6 +35,7 @@ private:
public:
void increase_density (const Particle &upPart, const vec3 &oldLoc_m) {}
void decrease_denisty (const vec3 &loc_m, const double &E_eV) {}
double get_density_m3(const vec3 &loc_m);
Content get_density_m3(const int &E_bin, const Bins &loc_bins);