diff --git a/src/mc_electron/T2IT2_cluster.h b/src/mc_electron/T2IT2_cluster.h index 5df5eae..1a003f1 100644 --- a/src/mc_electron/T2IT2_cluster.h +++ b/src/mc_electron/T2IT2_cluster.h @@ -9,7 +9,8 @@ #ifndef T2IT2_cluster_h #define T2IT2_cluster_h -#include "sub_interaction_base.h" +#include "TI_thermal_binary_base.h" + #include "janev_T2IT2_cluster.h" diff --git a/src/mc_electron/T2IT2_cx.h b/src/mc_electron/T2IT2_cx.h index ff7fc8c..a3e9808 100644 --- a/src/mc_electron/T2IT2_cx.h +++ b/src/mc_electron/T2IT2_cx.h @@ -9,7 +9,7 @@ #ifndef T2IT2_cx_h #define T2IT2_cx_h -#include "sub_interaction_base.h" +#include "TI_thermal_binary_base.h" #include "kinematics_base.h" #include "janev_T2IT2_cx.h" diff --git a/src/mc_electron/T2Ie_disexc.h b/src/mc_electron/T2Ie_disexc.h index e5e47f0..f8ca262 100644 --- a/src/mc_electron/T2Ie_disexc.h +++ b/src/mc_electron/T2Ie_disexc.h @@ -9,10 +9,11 @@ #ifndef T2Ie_disexc_h #define T2Ie_disexc_h +#include "TI_kinetic_base.h" -#include "sub_interaction_base.h" #include "janev_eT2I_disexc.h" + class T2Ie_DissExc : public Interaction_Base { public: T2Ie_DissExc(Population_Base *ePopulation, UniRNG *rngUni) : Interaction_Base(ePopulation, rngUni) {} diff --git a/src/mc_electron/T2Ie_recombination.h b/src/mc_electron/T2Ie_recombination.h index 10025aa..4d041c1 100644 --- a/src/mc_electron/T2Ie_recombination.h +++ b/src/mc_electron/T2Ie_recombination.h @@ -9,10 +9,11 @@ #ifndef T2Ie_recombination_h #define T2Ie_recombination_h -#include "sub_interaction_base.h" -#include "precomputed_interaction_base.h" +#include "TI_kinetic_base.h" + #include "janev_eT2I_recombination.h" + class T2Ie_Recombination : public TI_e_Precomputed_Interaction_Base { public: T2Ie_Recombination(Population_Base *ePopulation, UniRNG *rngUni) : TI_e_Precomputed_Interaction_Base(ePopulation, rngUni, 2*mT_eV) { diff --git a/src/mc_electron/T3IT2_elastic.h b/src/mc_electron/T3IT2_elastic.h index 73ed660..99efa68 100644 --- a/src/mc_electron/T3IT2_elastic.h +++ b/src/mc_electron/T3IT2_elastic.h @@ -9,7 +9,8 @@ #ifndef T3IT2_elastic_h #define T3IT2_elastic_h -#include "sub_interaction_base.h" +#include "TI_thermal_binary_base.h" + #include "tabata_T3IT2_elastic.h" diff --git a/src/mc_electron/T3IT2_radasc.h b/src/mc_electron/T3IT2_radasc.h index 9552872..cea415b 100644 --- a/src/mc_electron/T3IT2_radasc.h +++ b/src/mc_electron/T3IT2_radasc.h @@ -9,8 +9,8 @@ #ifndef T3IT2_radasc_h #define T3IT2_radasc_h -#include "sub_interaction_base.h" -// CS from Gerlich: +#include "TI_thermal_binary_base.h" + class T3IT2_RadAsc : public TI_thermal_binary_Precomputed_Interaction_Base { @@ -21,7 +21,7 @@ public: double get_microSigma_m2(const double &E_eV) { double v_ms = calc_v_ms_from_E_eV(E_eV, 3*mT_eV); - return 5e-23/v_ms; + return 5e-23/v_ms; // CS from Gerlich:1990aa } InteractionOut do_Interaction (Particle *interPart); }; diff --git a/src/mc_electron/T3IT2_terasc.h b/src/mc_electron/T3IT2_terasc.h index e2c4f22..ef73d7e 100644 --- a/src/mc_electron/T3IT2_terasc.h +++ b/src/mc_electron/T3IT2_terasc.h @@ -9,8 +9,8 @@ #ifndef T3IT2_terasc_h #define T3IT2_terasc_h -#include "sub_interaction_base.h" -// CS from Gerlich: +#include "TI_thermal_tenary_base.h" + class T3IT2_TerAsc : public TI_thermal_tenary_Precomputed_Interaction_Base { @@ -21,7 +21,7 @@ public: double get_microSigma_divbyn_m2(const double &E_eV) { double v_ms = calc_v_ms_from_E_eV(E_eV, 3*mT_eV); - return 7e-41*v_ms; + return 7e-41*v_ms; // CS from Gerlich:1990aa } InteractionOut do_Interaction (Particle *interPart); }; diff --git a/src/mc_electron/T3Ie_disexc.h b/src/mc_electron/T3Ie_disexc.h index 586ef1a..3135ee5 100644 --- a/src/mc_electron/T3Ie_disexc.h +++ b/src/mc_electron/T3Ie_disexc.h @@ -9,9 +9,11 @@ #ifndef T3Ie_disexc_h #define T3Ie_disexc_h -#include "sub_interaction_base.h" +#include "TI_kinetic_base.h" + #include "janev_eT3I_disexc.h" + class T3Ie_DissExc : public Interaction_Base { public: T3Ie_DissExc(Population_Base *ePopulation, UniRNG *rngUni) : Interaction_Base(ePopulation, rngUni) {} diff --git a/src/mc_electron/T3Ie_recombination.h b/src/mc_electron/T3Ie_recombination.h index 4d981e6..ce54393 100644 --- a/src/mc_electron/T3Ie_recombination.h +++ b/src/mc_electron/T3Ie_recombination.h @@ -9,10 +9,11 @@ #ifndef T3Ie_recombination_h #define T3Ie_recombination_h -#include "sub_interaction_base.h" -#include "precomputed_interaction_base.h" +#include "TI_kinetic_base.h" + #include "janev_eT3I_recombination.h" + class T3Ie_Recombination : public TI_e_Precomputed_Interaction_Base { public: T3Ie_Recombination(Population_Base *ePopulation, UniRNG *rngUni) : TI_e_Precomputed_Interaction_Base(ePopulation, rngUni, 3*mT_eV) { diff --git a/src/mc_electron/T5IT2_elastic.h b/src/mc_electron/T5IT2_elastic.h index da22c72..2354537 100644 --- a/src/mc_electron/T5IT2_elastic.h +++ b/src/mc_electron/T5IT2_elastic.h @@ -9,6 +9,7 @@ #ifndef T5IT2_elastic_h #define T5IT2_elastic_h +#include "TI_thermal_binary_base.h" class T5IT2_Elastic : public TI_thermal_binary_Precomputed_Interaction_Base { Tabata_T3IT2_Elastic tcs_gen; // Obviously wrong, but should be good enough. diff --git a/src/mc_electron/T5Ie_recombination.h b/src/mc_electron/T5Ie_recombination.h index 6a06244..4ef4baa 100644 --- a/src/mc_electron/T5Ie_recombination.h +++ b/src/mc_electron/T5Ie_recombination.h @@ -9,12 +9,11 @@ #ifndef T5Ie_recombination_h #define T5Ie_recombination_h - -#include "sub_interaction_base.h" -#include "precomputed_interaction_base.h" +#include "TI_kinetic_base.h" #include "petterson_eT5I_recombination.h" + class T5Ie_Recombination : public TI_e_Precomputed_Interaction_Base { public: T5Ie_Recombination(Population_Base *ePopulation, UniRNG *rngUni) : TI_e_Precomputed_Interaction_Base(ePopulation, rngUni, 5*mT_eV) { diff --git a/src/mc_electron/TIT2_elastic.h b/src/mc_electron/TIT2_elastic.h index 7bf76ee..345167f 100644 --- a/src/mc_electron/TIT2_elastic.h +++ b/src/mc_electron/TIT2_elastic.h @@ -9,8 +9,8 @@ #ifndef TIT2_elastic_h #define TIT2_elastic_h -#include "sub_interaction_base.h" -#include "kinematics_base.h" +#include "TI_thermal_binary_base.h" + #include "tabata_TIT2_elastic.h" diff --git a/src/mc_electron/TIT2_radasc.h b/src/mc_electron/TIT2_radasc.h index d7585c1..5250004 100644 --- a/src/mc_electron/TIT2_radasc.h +++ b/src/mc_electron/TIT2_radasc.h @@ -9,8 +9,7 @@ #ifndef TIT2_radasc_h #define TIT2_radasc_h -#include "sub_interaction_base.h" -// CS from Plasil:2012 +#include "TI_thermal_binary_base.h" class TIT2_RadAsc : public TI_thermal_binary_Precomputed_Interaction_Base { @@ -21,7 +20,7 @@ public: double get_microSigma_m2(const double &E_eV) { double v_ms = calc_v_ms_from_E_eV(E_eV, mT_eV); - return 5e-23/v_ms; + return 5e-23/v_ms; // CS from Plasil:2012 } InteractionOut do_Interaction (Particle *interPart); }; diff --git a/src/mc_electron/TIT2_terasc.h b/src/mc_electron/TIT2_terasc.h index 7cf3f04..9cac697 100644 --- a/src/mc_electron/TIT2_terasc.h +++ b/src/mc_electron/TIT2_terasc.h @@ -9,8 +9,8 @@ #ifndef TIT2_terasc_h #define TIT2_terasc_h -#include "sub_interaction_base.h" -// CS from Plasil:2012 +#include "TI_thermal_tenary_base.h" + class TIT2_TerAsc : public TI_thermal_tenary_Precomputed_Interaction_Base { @@ -21,7 +21,7 @@ public: double get_microSigma_divbyn_m2(const double &E_eV) { double v_ms = calc_v_ms_from_E_eV(E_eV, mT_eV); - return 2.6e-41/v_ms; + return 2.6e-41/v_ms; // CS from Plasil:2012 } InteractionOut do_Interaction (Particle *interPart); }; diff --git a/src/mc_electron/TI_kinetic_base.h b/src/mc_electron/TI_kinetic_base.h new file mode 100644 index 0000000..e153a6b --- /dev/null +++ b/src/mc_electron/TI_kinetic_base.h @@ -0,0 +1,127 @@ +// +// TI_kinetic_base.h +// mc_electron +// +// Created by Christian Reiling on 18.11.19. +// Copyright © 2019 Christian Reiling. All rights reserved. +// + +#ifndef TI_kinetic_base_h +#define TI_kinetic_base_h + + +#include "interaction_base.h" + +class TI_e_Interaction_Base : public Interaction_Base { // Interactions of ions with kinetic e Populations +protected: + double m1_eV; // energy of kinetic particle for CS measurement : e- + double m2_eV; // energy of massic initial particle : TI + int num_Ee_bins; // number of Ee_bins in Populations + double *Ee_mids; // values for energy mids of Ee_bins in Populations + double *ve_mids; // corresponding v_values + +public: + TI_e_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : Interaction_Base(Population, rngUni) { + m1_eV = Population->get_m_eV(); + m2_eV = m_eV; + + num_Ee_bins = Population->get_number_E_bins(); + if (num_Ee_bins <= 1) { + throw MyException("Population is not kinetic, when expected kinetic."); + } + ve_mids = new double[num_Ee_bins]; + Ee_mids = new double[num_Ee_bins]; + + for (int Ee_bin = 0; Ee_binget_E_bin_mid_eV(Ee_bin); + ve_mids[Ee_bin] = calc_v_ms_from_E_eV(Ee_mids[Ee_bin], m1_eV); + } + } + double get_macro_sigma_m(const Particle &interPart); + +protected: + double calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m); + double calc_microSigma_m2(const double &E1_eV, const int &Ee_bin); +private: + virtual double get_microSigma_m2(const double &E_eV) = 0; +}; + +inline double TI_e_Interaction_Base::get_macro_sigma_m(const Particle &interPart) { + return calc_macro_sigma_m(interPart.get_E_eV(), interPart.get_x_m()); +} + +inline double TI_e_Interaction_Base::calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { + Bins loc_bins = Population->get_loc_bin(loc_m); + double macro_sigma_m = 0; + for (int Ee_bin = 0; Ee_binget_density_m3(Ee_bin, loc_bins); + } + return macro_sigma_m; +} + +inline double TI_e_Interaction_Base::calc_microSigma_m2(const double &E2_eV, const int &Ee_bin) { + double v1_ms = ve_mids[Ee_bin]; + double v2_ms = calc_v_ms_from_E_eV(E2_eV, m2_eV); + + if (v1_ms > v2_ms*2000 ) { // 2000 represents 1% variation in energy + return get_microSigma_m2(Ee_mids[Ee_bin]); + } else { + auto integrand = [&](double theta) { + double E_eV = m1_eV/2 * (pow(v1_ms,2) + pow(v2_ms,2) - 2*v1_ms*v2_ms*cos(theta)) * pow(c_ms, -2); + return get_microSigma_m2(E_eV); + }; + return integrate(integrand, 0., pi, INT_N_INTPOINTS, simpson())/pi; + } +} + +class TI_e_Precomputed_Interaction_Base : public TI_e_Interaction_Base { // Precompute Interactions of ions with kinetic e Populations + Log_Scale E_scale; // E_scale for Interpolation calculation + double **precomputed_values; + +public: + TI_e_Precomputed_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : TI_e_Interaction_Base(Population, rngUni, m_eV), E_scale(INT_PRE_START, INT_PRE_END, INT_PRE_N) { + precomputed_values = new double *[E_scale.get_number_bins()]; + for (int EI_bin=0; EI_binget_loc_bin(loc_m); + double macro_sigma_m = 0; + + for (int Ee_bin = 0; Ee_binget_density_m3(Ee_bin, loc_bins); + } + return macro_sigma_m; +} + +#endif /* TI_kinetic_base_h */ diff --git a/src/mc_electron/TI_thermal_binary_base.h b/src/mc_electron/TI_thermal_binary_base.h new file mode 100644 index 0000000..61150c6 --- /dev/null +++ b/src/mc_electron/TI_thermal_binary_base.h @@ -0,0 +1,96 @@ +// +// TI_thermal_binary_base.h +// mc_electron +// +// Created by Christian Reiling on 18.11.19. +// Copyright © 2019 Christian Reiling. All rights reserved. +// + +#ifndef TI_thermal_binary_base_h +#define TI_thermal_binary_base_h + +#include "interaction_base.h" + + +class TI_thermal_binary_Interaction_Base : public Interaction_Base { // Binary interactions of tritium ions with thermal Populations +protected: + double m1_eV; // energy of kinetic particle for CS measurement : tritium ion + double v_therm; // typical speed for thermal population + +public: + TI_thermal_binary_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : Interaction_Base(Population, rngUni) { + if (Population->get_number_E_bins() > 1) { + throw MyException("Population is not thermal, when expected thermal."); + } + m1_eV = m_eV; + v_therm = Population->get_thermal_v_ms(); // Typical Speed of "Thermal Blur" + } + double get_macro_sigma_m(const Particle &interPart); + +protected: + double calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m); + double calc_microSigma_m2(const double &E_eV); +private: + virtual double get_microSigma_m2(const double &E_eV) = 0; +}; + +inline double TI_thermal_binary_Interaction_Base::get_macro_sigma_m(const Particle &interPart) { + vec3 loc_m = interPart.get_x_m(); + double v_ms = calc_vec3_abs(interPart.get_v_ms() - Population->get_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" + double E_eV = calc_E_eV_from_v_ms(v_ms, m1_eV); // Lab energy without thermal integration + return calc_macro_sigma_m(E_eV, loc_m); +} + +inline double TI_thermal_binary_Interaction_Base::calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { + return calc_microSigma_m2(E_eV)*Population->get_density_m3(loc_m); +} + +inline double TI_thermal_binary_Interaction_Base::calc_microSigma_m2(const double &E_eV) { + double v1_ms = calc_v_ms_from_E_eV(E_eV, m1_eV); + auto integrand = [&](double theta) { + double E_eV = m1_eV/2 * (pow(v1_ms,2) + pow(v_therm,2) - 2*v1_ms*v_therm*cos(theta)) * pow(c_ms, -2); + return get_microSigma_m2(E_eV); + }; + return integrate(integrand, 0., pi, INT_N_INTPOINTS, simpson())/pi; +} + + +class TI_thermal_binary_Precomputed_Interaction_Base : public TI_thermal_binary_Interaction_Base { // Precomputed Interactions of electrons with thermal Populations + Log_Scale E_scale; // E_scale for Interpolation calculation + double *precomputed_values; + +public: + TI_thermal_binary_Precomputed_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : TI_thermal_binary_Interaction_Base(Population, rngUni, m_eV), E_scale(INT_PRE_START, INT_PRE_END, INT_PRE_N) { + precomputed_values = new double [E_scale.get_number_bins()]; + } + void calc_values(); // must be called by derived class, can't call in this constructor, due to virtual pure + double get_macro_sigma_m(const Particle &interPart); +private: + double lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m); +}; + +inline void TI_thermal_binary_Precomputed_Interaction_Base::calc_values() { + for (int i=0; iget_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" + double E_eV = calc_E_eV_from_v_ms(v_ms, m1_eV); // Lab energy without thermal integration + + if (E_scale.in_scale(E_eV)) { + return lookup_macro_sigma_m(E_eV, loc_m); + } else { + return calc_macro_sigma_m(E_eV, loc_m); + } +} + +inline double TI_thermal_binary_Precomputed_Interaction_Base::lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { + int i = E_scale.calc_index(E_eV); + return precomputed_values[i] * Population->get_density_m3(loc_m); +} + + +#endif /* TI_thermal_binary_base_h */ diff --git a/src/mc_electron/TI_thermal_tenary_base.h b/src/mc_electron/TI_thermal_tenary_base.h new file mode 100644 index 0000000..b5745bb --- /dev/null +++ b/src/mc_electron/TI_thermal_tenary_base.h @@ -0,0 +1,93 @@ +// +// TI_thermal_tenary_base.h +// mc_electron +// +// Created by Christian Reiling on 18.11.19. +// Copyright © 2019 Christian Reiling. All rights reserved. +// + +#ifndef TI_thermal_tenary_base_h +#define TI_thermal_tenary_base_h + +#include "interaction_base.h" + + +class TI_thermal_tenary_Interaction_Base : public Interaction_Base { // Tenary interactions of tritium ions with thermal Populations +protected: + double m1_eV; // energy of kinetic particle for CS measurement : tritum ion + double v_therm; // typical spped for thermal population + +public: + TI_thermal_tenary_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : Interaction_Base(Population, rngUni) { + if (Population->get_number_E_bins() > 1) { + throw MyException("Population is not thermal, when expected thermal."); + } + m1_eV = m_eV; + v_therm = Population->get_thermal_v_ms(); // Typical Speed of "Thermal Blur" + } + double get_macro_sigma_m(const Particle &interPart); + +protected: + double calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m); + double calc_microSigma_divbyn_m2(const double &E_eV); +private: + virtual double get_microSigma_divbyn_m2(const double &E_eV) = 0; +}; + +inline double TI_thermal_tenary_Interaction_Base::get_macro_sigma_m(const Particle &interPart) { + vec3 loc_m = interPart.get_x_m(); + double v_ms = calc_vec3_abs(interPart.get_v_ms() - Population->get_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" + double E_eV = calc_E_eV_from_v_ms(v_ms, m1_eV); // Lab energy without thermal integration + return calc_macro_sigma_m(E_eV, loc_m); +} + +inline double TI_thermal_tenary_Interaction_Base::calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { + return calc_microSigma_divbyn_m2(E_eV)*pow(Population->get_density_m3(loc_m), 2); +} + +inline double TI_thermal_tenary_Interaction_Base::calc_microSigma_divbyn_m2(const double &E_eV) { + double v1_ms = calc_v_ms_from_E_eV(E_eV, m1_eV); + auto integrand = [&](double theta) { + double E_eV = m1_eV/2 * (pow(v1_ms,2) + pow(v_therm,2) - 2*v1_ms*v_therm*cos(theta)) * pow(c_ms, -2); + return get_microSigma_divbyn_m2(E_eV); + }; + return integrate(integrand, 0., pi, INT_N_INTPOINTS, simpson())/pi; +} + +class TI_thermal_tenary_Precomputed_Interaction_Base : public TI_thermal_tenary_Interaction_Base { // Precomputed Interactions of electrons with thermal Populations + Log_Scale E_scale; // E_scale for Interpolation calculation + double *precomputed_values; + +public: + TI_thermal_tenary_Precomputed_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : TI_thermal_tenary_Interaction_Base(Population, rngUni, m_eV), E_scale(INT_PRE_START, INT_PRE_END, INT_PRE_N) { + precomputed_values = new double [E_scale.get_number_bins()]; + } + void calc_values(); // must be called by derived class, can't call in this constructor, due to virtual pure + double get_macro_sigma_m(const Particle &interPart); +private: + double lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m); +}; + +inline void TI_thermal_tenary_Precomputed_Interaction_Base::calc_values() { + for (int i=0; iget_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" + double E_eV = calc_E_eV_from_v_ms(v_ms, m1_eV); // Lab energy without thermal integration + + if (E_scale.in_scale(E_eV)) { + return lookup_macro_sigma_m(E_eV, loc_m); + } else { + return calc_macro_sigma_m(E_eV, loc_m); + } +} + +inline double TI_thermal_tenary_Precomputed_Interaction_Base::lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { + int i = E_scale.calc_index(E_eV); + return precomputed_values[i] * pow(Population->get_density_m3(loc_m),2); +} +#endif /* TI_thermal_tenary_base_h */ diff --git a/src/mc_electron/constants.h b/src/mc_electron/constants.h index 3ab202a..f8945da 100644 --- a/src/mc_electron/constants.h +++ b/src/mc_electron/constants.h @@ -9,12 +9,12 @@ #ifndef constants_h #define constants_h -typedef const double constant; +#include "read_system.h" +typedef const double constant; constant scale_start = 1e-7; constant scale_end = 2e4; -constant infinity = 1e15; // Natural Constants constant pi = 3.1415; @@ -53,4 +53,10 @@ constant reduction_WGTS_rear = 0.033; constant reduction_tot_front = 5e-4; constant reduction_tot_rear = 5e-4; +// For interaction integration +const int INT_N_INTPOINTS = load_parameter("INT_N_INTPOINTS"); // Number of points for theta integration +const double INT_PRE_START = load_parameter("INT_PRE_START"); // Start energy for precomputed cross sections +const double INT_PRE_END = load_parameter("INT_PRE_END"); // End energy for precomputed cross sections +const int INT_PRE_N = load_parameter("INT_PRE_N"); //Number of points for precomputed cross sections + #endif /* constants_h */ diff --git a/src/mc_electron/eT2I_disexc.h b/src/mc_electron/eT2I_disexc.h index ed906ee..b574caa 100644 --- a/src/mc_electron/eT2I_disexc.h +++ b/src/mc_electron/eT2I_disexc.h @@ -9,7 +9,8 @@ #ifndef eT2I_disexc_h #define eT2I_disexc_h -#include "sub_interaction_base.h" +#include "exc_base.h" + #include "janev_eT2I_disexc.h" class eT2I_DissExc : public Excitation_Base { diff --git a/src/mc_electron/eT2I_recombination.h b/src/mc_electron/eT2I_recombination.h index 256cee5..4adc004 100644 --- a/src/mc_electron/eT2I_recombination.h +++ b/src/mc_electron/eT2I_recombination.h @@ -9,7 +9,8 @@ #ifndef eT2I_recombination_h #define eT2I_recombination_h -#include "sub_interaction_base.h" +#include "e_thermal_base.h" + #include "janev_eT2I_recombination.h" class eT2I_Recombination : public e_thermal_Precomputed_Interaction_Base { diff --git a/src/mc_electron/eT2_elastic.h b/src/mc_electron/eT2_elastic.h index c63d3dd..19c320f 100644 --- a/src/mc_electron/eT2_elastic.h +++ b/src/mc_electron/eT2_elastic.h @@ -9,8 +9,9 @@ #ifndef eT2_elastic_h #define eT2_elastic_h -#include "sub_interaction_base.h" -#include "precomputed_interaction_base.h" +#include "e_thermal_base.h" + + #include "uehara_eT2_elastic.hpp" #include "tcs_container.hpp" #include "dcs_theta_container.hpp" diff --git a/src/mc_electron/eT2_elexc_analytic.h b/src/mc_electron/eT2_elexc_analytic.h index 0843c1c..b316d90 100644 --- a/src/mc_electron/eT2_elexc_analytic.h +++ b/src/mc_electron/eT2_elexc_analytic.h @@ -9,8 +9,11 @@ #ifndef eT2_elexc_analytic_h #define eT2_elexc_analytic_h +#include "exc_base.h" + #include "janev_eT2_elexc.h" + class eT2_ElExc_Nu_Analytic : public Excitation_Base { Janev_eT2_ElExc_Nu janev_Nu; public: diff --git a/src/mc_electron/eT2_ionization.h b/src/mc_electron/eT2_ionization.h index 622cb15..b2bae47 100644 --- a/src/mc_electron/eT2_ionization.h +++ b/src/mc_electron/eT2_ionization.h @@ -9,7 +9,8 @@ #ifndef eT2_ionization_h #define eT2_ionization_h -#include "sub_interaction_base.h" +#include "e_thermal_base.h" + #include "tcs_container.hpp" #include "dcs_ionization_container.hpp" diff --git a/src/mc_electron/eT2_vibexc0102.h b/src/mc_electron/eT2_vibexc0102.h index 8b396dc..b97fcbc 100644 --- a/src/mc_electron/eT2_vibexc0102.h +++ b/src/mc_electron/eT2_vibexc0102.h @@ -10,8 +10,10 @@ #define eT2_vibexc0102_h #include "exc_base.h" + #include "janev_eT2_vibexc0102.h" + class eT2_VibExc01 : public Excitation_Base { Janev_eT2_VibExc calculator; public: diff --git a/src/mc_electron/eT3I_disexc.h b/src/mc_electron/eT3I_disexc.h index c1eaa30..a3cd5fa 100644 --- a/src/mc_electron/eT3I_disexc.h +++ b/src/mc_electron/eT3I_disexc.h @@ -9,7 +9,8 @@ #ifndef eT3I_disexc_h #define eT3I_disexc_h -#include "sub_interaction_base.h" +#include "exc_base.h" + #include "janev_eT3I_disexc.h" class eT3I_DissExc : public Excitation_Base { diff --git a/src/mc_electron/eT3I_recombination.h b/src/mc_electron/eT3I_recombination.h index 8370772..19c8787 100644 --- a/src/mc_electron/eT3I_recombination.h +++ b/src/mc_electron/eT3I_recombination.h @@ -9,7 +9,8 @@ #ifndef eT3I_recombination_h #define eT3I_recombination_h -#include "sub_interaction_base.h" +#include "e_thermal_base.h" + #include "janev_eT3I_recombination.h" class eT3I_Recombination : public e_thermal_Precomputed_Interaction_Base { diff --git a/src/mc_electron/eT5I_recombination.h b/src/mc_electron/eT5I_recombination.h index 30eac56..28ed8be 100644 --- a/src/mc_electron/eT5I_recombination.h +++ b/src/mc_electron/eT5I_recombination.h @@ -9,7 +9,8 @@ #ifndef eT5I_recombination_h #define eT5I_recombination_h -#include "sub_interaction_base.h" +#include "e_thermal_base.h" + #include "petterson_eT5I_recombination.h" class eT5I_Recombination : public e_thermal_Precomputed_Interaction_Base { diff --git a/src/mc_electron/e_thermal_base.h b/src/mc_electron/e_thermal_base.h new file mode 100644 index 0000000..1d92e94 --- /dev/null +++ b/src/mc_electron/e_thermal_base.h @@ -0,0 +1,120 @@ +// +// e_thermal_base.h +// mc_electron +// +// Created by Christian Reiling on 18.11.19. +// Copyright © 2019 Christian Reiling. All rights reserved. +// + +#ifndef e_thermal_base_h +#define e_thermal_base_h + +#include "interaction_base.h" + + +class e_thermal_Interaction_Base : public Interaction_Base { // Interactions of electrons with thermal Populations +protected: + double m1_eV; // energy of kinetic particle in CS measurement : e- + + double E_limit; // limit for integration calculation + double v_therm; // typical spped for thermal population + +public: + e_thermal_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : Interaction_Base(Population, rngUni) { + if (Population->get_number_E_bins() > 1) { + throw MyException("Population is not thermal, when expected thermal."); + } + m1_eV = m_eV; + v_therm = Population->get_thermal_v_ms(); // Typical Speed of "Thermal Blur" + E_limit = calc_E_eV_from_v_ms(v_therm * 2000, m1_eV); // 2000 represents 1% variation in energy + } + double get_macro_sigma_m(const Particle &interPart); + +protected: + double calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m); + double calc_microSigma_m2(const double &E_eV); + vec3 get_vOff_ms(const Particle &interPart, const double &minE_eV); // For derived class -> Roll energy loss +private: + virtual double get_microSigma_m2(const double &E_eV) = 0; +}; + +inline double e_thermal_Interaction_Base::get_macro_sigma_m(const Particle &interPart) { + vec3 loc_m = interPart.get_x_m(); + double v_ms = calc_vec3_abs(interPart.get_v_ms() - Population->get_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" + double E_eV = calc_E_eV_from_v_ms(v_ms, m1_eV); // Lab energy without thermal integration + return calc_macro_sigma_m(E_eV, loc_m); +} + +inline double e_thermal_Interaction_Base::calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { + return calc_microSigma_m2(E_eV)*Population->get_density_m3(loc_m); +} + +inline double e_thermal_Interaction_Base::calc_microSigma_m2(const double &E_eV) { + if (E_eV > E_limit) { + return get_microSigma_m2(E_eV); + } else { + double v1_ms = calc_v_ms_from_E_eV(E_eV, m1_eV); + auto integrand = [&](double theta) { + double E_eV = m1_eV/2 * (pow(v1_ms,2) + pow(v_therm,2) - 2*v1_ms*v_therm*cos(theta)) * pow(c_ms, -2); + return get_microSigma_m2(E_eV); + }; + return integrate(integrand, 0., pi, INT_N_INTPOINTS, simpson())/pi; + } +} + +inline vec3 e_thermal_Interaction_Base::get_vOff_ms(const Particle &interPart, const double &minE_eV) { + vec3 v1_ms = interPart.get_v_ms(); + vec3 v2_ms = Population->roll_v_ms(interPart.get_x_m()); + vec3 v1Lab_ms = v1_ms - v2_ms; + double T_eV = calc_E_eV_from_v_ms(v1Lab_ms, m1_eV); + if (T_eV < minE_eV) { + T_eV = calc_E_eV_from_v_ms(v1_ms, m1_eV); + if (T_eV < minE_eV) { + std::stringstream ss; + ss<<"Interaction_Base::get_vOff_ms: T_eV < minE_eV.\nT_eV= "<< T_eV<<"\t minE_eV= "<get_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" + double E_eV = calc_E_eV_from_v_ms(v_ms, m1_eV); // Lab energy without thermal integration + if (E_scale.in_scale(E_eV)) { + return lookup_macro_sigma_m(E_eV, loc_m); + } else { + return calc_macro_sigma_m(E_eV, loc_m); + } +} + +inline double e_thermal_Precomputed_Interaction_Base::lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { + int i = E_scale.calc_index(E_eV); + return precomputed_values[i] * Population->get_density_m3(loc_m); +} + + +#endif /* e_thermal_base_h */ diff --git a/src/mc_electron/exc_base.h b/src/mc_electron/exc_base.h index 5125070..a559ad6 100644 --- a/src/mc_electron/exc_base.h +++ b/src/mc_electron/exc_base.h @@ -9,6 +9,8 @@ #ifndef exc_base_h #define exc_base_h +#include "e_thermal_base.h" + #include "tcs_container.hpp" #include "dcs_base.h" diff --git a/src/mc_electron/interaction_base.h b/src/mc_electron/interaction_base.h index 2a281f7..6365a7a 100644 --- a/src/mc_electron/interaction_base.h +++ b/src/mc_electron/interaction_base.h @@ -9,71 +9,51 @@ #ifndef interaction_base_hpp #define interaction_base_hpp +#include +#include -#include "sub_interaction_base.h" +#include "particle.hpp" +#include "population_base.h" -#include "process_base.h" +#include "constants.h" +#include "kinematics.h" +#include "integrater.h" +#include "error_types.h" -class Interaction_Channel_Base : public Process_Base { - Interaction_Base **SubInteractions; - int numSubInteractions = 0; - - UniRNG *rngUni; +class InteractionOut { + bool delete_current; + Particle new_particles[3]; + int number_new_particles; public: - Interaction_Channel_Base(species this_species, UniRNG *rngUni) : Process_Base (this_species) { - this->rngUni = rngUni; - }; + InteractionOut() {reset();}; + void reset() { + delete_current = false; + number_new_particles = 0; + } - void add(Interaction_Base *addSubInteraction); - - InteractionOut do_Interaction(Particle *interPart); - double get_macro_sigma_m(const Particle &interPart); + void set_delete_current(const bool &delete_current) {this->delete_current = delete_current;} + bool get_delete_current() {return delete_current;} + void add_new_particle(const Particle &newParticle) { + new_particles[number_new_particles] = newParticle; + number_new_particles++; + } + int get_number_new_particles() {return number_new_particles;} + Particle *get_new_particles() {return new_particles;} }; -inline InteractionOut Interaction_Channel_Base::do_Interaction(Particle *interPart) { - double macro_sigma_m = get_macro_sigma_m(*interPart); - double currentStackedSigma = 0; - double targetStackedSigma = rngUni->random() * macro_sigma_m; - - for (int i = 0; i < numSubInteractions; i++) { - currentStackedSigma += SubInteractions[i]->get_macro_sigma_m(*interPart); - if (currentStackedSigma >= targetStackedSigma) { - return SubInteractions[i]->do_Interaction(interPart); - } - } - std::stringstream ss; - ss<<"Interaction_Channel_Base::do_Interaction: No Interactions added.\n"; - throw MyException (ss.str()); -} - - -inline double Interaction_Channel_Base::get_macro_sigma_m(const Particle &interPart) { - double macro_sigma_m = 0; - for (int i = 0; i < numSubInteractions; i++) { - macro_sigma_m += SubInteractions[i]->get_macro_sigma_m(interPart); - } - return macro_sigma_m; -} - -inline void Interaction_Channel_Base::add(Interaction_Base *addSubInteraction) { - if (numSubInteractions != 0) { - Interaction_Base *tempArray[numSubInteractions]; - for (int i = 0; i < numSubInteractions; i++) { - tempArray[i] = SubInteractions[i]; - } - delete[] SubInteractions; - SubInteractions = new Interaction_Base *[numSubInteractions + 1]; - for (int i = 0; i < numSubInteractions; i++) { - SubInteractions[i] = tempArray[i]; - } - } else { - SubInteractions = new Interaction_Base *[numSubInteractions + 1]; - } - SubInteractions[numSubInteractions] = addSubInteraction; - numSubInteractions += 1; -} - +class Interaction_Base { +protected: + Population_Base *Population; + UniRNG *rngUni; +public: + Interaction_Base(Population_Base *Population, UniRNG *rngUni) { + this->Population = Population; + this->rngUni = rngUni; + }; + virtual double get_macro_sigma_m(const Particle &interPart) = 0; + virtual InteractionOut do_Interaction (Particle *interPart) = 0; +}; #endif /* interaction_base_h */ diff --git a/src/mc_electron/interaction_builder.cpp b/src/mc_electron/interaction_builder.cpp index fdbcc92..fce799d 100644 --- a/src/mc_electron/interaction_builder.cpp +++ b/src/mc_electron/interaction_builder.cpp @@ -8,6 +8,7 @@ #include "interaction_builder.hpp" +#include "exc_base.h" // e impact #include "eT2_elastic.h" diff --git a/src/mc_electron/interaction_builder.hpp b/src/mc_electron/interaction_builder.hpp index 3dbae09..ddba86e 100644 --- a/src/mc_electron/interaction_builder.hpp +++ b/src/mc_electron/interaction_builder.hpp @@ -9,11 +9,12 @@ #ifndef interaction_builder_hpp #define interaction_builder_hpp -#include "interaction_base.h" -#include "manager_base.h" -#include "exc_base.h" +#include "manager_base.h" +#include "interaction_channel_base.h" #include "population_builder.hpp" +#include "dcs_base.h" + typedef Manager_Base Interaction_Manager; diff --git a/src/mc_electron/interaction_channel_base.h b/src/mc_electron/interaction_channel_base.h new file mode 100644 index 0000000..5f81908 --- /dev/null +++ b/src/mc_electron/interaction_channel_base.h @@ -0,0 +1,76 @@ +// +// interaction_channel_base.h +// mc_electron +// +// Created by Christian Reiling on 18.11.19. +// Copyright © 2019 Christian Reiling. All rights reserved. +// + +#ifndef interaction_channel_base_h +#define interaction_channel_base_h + +#include "process_base.h" +#include "interaction_base.h" + + +class Interaction_Channel_Base : public Process_Base { + Interaction_Base **SubInteractions; + int numSubInteractions = 0; + + UniRNG *rngUni; + +public: + Interaction_Channel_Base(species this_species, UniRNG *rngUni) : Process_Base (this_species) { + this->rngUni = rngUni; + }; + + void add(Interaction_Base *addSubInteraction); + + InteractionOut do_Interaction(Particle *interPart); + double get_macro_sigma_m(const Particle &interPart); +}; + +inline InteractionOut Interaction_Channel_Base::do_Interaction(Particle *interPart) { + double macro_sigma_m = get_macro_sigma_m(*interPart); + double currentStackedSigma = 0; + double targetStackedSigma = rngUni->random() * macro_sigma_m; + + for (int i = 0; i < numSubInteractions; i++) { + currentStackedSigma += SubInteractions[i]->get_macro_sigma_m(*interPart); + if (currentStackedSigma >= targetStackedSigma) { + return SubInteractions[i]->do_Interaction(interPart); + } + } + std::stringstream ss; + ss<<"Interaction_Channel_Base::do_Interaction: No Interactions added.\n"; + throw MyException (ss.str()); +} + + +inline double Interaction_Channel_Base::get_macro_sigma_m(const Particle &interPart) { + double macro_sigma_m = 0; + for (int i = 0; i < numSubInteractions; i++) { + macro_sigma_m += SubInteractions[i]->get_macro_sigma_m(interPart); + } + return macro_sigma_m; +} + +inline void Interaction_Channel_Base::add(Interaction_Base *addSubInteraction) { + if (numSubInteractions != 0) { + Interaction_Base *tempArray[numSubInteractions]; + for (int i = 0; i < numSubInteractions; i++) { + tempArray[i] = SubInteractions[i]; + } + delete[] SubInteractions; + SubInteractions = new Interaction_Base *[numSubInteractions + 1]; + for (int i = 0; i < numSubInteractions; i++) { + SubInteractions[i] = tempArray[i]; + } + } else { + SubInteractions = new Interaction_Base *[numSubInteractions + 1]; + } + SubInteractions[numSubInteractions] = addSubInteraction; + numSubInteractions += 1; +} + +#endif /* interaction_channel_base_h */ diff --git a/src/mc_electron/kinematics.h b/src/mc_electron/kinematics.h index 3701ab5..e394a9d 100644 --- a/src/mc_electron/kinematics.h +++ b/src/mc_electron/kinematics.h @@ -22,98 +22,16 @@ typedef blitz::TinyVector vec3; inline double calc_vec3_abs(const vec3 &vec) { return sqrt( pow(vec[0],2) + pow(vec[1],2) + pow(vec[2],2)); } - - - - -/* -inline double calc_gamma_from_beta(const double &beta) { - if (beta>=1) { - std::stringstream ss; - ss<<"calc_gamma_from_beta(): Input beta ="<=1) { - std::stringstream ss; - ss<<"calc_E_eV_from_v_ms(): Input speed v="<0."; - throw MyException(ss.str()); - } - double gamma = calc_gamma_from_beta(beta); - if (gamma == 1) { - return 0.5*beta*beta*m_eV; - } else { - return (gamma-1) * m_eV; - } - */ - return 0.5*v_ms/c_ms*v_ms/c_ms*m_eV; + return m_eV/2 * pow(v_ms/c_ms,2); } inline double calc_E_eV_from_v_ms(const vec3 &v_ms, const double &m_eV) { return calc_E_eV_from_v_ms(calc_vec3_abs(v_ms), m_eV); } -/* -inline double calc_beta_from_gamma(const double &gamma) { - - if (gamma<1) { - std::stringstream ss; - ss<<"calc_beta_from_gamma(): Input gamma ="<timer = timer; m_eV = get_species_mass(this_species); }; diff --git a/src/mc_electron/population_builder.cpp b/src/mc_electron/population_builder.cpp index 85c7c83..6f592af 100644 --- a/src/mc_electron/population_builder.cpp +++ b/src/mc_electron/population_builder.cpp @@ -13,17 +13,22 @@ #include "tritium2_population.h" +const int Population_Builder::POP_N_R = load_parameter("POP_N_R"); +const int Population_Builder::POP_N_PHI = load_parameter("POP_N_PHI"); +const int Population_Builder::POP_N_Z = load_parameter("POP_N_Z"); +const int Population_Builder::POP_N_E = load_parameter("POP_N_E"); +const double Population_Builder::POP_E_START = load_parameter("POP_E_START"); const double Population_Builder::wgtsTemp_K = load_parameter("TEMP"); const int Population_Builder::v_flow = load_parameter("T2_VELO"); Population_Manager Population_Builder::build(Timer *timer,UniRNG *rngUni, NormalRNG *rngNormal) { Population_Manager Populations; - int num_z_bins = 13; - int num_r_bins = 5; - int num_phi_bins = 1; - int num_E_bins = 50; - Populations.add(new Kinetic_Population(electron, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins, num_E_bins)); + int num_z_bins = POP_N_Z; + int num_r_bins = POP_N_R; + int num_phi_bins = POP_N_PHI; + int num_E_bins = POP_N_E; + Populations.add(new Kinetic_Population(electron, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins, num_E_bins, POP_E_START)); if (v_flow == -1) { Populations.add(new Thermal_Population(tritium, new WGTS_Kinematics(mT_eV, wgtsTemp_K, rngUni, rngNormal), timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins)); Populations.add(new Thermal_Population(tritiumI, new WGTS_Kinematics(mT_eV, wgtsTemp_K, rngUni, rngNormal), timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins)); diff --git a/src/mc_electron/population_builder.hpp b/src/mc_electron/population_builder.hpp index 9eb9f96..cf00a04 100644 --- a/src/mc_electron/population_builder.hpp +++ b/src/mc_electron/population_builder.hpp @@ -16,6 +16,11 @@ typedef Manager_Base Population_Manager; class Population_Builder { + static const int POP_N_R; + static const int POP_N_PHI; + static const int POP_N_Z; + static const int POP_N_E; + static const double POP_E_START; static const double wgtsTemp_K; static const int v_flow; public: diff --git a/src/mc_electron/population_container.cpp b/src/mc_electron/population_container.cpp index 1c49d54..dcedf97 100644 --- a/src/mc_electron/population_container.cpp +++ b/src/mc_electron/population_container.cpp @@ -13,13 +13,15 @@ using namespace std; -Population_Container::Population_Container(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins) { - init_scales(num_z_bins, num_r_bins, num_phi_bins, num_E_bins); +Population_Container::Population_Container(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins, double E_min_eV) { + init_scales(num_z_bins, num_r_bins, num_phi_bins, num_E_bins, E_min_eV); init_bin_offsets(); init_content_arrays(); init_size_array(); } +Population_Container::Population_Container(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins) : Population_Container(num_z_bins, num_r_bins, num_phi_bins, num_E_bins, 1e-7) {} + Population_Container::~Population_Container() { delete[] cum_times_s; delete[] offsets; @@ -50,11 +52,11 @@ Population_Container &Population_Container::operator=(const Population_Container return *this; } -void Population_Container::init_scales(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins) { +void Population_Container::init_scales(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins, double E_min_eV) { scales.z = Lin_Scale(z_RW_m, z_WGTS_end_m, num_z_bins); scales.r = Lin_Scale(0,r_WGTS_m, num_r_bins); scales.phi = Lin_Scale(0, 2*pi, num_phi_bins); - E_scale = Log_Scale(scale_start, scale_end, num_E_bins); + E_scale = Log_Scale(E_min_eV, scale_end, num_E_bins); } void Population_Container::init_bin_offsets() { diff --git a/src/mc_electron/population_container.hpp b/src/mc_electron/population_container.hpp index 46e23ec..be44647 100644 --- a/src/mc_electron/population_container.hpp +++ b/src/mc_electron/population_container.hpp @@ -54,12 +54,13 @@ class Population_Container { double *size_data_m3; public: + Population_Container(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins, double E_min_eV); Population_Container(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins); ~Population_Container(); Population_Container(const Population_Container& other); Population_Container& operator=(const Population_Container& other); private: - void init_scales(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins); + void init_scales(int num_z_bins, int num_r_bins, int num_phi_bins, int num_E_bins, double E_min_eV); void init_bin_offsets(); void init_content_arrays(); void init_size_array(); diff --git a/src/mc_electron/precomputed_interaction_base.h b/src/mc_electron/precomputed_interaction_base.h deleted file mode 100644 index 576f004..0000000 --- a/src/mc_electron/precomputed_interaction_base.h +++ /dev/null @@ -1,181 +0,0 @@ -// -// precomputed_interaction_base.h -// mc_electron -// -// Created by Christian Reiling on 15.11.19. -// Copyright © 2019 Christian Reiling. All rights reserved. -// - -#ifndef precomputed_interaction_base_h -#define precomputed_interaction_base_h - -#include "sub_interaction_base.h" -#include "log_scale.h" - - -class e_thermal_Precomputed_Interaction_Base : public e_thermal_Interaction_Base { // Precomputed Interactions of electrons with thermal Populations - Log_Scale E_scale; // E_scale for Interpolation calculation - double *precomputed_values; - -public: - e_thermal_Precomputed_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : e_thermal_Interaction_Base(Population, rngUni, m_eV), E_scale(1e-6, 1e-1, 1e5) { - precomputed_values = new double [E_scale.get_number_bins()]; - } - void calc_values(); // must be called by derived class, can't call in this constructor, due to virtual pure - double get_macro_sigma_m(const Particle &interPart); -private: - double lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m); -}; - -inline void e_thermal_Precomputed_Interaction_Base::calc_values() { - for (int i=0; iget_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" - double E_eV = m_eV/2*pow(v_ms/c_ms, 2); // Lab energy without thermal integration - - if (E_scale.in_scale(E_eV)) { - return lookup_macro_sigma_m(E_eV, loc_m); - } else { - return calc_macro_sigma_m(E_eV, loc_m); - } -} - -inline double e_thermal_Precomputed_Interaction_Base::lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { - int i = E_scale.calc_index(E_eV); - return precomputed_values[i] * Population->get_density_m3(loc_m); -} - - -class TI_thermal_binary_Precomputed_Interaction_Base : public TI_thermal_binary_Interaction_Base { // Precomputed Interactions of electrons with thermal Populations - Log_Scale E_scale; // E_scale for Interpolation calculation - double *precomputed_values; - -public: - TI_thermal_binary_Precomputed_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : TI_thermal_binary_Interaction_Base(Population, rngUni, m_eV), E_scale(1e-6, 1e-1, 1e5) { - precomputed_values = new double [E_scale.get_number_bins()]; - } - void calc_values(); // must be called by derived class, can't call in this constructor, due to virtual pure - double get_macro_sigma_m(const Particle &interPart); -private: - double lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m); -}; - -inline void TI_thermal_binary_Precomputed_Interaction_Base::calc_values() { - for (int i=0; iget_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" - double E_eV = m_eV/2*pow(v_ms/c_ms, 2); // Lab energy without thermal integration - - if (E_scale.in_scale(E_eV)) { - return lookup_macro_sigma_m(E_eV, loc_m); - } else { - return calc_macro_sigma_m(E_eV, loc_m); - } -} - -inline double TI_thermal_binary_Precomputed_Interaction_Base::lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { - int i = E_scale.calc_index(E_eV); - return precomputed_values[i] * Population->get_density_m3(loc_m); -} - - -class TI_thermal_tenary_Precomputed_Interaction_Base : public TI_thermal_tenary_Interaction_Base { // Precomputed Interactions of electrons with thermal Populations - Log_Scale E_scale; // E_scale for Interpolation calculation - double *precomputed_values; - -public: - TI_thermal_tenary_Precomputed_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : TI_thermal_tenary_Interaction_Base(Population, rngUni, m_eV), E_scale(1e-6, 1e-1, 1e5) { - precomputed_values = new double [E_scale.get_number_bins()]; - } - void calc_values(); // must be called by derived class, can't call in this constructor, due to virtual pure - double get_macro_sigma_m(const Particle &interPart); -private: - double lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m); -}; - -inline void TI_thermal_tenary_Precomputed_Interaction_Base::calc_values() { - for (int i=0; iget_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" - double E_eV = m_eV/2*pow(v_ms/c_ms, 2); // Lab energy without thermal integration - - if (E_scale.in_scale(E_eV)) { - return lookup_macro_sigma_m(E_eV, loc_m); - } else { - return calc_macro_sigma_m(E_eV, loc_m); - } -} - -inline double TI_thermal_tenary_Precomputed_Interaction_Base::lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { - int i = E_scale.calc_index(E_eV); - return precomputed_values[i] * pow(Population->get_density_m3(loc_m),2); -} - -class TI_e_Precomputed_Interaction_Base : public TI_e_Interaction_Base { // Precompute Interactions of ions with kinetic e Populations - - Log_Scale E_scale; // E_scale for Interpolation calculation - double **precomputed_values; - -public: - TI_e_Precomputed_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double mI_eV) : TI_e_Interaction_Base(Population, rngUni, mI_eV), E_scale(1e-6, 1e-1, 1e5) { - precomputed_values = new double *[E_scale.get_number_bins()]; - for (int EI_bin=0; EI_binget_loc_bin(loc_m); - double macro_sigma_m = 0; - - for (int Ee_bin = 0; Ee_binget_density_m3(Ee_bin, loc_bins); - } - return macro_sigma_m; -} - -#endif /* precomputed_interaction_base_h */ diff --git a/src/mc_electron/sub_interaction_base.h b/src/mc_electron/sub_interaction_base.h deleted file mode 100644 index 7a1d99b..0000000 --- a/src/mc_electron/sub_interaction_base.h +++ /dev/null @@ -1,263 +0,0 @@ -// -// sub_interaction_base.h -// mc_electron -// -// Created by Christian Reiling on 19.05.19. -// Copyright © 2019 Christian Reiling. All rights reserved. -// - -#ifndef sub_interaction_base_h -#define sub_interaction_base_h - -#include -#include - -#include "particle.hpp" -#include "population_base.h" - -#include "constants.h" -#include "integrater.h" -#include "error_types.h" - -class InteractionOut { - bool delete_current; - Particle new_particles[3]; - int number_new_particles; - -public: - InteractionOut() {reset();}; - void reset() { - delete_current = false; - number_new_particles = 0; - } - - void set_delete_current(const bool &delete_current) {this->delete_current = delete_current;} - bool get_delete_current() {return delete_current;} - void add_new_particle(const Particle &newParticle) { - new_particles[number_new_particles] = newParticle; - number_new_particles++; - } - int get_number_new_particles() {return number_new_particles;} - Particle *get_new_particles() {return new_particles;} -}; - -class Interaction_Base { -protected: - Population_Base *Population; - UniRNG *rngUni; -public: - Interaction_Base(Population_Base *Population, UniRNG *rngUni) { - this->Population = Population; - this->rngUni = rngUni; - }; - virtual double get_macro_sigma_m(const Particle &interPart) = 0; - virtual InteractionOut do_Interaction (Particle *interPart) = 0; -}; - -class e_thermal_Interaction_Base : public Interaction_Base { // Interactions of electrons with thermal Populations -protected: - double E_limit; - - double m_eV; // energy of kinetic particle for CS measurement : e- - double mI_eV; // energy of massic initial particle : TI - - double v_therm; // typical spped for thermal population - - -public: - e_thermal_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : Interaction_Base(Population, rngUni) { - if (Population->get_number_E_bins() > 1) { - throw MyException("Population is not thermal, when expected thermal."); - } - this->m_eV = m_eV; - mI_eV = Population->get_m_eV(); - v_therm = Population->get_thermal_v_ms(); // Typical Speed of "Thermal Blur" - E_limit = m_eV/2*pow(v_therm/c_ms * 2000, 2); - } - - double get_macro_sigma_m(const Particle &interPart) { - vec3 loc_m = interPart.get_x_m(); - double v_ms = calc_vec3_abs(interPart.get_v_ms() - Population->get_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" - double E_eV = m_eV/2*pow(v_ms/c_ms, 2); // Lab energy without thermal integration - return calc_macro_sigma_m(E_eV, loc_m); - } -private: - virtual double get_microSigma_m2(const double &E_eV) = 0; - -protected: - double calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { - return calc_microSigma_m2(E_eV)*Population->get_density_m3(loc_m); - } - - double calc_microSigma_m2(const double &E_eV) { - if (E_eV > E_limit) { // 0.005 represents 1% variation in energy - return get_microSigma_m2(E_eV); - } else { - double v1_ms = sqrt(2*E_eV/mI_eV)*c_ms; - auto integrand = [&](double theta) { - double E_eV = m_eV/2 * (pow(v1_ms,2) + pow(v_therm,2) - 2*v1_ms*v_therm*cos(theta)) * pow(c_ms, -2); - return get_microSigma_m2(E_eV); - }; - return integrate(integrand, 0., pi, 30, simpson())/pi; - } - } - - vec3 get_vOff_ms(const Particle &interPart, const double &minE_eV) { // Implemented for derived classes - double m_eV = interPart.get_m_eV(); - vec3 v1_ms = interPart.get_v_ms(); - vec3 v2_ms = Population->roll_v_ms(interPart.get_x_m()); - vec3 v1Lab_ms = v1_ms - v2_ms; - double T_eV = calc_E_eV_from_v_ms(v1Lab_ms, m_eV); - if (T_eV < minE_eV) { - T_eV = calc_E_eV_from_v_ms(v1_ms, m_eV); - if (T_eV < minE_eV) { - std::stringstream ss; - ss<<"Interaction_Base::get_vOff_ms: T_eV < minE_eV.\nT_eV= "<< T_eV<<"\t minE_eV= "<get_number_E_bins() > 1) { - throw MyException("Population is not thermal, when expected thermal."); - } - this->m_eV = m_eV; - m2_eV = Population->get_m_eV(); - v_therm = Population->get_thermal_v_ms(); // Typical Speed of "Thermal Blur" - } - - double get_macro_sigma_m(const Particle &interPart) { - vec3 loc_m = interPart.get_x_m(); - double v_ms = calc_vec3_abs(interPart.get_v_ms() - Population->get_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" - double E_eV = m_eV/2*pow(v_ms/c_ms, 2); // Lab energy without thermal integration - return calc_macro_sigma_m(E_eV, loc_m); - } -private: - virtual double get_microSigma_m2(const double &E_eV) = 0; - -protected: - double calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { - return calc_microSigma_m2(E_eV)*Population->get_density_m3(loc_m); - } - - double calc_microSigma_m2(const double &E_eV) { - double v1_ms = sqrt(2*E_eV/m2_eV)*c_ms; - auto integrand = [&](double theta) { - double E_eV = m_eV/2 * (pow(v1_ms,2) + pow(v_therm,2) - 2*v1_ms*v_therm*cos(theta)) * pow(c_ms, -2); - return get_microSigma_m2(E_eV); - }; - return integrate(integrand, 0., pi, 30, simpson())/pi; - } -}; - - -class TI_thermal_tenary_Interaction_Base : public Interaction_Base { // Interactions of electrons with thermal Populations -protected: - double m_eV; // energy of kinetic particle for CS measurement : TI - double m2_eV; // energy of massic initial particle : T2 - double v_therm; // typical spped for thermal population - -public: - TI_thermal_tenary_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double m_eV) : Interaction_Base(Population, rngUni) { - if (Population->get_number_E_bins() > 1) { - throw MyException("Population is not thermal, when expected thermal."); - } - this->m_eV = m_eV; - m2_eV = Population->get_m_eV(); - v_therm = Population->get_thermal_v_ms(); // Typical Speed of "Thermal Blur" - } - - double get_macro_sigma_m(const Particle &interPart) { - vec3 loc_m = interPart.get_x_m(); - double v_ms = calc_vec3_abs(interPart.get_v_ms() - Population->get_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" - double E_eV = m_eV/2*pow(v_ms/c_ms, 2); // Lab energy without thermal integration - return calc_macro_sigma_m(E_eV, loc_m); - } -private: - virtual double get_microSigma_divbyn_m2(const double &E_eV) = 0; - -protected: - double calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { - return calc_microSigma_divbyn_m2(E_eV)*pow(Population->get_density_m3(loc_m), 2); - } - - double calc_microSigma_divbyn_m2(const double &E_eV) { - double v1_ms = sqrt(2*E_eV/m2_eV)*c_ms; - auto integrand = [&](double theta) { - double E_eV = m_eV/2 * (pow(v1_ms,2) + pow(v_therm,2) - 2*v1_ms*v_therm*cos(theta)) * pow(c_ms, -2); - return get_microSigma_divbyn_m2(E_eV); - }; - return integrate(integrand, 0., pi, 30, simpson())/pi; - } -}; - - -class TI_e_Interaction_Base : public Interaction_Base { // Interactions of ions with kinetic e Populations -protected: - double m_eV; // energy of kinetic particle for CS measurement : e- - double mI_eV; // energy of massic initial particle : TI - int num_Ee_bins; // number of Ee_bins in Populations - double *Ee_mids; // values for energy mids of Ee_bins in Populations - double *ve_mids; // corresponding v_values - -public: - TI_e_Interaction_Base(Population_Base *Population, UniRNG *rngUni, double mI_eV) : Interaction_Base(Population, rngUni) { - m_eV = Population->get_m_eV(); - this->mI_eV = mI_eV; - - num_Ee_bins = Population->get_number_E_bins(); - if (num_Ee_bins <= 1) { - throw MyException("Population is not kinetic, when kinetic thermal."); - } - ve_mids = new double[num_Ee_bins]; - Ee_mids = new double[num_Ee_bins]; - - for (int Ee_bin = 0; Ee_binget_E_bin_mid_eV(Ee_bin); - ve_mids[Ee_bin] = sqrt(2*Ee_mids[Ee_bin]/m_eV)*c_ms; - } - } - - double get_macro_sigma_m(const Particle &interPart) { - return calc_macro_sigma_m(interPart.get_E_eV(), interPart.get_x_m()); - } -protected: - virtual double get_microSigma_m2(const double &E_eV) = 0; - - double calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { - Bins loc_bins = Population->get_loc_bin(loc_m); - double macro_sigma_m = 0; - for (int Ee_bin = 0; Ee_binget_density_m3(Ee_bin, loc_bins); - } - return macro_sigma_m; - } - - double calc_microSigma_m2(const double &E1_eV, const int &Ee_bin) { - double v1_ms = sqrt(2*E1_eV/mI_eV)*c_ms; - double v2_ms = ve_mids[Ee_bin]; - - if (v2_ms*0.005 > v1_ms) { // 0.005 represents 1% variation in energy - return get_microSigma_m2(Ee_mids[Ee_bin]); // location is dummy again... - } else { - auto integrand = [&](double theta) { - double E_eV = m_eV/2 * (pow(v1_ms,2) + pow(v2_ms,2) - 2*v1_ms*v2_ms*cos(theta)) * pow(c_ms, -2); - return get_microSigma_m2(E_eV); // location is dummy again... - }; - return integrate(integrand, 0., pi, 30, simpson())/pi; - } - } -}; - -#endif /* sub_interaction_base_h */