diff --git a/docs/antraege/hlrs_testzugang201908/hpc_antrag.pdf b/docs/antraege/hlrs_testzugang201908/hpc_antrag.pdf index 0ba2ac7..5d87c8c 100644 Binary files a/docs/antraege/hlrs_testzugang201908/hpc_antrag.pdf and b/docs/antraege/hlrs_testzugang201908/hpc_antrag.pdf differ diff --git a/docs/antraege/hlrs_testzugang201908/single_core.pdf b/docs/antraege/hlrs_testzugang201908/single_core.pdf index 7d2bc2c..644492f 100644 Binary files a/docs/antraege/hlrs_testzugang201908/single_core.pdf and b/docs/antraege/hlrs_testzugang201908/single_core.pdf differ diff --git a/src/mc_electron/integrater.h b/src/mc_electron/integrater.h new file mode 100644 index 0000000..15a16f9 --- /dev/null +++ b/src/mc_electron/integrater.h @@ -0,0 +1,69 @@ +// +// integrater.h +// mc_electron +// +// Created by Christian Reiling on 14.11.19. +// Copyright © 2019 Christian Reiling. All rights reserved. +// + +#ifndef integrater_h +#define integrater_h + +// Integrater from https://rosettacode.org/wiki/Numerical_integration#C.2B.2B + +// the integration routine +template +double integrate(F f, Float a, Float b, int steps, Method m) +{ + double s = 0; + double h = (b-a)/steps; + for (int i = 0; i < steps; ++i) + s += m(f, a + h*i, h); + return h*s; +} + +// methods +class rectangular +{ +public: + enum position_type { left, middle, right }; + rectangular(position_type pos): position(pos) {} + template + double operator()(F f, Float x, Float h) const + { + switch(position) + { + case left: + return f(x); + case middle: + return f(x+h/2); + case right: + return f(x+h); + } + } +private: + const position_type position; +}; + +class trapezium +{ +public: + template + double operator()(F f, Float x, Float h) const + { + return (f(x) + f(x+h))/2; + } +}; + +class simpson +{ +public: + template + double operator()(F f, Float x, Float h) const + { + return (f(x) + 4*f(x+h/2) + f(x+h))/6; + } +}; + + +#endif /* integrater_h */ diff --git a/src/mc_electron/sub_interaction_base.h b/src/mc_electron/sub_interaction_base.h index de01b80..e2dcf9f 100644 --- a/src/mc_electron/sub_interaction_base.h +++ b/src/mc_electron/sub_interaction_base.h @@ -15,6 +15,8 @@ #include "particle.hpp" #include "population_base.h" +#include "constants.h" +#include "integrater.h" #include "error_types.h" class InteractionOut { @@ -74,48 +76,48 @@ inline double Sub_Interaction_Base::get_macroSigma_m(const Particle &interPart) } inline double Sub_Interaction_Base::get_macroSigma_m_thermal(const Particle &interPart) { - /* Simply take energy of particle as lab energy, therefore assume interPart.E_eV >> population.E_eV - double E_eV = interPart.get_E_eV(); - vec3 loc_m = interPart.get_x_m(); - double microSigma_m2 = get_microSigma_m2(E_eV, loc_m); - double n_target_m3 = Population->get_density_m3(loc_m); - return microSigma_m2*n_target_m3; - */ - - // Calulate average interaction cross section by sigma = (sigma_min + sigma_max)/2 + // Calulate average interaction cross section by integration over theta vec3 loc_m = interPart.get_x_m(); double m_eV = interPart.get_m_eV(); double v1_ms = calc_vec3_abs(interPart.get_v_ms() - Population->get_drift_v_ms(loc_m)); // Shift to "Labframe without thermal blur" double v2_ms = Population->get_thermal_v_ms(loc_m); // Typical Speed of "Thermal Blur" - double E_min_eV = m_eV/2*pow(v1_ms - v2_ms,2)/c_ms/c_ms; - double E_max_eV = m_eV/2*pow(v1_ms + v2_ms,2)/c_ms/c_ms; - return (get_microSigma_m2(E_min_eV, loc_m) + get_microSigma_m2(E_max_eV, loc_m))/2*Population->get_density_m3(loc_m); + double micro_sigma; + if (v1_ms*0.005 > v2_ms) { // 0.005 represents 1% variation in energy + double E_eV = m_eV/2 * pow(v1_ms/c_ms,2); + micro_sigma = get_microSigma_m2(E_eV, loc_m); + } 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, loc_m); + }; + micro_sigma = integrate(integrand, 0., pi, 30, simpson()); + } + return micro_sigma*Population->get_density_m3(loc_m); } inline double Sub_Interaction_Base::get_macroSigma_m_kinetic(const Particle &interPart, const Sum_bounds &bounds) { - /* integrate over all energy bins, consider interPart.E_eV << E_eV. - vec3 loc_m = interPart.get_x_m(); - Content cont; - double macro_Sigma_m2 = 0; - for (int E_bin = 0; E_binget_density_m3(E_bin, bounds.loc_bins); - macro_Sigma_m2 += get_microSigma_m2(cont.E_eV, loc_m) * cont.n_m3; - } - return macro_Sigma_m2; - */ vec3 loc_m = interPart.get_x_m(); double m_eV = Population->get_m_eV(); // Since CS is given in lab frame of "kinetic particle hitting fixed T" Fix this more elegant later. double v1_ms = interPart.get_vAbs_ms(); Content cont; - double v2_ms, E_min_eV, E_max_eV; + double v2_ms; double macro_Sigma_m2 = 0; + double micro_sigma, E_eV; for (int E_bin = 0; E_binget_density_m3(E_bin, bounds.loc_bins); - v2_ms = sqrt(2*cont.E_eV/m_eV); - E_min_eV = m_eV/2*pow(v1_ms - v2_ms,2)/c_ms/c_ms; - E_max_eV = m_eV/2*pow(v1_ms + v2_ms,2)/c_ms/c_ms; - macro_Sigma_m2 += (get_microSigma_m2(E_min_eV, loc_m)+get_microSigma_m2(E_max_eV, loc_m))/2 * cont.n_m3; + v2_ms = sqrt(2*cont.E_eV/m_eV)*c_ms; + if (v2_ms > v1_ms*0.005) { // 0.005 represents 1% variation in energy + E_eV = m_eV/2 * pow(v2_ms/c_ms,2); + micro_sigma = get_microSigma_m2(E_eV, loc_m); + } 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, loc_m); + }; + micro_sigma = integrate(integrand, 0., pi, 30, simpson()); + macro_Sigma_m2 += micro_sigma * cont.n_m3; + } } return macro_Sigma_m2; } diff --git a/src/mc_electron/wgts_kinematics.h b/src/mc_electron/wgts_kinematics.h index 0673025..67ddb3f 100644 --- a/src/mc_electron/wgts_kinematics.h +++ b/src/mc_electron/wgts_kinematics.h @@ -16,6 +16,7 @@ class Base_Kinematics { UniRNG *rngUni; NormalRNG *rngNormal; double m_eV, wgtsTemp_K; + double v_thermal; public: Base_Kinematics(double m_eV, double wgtsTemp_K, UniRNG *rngUni, NormalRNG *rngNormal) { @@ -23,13 +24,14 @@ public: this->wgtsTemp_K = wgtsTemp_K; this->rngUni = rngUni; this->rngNormal = rngNormal; + v_thermal = sqrt(2*kb_eVK*30/m_eV)*c_ms; // most probable speed sqrt(2*kb*T/m) }; vec3 get_v_ms(const vec3&loc_m) { return roll_v_thermal_ms() + get_v_offset_ms(loc_m); } double get_thermal_v_ms(const vec3 & loc_m) { - return sqrt(2*kb_eVK*30/m_eV)*c_ms; // most probable speed sqrt(2*kb*T/m) + return v_thermal; } virtual vec3 get_v_offset_ms(const vec3 &loc_m) = 0; diff --git a/src/test_enviroment/main.cpp b/src/test_enviroment/main.cpp index 5cf8462..69cf444 100644 --- a/src/test_enviroment/main.cpp +++ b/src/test_enviroment/main.cpp @@ -7,46 +7,18 @@ // #include +#include "../mc_electron/integrater.h" using namespace std; -class data_holder { - int data; - friend class data_setter; -public: - data_holder() { - data = 3; - } - int get_data() { - return data; - } -}; - -class data_interface { - data_holder data; - friend class data_setter; -public: - data_interface() {}; - void show_data() { - cout<<"data = \t"<data = data; - } - void set_data(int input) { - data->data.data = input; - } -}; - +double f(double x, double y, double a) { return a*x*y; } int main() { - data_interface data; - data_setter data_s(&data); - data_s.set_data(5); - data.show_data(); + double a = 3; + auto g = [&] (double x) { + return f(x,x, a); + }; + + double s = integrate(g, 0.0, 1.0, 10, simpson()); + cout<