From 4d73f372f3c5aadfc7dd1981001c10a278877108 Mon Sep 17 00:00:00 2001 From: Joachim Rupp Date: Tue, 9 Mar 2021 15:51:17 +0100 Subject: [PATCH] Recombination Test Code --- src/mc_electron/T2Ie_recombination.h | 47 +++- src/mc_electron/TI_kinetic_base.h | 206 +++++++++++++++++- src/mc_electron/drift_base.h | 132 ++++++++++- src/mc_electron/eT2I_recombination.h | 12 +- src/mc_electron/e_thermal_base.h | 192 +++++++++++++++- src/mc_electron/h5tb_population_interface.cpp | 24 +- src/mc_electron/h5tb_population_interface.hpp | 10 +- src/mc_electron/injector.h | 29 ++- src/mc_electron/interaction_builder.cpp | 10 +- src/mc_electron/interaction_channel_base.h | 19 +- src/mc_electron/kinematics.h | 14 ++ src/mc_electron/kinetic_population.h | 21 +- src/mc_electron/main.cpp | 6 +- src/mc_electron/particle_looper.cpp | 111 +++++++++- src/mc_electron/particle_looper.hpp | 3 + src/mc_electron/population_builder.cpp | 13 +- src/mc_electron/population_container.cpp | 20 +- src/mc_electron/population_logger_base.h | 11 + src/mc_electron/simulation.cpp | 19 +- src/mc_electron/simulation.hpp | 2 + src/mc_electron/terminator_base.h | 1 + src/mc_electron/thermal_population.h | 7 +- src/mc_electron/timer.cpp | 4 + 23 files changed, 827 insertions(+), 86 deletions(-) diff --git a/src/mc_electron/T2Ie_recombination.h b/src/mc_electron/T2Ie_recombination.h index 8d06974..4311b18 100644 --- a/src/mc_electron/T2Ie_recombination.h +++ b/src/mc_electron/T2Ie_recombination.h @@ -18,14 +18,25 @@ using namespace std; 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) { + std::cout << "Konstruktor T2Ie_Recombinaton" << "\n"; calc_values(); // need to call here, because, constructor can't call pure virtual function } InteractionOut do_Interaction (Particle *interPart); protected: double get_microSigma_m2(const double &E_eV) { - //std::cout<<"Reco Crosssection: "<get_species()<<"\n"; - 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. - std::cout << "Ort des interpart = " << interPart->get_x_m()<<"\n"; - std::cout << "v_ms = " << Population->roll_v_ms(interPart->get_x_m())<<"\n"; + std::cout <get_species() << " RECO mit " <get_species()<<"\n"; + //std::cout << "Energie von teilchen " << interPart->get_E_eV() <<"\n"; + //std::cout << "sigma von interaction T2+ mit e- " << get_microSigma_m2(interPart->get_E_eV())<<"\n"; + + + //std::cout << "v_ms von pop e- = " << Population->roll_v_ms(interPart->get_x_m())[0]<<"\n"; + //std::cout << "v_ms von pop e- = " << Population->roll_v_ms(interPart->get_x_m())[0]<<"\n"; + //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. + //double E_eV = calc_E_eV_from_v_ms_richtig(Population->roll_v_ms(interPart->get_x_m())); + double E_eV = Population->roll_v_ms(interPart->get_x_m())(0); + //fehler? roll_v_ms gibt eine energie + std::cout << "Energie aus e- pop " << E_eV <<"\n"; + //std::cout << "Ort des interpart = " << interPart->get_x_m()<<"\n"; + + //E_eV = 1.0; //damit es mal geht, komischer Fehler + + double E_min_eV = 1e-7; + double E_max_eV = 2e4; + int number_E_bins = 50; Log_Scale E_scale; + E_scale = Log_Scale(E_min_eV, E_max_eV, number_E_bins); int Ee_bin = E_scale.calc_index(E_eV); std::cout<<"Ee_bin = " << Ee_bin<<"\n"; - std::cout << "E_eV = " << E_eV<<"\n"; + //std::cout << "E_eV = " << E_eV<<"\n"; Bins loc_bin = Population->get_loc_bin(interPart->get_x_m()); //std::cout<<"E aus roll v = "<get_density_m3(Ee_bin, loc_bin); //nur zum schauen - std::cout<<"Population vor Reco = "<decrease_denisty(interPart->get_x_m(), E_eV); double n2 = Population->get_density_m3(Ee_bin, loc_bin); //nur zum schauen - std::cout<<"Population vor Reco = "<get_loc_bin(loc_m); + + std::cout << "Energie von T2+ in calc macro sigma also in mirco sigma: " << E_eV << "\n"; + 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) { - //return get_microSigma_m2(Ee_mids[Ee_bin]); // No Integration... Only e- energy - double v1_ms = ve_mids[Ee_bin]; - double v2_ms = calc_v_ms_from_E_eV(E2_eV, m2_eV); + if(Population->get_density_m3(Ee_bin, loc_bins) > 0 ){ + + double v1_ms = ve_mids[Ee_bin]; //ist nährungsweise die richitge geschwindigkeit für elektorn + double v2_ms = calc_v_ms_from_E_eV(E_eV, m2_eV); //ist die richtige geschwindigkeit für ion if (v1_ms > v2_ms*2000 ) { // 2000 represents 1% variation in energy + //std::cout << "machen wir das?" << "\n"; + //std::cout << Ee_mids[Ee_bin] << "\n"; + //std::cout << get_microSigma_m2(Ee_mids[Ee_bin]) << "\n"; + //std::cout << "wird nicht gemacht oder? " << "\n"; return get_microSigma_m2(Ee_mids[Ee_bin]); + } else { + + //neu + + double v1_ms = ve_mids[Ee_bin]; + double v2_ms = calc_v_ms_from_E_eV(E_eV, m2_eV); + //std::cout << "v1 " << v1_ms <<"\n"; + //std::cout << "v2 " << v2_ms <<"\n"; + auto integrand = [&](double theta) { + + + double p1 = gammafaktor(v2_ms) * m2_eV * v2_ms / c_ms; + double p2 = gammafaktor(v1_ms) * m1_eV * v1_ms / c_ms; + + double E1 = sqrt(pow(m2_eV, 2) + pow(p1, 2)); // so ist es wie im python skyript + double E2 = sqrt(pow(m1_eV, 2) + pow(p2, 2)); // wie im skrpt + + /* + std::cout << "E1 " << E1 << "\n"; // ion + std::cout << "E2 " << E2 << "\n"; // elektron + std::cout << "v1 " << v1_ms << "\n"; // elektron + std::cout << "v2 " << v2_ms << "\n"; // ion + std::cout << "p1 " << p1 << "\n"; // p von ion + std::cout << "p2 " << p2 << "\n"; // p von elektorn + std::cout << "m1 " << m1_eV << "\n"; // elektron + std::cout << "m2 " << m2_eV << "\n"; // ion + */ + double s = pow(m1_eV,2) + pow(m2_eV,2) + 2 * E1 * E2 - 2 * p1 * p2 * cos(theta); + //std::cout << "s " << s << "\n"; + double E_cm_eV = sqrt(s) - m1_eV - m2_eV; + //std::cout << "theta " << theta << "\n"; + //std::cout << "E_cm_eV " << E_cm_eV << "\n"; + double twoEam2 = s - pow(m1_eV, 2) - pow(m2_eV, 2); + double E_incident = twoEam2/(2*m1_eV); + double E_kin_incident = E_incident - m2_eV; + double E_eV = E_kin_incident; + + //E_eV = m2_eV/2 * (pow(v1_ms,2) + pow(v2_ms,2) - 2*v1_ms*v2_ms*cos(theta)) * pow(c_ms, -2); // m1_eV equals reduced mass + + //std::cout << "Energie für microsigma berechnung " << E_eV <<"\n"; + return get_microSigma_m2(E_eV); + }; + + double integralergebnis = integrate(integrand, 0., pi, INT_N, simpson())/pi; + //std::cout << "integral gibt: " << integralergebnis <<"\n"; + + /* //alt 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, simpson())/pi; + */ + } + + std::cout << "monte carlo micro sigma " << calc_microSigma_m2(E_eV, Ee_bin) << "\n"; + std::cout << "Monte carlo macro sigma " << macro_sigma_m << "\n"; + + + //std::cout << "micro sigma in calcmacrosigma in ohne precomputed" << calc_microSigma_m2(E_eV, Ee_bin) <<"\n"; + } + } + + + + + return macro_sigma_m; +} + +inline double TI_e_Interaction_Base::calc_microSigma_m2(const double &E2_eV, const int &Ee_bin) { + //return get_microSigma_m2(Ee_mids[Ee_bin]); // No Integration... Only e- energy + double v1_ms = ve_mids[Ee_bin]; //ist nährungsweise die richitge geschwindigkeit für elektorn + double v2_ms = calc_v_ms_from_E_eV(E2_eV, m2_eV); //ist die richtige geschwindigkeit für ion + + if (v1_ms > v2_ms*2000 ) { // 2000 represents 1% variation in energy + //std::cout << "machen wir das?" << "\n"; + //std::cout << Ee_mids[Ee_bin] << "\n"; + //std::cout << get_microSigma_m2(Ee_mids[Ee_bin]) << "\n"; + return get_microSigma_m2(Ee_mids[Ee_bin]); + + } else { + + + + //neu + + double v1_ms = ve_mids[Ee_bin]; + double v2_ms = calc_v_ms_from_E_eV(E2_eV, m2_eV); + //std::cout << "v1 " << v1_ms <<"\n"; + //std::cout << "v2 " << v2_ms <<"\n"; + auto integrand = [&](double theta) { + + + double p1 = gammafaktor(v2_ms) * m2_eV * v2_ms / c_ms; + double p2 = gammafaktor(v1_ms) * m1_eV * v1_ms / c_ms; + + double E1 = sqrt(pow(m2_eV, 2) + pow(p1, 2)); // so ist es wie im python skyript + double E2 = sqrt(pow(m1_eV, 2) + pow(p2, 2)); // wie im skrpt + + + //std::cout << "E1 " << E1 << "\n"; // ion + //std::cout << "E2 " << E2 << "\n"; // elektron + //std::cout << "v1 " << v1_ms << "\n"; // elektron + //std::cout << "v2 " << v2_ms << "\n"; // ion + //std::cout << "p1 " << p1 << "\n"; // p von ion + //std::cout << "p2 " << p2 << "\n"; // p von elektorn + //std::cout << "m1 " << m1_eV << "\n"; // elektron + //std::cout << "m2 " << m2_eV << "\n"; // ion + + double s = pow(m1_eV,2) + pow(m2_eV,2) + 2 * E1 * E2 - 2 * p1 * p2 * cos(theta); + //std::cout << "s " << s << "\n"; + double E_cm_eV = sqrt(s) - m1_eV - m2_eV; + //std::cout << "theta " << theta << "\n"; + //std::cout << "E_cm_eV " << E_cm_eV << "\n"; + double twoEam2 = s - pow(m1_eV, 2) - pow(m2_eV, 2); + double E_incident = twoEam2/(2*m1_eV); + double E_kin_incident = E_incident - m2_eV; + + + //double E_eV = m2_eV/2 * (pow(v1_ms,2) + pow(v2_ms,2) - 2*v1_ms*v2_ms*cos(theta)) * pow(c_ms, -2); // m1_eV equals reduced mass + + //std::cout << "Energie für microsigma berechnung " << E_eV <<"\n"; + return get_microSigma_m2(E_kin_incident); + }; + + double integralergebnis = integrate(integrand, 0., pi, INT_N, simpson())/pi; + return integralergebnis; + //std::cout << "integral gibt: " << integralergebnis <<"\n"; + + + + /* + //alt + 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, simpson())/pi; + */ + } } @@ -94,8 +239,11 @@ private: }; inline void TI_e_Precomputed_Interaction_Base::calc_values() { + + std::cout << "EI_bins " << E_scale.get_number_bins() << "\n"; + std::cout << "Ee_bins " << num_Ee_bins << "\n"; for (int EI_bin=0; EI_bin get_loc_bin(loc_m); + + //for (int Ee_bin = 0; Ee_binget_E_bin_mid_eV(Ee_bin) <<"\n"; + // std::cout << "Dichte in bin: "<< Population->get_density_m3(Ee_bin, loc_bin)<<"\n"; + //} + + //std::cout << "Pop in TI_e_precomputed_interaction_base: " << Population->get_species() << "\n"; + //std::cout << "Dichte der Pop in get_macro_sigma: " << Population->get_density_m3(Ee_bin, loc_bin) <<"\n"; + if (E_scale.in_scale(E_eV)) { - return lookup_macro_sigma_m(E_eV, loc_m); + std::cout << "look up" << "\n"; + //double a = lookup_macro_sigma_m(E_eV, loc_m); + //std::cout << "TI_e_Precomputed_interaction_base lookup_macro_sigma: "<< a << "\n"; + return lookup_macro_sigma_m(E_eV, loc_m); //ist hier richtig + //return calc_macro_sigma_m(E_eV, loc_m); } else { + //double a = calc_macro_sigma_m(E_eV, loc_m); + //std::cout << "TI_e_Precomputed_interaction_base calc_macro_sigma: "<< a <<"\n"; + //return lookup_macro_sigma_m(E_eV, loc_m); + std::cout << "calc" << "\n"; return calc_macro_sigma_m(E_eV, loc_m); } } inline double TI_e_Precomputed_Interaction_Base::lookup_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { + + int EI_bin = E_scale.calc_index(E_eV); double *microSigmas = precomputed_values[EI_bin]; + std::cout << "EI_bin Ion Energie bin? " << EI_bin << "\n"; + //std::cout << "microSigmas schaut in precomputed values bei EI_bin: " << microSigmas << "\n"; + 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); + if(Population->get_density_m3(Ee_bin, loc_bins) > 0){ + std::cout << "Pop die Beitrag liefert: " << Population->get_species() << " "<< Population->get_density_m3(Ee_bin, loc_bins) <<"\n"; + std::cout << "micro sigma in look up macro sigma: " << microSigmas[Ee_bin] <<"\n"; + //std::cout << macro_sigma_m<<"\n"; + //std::cout << Ee_bin <<"\n"; + } + //std::cout << "hier gehts rein?" << "\n"; } + //std::cout << 1e17 * macro_sigma_m <<"\n"; + //std::cout << macro_sigma_m<<"\n"; return macro_sigma_m; } diff --git a/src/mc_electron/drift_base.h b/src/mc_electron/drift_base.h index 954126c..be40b41 100644 --- a/src/mc_electron/drift_base.h +++ b/src/mc_electron/drift_base.h @@ -10,7 +10,9 @@ #define drift_base_h #include "mover_base.h" - +#include "constants.h" +#include +#include // Drift Approximation: Assume constant B and only movement out in z=0, z=wgtsLength_m... class Drift_Base : public Mover_Base { @@ -18,12 +20,14 @@ public: Drift_Base(species this_species, Particle_Logger_Base *Logger, Population_Base *Population) : Mover_Base(this_species, Logger, Population) {}; void move(Particle *movePart, const double ¯o_sigma_m); - + //std::default_random_engine generator; + //std::uniform_real_distribution distribution(1e-15,1.0); + protected: double get_zNew_m(Particle *movePart, const double ¯o_sigma_m); virtual void doWallInteraction(Particle *movePart, vec3 *oldLoc_m, double *znew_m) = 0; virtual void do_E_calculus(Particle *movePart, const vec3 &oldLoc_m, const double ¯o_sigma_m) = 0; - + }; inline void Drift_Base::move(Particle *movePart, const double ¯o_sigma_m) { @@ -38,7 +42,120 @@ inline void Drift_Base::move(Particle *movePart, const double ¯o_sigma_m) { movePart->set_x_m(newLoc_m); do_E_calculus(movePart, oldLoc_m, macro_sigma_m); Logger->log(*movePart, oldLoc_m); + + //std::cout << "Pop in move sollte die vom current particle sein: " << Population->get_species() <<"\n"; + + double E_min_eV = 1e-7; + double E_max_eV = 2e4; + int number_E_bins = 50; + + Log_Scale E_scale; + E_scale = Log_Scale(E_min_eV, E_max_eV, number_E_bins); + double E_eV = movePart->get_E_eV(); + + + + try + { + double n = Population->get_density_m3(oldLoc_m); + //std::cout << "Pop vor Erhöhung: " << Population->get_species() << " "<< n <<"\n"; + + } + catch(const MyException& e) + { + double E_eV = movePart->get_E_eV(); + int Ee_bin = E_scale.calc_index(E_eV); + Bins loc_bin = Population->get_loc_bin(oldLoc_m); + double n = Population->get_density_m3(Ee_bin, loc_bin); + //std::cout << "Pop vor Erhöhung: " << Population->get_species() << " " << n << "\n"; + + + + + + /* + Bins dummyloc0 = Population->get_loc_bin(vec3(0,0,0)); + Bins dummyloc1 = Population->get_loc_bin(vec3(0,0,1)); + Bins dummyloc2 = Population->get_loc_bin(vec3(0,0,2)); + Bins dummyloc3 = Population->get_loc_bin(vec3(0,0,3)); + Bins dummyloc4 = Population->get_loc_bin(vec3(0,0,4)); + Bins dummyloc5 = Population->get_loc_bin(vec3(0,0,5)); + Bins dummyloc6 = Population->get_loc_bin(vec3(0,0,6)); + Bins dummyloc7 = Population->get_loc_bin(vec3(0,0,7)); + Bins dummyloc8 = Population->get_loc_bin(vec3(0,0,8)); + Bins dummyloc9 = Population->get_loc_bin(vec3(0,0,9)); + + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc0) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc1) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc2) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc3) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc4) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc5) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc6) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc7) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc8) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc9) << "\n"; + */ + //std::cerr << e.what() << '\n'; + /* + for (int Ee_bin = 0; Ee_binget_density_m3(Ee_bin, loc_bin) > 0){ + std::cout << "Dichte die einen Beitrag liefert: " << Population->get_density_m3(Ee_bin, loc_bin) <<"\n"; + //std::cout << macro_sigma_m<<"\n"; + //std::cout << Ee_bin <<"\n"; + } + + //std::cout << "hier gehts rein?" << "\n"; + }*/ + } + + + + //Population->get_density_m3() Population->increase_density(*movePart, oldLoc_m); + //Population->get_density_m3() + try + { + double n = Population->get_density_m3(oldLoc_m); + //std::cout << "Pop nach Erhöhung: " << Population->get_species() << " " << n <<"\n"; + + } + catch(const MyException& e) + { + double E_eV = movePart->get_E_eV(); + int Ee_bin = E_scale.calc_index(E_eV); + Bins loc_bin = Population->get_loc_bin(oldLoc_m); + double n = Population->get_density_m3(Ee_bin, loc_bin); + //std::cout << "Pop nach Erhöhung: " << Population->get_species() << " " << n << "\n"; + + + + + /* + Bins dummyloc0 = Population->get_loc_bin(vec3(0,0,0)); + Bins dummyloc1 = Population->get_loc_bin(vec3(0,0,1)); + Bins dummyloc2 = Population->get_loc_bin(vec3(0,0,2)); + Bins dummyloc3 = Population->get_loc_bin(vec3(0,0,3)); + Bins dummyloc4 = Population->get_loc_bin(vec3(0,0,4)); + Bins dummyloc5 = Population->get_loc_bin(vec3(0,0,5)); + Bins dummyloc6 = Population->get_loc_bin(vec3(0,0,6)); + Bins dummyloc7 = Population->get_loc_bin(vec3(0,0,7)); + Bins dummyloc8 = Population->get_loc_bin(vec3(0,0,8)); + Bins dummyloc9 = Population->get_loc_bin(vec3(0,0,9)); + + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc0) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc1) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc2) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc3) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc4) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc5) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc6) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc7) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc8) << "\n"; + std::cout << "pop: " << Population->get_density_m3(Ee_bin, dummyloc9) << "\n"; + */ + //std::cerr << e.what() << '\n'; + } } inline double Drift_Base::get_zNew_m(Particle *movePart, const double ¯o_sigma_m) { @@ -57,7 +174,14 @@ inline double Drift_Base::get_zNew_m(Particle *movePart, const double ¯o_sig } } else { double distance_m = 1/macro_sigma_m; - std::cout<<"Distanz = " << distance_m<<"\n"; + //distance * e^x mit mu=1 + //std::cout<<"Distanz ohne random = " << distance_m<<"\n"; + UniRNG rngUni; + double number = rngUni.random(); + //double number = distribution(generator); + //std::cout << "rngUni " << x <<"\n"; + distance_m = - distance_m * log(number); + //std::cout<<"Distanz mit random = " << distance_m<<"\n"; znew_m = zold_m + zDir*vForwardAbs_ms/vTotAbs_ms * distance_m; } return znew_m; diff --git a/src/mc_electron/eT2I_recombination.h b/src/mc_electron/eT2I_recombination.h index 23cb5ef..7a1be84 100644 --- a/src/mc_electron/eT2I_recombination.h +++ b/src/mc_electron/eT2I_recombination.h @@ -16,12 +16,14 @@ class eT2I_Recombination : public e_thermal_Precomputed_Interaction_Base { public: eT2I_Recombination(Population_Base *T2IPopulation, UniRNG *rngUni) : e_thermal_Precomputed_Interaction_Base(T2IPopulation, rngUni, me_eV) { + std::cout << "Konstruktor eT2I_Recombinaton" << "\n"; calc_values(); // need to call here, because, constructor can't call pure virtual function } double get_microSigma_m2(const double &E_eV) { //std::cout<<"werde ich benutzt?"<<"\n"; - //std::cout<< "micro sigma = "<< Janev_eT2I_Recombination::get_TCS(E_eV)<<"\n"; + //std::cout << " Energie in microsigma e- mit T2+" << E_eV << "\n"; + //std::cout<< " micro sigma e- mit T2+ = "<< Janev_eT2I_Recombination::get_TCS(E_eV)<<"\n"; return Janev_eT2I_Recombination::get_TCS(E_eV); } InteractionOut do_Interaction (Particle *interPart); @@ -32,13 +34,15 @@ inline InteractionOut eT2I_Recombination::do_Interaction (Particle *interPart) { InteractionOut res; res.set_delete_current(true); //std::cout<<"eT2I:\t"<<*interPart<<"\n"; - std::cout<<"e- wurde gelöscht"<<"\n"; + std::cout<get_species()<<" RECO mit " << Population->get_species() << "\n"; + //std::cout << "Energie von teilchen " << interPart->get_E_eV() <<"\n"; + //std::cout << "sigma von interaction e- mit T2+ " << get_microSigma_m2(interPart->get_E_eV())<< "\n"; //Bins loc_bin = Population->get_loc_bin(interPart->get_x_m()); double n1 = Population->get_density_m3(interPart->get_x_m()); //nur zum schauen - std::cout<<"Population vor Reco = "<< n1<<"\n"; + //std::cout<<"Population vor Recombination = "<< n1<<"\n"; Population->decrease_denisty(interPart->get_x_m(), 0); double n2 = Population->get_density_m3(interPart->get_x_m()); - std::cout<<"Population nach Reco = " <get_species()<<"\n"; //wird am anfang geladen ist T2+ pop, also schon ok 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" + //v_therm = Population->get_thermal_v_ms(); // Typical Speed of "Thermal Blur" + //v_therm = calc_v_ms_from_E_eV(0.1, 2*mT_eV); //gleiche energie + v_therm = calc_v_ms_from_E_eV(0.001, me_eV); // gleiche geschwidingkeit 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); @@ -42,26 +44,172 @@ inline double e_thermal_Interaction_Base::get_macro_sigma_m(const Particle &inte 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 + //std::cout << "e-thermal-base get-macro-sigma-m"<< "\n"; //wird es nicht return calc_macro_sigma_m(E_eV, loc_m); } + +double gammafaktor2(double v) { + return 1/sqrt(1-pow(v/c_ms, 2)); + } + inline double e_thermal_Interaction_Base::calc_macro_sigma_m(const double &E_eV, const vec3 &loc_m) { - //std::cout<<"hi"<<"\n"; + //std::cout <<"calc"<<"\n"; + //std::cout << "Dichte für get sigma: " << Population->get_density_m3(loc_m)<<"\n"; + //std::cout << "calc macro_sigma in e_thermal interaction base macht was "<< "\n"; + //std::cout << "Dichte die verwednet wird: "<get_density_m3(loc_m)<<"\n"; //die dichte ist falsch?, also sollte sich halt verkleinern + //std::cout << "macro sigma von calc macro sigma in e_thermal interaction base " << 1e15 * calc_microSigma_m2(E_eV)*Population->get_density_m3(loc_m)<<"\n"; + //std::cout << "microsigma = " << get_microSigma_m2(E_eV) << "\n"; + std::cout << "Energie = " << E_eV << "\n"; + + double v1_ms = calc_v_ms_from_E_eV(E_eV, m1_eV); + // Integration over theta and v + double m2_eV = Population->get_m_eV(); + //std::cout << "m2 " << m2_eV << "\n"; + + double v2_ms = v_therm; + //std::cout << "v2 " << v2_ms << "\n"; + + //double E1 = E_eV; //unnötig + //double E2 = calc_E_eV_from_v_ms(v2_ms, m2_eV); + + //auto integrand = [&](double v2_ms, double theta) + auto integrand = [&](double theta) { + + + //double v2_ms = calc_v_ms_from_E_eV(E_eV, m2_eV); + + //std::cout << "v1 " << v1_ms <<"\n"; + //std::cout << "v2 " << v2_ms <<"\n"; + + double p1 = gammafaktor2(v1_ms) * m1_eV * v1_ms / c_ms; // e- + double p2 = gammafaktor2(v2_ms) * m2_eV * v2_ms / c_ms; // ion + double E1 = sqrt(pow(m1_eV, 2) + pow(p1, 2)); // e- + double E2 = sqrt(pow(m2_eV, 2) + pow(p2, 2)); // ion + /* + std::cout << "E1 " << E1 << "\n"; //elektron + std::cout << "E2 " << E2 << "\n"; // ion + std::cout << "v1 " << v1_ms << "\n"; // elektron + std::cout << "v2 " << v2_ms << "\n"; // ion + std::cout << "p1 " << p1 << "\n"; // p von elektron + std::cout << "p2 " << p2 << "\n"; // p von ion + std::cout << "m1 " << m1_eV << "\n"; // elektron + std::cout << "m2 " << m2_eV << "\n"; // ion + */ + double s = pow(m1_eV,2) + pow(m2_eV,2) + 2 * E1 * E2 - 2 * p1 * p2 * cos(theta); + //std::cout << "s " << s << "\n"; + double E_cm_eV = sqrt(s) - m1_eV - m2_eV; + //std::cout << "theta " << theta << "\n"; + //std::cout << "E_cm_eV " << E_cm_eV << "\n"; + double twoEam2 = s - pow(m1_eV, 2) - pow(m2_eV, 2); + double E_incident = twoEam2/(2*m2_eV); + double E_kin_incident = E_incident - m1_eV; + + + //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); // m1_eV equals reduced mass + //std::cout << "geschwindigkeit pop " << v2_ms << "\n"; + //std::cout << "Energie " << E_eV <<"\n"; + //return Population->get_v_pdf(v2_ms)*get_microSigma_m2(E_eV)/pi; + return get_microSigma_m2(E_kin_incident); + }; + //std::cout << "Masse m1 " << m1_eV << "\n"; + //std::cout << "Masse m2 " << m2_eV << "\n"; + //std::cout << "thermal v " << v_therm << "\n"; + + //std::cout << "integral für e- ergebnis: " << double_simpson_integrate(integrand, 0., 3*v_therm, 0., pi, INT_N, INT_N) << "\n"; + double integralergebnis = integrate(integrand, 0., pi, INT_N, simpson())/pi; + std::cout << "integral gibt: " << integralergebnis <<"\n"; + std::cout << "Energie? " << E_eV << "\n"; + //std::cout << "E_limit? " << E_limit << "\n"; + std::cout << "get microsigma ohne integral (wird nicht verwendet) " << get_microSigma_m2(E_eV) << "\n"; + std::cout << "Monte Carlo sigma = " << calc_microSigma_m2(E_eV) << "\n"; + 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) { //return get_microSigma_m2(E_eV); //No Integration... Only e- energy if (E_eV > E_limit) { + //std::cout << " microsigma = " << get_microSigma_m2(E_eV) << "\n"; return get_microSigma_m2(E_eV); } else { double v1_ms = calc_v_ms_from_E_eV(E_eV, m1_eV); + + double m2_eV = Population->get_m_eV(); + //std::cout << "m2 " << m2_eV << "\n"; + + double v2_ms = v_therm; + //std::cout << "v2 " << v2_ms << "\n"; + + //double E1 = E_eV; //unnötig + //double E2 = calc_E_eV_from_v_ms(v2_ms, m2_eV); + + //auto integrand = [&](double v2_ms, double theta) + auto integrand = [&](double theta) { + //double v2_ms = calc_v_ms_from_E_eV(E_eV, m2_eV); + + //std::cout << "v1 " << v1_ms <<"\n"; + //std::cout << "v2 " << v2_ms <<"\n"; + + double p1 = gammafaktor2(v1_ms) * m1_eV * v1_ms / c_ms; // e- + double p2 = gammafaktor2(v2_ms) * m2_eV * v2_ms / c_ms; // ion + double E1 = sqrt(pow(m1_eV, 2) + pow(p1, 2)); // e- + double E2 = sqrt(pow(m2_eV, 2) + pow(p2, 2)); // ion + + //std::cout << "E1 " << E1 << "\n"; //elektron + //std::cout << "E2 " << E2 << "\n"; // ion + //std::cout << "v1 " << v1_ms << "\n"; // elektron + //std::cout << "v2 " << v2_ms << "\n"; // ion + //std::cout << "p1 " << p1 << "\n"; // p von elektron + //std::cout << "p2 " << p2 << "\n"; // p von ion + //std::cout << "m1 " << m1_eV << "\n"; // elektron + //std::cout << "m2 " << m2_eV << "\n"; // ion + + double s = pow(m1_eV,2) + pow(m2_eV,2) + 2 * E1 * E2 - 2 * p1 * p2 * cos(theta); + //std::cout << "s " << s << "\n"; + double E_cm_eV = sqrt(s) - m1_eV - m2_eV; + //std::cout << "theta " << theta << "\n"; + //std::cout << "E_cm_eV " << E_cm_eV << "\n"; + double twoEam2 = s - pow(m1_eV, 2) - pow(m2_eV, 2); + double E_incident = twoEam2/(2*m2_eV); + double E_kin_incident = E_incident - m1_eV; + + + //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); // m1_eV equals reduced mass + //std::cout << "geschwindigkeit pop " << v2_ms << "\n"; + //std::cout << "Energie " << E_eV <<"\n"; + //return Population->get_v_pdf(v2_ms)*get_microSigma_m2(E_eV)/pi; + return get_microSigma_m2(E_kin_incident); + }; + //std::cout << "Masse m1 " << m1_eV << "\n"; + //std::cout << "Masse m2 " << m2_eV << "\n"; + //std::cout << "thermal v " << v_therm << "\n"; + //std::cout << "integral für e- ergebnis: " << double_simpson_integrate(integrand, 0., 3*v_therm, 0., pi, INT_N, INT_N) << "\n"; + double integralergebnis = integrate(integrand, 0., pi, INT_N, simpson())/pi; + return integralergebnis; + + + +/* + // Integration over theta and v + double v2_ms = v_therm; + 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, simpson())/pi; +*/ + + + /* //alt // Integration over theta and v auto integrand = [&](double v2_ms, double theta) { + v2_ms = v2_ms + Population->get_drift() 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 Population->get_v_pdf(v2_ms)*get_microSigma_m2(E_eV)/pi; }; return double_simpson_integrate(integrand, 0., 3*v_therm, 0., pi, INT_N, INT_N); // 3*v_therm equals 99% of the integral + */ } } @@ -98,26 +246,47 @@ private: }; inline void e_thermal_Precomputed_Interaction_Base::calc_values() { + std::cout << "number E bins " << E_scale.get_number_bins() << "\n"; for (int i=0; i hier suchen! + vec3 loc_m = interPart.get_x_m(); - //std::cout<<"loc_m = "<get_species() << "\n"; + //std::cout << "verwendete Dichte für get_macro_sigma_m in e_thermal_precomputed_interaction_base: " << Population->get_species() << " "<get_density_m3(loc_m)<<"\n"; double v_ms = calc_vec3_abs(interPart.get_v_ms() - Population->get_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" - //std::cout<<"v_ms = "<get_species() << "\n"; + //double v_ms = calc_vec3_abs(interPart.get_v_ms()); //test ohne shift + //std::cout << "verwendete geschwindigkeit: " << v_ms << "\n"; + //std::cout << "thermal dirft v = " << Population->get_drift_v_ms(loc_m) << "\n"; + double E_eV = calc_E_eV_from_v_ms(v_ms, m1_eV); // Lab energy without thermal + //E_eV = interPart.get_E_eV(); // warum nicht so? + //double microsigma_montecarlo = calc_microSigma_m2(E_eV); + //std::cout << "Monte Carlo Micro Sigma = " << microsigma_montecarlo << "\n"; + //std::cout << "pop in get_macro_sigma_m in e_thermal_precomputed_interaction_base: " << Population->get_species()<<"\n"; + + + //return calc_macro_sigma_m(E_eV, loc_m); + if (E_scale.in_scale(E_eV)) { - //std::cout<< "Macro sigma = " << lookup_macro_sigma_m(E_eV, loc_m)<<"\n"; + //double a; + //a = lookup_macro_sigma_m(E_eV, loc_m); + //std::cout << " lookup_macro_sigma in get_macro_sigma in e_thermal_precomputed_base gibt: " << a <<"\n"; + std::cout << "look_up" << "\n"; return lookup_macro_sigma_m(E_eV, loc_m); + //return calc_macro_sigma_m(E_eV, loc_m); // zum testen } else { - //std::cout<< "Macro sigma = " << calc_macro_sigma_m(E_eV, loc_m)<<"\n"; + //double a; + //a = calc_macro_sigma_m(E_eV, loc_m); + //std::cout << "calc_macro_sigma in get_macro_sigma in e_thermal_precomputed_base: " << a << "\n"; + std::cout<< "calc" <<"\n"; 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) { @@ -126,6 +295,9 @@ inline double e_thermal_Precomputed_Interaction_Base::lookup_macro_sigma_m(const //std::cout <<"precomputed_values[i] = " << precomputed_values[i]<< "\n"; //std::cout << "pop denisity = " << Population->get_density_m3(loc_m)<<"\n"; //std::cout << "pop denisity species = " << Population->get_species()<<"\n"; + //std::cout <<"look up"<<"\n"; + //std::cout << "Dichte für get sigma in e_thermal_precomuputed_interaction_base: " << Population->get_density_m3(loc_m)<<"\n"; + std::cout << "precomputaed value der verwendet wird (Monte Carlo Sigma): " << precomputed_values[i] <<"\n"; return precomputed_values[i] * Population->get_density_m3(loc_m); } diff --git a/src/mc_electron/h5tb_population_interface.cpp b/src/mc_electron/h5tb_population_interface.cpp index 176cafd..7610ac4 100644 --- a/src/mc_electron/h5tb_population_interface.cpp +++ b/src/mc_electron/h5tb_population_interface.cpp @@ -15,43 +15,51 @@ using namespace std; pop_bin sample_log_cell = {0,0,0,0,0,0,0}; const size_t H5TB_Population_Interface::size = sizeof(pop_bin); -const char *H5TB_Population_Interface::fieldNames[7] = { +const char *H5TB_Population_Interface::fieldNames[9] = { "phys_time_s", "z_bin", "r_bin", "phi_bin", "E_bin", "cum_time", - "offset"}; -const size_t H5TB_Population_Interface::offset[7] = { + "offset", + "n_m3", + "tracking"}; +const size_t H5TB_Population_Interface::offset[9] = { HOFFSET(pop_bin, phys_time_s), HOFFSET(pop_bin, z_bin), HOFFSET(pop_bin, r_bin), HOFFSET(pop_bin, phi_bin), HOFFSET(pop_bin, E_bin), HOFFSET(pop_bin, cumulated_time_s), - HOFFSET(pop_bin, offset)}; -const hid_t H5TB_Population_Interface::fieldTypes[7] = { + HOFFSET(pop_bin, offset), + HOFFSET(pop_bin, n_m3), + HOFFSET(pop_bin, tracking)}; +const hid_t H5TB_Population_Interface::fieldTypes[9] = { H5T_NATIVE_DOUBLE, H5T_NATIVE_INT, H5T_NATIVE_INT, H5T_NATIVE_INT, H5T_NATIVE_INT, H5T_NATIVE_DOUBLE, + H5T_NATIVE_INT, + H5T_NATIVE_DOUBLE, H5T_NATIVE_INT}; const hsize_t H5TB_Population_Interface::chunkSize = 225; -const size_t H5TB_Population_Interface::sizes[7] = { +const size_t H5TB_Population_Interface::sizes[9] = { sizeof( sample_log_cell.phys_time_s), sizeof( sample_log_cell.z_bin), sizeof( sample_log_cell.r_bin), sizeof( sample_log_cell.phi_bin), sizeof( sample_log_cell.E_bin), sizeof( sample_log_cell.cumulated_time_s), - sizeof( sample_log_cell.offset)}; + sizeof( sample_log_cell.offset), + sizeof( sample_log_cell.n_m3), + sizeof( sample_log_cell.tracking)}; void H5TB_Population_Interface::create() { - herr_t state = H5TBmake_table(table_name.c_str(), *loc_id, table_name.c_str(), 7, 0, + herr_t state = H5TBmake_table(table_name.c_str(), *loc_id, table_name.c_str(), 9, 0, size, fieldNames, offset, fieldTypes, chunkSize, NULL, 0, NULL); if (state < 0) { diff --git a/src/mc_electron/h5tb_population_interface.hpp b/src/mc_electron/h5tb_population_interface.hpp index a791f24..3c745e1 100644 --- a/src/mc_electron/h5tb_population_interface.hpp +++ b/src/mc_electron/h5tb_population_interface.hpp @@ -24,16 +24,18 @@ struct pop_bin { int E_bin; double cumulated_time_s; int offset; + double n_m3; + int tracking; }; class H5TB_Population_Interface { static const size_t size; - static const char *fieldNames[7]; - static const size_t offset[7]; - static const hid_t fieldTypes[7]; + static const char *fieldNames[9]; + static const size_t offset[9]; + static const hid_t fieldTypes[9]; static const hsize_t chunkSize; - static const size_t sizes[7]; + static const size_t sizes[9]; int buffer_size = 225; pop_bin buffer[225]; diff --git a/src/mc_electron/injector.h b/src/mc_electron/injector.h index 2fde219..0498766 100644 --- a/src/mc_electron/injector.h +++ b/src/mc_electron/injector.h @@ -28,10 +28,21 @@ public: Injector(UniRNG *rngUni, NormalRNG *rngNormal, Population_Base *T2Population, int method, double energy_eV, int ions) : RNG_Base(rngUni, rngNormal){ this->T2Population = T2Population; this->method = method; + //std::cout << "Method in konsturktur: " << method <<"\n"; this->energy_eV = energy_eV; this->ions = ions; }; + + void set_method(int i){ + method = i; + std::cout << "habe methode auf " << i << " gesetzt" << "\n"; + } + + void print_method(){ + std::cout << "aktuelle method ist " << method <<"\n"; + } + int inject (std::vector *particle_queue, const int &last_ID); private: double roll_FermiEnergy_eV(); @@ -42,6 +53,7 @@ private: inline int Injector::inject (std::vector *particle_queue, const int &last_ID) { vec3 loc_m = T2Population->roll_x_ms(); vec3 v_ms; + vec3 vTI_ms; //vec3 direction; double E_eV; switch(method) { @@ -61,18 +73,28 @@ inline int Injector::inject (std::vector *particle_queue, const int &l particle_queue->push_back(PartFac.create_e(loc_m, v_ms, last_ID+1, last_ID+1)); break; case 3: // Delta Injection for Recombination Testing + + std::cout << "injecte e-" <<"\n"; loc_m = vec3(0.,0.,9.99); E_eV = energy_eV; //std::cout<<"E = "<< E_eV<<"\n"; //direction = vec3(0,0,-1); v_ms = vec3(0.,0.,-1.) * calc_v_ms_from_E_eV(E_eV, me_eV); + std::cout << "Geschwindigkeit e-: " << v_ms << "\n"; particle_queue->push_back(PartFac.create_e(loc_m, v_ms, last_ID+1, last_ID+1)); break; case 4: - loc_m = vec3(0.,0.,z_WGTS_end_m); + std::cout << "injecte T2+" <<"\n"; E_eV = energy_eV; + loc_m = vec3(0.,0.,9.99); + vTI_ms = vec3(0.,0.,-1.) * calc_v_ms_from_E_eV(E_eV, me_eV); + std::cout << "Geschwindigkeit T+: " << vTI_ms << "\n"; + particle_queue->push_back(PartFac.create_T2I(loc_m, vTI_ms, last_ID+1, last_ID+1)); + + //loc_m = vec3(0.,0.,z_WGTS_end_m); + //E_eV = energy_eV; //direction = vec3(0,0,-1); - v_ms = vec3(0.,0.,-1.) * calc_v_ms_from_E_eV(E_eV, me_eV); + //v_ms = vec3(0.,0.,-1.) * calc_v_ms_from_E_eV(E_eV, me_eV); //particle_queue->push_back(PartFac.create_e(loc_m, v_ms, last_ID+1, last_ID+1)); break; default: @@ -90,7 +112,8 @@ inline int Injector::inject (std::vector *particle_queue, const int &l if (ions == 2) { // 2: Delta Injection for Testing Recombination vec3 direction = vec3(0.,0.,-1.); vec3 loc_m = vec3(0.,0.,9.99); - vec3 vTI_ms = direction * calc_v_ms_from_E_eV(E_eV, 2*mT_eV); + vec3 vTI_ms = direction * calc_v_ms_from_E_eV(E_eV, me_eV); //gleiche geschwindigkeit + //vec3 vTI_ms = direction * calc_v_ms_from_E_eV(E_eV, 2*mT_eV); // gleiche energie particle_queue->push_back(PartFac.create_T2I(loc_m, vTI_ms, last_ID+2, last_ID+2)); return 2; diff --git a/src/mc_electron/interaction_builder.cpp b/src/mc_electron/interaction_builder.cpp index d6ac695..6ad9885 100644 --- a/src/mc_electron/interaction_builder.cpp +++ b/src/mc_electron/interaction_builder.cpp @@ -52,18 +52,18 @@ Interaction_Manager Interaction_Builder::build(Population_Manager *Populations, Interaction_Manager Interactions; Interactions.add(build_electron(Populations, rngUni)); //Interactions.add(build_tritium(Populations, rngUni)); - Interactions.add(build_tritiumI(Populations, rngUni)); + //Interactions.add(build_tritiumI(Populations, rngUni)); Interactions.add(build_tritium2I(Populations, rngUni)); - Interactions.add(build_tritium3I(Populations, rngUni)); - Interactions.add(build_tritium5I(Populations, rngUni)); + //Interactions.add(build_tritium3I(Populations, rngUni)); + //Interactions.add(build_tritium5I(Populations, rngUni)); return Interactions; } Interaction_Channel_Base* Interaction_Builder::build_electron(Population_Manager *Populations, UniRNG *rngUni) { Interaction_Channel_Base *eInteraction = new Interaction_Channel_Base(electron, rngUni); Population_Base *T2Population = Populations->find(tritium2); Population_Base *T2IPopulation = Populations->find(tritium2I); - Population_Base *T3IPopulation = Populations->find(tritium3I); - Population_Base *T5IPopulation = Populations->find(tritium5I); + //Population_Base *T3IPopulation = Populations->find(tritium3I); + //Population_Base *T5IPopulation = Populations->find(tritium5I); DCS_Base *exc_dcs = new ZeroPi_DCS(rngUni); if (load_parameter("eT2_ELA") == 1) { diff --git a/src/mc_electron/interaction_channel_base.h b/src/mc_electron/interaction_channel_base.h index e0af480..f52be16 100644 --- a/src/mc_electron/interaction_channel_base.h +++ b/src/mc_electron/interaction_channel_base.h @@ -32,8 +32,9 @@ public: }; inline InteractionOut Interaction_Channel_Base::do_Interaction(Particle *interPart) { - double macro_sigma_m = get_macro_sigma_m(*interPart); - //std::cout<<"MacroSigma_m = "<random() * macro_sigma_m; //std::cout<<"TargetStackedSigma_m = "<get_macro_sigma_m(*interPart); - if (currentStackedSigma >= targetStackedSigma) { + if (currentStackedSigma > targetStackedSigma) { + std::cout << "mache Interaktion" << "\n"; return SubInteractions[i]->do_Interaction(interPart); } + else{ + InteractionOut nichts; + std::cout << "Teilchen fliegt weiter"<< "\n"; + return nichts; + } + } std::stringstream ss; ss<<"Interaction_Channel_Base::do_Interaction: No Interactions added.\n"; @@ -57,8 +65,11 @@ inline double Interaction_Channel_Base::get_macro_sigma_m(const Particle &interP //std::cout<< "macro_sigma_m = " << macro_sigma_m << "\n"; //std::cout<<"Subinteraction "<get_macro_sigma_m(interPart); + //std::cout<< "macro_sigma aus get_macro_sigma in interaction_channel_base gibt im " << i << " Iterattionsschritt: " < vec3; inline double calc_vec3_abs(const vec3 &vec) { + //std::cout << vec[0] <<"\n"; return sqrt( pow(vec[0],2) + pow(vec[1],2) + pow(vec[2],2)); } @@ -35,6 +36,19 @@ inline double calc_v_ms_from_E_eV(const double &E_eV, const double &m_eV) { return sqrt(2*E_eV/m_eV) * c_ms; } +inline double get_vx_from_vec3(const vec3 &vec){ + + double a = sqrt( pow(vec[0],2) + pow(vec[1],2) + pow(vec[2],2)); + //a = a / (sqrt(3)); + return a; +} + +inline double calc_E_eV_from_v_ms_richtig(const vec3 &v_ms){ + return get_vx_from_vec3(v_ms); +} + + + inline vec3 calc_n_new(const vec3 &direction_old, const double &theta_change, const double &phi_change) { // Alireza Haghighat: Appendix 3 (p.249) vec3 nOld = direction_old/calc_vec3_abs(direction_old); diff --git a/src/mc_electron/kinetic_population.h b/src/mc_electron/kinetic_population.h index dc16600..d4c45bb 100644 --- a/src/mc_electron/kinetic_population.h +++ b/src/mc_electron/kinetic_population.h @@ -46,6 +46,7 @@ public: inline Kinetic_Population::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, double E_min_eV, double E_max_eV) : Population_Base(this_species), RNG_Base(rngUni, rngNormal), container(num_z_bins, num_r_bins, num_phi_bins, num_E_bins, E_min_eV, E_max_eV) { this->timer = timer; m_eV = get_species_mass(this_species); + //std::cout<< "Kinetic Population: " << this_species<<"\n"; }; inline void Kinetic_Population::increase_density (const Particle &upPart, const vec3 &oldLoc_m) { @@ -53,7 +54,7 @@ inline void Kinetic_Population::increase_density (const Particle &upPart, const } inline void Kinetic_Population::decrease_denisty (const vec3 &loc_m, const double &E_eV) { - std::cout<<"Kinetic POP"<<"\n"; + //std::cout<<"Kinetic POP"<<"\n"; container.increase_offset(loc_m, E_eV); } @@ -75,18 +76,28 @@ double Kinetic_Population::get_E_bin_mid_eV(const int &E_bin) { inline vec3 Kinetic_Population::roll_v_ms (const vec3 &loc_m) { Bins loc_bins = get_loc_bin(loc_m); double target = 0; + //std::cout << get_number_E_bins() <<"\n"; for (int E_bin = 0; E_binrandom(); + //std::cout << "Summe aller Dichten über alle bins: " << target<<"\n"; + target *= rngUni->random(); //wenn 0 dann blöd + //target = 0; + //std::cout << "target mit random number:" << target<<"\n"; + double current = 0; for (int E_bin = 0; E_bin= target) { - std::cout<<"roll_v_ms output = "< particle_queue; + int number_decays = 0; + while ( (number_decays < target_decays) || (!particle_queue.empty()) ) { + if (particle_queue.empty()) { + int num_new; + if(switcher){ + injector.set_method(3); + num_new = injector.inject(&particle_queue, get_last_id()); + } + + else{ + injector.set_method(4); + num_new = injector.inject(&particle_queue, get_last_id()); + } + + + /* + std::cout << "sind wir hier? " <<"\n"; + std::cout << "umschalter " << umschalter <<"\n"; + int num_new; + if(umschalter == false){ + + std::cout << "umschalter " << umschalter << "\n"; + injector.set_method(3); + injector.print_method(); + num_new = injector.inject(&particle_queue, get_last_id()); + umschalter = true; + std::cout << "wird umgeschaltet? " << umschalter << "\n"; + } + else{ + std::cout << "umschalter " << umschalter << "\n"; + injector.set_method(4); + injector.print_method(); + num_new = injector.inject(&particle_queue, get_last_id()); + umschalter = false; + } + */ + + number_decays = number_decays + 1; + local_decays = local_decays + 1; + ID_counter = ID_counter + num_new; + } + process_one(&particle_queue); + } + pop_loggers.log(); +} + + void Particle_Looper::process_one(std::vector *particle_queue) { int i = floor(rngUni.random()*particle_queue->size()); + //int i = particle_queue->size(); + //i = 0; + //std::cout << i << "\n"; Particle curPart = particle_queue->at(i); +; std::cout<<"################################################"<<"\n"; + std::cout<<"Current Particle: "<< curPart.get_species() <<"\n"; + std::cout<<"current particle energy "<< curPart.get_E_eV()<<"\n"; //Particle curPart = particle_queue->front(); Mover_Base *moverPtr = movers.find(curPart.get_species()); Interaction_Channel_Base *interactionPtr = interactions.find(curPart.get_species()); Terminator_Base *terminatorPtr = terminators.find(curPart.get_species()); InteractionOut IntOut; - double macro_sigma_m; + double macro_sigma_m; vec3 oldLoc_m; while (!terminatorPtr->check_terminlization(curPart)) { oldLoc_m = curPart.get_x_m(); + std::cout << "Wo sind wir gerade? " << oldLoc_m << "\n"; + //std::cout << "noch nichts passiert, richtig?"<< "\n"; macro_sigma_m = interactionPtr->get_macro_sigma_m(curPart); + //macro_sigma_m = macro_sigma_m * 1e21; + //std::cout<<"MacroSigma in particle_looper wird für move verwendet: "<< macro_sigma_m<<"\n"; + //macro_sigma_m = 1; //nur test - - std::cout<<"###############################"<<"\n"; - std::cout<<"Current Particle: "< also Interaktion "<<"\n"; + std::cout << "Move: " << "\n"; moverPtr->move(&curPart, macro_sigma_m); + std::cout << "Wo sind wir nach move? " << curPart.get_x_m() << "\n"; + if (terminatorPtr->check_terminlization(curPart)) { std::cout<<"Keine Interaktion."<<"\n"; break; // Don't double check terminlization, else n_double. } else { - std::cout<<"Interaktion."<<"\n"; + std::cout<<"Interaktion: "<<"\n"; + //curPart.set_x_m(oldLoc_m); IntOut = interactionPtr->do_Interaction(&curPart); for (int i=0; ipush_back(IntOut.get_new_particles()[i]); @@ -80,7 +164,7 @@ void Particle_Looper::process_one(std::vector *particle_queue) { } } } - particle_queue->erase(particle_queue->begin() + i); + particle_queue->erase(particle_queue->begin() + i ); } long int Particle_Looper::get_new_id() { @@ -101,6 +185,15 @@ void Particle_Looper::do_logging_off_loops(int target_decays) { ID_counter = prev_ID_counter; } +void Particle_Looper::do_logging_off_loops(int taget_decays, bool switcher){ + int prev_ID_counter = ID_counter; + set_logging(false); + do_loops(taget_decays, switcher); + set_logging(true); + ID_counter = prev_ID_counter; +} + + void Particle_Looper::set_logging(bool logging) { vector all_species = get_all_species_vector(); species current_species; diff --git a/src/mc_electron/particle_looper.hpp b/src/mc_electron/particle_looper.hpp index 5cbbe5b..9b775d7 100644 --- a/src/mc_electron/particle_looper.hpp +++ b/src/mc_electron/particle_looper.hpp @@ -36,6 +36,7 @@ class Particle_Looper { Population_Manager populations; Injector injector; + Injector injector2; Mover_Manager movers; Interaction_Manager interactions; Terminator_Manager terminators; @@ -66,6 +67,7 @@ private: public: void do_loops(int target_decays); + void do_loops(int taget_decays, bool switcher); private: void process_one(std::vector *particle_queue); long int get_new_id(); @@ -73,6 +75,7 @@ private: public: void do_logging_off_loops(int target_decays); + void do_logging_off_loops(int target_decays, bool switcher); private: void set_logging(bool logging); diff --git a/src/mc_electron/population_builder.cpp b/src/mc_electron/population_builder.cpp index 18af735..01a1b48 100644 --- a/src/mc_electron/population_builder.cpp +++ b/src/mc_electron/population_builder.cpp @@ -40,7 +40,18 @@ Population_Manager Population_Builder::build(Timer *timer,UniRNG *rngUni, Normal Populations.add(new Thermal_Population(tritium3I, new WGTS_Kinematics(3*mT_eV, wgtsTemp_K, rngUni, rngNormal), timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins)); Populations.add(new Thermal_Population(tritium5I, new WGTS_Kinematics(5*mT_eV, wgtsTemp_K, rngUni, rngNormal), timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins)); Populations.add(new T2_Population(new WGTS_Kinematics(2*mT_eV, wgtsTemp_K, rngUni, rngNormal), rngUni, rngNormal)); - } else { + } + else if (v_flow == 1){ + Populations.add(new Kinetic_Population(tritium, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins, num_E_bins, POP_E_START, POP_E_END)); + Populations.add(new Kinetic_Population(tritiumI, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins, num_E_bins, POP_E_START, POP_E_END)); + Populations.add(new Kinetic_Population(tritium2I, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins, num_E_bins, POP_E_START, POP_E_END)); + Populations.add(new Kinetic_Population(tritium3I, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins, num_E_bins, POP_E_START, POP_E_END)); + Populations.add(new Kinetic_Population(tritium5I, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins, num_E_bins, POP_E_START, POP_E_END)); + Populations.add(new T2_Population(new WGTS_Kinematics(2*mT_eV, wgtsTemp_K, rngUni, rngNormal), rngUni, rngNormal)); + + } + + else { Populations.add(new Thermal_Population(tritium, new Lin_Kinematics(mT_eV, wgtsTemp_K, v_flow, rngUni, rngNormal), timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins)); Populations.add(new Thermal_Population(tritiumI, new Lin_Kinematics(mT_eV, wgtsTemp_K, v_flow, rngUni, rngNormal), timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins)); Populations.add(new Thermal_Population(tritium2I, new Lin_Kinematics(2*mT_eV, wgtsTemp_K, v_flow, rngUni, rngNormal), timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins)); diff --git a/src/mc_electron/population_container.cpp b/src/mc_electron/population_container.cpp index c990ef3..08b9825 100644 --- a/src/mc_electron/population_container.cpp +++ b/src/mc_electron/population_container.cpp @@ -117,6 +117,7 @@ void Population_Container::increase_cum_time_s(const vec3 &loc1_m, const vec3 &l bin = calc_data_bin(bins_1, E_bin); cum_times_s[bin] += cum_time_s; } + //double n_m3 = cum_time_s/time_s/V_m3 - offset/V_m3 } } @@ -125,7 +126,7 @@ void Population_Container::increase_offset(const vec3 &loc_m, const double &E_eV Bins loc_bins = calc_loc_bin(loc_m); int bin = calc_data_bin(loc_bins, E_bin); offsets[bin] += 1; - std::cout<<"Offset[bin]= "<random()*(up-low); + //std::cout << "up " << up<<"\n"; + double a = low + rngUni->random()*(up-low); + //std::cout << a <<"\n"; + return low + rngUni->random()*(up-low); } int Population_Container::calc_data_bin(const Bins &loc_bin, const double &E_bin) { diff --git a/src/mc_electron/population_logger_base.h b/src/mc_electron/population_logger_base.h index 57cb7e0..6caf751 100644 --- a/src/mc_electron/population_logger_base.h +++ b/src/mc_electron/population_logger_base.h @@ -95,9 +95,15 @@ inline void Population_Logger::create_h5tb() { inline void Population_Logger::log() { pop_bin temp_bin; temp_bin.phys_time_s = timer->get_time_s(); + + //std::cout << "logging time " << timer->get_time_s() << "\n"; int bin; for (int i_z=0; i_z < container->scales.z.get_number_bins(); i_z++) { temp_bin.z_bin = i_z; + + //temp_bin.tracking += 1; + //std::cout << "tracking " << temp_bin.tracking << "\n"; + for (int i_r=0; i_r < container->scales.r.get_number_bins(); i_r++) { temp_bin.r_bin = i_r; for (int i_phi=0; i_phi < container->scales.phi.get_number_bins(); i_phi++) { @@ -107,6 +113,11 @@ inline void Population_Logger::log() { 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 = container->offsets[bin]; + temp_bin.n_m3 = container->get_density_m3(i_E, bin, temp_bin.phys_time_s); + //std::cout << temp_bin.n_m3 << "\n"; + + + h5tb.write(temp_bin); } } diff --git a/src/mc_electron/simulation.cpp b/src/mc_electron/simulation.cpp index 8e94463..40f5847 100644 --- a/src/mc_electron/simulation.cpp +++ b/src/mc_electron/simulation.cpp @@ -140,7 +140,7 @@ void Simulation::deconstruct_pop_arrays() { // Deallocate memory properly void Simulation::doit() { // 2 Phase: 1. calc average densities, 2. actual simulate - do_cycle(popCalcDecays, popCalcStep, false); + //do_cycle(popCalcDecays, popCalcStep, false); if (mpi_rank == 0) { cout<<"Population calculation done.\n"; } @@ -168,8 +168,18 @@ void Simulation::do_cycle(long int number_total, long int step_size, bool loggin if (mpi_rank < overflow) { // Split overflows equaly to left over CPUs. num_remaining += 1; } + switcher = true; for (int i = 0; i<(num_cycles-1); i++) { + std::cout << "sind wir hier?" <<"\n"; + do_decays(step_size, logging); + if(switcher == true){ + switcher = false; + } + else{ + switcher = true; + } + } if (num_cycles == 0) { // Rather unrealistic case.. maybe find a more elegant solution later. do_decays(num_remaining, logging); @@ -182,8 +192,10 @@ void Simulation::do_cycle(long int number_total, long int step_size, bool loggin void Simulation::do_decays(const long int &number_decays, const bool &logging) { if (logging) { looper.do_loops(number_decays); + //looper.do_loops(number_decays, switcher); } else { looper.do_logging_off_loops(number_decays); + //looper.do_logging_off_loops(number_decays, switcher); } number_local_decays += number_decays; sync_cpus(); @@ -246,12 +258,12 @@ void Simulation::print_term_stats() { Terminator_Manager *terminators = looper.get_terminators(); vector all_species = get_all_species_vector(); Termination_Stats local_stats, global_stats; - int local_array[7], global_array[7]; + int local_array[8], global_array[8]; for (vector::iterator itr = all_species.begin(); itr!= all_species.end(); itr++) { if (terminators->exists(*itr)) { local_stats = terminators->find(*itr)->get_stats(); local_stats.to_array(local_array); - MPI_Allreduce(local_array, global_array, 7, MPI_INT, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(local_array, global_array, 8, MPI_INT, MPI_SUM, MPI_COMM_WORLD); global_stats.from_array(global_array); if (mpi_rank == 0) { std::cout<<"# "<<*itr<<"\n"; @@ -262,6 +274,7 @@ void Simulation::print_term_stats() { std::cout<<"n_max\t"<get_time_s());} + double get_density_m3(const vec3 &loc_m) { + //std::cout << "get denistiy in thermal pop wird benutzt?"<< "\n"; //ja wird benutzt + //std::cout << "dichte von der thermal pop: "<get_time_s())<<"\n"; + return container.get_density_m3(loc_m, 0, timer->get_time_s());} double get_density_m3(const int &E_bin, const Bins &loc_bins) {throw MyException("Should not be called.\n.");} int get_number_E_bins() {return 1;} diff --git a/src/mc_electron/timer.cpp b/src/mc_electron/timer.cpp index bc5fb49..f88317b 100644 --- a/src/mc_electron/timer.cpp +++ b/src/mc_electron/timer.cpp @@ -45,6 +45,10 @@ void Timer::set_T2_activity_s() { } double Timer::get_time_s() { + //std::cout << "T2 aktivity " << T2_activity_s << "\n"; + //std::cout << "off set_time " << offset_time_s << "\n"; + //std::cout << "calc total decays " << calc_total_decays() << "\n"; + //std::cout << "get_time " << double(calc_total_decays())/T2_activity_s + offset_time_s << "\n"; return double(calc_total_decays())/T2_activity_s + offset_time_s; }