From 490bfd2cc630d8dba3e26dbf12ee7b974b51cf4e Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 8 Nov 2019 15:59:13 +0100 Subject: [PATCH] Readded density reduction by interaction for test --- .../christian/colab19/tex/vortrag.tex | 4 ++-- src/mc_electron/T2Ie_disexc.h | 3 ++- src/mc_electron/T2Ie_recombination.h | 4 ++-- src/mc_electron/T3Ie_disexc.h | 3 ++- src/mc_electron/T3Ie_recombination.h | 2 +- src/mc_electron/T5Ie_recombination.h | 4 ++-- src/mc_electron/eT2I_disexc.h | 2 +- src/mc_electron/eT2I_recombination.h | 2 +- src/mc_electron/kinetic_population.h | 5 +++++ src/mc_electron/population_base.h | 1 + src/mc_electron/population_container.cpp | 18 ++++++++++++++++-- src/mc_electron/population_container.hpp | 2 ++ src/mc_electron/population_load_saver.cpp | 5 +++-- src/mc_electron/population_logger_base.h | 2 +- src/mc_electron/simulation.cpp | 10 ++++++++++ src/mc_electron/simulation.hpp | 2 +- src/mc_electron/thermal_population.h | 3 +++ src/mc_electron/tritium2_population.h | 1 + 18 files changed, 56 insertions(+), 17 deletions(-) diff --git a/docs/vortraege/christian/colab19/tex/vortrag.tex b/docs/vortraege/christian/colab19/tex/vortrag.tex index 576673e..d1d38e0 100644 --- a/docs/vortraege/christian/colab19/tex/vortrag.tex +++ b/docs/vortraege/christian/colab19/tex/vortrag.tex @@ -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} diff --git a/src/mc_electron/T2Ie_disexc.h b/src/mc_electron/T2Ie_disexc.h index bd718eb..a1e40cb 100644 --- a/src/mc_electron/T2Ie_disexc.h +++ b/src/mc_electron/T2Ie_disexc.h @@ -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; } diff --git a/src/mc_electron/T2Ie_recombination.h b/src/mc_electron/T2Ie_recombination.h index aca8f4d..3bf6757 100644 --- a/src/mc_electron/T2Ie_recombination.h +++ b/src/mc_electron/T2Ie_recombination.h @@ -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; diff --git a/src/mc_electron/T3Ie_disexc.h b/src/mc_electron/T3Ie_disexc.h index 8cbd0a9..a73064d 100644 --- a/src/mc_electron/T3Ie_disexc.h +++ b/src/mc_electron/T3Ie_disexc.h @@ -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; } diff --git a/src/mc_electron/T3Ie_recombination.h b/src/mc_electron/T3Ie_recombination.h index b150079..8d8773e 100644 --- a/src/mc_electron/T3Ie_recombination.h +++ b/src/mc_electron/T3Ie_recombination.h @@ -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; diff --git a/src/mc_electron/T5Ie_recombination.h b/src/mc_electron/T5Ie_recombination.h index 614705b..ebd098f 100644 --- a/src/mc_electron/T5Ie_recombination.h +++ b/src/mc_electron/T5Ie_recombination.h @@ -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; diff --git a/src/mc_electron/eT2I_disexc.h b/src/mc_electron/eT2I_disexc.h index 9b9e726..3ce4eaa 100644 --- a/src/mc_electron/eT2I_disexc.h +++ b/src/mc_electron/eT2I_disexc.h @@ -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()); diff --git a/src/mc_electron/eT2I_recombination.h b/src/mc_electron/eT2I_recombination.h index e4d5234..0c12f8b 100644 --- a/src/mc_electron/eT2I_recombination.h +++ b/src/mc_electron/eT2I_recombination.h @@ -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; diff --git a/src/mc_electron/kinetic_population.h b/src/mc_electron/kinetic_population.h index c4c48aa..0f1dec0 100644 --- a/src/mc_electron/kinetic_population.h +++ b/src/mc_electron/kinetic_population.h @@ -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"; diff --git a/src/mc_electron/population_base.h b/src/mc_electron/population_base.h index 155fb9e..a97cc41 100644 --- a/src/mc_electron/population_base.h +++ b/src/mc_electron/population_base.h @@ -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; diff --git a/src/mc_electron/population_container.cpp b/src/mc_electron/population_container.cpp index ca5d08c..2f45e11 100644 --- a/src/mc_electron/population_container.cpp +++ b/src/mc_electron/population_container.cpp @@ -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; iE_scale.get_number_bins(); i_z++) { int bin = cont->calc_data_bin(Bins{i_z, i_r, i_phi}, i_E); *save_stream<cum_times_s[bin]<<"\n"; + *save_stream<cum_times_s[bin]<<"\t"; + *save_stream<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; diff --git a/src/mc_electron/population_logger_base.h b/src/mc_electron/population_logger_base.h index c025fcf..57cb7e0 100644 --- a/src/mc_electron/population_logger_base.h +++ b/src/mc_electron/population_logger_base.h @@ -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); } } diff --git a/src/mc_electron/simulation.cpp b/src/mc_electron/simulation.cpp index 5dc611f..913211b 100644 --- a/src/mc_electron/simulation.cpp +++ b/src/mc_electron/simulation.cpp @@ -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; ifind(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; jcum_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; jcum_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; } } diff --git a/src/mc_electron/simulation.hpp b/src/mc_electron/simulation.hpp index c25d0c3..e9034dc 100644 --- a/src/mc_electron/simulation.hpp +++ b/src/mc_electron/simulation.hpp @@ -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(); diff --git a/src/mc_electron/thermal_population.h b/src/mc_electron/thermal_population.h index d70a7e2..bf0ed79 100644 --- a/src/mc_electron/thermal_population.h +++ b/src/mc_electron/thermal_population.h @@ -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()); diff --git a/src/mc_electron/tritium2_population.h b/src/mc_electron/tritium2_population.h index c171a46..27fcb80 100644 --- a/src/mc_electron/tritium2_population.h +++ b/src/mc_electron/tritium2_population.h @@ -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);