Added Integration Method and Bug fix, which lead to T5+ recombination rate being way too high.

This commit is contained in:
Christian
2019-11-14 12:28:31 +01:00
parent 7fca174042
commit aef20ad949
6 changed files with 110 additions and 65 deletions
+69
View File
@@ -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<typename Method, typename F, typename Float>
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<typename F, typename Float>
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<typename F, typename Float>
double operator()(F f, Float x, Float h) const
{
return (f(x) + f(x+h))/2;
}
};
class simpson
{
public:
template<typename F, typename Float>
double operator()(F f, Float x, Float h) const
{
return (f(x) + 4*f(x+h/2) + f(x+h))/6;
}
};
#endif /* integrater_h */
+29 -27
View File
@@ -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_bin<bounds.num_E_bins; E_bin++) {
cont = Population->get_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_bin<bounds.num_E_bins; E_bin++) {
cont = Population->get_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;
}
+3 -1
View File
@@ -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;