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) {
|
void Func2D_Container::readFromCSV(std::string loadFilePath) {
|
||||||
// Very simple implementation, maybe improve in further version... stability towards file format, comments...
|
ifstream fileStream(loadFilePath);
|
||||||
double xTemp;
|
if (!fileStream.good()) {
|
||||||
double yTemp;
|
stringstream ss;
|
||||||
double fxyTemp;
|
ss<<"Func_Container::readFromCSV: Could not open file.\nloadFilePath= "<<loadFilePath<<endl;
|
||||||
|
throw MyException(ss.str());
|
||||||
ifstream file(loadFilePath);
|
|
||||||
|
|
||||||
while ((file >> xTemp) && (file >> yTemp) && (file >> fxyTemp)) {
|
|
||||||
add_ankerpoint(xTemp, yTemp, fxyTemp);
|
|
||||||
}
|
}
|
||||||
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) {
|
void Func_Container::readFromCSV(std::string loadFilePath) {
|
||||||
// Very simple implementation, maybe improve in further version... stability towards file format, comments...
|
ifstream fileStream(loadFilePath);
|
||||||
double xTemp;
|
|
||||||
double fxTemp;
|
|
||||||
|
|
||||||
ifstream file(loadFilePath);
|
if (!fileStream.good()) {
|
||||||
|
stringstream ss;
|
||||||
while ((file >> xTemp) && (file >> fxTemp)) {
|
ss<<"Func_Container::readFromCSV: Could not open file: "<<loadFilePath<<endl;
|
||||||
add_ankerpoint(xTemp, fxTemp);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,13 @@ public:
|
|||||||
private:
|
private:
|
||||||
dim1Map Map;
|
dim1Map Map;
|
||||||
void readFromCSV(std::string loadFilePath);
|
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 */
|
#endif /* function_container_hpp */
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ Parameter::Parameter() {
|
|||||||
// Simulation Specs
|
// Simulation Specs
|
||||||
|
|
||||||
seed = (int)getValue("seed");
|
seed = (int)getValue("seed");
|
||||||
numTotalElectrons = (long int)getValue("numTotalElectrons");
|
numberTotalDecays = (int)getValue("numberTotalDecays");
|
||||||
dt_s = getValue("dt_s");
|
dt_s = getValue("dt_s");
|
||||||
injectionMethod = (int)getValue("injectionMethod");
|
injectionMethod = (int)getValue("injectionMethod");
|
||||||
deltaKinEnergy_eV = getValue("deltaKinEnergy_eV");
|
deltaKinEnergy_eV = getValue("deltaKinEnergy_eV");
|
||||||
@@ -37,6 +37,7 @@ Parameter::Parameter() {
|
|||||||
cutoffMode = (int)getValue("cutoffMode");
|
cutoffMode = (int)getValue("cutoffMode");
|
||||||
cutoffEnergySet_eV = getValue("cutoffEnergySet_eV");
|
cutoffEnergySet_eV = getValue("cutoffEnergySet_eV");
|
||||||
cutoffFactor = getValue("cutoffFactor");
|
cutoffFactor = getValue("cutoffFactor");
|
||||||
|
maxNumberInteractionsPerElectron = getValue("maxNumberInteractionsPerElectron");
|
||||||
|
|
||||||
// Katrin Specs
|
// Katrin Specs
|
||||||
wgtsMagField_T = getValue("wgtsMagField_T");
|
wgtsMagField_T = getValue("wgtsMagField_T");
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
//Simulation Specs
|
//Simulation Specs
|
||||||
int seed ;
|
int seed ;
|
||||||
long int numTotalElectrons;
|
long int numberTotalDecays;
|
||||||
double dt_s;
|
double dt_s;
|
||||||
int injectionMethod; // 0 = Beta Decay, 1 = Delta, 2 = Maxwell Boltzmann
|
int injectionMethod; // 0 = Beta Decay, 1 = Delta, 2 = Maxwell Boltzmann
|
||||||
double deltaKinEnergy_eV;
|
double deltaKinEnergy_eV;
|
||||||
@@ -31,6 +31,7 @@ protected:
|
|||||||
int cutoffMode; // 0 = Energy from Parameter, 1 = WGTSTemperature*cutoffFactor
|
int cutoffMode; // 0 = Energy from Parameter, 1 = WGTSTemperature*cutoffFactor
|
||||||
double cutoffEnergySet_eV;
|
double cutoffEnergySet_eV;
|
||||||
double cutoffFactor;
|
double cutoffFactor;
|
||||||
|
int maxNumberInteractionsPerElectron;
|
||||||
|
|
||||||
//KATRIN Specs
|
//KATRIN Specs
|
||||||
double wgtsMagField_T;
|
double wgtsMagField_T;
|
||||||
|
|||||||
@@ -17,42 +17,55 @@ using namespace std;
|
|||||||
|
|
||||||
|
|
||||||
Simulation::Simulation() {
|
Simulation::Simulation() {
|
||||||
numberElectrons = 0;
|
numberTotalElectrons = 0;
|
||||||
|
numberDecays = 0;
|
||||||
rngUni.seed(seed);
|
rngUni.seed(seed);
|
||||||
updater_fraction = numTotalElectrons/100;
|
updater_fraction = numberTotalDecays/100;
|
||||||
updater_numberOfPrevious = 0;
|
updater_numberOfPrevious = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Simulation::doit() {
|
void Simulation::doit() {
|
||||||
vec3 oldLoc_m;
|
int numberInteractionsThisElectron = 0;
|
||||||
while ( (numberElectrons < numTotalElectrons) || (electronQue.size() > 0) ) {
|
while ( (numberDecays < numberTotalDecays) || (electronQue.size() > 0) ) {
|
||||||
if (electronQue.empty()) {
|
if (electronQue.empty()) {
|
||||||
electronQue.push_back(Kat.injectElectron(numberElectrons++, &rngUni, &rngNormal));
|
electronQue.push_back(Kat.injectElectron(numberTotalElectrons++, &rngUni, &rngNormal));
|
||||||
|
numberDecays++;
|
||||||
}
|
}
|
||||||
|
actionElectronPtr = &electronQue.front();
|
||||||
status_updater();
|
do_statusUpdate();
|
||||||
move_electron(&electronQue.front(), &Log);
|
move_electron(actionElectronPtr, &Log);
|
||||||
if (!Kat.check_Termination (electronQue.front()) ) {
|
if (!Kat.check_Termination (*actionElectronPtr) ) {
|
||||||
do_interaction(&electronQue.front());
|
do_interaction(actionElectronPtr);
|
||||||
}
|
}
|
||||||
if (Kat.check_Termination (electronQue.front())) {
|
if (Kat.check_Termination (*actionElectronPtr) || check_NumberInteractions(numberInteractionsThisElectron)) {
|
||||||
electronQue.pop_front();
|
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() {
|
void Simulation::doTC6() {
|
||||||
cout<<endl<<"Simulation::doTC6: Doing Testcase 6."<<endl<<endl;
|
cout<<endl<<"Simulation::doTC6: Doing Testcase 6."<<endl<<endl;
|
||||||
parameterCheck_TC6();
|
parameterCheck_TC6();
|
||||||
|
|
||||||
while ( (numberElectrons < numTotalElectrons) || (electronQue.size() > 0) ) {
|
while ( (numberTotalElectrons < numberTotalDecays) || (electronQue.size() > 0) ) {
|
||||||
if (!electronQue.empty()) {
|
if (!electronQue.empty()) {
|
||||||
throw MyException("Simulation::doTC6: electronQue should be 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
|
do_interaction(&electronQue.front()); //parameter should only allow for ionizations
|
||||||
electronQue.pop_front(); // delete initial electron
|
electronQue.pop_front(); // delete initial electron
|
||||||
Log.log_Electron(&electronQue.front(), vec3(0,0,0)); //should be daugther 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() {
|
void Simulation::do_statusUpdate() {
|
||||||
if (numberElectrons%updater_fraction == 0){
|
if (numberDecays%updater_fraction == 0){
|
||||||
if (updater_numberOfPrevious!=numberElectrons) {
|
if (updater_numberOfPrevious!=numberDecays) {
|
||||||
cout<<numberElectrons<<"/"<<numTotalElectrons<<endl;
|
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);
|
interactElectron->do_elaScattering(Kat.getTotSpeedT2_ms(newLoc_m, &rngUni, &rngNormal) , &rngUni);
|
||||||
break;
|
break;
|
||||||
case 2: // Ionization
|
case 2: // Ionization
|
||||||
electronQue.push_back( interactElectron->do_Ionization(Kat.getTotSpeedT2_ms(newLoc_m, &rngUni, &rngNormal), numberElectrons, &rngUni) );
|
electronQue.push_back( interactElectron->do_Ionization(Kat.getTotSpeedT2_ms(newLoc_m, &rngUni, &rngNormal), numberTotalElectrons, &rngUni) );
|
||||||
numberElectrons++;
|
numberTotalElectrons++;
|
||||||
// Update Ions...
|
// Update Ions...
|
||||||
break;
|
break;
|
||||||
case 3: // Recombination
|
case 3: // Recombination
|
||||||
|
|||||||
@@ -22,22 +22,23 @@
|
|||||||
class Simulation: private Parameter, private Constants {
|
class Simulation: private Parameter, private Constants {
|
||||||
public:
|
public:
|
||||||
Simulation();
|
Simulation();
|
||||||
void doit();
|
|
||||||
|
|
||||||
|
|
||||||
|
void doit();
|
||||||
private:
|
private:
|
||||||
void status_updater();
|
void do_statusUpdate();
|
||||||
void move_electron(Electron *moveElectron, Logger *Log);
|
void move_electron(Electron *moveElectron, Logger *Log);
|
||||||
void do_interaction(Electron *interactElectron);
|
void do_interaction(Electron *interactElectron);
|
||||||
|
bool check_NumberInteractions(int &numberInteractionsThisElectron);
|
||||||
|
|
||||||
// Simulation
|
|
||||||
Katrin Kat;
|
Katrin Kat;
|
||||||
Logger Log;
|
Logger Log;
|
||||||
ranlib::Uniform<double> rngUni;
|
ranlib::Uniform<double> rngUni;
|
||||||
ranlib::NormalUnit<double> rngNormal;
|
ranlib::NormalUnit<double> rngNormal;
|
||||||
int numberElectrons;
|
int numberTotalElectrons;
|
||||||
|
int numberDecays;
|
||||||
std::deque<Electron> electronQue;
|
std::deque<Electron> electronQue;
|
||||||
|
Electron *actionElectronPtr;
|
||||||
|
|
||||||
|
//Updater
|
||||||
int updater_numberOfPrevious;
|
int updater_numberOfPrevious;
|
||||||
int updater_fraction;
|
int updater_fraction;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -15,5 +19,8 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main(int argc, const char * argv[]) {
|
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