Added termination of Electrons after 100 Interactions
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");
|
||||||
numberTotalDecays = (long int)getValue("numberTotalDecays");
|
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");
|
||||||
|
|||||||
@@ -22,11 +22,10 @@ Simulation::Simulation() {
|
|||||||
rngUni.seed(seed);
|
rngUni.seed(seed);
|
||||||
updater_fraction = numberTotalDecays/100;
|
updater_fraction = numberTotalDecays/100;
|
||||||
updater_numberOfPrevious = 0;
|
updater_numberOfPrevious = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulation::doit() {
|
void Simulation::doit() {
|
||||||
Electron *actionElectronPtr;
|
int numberInteractionsThisElectron = 0;
|
||||||
while ( (numberDecays < numberTotalDecays) || (electronQue.size() > 0) ) {
|
while ( (numberDecays < numberTotalDecays) || (electronQue.size() > 0) ) {
|
||||||
if (electronQue.empty()) {
|
if (electronQue.empty()) {
|
||||||
electronQue.push_back(Kat.injectElectron(numberTotalElectrons++, &rngUni, &rngNormal));
|
electronQue.push_back(Kat.injectElectron(numberTotalElectrons++, &rngUni, &rngNormal));
|
||||||
@@ -38,12 +37,21 @@ void Simulation::doit() {
|
|||||||
if (!Kat.check_Termination (*actionElectronPtr) ) {
|
if (!Kat.check_Termination (*actionElectronPtr) ) {
|
||||||
do_interaction(actionElectronPtr);
|
do_interaction(actionElectronPtr);
|
||||||
}
|
}
|
||||||
if (Kat.check_Termination (*actionElectronPtr)) {
|
if (Kat.check_Termination (*actionElectronPtr) || check_NumberInteractions(numberInteractionsThisElectron)) {
|
||||||
electronQue.pop_front();
|
electronQue.pop_front();
|
||||||
|
numberInteractionsThisElectron = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool Simulation::check_NumberInteractions(int &numberInteractionsThisElectron) {
|
||||||
|
if (numberInteractionsThisElectron < 100) {
|
||||||
|
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();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ private:
|
|||||||
void do_statusUpdate();
|
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);
|
||||||
Katrin Kat;
|
Katrin Kat;
|
||||||
Logger Log;
|
Logger Log;
|
||||||
ranlib::Uniform<double> rngUni;
|
ranlib::Uniform<double> rngUni;
|
||||||
@@ -36,6 +36,9 @@ private:
|
|||||||
int numberTotalElectrons;
|
int numberTotalElectrons;
|
||||||
int numberDecays;
|
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