Merge branch 'master' of https://fsk-serval.puk.ac.za/gitea/katrin/katrin-plasma
This commit is contained in:
@@ -69,17 +69,37 @@ void Func2D_Container::add_ankerpoint(double x, double y, double fxy) {
|
||||
}
|
||||
|
||||
void Func2D_Container::readFromCSV(std::string loadFilePath) {
|
||||
// Very simple implementation, maybe improve in further version... stability towards file format, comments...
|
||||
double xTemp;
|
||||
double yTemp;
|
||||
double fxyTemp;
|
||||
|
||||
ifstream file(loadFilePath);
|
||||
|
||||
while ((file >> xTemp) && (file >> yTemp) && (file >> fxyTemp)) {
|
||||
add_ankerpoint(xTemp, yTemp, fxyTemp);
|
||||
ifstream fileStream(loadFilePath);
|
||||
if (!fileStream.good()) {
|
||||
stringstream ss;
|
||||
ss<<"Func_Container::readFromCSV: Could not open file.\nloadFilePath= "<<loadFilePath<<endl;
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
file.close();
|
||||
return;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -57,15 +57,69 @@ void Func_Container::add_ankerpoint(double x, double fx) {
|
||||
}
|
||||
|
||||
void Func_Container::readFromCSV(std::string loadFilePath) {
|
||||
// Very simple implementation, maybe improve in further version... stability towards file format, comments...
|
||||
double xTemp;
|
||||
double fxTemp;
|
||||
ifstream fileStream(loadFilePath);
|
||||
|
||||
ifstream file(loadFilePath);
|
||||
|
||||
while ((file >> xTemp) && (file >> fxTemp)) {
|
||||
add_ankerpoint(xTemp, fxTemp);
|
||||
if (!fileStream.good()) {
|
||||
stringstream ss;
|
||||
ss<<"Func_Container::readFromCSV: Could not open file: "<<loadFilePath<<endl;
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
file.close();
|
||||
|
||||
string lineFromFile;
|
||||
stringstream ss;
|
||||
double xTemp, fxTemp;
|
||||
bool lineReadError = false;
|
||||
|
||||
while (getline(fileStream, lineFromFile)) {
|
||||
removeLeadingWhites(lineFromFile);
|
||||
replaceDelimiter(lineFromFile);
|
||||
if ( checkIgnoreLine(lineFromFile) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ss.clear();
|
||||
ss.str(lineFromFile);
|
||||
|
||||
if (ss>>xTemp && ss>>fxTemp) {
|
||||
add_ankerpoint(xTemp, fxTemp);
|
||||
} else {
|
||||
if (!lineReadError) {
|
||||
cout<<"Func_Container::readFromCSV: Warning could not read line in inputFile. \nloadFilePath = "<<loadFilePath<<endl;
|
||||
lineReadError = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
fileStream.close();
|
||||
|
||||
}
|
||||
|
||||
void Func_Container::printAnkerpoints() {
|
||||
dim1Map::iterator AnkerItr;
|
||||
for (AnkerItr = Map.begin();AnkerItr!=Map.end();AnkerItr++) {
|
||||
cout<<AnkerItr->first<<"\t"<<AnkerItr->second<<"\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool checkIgnoreLine(string lineFromFile) {
|
||||
if (lineFromFile[0] =='#') {
|
||||
return true;
|
||||
} else if ( lineFromFile.empty() ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
void replaceDelimiter(string &lineFromFile) {
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ';', ' ');
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ',', ' ');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,13 @@ public:
|
||||
private:
|
||||
dim1Map Map;
|
||||
void readFromCSV(std::string loadFilePath);
|
||||
public:
|
||||
void printAnkerpoints();
|
||||
} ;
|
||||
|
||||
|
||||
void removeLeadingWhites(std::string &lineFromFile);
|
||||
void replaceDelimiter(std::string &lineFromFile);
|
||||
bool checkIgnoreLine(std::string lineFromFile);
|
||||
|
||||
#endif /* function_container_hpp */
|
||||
|
||||
@@ -24,7 +24,7 @@ Parameter::Parameter() {
|
||||
// Simulation Specs
|
||||
|
||||
seed = (int)getValue("seed");
|
||||
numTotalElectrons = (long int)getValue("numTotalElectrons");
|
||||
numberTotalDecays = (int)getValue("numberTotalDecays");
|
||||
dt_s = getValue("dt_s");
|
||||
injectionMethod = (int)getValue("injectionMethod");
|
||||
deltaKinEnergy_eV = getValue("deltaKinEnergy_eV");
|
||||
@@ -37,6 +37,7 @@ Parameter::Parameter() {
|
||||
cutoffMode = (int)getValue("cutoffMode");
|
||||
cutoffEnergySet_eV = getValue("cutoffEnergySet_eV");
|
||||
cutoffFactor = getValue("cutoffFactor");
|
||||
maxNumberInteractionsPerElectron = getValue("maxNumberInteractionsPerElectron");
|
||||
|
||||
// Katrin Specs
|
||||
wgtsMagField_T = getValue("wgtsMagField_T");
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
protected:
|
||||
//Simulation Specs
|
||||
int seed ;
|
||||
long int numTotalElectrons;
|
||||
long int numberTotalDecays;
|
||||
double dt_s;
|
||||
int injectionMethod; // 0 = Beta Decay, 1 = Delta, 2 = Maxwell Boltzmann
|
||||
double deltaKinEnergy_eV;
|
||||
@@ -31,6 +31,7 @@ protected:
|
||||
int cutoffMode; // 0 = Energy from Parameter, 1 = WGTSTemperature*cutoffFactor
|
||||
double cutoffEnergySet_eV;
|
||||
double cutoffFactor;
|
||||
int maxNumberInteractionsPerElectron;
|
||||
|
||||
//KATRIN Specs
|
||||
double wgtsMagField_T;
|
||||
|
||||
@@ -17,42 +17,55 @@ using namespace std;
|
||||
|
||||
|
||||
Simulation::Simulation() {
|
||||
numberElectrons = 0;
|
||||
numberTotalElectrons = 0;
|
||||
numberDecays = 0;
|
||||
rngUni.seed(seed);
|
||||
updater_fraction = numTotalElectrons/100;
|
||||
updater_fraction = numberTotalDecays/100;
|
||||
updater_numberOfPrevious = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Simulation::doit() {
|
||||
vec3 oldLoc_m;
|
||||
while ( (numberElectrons < numTotalElectrons) || (electronQue.size() > 0) ) {
|
||||
int numberInteractionsThisElectron = 0;
|
||||
while ( (numberDecays < numberTotalDecays) || (electronQue.size() > 0) ) {
|
||||
if (electronQue.empty()) {
|
||||
electronQue.push_back(Kat.injectElectron(numberElectrons++, &rngUni, &rngNormal));
|
||||
electronQue.push_back(Kat.injectElectron(numberTotalElectrons++, &rngUni, &rngNormal));
|
||||
numberDecays++;
|
||||
}
|
||||
|
||||
status_updater();
|
||||
move_electron(&electronQue.front(), &Log);
|
||||
if (!Kat.check_Termination (electronQue.front()) ) {
|
||||
do_interaction(&electronQue.front());
|
||||
actionElectronPtr = &electronQue.front();
|
||||
do_statusUpdate();
|
||||
move_electron(actionElectronPtr, &Log);
|
||||
if (!Kat.check_Termination (*actionElectronPtr) ) {
|
||||
do_interaction(actionElectronPtr);
|
||||
}
|
||||
if (Kat.check_Termination (electronQue.front())) {
|
||||
if (Kat.check_Termination (*actionElectronPtr) || check_NumberInteractions(numberInteractionsThisElectron)) {
|
||||
electronQue.pop_front();
|
||||
numberInteractionsThisElectron = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
bool Simulation::check_NumberInteractions(int &numberInteractionsThisElectron) {
|
||||
if (maxNumberInteractionsPerElectron == 0) {
|
||||
return(false);
|
||||
}
|
||||
|
||||
if (numberInteractionsThisElectron < maxNumberInteractionsPerElectron) {
|
||||
numberInteractionsThisElectron++;
|
||||
return(false);
|
||||
} else {
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::doTC6() {
|
||||
cout<<endl<<"Simulation::doTC6: Doing Testcase 6."<<endl<<endl;
|
||||
parameterCheck_TC6();
|
||||
|
||||
while ( (numberElectrons < numTotalElectrons) || (electronQue.size() > 0) ) {
|
||||
while ( (numberTotalElectrons < numberTotalDecays) || (electronQue.size() > 0) ) {
|
||||
if (!electronQue.empty()) {
|
||||
throw MyException("Simulation::doTC6: electronQue should be empty");
|
||||
}
|
||||
electronQue.push_back(Kat.injectElectron(numberElectrons++, &rngUni, &rngNormal));
|
||||
electronQue.push_back(Kat.injectElectron(numberTotalElectrons++, &rngUni, &rngNormal));
|
||||
do_interaction(&electronQue.front()); //parameter should only allow for ionizations
|
||||
electronQue.pop_front(); // delete initial electron
|
||||
Log.log_Electron(&electronQue.front(), vec3(0,0,0)); //should be daugther electron
|
||||
@@ -60,12 +73,12 @@ void Simulation::doTC6() {
|
||||
}
|
||||
};
|
||||
|
||||
void Simulation::status_updater() {
|
||||
if (numberElectrons%updater_fraction == 0){
|
||||
if (updater_numberOfPrevious!=numberElectrons) {
|
||||
cout<<numberElectrons<<"/"<<numTotalElectrons<<endl;
|
||||
void Simulation::do_statusUpdate() {
|
||||
if (numberDecays%updater_fraction == 0){
|
||||
if (updater_numberOfPrevious!=numberDecays) {
|
||||
cout<<numberDecays<<"/"<<numberTotalDecays<<endl;
|
||||
}
|
||||
updater_numberOfPrevious = numberElectrons;
|
||||
updater_numberOfPrevious = numberDecays;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,8 +108,8 @@ void Simulation::do_interaction(Electron *interactElectron) {
|
||||
interactElectron->do_elaScattering(Kat.getTotSpeedT2_ms(newLoc_m, &rngUni, &rngNormal) , &rngUni);
|
||||
break;
|
||||
case 2: // Ionization
|
||||
electronQue.push_back( interactElectron->do_Ionization(Kat.getTotSpeedT2_ms(newLoc_m, &rngUni, &rngNormal), numberElectrons, &rngUni) );
|
||||
numberElectrons++;
|
||||
electronQue.push_back( interactElectron->do_Ionization(Kat.getTotSpeedT2_ms(newLoc_m, &rngUni, &rngNormal), numberTotalElectrons, &rngUni) );
|
||||
numberTotalElectrons++;
|
||||
// Update Ions...
|
||||
break;
|
||||
case 3: // Recombination
|
||||
|
||||
@@ -22,22 +22,23 @@
|
||||
class Simulation: private Parameter, private Constants {
|
||||
public:
|
||||
Simulation();
|
||||
void doit();
|
||||
|
||||
|
||||
void doit();
|
||||
private:
|
||||
void status_updater();
|
||||
void do_statusUpdate();
|
||||
void move_electron(Electron *moveElectron, Logger *Log);
|
||||
void do_interaction(Electron *interactElectron);
|
||||
|
||||
|
||||
// Simulation
|
||||
bool check_NumberInteractions(int &numberInteractionsThisElectron);
|
||||
Katrin Kat;
|
||||
Logger Log;
|
||||
ranlib::Uniform<double> rngUni;
|
||||
ranlib::NormalUnit<double> rngNormal;
|
||||
int numberElectrons;
|
||||
int numberTotalElectrons;
|
||||
int numberDecays;
|
||||
std::deque<Electron> electronQue;
|
||||
Electron *actionElectronPtr;
|
||||
|
||||
//Updater
|
||||
int updater_numberOfPrevious;
|
||||
int updater_fraction;
|
||||
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
@@ -15,5 +19,8 @@
|
||||
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";
|
||||
|
||||
Func_Container Func(file);
|
||||
cout<<Func.interpolate(625)<<endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user