Multiple Changes:
Conceptional Change, where terminated Particles were set to Energy = 0. Now Particles are just moved within mover and termination detects, position and starts Interaction only if particle remains in tank. Added function_container: Filled with anker points and get values corresponding to input by interpolation. 2D Interpolation needs improvement. CSV-Read in function needs error checks of input file. Changes in katrin class: Boris Push and Drift Approximation improved. Minor Renamings.
This commit is contained in:
@@ -34,9 +34,9 @@ double BED_Ionization::get_TCS(double T_eV) {
|
||||
if (T_eV<=B_eV) {
|
||||
return (0);
|
||||
} else {
|
||||
double t = calc_t(T_eV);
|
||||
double t = get_t(T_eV);
|
||||
double fac = S_m2/(t+u+1);
|
||||
double sum1 = calc_Dt(t)*log(t);
|
||||
double sum1 = get_Dt(t)*log(t);
|
||||
double sum2 = (2-Ni/N)*( (t-1)/t - log(t)/(t+1) );
|
||||
return(fac*(sum1 + sum2) );
|
||||
}
|
||||
@@ -56,24 +56,24 @@ double BED_Ionization::get_SDCS (double T_eV, double W_eV) {
|
||||
if ( (T_eV<=B_eV) ||(W_eV >= (T_eV-B_eV) ) ) {
|
||||
return (0);
|
||||
} else {
|
||||
double t = calc_t(T_eV);
|
||||
double w = calc_w(W_eV);
|
||||
double t = get_t(T_eV);
|
||||
double w = get_w(W_eV);
|
||||
double fac = S_m2/B_eV/(t+u+1);
|
||||
double sum1 = (Ni/N - 2)/(t+1) * (1/(w+1) + 1/(t-w));
|
||||
double sum2 = (2-Ni/N) * (pow(w+1,-2) + pow(t-w,-2));
|
||||
double sum3 = log(t)/(N*(w+1)) * calc_dfdw(w);
|
||||
double sum3 = log(t)/(N*(w+1)) * get_dfdw(w);
|
||||
return(fac*(sum1 + sum2 + sum3));
|
||||
}
|
||||
}
|
||||
|
||||
double BED_Ionization::calc_t(double T_eV) {
|
||||
double BED_Ionization::get_t(double T_eV) {
|
||||
return(T_eV/B_eV);
|
||||
}
|
||||
double BED_Ionization::calc_w(double W_eV) {
|
||||
double BED_Ionization::get_w(double W_eV) {
|
||||
return(W_eV/B_eV);
|
||||
}
|
||||
|
||||
double BED_Ionization::calc_dfdw(double w) {
|
||||
double BED_Ionization::get_dfdw(double w) {
|
||||
double y = 1/(w+1);
|
||||
double res = 0;
|
||||
for (int i=0;i<4;i++) {
|
||||
@@ -82,7 +82,7 @@ double BED_Ionization::calc_dfdw(double w) {
|
||||
return(res);
|
||||
}
|
||||
|
||||
double BED_Ionization::calc_Dt(double t) {
|
||||
double BED_Ionization::get_Dt(double t) {
|
||||
double yh = 2/(t+1);
|
||||
double res = 0;
|
||||
for (int i=0;i<4;i++) {
|
||||
|
||||
@@ -25,11 +25,11 @@ private:
|
||||
static const double N,Ni;
|
||||
static const double c[4];
|
||||
|
||||
double calc_t(double T);
|
||||
double calc_w(double W);
|
||||
double get_t(double T);
|
||||
double get_w(double W);
|
||||
|
||||
double calc_dfdw(double w);
|
||||
double calc_Dt(double t);
|
||||
double get_dfdw(double w);
|
||||
double get_Dt(double t);
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
double Electron::calc_SigmaTotal_m2(vec3 speedT2_ms) {
|
||||
vector<double> Sigmas = calc_SigmaVector_m2(speedT2_ms);
|
||||
double Electron::get_SigmaTotal_m2(vec3 speedT2_ms) {
|
||||
vector<double> Sigmas = get_SigmaVector_m2(speedT2_ms);
|
||||
double sigmaTot_m2 = 0;
|
||||
for (vector<double>::iterator SigmasIt = Sigmas.begin() ; SigmasIt != Sigmas.end(); SigmasIt++) {
|
||||
sigmaTot_m2 += *SigmasIt;
|
||||
@@ -22,10 +22,10 @@ double Electron::calc_SigmaTotal_m2(vec3 speedT2_ms) {
|
||||
return(sigmaTot_m2);
|
||||
}
|
||||
|
||||
vector<double> Electron::calc_SigmaVector_m2(vec3 speedT2_ms) {
|
||||
vector<double> Electron::get_SigmaVector_m2(vec3 speedT2_ms) {
|
||||
vector<double> Sigmas;
|
||||
if (Particle::elaOn == 1) {
|
||||
Sigmas.push_back(calc_elaSigma_m2(speedT2_ms));
|
||||
Sigmas.push_back(get_elaSigma_m2(speedT2_ms));
|
||||
} else {
|
||||
Sigmas.push_back(0.);
|
||||
}
|
||||
@@ -39,12 +39,8 @@ vector<double> Electron::calc_SigmaVector_m2(vec3 speedT2_ms) {
|
||||
}
|
||||
|
||||
int Electron::roll_Interaction(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni) {
|
||||
// Check Moved Outside
|
||||
if (getKinEnergy_eV()==0) {
|
||||
return(0);
|
||||
}
|
||||
vector<double> Sigmas = calc_SigmaVector_m2(speedT2_ms);
|
||||
double RandPoint = rngUni->random() * calc_SigmaTotal_m2(speedT2_ms);
|
||||
vector<double> Sigmas = get_SigmaVector_m2(speedT2_ms);
|
||||
double RandPoint = rngUni->random() * get_SigmaTotal_m2(speedT2_ms);
|
||||
double Sum = 0;
|
||||
|
||||
for (int i=0; i<Sigmas.size();i++ ) {
|
||||
@@ -53,9 +49,7 @@ int Electron::roll_Interaction(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni)
|
||||
return(i+1);
|
||||
}
|
||||
}
|
||||
|
||||
throw MyException("Interaction::roll_Interaction: Error in finding Interaction.");
|
||||
|
||||
throw MyException("Electron::roll_Interaction(): Error in finding Interaction.");
|
||||
}
|
||||
|
||||
|
||||
@@ -74,12 +68,12 @@ void Electron::do_elaScattering (vec3 speedT2_ms, ranlib::Uniform<double> *rngUn
|
||||
}
|
||||
|
||||
|
||||
double Electron::calc_elaSigma_m2(vec3 speedT2_ms) {
|
||||
double Electron::get_elaSigma_m2(vec3 speedT2_ms) {
|
||||
double SigmaEla_m2;
|
||||
vec3 speedLab_ms = v_ms - speedT2_ms;
|
||||
double betaLab = calc_vecAbs(speedLab_ms)/c_ms;
|
||||
//double EkinLab_eV = calc_Ekin_eV_from_speed(speedLab_ms, m_eV);
|
||||
double elaEta = calc_elaEta(speedLab_ms);
|
||||
double betaLab = get_vecAbs(speedLab_ms)/c_ms;
|
||||
//double EkinLab_eV = get_Ekin_eV_from_speed(speedLab_ms, m_eV);
|
||||
double elaEta = get_elaEta(speedLab_ms);
|
||||
double numerator = pi*ZT2*(ZT2+1)*re_m*re_m * (1-pow(betaLab,2));
|
||||
double denominator = elaEta * (elaEta+1)*pow(betaLab,4);
|
||||
SigmaEla_m2 = numerator/denominator;
|
||||
@@ -87,9 +81,9 @@ double Electron::calc_elaSigma_m2(vec3 speedT2_ms) {
|
||||
}
|
||||
|
||||
|
||||
double Electron::calc_elaEta(vec3 speedLab_ms) {
|
||||
double Ekin_eVLab_eV = calc_Ekin_eV_from_speed(calc_vecAbs(speedLab_ms), m_eV);
|
||||
double betaLab = calc_vecAbs(speedLab_ms)/c_ms;
|
||||
double Electron::get_elaEta(vec3 speedLab_ms) {
|
||||
double Ekin_eVLab_eV = get_Ekin_eV_from_speed(get_vecAbs(speedLab_ms), m_eV);
|
||||
double betaLab = get_vecAbs(speedLab_ms)/c_ms;
|
||||
double etac = (Ekin_eVLab_eV < 50e3)? 1.198 : 1.13+3.76*pow(ZT2/(137*betaLab),2);
|
||||
double elaTau = Ekin_eVLab_eV/m_eV;
|
||||
return (etac * 1.7e-5 * pow(ZT2,2./3.) /(elaTau*(elaTau+2) ));
|
||||
@@ -97,9 +91,9 @@ double Electron::calc_elaEta(vec3 speedLab_ms) {
|
||||
|
||||
double Electron::roll_elaTheta(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni) {
|
||||
vec3 speedLab_ms = v_ms - speedT2_ms;
|
||||
double betaLab = calc_vecAbs(speedLab_ms)/c_ms;
|
||||
double elaEta = calc_elaEta(speedLab_ms);
|
||||
double const1 = 2*pi/calc_elaSigma_m2(speedT2_ms)*ZT2*(ZT2+1)*re_m*re_m*(1- pow(betaLab,2) )* pow(betaLab,-4);
|
||||
double betaLab = get_vecAbs(speedLab_ms)/c_ms;
|
||||
double elaEta = get_elaEta(speedLab_ms);
|
||||
double const1 = 2*pi/get_elaSigma_m2(speedT2_ms)*ZT2*(ZT2+1)*re_m*re_m*(1- pow(betaLab,2) )* pow(betaLab,-4);
|
||||
double theta = acos( pow( rngUni->random()/const1-pow(2*elaEta,-1) , -1 ) +1+2*elaEta);
|
||||
return(theta);
|
||||
}
|
||||
@@ -109,9 +103,9 @@ void Electron::do_elaKinetics(vec3 speedT2_ms, double thetaLab, double phiLab) {
|
||||
// Following Landau Lifschitz I Chapter 4 Paragraph 17
|
||||
vec3 n0, speedLab_ms, v1New_ms, v2New_ms;
|
||||
speedLab_ms = v_ms - speedT2_ms;
|
||||
n0 = calc_Newdirection(speedLab_ms, thetaLab, phiLab);
|
||||
v1New_ms = (mT2_eV*calc_vecAbs(speedLab_ms)*n0 + m_eV*speedLab_ms)/(m_eV+mT2_eV) + speedT2_ms;
|
||||
//v2New_ms = (-1*mass_eV*calc_vecAbs(speedLab_ms)*n0 + mass_eV*speedLab_ms)/(mass_eV+mT2_eV()) + speedT2_ms;
|
||||
n0 = get_Newdirection(speedLab_ms, thetaLab, phiLab);
|
||||
v1New_ms = (mT2_eV*get_vecAbs(speedLab_ms)*n0 + m_eV*speedLab_ms)/(m_eV+mT2_eV) + speedT2_ms;
|
||||
//v2New_ms = (-1*mass_eV*get_vecAbs(speedLab_ms)*n0 + mass_eV*speedLab_ms)/(mass_eV+mT2_eV()) + speedT2_ms;
|
||||
v_ms = v1New_ms; // In "Real frame": both particles moving
|
||||
return;
|
||||
}
|
||||
@@ -123,19 +117,19 @@ Using BED-Model Kim and Rudd 1994
|
||||
|
||||
double Electron::get_ionSigma_m2(vec3 speedT2_ms) {
|
||||
vec3 speedLab_ms = v_ms - speedT2_ms;
|
||||
double T_eV = calc_Ekin_eV_from_speed(calc_vecAbs(speedLab_ms), m_eV);
|
||||
double T_eV = get_Ekin_eV_from_speed(get_vecAbs(speedLab_ms), m_eV);
|
||||
return (BED_Ionization::get_TCS(T_eV));
|
||||
}
|
||||
|
||||
Electron Electron::do_Ionization(vec3 speedT2_ms, int newId, ranlib::Uniform<double> *rngUni) {
|
||||
vec3 speedOffset_ms = speedT2_ms;
|
||||
vec3 speedLab_ms = v_ms - speedOffset_ms;
|
||||
double T_eV = calc_Ekin_eV_from_speed(calc_vecAbs(speedLab_ms), m_eV);
|
||||
double T_eV = get_Ekin_eV_from_speed(get_vecAbs(speedLab_ms), m_eV);
|
||||
|
||||
if (T_eV < EionT2_eV) { // Deviation, since Interaction-Process sample using v=0, but Interaction uses v!=0
|
||||
speedOffset_ms = 0;
|
||||
speedLab_ms = v_ms - speedOffset_ms;
|
||||
T_eV = calc_Ekin_eV_from_speed(calc_vecAbs(v_ms), m_eV);
|
||||
T_eV = get_Ekin_eV_from_speed(get_SpeedAbs_ms(), m_eV);
|
||||
}
|
||||
|
||||
if (T_eV < EionT2_eV) {
|
||||
@@ -151,18 +145,18 @@ Electron Electron::do_Ionization(vec3 speedT2_ms, int newId, ranlib::Uniform<dou
|
||||
double theta1 = roll_IonTheta1(T_eV, W_eV, rngUni);
|
||||
double theta2 = roll_IonTheta2(T_eV, W_eV, rngUni);
|
||||
|
||||
double v1Absnew_ms = calc_Speed_from_Ekin_eV(E1_eV, m_eV);
|
||||
double v2Absnew_ms = calc_Speed_from_Ekin_eV(W_eV, m_eV);
|
||||
double v1Absnew_ms = get_Speed_from_Ekin_eV(E1_eV, m_eV);
|
||||
double v2Absnew_ms = get_Speed_from_Ekin_eV(W_eV, m_eV);
|
||||
|
||||
vec3 P1newDir, P2newDir, v1New_ms, v2New_ms ;
|
||||
P1newDir = calc_Newdirection(v_ms, theta1, phi1);
|
||||
P2newDir = calc_Newdirection(v_ms, theta2, phi2);
|
||||
P1newDir = get_Newdirection(v_ms, theta1, phi1);
|
||||
P2newDir = get_Newdirection(v_ms, theta2, phi2);
|
||||
|
||||
v1New_ms = v1Absnew_ms*P1newDir + speedOffset_ms;
|
||||
v2New_ms = v2Absnew_ms*P2newDir + speedOffset_ms;
|
||||
|
||||
setSpeed_ms(v1New_ms);
|
||||
Electron eNew = Electron(x_m, v2New_ms, newId, getId());
|
||||
set_Speed_ms(v1New_ms);
|
||||
Electron eNew = Electron(x_m, v2New_ms, newId, get_Id());
|
||||
|
||||
// Update Ion matrix here
|
||||
return(eNew);
|
||||
|
||||
@@ -18,16 +18,16 @@ public:
|
||||
virtual ~Electron() {}
|
||||
Electron(vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum) : Particle::Particle(me_eV, 1 , loc_m, speed_ms, idnum, parentIdnum, electron) {};
|
||||
public:
|
||||
double calc_SigmaTotal_m2(vec3 speedT2_ms);
|
||||
std::vector<double> calc_SigmaVector_m2(vec3 speedT2_ms);
|
||||
double get_SigmaTotal_m2(vec3 speedT2_ms);
|
||||
std::vector<double> get_SigmaVector_m2(vec3 speedT2_ms);
|
||||
int roll_Interaction(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
|
||||
// Elastic Scattering
|
||||
public:
|
||||
void do_elaScattering (vec3 speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
double calc_elaSigma_m2(vec3 speedT2_ms);
|
||||
double get_elaSigma_m2(vec3 speedT2_ms);
|
||||
protected:
|
||||
double calc_elaEta(vec3 speedLab_ms);
|
||||
double get_elaEta(vec3 speedLab_ms);
|
||||
double roll_elaTheta(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
void do_elaKinetics(vec3 speedT2_ms, double theta, double phi);
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// function2D_container.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 15.03.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "function2D_container.hpp"
|
||||
|
||||
#include "myexeption.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
Func2D_Container::Func2D_Container() {
|
||||
|
||||
}
|
||||
|
||||
Func2D_Container::Func2D_Container(std::string loadFilePath) {
|
||||
readFromCSV(loadFilePath);
|
||||
}
|
||||
|
||||
double Func2D_Container::interpolate(double x, double y) {
|
||||
// Method might be improved, since first check for x bins, and afterwards check for y bins, so theoretically not choosing closest neighbour in terms of y but giving priority to x-closeness.
|
||||
// Avoid Mistakes by having complete set of y-data and uniform grid or improve code later.
|
||||
|
||||
|
||||
if (Map.empty()) {
|
||||
throw MyException("Func2D_Container: Container is empty.");
|
||||
}
|
||||
|
||||
if (Map.begin() == Map.lower_bound(x) ) {
|
||||
return (Map.begin()->second.interpolate(y));
|
||||
} else if (Map.end() == Map.lower_bound(x)){
|
||||
return ( (--Map.end())->second.interpolate(y) );
|
||||
}
|
||||
|
||||
dim2Map::iterator lowAnker_Itr = --Map.lower_bound(x);
|
||||
dim2Map::iterator upAnker_Itr = Map.lower_bound(x);
|
||||
double lowAnker_x = lowAnker_Itr->first;
|
||||
double lowAnker_fxy = lowAnker_Itr->second.interpolate(y);
|
||||
double upAnker_x = upAnker_Itr->first;
|
||||
double upAnker_fxy = upAnker_Itr->second.interpolate(y);
|
||||
|
||||
double res = lowAnker_fxy + (x-lowAnker_x)/(upAnker_x-lowAnker_x) * (upAnker_fxy-lowAnker_fxy);
|
||||
return (res);
|
||||
|
||||
}
|
||||
|
||||
void Func2D_Container::add_ankerpoint(double x, double y, double fxy) {
|
||||
if ( Map.find(x)==Map.end() ) {
|
||||
Func_Container Temp_Container;
|
||||
Temp_Container.add_ankerpoint(y, fxy);
|
||||
Map.insert(dim2Pair (x, Temp_Container));
|
||||
} else {
|
||||
try {
|
||||
Map.find(x)->second.add_ankerpoint(y,fxy);
|
||||
} catch (MyException& caught) {
|
||||
stringstream ss;
|
||||
ss<<"Func2D_Container::add_ankerpoint: Error from "<<caught.what();
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void Func2D_Container::readFromCSV(std::string loadFilePath) {
|
||||
// Very simple implementation, maybe improve in further version... stability towards file format, comments...
|
||||
double xTemp;
|
||||
double yTemp;
|
||||
double fxyTemp;
|
||||
|
||||
ifstream file(loadFilePath);
|
||||
|
||||
while ((file >> xTemp) && (file >> yTemp) && (file >> fxyTemp)) {
|
||||
add_ankerpoint(xTemp, yTemp, fxyTemp);
|
||||
}
|
||||
file.close();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// function2D_container.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 15.03.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef function2D_container_hpp
|
||||
#define function2D_container_hpp
|
||||
|
||||
#include "function_container.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
|
||||
|
||||
typedef std::map<double,Func_Container> dim2Map;
|
||||
typedef std::pair<double,Func_Container> dim2Pair;
|
||||
|
||||
class Func2D_Container {
|
||||
public:
|
||||
Func2D_Container();
|
||||
Func2D_Container(std::string loadFilePath);
|
||||
double interpolate(double x, double y);
|
||||
|
||||
void add_ankerpoint(double x, double y, double fxy);
|
||||
private:
|
||||
|
||||
|
||||
dim2Map Map;
|
||||
void readFromCSV(std::string loadFilePath);
|
||||
|
||||
} ;
|
||||
|
||||
#endif /* function2D_container_hpp */
|
||||
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// function_container.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 15.03.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "function_container.hpp"
|
||||
|
||||
#include "myexeption.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
Func_Container::Func_Container() {
|
||||
|
||||
}
|
||||
|
||||
Func_Container::Func_Container(std::string loadFilePath) {
|
||||
readFromCSV(loadFilePath);
|
||||
}
|
||||
|
||||
double Func_Container::interpolate(double x) {
|
||||
if (Map.empty()) {
|
||||
throw MyException("Func_Container: Container is empty.");
|
||||
}
|
||||
|
||||
if (Map.begin() == Map.lower_bound(x) ) {
|
||||
return (Map.begin()->second);
|
||||
} else if (Map.end() == Map.lower_bound(x)){
|
||||
return ( (--Map.end())->second );
|
||||
}
|
||||
|
||||
dim1Map::iterator lowAnker_Itr = --Map.lower_bound(x);
|
||||
dim1Map::iterator upAnker_Itr = Map.lower_bound(x);
|
||||
double lowAnker_x = lowAnker_Itr->first;
|
||||
double lowAnker_fx = lowAnker_Itr->second;
|
||||
double upAnker_x = upAnker_Itr->first;
|
||||
double upAnker_fx = upAnker_Itr->second;
|
||||
|
||||
double res = lowAnker_fx + (x-lowAnker_x)/(upAnker_x-lowAnker_x) * (upAnker_fx-lowAnker_fx);
|
||||
return (res);
|
||||
}
|
||||
|
||||
|
||||
void Func_Container::add_ankerpoint(double x, double fx) {
|
||||
if ( Map.find(x)!=Map.end() ) {
|
||||
stringstream ss;
|
||||
ss<<"Func_Container::add_ankerpoint: Key x="<<x<<" already exists.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
Map.insert(dim1Pair(x, fx));
|
||||
return;
|
||||
}
|
||||
|
||||
void Func_Container::readFromCSV(std::string loadFilePath) {
|
||||
// Very simple implementation, maybe improve in further version... stability towards file format, comments...
|
||||
double xTemp;
|
||||
double fxTemp;
|
||||
|
||||
ifstream file(loadFilePath);
|
||||
|
||||
while ((file >> xTemp) && (file >> fxTemp)) {
|
||||
add_ankerpoint(xTemp, fxTemp);
|
||||
}
|
||||
file.close();
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// function_container.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 15.03.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef function_container_hpp
|
||||
#define function_container_hpp
|
||||
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
|
||||
typedef std::map<double,double> dim1Map;
|
||||
typedef std::pair<double,double> dim1Pair;
|
||||
|
||||
class Func_Container {
|
||||
public:
|
||||
Func_Container();
|
||||
Func_Container(std::string loadFilePath);
|
||||
void add_ankerpoint(double x, double fx);
|
||||
double interpolate(double x);
|
||||
private:
|
||||
dim1Map Map;
|
||||
void readFromCSV(std::string loadFilePath);
|
||||
} ;
|
||||
|
||||
|
||||
#endif /* function_container_hpp */
|
||||
@@ -15,72 +15,74 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
double calc_vecAbs(vec3 vec) {
|
||||
double get_vecAbs(vec3 vec) {
|
||||
return( sqrt( pow(vec[0],2) + pow(vec[1],2) + pow(vec[2],2)) );
|
||||
}
|
||||
|
||||
double calc_Ekin_eV_from_speed(double Speed_ms, double mass_eV) {
|
||||
|
||||
|
||||
double get_Ekin_eV_from_speed(double Speed_ms, double mass_eV) {
|
||||
double beta = Speed_ms/Constants::c_ms;
|
||||
if (beta>=1) {
|
||||
stringstream ss;
|
||||
ss<<"calc_Ekin_eV_from_speed(): Input speed v="<<Speed_ms<<" m/s equal or exeeds speed of light.";
|
||||
ss<<"get_Ekin_eV_from_speed(): Input speed v="<<Speed_ms<<" m/s equal or exeeds speed of light.";
|
||||
throw MyException(ss.str());
|
||||
} else if (beta<0) {
|
||||
stringstream ss;
|
||||
ss<<"calc_Ekin_eV_from_speed(): Input speed v="<<Speed_ms<<" m/s is expected to be absolute value therfore >0.";
|
||||
ss<<"get_Ekin_eV_from_speed(): Input speed v="<<Speed_ms<<" m/s is expected to be absolute value therfore >0.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double gamma = calc_gamma_from_beta(beta);
|
||||
double gamma = get_gamma_from_beta(beta);
|
||||
return ( (gamma-1) * mass_eV );
|
||||
}
|
||||
|
||||
double calc_gamma_from_beta(double beta) {
|
||||
double get_gamma_from_beta(double beta) {
|
||||
if (beta>=1) {
|
||||
stringstream ss;
|
||||
ss<<"calc_gamma_from_beta(): Input beta ="<<beta<<" equal or exeeds 1.";
|
||||
ss<<"get_gamma_from_beta(): Input beta ="<<beta<<" equal or exeeds 1.";
|
||||
throw MyException(ss.str());
|
||||
} else if (beta<0) {
|
||||
stringstream ss;
|
||||
ss<<"calc_gamma_from_beta(): Input beta ="<<beta<<" negative.";
|
||||
ss<<"get_gamma_from_beta(): Input beta ="<<beta<<" negative.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
return( pow(1 - pow(beta,2),-0.5) ) ;
|
||||
}
|
||||
|
||||
double calc_Speed_from_Ekin_eV(double Ekin_eV, double mass_eV) {
|
||||
double get_Speed_from_Ekin_eV(double Ekin_eV, double mass_eV) {
|
||||
if (Ekin_eV<0) {
|
||||
stringstream ss;
|
||||
ss<<"calc_Speed_from_Ekin_eV(): Input Ekin_eV ="<<Ekin_eV<<" negative.";
|
||||
ss<<"get_Speed_from_Ekin_eV(): Input Ekin_eV ="<<Ekin_eV<<" negative.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
double gamma = calc_gamma_from_Ekin_eV(Ekin_eV, mass_eV);
|
||||
double beta = calc_beta_from_gamma(gamma);
|
||||
double gamma = get_gamma_from_Ekin_eV(Ekin_eV, mass_eV);
|
||||
double beta = get_beta_from_gamma(gamma);
|
||||
return(beta * Constants::c_ms);
|
||||
}
|
||||
|
||||
double calc_gamma_from_Ekin_eV(double Ekin_eV, double mass_eV) {
|
||||
double get_gamma_from_Ekin_eV(double Ekin_eV, double mass_eV) {
|
||||
if (Ekin_eV<0) {
|
||||
stringstream ss;
|
||||
ss<<"calc_gamma_from_Ekin_eV(): Input Ekin_eV ="<<Ekin_eV<<" negative.";
|
||||
ss<<"get_gamma_from_Ekin_eV(): Input Ekin_eV ="<<Ekin_eV<<" negative.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return (1. + Ekin_eV/mass_eV);
|
||||
}
|
||||
|
||||
double calc_beta_from_gamma(double gamma) {
|
||||
double get_beta_from_gamma(double gamma) {
|
||||
if (gamma<1) {
|
||||
stringstream ss;
|
||||
ss<<"calc_beta_from_gamma(): Input gamma ="<<gamma<<" smaller 1.";
|
||||
ss<<"get_beta_from_gamma(): Input gamma ="<<gamma<<" smaller 1.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return( sqrt(1 - pow(gamma,-2)) );
|
||||
}
|
||||
|
||||
vec3 calc_Newdirection(vec3 direction_old, double theta_change,double phi_change) {
|
||||
vec3 get_Newdirection(vec3 direction_old, double theta_change,double phi_change) {
|
||||
// Transformation of direction following Plante and Cucinotta
|
||||
double theta_old = acos(direction_old[2]/calc_vecAbs(direction_old));
|
||||
double theta_old = acos(direction_old[2]/get_vecAbs(direction_old));
|
||||
double phi_old = atan2(direction_old[1],direction_old[0]);
|
||||
|
||||
double A3 = sin(theta_change)*cos(phi_change);
|
||||
@@ -136,7 +138,7 @@ double roll_MBEnergy(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *rn
|
||||
}
|
||||
beta = sqrt(C*(sum));
|
||||
|
||||
return((calc_gamma_from_beta(beta)-1)*mass_eV);
|
||||
return((get_gamma_from_beta(beta)-1)*mass_eV);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,22 +12,23 @@
|
||||
|
||||
#include "constants.hpp"
|
||||
|
||||
#include "blitz/array.h"
|
||||
#include "blitz/tinyvec2.h"
|
||||
#include <blitz/array.h>
|
||||
#include <blitz/tinyvec2.h>
|
||||
#include <random/uniform.h>
|
||||
#include <random/normal.h>
|
||||
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
|
||||
|
||||
double calc_vecAbs(blitz::TinyVector<double,3> vec);
|
||||
double calc_Speed_from_Ekin_eV(double Ekin_eV, double mass_eV);
|
||||
double calc_gamma_from_Ekin_eV(double Ekin_eV, double mass_eV);
|
||||
double calc_beta_from_gamma(double gamma);
|
||||
double calc_Ekin_eV_from_speed(double Speed, double mass_eV);
|
||||
double calc_gamma_from_beta(double beta);
|
||||
double get_vecAbs(vec3 vec);
|
||||
|
||||
vec3 calc_Newdirection(vec3 oldDir, double theta,double phi);
|
||||
double get_Speed_from_Ekin_eV(double Ekin_eV, double mass_eV);
|
||||
double get_gamma_from_Ekin_eV(double Ekin_eV, double mass_eV);
|
||||
double get_beta_from_gamma(double gamma);
|
||||
double get_Ekin_eV_from_speed(double Speed, double mass_eV);
|
||||
double get_gamma_from_beta(double beta);
|
||||
|
||||
vec3 get_Newdirection(vec3 oldDir, double theta,double phi);
|
||||
|
||||
vec3 roll_uniform_direction(ranlib::Uniform<double> *rngUni);
|
||||
double roll_MBEnergy(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *rngNormal);
|
||||
|
||||
+125
-60
@@ -34,8 +34,8 @@ vec3 Katrin::getElField_Vm(vec3 loc_m) {
|
||||
double Katrin::getTritiumDensity_m3(vec3 loc_m) {
|
||||
double mid_m = wgtsLength_m/2;
|
||||
double zProjection_m = (loc_m[2] < mid_m) ? loc_m[2] : wgtsLength_m - loc_m[2] ;
|
||||
double reductcalc_ionFactor = zProjection_m/mid_m;
|
||||
return(reductcalc_ionFactor * wgtsT2Density_m3);
|
||||
double reductget_ionFactor = zProjection_m/mid_m;
|
||||
return(reductget_ionFactor * wgtsT2Density_m3);
|
||||
}
|
||||
|
||||
vec3 Katrin::getTotSpeedT2_ms(vec3 loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
||||
@@ -51,7 +51,7 @@ vec3 Katrin::getFlowSpeedT2_ms(vec3 loc_m) {
|
||||
}
|
||||
|
||||
vec3 Katrin::getTempSpeedT2_ms(vec3 loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
||||
double tempOffsetABS_ms = calc_Speed_from_Ekin_eV(roll_MBEnergy(wgtsTemp_K,mT2_eV,rngNormal), mT2_eV);
|
||||
double tempOffsetABS_ms = get_Speed_from_Ekin_eV(roll_MBEnergy(wgtsTemp_K,mT2_eV,rngNormal), mT2_eV);
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni)*tempOffsetABS_ms;
|
||||
return(speed_ms);
|
||||
}
|
||||
@@ -77,10 +77,10 @@ Electron Katrin::injectElectron(int newId, ranlib::Uniform<double> *rngUni, ranl
|
||||
Ekin_eV = roll_MBEnergy(MBTemp_K,me_eV, rngNormal);
|
||||
break;
|
||||
default:
|
||||
throw MyException("Simulation::injectElectron: Invalid Injection Method.");
|
||||
throw MyException("Katrin::injectElectron: Invalid Injection Method.");
|
||||
break;
|
||||
}
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni) * calc_Speed_from_Ekin_eV(Ekin_eV,me_eV);
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni) * get_Speed_from_Ekin_eV(Ekin_eV,me_eV);
|
||||
return (Electron(loc_m, speed_ms,newId,newId));
|
||||
}
|
||||
|
||||
@@ -94,115 +94,180 @@ double Katrin::roll_FermiEnergy_eV(ranlib::Uniform<double> *rngUni) {
|
||||
eta1 = rngUni->random();
|
||||
eta2 = rngUni->random();
|
||||
Ecan_eV = Emin_eV + eta1*(Emax_eV - Emin_eV);
|
||||
} while(eta2*pmax > calc_FermiDecaySpectrumDensity(Ecan_eV));
|
||||
} while(eta2*pmax > get_FermiDecaySpectrumDensity(Ecan_eV));
|
||||
return(Ecan_eV);
|
||||
}
|
||||
|
||||
double Katrin::calc_FermiDecaySpectrumDensity(double Ekin_eV) {
|
||||
double Katrin::get_FermiDecaySpectrumDensity(double Ekin_eV) {
|
||||
if (Ekin_eV>TritiumDecayEndpoint_eV) {
|
||||
return (0.);
|
||||
} else{
|
||||
double p_eV = sqrt(Ekin_eV*Ekin_eV + 2 * Ekin_eV * me_eV);
|
||||
return( BetaDecayConst * calc_FermiFunction(2, Ekin_eV) * p_eV*(Ekin_eV+me_eV)*pow(TritiumDecayEndpoint_eV-Ekin_eV,2) );
|
||||
return( BetaDecayConst * get_FermiFunction(2, Ekin_eV) * p_eV*(Ekin_eV+me_eV)*pow(TritiumDecayEndpoint_eV-Ekin_eV,2) );
|
||||
}
|
||||
}
|
||||
|
||||
double Katrin::calc_FermiFunction(double Z, double Ekin_eV) {
|
||||
double Katrin::get_FermiFunction(double Z, double Ekin_eV) {
|
||||
double gamma = 1+ Ekin_eV/me_eV;
|
||||
double beta = sqrt(1 - pow(gamma,-2));
|
||||
double eta =Z/beta/137.;
|
||||
return( 2*pi*eta/(1-exp(-2*pi*eta)) );
|
||||
}
|
||||
|
||||
// Move Electrons
|
||||
void Katrin::do_BorisPush(Electron *moveElectron) {
|
||||
double MFP_m = get_MFP_m(moveElectron);
|
||||
vec3 oldLoc_m = moveElectron->getLoc_m();
|
||||
vec3 E_Vm, B_T;
|
||||
// Move Electrons and Log
|
||||
void Katrin::do_BorisPushMovement(Electron *moveElectron, double distance_m, Logger *Log) {
|
||||
// Rework, with Logging and Reflection at wall
|
||||
vec3 loc_m;
|
||||
|
||||
double distance = 0.;
|
||||
while (distance < MFP_m) {
|
||||
E_Vm = getElField_Vm(oldLoc_m);
|
||||
B_T = getMagField_T(oldLoc_m);
|
||||
distance += moveElectron->borisFly_m(E_Vm , B_T , dt_s);
|
||||
if (movedOutside(moveElectron->getLoc_m())) {
|
||||
moveElectron->setSpeed_ms(vec3(0,0,0));
|
||||
double oldzDir = moveElectron->get_Speed_ms()[2] < 0 ? -1 : 1;
|
||||
vec3 oldLoc_m = moveElectron->get_Location_m();
|
||||
|
||||
double traveledDistance_m = 0;
|
||||
|
||||
while (traveledDistance_m < distance_m) {
|
||||
loc_m = moveElectron->get_Location_m();
|
||||
|
||||
traveledDistance_m += moveElectron->do_BorisStep_m(getElField_Vm(loc_m) , getMagField_T(loc_m) , dt_s);
|
||||
|
||||
doBoris_WallInteraction(moveElectron);
|
||||
|
||||
if (check_WallTermination(*moveElectron) == 0) {
|
||||
Log->log_Electron(moveElectron, oldLoc_m);
|
||||
return;
|
||||
}
|
||||
doBoris_LogzDirChange(moveElectron, &oldzDir, &oldLoc_m, Log);
|
||||
|
||||
}
|
||||
Log->log_Electron(moveElectron, oldLoc_m);
|
||||
return;
|
||||
}
|
||||
|
||||
void Katrin::doBoris_WallInteraction(Electron *moveElectron) {
|
||||
vec3 loc_m = moveElectron->get_Location_m();
|
||||
double r_m = moveElectron->get_Radius_m();
|
||||
if (loc_m[2]<=0) { // Rear Wall Termination
|
||||
vec3 newLoc_m = moveElectron->get_Location_m();
|
||||
newLoc_m[2] = 0;
|
||||
moveElectron->set_Location_m(newLoc_m);
|
||||
} else if (r_m>=wgtsRadius_m) { // WGTS Wall Termination
|
||||
vec3 newLoc_m = moveElectron->get_Location_m();
|
||||
double z_m = newLoc_m[2];
|
||||
newLoc_m[2] = 0;
|
||||
newLoc_m = (wgtsRadius_m * 1.01)/get_vecAbs(newLoc_m) * newLoc_m; //1.01 to move Electron slightly out of WGTS
|
||||
newLoc_m[2] = z_m;
|
||||
} else if (loc_m[2]>=wgtsLength_m) { // Spectrometer Reflection
|
||||
moveElectron->set_Speed_ms( -1*(moveElectron->get_Speed_ms()) );
|
||||
}
|
||||
}
|
||||
|
||||
void Katrin::doBoris_LogzDirChange(Electron *moveElectron, double *oldzDir, vec3 *oldLoc_m, Logger *Log) {
|
||||
double zDir = moveElectron->get_Speed_ms()[2] < 0 ? -1 : 1;
|
||||
if (*oldzDir != zDir) {
|
||||
Log->log_Electron(moveElectron, *oldLoc_m);
|
||||
*oldzDir = zDir;
|
||||
*oldLoc_m = moveElectron->get_Location_m();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void Katrin::do_DriftApproximation(Electron *moveElectron) {
|
||||
void Katrin::do_DriftApproximationMovement(Electron *moveElectron, double distance_m, Logger *Log) {
|
||||
// Drift Approximation: Assume constant B and only movement out in z=0, z=wgtsLength_m...
|
||||
double MFP_m = get_MFP_m(moveElectron);
|
||||
vec3 oldLoc_m = moveElectron->getLoc_m();
|
||||
vec3 oldLoc_m = moveElectron->get_Location_m();
|
||||
vec3 newLoc_m = oldLoc_m;
|
||||
vec3 v_ms = moveElectron->getSpeed_ms();
|
||||
|
||||
double znew_m = getDrift_znew_m(MFP_m, oldLoc_m[2], v_ms);
|
||||
|
||||
double znew_m = getDrift_znew_m(distance_m, moveElectron);
|
||||
doDrift_WallInteraction(&oldLoc_m, &znew_m, moveElectron, Log);
|
||||
newLoc_m[2] = znew_m;
|
||||
moveElectron->setLoc_m(newLoc_m);
|
||||
if (movedOutside(newLoc_m)) {
|
||||
moveElectron->setSpeed_ms(vec3(0,0,0));
|
||||
}
|
||||
|
||||
moveElectron->set_Location_m(newLoc_m);
|
||||
Log->log_Electron(moveElectron, oldLoc_m);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
double Katrin::getDrift_znew_m(double MFP_m, double zold_m, vec3 v_ms) {
|
||||
double vAbs_ms = calc_vecAbs(v_ms);
|
||||
double vDir = v_ms[2] < 0 ? -1 : 1;
|
||||
double Katrin::getDrift_znew_m(double distance_m, Electron *moveElectron) {
|
||||
double zold_m = moveElectron->get_Location_m()[2];
|
||||
|
||||
vec3 vPar_ms = vec3(0,0,0);
|
||||
vPar_ms[2] = v_ms[2];
|
||||
double vParAbs_ms = calc_vecAbs(vPar_ms);
|
||||
vec3 v_ms = moveElectron->get_Speed_ms();
|
||||
double vTotAbs_ms = get_vecAbs(v_ms);
|
||||
double vForwardAbs_ms = get_vecAbs(vec3(0,0,v_ms[2]));
|
||||
double zDir = v_ms[2] < 0 ? -1 : 1;
|
||||
|
||||
double deltaZ_m = vDir*vParAbs_ms/vAbs_ms * MFP_m;
|
||||
|
||||
double znew_m = zold_m + deltaZ_m;
|
||||
|
||||
if (znew_m < 0) {
|
||||
znew_m = 0;
|
||||
} else if (znew_m > wgtsLength_m) {
|
||||
znew_m = 2*wgtsLength_m - znew_m;
|
||||
}
|
||||
double znew_m = zold_m + zDir*vForwardAbs_ms/vTotAbs_ms * distance_m;
|
||||
return (znew_m);
|
||||
}
|
||||
|
||||
void Katrin::doDrift_WallInteraction(vec3 *oldLoc_m, double *znew_m, Electron *moveElectron, Logger *Log) {
|
||||
if (*znew_m >= wgtsLength_m) { // Moveing into Spectrometer and reversing Speed.
|
||||
vec3 reverseLoc_m = *oldLoc_m;
|
||||
reverseLoc_m[2] = wgtsLength_m;
|
||||
moveElectron->set_Location_m(reverseLoc_m);
|
||||
|
||||
Log->log_Electron(moveElectron, *oldLoc_m);
|
||||
|
||||
*oldLoc_m = reverseLoc_m;
|
||||
*znew_m = 2*wgtsLength_m - *znew_m;
|
||||
|
||||
moveElectron->set_Speed_ms( -1*(moveElectron->get_Speed_ms()) );
|
||||
}
|
||||
if (*znew_m <= 0) {
|
||||
*znew_m = 0;
|
||||
}
|
||||
}
|
||||
|
||||
double Katrin::get_MFP_m(Electron *moveElectron) {
|
||||
//Rework for inserting vector of Interactions
|
||||
vec3 loc_m, speedT2_ms;
|
||||
double sigmaTot_m2, density_m3, MFP_m;
|
||||
loc_m = moveElectron->getLoc_m();
|
||||
loc_m = moveElectron->get_Location_m();
|
||||
speedT2_ms = getFlowSpeedT2_ms(loc_m);
|
||||
|
||||
sigmaTot_m2 = moveElectron->calc_SigmaTotal_m2(speedT2_ms);
|
||||
sigmaTot_m2 = moveElectron->get_SigmaTotal_m2(speedT2_ms);
|
||||
density_m3 = getTritiumDensity_m3(loc_m);
|
||||
MFP_m = 1/(density_m3 * sigmaTot_m2);
|
||||
return(MFP_m);
|
||||
}
|
||||
|
||||
bool Katrin::movedOutside(vec3 loc_m) {
|
||||
double r_m = sqrt( pow(loc_m(0),2) + pow(loc_m(1),2) );
|
||||
return ( ! (loc_m[2]>0 && loc_m[2]<=wgtsLength_m && r_m<wgtsRadius_m ) );
|
||||
// Terminate Electrons
|
||||
bool Katrin::check_Termination(Electron checkElectron) {
|
||||
return ( check_EnergyTermination(checkElectron) || check_WallTermination(checkElectron) );
|
||||
}
|
||||
|
||||
// Terminate Electrons
|
||||
bool Katrin::get_Terminated(Electron termElectron) {
|
||||
double Ekin_eV, ETemp_eV;
|
||||
Ekin_eV = termElectron.getKinEnergy_eV();
|
||||
ETemp_eV = kb_eVK*wgtsTemp_K;
|
||||
bool Katrin::check_EnergyTermination(double Ekin_eV) {
|
||||
double ETemp_eV = kb_eVK*wgtsTemp_K;
|
||||
if (ETemp_eV<0) {
|
||||
throw MyException("Simulation::checkTermination: ETemp_eV < 0.");
|
||||
throw MyException("Katrin::checkTermination: ETemp_eV < 0.");
|
||||
}
|
||||
|
||||
if (Ekin_eV<=cutoffEnergy_eV) {
|
||||
return(true);
|
||||
return (true);
|
||||
}
|
||||
return(false);
|
||||
return (false);
|
||||
}
|
||||
|
||||
bool Katrin::check_EnergyTermination(Electron checkElectron) {
|
||||
double Ekin_eV = checkElectron.get_EKin_eV();
|
||||
return (check_EnergyTermination(Ekin_eV));
|
||||
}
|
||||
|
||||
bool Katrin::check_WallTermination(vec3 loc_m) {
|
||||
double z_m = loc_m[2];
|
||||
double r_m = sqrt( pow(loc_m[0],2) + pow(loc_m[1],2) );
|
||||
if (z_m <=0) {
|
||||
return (true);
|
||||
} else if (r_m >= wgtsRadius_m) {
|
||||
return (true);
|
||||
} else {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
|
||||
bool Katrin::check_WallTermination(Electron checkElectron) {
|
||||
vec3 loc_m = checkElectron.get_Location_m();
|
||||
return (check_WallTermination(loc_m));
|
||||
}
|
||||
|
||||
|
||||
void Katrin::set_cutoffEnergy_eV() {
|
||||
if (cutoffMode==0) {
|
||||
cutoffEnergy_eV = cutoffEnergySet_eV;
|
||||
@@ -210,7 +275,7 @@ void Katrin::set_cutoffEnergy_eV() {
|
||||
cutoffEnergy_eV = kb_eVK*wgtsTemp_K*cutoffFactor;
|
||||
} else {
|
||||
stringstream ss;
|
||||
ss<<"Mover::Mover(): cutoffMode= "<<cutoffMode<<" not defined.";
|
||||
ss<<"Katrin::set_cutoffEnergy_eV(): cutoffMode= "<<cutoffMode<<" not defined.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "parameter.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "electron.hpp"
|
||||
|
||||
#include "blitz/tinyvec2.h"
|
||||
@@ -36,21 +37,27 @@ public:
|
||||
Electron injectElectron(int newId, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
||||
private:
|
||||
double roll_FermiEnergy_eV(ranlib::Uniform<double> *rngUni);
|
||||
double calc_FermiDecaySpectrumDensity(double Ekin_eV);
|
||||
double calc_FermiFunction(double Z, double Ekin_eV);
|
||||
double get_FermiDecaySpectrumDensity(double Ekin_eV);
|
||||
double get_FermiFunction(double Z, double Ekin_eV);
|
||||
|
||||
// Move Electrons
|
||||
public:
|
||||
void do_BorisPush(Electron *moveElectron);
|
||||
void do_DriftApproximation(Electron *moveElectron);
|
||||
private:
|
||||
double getDrift_znew_m(double MFP_m, double zold_m, vec3 v_ms);
|
||||
bool movedOutside(blitz::TinyVector<double,3> loc_m);
|
||||
double get_MFP_m(Electron *moveElectron);
|
||||
void do_BorisPushMovement(Electron *moveElectron, double distance_m, Logger *Log);
|
||||
void do_DriftApproximationMovement(Electron *moveElectron, double distance_m, Logger *Log);
|
||||
private:
|
||||
double getDrift_znew_m(double MFP_m, Electron *moveElectron);
|
||||
void doDrift_WallInteraction(vec3 *oldLoc_m, double *znew_m, Electron *moveElectron, Logger *Log);
|
||||
void doBoris_WallInteraction(Electron *moveElectron);
|
||||
void doBoris_LogzDirChange(Electron *moveElectron, double *oldzDir, vec3 *oldLoc_m, Logger *Log);
|
||||
|
||||
// Terminate Electrons
|
||||
public:
|
||||
bool get_Terminated(Electron termElectron);
|
||||
bool check_Termination(Electron checkElectron);
|
||||
bool check_EnergyTermination(double Ekin_eV);
|
||||
bool check_EnergyTermination(Electron checkElectron);
|
||||
bool check_WallTermination(vec3 loc_m);
|
||||
bool check_WallTermination(Electron checkElectron);
|
||||
private:
|
||||
double cutoffEnergy_eV;
|
||||
void set_cutoffEnergy_eV();
|
||||
|
||||
@@ -37,7 +37,7 @@ void Logger::log_Electron(Electron *logElectron, blitz::TinyVector<double,3> old
|
||||
outStream[0]<<*logElectron<<endl;
|
||||
} else {
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = logElectron->getLoc_m()[2];
|
||||
double znew = logElectron->get_Location_m()[2];
|
||||
double zmin = min(zold,znew);
|
||||
double zmax = max(zold,znew);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ using namespace std;
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
clock_t start = clock();
|
||||
|
||||
/*
|
||||
try {
|
||||
Simulation Sim;
|
||||
Sim.doit();
|
||||
@@ -23,6 +23,8 @@ int main(int argc, const char * argv[]) {
|
||||
cout<<caught.what()<<endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
*/
|
||||
Simulation Sim;
|
||||
Sim.doit();
|
||||
cout<<"Duration: "<< ( clock() - start ) / (double) CLOCKS_PER_SEC <<'\n';
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ using namespace std;
|
||||
Parameter::Parameter() {
|
||||
// Simulation Specs
|
||||
|
||||
seed = (int)getValue("seed");
|
||||
seed = (int)getValue("seed");
|
||||
numTotalElectrons = (long int)getValue("numTotalElectrons");
|
||||
dt_s = getValue("dt_s");
|
||||
injectionMethod = (int)getValue("injectionMethod");
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
|
||||
protected:
|
||||
//Simulation Specs
|
||||
int seed;
|
||||
int seed ;
|
||||
long int numTotalElectrons;
|
||||
double dt_s;
|
||||
int injectionMethod; // 0 = Beta Decay, 1 = Delta, 2 = Maxwell Boltzmann
|
||||
|
||||
@@ -74,17 +74,17 @@ Particle::Particle(double mass_eV, double charge_e,vec3 loc_m, vec3 speed_ms, do
|
||||
s = spec;
|
||||
}
|
||||
|
||||
double Particle::borisFly_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s) {
|
||||
double Particle::do_BorisStep_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s) {
|
||||
double distance_m;
|
||||
x_m += dt_s/2 * v_ms;
|
||||
distance_m = dt_s/2 * getSpeedAbs_ms();
|
||||
this->changeSpeedBoris(E_Vm , B_T , dt_s);
|
||||
distance_m = dt_s/2 * get_SpeedAbs_ms();
|
||||
this->doBoris_SpeedChange(E_Vm , B_T , dt_s);
|
||||
x_m += dt_s/2 * v_ms;
|
||||
distance_m += dt_s/2 * getSpeedAbs_ms();
|
||||
distance_m += dt_s/2 * get_SpeedAbs_ms();
|
||||
return(distance_m);
|
||||
}
|
||||
|
||||
void Particle::changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s) {
|
||||
void Particle::doBoris_SpeedChange(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s) {
|
||||
blitz::TinyVector<double, 3> vMinus_ms, vPlus_ms, vPrime_ms, t, s;
|
||||
double q_C = -1*Z * e_C;
|
||||
double m_kg = m_eV*e_C/c_ms/c_ms;
|
||||
|
||||
@@ -38,28 +38,28 @@ protected:
|
||||
|
||||
public:
|
||||
// Get Properties Methods
|
||||
double getMass_eV() { return(m_eV); }
|
||||
double getCharge_e() { return(Z); }
|
||||
vec3 getLoc_m() { return(x_m); }
|
||||
vec3 getSpeed_ms() { return(v_ms); }
|
||||
species getSpecies() {return(s); }
|
||||
double getId() { return(Id); }
|
||||
double getParentId() { return(parentId); }
|
||||
double get_Mass_eV() { return(m_eV); }
|
||||
double get_Charge_e() { return(Z); }
|
||||
vec3 get_Location_m() { return(x_m); }
|
||||
vec3 get_Speed_ms() { return(v_ms); }
|
||||
species get_Species() {return(s); }
|
||||
double get_Id() { return(Id); }
|
||||
double get_ParentId() { return(parentId); }
|
||||
|
||||
// Get Properties
|
||||
double getRadius_m() { return ( sqrt( pow(x_m[0],2) + pow(x_m[1],2) ) ); }
|
||||
double getSpeedAbs_ms() { return ( calc_vecAbs(v_ms) ); }
|
||||
double getKinEnergy_eV() { return ( calc_Ekin_eV_from_speed(getSpeedAbs_ms(), m_eV) ); }
|
||||
double get_Radius_m() { return ( sqrt( pow(x_m[0],2) + pow(x_m[1],2) ) ); }
|
||||
double get_SpeedAbs_ms() { return ( get_vecAbs(v_ms) ); }
|
||||
double get_EKin_eV() { return ( get_Ekin_eV_from_speed(get_SpeedAbs_ms(), m_eV) ); }
|
||||
|
||||
// Set Properties Methods
|
||||
void setLoc_m(blitz::TinyVector<double, 3> xnew_m) {x_m = xnew_m; };
|
||||
void setSpeed_ms(blitz::TinyVector<double, 3> vnew_ms) {v_ms = vnew_ms; };
|
||||
void set_Location_m(blitz::TinyVector<double, 3> xnew_m) {x_m = xnew_m; };
|
||||
void set_Speed_ms(blitz::TinyVector<double, 3> vnew_ms) {v_ms = vnew_ms; };
|
||||
|
||||
//Boris Push: Propagate Flight for one timestep dt_s in E_Vm and B_T and returns distance.
|
||||
public:
|
||||
double borisFly_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s);
|
||||
double do_BorisStep_m(blitz::TinyVector<double, 3> E_Vm , blitz::TinyVector<double, 3> B_T , double dt_s);
|
||||
protected:
|
||||
void changeSpeedBoris(blitz::TinyVector<double, 3> E_Vm,blitz::TinyVector<double, 3> B_T , double dt_s);
|
||||
void doBoris_SpeedChange(blitz::TinyVector<double, 3> E_Vm,blitz::TinyVector<double, 3> B_T , double dt_s);
|
||||
|
||||
public:
|
||||
friend std::ostream& operator<<(std::ostream& os, const Particle& partOut);
|
||||
|
||||
@@ -32,12 +32,11 @@ void Simulation::doit() {
|
||||
}
|
||||
|
||||
status_updater();
|
||||
oldLoc_m = electronQue.front().getLoc_m();
|
||||
move_electron(&electronQue.front());
|
||||
Log.log_Electron(&electronQue.front(), oldLoc_m);
|
||||
do_interaction(&electronQue.front());
|
||||
|
||||
if (Kat.get_Terminated (electronQue.front())) {
|
||||
move_electron(&electronQue.front(), &Log);
|
||||
if (!Kat.check_EnergyTermination (electronQue.front()) ) {
|
||||
do_interaction(&electronQue.front());
|
||||
}
|
||||
if (Kat.check_EnergyTermination (electronQue.front())) {
|
||||
electronQue.pop_front();
|
||||
}
|
||||
}
|
||||
@@ -69,11 +68,12 @@ void Simulation::status_updater() {
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::move_electron(Electron *moveElectron) {
|
||||
void Simulation::move_electron(Electron *moveElectron, Logger *Log) {
|
||||
double MFP_m = Kat.get_MFP_m(&electronQue.front());
|
||||
if (propagationMethod==0) {
|
||||
Kat.do_DriftApproximation(moveElectron);
|
||||
Kat.do_DriftApproximationMovement(moveElectron, MFP_m, Log);
|
||||
} else if (propagationMethod==1) {
|
||||
Kat.do_BorisPush(moveElectron); // If moved outside set v = 0,0,0;
|
||||
Kat.do_BorisPushMovement(moveElectron, MFP_m, Log); // If moved outside set v = 0,0,0;
|
||||
} else {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::move_electron: propagationMethod="<<propagationMethod<<" not valid.";
|
||||
@@ -82,11 +82,14 @@ void Simulation::move_electron(Electron *moveElectron) {
|
||||
}
|
||||
|
||||
void Simulation::do_interaction(Electron *interactElectron) {
|
||||
vec3 newLoc_m = electronQue.front().getLoc_m();
|
||||
vec3 newLoc_m = electronQue.front().get_Location_m();
|
||||
if (Kat.check_Termination(*interactElectron)) {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::do_interaction: Particle already terminated.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
int process = interactElectron->roll_Interaction(Kat.getFlowSpeedT2_ms(newLoc_m),&rngUni);
|
||||
switch ( process ) {
|
||||
case 0: //Moved Outside
|
||||
break;
|
||||
switch (process) {
|
||||
case 1: // Elastic Scattering
|
||||
interactElectron->do_elaScattering(Kat.getTotSpeedT2_ms(newLoc_m, &rngUni, &rngNormal) , &rngUni);
|
||||
break;
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
|
||||
private:
|
||||
void status_updater();
|
||||
void move_electron(Electron *moveElectron);
|
||||
void move_electron(Electron *moveElectron, Logger *Log);
|
||||
void do_interaction(Electron *interactElectron);
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// main.cpp
|
||||
// test_enviroment
|
||||
//
|
||||
// Created by Christian Reiling on 13.03.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include "function_container.hpp"
|
||||
#include "function2D_container.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user