Conceptional Change, where terminated Particles were set to Energy = 0. Now Particles are just moved within mover and termination detects, position and starts Interaction only if particle remains in tank. Added function_container: Filled with anker points and get values corresponding to input by interpolation. 2D Interpolation needs improvement. CSV-Read in function needs error checks of input file. Changes in katrin class: Boris Push and Drift Approximation improved. Minor Renamings.
72 lines
1.7 KiB
C++
72 lines
1.7 KiB
C++
//
|
|
// function_container.cpp
|
|
// mc_electron
|
|
//
|
|
// Created by Christian Reiling on 15.03.19.
|
|
// Copyright © 2019 Christian Reiling. All rights reserved.
|
|
//
|
|
|
|
#include "function_container.hpp"
|
|
|
|
#include "myexeption.h"
|
|
|
|
#include <fstream>
|
|
#include <sstream>
|
|
|
|
using namespace std;
|
|
|
|
Func_Container::Func_Container() {
|
|
|
|
}
|
|
|
|
Func_Container::Func_Container(std::string loadFilePath) {
|
|
readFromCSV(loadFilePath);
|
|
}
|
|
|
|
double Func_Container::interpolate(double x) {
|
|
if (Map.empty()) {
|
|
throw MyException("Func_Container: Container is empty.");
|
|
}
|
|
|
|
if (Map.begin() == Map.lower_bound(x) ) {
|
|
return (Map.begin()->second);
|
|
} else if (Map.end() == Map.lower_bound(x)){
|
|
return ( (--Map.end())->second );
|
|
}
|
|
|
|
dim1Map::iterator lowAnker_Itr = --Map.lower_bound(x);
|
|
dim1Map::iterator upAnker_Itr = Map.lower_bound(x);
|
|
double lowAnker_x = lowAnker_Itr->first;
|
|
double lowAnker_fx = lowAnker_Itr->second;
|
|
double upAnker_x = upAnker_Itr->first;
|
|
double upAnker_fx = upAnker_Itr->second;
|
|
|
|
double res = lowAnker_fx + (x-lowAnker_x)/(upAnker_x-lowAnker_x) * (upAnker_fx-lowAnker_fx);
|
|
return (res);
|
|
}
|
|
|
|
|
|
void Func_Container::add_ankerpoint(double x, double fx) {
|
|
if ( Map.find(x)!=Map.end() ) {
|
|
stringstream ss;
|
|
ss<<"Func_Container::add_ankerpoint: Key x="<<x<<" already exists.";
|
|
throw MyException(ss.str());
|
|
}
|
|
Map.insert(dim1Pair(x, fx));
|
|
return;
|
|
}
|
|
|
|
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 file(loadFilePath);
|
|
|
|
while ((file >> xTemp) && (file >> fxTemp)) {
|
|
add_ankerpoint(xTemp, fxTemp);
|
|
}
|
|
file.close();
|
|
return;
|
|
}
|