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) {
|
||||
// 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");
|
||||
numberTotalDecays = (long int)getValue("numberTotalDecays");
|
||||
numberTotalDecays = (int)getValue("numberTotalDecays");
|
||||
dt_s = getValue("dt_s");
|
||||
injectionMethod = (int)getValue("injectionMethod");
|
||||
deltaKinEnergy_eV = getValue("deltaKinEnergy_eV");
|
||||
|
||||
@@ -22,11 +22,10 @@ Simulation::Simulation() {
|
||||
rngUni.seed(seed);
|
||||
updater_fraction = numberTotalDecays/100;
|
||||
updater_numberOfPrevious = 0;
|
||||
|
||||
}
|
||||
|
||||
void Simulation::doit() {
|
||||
Electron *actionElectronPtr;
|
||||
int numberInteractionsThisElectron = 0;
|
||||
while ( (numberDecays < numberTotalDecays) || (electronQue.size() > 0) ) {
|
||||
if (electronQue.empty()) {
|
||||
electronQue.push_back(Kat.injectElectron(numberTotalElectrons++, &rngUni, &rngNormal));
|
||||
@@ -38,12 +37,21 @@ void Simulation::doit() {
|
||||
if (!Kat.check_Termination (*actionElectronPtr) ) {
|
||||
do_interaction(actionElectronPtr);
|
||||
}
|
||||
if (Kat.check_Termination (*actionElectronPtr)) {
|
||||
if (Kat.check_Termination (*actionElectronPtr) || check_NumberInteractions(numberInteractionsThisElectron)) {
|
||||
electronQue.pop_front();
|
||||
numberInteractionsThisElectron = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
bool Simulation::check_NumberInteractions(int &numberInteractionsThisElectron) {
|
||||
if (numberInteractionsThisElectron < 100) {
|
||||
numberInteractionsThisElectron++;
|
||||
return(false);
|
||||
} else {
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
void Simulation::doTC6() {
|
||||
cout<<endl<<"Simulation::doTC6: Doing Testcase 6."<<endl<<endl;
|
||||
parameterCheck_TC6();
|
||||
|
||||
@@ -28,7 +28,7 @@ private:
|
||||
void do_statusUpdate();
|
||||
void move_electron(Electron *moveElectron, Logger *Log);
|
||||
void do_interaction(Electron *interactElectron);
|
||||
|
||||
bool check_NumberInteractions(int &numberInteractionsThisElectron);
|
||||
Katrin Kat;
|
||||
Logger Log;
|
||||
ranlib::Uniform<double> rngUni;
|
||||
@@ -36,6 +36,9 @@ private:
|
||||
int numberTotalElectrons;
|
||||
int numberDecays;
|
||||
std::deque<Electron> electronQue;
|
||||
Electron *actionElectronPtr;
|
||||
|
||||
//Updater
|
||||
int updater_numberOfPrevious;
|
||||
int updater_fraction;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user