Major changes:
- Moved to array operations for main loops. - Changed to setting pointers to operator only once before loop. - Changed Population Containers - Added Recombination - Added Inelastic Scattering Kinematics - Reworked Elastic Scattering Cross Section - Reworked Elastic Scattering Kinematics - Reworked organisation of different particle species and corresponding operators
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// average_container.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 10.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef average_container_h
|
||||
#define average_container_h
|
||||
|
||||
|
||||
#include "edge_container.h"
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
class Average_Container : public Base_Container<T_Map> {
|
||||
public:
|
||||
Average_Container() : Base_Container<T_Map>() {}
|
||||
Average_Container(std::string load_path) : Base_Container<T_Map>(load_path) {}
|
||||
Average_Container(const Edge_Container<T_Map> &edgeContainer) {calcMap(edgeContainer);};
|
||||
|
||||
public:
|
||||
void calcMap(const Edge_Container<T_Map> &edgeContainer);
|
||||
private:
|
||||
void rec_calcMap(const double &subMap, std::deque<double> Points);
|
||||
template <typename T> void rec_calcMap(const T &subMapm, std::deque<double> Points);
|
||||
|
||||
public:
|
||||
double get_value(std::deque<double> point);
|
||||
};
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
void Average_Container<T_Map>::calcMap(const Edge_Container<T_Map> &edgeContainer) {
|
||||
T_Map edgeMap = edgeContainer.getMap();
|
||||
if (edgeMap.empty()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Average_Container::calcMap: Input Edge_Container empty.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
Base_Container<T_Map>::Map.clear();
|
||||
std::deque<double> Points;
|
||||
rec_calcMap(edgeMap, Points);
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
void Average_Container<T_Map>::rec_calcMap(const double &subMap, std::deque<double> Points) {
|
||||
Points.push_back(subMap);
|
||||
Base_Container<T_Map>::addPoint(Points);
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
template <typename T>
|
||||
void Average_Container<T_Map>::rec_calcMap(const T &subMap, std::deque<double> Points) {
|
||||
double curVal, nextVal, avgVal;
|
||||
typename T::const_iterator curItr, nextItr;
|
||||
for (nextItr = ++(subMap.cbegin()); nextItr!= subMap.cend(); nextItr++) {
|
||||
curItr = nextItr;
|
||||
--curItr;
|
||||
curVal = curItr->first;
|
||||
nextVal = nextItr->first;
|
||||
avgVal = curVal + (nextVal-curVal)/2;
|
||||
Points.push_back(avgVal);
|
||||
rec_calcMap(curItr->second, Points);
|
||||
Points.pop_back();
|
||||
}
|
||||
// insert last point as overflow value
|
||||
curItr = (--subMap.cend());
|
||||
Points.push_back(curItr->first);
|
||||
rec_calcMap(curItr->second, Points);
|
||||
}
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
double Average_Container<T_Map>::get_value(std::deque <double> Point) {
|
||||
Base_Container<T_Map>::checkEmpty();
|
||||
if (Base_Container<T_Map>::Dim != Point.size()) {
|
||||
std::stringstream ss;
|
||||
ss<<"EdgeBase_Container::interpolate: deque point dimension missmatch.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return (Base_Container<T_Map>::get_value(Point, Lower_bound_Over));
|
||||
}
|
||||
|
||||
#endif /* average_container_h */
|
||||
@@ -0,0 +1,328 @@
|
||||
//
|
||||
// base_container.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 10.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef base_container_h
|
||||
#define base_container_h
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <deque>
|
||||
#include "blitz/tinyvec2.h"
|
||||
#include "blitz/array.h"
|
||||
|
||||
#include "error_types.h"
|
||||
#include "read_system.h"
|
||||
#include "constants.h"
|
||||
|
||||
typedef std::deque<double> ddeque;
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
typedef std::map<double,double> dim1Map;
|
||||
typedef std::map<double,dim1Map> dim2Map;
|
||||
typedef std::map<double,dim2Map> dim3Map;
|
||||
typedef std::map<double,dim3Map> dim4Map;
|
||||
|
||||
enum searchStyle {Find, Lower_bound, Lower_bound_Over};
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
class Base_Container {
|
||||
protected:
|
||||
T_Map Map;
|
||||
int Dim;
|
||||
|
||||
public:
|
||||
Base_Container() {
|
||||
Dim = calc_Dim<T_Map>();
|
||||
}
|
||||
Base_Container(std::string load_path) {
|
||||
Dim = calc_Dim<T_Map>();
|
||||
importFromCSV(load_path);
|
||||
}
|
||||
|
||||
protected:
|
||||
template <typename T> double calc_Dim();
|
||||
private:
|
||||
void inc_Count(dim1Map *subMap, int *count) ;
|
||||
template <typename T> void inc_Count(std::map<double,T> *subMap, int *count);
|
||||
|
||||
public:
|
||||
void importFromCSV(std::string load_path);
|
||||
private:
|
||||
std::ifstream createImportStream(const std::string &load_path) ;
|
||||
void addPointFromLine(const std::string &lineFromFile);
|
||||
|
||||
public:
|
||||
void addPoint(std::deque<double> pointIn);
|
||||
private:
|
||||
void rec_addPoint(std::map<double,double> *subMap, std::deque<double> pointIn);
|
||||
template <typename T> void rec_addPoint (std::map<double,T> *subMap, std::deque<double> pointIn);
|
||||
|
||||
public:
|
||||
void exportToCSV(std::string exportPath) ;
|
||||
private:
|
||||
std::ofstream createExportStream(const std::string &exportPath) ;
|
||||
std::string getExportFileHeader() ;
|
||||
void rec_exportToCSV (const dim1Map &subMap, std::ofstream &exportStream, std::string preset = "") ;
|
||||
template <typename T> void rec_exportToCSV(const T &subMap, std::ofstream &exportStream, std::string preset = "") ;
|
||||
|
||||
protected:
|
||||
double get_value(std::deque<double> Points, searchStyle searchMode) ;
|
||||
template <typename T_target> T_target* getSubMap(std::deque<double> Points, searchStyle searchMode) ;
|
||||
private:
|
||||
template <typename T_target> void rec_getSubMap(T_target *subMap, T_target **targetMapPtr, std::deque<double> Points, searchStyle searchMode) ;
|
||||
template <typename T_target, typename T> void rec_getSubMap(T *subMap, T_target **targetMapPtr, std::deque<double> Points, searchStyle searchMode) ;
|
||||
template <class T> typename T::iterator searchItrByStyle(T *subMap, double x, searchStyle searchMode) ;
|
||||
|
||||
protected:
|
||||
void checkEmpty() ;
|
||||
public:
|
||||
T_Map getMap() const {return (Map);}
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
template <typename T>
|
||||
double Base_Container<T_Map>::calc_Dim() {
|
||||
T dummyMap;
|
||||
int count = 0;
|
||||
inc_Count(&dummyMap, &count);
|
||||
return (count);
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
void Base_Container<T_Map>::inc_Count(dim1Map *subMap, int *count) {
|
||||
++(*count);
|
||||
subMap->insert(std::pair<double,double>(0,0));
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
template <typename T>
|
||||
void Base_Container<T_Map>::inc_Count(std::map<double,T> *subMap, int *count) {
|
||||
++(*count);
|
||||
T tempMap;
|
||||
inc_Count(&tempMap, count);
|
||||
subMap->insert(std::pair<double,T>(0,tempMap));
|
||||
}
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
void Base_Container<T_Map>::importFromCSV(std::string load_path) {
|
||||
std::ifstream importStream = createImportStream(load_path);
|
||||
std::string lineFromFile;
|
||||
while (getline(importStream, lineFromFile)) {
|
||||
removeLeadingWhites(lineFromFile);
|
||||
replaceDelimiter(lineFromFile);
|
||||
if ( checkIgnoreLine(lineFromFile) ) {
|
||||
continue;
|
||||
}
|
||||
addPointFromLine(lineFromFile);
|
||||
}
|
||||
importStream.close();
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
std::ifstream Base_Container<T_Map>::createImportStream(const std::string &load_path) {
|
||||
std::ifstream importStream(load_path);
|
||||
if (!importStream.good()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Base_Container::readFromCSV: Could not open file. \n loadFilePath= "<<load_path<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return(importStream);
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
void Base_Container<T_Map>::addPointFromLine(const std::string &lineFromFile) {
|
||||
std::stringstream ss;
|
||||
ss.str(lineFromFile);
|
||||
std::deque<double> dequeTemp;
|
||||
double tempVal;
|
||||
for (int i = 0;i<=Dim;i++) {
|
||||
if (ss>>tempVal) {
|
||||
dequeTemp.push_back(tempVal);
|
||||
} else {
|
||||
std::cout<<"Base_Container::addPointFromFile: Warning could not read line in inputFile. \nloadFilePath\t"<<lineFromFile<<"\n";
|
||||
}
|
||||
}
|
||||
addPoint(dequeTemp);
|
||||
}
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
void Base_Container<T_Map>::addPoint(std::deque<double> pointIn) {
|
||||
if (pointIn.size() != Dim+1) {
|
||||
std::stringstream ss;
|
||||
ss<<"Base_Container::addPoint: deque pointIn dimension missmatch.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
rec_addPoint(&Map, pointIn);
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
void Base_Container<T_Map>::rec_addPoint(dim1Map *subMap, std::deque<double> pointIn) { //Iteration End
|
||||
if (pointIn.size()!=2) {
|
||||
std::stringstream ss;
|
||||
ss<<"Base_Container::addPoint: Dimension missmatch of pointIn.\nDelta =\t"<<pointIn.size()-2<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double x = pointIn[0];
|
||||
double f = pointIn[1];
|
||||
if (subMap->find(x) != subMap->end()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Base_Container::addPoint: Dublicate insertion of key.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
subMap->insert(std::pair<double,double>(x, f));
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
template <typename T>
|
||||
void Base_Container<T_Map>::rec_addPoint (std::map<double,T> *subMap, std::deque<double> pointIn) {
|
||||
double x = *pointIn.begin();
|
||||
pointIn.pop_front();
|
||||
if (subMap->find(x) == subMap->end()) { // No such element -> generate new Map and insert
|
||||
T tempMap;
|
||||
rec_addPoint(&tempMap, pointIn);
|
||||
subMap->insert(std::pair<double,T>(x,tempMap));
|
||||
} else { // Found such element -> Insert to existing map using iteration
|
||||
rec_addPoint(&subMap->find(x)->second, pointIn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
void Base_Container<T_Map>::exportToCSV(std::string exportPath) {
|
||||
checkEmpty();
|
||||
std::ofstream exportStream = createExportStream(exportPath);
|
||||
exportStream<<getExportFileHeader();
|
||||
rec_exportToCSV(Map, exportStream, "");
|
||||
exportStream.close();
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
std::ofstream Base_Container<T_Map>::createExportStream(const std::string &exportPath) {
|
||||
std::ofstream exportStream(exportPath);
|
||||
if (!exportStream.good()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Base_Container::exportToCSV: Could not open file.\nexportFilePath\t "<<exportPath<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return(exportStream);
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
std::string Base_Container<T_Map>::getExportFileHeader() {
|
||||
std::stringstream ss;
|
||||
ss<<"# Automatically generated Data of Function2D_Container class by exportToFile().\n";
|
||||
ss<<"# Generated on "<<getTimeString()<<".\n";
|
||||
ss<<"#key1 (usually Energy)\tkey2 (angluar distribution or secondary energy)\tparameter (usually SDCS)\n";
|
||||
return(ss.str());
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
void Base_Container<T_Map>::rec_exportToCSV(const dim1Map &subMap, std::ofstream &exportStream, std::string preset) {
|
||||
for (dim1Map::const_iterator Itr = subMap.cbegin();Itr!=subMap.cend();Itr++) {
|
||||
exportStream<<preset<<Itr->first<<"\t"<<Itr->second<<"\n";
|
||||
}
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
template <typename T>
|
||||
void Base_Container<T_Map>::rec_exportToCSV(const T &subMap, std::ofstream &exportStream, std::string preset) {
|
||||
std::stringstream ss;
|
||||
for (typename T::const_iterator Itr = subMap.cbegin();Itr!=subMap.cend();Itr++) {
|
||||
ss.clear();
|
||||
ss.str("");
|
||||
ss<<preset<<Itr->first<<"\t";
|
||||
rec_exportToCSV(Itr->second, exportStream, ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
double Base_Container<T_Map>::get_value(std::deque<double> Points, searchStyle searchMode) {
|
||||
double x = Points.back();
|
||||
Points.pop_back();
|
||||
dim1Map *subMap = getSubMap<dim1Map>(Points, searchMode);
|
||||
dim1Map::const_iterator Itr = searchItrByStyle(subMap, x, searchMode);
|
||||
return(Itr->second);
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
template <typename T_target>
|
||||
T_target* Base_Container<T_Map>::getSubMap(std::deque<double> Points, searchStyle searchMode) {
|
||||
checkEmpty();
|
||||
double T_Dim = calc_Dim<T_target>();
|
||||
if (Points.size() != Dim - T_Dim) {
|
||||
std::stringstream ss;
|
||||
ss<<"Base_Container::getSubMap: Dimension Missmatch of Points\n Missmatch =\t<< "<<Points.size() - (Dim - T_Dim)<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
T_target *targetMap;
|
||||
rec_getSubMap(&Map, &targetMap, Points, searchMode);
|
||||
return (targetMap);
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
template <typename T_target>
|
||||
void Base_Container<T_Map>::rec_getSubMap(T_target *subMap, T_target **targetMapPtr, std::deque<double> Points, searchStyle searchMode) {
|
||||
if (Points.size() != 0) {
|
||||
std::stringstream ss;
|
||||
ss<<"Base_Container::get_subItr: Dimension Missmatch of Points\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
*targetMapPtr = subMap;
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
template <typename T_target, typename T>
|
||||
void Base_Container<T_Map>::rec_getSubMap(T *subMap, T_target **targetMapPtr, std::deque<double> Points, searchStyle searchMode) {
|
||||
double x = Points.front();
|
||||
Points.pop_front();
|
||||
typename T::iterator Itr = searchItrByStyle(subMap, x, searchMode);
|
||||
rec_getSubMap(&(Itr->second), targetMapPtr, Points, searchMode);
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
template <class T>
|
||||
typename T::iterator Base_Container<T_Map>::searchItrByStyle(T *subMap, double x, searchStyle searchMode) {
|
||||
typename T::iterator Itr;
|
||||
if (searchMode == Find) {
|
||||
Itr = subMap->find(x);
|
||||
} else if (searchMode == Lower_bound) {
|
||||
Itr = subMap->lower_bound(x);
|
||||
} else if (searchMode == Lower_bound_Over) {
|
||||
Itr = subMap->lower_bound(x);
|
||||
if (Itr == subMap->end()) {
|
||||
--Itr;
|
||||
}
|
||||
}
|
||||
if (Itr == subMap->end()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Base_Container::calcItr: Point is out of bound.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return (Itr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
void Base_Container<T_Map>::checkEmpty() {
|
||||
if (Map.empty()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Base_Conainer::checkEmpty: Map is empty.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* base_container_h */
|
||||
@@ -24,11 +24,12 @@ constant ERyd_eV = 13.605693009;
|
||||
|
||||
// Particle Properties
|
||||
constant me_eV = 0.511e6;
|
||||
constant mT_eV = 2.8094320212e9;
|
||||
constant mT2_eV = mT_eV*2;
|
||||
|
||||
constant re_m = 2.817940322719e-15;
|
||||
|
||||
constant ZT2 = 2.;
|
||||
constant mT_eV = 2.8094320212e9;
|
||||
constant mT2_eV = mT_eV*2;
|
||||
constant EionT2_eV = 15.43;
|
||||
constant decayConstT2_s = 1.78405e-09;
|
||||
|
||||
|
||||
@@ -1,279 +0,0 @@
|
||||
//
|
||||
// container_base_functions.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 08.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef container_base_functions_h
|
||||
#define container_base_functions_h
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <deque>
|
||||
#include "blitz/tinyvec2.h"
|
||||
#include "blitz/array.h"
|
||||
|
||||
#include "error_types.h"
|
||||
#include "read_system.h"
|
||||
#include "constants.h"
|
||||
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
typedef std::map<double,double> dim1Map;
|
||||
|
||||
|
||||
namespace container_base {
|
||||
inline void add_To_Map(std::map<double,double> *Map, const std::deque<double> &queIn) { //Iteration End
|
||||
if (queIn.size()!=2) {
|
||||
std::stringstream ss;
|
||||
ss<<"addTo_Map: vecIn not big enough.";
|
||||
std::cout<<ss.str()<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double x1 = *queIn.begin();
|
||||
double f = *queIn.rbegin();
|
||||
if ( Map->find(x1)!=Map->end() ) {
|
||||
std::stringstream ss;
|
||||
ss<<"HIT: Key x="<<x1<<" already exists.";
|
||||
std::cout<<ss.str()<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
Map->insert(std::pair<double,double>(x1, f));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void add_To_Map (std::map<double,T> *Map, std::deque<double> queIn) {
|
||||
double xN = *queIn.begin();
|
||||
queIn.pop_front();
|
||||
T tempMap;
|
||||
if ( Map->find(xN)==Map->end() ) { // No such element -> generate new Map and insert
|
||||
T tempMap;
|
||||
add_To_Map(&tempMap, queIn);
|
||||
Map->insert(std::pair<double,T>(xN,tempMap));
|
||||
} else { // Found such element -> Insert to existing map using iteration
|
||||
add_To_Map(&Map->find(xN)->second, queIn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline void add_From_Csv (T *Map, const int &dim, const std::string &loadFilePath) {
|
||||
std::ifstream fileStream(loadFilePath);
|
||||
|
||||
if (!fileStream.good()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Func_Container::readFromCSV: Could not open file. \n loadFilePath= "<<loadFilePath<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
std::string lineFromFile;
|
||||
std::stringstream ss;
|
||||
double temp;
|
||||
std::deque<double> dequeTemp;
|
||||
bool lineReadError = false;
|
||||
|
||||
while (getline(fileStream, lineFromFile)) {
|
||||
removeLeadingWhites(lineFromFile);
|
||||
replaceDelimiter(lineFromFile);
|
||||
if ( checkIgnoreLine(lineFromFile) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ss.clear();
|
||||
ss.str(lineFromFile);
|
||||
dequeTemp.clear();
|
||||
for (int i =0;i<=dim;i++) {
|
||||
if (ss>>temp) {
|
||||
dequeTemp.push_back(temp);
|
||||
} else if (!lineReadError) {
|
||||
std::cout<<"Func_Container::readFromCSV: Warning could not read line in inputFile. \nloadFilePath = "<<loadFilePath<<"\n";
|
||||
lineReadError = true;
|
||||
|
||||
}
|
||||
}
|
||||
if (dequeTemp.size() == dim+1) {
|
||||
add_To_Map(Map, dequeTemp);
|
||||
}
|
||||
}
|
||||
fileStream.close();
|
||||
}
|
||||
|
||||
inline void write_To_Csv(const dim1Map &Map, std::ofstream *outFile, std::string preset = "") { //Iteration End
|
||||
for (dim1Map::const_iterator Itr = Map.begin();Itr!=Map.end();Itr++) {
|
||||
(*outFile)<<preset<<Itr->first<<"\t"<<Itr->second<<"\n";
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void write_To_Csv(const T &Map, std::ofstream *outFile, std::string preset = "") {
|
||||
std::stringstream ss;
|
||||
for (typename T::const_iterator Itr = Map.begin();Itr!=Map.end();Itr++) {
|
||||
ss.clear();
|
||||
ss.str("");
|
||||
ss<<preset<<Itr->first<<"\t";
|
||||
write_To_Csv(Itr->second, outFile, ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void export_To_Csv(const T &Map, std::string exportFilePath) {
|
||||
std::ofstream outFile;
|
||||
outFile.open(exportFilePath);
|
||||
if (!outFile.good()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Func2D_Container::exportToFile: Could not open file. \n exportFilePath= "<<exportFilePath<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
outFile<<"# Automatically generated Data of Function2D_Container class by exportToFile().\n";
|
||||
outFile<<"# Generated on "<<getTimeString()<<".\n";
|
||||
outFile<<"#key1 (usually Energy)\tkey2 (angluar distribution or secondary energy)\tparameter (usually SDCS)\n";
|
||||
|
||||
write_To_Csv(Map,&outFile);
|
||||
outFile.close();
|
||||
}
|
||||
|
||||
inline double get_Value(const dim1Map &Map, std::deque<double> Cord) {
|
||||
if (Cord.size()!=1) {
|
||||
std::stringstream ss;
|
||||
ss<<"getValue: Length of Cord and &Map do not map.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double x = *Cord.begin();
|
||||
if (Map.rbegin()->first < x) {
|
||||
return(Map.rbegin()->second);
|
||||
} else {
|
||||
return (Map.lower_bound(x)->second);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline double get_Value(const T &Map, std::deque<double> Cord) {
|
||||
double x = *Cord.begin();
|
||||
Cord.pop_front();
|
||||
if (Map.rbegin()->first < x) {
|
||||
return( get_Value(Map.rbegin()->second, Cord) );
|
||||
} else {
|
||||
return ( get_Value(Map.lower_bound(x)->second, Cord) );
|
||||
}
|
||||
}
|
||||
|
||||
inline double interpolate_Value(const dim1Map &Map, std::deque<double> Cord) {
|
||||
if (Cord.size()!=1) {
|
||||
std::stringstream ss;
|
||||
ss<<"interpolat_Value: Length of Cord and &Map do not map.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double x = *Cord.begin();
|
||||
if (Map.begin() == Map.lower_bound(x) ) {
|
||||
return (Map.begin()->second);
|
||||
} else if (Map.end() == Map.lower_bound(x)){
|
||||
return ( (--Map.end())->second );
|
||||
}
|
||||
|
||||
dim1Map::const_iterator lowAnker_Itr = --Map.lower_bound(x);
|
||||
dim1Map::const_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);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline double interpolate_Value(const T &Map, std::deque<double> Cord) {
|
||||
double x = *Cord.begin();
|
||||
Cord.pop_front();
|
||||
|
||||
if (x < Map.begin()->first) {
|
||||
return ( interpolate_Value(Map.begin()->second, Cord) );
|
||||
} else if (x > Map.rbegin()->first){
|
||||
return ( interpolate_Value( (Map.rbegin())->second, Cord) );
|
||||
}
|
||||
|
||||
typename T::const_iterator lowAnker_Itr = --Map.lower_bound(x);
|
||||
typename T::const_iterator upAnker_Itr = Map.lower_bound(x);
|
||||
double lowAnker_x = lowAnker_Itr->first;
|
||||
double lowAnker_fxy = interpolate_Value(lowAnker_Itr->second, Cord);
|
||||
double upAnker_x = upAnker_Itr->first;
|
||||
double upAnker_fxy = interpolate_Value(upAnker_Itr->second, Cord);
|
||||
|
||||
double res = lowAnker_fxy + (x-lowAnker_x)/(upAnker_x-lowAnker_x) * (upAnker_fxy-lowAnker_fxy);
|
||||
return (res);
|
||||
}
|
||||
|
||||
inline void set_Itr(dim1Map *Map, std::deque<double> Cord, dim1Map::iterator &Itr) {
|
||||
if (Cord.size()!=1) {
|
||||
std::stringstream ss;
|
||||
ss<<"set_Itr: Length of Cord and &Map do not map.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double x = *Cord.begin();
|
||||
|
||||
if (x>Map->rbegin()->first) {
|
||||
Itr = (--Map->end());
|
||||
} else {
|
||||
Itr = Map->lower_bound(x);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void set_Itr(T *Map, std::deque<double> Cord, dim1Map::iterator &Itr) {
|
||||
double x = *Cord.begin();
|
||||
Cord.pop_front();
|
||||
if (x > Map->rbegin()->first) {
|
||||
set_Itr( &(Map->rbegin()->second), Cord, Itr );
|
||||
} else {
|
||||
set_Itr( &((Map->lower_bound(x))->second), Cord, Itr );
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline dim1Map::iterator get_Itr(T *Map, std::deque<double> Cord) {
|
||||
dim1Map::iterator res;
|
||||
set_Itr(Map, Cord, res);
|
||||
return(res);
|
||||
}
|
||||
|
||||
inline void set_constItr(const dim1Map *Map, std::deque<double> Cord, dim1Map::const_iterator &Itr) {
|
||||
if (Cord.size()!=1) {
|
||||
std::stringstream ss;
|
||||
ss<<"set_Itr: Length of Cord and &Map do not map.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double x = *Cord.begin();
|
||||
|
||||
if (x>(--Map->cend())->first) {
|
||||
Itr = (--Map->cend());
|
||||
} else {
|
||||
Itr = Map->lower_bound(x);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void set_constItr(const T *Map, std::deque<double> Cord, dim1Map::const_iterator &Itr) {
|
||||
double x = *Cord.begin();
|
||||
Cord.pop_front();
|
||||
if (x > (--Map->cend())->first) {
|
||||
set_constItr( &((--Map->cend())->second), Cord, Itr );
|
||||
} else {
|
||||
set_constItr( &((Map->lower_bound(x))->second), Cord, Itr );
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline dim1Map::const_iterator get_constItr(const T *Map, std::deque<double> Cord) {
|
||||
dim1Map::const_iterator res;
|
||||
set_constItr(Map, Cord, res);
|
||||
return(res);
|
||||
}
|
||||
|
||||
// Write some iterator over all bins in maps.
|
||||
} // namespace
|
||||
|
||||
|
||||
#endif /* container_base_functions_h */
|
||||
@@ -1,354 +0,0 @@
|
||||
//
|
||||
// density_container.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 06.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "density_container.hpp"
|
||||
|
||||
#include "blitz/tinyvec2.h"
|
||||
|
||||
#include "katrin_geo.hpp"
|
||||
|
||||
#include "kinematics.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
WGTS_Geo::WGTS_Geo(vec3 zrphi_numBins) {
|
||||
this->z_min_m = Katrin_Geo::get_z_RW_m();
|
||||
this->z_max_m = Katrin_Geo::get_z_WGTSend_m();
|
||||
this->r_max_m = Katrin_Geo::get_radius_m();
|
||||
this->zrphi_numBins = zrphi_numBins;
|
||||
init_bin_maps();
|
||||
}
|
||||
|
||||
WGTS_Geo::WGTS_Geo(double z_min_m, double z_max_m, double r_max_m, vec3 zrphi_numBins) {
|
||||
this->z_min_m = z_min_m;
|
||||
this->z_max_m = z_max_m;
|
||||
this->r_max_m = r_max_m;
|
||||
this->zrphi_numBins = zrphi_numBins;
|
||||
init_bin_maps();
|
||||
}
|
||||
|
||||
void WGTS_Geo::init_bin_maps() {
|
||||
int n_z = zrphi_numBins[0];
|
||||
int n_r = zrphi_numBins[1];
|
||||
int n_phi = zrphi_numBins[2];
|
||||
double len_m = (z_max_m-z_min_m)/n_z;
|
||||
double rad_step_m = r_max_m/n_r;
|
||||
|
||||
double z_m,r_m;
|
||||
for (int i_z=1;i_z<=n_z;i_z++) {
|
||||
z_m = z_min_m + i_z * len_m;
|
||||
bin_l_m.insert(dim1Pair(z_m,len_m));
|
||||
}
|
||||
double V_m3;
|
||||
for (int i_r=1;i_r<=n_r;i_r++) {
|
||||
r_m = i_r * rad_step_m;
|
||||
V_m3 = (pi*pow(r_m,2)-pi*pow(r_m-rad_step_m,2))/n_phi;
|
||||
bin_V_m3.insert(dim1Pair(r_m,V_m3));
|
||||
}
|
||||
}
|
||||
|
||||
double WGTS_Geo::get_Bin_l_m(double z_m) const {
|
||||
if (check_z_outside(z_m)) {
|
||||
stringstream ss;
|
||||
ss<<"WGTS_Geo_Container::get_Bin_l_m: z_m not in Container.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return (bin_l_m.lower_bound(z_m)->second);
|
||||
}
|
||||
|
||||
double WGTS_Geo::get_Bin_V_m3(double z_m, double r_m) const {
|
||||
if (check_r_outside(r_m)) {
|
||||
stringstream ss;
|
||||
ss<<"WGTS_Geo_Container::get_Bin_V_m3: r_m not in Container.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return (bin_V_m3.lower_bound(r_m)->second);
|
||||
}
|
||||
|
||||
bool WGTS_Geo::outside_Container(vec3 Cords, cordStyle cordStyleIn) const {
|
||||
Cords = zrphiCords(Cords, cordStyleIn);
|
||||
return (check_z_outside (Cords[0]) || check_r_outside(Cords[1]));
|
||||
}
|
||||
bool WGTS_Geo::check_z_outside (double z_m) const {
|
||||
if (z_m<z_min_m) {
|
||||
return (true);
|
||||
}
|
||||
if (z_m>z_max_m) {
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
bool WGTS_Geo::check_r_outside (double r_m) const {
|
||||
if (r_m>r_max_m) {
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
vec3 WGTS_Geo::zrphiCords(vec3 Cords, cordStyle cordStyleIn) const {
|
||||
if (cordStyleIn == zrphi) {
|
||||
return (Cords);
|
||||
}
|
||||
double z = Cords[2];
|
||||
double r = sqrt(Cords[0]*Cords[0] + Cords[1]*Cords[1]);
|
||||
double phi;
|
||||
if (Cords[0] >= 0) {
|
||||
phi = acos(Cords[1]/r);
|
||||
} else {
|
||||
phi = 2*pi - acos(Cords[1]/r);
|
||||
}
|
||||
return (vec3(z,r,phi));
|
||||
}
|
||||
|
||||
|
||||
WGTS3D_ParticleTime_s_Container::WGTS3D_ParticleTime_s_Container(double z_min_m, double z_max_m, double r_max_m, vec3 zrphi_numBins) : WGTS_Geo(z_min_m, z_max_m, r_max_m, zrphi_numBins) {
|
||||
init_Map();
|
||||
}
|
||||
WGTS3D_ParticleTime_s_Container::WGTS3D_ParticleTime_s_Container(vec3 zrphi_numBins) : WGTS_Geo(zrphi_numBins) {
|
||||
init_Map();
|
||||
}
|
||||
|
||||
void WGTS3D_ParticleTime_s_Container::init_Map() {
|
||||
// Give posibility for non linear Bins....
|
||||
int n_z = zrphi_numBins[0];
|
||||
int n_r = zrphi_numBins[1];
|
||||
int n_phi = zrphi_numBins[2];
|
||||
double step_z_m = (z_max_m-z_min_m)/n_z;
|
||||
double step_r_m = r_max_m/n_r;
|
||||
double step_phi = 2*pi/n_phi;
|
||||
|
||||
double z_m,r_m,phi;
|
||||
for (int i_z=1;i_z<=n_z;i_z++) {
|
||||
z_m = z_min_m + i_z * step_z_m;
|
||||
for (int i_r=1;i_r<=n_r;i_r++) {
|
||||
r_m = i_r * step_r_m;
|
||||
for (int i_phi=1;i_phi<=n_phi;i_phi++) {
|
||||
phi = step_phi * i_phi;
|
||||
add_ankerpoint(z_m, r_m, phi, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double WGTS3D_ParticleTime_s_Container::getDensity_m3(vec3 loc_m, double physTime_s, cordStyle cordStyleIn) const {
|
||||
if (outside_Container(loc_m, cordStyleIn)) {
|
||||
stringstream ss;
|
||||
ss<<"WGTS3D_ParticleTime_s_Container::getDensity: loc_old or loc_new not in Container.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
loc_m = zrphiCords(loc_m, cordStyleIn);
|
||||
double V_m3 = get_Bin_V_m3(loc_m[0], loc_m[1]);
|
||||
double cumTime_s = findBin(loc_m)->second;
|
||||
return (cumTime_s/physTime_s/V_m3);
|
||||
}
|
||||
|
||||
void WGTS3D_ParticleTime_s_Container::up_DriftApprox_Density(double vAbs_ms, vec3 loc_old, vec3 loc_new, cordStyle cordStyleIn) {
|
||||
if (outside_Container(loc_old, cordStyleIn) || outside_Container(loc_new, cordStyleIn)) {
|
||||
stringstream ss;
|
||||
ss<<"WGTS3D_ParticleTime_s_Container::up_DriftApprox_Density: loc_old or loc_new not in Container.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
vec3 loc_min = zrphiCords(loc_old, cordStyleIn);
|
||||
vec3 loc_max = zrphiCords(loc_new, cordStyleIn);
|
||||
double zmin_m = loc_min[0];
|
||||
double zmax_m = loc_min[0];
|
||||
if (zmax_m<zmin_m) {
|
||||
swap (zmin_m, zmax_m);
|
||||
swap (loc_min, loc_max);
|
||||
}
|
||||
// Todo: Check start and end in same r and phi bin here
|
||||
|
||||
dim3Map::iterator zItr_min = Map.lower_bound(zmin_m);
|
||||
dim3Map::iterator zItr_max = Map.lower_bound(zmax_m);
|
||||
double r_m = loc_min[1];
|
||||
double phi = loc_min[2];
|
||||
vec3 zrPhiCords = vec3 (0,r_m,phi);
|
||||
double z_m, l_m;
|
||||
for (dim3Map::iterator Itr = zItr_min;Itr != zItr_max;Itr++) {
|
||||
z_m = Itr->first;
|
||||
l_m = get_Bin_l_m(z_m);
|
||||
zrPhiCords[0] = z_m;
|
||||
findBin(zrPhiCords)->second += l_m/vAbs_ms;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WGTS4D_ParticleTime_s_Container::WGTS4D_ParticleTime_s_Container(double z_min_m, double z_max_m, double r_max_m, vec3 zrphi_numBins, double mass_eV, double Emin_eV, double Emax_eV, double pointsPerEorder) : WGTS_Geo(z_min_m, z_max_m, r_max_m, zrphi_numBins) {
|
||||
this->Emin_eV = Emin_eV;
|
||||
this->Emax_eV = Emax_eV;
|
||||
this->pointsPerEorder = pointsPerEorder;
|
||||
this->mass_eV = mass_eV;
|
||||
init_Map();
|
||||
}
|
||||
|
||||
WGTS4D_ParticleTime_s_Container::WGTS4D_ParticleTime_s_Container(vec3 zrphi_numBins, double mass_eV, double Emin_eV, double Emax_eV, double pointsPerEorder) : WGTS_Geo(zrphi_numBins) {
|
||||
this->Emin_eV = Emin_eV;
|
||||
this->Emax_eV = Emax_eV;
|
||||
this->pointsPerEorder = pointsPerEorder;
|
||||
this->mass_eV = mass_eV;
|
||||
init_Map();
|
||||
}
|
||||
|
||||
void WGTS4D_ParticleTime_s_Container::init_Map() {
|
||||
// Give posibility for non linear Bins....
|
||||
int n_z = zrphi_numBins[0];
|
||||
int n_r = zrphi_numBins[1];
|
||||
int n_phi = zrphi_numBins[2];
|
||||
double step_z_m = (z_max_m-z_min_m)/n_z;
|
||||
double step_r_m = r_max_m/n_r;
|
||||
double step_phi = 2*pi/n_phi;
|
||||
|
||||
int E_interval = pointsPerEorder -1;
|
||||
int E_minI = floor(log10(Emin_eV)*E_interval);
|
||||
int E_maxI = ceil(log10(Emax_eV)*E_interval);
|
||||
|
||||
double z_m,r_m,phi, E_eV;
|
||||
for (int i_z=1;i_z<=n_z;i_z++) {
|
||||
z_m = z_min_m + i_z * step_z_m;
|
||||
for (int i_r=1;i_r<=n_r;i_r++) {
|
||||
r_m = i_r * step_r_m;
|
||||
for (int i_phi=1;i_phi<=n_phi;i_phi++) {
|
||||
phi = step_phi * i_phi;
|
||||
for (int i_E = E_minI;i_E<=E_maxI;i_E++) {
|
||||
E_eV = pow(10,double (i_E)/double(E_interval));
|
||||
add_ankerpoint(z_m, r_m, phi, E_eV, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double WGTS4D_ParticleTime_s_Container::getDensity_m3(vec3 loc_m, double physTime_s, cordStyle cordStyleIn) const {
|
||||
if (outside_Container(loc_m, cordStyleIn)) {
|
||||
stringstream ss;
|
||||
ss<<"WGTS4D_ParticleTime_s_Container::getDensity: loc_old or loc_new not in Container.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
loc_m = zrphiCords(loc_m, cordStyleIn);
|
||||
double V_m3 = get_Bin_V_m3(loc_m[0], loc_m[1]);
|
||||
return (get_CumTime_s(loc_m)/physTime_s/V_m3);
|
||||
}
|
||||
|
||||
void WGTS4D_ParticleTime_s_Container::up_DriftApprox_Density(double vAbs_ms, vec3 loc_old, vec3 loc_new, cordStyle cordStyleIn) {
|
||||
if (outside_Container(loc_old, cordStyleIn) || outside_Container(loc_new, cordStyleIn)) {
|
||||
stringstream ss;
|
||||
ss<<"WGTS4D_ParticleTime_s_Container::up_DriftApprox_Density: loc_old or loc_new not in Container.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
vec3 loc_min = zrphiCords(loc_old, cordStyleIn);
|
||||
vec3 loc_max = zrphiCords(loc_new, cordStyleIn);
|
||||
double zmin_m = loc_min[0];
|
||||
double zmax_m = loc_max[0];
|
||||
if (zmax_m < zmin_m) {
|
||||
swap (zmin_m, zmax_m);
|
||||
swap (loc_min, loc_max);
|
||||
}
|
||||
// Todo: Check start and end in same r and phi bin here
|
||||
|
||||
dim4Map::iterator zItr_min = Map.lower_bound(zmin_m);
|
||||
dim4Map::iterator zItr_max = Map.lower_bound(zmax_m);
|
||||
double r_m = loc_min[1];
|
||||
double phi = loc_min[2];
|
||||
double E_eV = calc_Ekin_eV_from_speed(vAbs_ms, mass_eV);
|
||||
vec3 zrPhiCords = vec3 (0,r_m,phi);
|
||||
double z_m, l_m;
|
||||
for (dim4Map::iterator Itr = zItr_min;Itr != zItr_max;Itr++) {
|
||||
z_m = Itr->first;
|
||||
l_m = get_Bin_l_m(z_m);
|
||||
zrPhiCords[0] = z_m;
|
||||
findBin(zrPhiCords, E_eV)->second += l_m/vAbs_ms;
|
||||
}
|
||||
}
|
||||
|
||||
double WGTS4D_ParticleTime_s_Container::get_CumTime_s(vec3 zrPhiCords) const {
|
||||
dim1Map EMap = findBin(zrPhiCords)->second;
|
||||
double num = 0;
|
||||
for (dim1Map::iterator Itr=EMap.begin();Itr!=EMap.end();Itr++) {
|
||||
num +=Itr->second;
|
||||
}
|
||||
return(num);
|
||||
}
|
||||
|
||||
double WGTS4D_ParticleTime_s_Container::roll_Energy_eV(vec3 loc_m, UniRNG *rngUni, cordStyle cordStyleIn) const {
|
||||
loc_m = zrphiCords(loc_m, cordStyleIn);
|
||||
dim1Map EMap = findBin(loc_m)->second;
|
||||
double maxValue = get_CumTime_s(loc_m);
|
||||
|
||||
|
||||
double sum = 0;
|
||||
double target = rngUni->random() * maxValue;
|
||||
dim1Map::iterator Itr = EMap.begin();
|
||||
do {
|
||||
sum += Itr->second;
|
||||
Itr++;
|
||||
} while(sum < target);
|
||||
Itr--;
|
||||
|
||||
if (Itr == EMap.begin() ) {
|
||||
return (Itr->first);
|
||||
} else {
|
||||
double E_eV = ( (Itr->first) + ((--Itr)->first) )/2;
|
||||
return (E_eV);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dim2Map::const_iterator WGTS4D_ParticleTime_s_Container::findBin(vec3 zrPhiCords) const { // improve -> template
|
||||
double z_m = zrPhiCords[0];
|
||||
dim3Map Map3;
|
||||
if (z_m > Map.rbegin()->first) {
|
||||
Map3 = (--Map.end())->second;
|
||||
} else {
|
||||
Map3 = Map.lower_bound(z_m)->second;
|
||||
}
|
||||
|
||||
double r_m = zrPhiCords[1];
|
||||
dim2Map Map2;
|
||||
if (r_m > Map3.rbegin()->first) {
|
||||
Map2 = (--Map3.end())->second;
|
||||
} else {
|
||||
Map2 = Map3.lower_bound(r_m)->second;
|
||||
}
|
||||
|
||||
double phi = zrPhiCords[2];
|
||||
dim2Map::const_iterator Itr;
|
||||
if (phi > Map3.rbegin()->first) {
|
||||
Itr = (--Map2.end());
|
||||
} else {
|
||||
Itr = Map2.lower_bound(phi);
|
||||
}
|
||||
|
||||
return (Itr);
|
||||
}
|
||||
|
||||
dim2Map::iterator WGTS4D_ParticleTime_s_Container::findBin(vec3 zrPhiCords) { // improve -> template
|
||||
double z_m = zrPhiCords[0];
|
||||
dim3Map Map3;
|
||||
if (z_m > Map.rbegin()->first) {
|
||||
Map3 = (--Map.end())->second;
|
||||
} else {
|
||||
Map3 = Map.lower_bound(z_m)->second;
|
||||
}
|
||||
|
||||
double r_m = zrPhiCords[1];
|
||||
dim2Map Map2;
|
||||
if (r_m > Map3.rbegin()->first) {
|
||||
Map2 = (--Map3.end())->second;
|
||||
} else {
|
||||
Map2 = Map3.lower_bound(r_m)->second;
|
||||
}
|
||||
|
||||
double phi = zrPhiCords[2];
|
||||
dim2Map::iterator Itr;
|
||||
if (phi > Map3.rbegin()->first) {
|
||||
Itr = (--Map2.end());
|
||||
} else {
|
||||
Itr = Map2.lower_bound(phi);
|
||||
}
|
||||
|
||||
return (Itr);
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
//
|
||||
// density_container.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 06.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef density_container_hpp
|
||||
#define density_container_hpp
|
||||
|
||||
#include "container_base_functions.h"
|
||||
|
||||
#include "random_operations.h"
|
||||
|
||||
typedef std::map<double,double> dim1Map;
|
||||
typedef std::pair<double,double> dim1Pair;
|
||||
|
||||
typedef std::map<double,dim1Map> dim2Map;
|
||||
typedef std::pair<double,dim1Map> dim2Pair;
|
||||
|
||||
typedef std::map<double,dim2Map> dim3Map;
|
||||
typedef std::pair<double,dim2Map> dim3Pair;
|
||||
|
||||
typedef std::map<double,dim3Map> dim4Map;
|
||||
typedef std::pair<double,dim3Map> dim4Pair;
|
||||
|
||||
typedef enum cordStyle{xyz, zrphi} cordStyle;
|
||||
|
||||
|
||||
class Base3D_FuncContainer {
|
||||
protected:
|
||||
dim3Map Map;
|
||||
public:
|
||||
Base3D_FuncContainer() {};
|
||||
Base3D_FuncContainer(std::string loadFilePath) {fillFromCSV(loadFilePath);};
|
||||
|
||||
void fillFromCSV(std::string loadFilePath){container_base::add_From_Csv(&Map, 3, loadFilePath);};
|
||||
void add_ankerpoint(double x, double y, double z, double fxyz){container_base::add_To_Map(&Map, std::deque<double> {x,y,z,fxyz});};
|
||||
|
||||
void exportToFile(std::string exportFilePath) const {container_base::export_To_Csv(Map, exportFilePath);};
|
||||
|
||||
dim3Map get_Map() const {return (Map);}
|
||||
};
|
||||
|
||||
|
||||
class WGTS_Geo {
|
||||
protected:
|
||||
double z_min_m;
|
||||
double z_max_m;
|
||||
double r_max_m;
|
||||
vec3 zrphi_numBins;
|
||||
dim1Map bin_l_m;
|
||||
dim1Map bin_V_m3;
|
||||
|
||||
public:
|
||||
WGTS_Geo(double z_min_m, double z_max_m, double r_max_m, vec3 zrphi_numBins);
|
||||
WGTS_Geo(vec3 zrphi_numBins);
|
||||
|
||||
private:
|
||||
void init_bin_maps();
|
||||
|
||||
public:
|
||||
double get_Bin_l_m (double z_m) const ;
|
||||
double get_Bin_V_m3(double z_m, double r_m) const;
|
||||
|
||||
bool outside_Container(vec3 Cords, cordStyle cordStyleIn = xyz) const;
|
||||
bool check_z_outside (double z_m) const;
|
||||
bool check_r_outside (double r_m) const;
|
||||
|
||||
vec3 zrphiCords(vec3 Cords, cordStyle cordStyleIn) const;
|
||||
};
|
||||
|
||||
// WGTS3D_ParticleTime_s_Container Contains cumulative duration of stay in bin.
|
||||
class WGTS3D_ParticleTime_s_Container : private Base3D_FuncContainer , private WGTS_Geo {
|
||||
public:
|
||||
WGTS3D_ParticleTime_s_Container(double z_min_m, double z_max_m, double r_max_m, vec3 zrphi_numBins);
|
||||
WGTS3D_ParticleTime_s_Container(vec3 zrphi_numBins);
|
||||
private:
|
||||
void init_Map();
|
||||
|
||||
public:
|
||||
double getDensity_m3(vec3 loc_m, double simTime_s, cordStyle cordStyleIn = xyz) const;
|
||||
|
||||
void upDensity(double vAbs_ms, vec3 loc_old, vec3 loc_new, cordStyle cordStyleIn = xyz) {up_DriftApprox_Density(vAbs_ms, loc_old, loc_new, cordStyleIn);};
|
||||
private:
|
||||
void up_DriftApprox_Density(double vAbs_ms, vec3 loc_old, vec3 loc_new, cordStyle cordStyleIn = xyz);
|
||||
|
||||
dim1Map::iterator findBin(vec3 zrPhiCords) {return (container_base::get_Itr(&Map, std::deque<double> {zrPhiCords[0],zrPhiCords[1],zrPhiCords[2]}));};
|
||||
dim1Map::const_iterator findBin(vec3 zrPhiCords) const {return (container_base::get_constItr(&Map, std::deque<double> {zrPhiCords[0],zrPhiCords[1],zrPhiCords[2]}));};
|
||||
};
|
||||
// Add option to load default from file...
|
||||
//Part3D_WGTS_Container(std::string loadFilePath, double z_min_m, double z_max_m, double r_max_m, vec3 zrphi_numBins);
|
||||
//void check_Bins()
|
||||
|
||||
|
||||
class Base4D_FuncContainer {
|
||||
protected:
|
||||
dim4Map Map;
|
||||
|
||||
public:
|
||||
Base4D_FuncContainer() {};
|
||||
Base4D_FuncContainer(std::string loadFilePath) {fillFromCSV(loadFilePath);};
|
||||
|
||||
void fillFromCSV(std::string loadFilePath){container_base::add_From_Csv(&Map, 4, loadFilePath);};
|
||||
void add_ankerpoint(double x, double y, double z, double E, double fxyzE){container_base::add_To_Map(&Map, std::deque<double> {x,y,z,E,fxyzE});};
|
||||
|
||||
void exportToFile(std::string exportFilePath){container_base::export_To_Csv(Map, exportFilePath);};
|
||||
|
||||
dim4Map get_Map() {return (Map);}
|
||||
};
|
||||
|
||||
|
||||
class WGTS4D_ParticleTime_s_Container : private Base4D_FuncContainer , private WGTS_Geo {
|
||||
double mass_eV;
|
||||
double Emin_eV;
|
||||
double Emax_eV;
|
||||
double pointsPerEorder;
|
||||
|
||||
public:
|
||||
WGTS4D_ParticleTime_s_Container(double z_min_m, double z_max_m, double r_max_m, vec3 zrphi_numBins, double mass_eV, double Emin_eV, double Emax_eV, double pointsPerEorder);
|
||||
WGTS4D_ParticleTime_s_Container(vec3 zrphi_numBins, double mass_eV, double Emin_eV, double Emax_eV, double pointsPerEorder);
|
||||
|
||||
private:
|
||||
void init_Map();
|
||||
|
||||
public:
|
||||
double getDensity_m3(vec3 loc_m, double simTime_s, cordStyle cordStyleIn = xyz) const ;
|
||||
private:
|
||||
double get_CumTime_s(vec3 zrPhiCords) const ;
|
||||
|
||||
public:
|
||||
void upDensity(double vAbs_ms, vec3 loc_old, vec3 loc_new, cordStyle cordStyleIn = xyz) {up_DriftApprox_Density(vAbs_ms, loc_old, loc_new, cordStyleIn);};
|
||||
private:
|
||||
void up_DriftApprox_Density(double vAbs_ms, vec3 loc_old, vec3 loc_new, cordStyle cordStyleIn = xyz);
|
||||
|
||||
public:
|
||||
double roll_Energy_eV(vec3 loc_m, UniRNG *rngUni, cordStyle cordStyleIn = xyz) const ;
|
||||
|
||||
dim2Map::iterator findBin(vec3 zrPhiCords);
|
||||
dim1Map::iterator findBin(vec3 zrPhiCords, double E_eV) {return (container_base::get_Itr(&Map, std::deque<double> {zrPhiCords[0], zrPhiCords[1], zrPhiCords[2], E_eV}));
|
||||
}
|
||||
dim2Map::const_iterator findBin(vec3 zrPhiCords) const;
|
||||
dim1Map::const_iterator findBin(vec3 zrPhiCords, double E_eV) const {return (container_base::get_constItr(&Map, std::deque<double> {zrPhiCords[0], zrPhiCords[1], zrPhiCords[2], E_eV}));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* density_container_hpp */
|
||||
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// edge_container.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 10.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef edge_container_h
|
||||
#define edge_container_h
|
||||
|
||||
#include "base_container.h"
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
class Edge_Container : public Base_Container<T_Map> {
|
||||
|
||||
public:
|
||||
Edge_Container() : Base_Container<T_Map>() {} ;
|
||||
Edge_Container(std::string load_path) : Base_Container<T_Map>(load_path) {} ;
|
||||
|
||||
public:
|
||||
//set_from_function();
|
||||
|
||||
public:
|
||||
double interpolate(ddeque point) ;
|
||||
private:
|
||||
double rec_interpolate(const double &Map, std::deque<double> subPoint) ;
|
||||
template <typename T> double rec_interpolate(const T &Map, std::deque<double> subPoint) ;
|
||||
};
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
double Edge_Container<T_Map>::interpolate(std::deque<double> point) {
|
||||
Base_Container<T_Map>::checkEmpty();
|
||||
if (Base_Container<T_Map>::Dim != point.size()) {
|
||||
std::stringstream ss;
|
||||
ss<<"EdgeBase_Container::interpolate: deque point dimension missmatch.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return (rec_interpolate(Base_Container<T_Map>::Map, point) );
|
||||
}
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
double Edge_Container<T_Map>::rec_interpolate(const double &subMap, std::deque<double> subPoint) {
|
||||
if (subPoint.size() != 0) {
|
||||
std::stringstream ss;
|
||||
ss<<"sub_interpolate: deque subPoint dimension missmatch.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return (subMap);
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
template <typename T>
|
||||
double Edge_Container<T_Map>::rec_interpolate(const T &subMap, std::deque<double> subPoint) {
|
||||
double x = *subPoint.begin();
|
||||
subPoint.pop_front();
|
||||
|
||||
typename T::const_iterator upItr = subMap.lower_bound(x);
|
||||
|
||||
if (upItr == subMap.cbegin()) {
|
||||
return (rec_interpolate(upItr->second, subPoint));
|
||||
} else {
|
||||
typename T::const_iterator lowItr = upItr;
|
||||
--lowItr;
|
||||
if (upItr == subMap.cend()) {
|
||||
return (rec_interpolate(lowItr->second, subPoint));
|
||||
} else {
|
||||
double low_x = lowItr->first;
|
||||
double low_f = rec_interpolate(lowItr->second, subPoint);
|
||||
double up_x = upItr->first;
|
||||
double up_f = rec_interpolate(upItr->second, subPoint);
|
||||
|
||||
double res = low_f + (x-low_x)/(up_x-low_x) * (up_f-low_f);
|
||||
return (res);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* edge_container_h */
|
||||
@@ -1,164 +0,0 @@
|
||||
//
|
||||
// electron_interactions.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "electron_interactions.hpp"
|
||||
|
||||
#include "uehara_eT2_elastic.hpp"
|
||||
|
||||
#include "read_system.h"
|
||||
|
||||
|
||||
double e_T2_elasticScattering::get_macroSigma_m2(const Particle &interPart) const {
|
||||
double Ekin_eV = interPart.get_EKin_eV();
|
||||
double microSigma_m2 = Uehara_eT2_ElasticScattering::calc_TCS(Ekin_eV);
|
||||
vec3 loc_m = interPart.get_Location_m();
|
||||
double nT2_m3 = Pop->get_Density_m3(tritium2, loc_m);
|
||||
return (microSigma_m2*nT2_m3);
|
||||
}
|
||||
|
||||
InteractionOut e_T2_elasticScattering::do_Interaction (Particle *interPart) const {
|
||||
// Here theta and phi are COM-Angles.... prob not correct. For m1 << m2 COM - Angle ~ Lab Angle
|
||||
vec3 v_ms = interPart->get_Speed_ms();
|
||||
vec3 vT2_ms = Pop->roll_Speed_ms(tritium2, interPart->get_Location_m());
|
||||
vec3 vLab_ms = v_ms - vT2_ms;
|
||||
double T_eV = calc_Ekin_eV_from_speed(vLab_ms, me_eV);
|
||||
double thetaLab = Uehara_eT2_ElasticScattering::roll_theta(T_eV, rngUni);
|
||||
double phiLab = rngUni->random() * 2 * pi;
|
||||
interPart->set_Speed_ms( calc_vNew_ms(v_ms, vT2_ms, thetaLab, phiLab) );
|
||||
return (InteractionOut());
|
||||
}
|
||||
|
||||
|
||||
vec3 e_T2_elasticScattering::calc_vNew_ms(vec3 vOld_ms, vec3 vT2_ms, double thetaLab, double phiLab) const {
|
||||
// Following Landau Lifschitz I Chapter 4 Paragraph 17
|
||||
vec3 speedLab_ms = vOld_ms - vT2_ms;
|
||||
vec3 n0 = calc_newDirection(speedLab_ms, thetaLab, phiLab);
|
||||
vec3 vNew_ms = (mT2_eV*vec3Abs(speedLab_ms)*n0 + me_eV*speedLab_ms)/(me_eV+mT2_eV) + vT2_ms;
|
||||
//vec3 v2New_ms = (-1*mass_eV*vec3Abs(speedLab_ms)*n0 + mass_eV*speedLab_ms)/(mass_eV+mT2_eV()) + speedT2_ms;
|
||||
return (vNew_ms);
|
||||
}
|
||||
|
||||
|
||||
Average1D_FuncContainer e_T2_ionization::BED_TCS_average_container=Average1D_FuncContainer( getDataPath() + "BED_average_TCS.dat");
|
||||
Stacked2D_FuncContainer e_T2_ionization::BED_SDCS_stacked_container=Stacked2D_FuncContainer( getDataPath() + "BED_stacked_SDCS.dat");
|
||||
|
||||
|
||||
double e_T2_ionization::get_macroSigma_m2(const Particle &interPart) const {
|
||||
double T_eV = interPart.get_EKin_eV();
|
||||
double microSigma_m2 = BED_TCS_average_container.get_Value(T_eV);
|
||||
vec3 loc_m = interPart.get_Location_m();
|
||||
double nT2_m3 = Pop->get_Density_m3(tritium2, loc_m);
|
||||
return (microSigma_m2*nT2_m3);
|
||||
}
|
||||
|
||||
|
||||
InteractionOut e_T2_ionization::do_Interaction (Particle *interPart) const {
|
||||
vec3 vLab_ms = roll_vLab_ms(*interPart);
|
||||
vec3 v_ms = interPart->get_Speed_ms();
|
||||
|
||||
double T_eV = calc_Ekin_eV_from_speed(v_ms, me_eV);
|
||||
if (T_eV < EionT2_eV) {
|
||||
throw MyException("Electron::do_Ionization: Ekin_eV < EIonT2_eV.");
|
||||
}
|
||||
double W_eV = roll_ionW_eV(T_eV);
|
||||
|
||||
double E1_eV = T_eV-EionT2_eV - W_eV;
|
||||
|
||||
double phi1 = rngUni->random()*2*pi;
|
||||
double phi2 = phi1-pi;
|
||||
|
||||
double theta1 = roll_IonTheta1(T_eV, W_eV);
|
||||
double theta2 = roll_IonTheta2(T_eV, W_eV);
|
||||
|
||||
double v1Absnew_ms = calc_Speed_from_Ekin_eV(E1_eV, me_eV);
|
||||
double v2Absnew_ms = calc_Speed_from_Ekin_eV(W_eV, me_eV);
|
||||
|
||||
vec3 P1newDir, P2newDir, v1New_ms, v2New_ms ;
|
||||
P1newDir = calc_newDirection(v_ms, theta1, phi1);
|
||||
P2newDir = calc_newDirection(v_ms, theta2, phi2);
|
||||
|
||||
vec3 vOff_ms = vLab_ms - v_ms;
|
||||
v1New_ms = v1Absnew_ms*P1newDir + vOff_ms;
|
||||
v2New_ms = v2Absnew_ms*P2newDir + vOff_ms;
|
||||
|
||||
interPart->set_Speed_ms(v1New_ms);
|
||||
|
||||
vec3 loc_m = interPart->get_Location_m();
|
||||
Particle eNew = PartBuilder.createElectron(loc_m, v2New_ms, -1, interPart->get_Id());
|
||||
InteractionOut InterOut;
|
||||
InterOut.add_newParticle(eNew);
|
||||
|
||||
vec3 vT_ms = Pop->roll_Speed_ms(tritium, loc_m);
|
||||
Particle TNew = PartBuilder.createTritium(loc_m, vT_ms, -1, interPart->get_Id());
|
||||
InterOut.add_newParticle(TNew);
|
||||
|
||||
return(InterOut);
|
||||
}
|
||||
|
||||
vec3 e_T2_ionization::roll_vLab_ms(const Particle &interPart) const {
|
||||
vec3 v_ms = interPart.get_Speed_ms();
|
||||
vec3 vT2_ms = Pop->roll_Speed_ms(tritium2, interPart.get_Location_m());
|
||||
vec3 vOff_ms = vT2_ms;
|
||||
vec3 vLab_ms = v_ms - vOff_ms;
|
||||
double T_eV = calc_Ekin_eV_from_speed(vLab_ms, me_eV);
|
||||
if (T_eV < EionT2_eV) { // Set Tritium Speed to 0 if unlucky roll
|
||||
T_eV = calc_Ekin_eV_from_speed(v_ms, me_eV);
|
||||
}
|
||||
return (T_eV);
|
||||
}
|
||||
|
||||
double e_T2_ionization::roll_ionW_eV(double T_eV) const {
|
||||
return (BED_SDCS_stacked_container.sample_Value(T_eV, rngUni));
|
||||
/*
|
||||
double pmax, Wmin_eV, Wmax_eV, Wcan_eV,eta1,eta2;
|
||||
|
||||
//pmax = ionTCS_container.interpolate(T_eV);
|
||||
pmax = BED_eT2_Ionization::get_TCS(T_eV);
|
||||
Wmin_eV = 0;
|
||||
Wmax_eV = T_eV-EionT2_eV;
|
||||
do {
|
||||
eta1 = rngUni->random();
|
||||
eta2 = rngUni->random();
|
||||
Wcan_eV = Wmin_eV + eta1*(Wmax_eV - Wmin_eV);
|
||||
} while(eta2*pmax > BED_eT2_Ionization::get_SDCS(T_eV, Wcan_eV));
|
||||
//} while(eta2*pmax > ionSDCS_container.interpolate(T_eV, Wcan_eV));
|
||||
double W_eV = (Wcan_eV< (T_eV-EionT2_eV)/2 ) ? Wcan_eV : (T_eV-EionT2_eV) - Wcan_eV;
|
||||
return(W_eV);
|
||||
*/
|
||||
}
|
||||
|
||||
double e_T2_ionization::roll_IonTheta1(double T_eV, double W_eV) const {
|
||||
double theta1;
|
||||
if (W_eV > 100) {
|
||||
double numerator = W_eV/T_eV;
|
||||
double denominator = (1-W_eV / T_eV)*(T_eV/(2*me_eV)) + 1;
|
||||
theta1 = asin(sqrt(numerator/denominator));
|
||||
} else {
|
||||
theta1 = rngUni->random()*pi/4;
|
||||
}
|
||||
return (theta1);
|
||||
}
|
||||
|
||||
double e_T2_ionization::roll_IonTheta2(double T_eV, double W_eV) const {
|
||||
double theta2;
|
||||
if (W_eV > 200) {
|
||||
double numerator = 1- W_eV/T_eV;
|
||||
double denominator = 1 + W_eV/(2*me_eV);
|
||||
theta2 = asin(sqrt(numerator/denominator));
|
||||
} else if (W_eV >= 50) {
|
||||
double decider = rngUni->random();
|
||||
if (decider < 0.9) {
|
||||
theta2 = 1 + rngUni->random() * pi/4 + pi/4;
|
||||
} else {
|
||||
theta2 = rngUni->random() * pi;
|
||||
}
|
||||
} else {
|
||||
theta2 = rngUni->random() * pi;
|
||||
}
|
||||
return(theta2);
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
//
|
||||
// electron_interactions.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef electron_interactions_hpp
|
||||
#define electron_interactions_hpp
|
||||
|
||||
#include "interaction_species.hpp"
|
||||
#include "function_container.hpp"
|
||||
|
||||
/*
|
||||
Elastic Scattering:
|
||||
Using Rutherford Model with screening parameter following
|
||||
Cross-sections for water vapour for the Monte Carlo electron track structure code from 10eV to the MeV region
|
||||
S Uehara et al 1993 Phys. Med. Biol. 38 1841
|
||||
*/
|
||||
class e_T2_elasticScattering : public Interaction {
|
||||
public:
|
||||
e_T2_elasticScattering(Population *Pop, UniRNG *rngUni, NormalRNG *rngNormal) : Interaction(electron, Pop, rngUni, rngNormal) {};
|
||||
|
||||
double get_macroSigma_m2(const Particle &interPart) const;
|
||||
InteractionOut do_Interaction (Particle *interPart) const;
|
||||
|
||||
private:
|
||||
vec3 calc_vNew_ms(vec3 vOld_ms, vec3 vT2_ms, double thetaLab, double phiLab) const;
|
||||
};
|
||||
|
||||
/*
|
||||
Ionization:
|
||||
Using BED-Model Kim and Rudd 1994
|
||||
*/
|
||||
class e_T2_ionization : public Interaction {
|
||||
static Average1D_FuncContainer BED_TCS_average_container;
|
||||
static Stacked2D_FuncContainer BED_SDCS_stacked_container;
|
||||
|
||||
ParticleBuilder PartBuilder;
|
||||
|
||||
public:
|
||||
e_T2_ionization(Population *Pop, UniRNG *rngUni, NormalRNG *rngNormal) : Interaction(electron, Pop, rngUni, rngNormal) {};
|
||||
|
||||
double get_macroSigma_m2(const Particle &interPart) const;
|
||||
InteractionOut do_Interaction (Particle *interPart) const;
|
||||
private:
|
||||
vec3 roll_vLab_ms(const Particle &interPart) const;
|
||||
double roll_ionW_eV(double T_eV) const;
|
||||
double roll_IonTheta1(double T_eV, double W_eV) const;
|
||||
double roll_IonTheta2(double T_eV, double W_eV) const;
|
||||
};
|
||||
|
||||
|
||||
#endif /* electron_interactions_hpp */
|
||||
@@ -1,30 +0,0 @@
|
||||
//
|
||||
// electron_population.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 07.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "electron_population.hpp"
|
||||
|
||||
double e_Density::get_Density_m3(vec3 loc_m) const {
|
||||
Katrin_Geo::check_inKatrin(loc_m);
|
||||
double physTime_s = Tim->get_physTime_s();
|
||||
double dens = e_Container.getDensity_m3(loc_m, physTime_s, xyz);
|
||||
return(dens);
|
||||
}
|
||||
|
||||
vec3 e_Density::roll_Speed_ms(vec3 loc_m) const {
|
||||
Katrin_Geo::check_inKatrin(loc_m);
|
||||
double E_eV = e_Container.roll_Energy_eV(loc_m, rngUni);
|
||||
double vAbs_ms = calc_Speed_from_Ekin_eV(E_eV, me_eV);
|
||||
vec3 v_ms = roll_uniform_direction(rngUni) * vAbs_ms;
|
||||
return(v_ms);
|
||||
}
|
||||
|
||||
void e_Density::up_Denisty(vec3 oldLoc_m, vec3 newLoc_m, double Ekin_eV) {
|
||||
double vAbs_ms = calc_Speed_from_Ekin_eV(Ekin_eV, me_eV);
|
||||
e_Container.upDensity(vAbs_ms, oldLoc_m, newLoc_m);
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
//
|
||||
// electron_population.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 07.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef electron_population_hpp
|
||||
#define electron_population_hpp
|
||||
|
||||
#include "timer.hpp"
|
||||
#include "density_container.hpp"
|
||||
#include "katrin_geo.hpp"
|
||||
|
||||
#include "population_base.h"
|
||||
#include "constants.h"
|
||||
|
||||
|
||||
class e_Density : public Population_Base, public RNG_Base {
|
||||
WGTS4D_ParticleTime_s_Container e_Container;
|
||||
Timer *Tim;
|
||||
|
||||
public:
|
||||
e_Density(Timer *Tim, UniRNG *rngUni, NormalRNG *rngNormal) : Population_Base(electron), RNG_Base(rngUni, rngNormal), e_Container(vec3(10,10,10), me_eV, zero, 2e4, 20) {
|
||||
this->Tim = Tim;
|
||||
};
|
||||
|
||||
double get_Density_m3(vec3 loc_m) const ;
|
||||
|
||||
vec3 roll_Speed_ms(vec3 loc_m) const;
|
||||
|
||||
void up_Denisty(vec3 oldLoc_m, vec3 newLoc_m, double Ekin_eV);
|
||||
};
|
||||
|
||||
|
||||
#endif /* electron_population_hpp */
|
||||
@@ -1,52 +0,0 @@
|
||||
//
|
||||
// find_species.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 03.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef find_species_h
|
||||
#define find_species_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "particle.hpp"
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline typename std::vector<T*>::iterator find_SpeciesItr(std::vector<T*> *Vec, species Species) {
|
||||
typename std::vector<T*>::iterator Itr;
|
||||
if (Vec->size() == 0) {
|
||||
Itr = Vec->end();
|
||||
} else {
|
||||
Itr = Vec->begin();
|
||||
while (Itr != Vec->end() ) {
|
||||
if ((*Itr)->get_Species() == Species) {
|
||||
break;
|
||||
}
|
||||
Itr++;
|
||||
}
|
||||
}
|
||||
return (Itr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline typename std::vector<T*>::const_iterator find_SpeciesConstItr(const std::vector<T*> *Vec, species Species) {
|
||||
typename std::vector<T*>::const_iterator Itr;
|
||||
if (Vec->size() == 0) {
|
||||
Itr = Vec->cend();
|
||||
} else {
|
||||
Itr = Vec->cbegin();
|
||||
while (Itr != Vec->cend() ) {
|
||||
if ( (*Itr)->get_Species() == Species) {
|
||||
break;
|
||||
}
|
||||
Itr++;
|
||||
}
|
||||
}
|
||||
return (Itr);
|
||||
}
|
||||
|
||||
|
||||
#endif /* find_species_h */
|
||||
@@ -1,188 +0,0 @@
|
||||
//
|
||||
// function_container.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 15.03.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "function_container.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
inline void Base_FuncContainer::averageMap_from_edgeMap (dim1Map *averageMap, dim1Map &edgeMap) {
|
||||
averageMap->clear();
|
||||
dim1Map::iterator curItr, afterItr;
|
||||
afterItr = edgeMap.begin();
|
||||
curItr = edgeMap.begin();
|
||||
afterItr++;
|
||||
while (afterItr!=edgeMap.end()) {
|
||||
averageMap->insert(dim1Pair( curItr->first + (afterItr->first-curItr->first)/2, curItr->second ));
|
||||
curItr++;
|
||||
afterItr++;
|
||||
}
|
||||
averageMap->insert(dim1Pair( curItr->first , curItr->second ));
|
||||
}
|
||||
|
||||
inline void Base_FuncContainer::stackedMap_from_averageMap (dim1Map *stackedMap, dim1Map &averageMap, double lowerEdge) {
|
||||
double tot = 0;
|
||||
dim1Map::iterator prevItr, currItr;
|
||||
prevItr = averageMap.begin();
|
||||
currItr = averageMap.begin();
|
||||
tot += (currItr->first - lowerEdge) * currItr->second;
|
||||
currItr ++;
|
||||
while (currItr!=averageMap.end()) {
|
||||
tot += (currItr->first - prevItr->first) * currItr->second;
|
||||
currItr++;
|
||||
prevItr++;
|
||||
}
|
||||
//tot = tot/(averageMap.rbegin()->first - lowerEdge);
|
||||
|
||||
stackedMap->clear();
|
||||
prevItr = averageMap.begin();
|
||||
currItr = averageMap.begin();
|
||||
double curVal = (currItr->first - lowerEdge)* currItr->second/tot;
|
||||
container_base::add_To_Map(stackedMap, deque<double> {curVal,currItr->first});
|
||||
currItr ++;
|
||||
while (currItr!=averageMap.end()) {
|
||||
curVal += (currItr->first - prevItr->first)*currItr->second/tot;
|
||||
container_base::add_To_Map(stackedMap, deque<double> {curVal,currItr->first});
|
||||
currItr++;
|
||||
prevItr++;
|
||||
}
|
||||
}
|
||||
|
||||
inline double Base_FuncContainer::sampleValue_from_stackedMap (const dim1Map &stackedMap, ranlib::Uniform<double> *rngUni) const {
|
||||
return (stackedMap.lower_bound(rngUni->random())->second);
|
||||
}
|
||||
|
||||
|
||||
void Base1D_FuncContainer::fillFromFunction(double (*f)(const double &), double minKey, double maxKey, int numpointsPerOrder) {
|
||||
int interval = numpointsPerOrder -1;
|
||||
int minI = floor(log10(minKey)*interval);
|
||||
int maxI = ceil(log10(maxKey)*interval);
|
||||
double x, fx;
|
||||
try {
|
||||
x = pow(10,double (minI)/double(interval));
|
||||
fx = f(x);
|
||||
} catch (...) {
|
||||
fx = f(x);
|
||||
}
|
||||
add_ankerpoint(x, fx);
|
||||
try {
|
||||
x = pow(10,double (maxI)/double(interval));
|
||||
fx = f(x);
|
||||
} catch (...) {
|
||||
fx = f(x);
|
||||
}
|
||||
add_ankerpoint(x, fx);
|
||||
for (int i = minI + 1;i<maxI;i++) {
|
||||
x = pow(10,double (i)/double(interval));
|
||||
fx = f(x);
|
||||
add_ankerpoint(x, fx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Average1D_FuncContainer::set_Map(dim1Map &edgeMap) {
|
||||
averageMap_from_edgeMap (&Map, edgeMap);
|
||||
}
|
||||
|
||||
void Average1D_FuncContainer::set_Map(Edge1D_FuncContainer &edgeContainer) {
|
||||
dim1Map edgeMap = edgeContainer.get_Map();
|
||||
set_Map(edgeMap);
|
||||
}
|
||||
|
||||
|
||||
void Edge2D_FuncContainer::get_Ionization_fromFunction(double (*f)(const double &, const double &), double minX, double maxX, int numpointsPerXOrder, int numYpoints) {
|
||||
int Xinterval = numpointsPerXOrder -1;
|
||||
int minXI = floor(log10(minX)*Xinterval);
|
||||
int maxXI = ceil(log10(maxX)*Xinterval);
|
||||
|
||||
int Yinterval = numYpoints-1;
|
||||
double minY, maxY;
|
||||
int minYI, maxYI;
|
||||
double x, y, fxy;
|
||||
|
||||
for (int XI = minXI; XI<=maxXI; XI++) {
|
||||
x = pow(10,double (XI)/double(Xinterval));
|
||||
minY = 1e-5;
|
||||
maxY = (x-EionT2_eV)/2;
|
||||
if (maxY<0) {
|
||||
add_ankerpoint(x,0,0);
|
||||
continue;
|
||||
}
|
||||
minYI = floor(log10(minY)*Yinterval);
|
||||
maxYI = ceil(log10(maxY)*Yinterval);
|
||||
for (int YI = minYI; YI<maxYI; YI++) {
|
||||
y = pow(10,double (YI)/double(Yinterval));
|
||||
fxy = f(x,y);
|
||||
add_ankerpoint(x, y,fxy);
|
||||
}
|
||||
add_ankerpoint(x,maxY,f(x,maxY));
|
||||
}
|
||||
}
|
||||
|
||||
void Edge2D_FuncContainer::get_Elastic_fromFunction(double (*f)(const double &, const double &), double minX, double maxX, int numpointsPerXOrder, int numpointsOverY) {
|
||||
int Xinterval = numpointsPerXOrder -1;
|
||||
int minXI = floor(log10(minX)*Xinterval);
|
||||
int maxXI = ceil(log10(maxX)*Xinterval);
|
||||
double x, y, fxy;
|
||||
|
||||
for (int XI = minXI; XI<=maxXI; XI++) {
|
||||
x = pow(10,double (XI)/double(Xinterval));
|
||||
for (int YI = 0; YI<numpointsOverY; YI++) {
|
||||
y = YI/(numpointsOverY-1)*pi;
|
||||
fxy = f(x,y);
|
||||
add_ankerpoint(x, y,fxy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Average2D_FuncContainer::set_Map(dim2Map &edgeMap) {
|
||||
// should template averageMap_from_edgeMap function and reuse it for first iteration...
|
||||
Map.clear();
|
||||
dim2Map::iterator curItr, afterItr;
|
||||
afterItr = edgeMap.begin();
|
||||
curItr = edgeMap.begin();
|
||||
afterItr++;
|
||||
dim1Map tempMap;
|
||||
while (afterItr!=edgeMap.end()) {
|
||||
averageMap_from_edgeMap (&tempMap, curItr->second);
|
||||
Map.insert(dim2Pair( curItr->first + (afterItr->first-curItr->first)/2, tempMap ));
|
||||
curItr++;
|
||||
afterItr++;
|
||||
}
|
||||
averageMap_from_edgeMap (&tempMap, curItr->second);
|
||||
Map.insert(dim2Pair( curItr->first , tempMap ));
|
||||
}
|
||||
|
||||
void Average2D_FuncContainer::set_Map(Edge2D_FuncContainer &edgeContainer) {
|
||||
dim2Map edgeMap = edgeContainer.get_Map();
|
||||
set_Map(edgeMap);
|
||||
}
|
||||
|
||||
|
||||
void Stacked2D_FuncContainer::set_Map(dim2Map &averageMap) {
|
||||
Map.clear();
|
||||
dim1Map tempMap;
|
||||
for (dim2Map::iterator Itr=averageMap.begin(); Itr!=averageMap.end() ; Itr++) {
|
||||
stackedMap_from_averageMap (&tempMap, Itr->second, 0);
|
||||
Map.insert(dim2Pair( Itr->first , tempMap ));
|
||||
}
|
||||
}
|
||||
|
||||
void Stacked2D_FuncContainer::set_Map(Average2D_FuncContainer &averageContainer) {
|
||||
dim2Map averageMap = averageContainer.get_Map();
|
||||
set_Map(averageMap);
|
||||
}
|
||||
|
||||
double Stacked2D_FuncContainer::sample_Value(double x, ranlib::Uniform<double> *rngUni) const {
|
||||
if (Map.rbegin()->first < x) {
|
||||
return (sampleValue_from_stackedMap (Map.rbegin()->second, rngUni));
|
||||
} else {
|
||||
return (sampleValue_from_stackedMap (Map.lower_bound(x)->second, rngUni));
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
//
|
||||
// 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 <random/uniform.h>
|
||||
|
||||
#include "container_base_functions.h"
|
||||
|
||||
typedef std::map<double,double> dim1Map;
|
||||
typedef std::pair<double,double> dim1Pair;
|
||||
|
||||
|
||||
// Base_FuncContainer: Provide Operation on dim1Maps.
|
||||
class Base_FuncContainer {
|
||||
protected:
|
||||
double interpolateFrom_Map (dim1Map &Map, double x) const;
|
||||
void averageMap_from_edgeMap (dim1Map *averageMap, dim1Map &edgeMap);
|
||||
void stackedMap_from_averageMap (dim1Map *stackedMap, dim1Map &averageMap, double lowerEdge = 0);
|
||||
double sampleValue_from_stackedMap (const dim1Map &stackedMap, ranlib::Uniform<double> *rngUni) const;
|
||||
};
|
||||
|
||||
// Base1D_Container: Provide Map and input output methods of the map.
|
||||
class Base1D_FuncContainer : protected Base_FuncContainer {
|
||||
public:
|
||||
Base1D_FuncContainer() {};
|
||||
Base1D_FuncContainer(std::string loadFilePath) {fillFromCSV(loadFilePath);};
|
||||
|
||||
void fillFromFunction(double (*f)(const double &), double minX, double maxX, int numpointsPerOrder);
|
||||
void fillFromCSV(std::string loadFilePath) {container_base::add_From_Csv (&Map, 1, loadFilePath);};
|
||||
void add_ankerpoint(double x, double fx) {container_base::add_To_Map(&Map, std::deque<double> {x,fx});};
|
||||
|
||||
void exportToFile(std::string exportFilePath) const {container_base::export_To_Csv(Map, exportFilePath);};
|
||||
|
||||
dim1Map get_Map() const {return (Map);}
|
||||
protected:
|
||||
dim1Map Map;
|
||||
} ;
|
||||
|
||||
// Edge1D_Container: To store values calculated values at given points.
|
||||
class Edge1D_FuncContainer : public Base1D_FuncContainer {
|
||||
public:
|
||||
Edge1D_FuncContainer() : Base1D_FuncContainer() {};
|
||||
Edge1D_FuncContainer(std::string loadFilePath) : Base1D_FuncContainer(loadFilePath){};
|
||||
|
||||
double interpolate(double x) const {return (container_base::interpolate_Value(Map,std::deque<double>{x}));};
|
||||
};
|
||||
|
||||
// Average1D_Container: Calculates new edges, so values from edge bin correspond to mean value.
|
||||
// From old edge bins let f(x_i,old)=f_i,old, for i=1,...,m
|
||||
// Calculate new edges for average bins: x_i,new = |x_i,old + x_i+1,old|/2 for i=1,...,m-1
|
||||
// x_m,new = x_m,old
|
||||
// for x_i,new < x <= x_(i+1) -> f(x) = f_(i+1),old for i=1,...,m-1
|
||||
// for x < x_1 -> f(x) = f_1,old and fox x > x_m -> f(x) = f_m,old
|
||||
class Average1D_FuncContainer : public Base1D_FuncContainer {
|
||||
public:
|
||||
Average1D_FuncContainer() : Base1D_FuncContainer() {};
|
||||
Average1D_FuncContainer(std::string loadFilePath) : Base1D_FuncContainer(loadFilePath){};
|
||||
Average1D_FuncContainer (dim1Map &edgeMap) {set_Map(edgeMap);};
|
||||
Average1D_FuncContainer (Edge1D_FuncContainer &edgeContainer) {set_Map(edgeContainer);};
|
||||
|
||||
void set_Map(dim1Map &edgeMap);
|
||||
void set_Map(Edge1D_FuncContainer &edgeContainer);
|
||||
|
||||
double get_Value(double x) const {return ( container_base::get_Value(Map, std::deque<double> {x}) );};
|
||||
};
|
||||
|
||||
|
||||
typedef std::map<double,dim1Map> dim2Map;
|
||||
typedef std::pair<double,dim1Map> dim2Pair;
|
||||
|
||||
// Base2D_Container: Analog to Base1D_Container but in 2 dimensions. Map stores a Map.
|
||||
class Base2D_FuncContainer : protected Base_FuncContainer {
|
||||
public:
|
||||
Base2D_FuncContainer() {};
|
||||
Base2D_FuncContainer(std::string loadFilePath) {fillFromCSV(loadFilePath);};
|
||||
|
||||
void fillFromCSV(std::string loadFilePath){container_base::add_From_Csv (&Map, 2, loadFilePath);};
|
||||
void add_ankerpoint(double x, double y, double fxy) {container_base::add_To_Map(&Map, std::deque<double> {x,y,fxy});};
|
||||
|
||||
void exportToFile(std::string exportFilePath) {container_base::export_To_Csv(Map, exportFilePath);};
|
||||
|
||||
dim2Map get_Map() const {return (Map);}
|
||||
protected:
|
||||
dim2Map Map;
|
||||
|
||||
} ;
|
||||
|
||||
// Edge2D_Container: Analog to Edge1D_Container
|
||||
class Edge2D_FuncContainer : public Base2D_FuncContainer {
|
||||
public:
|
||||
Edge2D_FuncContainer() : Base2D_FuncContainer() {};
|
||||
Edge2D_FuncContainer(std::string loadFilePath) : Base2D_FuncContainer(loadFilePath) {};
|
||||
|
||||
double interpolate(double x, double y) const {return (container_base::interpolate_Value(Map,std::deque<double>{x,y}));};
|
||||
|
||||
void get_Ionization_fromFunction(double (*f)(const double &, const double &), double minX, double maxX, int numpointsPerXOrder, int numpointsPerYOrder);
|
||||
void get_Elastic_fromFunction(double (*f)(const double &, const double &), double minX, double maxX, int numpointsPerXOrder, int numpointsOverY);
|
||||
};
|
||||
|
||||
// Average2D_Container:
|
||||
// Analog to Average1D_Container. First calculate new x bins.
|
||||
// Then within each new x bin calculate new y bins
|
||||
class Average2D_FuncContainer : public Base2D_FuncContainer {
|
||||
public:
|
||||
Average2D_FuncContainer() : Base2D_FuncContainer() {};
|
||||
Average2D_FuncContainer(std::string loadFilePath) : Base2D_FuncContainer(loadFilePath){};
|
||||
Average2D_FuncContainer (dim2Map &edgeMap) {set_Map(edgeMap);};
|
||||
Average2D_FuncContainer (Edge2D_FuncContainer &edgeContainer) {set_Map(edgeContainer);};
|
||||
|
||||
void set_Map(dim2Map &edgeMap);
|
||||
void set_Map(Edge2D_FuncContainer &edgeContainer);
|
||||
double get_Value(double x, double y) const {return ( container_base::get_Value(Map, std::deque<double> {x,y}) );};
|
||||
};
|
||||
|
||||
// Stacked2D_Container:
|
||||
// first key corresponds to x, second key to stacked up values f(x,y) from average Map normed and value to y
|
||||
class Stacked2D_FuncContainer : public Base2D_FuncContainer {
|
||||
public:
|
||||
Stacked2D_FuncContainer() : Base2D_FuncContainer() {};
|
||||
Stacked2D_FuncContainer(std::string loadFilePath) : Base2D_FuncContainer(loadFilePath){};
|
||||
Stacked2D_FuncContainer (Average2D_FuncContainer &averageContainer) {set_Map(averageContainer);};
|
||||
Stacked2D_FuncContainer (dim2Map &averageMap) {set_Map(averageMap);};
|
||||
|
||||
void set_Map(dim2Map &averageMap);
|
||||
void set_Map(Average2D_FuncContainer &averageContainer);
|
||||
|
||||
double sample_Value(double x, ranlib::Uniform<double> *rngUni) const;
|
||||
};
|
||||
|
||||
|
||||
#endif /* function_container_hpp */
|
||||
@@ -46,14 +46,14 @@ Particle Injector::injectElectron (const int &newId) {
|
||||
}
|
||||
|
||||
double Injector::roll_FermiEnergy_eV() {
|
||||
double pmax,Emin_eV, Emax_eV, Ecan_eV,eta1,eta2;
|
||||
double pmax,E_min_eV, E_max_eV, Ecan_eV,eta1,eta2;
|
||||
pmax = 1.5e-28; // From Plotting EnergyDistributionBetaDecay
|
||||
Emin_eV = zero;
|
||||
Emax_eV = TritiumDecayEndpoint_eV;
|
||||
E_min_eV = zero;
|
||||
E_max_eV = TritiumDecayEndpoint_eV;
|
||||
do {
|
||||
eta1 = rngUni->random();
|
||||
eta2 = rngUni->random();
|
||||
Ecan_eV = Emin_eV + eta1*(Emax_eV - Emin_eV);
|
||||
Ecan_eV = E_min_eV + eta1*(E_max_eV - E_min_eV);
|
||||
} while(eta2*pmax > get_FermiDecaySpectrumDensity(Ecan_eV));
|
||||
return(Ecan_eV);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class Injector : RNG_Base {
|
||||
static const int injectionMethod;
|
||||
static const double injectionEnergy_eV;
|
||||
|
||||
ParticleBuilder PartFac;
|
||||
Particle_Builder PartFac;
|
||||
|
||||
public:
|
||||
Injector() : RNG_Base(NULL, NULL) {};
|
||||
|
||||
@@ -9,62 +9,75 @@
|
||||
#ifndef interaction_base_hpp
|
||||
#define interaction_base_hpp
|
||||
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
|
||||
#include "particle.hpp"
|
||||
#include "population.hpp"
|
||||
|
||||
#include "error_types.h"
|
||||
|
||||
|
||||
class InteractionOut {
|
||||
bool deleteCur;
|
||||
std::deque <Particle> newParticles;
|
||||
#include "sub_interaction_base.h"
|
||||
|
||||
#include "process_base.h"
|
||||
|
||||
|
||||
class Interaction_Base : public Process_Base {
|
||||
Sub_Interaction_Base **SubInteractions;
|
||||
int numSubInteractions = 0;
|
||||
|
||||
UniRNG *rngUni;
|
||||
|
||||
public:
|
||||
InteractionOut() {reset();};
|
||||
|
||||
void reset() {
|
||||
deleteCur = false;
|
||||
newParticles.empty();
|
||||
}
|
||||
|
||||
void set_deleteCur(const bool &deleteCur) {this->deleteCur = deleteCur;}
|
||||
void set_newParticles(const std::deque<Particle> &newParticles) {this->newParticles = newParticles;}
|
||||
void add_newParticle(const Particle &newParticle) {newParticles.push_back(newParticle);}
|
||||
|
||||
void appendDeque(std::deque<Particle> *Que, int *currentNewID) {
|
||||
Particle curPart;
|
||||
for (std::deque<Particle>::iterator Itr = newParticles.begin();Itr!=newParticles.end();Itr++) {
|
||||
curPart = (*Itr);
|
||||
curPart.set_Id(*currentNewID);
|
||||
currentNewID++;
|
||||
Que->push_back(curPart);
|
||||
}
|
||||
}
|
||||
|
||||
bool terminateCurrent() const {return(deleteCur);};
|
||||
//std::deque<Particle> get_newParticles() const {return(newParticles);};
|
||||
};
|
||||
|
||||
|
||||
class Interaction : public RNG_Base {
|
||||
protected:
|
||||
Population *Pop;
|
||||
species Species;
|
||||
|
||||
public:
|
||||
Interaction(species Species, Population *Pop, UniRNG *rngUni, NormalRNG *rngNormal) : RNG_Base(rngUni, rngNormal) {
|
||||
this->Species = Species;
|
||||
this->Pop = Pop;
|
||||
Interaction_Base(species this_species, UniRNG *rngUni) : Process_Base (this_species) {
|
||||
this->rngUni = rngUni;
|
||||
};
|
||||
|
||||
species get_Species() const {return(Species);}
|
||||
void add(Sub_Interaction_Base *addSubInteraction);
|
||||
|
||||
InteractionOut do_Interaction(Particle *interPart);
|
||||
double get_macroSigma_m2(const Particle &interPart);
|
||||
|
||||
virtual double get_macroSigma_m2(const Particle &interPart) const = 0;
|
||||
virtual InteractionOut do_Interaction (Particle *interPart) const = 0;
|
||||
};
|
||||
|
||||
|
||||
inline InteractionOut Interaction_Base::do_Interaction(Particle *interPart) {
|
||||
double macroSigma_m2 = get_macroSigma_m2(*interPart);
|
||||
|
||||
double currentStackedSigma = zero;
|
||||
double targetStackedSigma = rngUni->random() * macroSigma_m2;
|
||||
|
||||
|
||||
for (int i = 0; i < numSubInteractions; i++) {
|
||||
currentStackedSigma += SubInteractions[i]->get_macroSigma_m2(*interPart);
|
||||
if (currentStackedSigma > targetStackedSigma) {
|
||||
return (SubInteractions[i]->do_Interaction(interPart));
|
||||
}
|
||||
}
|
||||
std::stringstream ss;
|
||||
ss<<"Interaction_Base::do_Interactio: No Interaction selected.\n";
|
||||
throw MyException (ss.str());
|
||||
}
|
||||
|
||||
inline double Interaction_Base::get_macroSigma_m2(const Particle &interPart) {
|
||||
double macroSigma_m2 = zero;
|
||||
for (int i = 0; i < numSubInteractions; i++) {
|
||||
macroSigma_m2 += SubInteractions[i]->get_macroSigma_m2(interPart);
|
||||
}
|
||||
return(macroSigma_m2);
|
||||
}
|
||||
|
||||
inline void Interaction_Base::add(Sub_Interaction_Base *addSubInteraction) {
|
||||
if (numSubInteractions != 0) {
|
||||
Sub_Interaction_Base *tempArray[numSubInteractions];
|
||||
for (int i = 0; i < numSubInteractions; i++) {
|
||||
tempArray[i] = SubInteractions[i];
|
||||
}
|
||||
delete[] SubInteractions;
|
||||
SubInteractions = new Sub_Interaction_Base *[numSubInteractions + 1];
|
||||
for (int i = 0; i < numSubInteractions; i++) {
|
||||
SubInteractions[i] = tempArray[i];
|
||||
}
|
||||
} else {
|
||||
SubInteractions = new Sub_Interaction_Base *[numSubInteractions + 1];
|
||||
}
|
||||
SubInteractions[numSubInteractions] = addSubInteraction;
|
||||
numSubInteractions += 1;
|
||||
}
|
||||
|
||||
|
||||
#endif /* interaction_base_h */
|
||||
|
||||
@@ -8,38 +8,49 @@
|
||||
|
||||
#include "interaction_builder.hpp"
|
||||
|
||||
#include "eT2_elastic.h"
|
||||
#include "eT2_ionization.h"
|
||||
#include "e_T2I_recombination.h"
|
||||
|
||||
const int InteractionBuilder::eT2elastic = getParameter("eT2elastic");
|
||||
const int InteractionBuilder::eT2ionization = getParameter("eT2ionization");
|
||||
#include "TT2_elastic.h"
|
||||
|
||||
InteractionProcessor InteractionBuilder::build_InteractionProcessor(Population *Pop, UniRNG *rngUni, NormalRNG *rngNormal) {
|
||||
InteractionProcessor InterProcessor;
|
||||
InterProcessor.add_ParticleInteraction(build_eInteractions(Pop, rngUni, rngNormal));
|
||||
InterProcessor.add_ParticleInteraction(build_TInteractions(Pop, rngUni, rngNormal));
|
||||
return(InterProcessor);
|
||||
const int Interaction_Builder::eT2elastic = getParameter("eT2elastic");
|
||||
const int Interaction_Builder::eT2ionization = getParameter("eT2ionization");
|
||||
|
||||
|
||||
Interaction_Manager Interaction_Builder::build(Population_Manager *Populations, UniRNG *rngUni) {
|
||||
Interaction_Manager Interactions;
|
||||
Interactions.add(build_electron(Populations, rngUni));
|
||||
Interactions.add(build_tritiumI(Populations, rngUni));
|
||||
Interactions.add(build_tritium2I(Populations, rngUni));
|
||||
return(Interactions);
|
||||
}
|
||||
|
||||
ParticleInteractions* InteractionBuilder::build_eInteractions(Population *Pop, UniRNG *rngUni, NormalRNG *rngNormal) {
|
||||
ParticleInteractions* eInteractions = new ParticleInteractions(electron, Pop, rngUni, rngNormal);
|
||||
Interaction_Base* Interaction_Builder::build_electron(Population_Manager *Populations, UniRNG *rngUni) {
|
||||
Interaction_Base *eInteraction = new Interaction_Base(electron, rngUni);
|
||||
Population_Base *T2Population = Populations->find(tritium2);
|
||||
Population_Base *T2IPopulation = Populations->find(tritium2I);
|
||||
|
||||
if (eT2elastic == 1) {
|
||||
eInteractions->add_Interaction(new e_T2_elasticScattering(Pop, rngUni, rngNormal));
|
||||
eInteraction->add(new eT2_Elastic(T2Population, rngUni));
|
||||
}
|
||||
if (eT2ionization == 1) {
|
||||
eInteractions->add_Interaction(new e_T2_ionization(Pop, rngUni, rngNormal));
|
||||
eInteraction->add(new eT2_T2I_Ionization_Container(T2Population, rngUni));
|
||||
}
|
||||
return(eInteractions);
|
||||
eInteraction->add(new eT2I_Recombination(T2IPopulation, rngUni));
|
||||
return(eInteraction);
|
||||
}
|
||||
|
||||
ParticleInteractions* InteractionBuilder::build_TInteractions(Population *Pop, UniRNG *rngUni, NormalRNG *rngNormal) {
|
||||
ParticleInteractions* TInteractions = new ParticleInteractions(tritium, Pop, rngUni, rngNormal);
|
||||
Interaction_Base* Interaction_Builder::build_tritiumI(Population_Manager *Populations, UniRNG *rngUni) {
|
||||
Interaction_Base *TI_Interaction = new Interaction_Base(tritiumI, rngUni);
|
||||
Population_Base *T2Population = Populations->find(tritium2);
|
||||
|
||||
TInteractions->add_Interaction(new T_T2_elasticScattering(Pop, rngUni, rngNormal));
|
||||
//TI_Interaction->add(new TT2_Elastic(T2Population, rngUni));
|
||||
|
||||
return(TInteractions);
|
||||
return(TI_Interaction);
|
||||
}
|
||||
|
||||
/*
|
||||
ParticleInteractions InteractionBuilder::build_T2Interactions() {
|
||||
|
||||
Interaction_Base* Interaction_Builder::build_tritium2I(Population_Manager *Populations, UniRNG *rngUni) {
|
||||
Interaction_Base *TI2_Interaction = new Interaction_Base(tritium2I, rngUni);
|
||||
return(TI2_Interaction);
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -9,25 +9,25 @@
|
||||
#ifndef interaction_builder_hpp
|
||||
#define interaction_builder_hpp
|
||||
|
||||
#include "population.hpp"
|
||||
#include "interaction_processor.hpp"
|
||||
#include "interaction_species.hpp"
|
||||
#include "electron_interactions.hpp"
|
||||
#include "tritium_interactions.hpp"
|
||||
#include "interaction_base.h"
|
||||
#include "manager_base.h"
|
||||
|
||||
#include "population_builder.hpp"
|
||||
|
||||
class InteractionBuilder {
|
||||
typedef Manager_Base<Interaction_Base> Interaction_Manager;
|
||||
|
||||
class Interaction_Builder {
|
||||
static const int eT2ionization;
|
||||
static const int eT2elastic;
|
||||
|
||||
public:
|
||||
InteractionBuilder() {};
|
||||
Interaction_Builder() {};
|
||||
|
||||
static InteractionProcessor build_InteractionProcessor(Population *Pop, UniRNG *rngUni, NormalRNG *rngNormal);
|
||||
static Interaction_Manager build(Population_Manager *Populations, UniRNG *rngUni);
|
||||
private:
|
||||
static ParticleInteractions* build_eInteractions(Population *Pop, UniRNG *rngUni, NormalRNG *rngNormal);
|
||||
static ParticleInteractions* build_TInteractions(Population *Pop, UniRNG *rngUni, NormalRNG *rngNormal);
|
||||
|
||||
static Interaction_Base* build_electron(Population_Manager *Populations, UniRNG *rngUni);
|
||||
static Interaction_Base* build_tritiumI(Population_Manager *Populations, UniRNG *rngUni);
|
||||
static Interaction_Base* build_tritium2I(Population_Manager *Populations, UniRNG *rngUni);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
//
|
||||
// interaction_processor.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "interaction_processor.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
InteractionOut InteractionProcessor::do_Interaction(Particle *interPart) const {
|
||||
species Species = interPart->get_Species();
|
||||
ParticleInteractionsVec::const_iterator Itr = find_ParticleInteraction(Species);
|
||||
if (Itr == ParticleInteractions.end()) {
|
||||
stringstream ss;
|
||||
ss<<"InteractionProcessor::do_Interaction: No Interaction declare for Particles of Species:\n"<<Species<<"\n";
|
||||
throw MyException (ss.str());
|
||||
|
||||
}
|
||||
return ( (*Itr)->do_Interaction(interPart) );
|
||||
}
|
||||
|
||||
double InteractionProcessor::get_macroSigma_m2(const Particle &interPart) const {
|
||||
double macroSigma_m2 = 0;
|
||||
species Species = interPart.get_Species();
|
||||
ParticleInteractionsVec::const_iterator Itr = find_ParticleInteraction(Species);
|
||||
if (Itr != ParticleInteractions.end()) {
|
||||
macroSigma_m2 = (*Itr)->get_macroSigma_m2(interPart);
|
||||
} else {
|
||||
cout<<"Warning: No Interaction for Particle of Species"<<Species<<"\n";
|
||||
}
|
||||
return (macroSigma_m2);
|
||||
}
|
||||
|
||||
|
||||
void InteractionProcessor::add_ParticleInteraction(class ParticleInteractions* particleInteraction) {
|
||||
if (empty()) {
|
||||
} else if (find_ParticleInteraction(particleInteraction->get_Species()) != ParticleInteractions.end()) {
|
||||
stringstream ss;
|
||||
ss<<"InteractionProcessor::add_ParticleInteraction: Species already exists.\nSpecies:\t"<<particleInteraction->get_Species()<<"\n";
|
||||
throw MyException (ss.str());
|
||||
}
|
||||
ParticleInteractions.push_back(particleInteraction);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
//
|
||||
// interaction_processor.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef interaction_processor_hpp
|
||||
#define interaction_processor_hpp
|
||||
|
||||
#include "interaction_species.hpp"
|
||||
|
||||
#include "find_species.h"
|
||||
|
||||
typedef std::vector <ParticleInteractions*> ParticleInteractionsVec;
|
||||
|
||||
|
||||
class InteractionProcessor {
|
||||
ParticleInteractionsVec ParticleInteractions;
|
||||
|
||||
public:
|
||||
InteractionProcessor() {};
|
||||
|
||||
InteractionOut do_Interaction(Particle *interPart) const;
|
||||
double get_macroSigma_m2(const Particle &interPart) const;
|
||||
|
||||
public:
|
||||
void add_ParticleInteraction(class ParticleInteractions* particleInteraction);
|
||||
|
||||
bool empty() const {return (ParticleInteractions.size()==0 ? true : false);}
|
||||
private:
|
||||
ParticleInteractionsVec::const_iterator find_ParticleInteraction (species findSpec) const {return (find_SpeciesConstItr(&ParticleInteractions, findSpec));}
|
||||
ParticleInteractionsVec::iterator find_ParticleInteraction (species findSpec) {return (find_SpeciesItr(&ParticleInteractions, findSpec));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* interaction_processor_hpp */
|
||||
@@ -1,62 +0,0 @@
|
||||
//
|
||||
// interaction_species.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 27.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "interaction_species.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
InteractionOut ParticleInteractions::do_Interaction(Particle *interPart) const {
|
||||
double macroSigma_m2 = get_macroSigma_m2(*interPart);
|
||||
if (macroSigma_m2 == 0) {
|
||||
stringstream ss;
|
||||
ss<<"ParticleInteractions::do_Interaction: Interaction Cross Section = 0 for particle of Species "<<get_Species()<<".\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
double currentStackedSigma = 0;
|
||||
double targetStackedSigma = rngUni->random() * macroSigma_m2;
|
||||
InteractionsVec::const_iterator Itr = Interactions.cbegin();
|
||||
do {
|
||||
currentStackedSigma += (*Itr)->get_macroSigma_m2(*interPart);
|
||||
Itr++;
|
||||
} while(currentStackedSigma < targetStackedSigma);
|
||||
Itr--;
|
||||
return ((*Itr)->do_Interaction(interPart));
|
||||
}
|
||||
|
||||
double ParticleInteractions::get_macroSigma_m2(const Particle &interPart) const {
|
||||
double macroSigma_m2 = 0;
|
||||
if (!empty()) {
|
||||
for (InteractionsVec::const_iterator Itr = Interactions.begin();Itr!=Interactions.end();Itr++) {
|
||||
macroSigma_m2 += (*Itr)->get_macroSigma_m2(interPart);
|
||||
}
|
||||
} else {
|
||||
//cout<<"Warning: No Interaction for Particle of Type "<<get_Species()<<"\n";
|
||||
}
|
||||
return(macroSigma_m2);
|
||||
}
|
||||
|
||||
void ParticleInteractions::add_Interaction(Interaction* addInteraction) {
|
||||
if (Interactions.size()>0) {
|
||||
for (InteractionsVec::iterator Itr = Interactions.begin();Itr!=Interactions.end();Itr++) {
|
||||
if ( typeid(addInteraction) == typeid(Itr)) {
|
||||
stringstream ss;
|
||||
ss<<"ParticleInteractions::add_Interaction: Interactions already exists.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (addInteraction->get_Species() != get_Species()) {
|
||||
stringstream ss;
|
||||
ss<<"ParticleInteractions::add_Interaction: Species of adding Interaction missmatches this ParticleInteractions species: \nThis Species:\t"<<get_Species()<<"\nadding Species:\t"<<addInteraction->get_Species()<<"\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
Interactions.push_back(addInteraction);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
//
|
||||
// interaction_species.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 27.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef interaction_species_hpp
|
||||
#define interaction_species_hpp
|
||||
|
||||
#include "population.hpp"
|
||||
|
||||
#include "interaction_base.h"
|
||||
|
||||
typedef std::vector<Interaction*> InteractionsVec;
|
||||
|
||||
|
||||
class ParticleInteractions : public RNG_Base {
|
||||
Population *Pop;
|
||||
species Species;
|
||||
InteractionsVec Interactions;
|
||||
|
||||
public:
|
||||
ParticleInteractions(species Species, Population *Pop, UniRNG *rngUni, NormalRNG *rngNormal) : RNG_Base(rngUni, rngNormal) {
|
||||
this->Pop = Pop;
|
||||
this->Species = Species;
|
||||
};
|
||||
|
||||
InteractionOut do_Interaction(Particle *interPart) const;
|
||||
double get_macroSigma_m2(const Particle &interPart) const;
|
||||
|
||||
void add_Interaction(Interaction* addInteraction);
|
||||
|
||||
species get_Species() const {return (Species);};
|
||||
bool empty() const {return (Interactions.size()==0 ? true : false);}
|
||||
};
|
||||
|
||||
|
||||
#endif /* interaction_species_hpp */
|
||||
@@ -16,7 +16,7 @@ class Katrin_Fields {
|
||||
static const double wgtsMagField_T;
|
||||
|
||||
public:
|
||||
Katrin_Fields(){};
|
||||
Katrin_Fields() {};
|
||||
|
||||
static vec3 getMagField_T(vec3 loc_m) {
|
||||
Katrin_Geo::check_inKatrin(loc_m);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#define kinematics_h
|
||||
|
||||
#include <sstream>
|
||||
#include <blitz/array.h>
|
||||
#include <blitz/tinyvec2.h>
|
||||
|
||||
#include "constants.h"
|
||||
@@ -90,38 +91,39 @@ inline double calc_Speed_from_Ekin_eV(const double &Ekin_eV, const double &mass_
|
||||
}
|
||||
|
||||
inline vec3 calc_newDirection(const vec3 &direction_old, const double &theta_change, const double &phi_change) {
|
||||
// Transformation of direction following Plante and Cucinotta
|
||||
double theta_old = acos(direction_old[2]/vec3Abs(direction_old));
|
||||
double phi_old = atan2(direction_old[1],direction_old[0]);
|
||||
|
||||
double A3 = sin(theta_change)*cos(phi_change);
|
||||
double A4 = A3*cos(theta_old) + cos(theta_change)*sin(theta_old);
|
||||
double A5 = sin(theta_change)*sin(phi_change);
|
||||
double A11 = A4*cos(phi_old) - A5*sin(phi_old);
|
||||
double A21 = A4*sin(phi_old) + A5*cos(phi_old);
|
||||
double theta_new = acos( cos(theta_old)*cos(theta_change)-A3*sin(theta_old) );
|
||||
|
||||
// Get right phi1, maybe more elegant way later. Problem comes from reverse functions only being on range of pi. So combine both statements to get proper phi over 2pi.
|
||||
int digits = 6;
|
||||
double fac = pow(10,digits);
|
||||
double phi_new = -1;
|
||||
double phi_new_candidates [4];
|
||||
phi_new_candidates[0] = acos( roundf ( A11/sin(theta_new) *fac)/fac );
|
||||
phi_new_candidates[1] = 2*pi - phi_new_candidates[0];
|
||||
phi_new_candidates[2] = asin ( roundf ( A21/sin(theta_new) *fac)/fac );
|
||||
phi_new_candidates[3] = pi - phi_new_candidates[2];
|
||||
phi_new_candidates[2] = (phi_new_candidates[2] > 0) ? phi_new_candidates[2] : 2*pi + phi_new_candidates[2];
|
||||
for (int i=0;i<3;i++) {
|
||||
for (int j=i+1;j<4;j++) {
|
||||
if (phi_new_candidates[i]-phi_new_candidates[j] < 0.0001) {
|
||||
phi_new = phi_new_candidates[i];
|
||||
}
|
||||
}
|
||||
// Alireza Haghighat: Appendix 3 (p.249)
|
||||
vec3 nOld = direction_old/vec3Abs(direction_old);
|
||||
double u = nOld[0];
|
||||
double v = nOld[1];
|
||||
double w = nOld[2];
|
||||
double s = sqrt(1-w*w);
|
||||
double uNew, vNew, wNew;
|
||||
if (w!=1) {
|
||||
uNew = -(u*w/s*cos(phi_change) - v/s*sin(phi_change))*sin(theta_change) + u*cos(theta_change);
|
||||
vNew = -(v*w/s*cos(phi_change) + u/s*sin(phi_change))*sin(theta_change) + v*cos(theta_change);
|
||||
wNew = s*(sin(theta_change)*cos(phi_change)) + w*cos(theta_change);
|
||||
} else {
|
||||
uNew = sin(theta_change)*cos(phi_change);
|
||||
vNew = sin(theta_change)*sin(phi_change);
|
||||
wNew = cos(theta_change);
|
||||
}
|
||||
if (phi_new == -1) {
|
||||
throw MyException("Interaction::getElaNewDir: phi1 not found.");
|
||||
return(vec3(uNew, vNew, wNew));
|
||||
}
|
||||
|
||||
inline double get_z_m(const vec3 &loc_m) {
|
||||
return (loc_m[2]);
|
||||
}
|
||||
|
||||
inline double get_r_m(const vec3 &loc_m) {
|
||||
return (sqrt(loc_m[0]*loc_m[0] + loc_m[1]*loc_m[1]));
|
||||
}
|
||||
|
||||
inline double get_phi(const vec3 &loc_m) {
|
||||
if (loc_m[0] >= 0) {
|
||||
return ( acos(loc_m[1]/get_r_m(loc_m)) );
|
||||
} else {
|
||||
return ( 2*pi - acos(loc_m[1]/get_r_m(loc_m)) );
|
||||
}
|
||||
return(vec3(sin(theta_new)*cos(phi_new) , sin(theta_new)*sin(phi_new) , cos(theta_new)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,13 +7,14 @@
|
||||
//
|
||||
|
||||
#include "simulation.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
|
||||
clock_t start = clock();
|
||||
Simulation Sim;
|
||||
Sim.doit();
|
||||
cout<<"Duration: "<< ( clock() - start ) / (double) CLOCKS_PER_SEC <<'\n';
|
||||
|
||||
}
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
//
|
||||
// mover.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "mover.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "katrin_fields.hpp"
|
||||
|
||||
#include "read_system.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
const int Mover::propagationMethod = getParameter("propagationMethod");
|
||||
const double Mover::dt_s = getParameter("dt_s");
|
||||
|
||||
void Mover::moveParticle(Particle *movePart, const double &distance_m) {
|
||||
this->movePart = movePart;
|
||||
if (propagationMethod==0) {
|
||||
do_DriftApproximationMovement(distance_m);
|
||||
} else if (propagationMethod==1) {
|
||||
do_BorisPushMovement(distance_m);
|
||||
} else {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::move_electron: propagationMethod="<<propagationMethod<<" not valid.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
this->movePart = NULL;
|
||||
}
|
||||
|
||||
// Drift Approximation: Assume constant B and only movement out in z=0, z=wgtsLength_m...
|
||||
void Mover::do_DriftApproximationMovement(const double &distance_m) {
|
||||
vec3 oldLoc_m = movePart->get_Location_m();
|
||||
vec3 newLoc_m = oldLoc_m;
|
||||
|
||||
double znew_m = getDrift_znew_m(distance_m);
|
||||
doDrift_WallInteraction(&oldLoc_m, &znew_m);
|
||||
newLoc_m[2] = znew_m;
|
||||
|
||||
movePart->set_Location_m(newLoc_m);
|
||||
Log->log_Particle(*movePart,oldLoc_m);
|
||||
}
|
||||
double Mover::getDrift_znew_m(const double &distance_m) {
|
||||
double zold_m = movePart->get_Location_m()[2];
|
||||
|
||||
vec3 v_ms = movePart->get_Speed_ms();
|
||||
double vTotAbs_ms = vec3Abs(v_ms);
|
||||
double vForwardAbs_ms = vec3Abs(vec3(0,0,v_ms[2]));
|
||||
double zDir = v_ms[2] < 0 ? -1 : 1;
|
||||
|
||||
double znew_m = zold_m + zDir*vForwardAbs_ms/vTotAbs_ms * distance_m;
|
||||
return (znew_m);
|
||||
}
|
||||
|
||||
void Mover::doDrift_WallInteraction(vec3 *oldLoc_m, double *znew_m) {
|
||||
if (*znew_m >= Katrin_Geo::get_z_WGTSend_m()) { // Moveing into Spectrometer and reversing Speed.
|
||||
vec3 reverseLoc_m = *oldLoc_m;
|
||||
|
||||
// Log Movement before Reflection
|
||||
reverseLoc_m[2] = Katrin_Geo::get_z_WGTSend_m();
|
||||
movePart->set_Location_m(reverseLoc_m);
|
||||
Log->log_Particle(*movePart,*oldLoc_m);
|
||||
|
||||
// Final Movement
|
||||
*oldLoc_m = reverseLoc_m;
|
||||
*znew_m = Katrin_Geo::get_z_WGTSend_m() - (*znew_m - Katrin_Geo::get_z_WGTSend_m());
|
||||
movePart->set_Speed_ms( -1*(movePart->get_Speed_ms()) );
|
||||
}
|
||||
if (*znew_m <= Katrin_Geo::get_z_RW_m()) {
|
||||
*znew_m = Katrin_Geo::get_z_RW_m();
|
||||
}
|
||||
}
|
||||
|
||||
void Mover::do_BorisPushMovement(const double &distance_m) {
|
||||
vec3 loc_m, E_Vm ,B_T;
|
||||
// Prepare detection for change of z direction for logging
|
||||
double oldzDir = movePart->get_Speed_ms()[2] < 0 ? -1 : 1;
|
||||
vec3 oldLoc_m = movePart->get_Location_m();
|
||||
|
||||
double traveledDistance_m = 0;
|
||||
while (traveledDistance_m < distance_m) {
|
||||
loc_m = movePart->get_Location_m();
|
||||
E_Vm = Katrin_Fields::getElField_Vm(loc_m);
|
||||
B_T = Katrin_Fields::getMagField_T(loc_m);
|
||||
|
||||
traveledDistance_m += doBoris_singleStep_m(E_Vm, B_T);
|
||||
if (doBoris_WallInteraction() == true) {
|
||||
Log->log_Particle(*movePart, oldLoc_m);
|
||||
return;
|
||||
}
|
||||
doBoris_LogzDirChange(&oldzDir, &oldLoc_m); // Log if z direction changes, and adapt quantities
|
||||
}
|
||||
Log->log_Particle(*movePart, oldLoc_m);
|
||||
return;
|
||||
}
|
||||
|
||||
double Mover::doBoris_singleStep_m(const vec3 &E_Vm , const vec3 &B_T) {
|
||||
double distance_m;
|
||||
vec3 x_m = movePart->get_Location_m();
|
||||
vec3 v_ms = movePart->get_Speed_ms();
|
||||
x_m += dt_s/2 * v_ms;
|
||||
distance_m = dt_s/2 * vec3Abs(v_ms);
|
||||
doBoris_speedChange(E_Vm , B_T);
|
||||
x_m += dt_s/2 * v_ms;
|
||||
distance_m += dt_s/2 * vec3Abs(v_ms);
|
||||
movePart->set_Location_m(x_m);
|
||||
return(distance_m);
|
||||
}
|
||||
|
||||
void Mover::doBoris_speedChange(const vec3 &E_Vm, const vec3 &B_T) {
|
||||
double q_C = movePart->get_Charge_nat() * e_C;
|
||||
double m_kg = movePart->get_Mass_eV() * e_C/c_ms/c_ms;
|
||||
vec3 v_ms = movePart->get_Speed_ms();
|
||||
|
||||
vec3 t = q_C*dt_s/(2*m_kg) * B_T;
|
||||
vec3 s = (2*t)/(1+dot(t,t));
|
||||
vec3 vMinus_ms = v_ms + (q_C*E_Vm*dt_s)/(2*m_kg);
|
||||
vec3 vPrime_ms = vMinus_ms + cross(vMinus_ms,t);
|
||||
vec3 vPlus_ms = vMinus_ms + cross(vPrime_ms,s);
|
||||
v_ms = vPlus_ms + q_C/m_kg*E_Vm*0.5*dt_s;
|
||||
movePart->set_Speed_ms(v_ms);
|
||||
}
|
||||
|
||||
bool Mover::doBoris_WallInteraction() {
|
||||
vec3 loc_m = movePart->get_Location_m();
|
||||
double r_m = movePart->get_Radius_m();
|
||||
if (loc_m[2]<=Katrin_Geo::get_z_RW_m()) { // Rear Wall Termination
|
||||
vec3 newLoc_m = movePart->get_Location_m();
|
||||
newLoc_m[2] = 0;
|
||||
movePart->set_Location_m(newLoc_m);
|
||||
return (true);
|
||||
}
|
||||
if (r_m>=Katrin_Geo::get_radius_m()) { // WGTS Wall Termination
|
||||
vec3 newLoc_m = movePart->get_Location_m();
|
||||
double z_m = newLoc_m[2];
|
||||
newLoc_m[2] = 0;
|
||||
newLoc_m = (Katrin_Geo::get_radius_m() * 1.01)/vec3Abs(newLoc_m) * newLoc_m; //1.01 to move Particle slightly out of WGTS
|
||||
newLoc_m[2] = z_m;
|
||||
return (true);
|
||||
}
|
||||
if (loc_m[2]>=Katrin_Geo::get_z_WGTSend_m()) { // Spectrometer Reflection
|
||||
movePart->set_Speed_ms( -1*(movePart->get_Speed_ms()) );
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
void Mover::doBoris_LogzDirChange(double *oldzDir, vec3 *oldLoc_m) {
|
||||
double zDir = movePart->get_Speed_ms()[2] < 0 ? -1 : 1;
|
||||
if (*oldzDir != zDir) {
|
||||
Log->log_Particle(*movePart, *oldLoc_m);
|
||||
*oldzDir = zDir;
|
||||
*oldLoc_m = movePart->get_Location_m();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// mover.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef mover_hpp
|
||||
#define mover_hpp
|
||||
|
||||
#include "particle.hpp"
|
||||
#include "h5_logger.hpp"
|
||||
|
||||
#include "kinematics.h"
|
||||
|
||||
|
||||
// Mover: Moves Particles within WGTS using parameter propagationMethod to determine Method.
|
||||
// Also Logging during movement
|
||||
class Mover {
|
||||
static const int propagationMethod;
|
||||
static const double dt_s;
|
||||
|
||||
H5_Logger *Log;
|
||||
|
||||
Particle *movePart;
|
||||
|
||||
public:
|
||||
Mover() {this->Log = NULL;}
|
||||
Mover(H5_Logger *Log) {
|
||||
this->Log = Log;
|
||||
};
|
||||
|
||||
void moveParticle(Particle *movePart, const double &distance_m);
|
||||
|
||||
private:
|
||||
void do_DriftApproximationMovement(const double &distance_m);
|
||||
double getDrift_znew_m(const double &distance_m);
|
||||
void doDrift_WallInteraction(vec3 *oldLoc_m, double *znew_m);
|
||||
|
||||
void do_BorisPushMovement(const double &distance_m);
|
||||
double doBoris_singleStep_m(const vec3 &E_Vm , const vec3 &B_T);
|
||||
void doBoris_speedChange(const vec3 &E_Vm, const vec3 &B_T);
|
||||
bool doBoris_WallInteraction();
|
||||
void doBoris_LogzDirChange(double *oldzDir, vec3 *oldLoc_m);
|
||||
};
|
||||
|
||||
|
||||
#endif /* mover_hpp */
|
||||
@@ -11,20 +11,54 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
ostream& operator<<(ostream& os, const species& SpecOut) {
|
||||
switch (SpecOut) {
|
||||
std::string get_species_string(const species &spec) {
|
||||
string res;
|
||||
switch (spec) {
|
||||
case electron:
|
||||
os<<"e-";
|
||||
res = "e-";
|
||||
break;
|
||||
case tritium:
|
||||
os<<"T3";
|
||||
case tritiumI:
|
||||
res = "T+";
|
||||
break;
|
||||
case tritium2I:
|
||||
res = "T2+";
|
||||
break;
|
||||
case tritium2:
|
||||
os<<"T_2";
|
||||
res = "T2";
|
||||
break;
|
||||
default:
|
||||
os<<"";
|
||||
stringstream ss;
|
||||
ss<<"get_species_string: Species not defined\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
double get_species_mass(const species &spec) {
|
||||
double res;
|
||||
switch (spec) {
|
||||
case electron:
|
||||
res = me_eV;
|
||||
break;
|
||||
case tritiumI:
|
||||
res = mT_eV;
|
||||
break;
|
||||
case tritium2I:
|
||||
res = mT2_eV;
|
||||
break;
|
||||
case tritium2:
|
||||
res = mT2_eV;
|
||||
break;
|
||||
default:
|
||||
stringstream ss;
|
||||
ss<<"get_species_mass: Species not defined\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream& os, const species& spec) {
|
||||
os<<get_species_string(spec);
|
||||
return (os);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
#include "constants.h"
|
||||
#include "kinematics.h"
|
||||
|
||||
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
typedef enum species{electron, tritium, tritium2}species;
|
||||
|
||||
typedef enum species{electron, tritiumI, tritium2I, tritium2} species;
|
||||
double get_species_mass(const species &spec);
|
||||
std::string get_species_string(const species &spec);
|
||||
std::ostream& operator<<(std::ostream& os, const species& spec);
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const species& SpecOut);
|
||||
|
||||
class Particle {
|
||||
public:
|
||||
@@ -37,17 +40,17 @@ protected:
|
||||
unsigned int parentId;
|
||||
|
||||
public:
|
||||
double get_Mass_eV() { return(m_eV);}
|
||||
double get_Charge_nat() { return(Z);}
|
||||
vec3 get_Location_m() const { return(x_m);}
|
||||
vec3 get_Speed_ms() const { return(v_ms);}
|
||||
species get_Species() const {return(s);}
|
||||
double get_Id() const { return(Id);}
|
||||
double get_ParentId() const { return(parentId);}
|
||||
double get_Mass_eV() const {return(m_eV);}
|
||||
double get_Charge_nat() const {return(Z);}
|
||||
vec3 get_Location_m() const {return(x_m);}
|
||||
vec3 get_Speed_ms() const {return(v_ms);}
|
||||
species get_species() const {return(s);}
|
||||
double get_Id() const {return(Id);}
|
||||
double get_ParentId() const {return(parentId);}
|
||||
|
||||
double get_Radius_m() { return ( sqrt( pow(x_m[0],2) + pow(x_m[1],2) ) );}
|
||||
double get_SpeedAbs_ms() const { return ( vec3Abs(v_ms) ); } ;
|
||||
double get_EKin_eV() const { return ( calc_Ekin_eV_from_speed(v_ms, m_eV) );}
|
||||
double get_Radius_m() const {return ( sqrt( pow(x_m[0],2) + pow(x_m[1],2) ) );}
|
||||
double get_SpeedAbs_ms() const {return ( vec3Abs(v_ms) ); } ;
|
||||
double get_EKin_eV() const {return ( calc_Ekin_eV_from_speed(v_ms, m_eV) );}
|
||||
|
||||
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;}
|
||||
@@ -56,17 +59,23 @@ public:
|
||||
friend std::ostream& operator<<(std::ostream& os, const Particle& partOut);
|
||||
};
|
||||
|
||||
class ParticleBuilder {
|
||||
class Particle_Builder {
|
||||
public:
|
||||
ParticleBuilder() {};
|
||||
Particle_Builder() {};
|
||||
|
||||
Particle createElectron(vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum) const {
|
||||
static Particle createElectron(vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum) {
|
||||
return ( Particle(me_eV, -1 , loc_m, speed_ms, idnum, parentIdnum, electron));
|
||||
}
|
||||
|
||||
Particle createTritium(vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum) const {
|
||||
return ( Particle(mT_eV, 1 , loc_m, speed_ms, idnum, parentIdnum, tritium));
|
||||
static Particle createTritiumI(vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum) {
|
||||
return ( Particle(mT_eV, 1 , loc_m, speed_ms, idnum, parentIdnum, tritiumI));
|
||||
}
|
||||
|
||||
static Particle createTritium2I(vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum) {
|
||||
return ( Particle(2*mT_eV, 1 , loc_m, speed_ms, idnum, parentIdnum, tritium2I));
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -8,17 +8,22 @@
|
||||
|
||||
#include "population_builder.hpp"
|
||||
|
||||
#include "electron_population.hpp"
|
||||
#include "tritium_population.hpp"
|
||||
#include "tritium2_population.hpp"
|
||||
#include "electron_population.h"
|
||||
#include "thermal_katrin_base.h"
|
||||
#include "tritium2_population.h"
|
||||
|
||||
|
||||
Population Population_Builder::build_Population(Timer *Tim,UniRNG *rngUni, NormalRNG *rngNormal) {
|
||||
Population Kat_Population;
|
||||
Kat_Population.add_Population(new e_Density(Tim, rngUni, rngNormal));
|
||||
Kat_Population.add_Population(new T_Density(Tim, rngUni, rngNormal));
|
||||
Kat_Population.add_Population(new T2_Density(rngUni, rngNormal));
|
||||
Population_Manager Population_Builder::build(Timer *timer,UniRNG *rngUni, NormalRNG *rngNormal) {
|
||||
Population_Manager Populations;
|
||||
int num_z_bins = 10;
|
||||
int num_r_bins = 10;
|
||||
int num_phi_bins = 20;
|
||||
//Populations.add(new E_Population(timer, rngUni, rngNormal));
|
||||
Populations.add(new Thermal_Katrin_Base(electron, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins));
|
||||
Populations.add(new Thermal_Katrin_Base(tritiumI, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins));
|
||||
Populations.add(new Thermal_Katrin_Base(tritium2I, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins));
|
||||
Populations.add(new T2_Population(rngUni, rngNormal));
|
||||
|
||||
return (Kat_Population);
|
||||
return (Populations);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,15 +9,18 @@
|
||||
#ifndef population_builder_hpp
|
||||
#define population_builder_hpp
|
||||
|
||||
#include "population.hpp"
|
||||
#include "timer.hpp"
|
||||
#include "manager_base.h"
|
||||
#include "population_base.h"
|
||||
|
||||
typedef Manager_Base<Population_Base> Population_Manager;
|
||||
|
||||
|
||||
class Population_Builder {
|
||||
public:
|
||||
Population_Builder() {};
|
||||
|
||||
static Population build_Population(Timer *Tim, UniRNG *rngUni, NormalRNG *rngNormal);
|
||||
static Population_Manager build(Timer *timer, UniRNG *rngUni, NormalRNG *rngNormal);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -170,7 +170,6 @@ inline std::string getDataPath() {
|
||||
return (getHomebase() + "src/mc_electron/data/");
|
||||
}
|
||||
|
||||
|
||||
inline std::string remove_catEnding (std::string inString) {
|
||||
if ( inString.substr(inString.size()-4, 4) == ".cat" ){
|
||||
return (inString.substr(0, inString.size()-4) );
|
||||
|
||||
@@ -13,15 +13,19 @@ using namespace std;
|
||||
|
||||
const long int Simulation::seed = getParameter("seed");
|
||||
const long int Simulation::numberTotalDecays = getParameter("numberTotalDecays");
|
||||
const int Simulation::maxInteractions = getParameter("maxInteractions");
|
||||
|
||||
void Simulation::init_Simulation() {
|
||||
void Simulation::init() {
|
||||
set_RNGs();
|
||||
Tim = Timer(&numberDecays);
|
||||
Pop = Population_Builder::build_Population(&Tim, &rngUni, &rngNormal);
|
||||
Inj = Injector(&rngUni, &rngNormal);
|
||||
Mov = Mover(&Log);
|
||||
Inter = InteractionBuilder::build_InteractionProcessor(&Pop, &rngUni, &rngNormal);
|
||||
|
||||
timer = Timer(&numberDecays);
|
||||
loggers = Particle_Logger_Builder::build(&h5f);
|
||||
populations = Population_Builder::build(&timer, &rngUni, &rngNormal);
|
||||
|
||||
injector = Injector(&rngUni, &rngNormal);
|
||||
movers = Mover_Builder::build(&loggers, &populations);
|
||||
interactions = Interaction_Builder::build(&populations, &rngUni);
|
||||
terminators = Terminator_Builder::build();
|
||||
|
||||
set_statusUpdater();
|
||||
}
|
||||
|
||||
@@ -36,6 +40,11 @@ void Simulation::set_statusUpdater() {
|
||||
}
|
||||
|
||||
void Simulation::doit() {
|
||||
Mover_Base *moverPtr;
|
||||
Interaction_Base *interactionPtr;
|
||||
Terminator_Base *terminatorPtr;
|
||||
|
||||
|
||||
InteractionOut IntOut;
|
||||
double mfp;
|
||||
std::deque<Particle> partQue;
|
||||
@@ -43,7 +52,7 @@ void Simulation::doit() {
|
||||
vec3 oldLoc_m;
|
||||
while ( (numberDecays < numberTotalDecays) || (!partQue.empty()) ) {
|
||||
if (partQue.empty()) {
|
||||
curPart = Inj.injectElectron(numberTotalParticles);
|
||||
curPart = injector.injectElectron(numberTotalParticles);
|
||||
numberDecays++;
|
||||
numberTotalParticles++;
|
||||
do_statusUpdate();
|
||||
@@ -51,16 +60,24 @@ void Simulation::doit() {
|
||||
curPart = partQue.front();
|
||||
partQue.pop_front();
|
||||
}
|
||||
moverPtr = movers.find(curPart.get_species());
|
||||
interactionPtr = interactions.find(curPart.get_species());
|
||||
terminatorPtr = terminators.find(curPart.get_species());
|
||||
|
||||
while (!Term.check_Termination(curPart)) {
|
||||
|
||||
while (!terminatorPtr->checkTermination(curPart)) {
|
||||
oldLoc_m = curPart.get_Location_m();
|
||||
mfp = 1/Inter.get_macroSigma_m2(curPart);
|
||||
Mov.moveParticle(&curPart, mfp);
|
||||
Pop.up_Denisty(oldLoc_m, curPart);
|
||||
if (!Term.check_Termination(curPart)) {
|
||||
IntOut = Inter.do_Interaction(&curPart);
|
||||
IntOut.appendDeque(&partQue, &numberTotalParticles);
|
||||
if (IntOut.terminateCurrent()) {
|
||||
mfp = 1/interactionPtr->get_macroSigma_m2(curPart);
|
||||
moverPtr->move(&curPart, mfp);
|
||||
if (!terminatorPtr->checkTermination(curPart)) {
|
||||
IntOut = interactionPtr->do_Interaction(&curPart);
|
||||
for (int i=0; i<IntOut.get_number_new_particles(); i++) {
|
||||
partQue.push_back(IntOut.get_new_particles()[i]);
|
||||
}
|
||||
if (IntOut.get_delete_density()) {
|
||||
// Decrease Density by one now.
|
||||
}
|
||||
if (IntOut.get_delete_current()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -68,6 +85,8 @@ void Simulation::doit() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
void Simulation::do_statusUpdate() {
|
||||
if (numberDecays%updater_fraction == 0){
|
||||
if (updater_numberOfPrevious!=numberDecays) {
|
||||
|
||||
@@ -9,31 +9,38 @@
|
||||
#ifndef simulation_hpp
|
||||
#define simulation_hpp
|
||||
|
||||
#include "h5_file.hpp"
|
||||
#include "timer.hpp"
|
||||
|
||||
#include "logger_builder.hpp"
|
||||
#include "population_builder.hpp"
|
||||
|
||||
#include "injector.hpp"
|
||||
#include "mover.hpp"
|
||||
#include "terminator.hpp"
|
||||
#include "mover_builder.hpp"
|
||||
#include "interaction_builder.hpp"
|
||||
#include "particle.hpp"
|
||||
#include "terminator_builder.hpp"
|
||||
|
||||
|
||||
|
||||
|
||||
class Simulation {
|
||||
static const long int seed;
|
||||
static const long int numberTotalDecays;
|
||||
static const int maxInteractions;
|
||||
|
||||
UniRNG rngUni;
|
||||
NormalRNG rngNormal;
|
||||
|
||||
H5_Logger Log;
|
||||
Timer Tim;
|
||||
Population Pop;
|
||||
H5_File h5f;
|
||||
Timer timer;
|
||||
|
||||
Injector Inj;
|
||||
Mover Mov;
|
||||
InteractionProcessor Inter;
|
||||
Terminator Term;
|
||||
Particle_Logger_Manager loggers;
|
||||
Population_Manager populations;
|
||||
|
||||
|
||||
Injector injector;
|
||||
Mover_Manager movers;
|
||||
Interaction_Manager interactions;
|
||||
Terminator_Manager terminators;
|
||||
|
||||
int numberTotalParticles = 0;
|
||||
int numberDecays = 0;
|
||||
@@ -42,9 +49,11 @@ class Simulation {
|
||||
int updater_fraction;
|
||||
|
||||
public:
|
||||
Simulation() {init_Simulation();}
|
||||
Simulation() {
|
||||
init();
|
||||
}
|
||||
private:
|
||||
void init_Simulation();
|
||||
void init();
|
||||
void set_RNGs();
|
||||
void set_statusUpdater();
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
//
|
||||
// size_container.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 27.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "size_container.hpp"
|
||||
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// size_container.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 27.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef size_container_hpp
|
||||
#define size_container_hpp
|
||||
|
||||
#include "linScale.h"
|
||||
#include "katrin_geo.hpp"
|
||||
|
||||
|
||||
class Size_Container {
|
||||
double *data;
|
||||
Lin_Scale r_scale;
|
||||
double cell_length_m;
|
||||
|
||||
public:
|
||||
~Size_Container() {
|
||||
delete[] data;
|
||||
};
|
||||
|
||||
Size_Container(int num_z_bins, int num_r_bins, int num_phi_bins) {
|
||||
r_scale = Lin_Scale(0, Katrin_Geo::get_radius_m(), num_r_bins);
|
||||
cell_length_m = (Katrin_Geo::get_z_WGTSend_m()-Katrin_Geo::get_z_RW_m()) / (num_z_bins-1);
|
||||
|
||||
data = new double[num_r_bins + 1];
|
||||
for (int i = 0; i<=num_r_bins; i++) {
|
||||
data[i] = cell_length_m * calc_disc_surface_m2(i)/num_phi_bins;
|
||||
}
|
||||
}
|
||||
|
||||
double calc_disc_surface_m2 (const int &r_bin) {
|
||||
if (r_bin == 0) {
|
||||
return (0);
|
||||
}
|
||||
double previous_r_m = r_scale.calc_upper_bound(r_bin-1);
|
||||
double this_r_m = r_scale.calc_upper_bound(r_bin);
|
||||
double A_m2 = pi * (this_r_m * this_r_m - previous_r_m * previous_r_m);
|
||||
return(A_m2);
|
||||
}
|
||||
|
||||
double get_cell_volume_m3(const double &r_m) {
|
||||
int r_bin = r_scale.calc_index(r_m);
|
||||
return (data[r_bin]);
|
||||
}
|
||||
|
||||
double get_cell_volume_m3(const vec3 &loc_m) {
|
||||
double r_m = get_r_m(loc_m);
|
||||
return (get_cell_volume_m3(r_m));
|
||||
}
|
||||
|
||||
double get_cell_length_m() {
|
||||
return (cell_length_m);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /* size_container_hpp */
|
||||
@@ -0,0 +1,131 @@
|
||||
//
|
||||
// stacked_container.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 10.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef stacked_container_h
|
||||
#define stacked_container_h
|
||||
|
||||
|
||||
#include "average_container.h"
|
||||
|
||||
#include "random_operations.h"
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
class Stacked_Container : public Base_Container<T_Map> {
|
||||
double lowerEdge = 0;
|
||||
|
||||
public:
|
||||
Stacked_Container() : Base_Container<T_Map>() {} ;
|
||||
|
||||
Stacked_Container(const double &lowerEdge, std::string load_path) : Base_Container<T_Map>(load_path) {
|
||||
this->lowerEdge = lowerEdge;
|
||||
}
|
||||
Stacked_Container(const double &lowerEdge, const Average_Container<T_Map> &averageContainer) {
|
||||
this->lowerEdge = lowerEdge;
|
||||
calcMap(averageContainer);
|
||||
}
|
||||
|
||||
public:
|
||||
void calcMap(const Average_Container<T_Map> &averageContainer, const double &lowerEdge);
|
||||
private:
|
||||
void rec_calcMap(const dim1Map &subMap, std::deque<double> Points);
|
||||
template <typename T> void rec_calcMap(const T &subMapm, std::deque<double> Points);
|
||||
double calc_tot(const dim1Map &subMap);
|
||||
|
||||
public:
|
||||
double sample(const std::deque<double> &Points, UniRNG *rngUni);
|
||||
};
|
||||
|
||||
|
||||
template <class T_Map>
|
||||
void Stacked_Container<T_Map>::calcMap(const Average_Container<T_Map> &averageContainer, const double &lowerEdge) {
|
||||
this->lowerEdge = lowerEdge;
|
||||
T_Map averageMap = averageContainer.getMap();
|
||||
if (averageMap.empty()) {
|
||||
std::stringstream ss;
|
||||
ss<<"Stacked_Container::calcMap: Input Average_Container empty.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
Base_Container<T_Map>::Map.clear();
|
||||
std::deque<double> Points;
|
||||
rec_calcMap(averageMap, Points);
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
void Stacked_Container<T_Map>::rec_calcMap(const dim1Map &subMap, std::deque<double> Points) {
|
||||
double tot = calc_tot(subMap);
|
||||
double curVal, width, heigth;
|
||||
// first value manually, because of lowerEdge
|
||||
width = subMap.cbegin()->first - lowerEdge;
|
||||
heigth = subMap.cbegin()->second/tot;
|
||||
curVal = width * heigth;
|
||||
Points.push_back(curVal);
|
||||
Points.push_back(subMap.cbegin()->first);
|
||||
Base_Container<T_Map>::addPoint(Points);
|
||||
Points.pop_back();
|
||||
Points.pop_back();
|
||||
|
||||
dim1Map::const_iterator preItr;
|
||||
for (dim1Map::const_iterator curItr = (++subMap.cbegin()); curItr!=subMap.cend(); curItr++) {
|
||||
preItr = curItr;
|
||||
--preItr;
|
||||
width = curItr->first - preItr->first;
|
||||
heigth = curItr->second/tot;
|
||||
curVal += width*heigth;
|
||||
Points.push_back(curVal);
|
||||
Points.push_back(curItr->first);
|
||||
Base_Container<T_Map>::addPoint(Points);
|
||||
Points.pop_back();
|
||||
Points.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
template <typename T>
|
||||
void Stacked_Container<T_Map>::rec_calcMap(const T &subMap, std::deque<double> Points) {
|
||||
for (typename T::const_iterator Itr = subMap.cbegin(); Itr!= subMap.cend(); Itr++) {
|
||||
Points.push_back(Itr->first);
|
||||
rec_calcMap(Itr->second, Points);
|
||||
Points.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
double Stacked_Container<T_Map>::calc_tot(const dim1Map &subMap) {
|
||||
double tot = 0;
|
||||
// insert first value manually
|
||||
double width, heigth;
|
||||
width = subMap.begin()->first - lowerEdge;
|
||||
heigth = subMap.begin()->second;
|
||||
tot += width*heigth;
|
||||
dim1Map::const_iterator preItr;
|
||||
for (dim1Map::const_iterator curItr = (++subMap.cbegin()); curItr!=subMap.cend(); curItr++) {
|
||||
preItr = curItr;
|
||||
--preItr;
|
||||
width = curItr->first - preItr->first;
|
||||
heigth = curItr->second;
|
||||
tot += width*heigth;
|
||||
}
|
||||
return (tot);
|
||||
}
|
||||
|
||||
template <class T_Map>
|
||||
double Stacked_Container<T_Map>::sample(const std::deque<double> &Points, UniRNG *rngUni) {
|
||||
Base_Container<T_Map>::checkEmpty();
|
||||
if (Points.size() != Base_Container<T_Map>::Dim - 1) {
|
||||
std::stringstream ss;
|
||||
ss<<"Stacked_Container::sample: deque Point dimension missmatch.\n";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
dim1Map *endMap = Base_Container<T_Map>::template getSubMap<dim1Map>(Points, Lower_bound_Over);
|
||||
|
||||
return (endMap->lower_bound(rngUni->random())->second);
|
||||
}
|
||||
|
||||
|
||||
#endif /* stacked_container_h */
|
||||
@@ -1,48 +0,0 @@
|
||||
//
|
||||
// terminator.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "terminator.hpp"
|
||||
|
||||
#include "katrin_geo.hpp"
|
||||
|
||||
#include "read_system.h"
|
||||
|
||||
|
||||
const double Terminator::cutoffEnergy_eV = getParameter("cutoffEnergy_eV");
|
||||
|
||||
bool Terminator::check_Termination(const Particle &checkPart) {
|
||||
double Ekin_eV = checkPart.get_EKin_eV();
|
||||
vec3 loc_m = checkPart.get_Location_m();
|
||||
bool E_check = check_EnergyTermination(Ekin_eV);
|
||||
bool loc_check = check_WallTermination(loc_m);
|
||||
if (checkPart.get_Species() == electron) {
|
||||
return(E_check || loc_check);
|
||||
} else {
|
||||
return (loc_check);
|
||||
}
|
||||
}
|
||||
|
||||
bool Terminator::check_EnergyTermination(const double &Ekin_eV) {
|
||||
if (Ekin_eV<=cutoffEnergy_eV) {
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
bool Terminator::check_WallTermination(const 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 <=Katrin_Geo::get_z_RW_m()) {
|
||||
return (true);
|
||||
}
|
||||
if (r_m >= Katrin_Geo::get_radius_m()) {
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
//
|
||||
// terminator.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 13.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef terminator_hpp
|
||||
#define terminator_hpp
|
||||
|
||||
#include "particle.hpp"
|
||||
|
||||
|
||||
class Terminator {
|
||||
static const double cutoffEnergy_eV;
|
||||
|
||||
public:
|
||||
Terminator() {};
|
||||
|
||||
static bool check_Termination(const Particle &checkPart);
|
||||
private:
|
||||
static bool check_EnergyTermination(const double &Ekin_eV);
|
||||
static bool check_WallTermination(const vec3 &loc_m);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* terminator_hpp */
|
||||
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// thermal_katrin_base.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 27.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef thermal_katrin_base_h
|
||||
#define thermal_katrin_base_h
|
||||
|
||||
#include "thermal_base.h"
|
||||
|
||||
|
||||
class Thermal_Katrin_Base : public Thermal_Base {
|
||||
static const double wgtsTemp_K;
|
||||
static const double wgtsT2FlowSpeed_ms;
|
||||
|
||||
double m_eV;
|
||||
|
||||
public:
|
||||
Thermal_Katrin_Base(species this_species, Timer *timer, UniRNG *rngUni, NormalRNG *rngNormal, int num_z_bins, int num_r_bins, int num_phi_bins) : Thermal_Base(this_species, timer, rngUni, rngNormal, num_z_bins, num_r_bins, num_phi_bins) {
|
||||
m_eV = get_species_mass(this_species);
|
||||
};
|
||||
|
||||
vec3 get_average_speed_ms(const vec3 &loc_m);
|
||||
vec3 roll_speed_ms(const vec3 &loc_m);
|
||||
private:
|
||||
vec3 roll_thermSpeed_ms(const vec3 &loc_m);
|
||||
};
|
||||
|
||||
|
||||
const double Thermal_Katrin_Base::wgtsTemp_K = getParameter("wgtsTemp_K");
|
||||
const double Thermal_Katrin_Base::wgtsT2FlowSpeed_ms = getParameter("wgtsT2FlowSpeed_ms");
|
||||
|
||||
inline vec3 Thermal_Katrin_Base::get_average_speed_ms(const vec3 &loc_m) {
|
||||
if (Katrin_Geo::inWGTS(loc_m)) {
|
||||
double z_wgtsHalf_m = Katrin_Geo::get_z_WGTSstart_m() + (Katrin_Geo::get_z_WGTSend_m() - Katrin_Geo::get_z_WGTSstart_m())/2;
|
||||
double sign = (loc_m[2] < z_wgtsHalf_m) ? -1 : 1;
|
||||
double zSpeed_ms = sign*wgtsT2FlowSpeed_ms;
|
||||
return ( vec3(0,0,zSpeed_ms) );
|
||||
} else {
|
||||
return (vec3(0,0,0));
|
||||
}
|
||||
}
|
||||
|
||||
inline vec3 Thermal_Katrin_Base::roll_speed_ms(const vec3 &loc_m) {
|
||||
Katrin_Geo::check_inKatrin(loc_m);
|
||||
return (get_average_speed_ms(loc_m) + roll_thermSpeed_ms(loc_m));
|
||||
}
|
||||
|
||||
|
||||
inline vec3 Thermal_Katrin_Base::roll_thermSpeed_ms(const vec3 &loc_m) {
|
||||
double E_eV = roll_MBEnergy(wgtsTemp_K, m_eV, rngNormal);
|
||||
double abs_speed_ms = calc_Speed_from_Ekin_eV(E_eV, m_eV);
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni)*abs_speed_ms;
|
||||
return(speed_ms);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* thermal_katrin_base_h */
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
#include "read_system.h"
|
||||
|
||||
|
||||
const double Timer::wgtsT2MaxDensity_m3 = getParameter("wgtsT2MaxDensity_m3");
|
||||
|
||||
double Timer::get_physTime_s() {
|
||||
|
||||
@@ -12,24 +12,21 @@
|
||||
#include "katrin_geo.hpp"
|
||||
class Timer {
|
||||
static const double wgtsT2MaxDensity_m3;
|
||||
|
||||
double T2_activity_s;
|
||||
|
||||
int *numTotDecays;
|
||||
|
||||
public:
|
||||
Timer() {numTotDecays = NULL;}
|
||||
|
||||
Timer(int *numTotDecays) {
|
||||
this->numTotDecays = numTotDecays;
|
||||
set_T2_activity_s();
|
||||
}
|
||||
|
||||
double get_physTime_s();
|
||||
|
||||
private:
|
||||
void set_T2_activity_s();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
//
|
||||
// tritium2_population.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 07.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "tritium2_population.hpp"
|
||||
|
||||
|
||||
const double T2_Density::wgtsT2MaxDensity_m3 = getParameter("wgtsT2MaxDensity_m3");
|
||||
const double T2_Density::wgtsTemp_K = getParameter("wgtsTemp_K");
|
||||
const double T2_Density::wgtsT2FlowSpeed_ms = getParameter("wgtsT2FlowSpeed_ms");
|
||||
|
||||
double T2_Density::get_Density_m3(vec3 loc_m) const {
|
||||
Katrin_Geo::check_inKatrin(loc_m);
|
||||
if (!Katrin_Geo::inWGTS(loc_m)) {
|
||||
return (zero);
|
||||
} else {
|
||||
return (calc_DensityTriangle(loc_m[2]));
|
||||
}
|
||||
}
|
||||
|
||||
double T2_Density::calc_DensityTriangle(double z_m) const {
|
||||
double z_wgts_m = z_m - Katrin_Geo::get_z_WGTSstart_m(); // Cords with z=0 at beginning of WGTS
|
||||
double wgtsLength_m = Katrin_Geo::get_wgtsLength_m();
|
||||
double wgtsHalfLength_m = wgtsLength_m/2;
|
||||
double zProjection_m = (z_wgts_m < wgtsHalfLength_m) ? z_wgts_m : wgtsLength_m - z_wgts_m;
|
||||
double reduction_Factor = zProjection_m/wgtsHalfLength_m; //Correction since reflection
|
||||
return(reduction_Factor * wgtsT2MaxDensity_m3);
|
||||
}
|
||||
|
||||
vec3 T2_Density::roll_Speed_ms(vec3 loc_m) const {
|
||||
Katrin_Geo::check_inKatrin(loc_m);
|
||||
return (calc_flowSpeed_ms(loc_m) + roll_thermSpeed_ms(loc_m));
|
||||
}
|
||||
|
||||
vec3 T2_Density::calc_flowSpeed_ms(vec3 loc_m) const {
|
||||
if (Katrin_Geo::inWGTS(loc_m)) {
|
||||
double z_wgtsHalf_m = Katrin_Geo::get_z_WGTSstart_m() + (Katrin_Geo::get_z_WGTSend_m() - Katrin_Geo::get_z_WGTSstart_m())/2;
|
||||
double sign = (loc_m[2] < z_wgtsHalf_m) ? -1 : 1;
|
||||
double zSpeed_ms = sign*wgtsT2FlowSpeed_ms;
|
||||
return ( vec3(0,0,zSpeed_ms) );
|
||||
} else {
|
||||
return (vec3(0,0,0));
|
||||
}
|
||||
}
|
||||
|
||||
vec3 T2_Density::roll_thermSpeed_ms(vec3 loc_m) const {
|
||||
double Ekin_eV = roll_MBEnergy(wgtsTemp_K,mT2_eV,rngNormal);
|
||||
double Speed_ms = calc_Speed_from_Ekin_eV(Ekin_eV, mT2_eV);
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni)*Speed_ms;
|
||||
return(speed_ms);
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
//
|
||||
// tritium2_population.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 07.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef tritium2_population_hpp
|
||||
#define tritium2_population_hpp
|
||||
|
||||
#include "population_base.h"
|
||||
|
||||
|
||||
class T2_Density : public Population_Base, public RNG_Base {
|
||||
static const double wgtsT2MaxDensity_m3;
|
||||
static const double wgtsTemp_K;
|
||||
static const double wgtsT2FlowSpeed_ms;
|
||||
|
||||
public:
|
||||
T2_Density(UniRNG *rngUni, NormalRNG *rngNormal) : Population_Base(tritium2), RNG_Base(rngUni, rngNormal){};
|
||||
|
||||
double get_Density_m3(vec3 loc_m) const ;
|
||||
private:
|
||||
double calc_DensityTriangle(double z_m) const;
|
||||
|
||||
public:
|
||||
vec3 roll_Speed_ms(vec3 loc_m) const;
|
||||
private:
|
||||
vec3 calc_flowSpeed_ms(vec3 loc_m) const;
|
||||
vec3 roll_thermSpeed_ms(vec3 loc_m) const;
|
||||
|
||||
public:
|
||||
void up_Denisty(vec3 oldLoc_m, vec3 newLoc_m, double Ekin_eV) {};
|
||||
};
|
||||
|
||||
|
||||
#endif /* tritium2_population_hpp */
|
||||
@@ -1,33 +0,0 @@
|
||||
//
|
||||
// tritium_interactions.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "tritium_interactions.hpp"
|
||||
|
||||
double T_T2_elasticScattering::get_macroSigma_m2(const Particle &interPart) const {
|
||||
vec3 loc_m = interPart.get_Location_m();
|
||||
double n_m3 = Pop->get_Density_m3(tritium2, loc_m);
|
||||
return (HardSphere.get_TCS() * n_m3);
|
||||
}
|
||||
|
||||
InteractionOut T_T2_elasticScattering::do_Interaction (Particle *interPart) const {
|
||||
vec3 v_ms = interPart->get_Speed_ms();
|
||||
vec3 vT2_ms = Pop->roll_Speed_ms(tritium2, interPart->get_Location_m());
|
||||
vec3 vLab_ms = v_ms - vT2_ms;
|
||||
double thetaLab = HardSphere.roll_theta(rngUni);
|
||||
double phiLab = rngUni->random() * 2 * pi;
|
||||
interPart->set_Speed_ms( calc_vNew_ms(v_ms, vT2_ms, thetaLab, phiLab) );
|
||||
return (InteractionOut());
|
||||
}
|
||||
|
||||
vec3 T_T2_elasticScattering::calc_vNew_ms(vec3 vOld_ms, vec3 vT2_ms, double thetaLab, double phiLab) const {
|
||||
vec3 speedLab_ms = vOld_ms - vT2_ms;
|
||||
vec3 n0 = calc_newDirection(speedLab_ms, thetaLab, phiLab);
|
||||
vec3 vNew_ms = (mT2_eV*vec3Abs(speedLab_ms)*n0 + me_eV*speedLab_ms)/(me_eV+mT2_eV) + vT2_ms;
|
||||
return (vNew_ms);
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
//
|
||||
// tritium_interactions.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 16.04.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef tritium_interactions_hpp
|
||||
#define tritium_interactions_hpp
|
||||
|
||||
#include "interaction_species.hpp"
|
||||
|
||||
#include "hardsphere_elastic.h"
|
||||
|
||||
class T_T2_elasticScattering : public Interaction {
|
||||
const Hardsphere_elasticScattering HardSphere = Hardsphere_elasticScattering(3.4614e-15);
|
||||
public:
|
||||
T_T2_elasticScattering(Population *Pop, UniRNG *rngUni, NormalRNG *rngNormal) : Interaction(tritium, Pop, rngUni, rngNormal) {};
|
||||
|
||||
double get_macroSigma_m2(const Particle &interPart) const;
|
||||
InteractionOut do_Interaction (Particle *interPart) const;
|
||||
|
||||
private:
|
||||
vec3 calc_vNew_ms(vec3 vOld_ms, vec3 vT2_ms, double thetaLab, double phiLab) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* tritium_interactions_hpp */
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// tritium_population.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 06.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "tritium_population.hpp"
|
||||
|
||||
|
||||
const double T_Density::wgtsTemp_K = getParameter("wgtsTemp_K");
|
||||
const double T_Density::wgtsT2FlowSpeed_ms = getParameter("wgtsT2FlowSpeed_ms");
|
||||
|
||||
double T_Density::get_Density_m3(vec3 loc_m) const {
|
||||
Katrin_Geo::check_inKatrin(loc_m);
|
||||
double physTime_s = Tim->get_physTime_s();
|
||||
double dens = T_Container.getDensity_m3(loc_m, physTime_s, xyz);
|
||||
return(dens);
|
||||
}
|
||||
|
||||
vec3 T_Density::roll_Speed_ms(vec3 loc_m) const {
|
||||
Katrin_Geo::check_inKatrin(loc_m);
|
||||
return (calc_flowSpeed_ms(loc_m) + roll_thermSpeed_ms(loc_m));
|
||||
}
|
||||
|
||||
vec3 T_Density::calc_flowSpeed_ms(vec3 loc_m) const {
|
||||
if (Katrin_Geo::inWGTS(loc_m)) {
|
||||
double z_wgtsHalf_m = Katrin_Geo::get_z_WGTSstart_m() + (Katrin_Geo::get_z_WGTSend_m() - Katrin_Geo::get_z_WGTSstart_m())/2;
|
||||
double sign = (loc_m[2] < z_wgtsHalf_m) ? -1 : 1;
|
||||
double zSpeed_ms = sign*wgtsT2FlowSpeed_ms;
|
||||
return ( vec3(0,0,zSpeed_ms) );
|
||||
} else {
|
||||
return (vec3(0,0,0));
|
||||
}
|
||||
}
|
||||
|
||||
vec3 T_Density::roll_thermSpeed_ms(vec3 loc_m) const {
|
||||
double Ekin_eV = roll_MBEnergy(wgtsTemp_K,mT2_eV,rngNormal);
|
||||
double Speed_ms = calc_Speed_from_Ekin_eV(Ekin_eV, mT2_eV);
|
||||
vec3 speed_ms = roll_uniform_direction(rngUni)*Speed_ms;
|
||||
return(speed_ms);
|
||||
}
|
||||
|
||||
void T_Density::up_Denisty(vec3 oldLoc_m, vec3 newLoc_m, double Ekin_eV) {
|
||||
double vAbs_ms = calc_Speed_from_Ekin_eV(Ekin_eV, me_eV);
|
||||
T_Container.upDensity(vAbs_ms, oldLoc_m, newLoc_m);
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
//
|
||||
// tritium_population.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 06.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef tritium_population_hpp
|
||||
#define tritium_population_hpp
|
||||
|
||||
#include "density_container.hpp"
|
||||
|
||||
#include "population_base.h"
|
||||
|
||||
|
||||
class T_Density : public Population_Base, public RNG_Base {
|
||||
static const double wgtsTemp_K;
|
||||
static const double wgtsT2FlowSpeed_ms;
|
||||
|
||||
WGTS3D_ParticleTime_s_Container T_Container;
|
||||
Timer *Tim;
|
||||
|
||||
public:
|
||||
T_Density(Timer *Tim, UniRNG *rngUni, NormalRNG *rngNormal) : Population_Base(tritium), RNG_Base(rngUni, rngNormal), T_Container(vec3(10,10,10)) {
|
||||
this->Tim = Tim;
|
||||
};
|
||||
|
||||
double get_Density_m3(vec3 loc_m) const ;
|
||||
|
||||
public:
|
||||
vec3 roll_Speed_ms(vec3 loc_m) const;
|
||||
private:
|
||||
vec3 calc_flowSpeed_ms(vec3 loc_m) const;
|
||||
vec3 roll_thermSpeed_ms(vec3 loc_m) const;
|
||||
|
||||
public:
|
||||
void up_Denisty(vec3 oldLoc_m, vec3 newLoc_m, double Ekin_eV);
|
||||
};
|
||||
|
||||
#endif /* tritium_population_hpp */
|
||||
@@ -7,19 +7,17 @@
|
||||
//
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <deque>
|
||||
#include <sstream>
|
||||
#include "tcs_container.hpp"
|
||||
#include "dcs_container.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
clock_t start;
|
||||
UniRNG rngUni;
|
||||
TCS_Container tcs_data = TCS_Container(1e-5, 2e4, 1e3, getDataPath() + "eT2_TCS_ela_concat.dat");
|
||||
DCS_Theta_Container dcs_data = DCS_Theta_Container(1e-5, 2e4, 1e3, 200, getDataPath() + "eT2_DCS_ela_concat.dat");
|
||||
|
||||
int *test;
|
||||
test = new int[3];
|
||||
test[2] = 3;
|
||||
cout<<test[7];
|
||||
//tcs_data.debug();
|
||||
std::cout<<tcs_data.get_value(0)<<"\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user