104 lines
2.7 KiB
C++
104 lines
2.7 KiB
C++
//
|
|
// injector.h
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 14.11.19.
|
|
// Copyright © 2019 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
#ifndef injector_h
|
|
#define injector_h
|
|
|
|
#include "population_base.h"
|
|
|
|
#include <vector>
|
|
#include "random_operations.h"
|
|
|
|
|
|
class Injector : RNG_Base {
|
|
int method;
|
|
double energy_eV;
|
|
int ions;
|
|
Population_Base *T2Population;
|
|
|
|
Particle_Builder PartFac;
|
|
|
|
public:
|
|
Injector() : RNG_Base(nullptr, nullptr) {};
|
|
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;
|
|
this->energy_eV = energy_eV;
|
|
this->ions = ions;
|
|
};
|
|
|
|
int inject (std::vector<Particle> *particle_queue, const int &last_ID);
|
|
private:
|
|
double roll_FermiEnergy_eV();
|
|
double get_FermiDecaySpectrumDensity(const double &E_eV);
|
|
double get_FermiFunction(const double &Z, const double &E_eV);
|
|
};
|
|
|
|
inline int Injector::inject (std::vector<Particle> *particle_queue, const int &last_ID) {
|
|
vec3 loc_m = T2Population->roll_x_ms();
|
|
|
|
double E_eV;
|
|
switch(method) {
|
|
case 0: // Fermi
|
|
E_eV = roll_FermiEnergy_eV();
|
|
break;
|
|
case 1: //Delta
|
|
E_eV = energy_eV;
|
|
break;
|
|
case 2: //Maxwell Boltzman
|
|
E_eV = roll_MBEnergy(energy_eV/kb_eVK, me_eV, rngNormal);
|
|
break;
|
|
default:
|
|
throw MyException("Katrin::injectElectron: Invalid Injection Method.");
|
|
break;
|
|
}
|
|
vec3 v_ms = roll_uniform_direction(rngUni) * 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));
|
|
|
|
if (ions == 0) {
|
|
return 1;
|
|
} else {
|
|
vec3 vTI_ms = T2Population->roll_v_ms(loc_m);
|
|
particle_queue->push_back(PartFac.create_T2I(loc_m, vTI_ms, last_ID+2, last_ID+2));
|
|
return 2;
|
|
}
|
|
|
|
}
|
|
|
|
inline double Injector::roll_FermiEnergy_eV() {
|
|
double pmax,E_min_eV, E_max_eV, Ecan_eV,eta1,eta2;
|
|
pmax = 1.5e-28; // From Plotting EnergyDistributionBetaDecay
|
|
E_min_eV = scale_start;
|
|
E_max_eV = TritiumDecayEndpoint_eV;
|
|
do {
|
|
eta1 = rngUni->random();
|
|
eta2 = rngUni->random();
|
|
Ecan_eV = E_min_eV + eta1*(E_max_eV - E_min_eV);
|
|
} while(eta2*pmax > get_FermiDecaySpectrumDensity(Ecan_eV));
|
|
return Ecan_eV;
|
|
}
|
|
|
|
inline double Injector::get_FermiDecaySpectrumDensity(const double &E_eV) {
|
|
if (E_eV>TritiumDecayEndpoint_eV) {
|
|
return 0;
|
|
} else{
|
|
double p_eV = sqrt(E_eV*E_eV + 2 * E_eV * me_eV);
|
|
return BetaDecayConst*get_FermiFunction(2, E_eV)*p_eV*(E_eV+me_eV)*pow(TritiumDecayEndpoint_eV-E_eV,2);
|
|
}
|
|
}
|
|
|
|
inline double Injector::get_FermiFunction(const double &Z, const double &E_eV) {
|
|
double gamma = 1+ E_eV/me_eV;
|
|
double beta = sqrt(1 - pow(gamma,-2));
|
|
double eta =Z/beta/137.;
|
|
return 2*pi*eta/(1-exp(-2*pi*eta));
|
|
}
|
|
|
|
|
|
#endif /* injector_h */
|