Added Integration Method and Bug fix, which lead to T5+ recombination rate being way too high.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -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 */
|
||||||
@@ -15,6 +15,8 @@
|
|||||||
#include "particle.hpp"
|
#include "particle.hpp"
|
||||||
#include "population_base.h"
|
#include "population_base.h"
|
||||||
|
|
||||||
|
#include "constants.h"
|
||||||
|
#include "integrater.h"
|
||||||
#include "error_types.h"
|
#include "error_types.h"
|
||||||
|
|
||||||
class InteractionOut {
|
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) {
|
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
|
// Calulate average interaction cross section by integration over theta
|
||||||
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
|
|
||||||
vec3 loc_m = interPart.get_x_m();
|
vec3 loc_m = interPart.get_x_m();
|
||||||
double m_eV = interPart.get_m_eV();
|
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 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 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 micro_sigma;
|
||||||
double E_max_eV = m_eV/2*pow(v1_ms + v2_ms,2)/c_ms/c_ms;
|
if (v1_ms*0.005 > v2_ms) { // 0.005 represents 1% variation in energy
|
||||||
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 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) {
|
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();
|
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 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();
|
double v1_ms = interPart.get_vAbs_ms();
|
||||||
|
|
||||||
Content cont;
|
Content cont;
|
||||||
double v2_ms, E_min_eV, E_max_eV;
|
double v2_ms;
|
||||||
double macro_Sigma_m2 = 0;
|
double macro_Sigma_m2 = 0;
|
||||||
|
double micro_sigma, E_eV;
|
||||||
for (int E_bin = 0; E_bin<bounds.num_E_bins; E_bin++) {
|
for (int E_bin = 0; E_bin<bounds.num_E_bins; E_bin++) {
|
||||||
cont = Population->get_density_m3(E_bin, bounds.loc_bins);
|
cont = Population->get_density_m3(E_bin, bounds.loc_bins);
|
||||||
v2_ms = sqrt(2*cont.E_eV/m_eV);
|
v2_ms = sqrt(2*cont.E_eV/m_eV)*c_ms;
|
||||||
E_min_eV = m_eV/2*pow(v1_ms - v2_ms,2)/c_ms/c_ms;
|
if (v2_ms > v1_ms*0.005) { // 0.005 represents 1% variation in energy
|
||||||
E_max_eV = m_eV/2*pow(v1_ms + v2_ms,2)/c_ms/c_ms;
|
E_eV = m_eV/2 * pow(v2_ms/c_ms,2);
|
||||||
macro_Sigma_m2 += (get_microSigma_m2(E_min_eV, loc_m)+get_microSigma_m2(E_max_eV, loc_m))/2 * cont.n_m3;
|
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;
|
return macro_Sigma_m2;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class Base_Kinematics {
|
|||||||
UniRNG *rngUni;
|
UniRNG *rngUni;
|
||||||
NormalRNG *rngNormal;
|
NormalRNG *rngNormal;
|
||||||
double m_eV, wgtsTemp_K;
|
double m_eV, wgtsTemp_K;
|
||||||
|
double v_thermal;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Base_Kinematics(double m_eV, double wgtsTemp_K, UniRNG *rngUni, NormalRNG *rngNormal) {
|
Base_Kinematics(double m_eV, double wgtsTemp_K, UniRNG *rngUni, NormalRNG *rngNormal) {
|
||||||
@@ -23,13 +24,14 @@ public:
|
|||||||
this->wgtsTemp_K = wgtsTemp_K;
|
this->wgtsTemp_K = wgtsTemp_K;
|
||||||
this->rngUni = rngUni;
|
this->rngUni = rngUni;
|
||||||
this->rngNormal = rngNormal;
|
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) {
|
vec3 get_v_ms(const vec3&loc_m) {
|
||||||
return roll_v_thermal_ms() + get_v_offset_ms(loc_m);
|
return roll_v_thermal_ms() + get_v_offset_ms(loc_m);
|
||||||
}
|
}
|
||||||
|
|
||||||
double get_thermal_v_ms(const vec3 & 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;
|
virtual vec3 get_v_offset_ms(const vec3 &loc_m) = 0;
|
||||||
|
|||||||
@@ -7,46 +7,18 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "../mc_electron/integrater.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class data_holder {
|
double f(double x, double y, double a) { return a*x*y; }
|
||||||
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.get_data()<<"\n";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class data_setter {
|
|
||||||
data_interface *data;
|
|
||||||
public:
|
|
||||||
data_setter(data_interface *data) {
|
|
||||||
this->data = data;
|
|
||||||
}
|
|
||||||
void set_data(int input) {
|
|
||||||
data->data.data = input;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
data_interface data;
|
double a = 3;
|
||||||
data_setter data_s(&data);
|
auto g = [&] (double x) {
|
||||||
data_s.set_data(5);
|
return f(x,x, a);
|
||||||
data.show_data();
|
};
|
||||||
|
|
||||||
|
double s = integrate(g, 0.0, 1.0, 10, simpson());
|
||||||
|
cout<<s<<endl;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user