Merge branch 'working'
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
# 1. Compiler
|
||||
|
||||
# Compiler (non-MPI)
|
||||
CXX = g++
|
||||
CXX = g++ -std=c++11
|
||||
CC = gcc
|
||||
FC = gfortran
|
||||
|
||||
@@ -79,7 +79,7 @@ INSTALL = install
|
||||
###########################################################################
|
||||
# 4. Weitere Variablen, die (evtl!) irgendwo zur Makefile-Steuerung verwendet
|
||||
# werden (teilweise redundant, teilweise kaputt)
|
||||
CPU_TYPE := $(shell cat /proc/cpuinfo|grep Quad| wc -l ) + $(shell cat /proc/cpuinfo|grep i7| wc -l )
|
||||
# CPU_TYPE := $(shell cat /proc/cpuinfo|grep Quad| wc -l ) + $(shell cat /proc/cpuinfo|grep i7| wc -l )
|
||||
|
||||
# Mehrere kaputte svn-makros
|
||||
REVNUM = 0
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
# 1. Compiler
|
||||
|
||||
# Compiler (non-MPI)
|
||||
CXX = g++
|
||||
CXX = g++ -std=c++11
|
||||
CC = gcc
|
||||
FC = gfortran
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "bedionization.hpp"
|
||||
|
||||
#include "myexeption.h"
|
||||
#include "functions.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
#include <sstream>
|
||||
@@ -18,7 +18,7 @@
|
||||
using namespace std;
|
||||
|
||||
const double BED_Ionization::S_m2 = 5.4721e-20;
|
||||
const double BED_Ionization::B_eV = Constants().EionT2_eV;
|
||||
const double BED_Ionization::B_eV = EionT2_eV;
|
||||
const double BED_Ionization::u = 1.664;
|
||||
const double BED_Ionization::N = 2;
|
||||
const double BED_Ionization::Ni = 1.173;
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
//
|
||||
// constants.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 09.02.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#include "constants.hpp"
|
||||
|
||||
|
||||
// Natural Constants
|
||||
constant Constants::pi = 3.1415;
|
||||
constant Constants::c_ms = 299792458;
|
||||
constant Constants::kb_eVK = 8.6173303e-5;
|
||||
constant Constants::e_C = 1.602176462e-19;
|
||||
constant Constants::rBohr_m = 0.52917721067e-10;
|
||||
constant Constants::ERyd_eV = 13.605693009;
|
||||
|
||||
// Particle Properties
|
||||
constant Constants::me_eV = 0.511e6;
|
||||
constant Constants::re_m = 2.817940322719e-15;
|
||||
constant Constants::ZT2 = 2.;
|
||||
constant Constants::mT2_eV = 5.61886404234e9;
|
||||
constant Constants::EionT2_eV = 15.43;
|
||||
|
||||
// Beta Decay
|
||||
constant Constants::BetaDecayConst = 1.2072343416696292e-47;
|
||||
constant Constants::TritiumDecayEndpoint_eV = 18.574e3;
|
||||
|
||||
@@ -12,29 +12,24 @@
|
||||
|
||||
typedef const double constant;
|
||||
|
||||
class Constants {
|
||||
public:
|
||||
Constants() {};
|
||||
// Natural Constants
|
||||
static constant pi;
|
||||
static constant c_ms;
|
||||
static constant kb_eVK;
|
||||
static constant e_C;
|
||||
static constant rBohr_m;
|
||||
static constant ERyd_eV;
|
||||
|
||||
// Particle Properties
|
||||
static constant me_eV;
|
||||
static constant re_m;
|
||||
static constant ZT2;
|
||||
static constant mT2_eV;
|
||||
static constant EionT2_eV;
|
||||
|
||||
// Beta Decay
|
||||
static constant BetaDecayConst;
|
||||
static constant TritiumDecayEndpoint_eV;
|
||||
// Natural Constants
|
||||
constant pi = 3.1415;
|
||||
constant c_ms = 299792458;
|
||||
constant kb_eVK = 8.6173303e-5;
|
||||
constant e_C = 1.602176462e-19;
|
||||
constant rBohr_m = 0.52917721067e-10;
|
||||
constant ERyd_eV = 13.605693009;
|
||||
|
||||
};
|
||||
// Particle Properties
|
||||
constant me_eV = 0.511e6;
|
||||
constant re_m = 2.817940322719e-15;
|
||||
constant ZT2 = 2.;
|
||||
constant mT2_eV = 5.61886404234e9;
|
||||
constant EionT2_eV = 15.43;
|
||||
|
||||
// Beta Decay
|
||||
constant BetaDecayConst = 1.2072343416696292e-47;
|
||||
constant TritiumDecayEndpoint_eV = 18.574e3;
|
||||
|
||||
|
||||
#endif /* constants_hpp */
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
#include "electron.hpp"
|
||||
|
||||
#include "myexeption.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int Electron::ionOn = getParameter("ionOn");
|
||||
const int Electron::elaOn = getParameter("elaOn");
|
||||
|
||||
double Electron::get_SigmaTotal_m2(vec3 speedT2_ms) {
|
||||
vector<double> Sigmas = get_SigmaVector_m2(speedT2_ms);
|
||||
@@ -24,13 +24,13 @@ double Electron::get_SigmaTotal_m2(vec3 speedT2_ms) {
|
||||
|
||||
vector<double> Electron::get_SigmaVector_m2(vec3 speedT2_ms) {
|
||||
vector<double> Sigmas;
|
||||
if (Particle::elaOn == 1) {
|
||||
if (elaOn == 1) {
|
||||
Sigmas.push_back(get_elaSigma_m2(speedT2_ms));
|
||||
} else {
|
||||
Sigmas.push_back(0.);
|
||||
}
|
||||
|
||||
if (Particle::ionOn == 1) {
|
||||
if (ionOn == 1) {
|
||||
Sigmas.push_back(get_ionSigma_m2(speedT2_ms));
|
||||
} else {
|
||||
Sigmas.push_back(0.);
|
||||
@@ -94,7 +94,9 @@ double Electron::roll_elaTheta(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni)
|
||||
double betaLab = get_vecAbs(speedLab_ms)/c_ms;
|
||||
double elaEta = get_elaEta(speedLab_ms);
|
||||
double const1 = 2*pi/get_elaSigma_m2(speedT2_ms)*ZT2*(ZT2+1)*re_m*re_m*(1- pow(betaLab,2) )* pow(betaLab,-4);
|
||||
double theta = acos( pow( rngUni->random()/const1-pow(2*elaEta,-1) , -1 ) +1+2*elaEta);
|
||||
double fac = pow( rngUni->random()/const1-pow(2*elaEta,-1) , -1 ) +1+2*elaEta;
|
||||
double theta = acos( fac);
|
||||
|
||||
return(theta);
|
||||
}
|
||||
|
||||
@@ -208,3 +210,7 @@ double Electron::roll_IonTheta2(double T_eV, double W_eV, ranlib::Uniform<double
|
||||
}
|
||||
return(theta2);
|
||||
}
|
||||
|
||||
/*
|
||||
Func_Container Electron::elaTCS_container = Func_Container("/Users/ChristianReiling/Documents/Masterarbeit/katrin-plasma/src/mc_electron/data/yoon_TCS_elastic.dat");
|
||||
*/
|
||||
|
||||
@@ -11,16 +11,22 @@
|
||||
|
||||
#include "particle.hpp"
|
||||
#include "bedionization.hpp"
|
||||
#include "function_container.hpp"
|
||||
|
||||
|
||||
class Electron : public Particle, private BED_Ionization {
|
||||
public:
|
||||
virtual ~Electron() {}
|
||||
Electron(vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum) : Particle::Particle(me_eV, 1 , loc_m, speed_ms, idnum, parentIdnum, electron) {};
|
||||
|
||||
// Interactions
|
||||
public:
|
||||
double get_SigmaTotal_m2(vec3 speedT2_ms);
|
||||
std::vector<double> get_SigmaVector_m2(vec3 speedT2_ms);
|
||||
int roll_Interaction(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
private:
|
||||
static const int ionOn;
|
||||
static const int elaOn;
|
||||
|
||||
// Elastic Scattering
|
||||
public:
|
||||
@@ -31,19 +37,19 @@ protected:
|
||||
double roll_elaTheta(vec3 speedT2_ms, ranlib::Uniform<double> *rngUni);
|
||||
void do_elaKinetics(vec3 speedT2_ms, double theta, double phi);
|
||||
|
||||
|
||||
// Ionization
|
||||
|
||||
public:
|
||||
double get_ionSigma_m2(vec3 speedT2_ms);
|
||||
Electron do_Ionization(vec3 speedT2_ms, int newId, ranlib::Uniform<double> *rngUni);
|
||||
protected:
|
||||
double roll_ionW_eV(double T_eV, ranlib::Uniform<double> *rngUni);
|
||||
|
||||
|
||||
double roll_IonTheta1(double T_eV, double W_eV, ranlib::Uniform<double> *rngUni);
|
||||
double roll_IonTheta2(double T_eV, double W_eV, ranlib::Uniform<double> *rngUni);
|
||||
|
||||
|
||||
// Testing Container
|
||||
//static Func_Container elaTCS_container;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
//
|
||||
// function2D_container.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 15.03.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "function2D_container.hpp"
|
||||
|
||||
#include "myexeption.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
Func2D_Container::Func2D_Container() {
|
||||
|
||||
}
|
||||
|
||||
Func2D_Container::Func2D_Container(std::string loadFilePath) {
|
||||
readFromCSV(loadFilePath);
|
||||
}
|
||||
|
||||
double Func2D_Container::interpolate(double x, double y) {
|
||||
// Method might be improved, since first check for x bins, and afterwards check for y bins, so theoretically not choosing closest neighbour in terms of y but giving priority to x-closeness.
|
||||
// Avoid Mistakes by having complete set of y-data and uniform grid or improve code later.
|
||||
|
||||
|
||||
if (Map.empty()) {
|
||||
throw MyException("Func2D_Container: Container is empty.");
|
||||
}
|
||||
|
||||
if (Map.begin() == Map.lower_bound(x) ) {
|
||||
return (Map.begin()->second.interpolate(y));
|
||||
} else if (Map.end() == Map.lower_bound(x)){
|
||||
return ( (--Map.end())->second.interpolate(y) );
|
||||
}
|
||||
|
||||
dim2Map::iterator lowAnker_Itr = --Map.lower_bound(x);
|
||||
dim2Map::iterator upAnker_Itr = Map.lower_bound(x);
|
||||
double lowAnker_x = lowAnker_Itr->first;
|
||||
double lowAnker_fxy = lowAnker_Itr->second.interpolate(y);
|
||||
double upAnker_x = upAnker_Itr->first;
|
||||
double upAnker_fxy = upAnker_Itr->second.interpolate(y);
|
||||
|
||||
double res = lowAnker_fxy + (x-lowAnker_x)/(upAnker_x-lowAnker_x) * (upAnker_fxy-lowAnker_fxy);
|
||||
return (res);
|
||||
|
||||
}
|
||||
|
||||
void Func2D_Container::add_ankerpoint(double x, double y, double fxy) {
|
||||
if ( Map.find(x)==Map.end() ) {
|
||||
Func_Container Temp_Container;
|
||||
Temp_Container.add_ankerpoint(y, fxy);
|
||||
Map.insert(dim2Pair (x, Temp_Container));
|
||||
} else {
|
||||
try {
|
||||
Map.find(x)->second.add_ankerpoint(y,fxy);
|
||||
} catch (MyException& caught) {
|
||||
stringstream ss;
|
||||
ss<<"Func2D_Container::add_ankerpoint: Error from "<<caught.what();
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void Func2D_Container::readFromCSV(std::string loadFilePath) {
|
||||
ifstream fileStream(loadFilePath);
|
||||
if (!fileStream.good()) {
|
||||
stringstream ss;
|
||||
ss<<"Func_Container::readFromCSV: Could not open file.\nloadFilePath= "<<loadFilePath<<endl;
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
string lineFromFile;
|
||||
stringstream ss;
|
||||
double xTemp,yTemp,fxyTemp;
|
||||
bool lineReadError = false;
|
||||
|
||||
while (getline(fileStream, lineFromFile)) {
|
||||
removeLeadingWhites(lineFromFile);
|
||||
replaceDelimiter(lineFromFile);
|
||||
if ( checkIgnoreLine(lineFromFile) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ss.clear();
|
||||
ss.str(lineFromFile);
|
||||
|
||||
if (ss>>xTemp && ss>>yTemp&& ss>>fxyTemp) {
|
||||
add_ankerpoint(xTemp, yTemp, fxyTemp);
|
||||
} else {
|
||||
if (!lineReadError) {
|
||||
cout<<"Func_Container::readFromCSV: Warning could not read line in inputFile. \nloadFilePath = "<<loadFilePath<<endl;
|
||||
lineReadError = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
fileStream.close();
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
//
|
||||
// function2D_container.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 15.03.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef function2D_container_hpp
|
||||
#define function2D_container_hpp
|
||||
|
||||
#include "function_container.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
|
||||
|
||||
typedef std::map<double,Func_Container> dim2Map;
|
||||
typedef std::pair<double,Func_Container> dim2Pair;
|
||||
|
||||
class Func2D_Container {
|
||||
public:
|
||||
Func2D_Container();
|
||||
Func2D_Container(std::string loadFilePath);
|
||||
double interpolate(double x, double y);
|
||||
|
||||
void add_ankerpoint(double x, double y, double fxy);
|
||||
private:
|
||||
|
||||
|
||||
dim2Map Map;
|
||||
void readFromCSV(std::string loadFilePath);
|
||||
|
||||
} ;
|
||||
|
||||
#endif /* function2D_container_hpp */
|
||||
@@ -8,16 +8,13 @@
|
||||
|
||||
#include "function_container.hpp"
|
||||
|
||||
#include "myexeption.h"
|
||||
#include "functions.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
Func_Container::Func_Container() {
|
||||
|
||||
}
|
||||
|
||||
Func_Container::Func_Container(std::string loadFilePath) {
|
||||
readFromCSV(loadFilePath);
|
||||
@@ -100,26 +97,87 @@ void Func_Container::printAnkerpoints() {
|
||||
}
|
||||
}
|
||||
|
||||
// Func2D_Container
|
||||
Func2D_Container::Func2D_Container(std::string loadFilePath) {
|
||||
readFromCSV(loadFilePath);
|
||||
}
|
||||
|
||||
bool checkIgnoreLine(string lineFromFile) {
|
||||
if (lineFromFile[0] =='#') {
|
||||
return true;
|
||||
} else if ( lineFromFile.empty() ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
double Func2D_Container::interpolate(double x, double y) {
|
||||
// Method might be improved, since first check for x bins, and afterwards check for y bins, so theoretically not choosing closest neighbour in terms of y but giving priority to x-closeness.
|
||||
// Avoid Mistakes by having complete set of y-data and uniform grid or improve code later.
|
||||
|
||||
|
||||
if (Map.empty()) {
|
||||
throw MyException("Func2D_Container: Container is empty.");
|
||||
}
|
||||
|
||||
if (Map.begin() == Map.lower_bound(x) ) {
|
||||
return (Map.begin()->second.interpolate(y));
|
||||
} else if (Map.end() == Map.lower_bound(x)){
|
||||
return ( (--Map.end())->second.interpolate(y) );
|
||||
}
|
||||
|
||||
dim2Map::iterator lowAnker_Itr = --Map.lower_bound(x);
|
||||
dim2Map::iterator upAnker_Itr = Map.lower_bound(x);
|
||||
double lowAnker_x = lowAnker_Itr->first;
|
||||
double lowAnker_fxy = lowAnker_Itr->second.interpolate(y);
|
||||
double upAnker_x = upAnker_Itr->first;
|
||||
double upAnker_fxy = upAnker_Itr->second.interpolate(y);
|
||||
|
||||
double res = lowAnker_fxy + (x-lowAnker_x)/(upAnker_x-lowAnker_x) * (upAnker_fxy-lowAnker_fxy);
|
||||
return (res);
|
||||
|
||||
}
|
||||
void removeLeadingWhites(string &lineFromFile) {
|
||||
static const string WHITESPACE = " \n\r\t\f\v";
|
||||
size_t start = lineFromFile.find_first_not_of(WHITESPACE);
|
||||
lineFromFile = (start == std::string::npos) ? "" : lineFromFile.substr(start);
|
||||
|
||||
void Func2D_Container::add_ankerpoint(double x, double y, double fxy) {
|
||||
if ( Map.find(x)==Map.end() ) {
|
||||
Func_Container Temp_Container;
|
||||
Temp_Container.add_ankerpoint(y, fxy);
|
||||
Map.insert(dim2Pair (x, Temp_Container));
|
||||
} else {
|
||||
try {
|
||||
Map.find(x)->second.add_ankerpoint(y,fxy);
|
||||
} catch (MyException& caught) {
|
||||
stringstream ss;
|
||||
ss<<"Func2D_Container::add_ankerpoint: Error from "<<caught.what();
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void replaceDelimiter(string &lineFromFile) {
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ';', ' ');
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ',', ' ');
|
||||
return;
|
||||
void Func2D_Container::readFromCSV(std::string loadFilePath) {
|
||||
ifstream fileStream(loadFilePath);
|
||||
if (!fileStream.good()) {
|
||||
stringstream ss;
|
||||
ss<<"Func_Container::readFromCSV: Could not open file.\nloadFilePath= "<<loadFilePath<<endl;
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
string lineFromFile;
|
||||
stringstream ss;
|
||||
double xTemp,yTemp,fxyTemp;
|
||||
bool lineReadError = false;
|
||||
|
||||
while (getline(fileStream, lineFromFile)) {
|
||||
removeLeadingWhites(lineFromFile);
|
||||
replaceDelimiter(lineFromFile);
|
||||
if ( checkIgnoreLine(lineFromFile) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ss.clear();
|
||||
ss.str(lineFromFile);
|
||||
|
||||
if (ss>>xTemp && ss>>yTemp&& ss>>fxyTemp) {
|
||||
add_ankerpoint(xTemp, yTemp, fxyTemp);
|
||||
} else {
|
||||
if (!lineReadError) {
|
||||
cout<<"Func_Container::readFromCSV: Warning could not read line in inputFile. \nloadFilePath = "<<loadFilePath<<endl;
|
||||
lineReadError = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
fileStream.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,16 +9,16 @@
|
||||
#ifndef function_container_hpp
|
||||
#define function_container_hpp
|
||||
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
typedef std::map<double,double> dim1Map;
|
||||
typedef std::pair<double,double> dim1Pair;
|
||||
|
||||
class Func_Container {
|
||||
public:
|
||||
Func_Container();
|
||||
Func_Container() {};
|
||||
Func_Container(std::string loadFilePath);
|
||||
void add_ankerpoint(double x, double fx);
|
||||
double interpolate(double x);
|
||||
@@ -30,8 +30,20 @@ public:
|
||||
} ;
|
||||
|
||||
|
||||
void removeLeadingWhites(std::string &lineFromFile);
|
||||
void replaceDelimiter(std::string &lineFromFile);
|
||||
bool checkIgnoreLine(std::string lineFromFile);
|
||||
typedef std::map<double,Func_Container> dim2Map;
|
||||
typedef std::pair<double,Func_Container> dim2Pair;
|
||||
|
||||
class Func2D_Container {
|
||||
public:
|
||||
Func2D_Container() {};
|
||||
Func2D_Container(std::string loadFilePath);
|
||||
double interpolate(double x, double y);
|
||||
|
||||
void add_ankerpoint(double x, double y, double fxy);
|
||||
private:
|
||||
dim2Map Map;
|
||||
void readFromCSV(std::string loadFilePath);
|
||||
|
||||
} ;
|
||||
|
||||
#endif /* function_container_hpp */
|
||||
|
||||
+110
-19
@@ -9,20 +9,109 @@
|
||||
|
||||
#include "functions.hpp"
|
||||
|
||||
#include "myexeption.h"
|
||||
#include "constants.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
double get_vecAbs(vec3 vec) {
|
||||
return( sqrt( pow(vec[0],2) + pow(vec[1],2) + pow(vec[2],2)) );
|
||||
// Read Parameters from file
|
||||
double getParameter(string parName) {
|
||||
string parpath = getEnv("parpath");
|
||||
string parfile = getEnv("parfile");
|
||||
if (parpath == "") {
|
||||
throw MyException("Parameter::getParameter: Environment variable parpath not defined.");
|
||||
}
|
||||
if (parfile == "") {
|
||||
throw MyException("Parameter::getParameter: Environment variable parfile not defined.");
|
||||
}
|
||||
makePath(parpath);
|
||||
string loadFilePath = parpath + parfile;
|
||||
ifstream fileStream(loadFilePath);
|
||||
|
||||
if (!fileStream.good()) {
|
||||
stringstream ss;
|
||||
ss<<"Parameter::getParameter: Could not open file.\n loadFilePath =\t"<<loadFilePath<<endl;
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
string lineFromFile;
|
||||
stringstream ss;
|
||||
string parNameTemp;
|
||||
double parTemp;
|
||||
bool lineReadError = false;
|
||||
|
||||
while (getline(fileStream, lineFromFile)) {
|
||||
removeLeadingWhites(lineFromFile);
|
||||
replaceDelimiter(lineFromFile);
|
||||
if ( checkIgnoreLine(lineFromFile) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ss.clear();
|
||||
ss.str(lineFromFile);
|
||||
|
||||
if (ss>>parNameTemp && ss>>parTemp) {
|
||||
if (parNameTemp == parName) {
|
||||
fileStream.close();
|
||||
return (parTemp);
|
||||
}
|
||||
} else {
|
||||
if (!lineReadError) {
|
||||
cout<<"Parameter::getParameter: Line in parameter file faulty. \n path =\t"<<loadFilePath<<endl;
|
||||
lineReadError = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ss.clear();
|
||||
ss<<"Parameter::getParameter: Parameter not found in file.\n parName =\t"<<parName<<"\n loadFilePath = \t"<<loadFilePath;
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
|
||||
|
||||
//String Manipulations for Read in from files
|
||||
std::string getEnv (std::string envName) {
|
||||
char * val = getenv( envName.c_str() );
|
||||
return val == NULL ? std::string("") : std::string(val);
|
||||
}
|
||||
|
||||
void makePath (std::string &path) {
|
||||
if (path.back() != '/') {
|
||||
path = path + '/';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
bool checkIgnoreLine(std::string lineFromFile) {
|
||||
if (lineFromFile[0] =='#') {
|
||||
return true;
|
||||
} else if ( lineFromFile.empty() ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
void removeLeadingWhites(std::string &lineFromFile) {
|
||||
static const std::string WHITESPACE = " \n\r\t\f\v";
|
||||
size_t start = lineFromFile.find_first_not_of(WHITESPACE);
|
||||
lineFromFile = (start == std::string::npos) ? "" : lineFromFile.substr(start);
|
||||
return;
|
||||
}
|
||||
|
||||
void replaceDelimiter(std::string &lineFromFile) {
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ';', ' ');
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ',', ' ');
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), '=', ' ');
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate Kinematic Relations
|
||||
double get_Ekin_eV_from_speed(double Speed_ms, double mass_eV) {
|
||||
double beta = Speed_ms/Constants::c_ms;
|
||||
double beta = Speed_ms/c_ms;
|
||||
if (beta>=1) {
|
||||
stringstream ss;
|
||||
ss<<"get_Ekin_eV_from_speed(): Input speed v="<<Speed_ms<<" m/s equal or exeeds speed of light.";
|
||||
@@ -59,7 +148,7 @@ double get_Speed_from_Ekin_eV(double Ekin_eV, double mass_eV) {
|
||||
|
||||
double gamma = get_gamma_from_Ekin_eV(Ekin_eV, mass_eV);
|
||||
double beta = get_beta_from_gamma(gamma);
|
||||
return(beta * Constants::c_ms);
|
||||
return(beta * c_ms);
|
||||
}
|
||||
|
||||
double get_gamma_from_Ekin_eV(double Ekin_eV, double mass_eV) {
|
||||
@@ -80,6 +169,12 @@ double get_beta_from_gamma(double gamma) {
|
||||
return( sqrt(1 - pow(gamma,-2)) );
|
||||
}
|
||||
|
||||
|
||||
// Operations on 3 dimensional Vectors
|
||||
double get_vecAbs(vec3 vec) {
|
||||
return( sqrt( pow(vec[0],2) + pow(vec[1],2) + pow(vec[2],2)) );
|
||||
}
|
||||
|
||||
vec3 get_Newdirection(vec3 direction_old, double theta_change,double phi_change) {
|
||||
// Transformation of direction following Plante and Cucinotta
|
||||
double theta_old = acos(direction_old[2]/get_vecAbs(direction_old));
|
||||
@@ -92,45 +187,42 @@ vec3 get_Newdirection(vec3 direction_old, double theta_change,double phi_change)
|
||||
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.
|
||||
// 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*Constants::pi - phi_new_candidates[0];
|
||||
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] = Constants::pi - phi_new_candidates[2];
|
||||
phi_new_candidates[2] = (phi_new_candidates[2] > 0) ? phi_new_candidates[2] : 2*Constants::pi + phi_new_candidates[2];
|
||||
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];
|
||||
goto endloops;
|
||||
}
|
||||
}
|
||||
}
|
||||
endloops:
|
||||
if (phi_new == -1) {
|
||||
for (int j = 0;j<3;j++) {
|
||||
cout<<"phi1c["<<j<<"]="<<phi_new_candidates[j]<<endl;
|
||||
}
|
||||
throw MyException("Interaction::getElaNewDir: phi1 not found.");
|
||||
}
|
||||
return(vec3(sin(theta_new)*cos(phi_new) , sin(theta_new)*sin(phi_new) , cos(theta_new)));
|
||||
}
|
||||
|
||||
|
||||
// Functions for Random Sampling
|
||||
vec3 roll_uniform_direction(ranlib::Uniform<double> *rngUni) {
|
||||
vec3 dir;
|
||||
double phi = 2*Constants::pi*rngUni->random();
|
||||
double theta = Constants::pi*rngUni->random();
|
||||
double phi = 2*pi*rngUni->random();
|
||||
double theta = pi*rngUni->random();
|
||||
dir = sin(theta)*cos(phi) , sin(theta)*sin(phi) , cos(theta);
|
||||
return(dir);
|
||||
}
|
||||
|
||||
double roll_MBEnergy(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *rngNormal) {
|
||||
|
||||
double C = Constants::kb_eVK*Temp_K/mass_eV;
|
||||
double C = kb_eVK*Temp_K/mass_eV;
|
||||
double beta = 0;
|
||||
double sum = 0;
|
||||
for (int i=0;i<3;i++) {
|
||||
@@ -141,7 +233,6 @@ double roll_MBEnergy(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *rn
|
||||
return((get_gamma_from_beta(beta)-1)*mass_eV);
|
||||
}
|
||||
|
||||
|
||||
double roll_Rejectionmethod(double (*pdf)(double), double xmin, double xmax, double pmax, ranlib::Uniform<double> *rngUni) {
|
||||
// get Energy distribution using Rejection Method
|
||||
double xcan,eta1,eta2;
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
#define functions_hpp
|
||||
|
||||
|
||||
#include "constants.hpp"
|
||||
#include <iostream>
|
||||
// #include <string>
|
||||
|
||||
#include <blitz/array.h>
|
||||
#include <blitz/tinyvec2.h>
|
||||
@@ -20,16 +21,37 @@
|
||||
typedef blitz::TinyVector<double,3> vec3;
|
||||
|
||||
|
||||
double get_vecAbs(vec3 vec);
|
||||
// Custom Error Type
|
||||
struct MyException : public std::exception
|
||||
{
|
||||
std::string s;
|
||||
MyException(std::string errorMessage) : s(errorMessage) {}
|
||||
~MyException() throw () {}
|
||||
const char* what() const throw() { return s.c_str(); }
|
||||
};
|
||||
|
||||
// Read Parameters from file
|
||||
double getParameter(std::string parName);
|
||||
|
||||
//String Manipulations for Read in from files
|
||||
std::string getEnv (std::string envName); // string version of C function getenv.
|
||||
void makePath (std::string &path); // append '/' if necessary to path.
|
||||
bool checkIgnoreLine(std::string lineFromFile); // true if line is empty or starts with #
|
||||
void removeLeadingWhites(std::string &lineFromFile);
|
||||
void replaceDelimiter(std::string &lineFromFile); // replaces delimiter (';'',''=') with whitespace
|
||||
|
||||
// Calculate Kinematic Relations
|
||||
double get_Speed_from_Ekin_eV(double Ekin_eV, double mass_eV);
|
||||
double get_gamma_from_Ekin_eV(double Ekin_eV, double mass_eV);
|
||||
double get_beta_from_gamma(double gamma);
|
||||
double get_Ekin_eV_from_speed(double Speed, double mass_eV);
|
||||
double get_gamma_from_beta(double beta);
|
||||
|
||||
vec3 get_Newdirection(vec3 oldDir, double theta,double phi);
|
||||
// Operations on 3 dimensional Vectors
|
||||
double get_vecAbs(vec3 vec);
|
||||
vec3 get_Newdirection(vec3 oldDir, double theta,double phi); // Calculates new Direction after Interaction with (theta, phi)
|
||||
|
||||
// Functions for Random Sampling
|
||||
vec3 roll_uniform_direction(ranlib::Uniform<double> *rngUni);
|
||||
double roll_MBEnergy(double Temp_K,double mass_eV,ranlib::NormalUnit<double> *rngNormal);
|
||||
double doRejectionMethod(double pdf(double), double xmin, double xmax, double pmax, ranlib::Uniform<double> *rngUni);
|
||||
|
||||
+20
-23
@@ -9,7 +9,6 @@
|
||||
|
||||
#include "katrin.hpp"
|
||||
|
||||
#include "myexeption.h"
|
||||
#include "functions.hpp"
|
||||
|
||||
#include "sstream"
|
||||
@@ -17,9 +16,19 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
Katrin::Katrin() {
|
||||
set_cutoffEnergy_eV();
|
||||
}
|
||||
const double Katrin::wgtsMagField_T = getParameter("wgtsMagField_T");
|
||||
const double Katrin::wgtsLength_m = getParameter("wgtsLength_m");
|
||||
const double Katrin::wgtsRadius_m = getParameter("wgtsRadius_m");
|
||||
const double Katrin::wgtsT2MaxDensity_m3 = getParameter("wgtsT2MaxDensity_m3");
|
||||
const double Katrin::wgtsTemp_K = getParameter("wgtsTemp_K");
|
||||
const double Katrin::wgtsT2FlowSpeed_ms = getParameter("wgtsT2FlowSpeed_ms");
|
||||
|
||||
const int Katrin::injectionMethod = getParameter("injectionMethod");
|
||||
const double Katrin::injectionEnergy_eV = getParameter("injectionEnergy_eV");
|
||||
|
||||
const double Katrin::dt_s = getParameter("dt_s");
|
||||
|
||||
const double Katrin::cutoffEnergy_eV = getParameter("cutoffEnergy_eV");
|
||||
|
||||
vec3 Katrin::getMagField_T(vec3 loc_m) {
|
||||
vec3 MagField_T;
|
||||
@@ -35,7 +44,7 @@ double Katrin::getTritiumDensity_m3(vec3 loc_m) {
|
||||
double mid_m = wgtsLength_m/2;
|
||||
double zProjection_m = (loc_m[2] < mid_m) ? loc_m[2] : wgtsLength_m - loc_m[2] ;
|
||||
double reductget_ionFactor = zProjection_m/mid_m;
|
||||
return(reductget_ionFactor * wgtsT2Density_m3);
|
||||
return(reductget_ionFactor * wgtsT2MaxDensity_m3);
|
||||
}
|
||||
|
||||
vec3 Katrin::getTotSpeedT2_ms(vec3 loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
||||
@@ -57,7 +66,6 @@ vec3 Katrin::getTempSpeedT2_ms(vec3 loc_m, ranlib::Uniform<double> *rngUni, ranl
|
||||
}
|
||||
|
||||
Electron Katrin::injectElectron(int newId, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal) {
|
||||
|
||||
double r_m = wgtsRadius_m*sqrt(rngUni->random());
|
||||
double phi = rngUni->random()*2*pi;
|
||||
|
||||
@@ -71,10 +79,10 @@ Electron Katrin::injectElectron(int newId, ranlib::Uniform<double> *rngUni, ranl
|
||||
Ekin_eV = roll_FermiEnergy_eV(rngUni);
|
||||
break;
|
||||
case 1: //Delta
|
||||
Ekin_eV = deltaKinEnergy_eV;
|
||||
Ekin_eV = injectionEnergy_eV;
|
||||
break;
|
||||
case 2: //Maxwell Boltzman
|
||||
Ekin_eV = roll_MBEnergy(MBTemp_K,me_eV, rngNormal);
|
||||
Ekin_eV = roll_MBEnergy(injectionEnergy_eV/kb_eVK,me_eV, rngNormal);
|
||||
break;
|
||||
default:
|
||||
throw MyException("Katrin::injectElectron: Invalid Injection Method.");
|
||||
@@ -115,7 +123,7 @@ double Katrin::get_FermiFunction(double Z, double Ekin_eV) {
|
||||
}
|
||||
|
||||
// Move Electrons and Log
|
||||
void Katrin::do_BorisPushMovement(Electron *moveElectron, double distance_m, Logger *Log) {
|
||||
void Katrin::do_BorisPushMovement(Electron *moveElectron, double distance_m, H5_Logger *Log) {
|
||||
// Rework, with Logging and Reflection at wall
|
||||
vec3 loc_m;
|
||||
|
||||
@@ -160,7 +168,7 @@ void Katrin::doBoris_WallInteraction(Electron *moveElectron) {
|
||||
}
|
||||
}
|
||||
|
||||
void Katrin::doBoris_LogzDirChange(Electron *moveElectron, double *oldzDir, vec3 *oldLoc_m, Logger *Log) {
|
||||
void Katrin::doBoris_LogzDirChange(Electron *moveElectron, double *oldzDir, vec3 *oldLoc_m, H5_Logger *Log) {
|
||||
double zDir = moveElectron->get_Speed_ms()[2] < 0 ? -1 : 1;
|
||||
if (*oldzDir != zDir) {
|
||||
Log->log_Electron(moveElectron, *oldLoc_m);
|
||||
@@ -170,7 +178,7 @@ void Katrin::doBoris_LogzDirChange(Electron *moveElectron, double *oldzDir, vec3
|
||||
return;
|
||||
}
|
||||
|
||||
void Katrin::do_DriftApproximationMovement(Electron *moveElectron, double distance_m, Logger *Log) {
|
||||
void Katrin::do_DriftApproximationMovement(Electron *moveElectron, double distance_m, H5_Logger *Log) {
|
||||
// Drift Approximation: Assume constant B and only movement out in z=0, z=wgtsLength_m...
|
||||
vec3 oldLoc_m = moveElectron->get_Location_m();
|
||||
vec3 newLoc_m = oldLoc_m;
|
||||
@@ -197,7 +205,7 @@ double Katrin::getDrift_znew_m(double distance_m, Electron *moveElectron) {
|
||||
return (znew_m);
|
||||
}
|
||||
|
||||
void Katrin::doDrift_WallInteraction(vec3 *oldLoc_m, double *znew_m, Electron *moveElectron, Logger *Log) {
|
||||
void Katrin::doDrift_WallInteraction(vec3 *oldLoc_m, double *znew_m, Electron *moveElectron, H5_Logger *Log) {
|
||||
if (*znew_m >= wgtsLength_m) { // Moveing into Spectrometer and reversing Speed.
|
||||
vec3 reverseLoc_m = *oldLoc_m;
|
||||
reverseLoc_m[2] = wgtsLength_m;
|
||||
@@ -268,14 +276,3 @@ bool Katrin::check_WallTermination(Electron checkElectron) {
|
||||
}
|
||||
|
||||
|
||||
void Katrin::set_cutoffEnergy_eV() {
|
||||
if (cutoffMode==0) {
|
||||
cutoffEnergy_eV = cutoffEnergySet_eV;
|
||||
} else if (cutoffMode==1) {
|
||||
cutoffEnergy_eV = kb_eVK*wgtsTemp_K*cutoffFactor;
|
||||
} else {
|
||||
stringstream ss;
|
||||
ss<<"Katrin::set_cutoffEnergy_eV(): cutoffMode= "<<cutoffMode<<" not defined.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
+24
-10
@@ -9,7 +9,6 @@
|
||||
#ifndef katrin_hpp
|
||||
#define katrin_hpp
|
||||
|
||||
#include "parameter.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "logger.hpp"
|
||||
#include "electron.hpp"
|
||||
@@ -20,10 +19,12 @@
|
||||
#include <random/normal.h>
|
||||
|
||||
|
||||
class Katrin: private Parameter, private Constants {
|
||||
class Katrin {
|
||||
public:
|
||||
Katrin();
|
||||
Katrin() {};
|
||||
|
||||
// Katrin Properties
|
||||
public:
|
||||
vec3 getMagField_T(vec3 loc_m);
|
||||
vec3 getElField_Vm(vec3 loc_m);
|
||||
double getTritiumDensity_m3(vec3 loc_m);
|
||||
@@ -31,8 +32,15 @@ public:
|
||||
vec3 getTotSpeedT2_ms(vec3 loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
||||
vec3 getFlowSpeedT2_ms(vec3 loc_m);
|
||||
vec3 getTempSpeedT2_ms(vec3 loc_m, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
||||
private:
|
||||
static const double wgtsMagField_T;
|
||||
static const double wgtsLength_m;
|
||||
static const double wgtsRadius_m;
|
||||
static const double wgtsT2MaxDensity_m3;
|
||||
static const double wgtsTemp_K;
|
||||
static const double wgtsT2FlowSpeed_ms;
|
||||
|
||||
// Injection
|
||||
// Electron Injection
|
||||
public:
|
||||
Electron injectElectron(int newId, ranlib::Uniform<double> *rngUni, ranlib::NormalUnit<double> *rngNormal);
|
||||
private:
|
||||
@@ -40,16 +48,22 @@ private:
|
||||
double get_FermiDecaySpectrumDensity(double Ekin_eV);
|
||||
double get_FermiFunction(double Z, double Ekin_eV);
|
||||
|
||||
static const int injectionMethod;
|
||||
static const double injectionEnergy_eV;
|
||||
|
||||
// Move Electrons
|
||||
public:
|
||||
double get_MFP_m(Electron *moveElectron);
|
||||
void do_BorisPushMovement(Electron *moveElectron, double distance_m, Logger *Log);
|
||||
void do_DriftApproximationMovement(Electron *moveElectron, double distance_m, Logger *Log);
|
||||
void do_BorisPushMovement(Electron *moveElectron, double distance_m, H5_Logger *Log);
|
||||
void do_DriftApproximationMovement(Electron *moveElectron, double distance_m, H5_Logger *Log);
|
||||
private:
|
||||
double getDrift_znew_m(double MFP_m, Electron *moveElectron);
|
||||
void doDrift_WallInteraction(vec3 *oldLoc_m, double *znew_m, Electron *moveElectron, Logger *Log);
|
||||
void doDrift_WallInteraction(vec3 *oldLoc_m, double *znew_m, Electron *moveElectron, H5_Logger *Log);
|
||||
void doBoris_WallInteraction(Electron *moveElectron);
|
||||
void doBoris_LogzDirChange(Electron *moveElectron, double *oldzDir, vec3 *oldLoc_m, Logger *Log);
|
||||
void doBoris_LogzDirChange(Electron *moveElectron, double *oldzDir, vec3 *oldLoc_m, H5_Logger *Log);
|
||||
|
||||
static const double dt_s;
|
||||
|
||||
|
||||
// Terminate Electrons
|
||||
public:
|
||||
@@ -59,8 +73,8 @@ private:
|
||||
bool check_EnergyTermination(Electron checkElectron);
|
||||
bool check_WallTermination(vec3 loc_m);
|
||||
bool check_WallTermination(Electron checkElectron);
|
||||
double cutoffEnergy_eV;
|
||||
void set_cutoffEnergy_eV();
|
||||
|
||||
static const double cutoffEnergy_eV;
|
||||
};
|
||||
|
||||
#endif /* katrin_hpp */
|
||||
|
||||
+241
-68
@@ -8,48 +8,30 @@
|
||||
|
||||
#include "logger.hpp"
|
||||
|
||||
#include "myexeption.h"
|
||||
#include "hdf5.h"
|
||||
#include "hdf5_hl.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
Logger::Logger() {
|
||||
|
||||
const int Base_Logger::numberZBins = getParameter("numberZBins");
|
||||
const double Base_Logger::wgtsLength_m = getParameter("wgtsLength_m");
|
||||
|
||||
// Base_Logger
|
||||
Base_Logger::Base_Logger() {
|
||||
if (numberZBins == 0) {
|
||||
cout<<"Logging turned off."<<endl;
|
||||
logging = false;
|
||||
return;
|
||||
}
|
||||
create_outdirName();
|
||||
set_zLogValues();
|
||||
set_outStream();
|
||||
|
||||
}
|
||||
|
||||
void Logger::log_Electron(Electron *logElectron, blitz::TinyVector<double,3> oldLoc_m) {
|
||||
if (!logging) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Assumption: no change of sign in v_z
|
||||
if (numberZBins == -1) {
|
||||
outStream[0]<<*logElectron<<endl;
|
||||
} else {
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = logElectron->get_Location_m()[2];
|
||||
double zmin = min(zold,znew);
|
||||
double zmax = max(zold,znew);
|
||||
|
||||
for (int i=0;i<numberZBins;i++) {
|
||||
if (zLogValues[i]>=zmin && zLogValues[i]<=zmax) {
|
||||
outStream[i]<<*logElectron<<endl; // Location wrong, because it s the new Location.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::set_zLogValues() {
|
||||
void Base_Logger::set_zLogValues() {
|
||||
zLogValues.clear();
|
||||
logging = true;
|
||||
if (numberZBins == -1) {
|
||||
@@ -66,7 +48,237 @@ void Logger::set_zLogValues() {
|
||||
return;
|
||||
}
|
||||
|
||||
void Logger::set_outStream() {
|
||||
string Base_Logger::getTimeString() {
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
char buffer[80];
|
||||
time (&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
strftime(buffer,sizeof(buffer),"%Y%m%d",timeinfo);
|
||||
string str(buffer);
|
||||
return(str);
|
||||
}
|
||||
|
||||
std::string Base_Logger::getparName() {
|
||||
string parpath = getenv("parpath");
|
||||
string parfile = remove_catEnding(getenv("parfile"));
|
||||
return (parpath + "/" + parfile);
|
||||
}
|
||||
|
||||
std::string Base_Logger::remove_catEnding (std::string inString) {
|
||||
if ( inString.substr(inString.size()-4, 4) == ".cat" ){
|
||||
return (inString.substr(0, inString.size()-4) );
|
||||
} else {
|
||||
return (inString);
|
||||
}
|
||||
}
|
||||
|
||||
bool Base_Logger::isFile(std::string fileName) {
|
||||
struct stat buffer;
|
||||
return (stat (fileName.c_str(), &buffer) == 0);
|
||||
}
|
||||
|
||||
bool Base_Logger::isDir(std::string dirPath) {
|
||||
struct stat info;
|
||||
if( stat( dirPath.c_str(), &info ) != 0 )
|
||||
return (false);
|
||||
else if( info.st_mode & S_IFDIR ) // S_ISDIR() doesn't exist on my windows
|
||||
return (true);
|
||||
else
|
||||
return (false);
|
||||
}
|
||||
|
||||
// H5_Logger
|
||||
H5_Logger::H5_Logger() : Base_Logger() {
|
||||
set_outH5FName();
|
||||
create_outH5F();
|
||||
create_H5Gs();
|
||||
create_particle_electronH5TBs();
|
||||
//set_outStream();
|
||||
}
|
||||
|
||||
// File
|
||||
void H5_Logger::set_outH5FName() {
|
||||
string parname = getparName();
|
||||
stringstream H5name;
|
||||
int i = 1;
|
||||
do {
|
||||
H5name.str(std::string());
|
||||
H5name << parname << "_" << getTimeString() << "_" << i++<<".h5";
|
||||
} while ( isFile(H5name.str()) );
|
||||
outH5FName = H5name.str();
|
||||
return;
|
||||
}
|
||||
|
||||
void H5_Logger::create_outH5F() {
|
||||
const string consth5Name = outH5FName;
|
||||
outH5F = H5Fcreate(consth5Name.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
|
||||
}
|
||||
|
||||
// Groups
|
||||
void H5_Logger::create_H5Gs() {
|
||||
particleH5G = H5Gcreate2(outH5F, "/Particles", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
if (numberZBins == -1) {
|
||||
particle_zH5G = new hid_t[1];
|
||||
particle_zH5G[0] = H5Gcreate2(outH5F, "/Particles/z=all", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
} else {
|
||||
particle_zH5G = new hid_t [numberZBins];
|
||||
for (int i = 0; i < numberZBins; i++)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "/Particles/z=" << zLogValues[i];
|
||||
particle_zH5G[i] = H5Gcreate2(outH5F, ss.str().c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Electrons
|
||||
const size_t H5_Logger::particle_electronH5TB_size = sizeof(logElectron);
|
||||
const char *H5_Logger::particle_electronH5TB_fieldNames[8] = { "Id","ParentId", "x_m", "y_m", "z_m", "vx_ms", "vy_ms", "vz_ms" };
|
||||
const size_t H5_Logger::particle_electronH5TB_offset[8] = {
|
||||
HOFFSET(logElectron, Id),
|
||||
HOFFSET(logElectron, parentId),
|
||||
HOFFSET(logElectron, x_m),
|
||||
HOFFSET(logElectron, y_m),
|
||||
HOFFSET(logElectron, z_m),
|
||||
HOFFSET(logElectron, vx_ms),
|
||||
HOFFSET(logElectron, vy_ms),
|
||||
HOFFSET(logElectron, vz_ms)};
|
||||
const hid_t H5_Logger::particle_electronH5TB_fieldTypes[8] = {
|
||||
H5T_NATIVE_INT,
|
||||
H5T_NATIVE_INT,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE,
|
||||
H5T_NATIVE_DOUBLE};
|
||||
const hsize_t H5_Logger::particle_electronH5TB_chunkSize = 4096;
|
||||
|
||||
logElectron sampleLogElectron = {0,0,0,0,0,0,0,0};
|
||||
const size_t H5_Logger::particle_electronH5TB_sizes[8] = {
|
||||
sizeof( sampleLogElectron.Id),
|
||||
sizeof( sampleLogElectron.parentId),
|
||||
sizeof( sampleLogElectron.x_m),
|
||||
sizeof( sampleLogElectron.y_m),
|
||||
sizeof( sampleLogElectron.z_m),
|
||||
sizeof( sampleLogElectron.vx_ms),
|
||||
sizeof( sampleLogElectron.vy_ms),
|
||||
sizeof( sampleLogElectron.vz_ms)};
|
||||
|
||||
void H5_Logger::test_log() {
|
||||
Electron testElectron = Electron(vec3(1,2,3), vec3(4,5,6), 7, 8);
|
||||
log_Electron(&testElectron, vec3(9,10,7));
|
||||
return;
|
||||
}
|
||||
|
||||
void H5_Logger::log_Electron(Electron *inElectron,blitz::TinyVector<double,3> oldLoc_m) {
|
||||
if (!logging) {
|
||||
return;
|
||||
}
|
||||
logElectron logElectron_buffer = Electron_to_logElectron(inElectron);
|
||||
// Assumption: no change of sign in v_z
|
||||
if (numberZBins == -1) {
|
||||
H5TBappend_records(particle_zH5G[0], "electrons", 1, particle_electronH5TB_size, particle_electronH5TB_offset, particle_electronH5TB_sizes, &logElectron_buffer );
|
||||
} else {
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = inElectron->get_Location_m()[2];
|
||||
double zmin = min(zold,znew);
|
||||
double zmax = max(zold,znew);
|
||||
|
||||
for (int i=0;i<numberZBins;i++) {
|
||||
if (zLogValues[i]>=zmin && zLogValues[i]<=zmax) {
|
||||
H5TBappend_records(particle_zH5G[i], "electrons", 1, particle_electronH5TB_size, particle_electronH5TB_offset, particle_electronH5TB_sizes, &logElectron_buffer ); // Location wrong, because it s the new Location.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void H5_Logger::create_particle_electronH5TBs() {
|
||||
if (numberZBins == -1) {
|
||||
particle_electronH5T = new hid_t[1];
|
||||
particle_electronH5T[0] = H5TBmake_table( "Electron Table", particle_zH5G[0], "electrons", 8, 0,
|
||||
particle_electronH5TB_size, particle_electronH5TB_fieldNames, particle_electronH5TB_offset, particle_electronH5TB_fieldTypes,
|
||||
particle_electronH5TB_chunkSize, NULL, 0, NULL);
|
||||
} else {
|
||||
particle_electronH5T = new hid_t[numberZBins];
|
||||
for (int i = 0; i < numberZBins; i++)
|
||||
{
|
||||
particle_electronH5T[i] = H5TBmake_table( "Electron Table", particle_zH5G[i], "electrons",8,0,
|
||||
particle_electronH5TB_size, particle_electronH5TB_fieldNames, particle_electronH5TB_offset, particle_electronH5TB_fieldTypes,
|
||||
particle_electronH5TB_chunkSize, NULL, 0, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logElectron H5_Logger::Electron_to_logElectron(Electron *inElectron) {
|
||||
logElectron res;
|
||||
res.Id = inElectron->get_Id();
|
||||
res.parentId = inElectron->get_ParentId();
|
||||
res.x_m = inElectron->get_Location_m()[0];
|
||||
res.y_m = inElectron->get_Location_m()[1];
|
||||
res.z_m = inElectron->get_Location_m()[2];
|
||||
res.vx_ms = inElectron->get_Speed_ms()[0];
|
||||
res.vy_ms = inElectron->get_Speed_ms()[1];
|
||||
res.vz_ms = inElectron->get_Speed_ms()[2];
|
||||
return (res);
|
||||
}
|
||||
|
||||
// ASCI_Logger
|
||||
ASCI_Logger::ASCI_Logger() : Base_Logger() {
|
||||
set_outdirName();
|
||||
create_outdir();
|
||||
set_outStream();
|
||||
}
|
||||
|
||||
void ASCI_Logger::log_Electron(Electron *inElectron, blitz::TinyVector<double,3> oldLoc_m) {
|
||||
if (!logging) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Assumption: no change of sign in v_z
|
||||
if (numberZBins == -1) {
|
||||
outStream[0]<<*inElectron<<endl;
|
||||
} else {
|
||||
double zold = oldLoc_m[2];
|
||||
double znew = inElectron->get_Location_m()[2];
|
||||
double zmin = min(zold,znew);
|
||||
double zmax = max(zold,znew);
|
||||
|
||||
for (int i=0;i<numberZBins;i++) {
|
||||
if (zLogValues[i]>=zmin && zLogValues[i]<=zmax) {
|
||||
outStream[i]<<*inElectron<<endl; // Location wrong, because it s the new Location.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ASCI_Logger::set_outdirName() {
|
||||
string parname = getparName();
|
||||
stringstream dirname;
|
||||
int i = 1;
|
||||
do {
|
||||
dirname.str(std::string());
|
||||
dirname << parname << "_" << getTimeString() << "_" << i++;
|
||||
} while ( isDir(dirname.str()) );
|
||||
outdirName = dirname.str();
|
||||
return;
|
||||
}
|
||||
|
||||
void ASCI_Logger::create_outdir() {
|
||||
if (mkdir(outdirName.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
|
||||
stringstream ss;
|
||||
ss<<"ASCI_Logger::create_outdir: Could not create output directiory.\n outdirName = "<<outdirName<<endl;
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void ASCI_Logger::set_outStream() {
|
||||
if (numberZBins == -1) {
|
||||
outStream = new ofstream [1];
|
||||
stringstream ss;
|
||||
@@ -82,42 +294,3 @@ void Logger::set_outStream() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::create_outdirName() {
|
||||
string poub = getenv("parpath");
|
||||
string pname = getenv("parfile");
|
||||
int i = 1;
|
||||
stringstream dirname;
|
||||
struct stat statbuf;
|
||||
int isDir;
|
||||
do {
|
||||
dirname.str(std::string());
|
||||
dirname << poub << "/" << pname << "_" << getTimeString() << "_" << i++;
|
||||
isDir = 0;
|
||||
if (stat(dirname.str().c_str(), &statbuf) != -1) {
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
isDir = 1;
|
||||
}
|
||||
}
|
||||
} while ( isDir == 1 );
|
||||
if (mkdir(dirname.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
|
||||
stringstream ss;
|
||||
ss<<"Simulation::initLogger: Could not create folder "<<dirname.str()<<" for Logging.";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
outdirName = dirname.str();
|
||||
return;
|
||||
}
|
||||
|
||||
string Logger::getTimeString() {
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
char buffer[80];
|
||||
time (&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
strftime(buffer,sizeof(buffer),"%Y%m%d",timeinfo);
|
||||
string str(buffer);
|
||||
return(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,25 +9,97 @@
|
||||
#ifndef logger_hpp
|
||||
#define logger_hpp
|
||||
|
||||
#include "parameter.hpp"
|
||||
#include "electron.hpp"
|
||||
|
||||
#include "hdf5.h"
|
||||
|
||||
class Logger : private Parameter {
|
||||
typedef struct logElectron {
|
||||
unsigned int Id;
|
||||
unsigned int parentId;
|
||||
double x_m;
|
||||
double y_m;
|
||||
double z_m;
|
||||
double vx_ms;
|
||||
double vy_ms;
|
||||
double vz_ms;
|
||||
} logElectron;
|
||||
|
||||
|
||||
// Base_Logger: Base_Class for all Logger: Reading Paramter and calculating z-Barrieres.
|
||||
class Base_Logger {
|
||||
public:
|
||||
Logger();
|
||||
Base_Logger();
|
||||
|
||||
protected:
|
||||
static const int numberZBins;
|
||||
static const double wgtsLength_m;
|
||||
|
||||
void log_Electron(Electron *logElectron,blitz::TinyVector<double,3> oldLoc_m);
|
||||
private:
|
||||
bool logging;
|
||||
std::string outdirName;
|
||||
std::vector<double> zLogValues;
|
||||
std::ofstream *outStream;
|
||||
|
||||
void set_zLogValues();
|
||||
void set_outStream();
|
||||
void create_outdirName();
|
||||
|
||||
std::string getparName();
|
||||
std::string getTimeString();
|
||||
std::string remove_catEnding (std::string inString);
|
||||
bool isFile(std::string fileName);
|
||||
bool isDir(std::string dirPath);
|
||||
};
|
||||
|
||||
// H5_Logger: Logging to HDF5 file format.
|
||||
class H5_Logger : private Base_Logger {
|
||||
|
||||
|
||||
public:
|
||||
H5_Logger();
|
||||
|
||||
|
||||
private:
|
||||
// File
|
||||
std::string outH5FName;
|
||||
hid_t outH5F;
|
||||
|
||||
void set_outH5FName();
|
||||
void create_outH5F();
|
||||
|
||||
// Groups
|
||||
hid_t particleH5G;
|
||||
hid_t *particle_zH5G;
|
||||
|
||||
void create_H5Gs();
|
||||
|
||||
// Electrons
|
||||
public:
|
||||
void test_log();
|
||||
void log_Electron(Electron *inElectron,blitz::TinyVector<double,3> oldLoc_m);
|
||||
private:
|
||||
static const size_t particle_electronH5TB_size;
|
||||
static const char *particle_electronH5TB_fieldNames[8];
|
||||
static const size_t particle_electronH5TB_offset[8];
|
||||
static const hid_t particle_electronH5TB_fieldTypes[8];
|
||||
static const hsize_t particle_electronH5TB_chunkSize;
|
||||
static const size_t particle_electronH5TB_sizes[8];
|
||||
|
||||
hid_t *particle_electronH5T;
|
||||
|
||||
void create_particle_electronH5TBs();
|
||||
|
||||
logElectron Electron_to_logElectron(Electron *inElectron);
|
||||
};
|
||||
|
||||
// ASCI_Logger: Log to ASCI-File. Only Electron Logger. Not very efficient.
|
||||
class ASCI_Logger : private Base_Logger {
|
||||
public:
|
||||
ASCI_Logger();
|
||||
|
||||
void log_Electron(Electron *inElectron,blitz::TinyVector<double,3> oldLoc_m);
|
||||
private:
|
||||
std::string outdirName;
|
||||
std::ofstream *outStream;
|
||||
|
||||
void set_outdirName();
|
||||
void create_outdir();
|
||||
void set_outStream();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "simulation.hpp"
|
||||
|
||||
#include "myexeption.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
@@ -8,13 +8,14 @@ CXXFLAGS = $(X_OFLAGS) -I.. $(X_INC)
|
||||
|
||||
LDFLAGS = $(X_LIB)
|
||||
|
||||
LOADLIBES = -lblitz -lm
|
||||
LOADLIBES = -lblitz -lm -lhdf5 -lhdf5_hl
|
||||
|
||||
TARGETS = mcelectron
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
mcelectron: main.o parameter.o functions.o constants.o katrin.o logger.o simulation.o \
|
||||
mcelectron: main.o simulation.o\
|
||||
functions.o function_container.o katrin.o logger.o \
|
||||
particle.o electron.o bedionization.o
|
||||
$(CXX) -o $@ $^ $(LDFLAGS) $(LOADLIBES)
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
//
|
||||
// myexeption.h
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 01.03.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef myexeption_h
|
||||
#define myexeption_h
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct MyException : public exception
|
||||
{
|
||||
string s;
|
||||
MyException(string ss) : s(ss) {}
|
||||
~MyException() throw () {} // Updated
|
||||
const char* what() const throw() { return s.c_str(); }
|
||||
};
|
||||
|
||||
#endif /* myexeption_h */
|
||||
@@ -1,103 +0,0 @@
|
||||
//
|
||||
// parameter.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 26.02.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#include "parameter.hpp"
|
||||
|
||||
#include "myexeption.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
Parameter::Parameter() {
|
||||
// Simulation Specs
|
||||
|
||||
seed = (int)getValue("seed");
|
||||
numberTotalDecays = (int)getValue("numberTotalDecays");
|
||||
dt_s = getValue("dt_s");
|
||||
injectionMethod = (int)getValue("injectionMethod");
|
||||
deltaKinEnergy_eV = getValue("deltaKinEnergy_eV");
|
||||
MBTemp_K = getValue("MBTemp_K");
|
||||
elaOn = (int)getValue("elaOn");
|
||||
ionOn = (int)getValue("ionOn");
|
||||
propagationMethod = (int)getValue("propagationMethod");
|
||||
|
||||
// Cutoff
|
||||
cutoffMode = (int)getValue("cutoffMode");
|
||||
cutoffEnergySet_eV = getValue("cutoffEnergySet_eV");
|
||||
cutoffFactor = getValue("cutoffFactor");
|
||||
maxNumberInteractionsPerElectron = getValue("maxNumberInteractionsPerElectron");
|
||||
|
||||
// Katrin Specs
|
||||
wgtsMagField_T = getValue("wgtsMagField_T");
|
||||
wgtsLength_m = getValue("wgtsLength_m");
|
||||
wgtsRadius_m = getValue("wgtsRadius_m");
|
||||
wgtsT2Density_m3 = getValue("wgtsT2Density_m3");
|
||||
wgtsTemp_K = getValue("wgtsTemp_K");
|
||||
wgtsT2FlowSpeed_ms = getValue("wgtsT2FlowSpeed_ms");
|
||||
|
||||
// Output
|
||||
numberZBins = getValue ("numberZBins");
|
||||
|
||||
}
|
||||
|
||||
|
||||
double Parameter::getValue(string varName) {
|
||||
char* ext = (char*)("cat");
|
||||
char* str = strdup(varName.c_str());
|
||||
double temp;
|
||||
char dummy[256];
|
||||
char fname[256],*parfile;
|
||||
FILE *fcat;
|
||||
|
||||
if (getenv("parpath") == NULL)
|
||||
{
|
||||
throw MyException("Parameter::value: Environment variable parpath not defined.");
|
||||
}
|
||||
strcpy(fname, getenv("parpath"));
|
||||
parfile = getenv("parfile");
|
||||
if (parfile == NULL)
|
||||
{
|
||||
throw MyException("Parameter::value: Environment variable parfile not defined.");
|
||||
}
|
||||
if (!ext)
|
||||
{
|
||||
ext = (char*)("cat");
|
||||
}
|
||||
sprintf(fname,"%s/%s.%s",getenv("parpath"),getenv("parfile"), ext);
|
||||
if (!(fcat = fopen(fname, "r")))
|
||||
{
|
||||
stringstream ss;
|
||||
ss<<"Parameter::value: Can not open file " <<fname<<".";
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
while (!feof(fcat))
|
||||
{
|
||||
// fscanf(fcat, "'%s%*[^']'%F%*[^']",dummy,&temp); 1
|
||||
fscanf(fcat, "%s = %lf", dummy, &temp);
|
||||
// if (strncmp(dummy, str,strlen(str)) == 0) {
|
||||
if (strcmp(dummy, str) == 0)
|
||||
{
|
||||
fclose(fcat);
|
||||
return(temp);
|
||||
}
|
||||
}
|
||||
fclose(fcat);
|
||||
|
||||
stringstream ss;
|
||||
ss<<"Parameter::value: Variable "<<str<<" not found.";
|
||||
throw MyException(ss.str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
//
|
||||
// parameter.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 20.09.18.
|
||||
// Copyright © 2018 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef parameter_hpp
|
||||
#define parameter_hpp
|
||||
|
||||
#include <string>
|
||||
|
||||
class Parameter {
|
||||
public:
|
||||
Parameter();
|
||||
|
||||
protected:
|
||||
//Simulation Specs
|
||||
int seed ;
|
||||
long int numberTotalDecays;
|
||||
double dt_s;
|
||||
int injectionMethod; // 0 = Beta Decay, 1 = Delta, 2 = Maxwell Boltzmann
|
||||
double deltaKinEnergy_eV;
|
||||
double MBTemp_K;
|
||||
int elaOn;
|
||||
int ionOn;
|
||||
int propagationMethod; // 0 = Drift Approximation, 1 = Borispush
|
||||
|
||||
// Cutoff
|
||||
int cutoffMode; // 0 = Energy from Parameter, 1 = WGTSTemperature*cutoffFactor
|
||||
double cutoffEnergySet_eV;
|
||||
double cutoffFactor;
|
||||
int maxNumberInteractionsPerElectron;
|
||||
|
||||
//KATRIN Specs
|
||||
double wgtsMagField_T;
|
||||
double wgtsLength_m;
|
||||
double wgtsRadius_m;
|
||||
double wgtsT2Density_m3;
|
||||
double wgtsTemp_K;
|
||||
double wgtsT2FlowSpeed_ms;
|
||||
|
||||
// Output
|
||||
int numberZBins;
|
||||
|
||||
private:
|
||||
double getValue(std::string varName);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -9,7 +9,6 @@
|
||||
#ifndef particle_hpp
|
||||
#define particle_hpp
|
||||
|
||||
#include "parameter.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "functions.hpp"
|
||||
|
||||
@@ -22,7 +21,7 @@ typedef enum species{undef, electron, positron, proton, tritium, tritium2, heliu
|
||||
std::ostream& operator<<(std::ostream& os, const species& SpecOut);
|
||||
|
||||
|
||||
class Particle: protected Parameter, protected Constants{
|
||||
class Particle {
|
||||
public:
|
||||
Particle(double mass_eV, double charge_e,vec3 loc_m, vec3 speed_ms, double idnum, double parentIdnum, species spec);
|
||||
|
||||
@@ -32,8 +31,8 @@ protected:
|
||||
vec3 x_m;
|
||||
vec3 v_ms;
|
||||
species s;
|
||||
unsigned long int Id;
|
||||
unsigned long int parentId;
|
||||
unsigned int Id;
|
||||
unsigned int parentId;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@@ -9,13 +9,19 @@
|
||||
|
||||
#include "simulation.hpp"
|
||||
|
||||
#include "myexeption.h"
|
||||
#include "constants.hpp"
|
||||
#include "functions.hpp"
|
||||
|
||||
#include "fstream"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
const long int Simulation::seed = getParameter("seed");
|
||||
const long int Simulation::numberTotalDecays = getParameter("numberTotalDecays");
|
||||
const int Simulation::propagationMethod = getParameter("propagationMethod");
|
||||
const int Simulation::maxInteractions = getParameter("maxInteractions");
|
||||
|
||||
Simulation::Simulation() {
|
||||
numberTotalElectrons = 0;
|
||||
numberDecays = 0;
|
||||
@@ -45,11 +51,11 @@ void Simulation::doit() {
|
||||
};
|
||||
|
||||
bool Simulation::check_NumberInteractions(int &numberInteractionsThisElectron) {
|
||||
if (maxNumberInteractionsPerElectron == 0) {
|
||||
if (maxInteractions == 0) {
|
||||
return(false);
|
||||
}
|
||||
|
||||
if (numberInteractionsThisElectron < maxNumberInteractionsPerElectron) {
|
||||
if (numberInteractionsThisElectron < maxInteractions) {
|
||||
numberInteractionsThisElectron++;
|
||||
return(false);
|
||||
} else {
|
||||
@@ -82,7 +88,7 @@ void Simulation::do_statusUpdate() {
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::move_electron(Electron *moveElectron, Logger *Log) {
|
||||
void Simulation::move_electron(Electron *moveElectron, H5_Logger *Log) {
|
||||
double MFP_m = Kat.get_MFP_m(&electronQue.front());
|
||||
if (propagationMethod==0) {
|
||||
Kat.do_DriftApproximationMovement(moveElectron, MFP_m, Log);
|
||||
@@ -125,10 +131,10 @@ void Simulation::do_interaction(Electron *interactElectron) {
|
||||
|
||||
void Simulation::parameterCheck_TC6() {
|
||||
if (
|
||||
injectionMethod == 1 &&
|
||||
elaOn == 0 &&
|
||||
ionOn == 1 &&
|
||||
numberZBins == -1
|
||||
getParameter("injectionMethod") == 1 &&
|
||||
getParameter("elaOn") == 0 &&
|
||||
getParameter("ionOn") == 1 &&
|
||||
getParameter("numberZBins") == -1
|
||||
) {
|
||||
return;
|
||||
}else {
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#define simulation_hpp
|
||||
|
||||
|
||||
#include "parameter.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "katrin.hpp"
|
||||
#include "electron.hpp"
|
||||
#include "logger.hpp"
|
||||
@@ -19,22 +17,26 @@
|
||||
#include <deque>
|
||||
|
||||
|
||||
class Simulation: private Parameter, private Constants {
|
||||
class Simulation {
|
||||
public:
|
||||
Simulation();
|
||||
|
||||
|
||||
void doit();
|
||||
private:
|
||||
void do_statusUpdate();
|
||||
void move_electron(Electron *moveElectron, Logger *Log);
|
||||
void move_electron(Electron *moveElectron, H5_Logger *Log);
|
||||
void do_interaction(Electron *interactElectron);
|
||||
bool check_NumberInteractions(int &numberInteractionsThisElectron);
|
||||
|
||||
Katrin Kat;
|
||||
Logger Log;
|
||||
H5_Logger Log;
|
||||
|
||||
ranlib::Uniform<double> rngUni;
|
||||
ranlib::NormalUnit<double> rngNormal;
|
||||
|
||||
int numberTotalElectrons;
|
||||
int numberDecays;
|
||||
|
||||
std::deque<Electron> electronQue;
|
||||
Electron *actionElectronPtr;
|
||||
|
||||
@@ -42,6 +44,11 @@ private:
|
||||
int updater_numberOfPrevious;
|
||||
int updater_fraction;
|
||||
|
||||
static const long int seed;
|
||||
static const long int numberTotalDecays;
|
||||
|
||||
static const int propagationMethod;
|
||||
static const int maxInteractions;
|
||||
public:
|
||||
void doTC6();
|
||||
private:
|
||||
|
||||
@@ -7,20 +7,39 @@
|
||||
//
|
||||
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include "function_container.hpp"
|
||||
#include "function2D_container.hpp"
|
||||
//#include <mpi.h>
|
||||
#include "hdf5.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
string file = "/Users/ChristianReiling/Documents/Masterarbeit/katrin-plasma/src/test_enviroment/yoon_TCS_ionization.dat";
|
||||
int main() {
|
||||
|
||||
Func_Container Func(file);
|
||||
cout<<Func.interpolate(625)<<endl;
|
||||
const std::string filePath = "/Users/ChristianReiling/Desktop/hdf5_example/examplefile.h5";
|
||||
|
||||
hid_t file_id, dataset_id, dataspace_id; /* identifiers */
|
||||
hsize_t dims[2];
|
||||
herr_t status;
|
||||
|
||||
/* Create a new file using default properties. */
|
||||
file_id = H5Fcreate(filePath.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/* Create the data space for the dataset. */
|
||||
dims[0] = 4;
|
||||
dims[1] = 6;
|
||||
dataspace_id = H5Screate_simple(2, dims, NULL);
|
||||
|
||||
/* Create the dataset. */
|
||||
dataset_id = H5Dcreate2(file_id, "/dset", H5T_STD_I32BE, dataspace_id,
|
||||
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/* End access to the dataset and release resources used by it. */
|
||||
status = H5Dclose(dataset_id);
|
||||
|
||||
/* Terminate access to the data space. */
|
||||
status = H5Sclose(dataspace_id);
|
||||
|
||||
/* Close the file. */
|
||||
status = H5Fclose(file_id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user