Skip to content

Commit 7edf610

Browse files
author
mgotz
committed
initial copy from offline repository
1 parent 41bbafc commit 7edf610

22 files changed

+1935
-1
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.0.2)
2+
3+
project(IK_Simulation)
4+
5+
set(Boost_USE_STATIC_LIBS ON)
6+
find_package(Boost 1.55.0 REQUIRED program_options)
7+
8+
include_directories(include ${Boost_INCLUDE_DIRS})
9+
10+
file(GLOB HEADERS "include/*.hpp")
11+
file(GLOB SOURCES "src/*.cpp")
12+
13+
add_executable(IK_Simulation ${SOURCES} ${HEADERS})
14+
target_link_libraries(IK_Simulation ${Boost_LIBRARIES})

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
1-
# numerical-ks-calculator
1+
# IC_Simulation
22
numerical solution of charge transport, creatiion and recombination inside a 1D ionization chamber model
3+
4+
Building:
5+
run cmake from a directory you want to build in and give a path to this directory as argument
6+
cmake will create a makefile, which can be used to build by simply runn make
7+
8+
Requirements: standard library and program_options from the boost library
9+
Tested on gcc 4.9.2
10+
11+
12+
Alternatively compile manually. Source files are in src, headers are in include directories.
13+
Link all files and don't forget -lboost_program_options
14+
15+
Usage:
16+
The program's parameters can be given either on the command line or in a configuration file (or any combination of the two)
17+
Run IK_Simluation -h to see a list of the parameters.
18+
19+
Beyond the straightfoward settings, the program needs a chamber file and an active medium file.
20+
The chamber file gives the dimensions and properties (mainly calibration factor to calculate liberated charge from a given dose)
21+
of the chamber.
22+
See AdvMarkus_kammer.txt for an example.
23+
24+
The active_medium file specifies the properties of the filling gas.
25+
Those can be simple constants, function definitions or point to additional files, if they are given in a spline format
26+
See active_medium_air_with_direct.txt for an example.

include/active_medium.hpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef ACTIVE_MEDIUM
2+
#define ACTIVE_MEDIUM
3+
/*
4+
this class defines an active medium, with several methods to return its properties, such as ion mobility or electron attachment depending on the electri field strength
5+
it is constructed by reading an ini-style file with boost::property_tree
6+
*/
7+
8+
9+
#include "active_medium_functiods.hpp"
10+
11+
#include <fstream>
12+
#include <limits>
13+
#include <vector>
14+
#include <string>
15+
#include <stdexcept>
16+
17+
18+
using namespace std;
19+
20+
21+
class active_medium
22+
{
23+
public:
24+
active_medium(std::string); //constructor takes file path to the active medium ini file
25+
26+
//methods to get the different properties:
27+
double mobility_e (double);
28+
double mobility_pos (double);
29+
double mobility_neg (double);
30+
double attachment (double);
31+
double volume_recombination (double);
32+
double direct_recombination (double);
33+
34+
double relative_permittivity(double);
35+
36+
void write_log(ofstream&); //write table of function values in stream
37+
38+
double mMaxE;
39+
private:
40+
//functiods for the different properties
41+
vector<evaluation_functiod*> mFunctiods;
42+
};
43+
44+
class unknown_arg_error : public runtime_error
45+
{
46+
public:
47+
unknown_arg_error(const string &message) : runtime_error(message) {}
48+
};
49+
class file_open_error : public runtime_error
50+
{
51+
public:
52+
file_open_error(const string &message) : runtime_error(message) {}
53+
};
54+
55+
56+
57+
58+
#endif
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#ifndef ACTIVE_MEDIUM_FUNCTIODS
2+
#define ACTIVE_MEDIUM_FUNCTIODS
3+
/*
4+
There is one abstract base class the evaluation_functiod and several implementation
5+
Each instance of an implementation is a function with some parameters that are defined at construction, such that the function can then be evaluated
6+
at different value with the same parameters
7+
*/
8+
9+
10+
#include <fstream>
11+
#include <cmath>
12+
#include <limits>
13+
14+
class evaluation_functiod{
15+
public:
16+
virtual double evaluate(double) = 0; //=0 makes this an abstract class, i.e. method is not defined and needs to be defined in the children
17+
virtual ~evaluation_functiod() = 0;
18+
double mMaxE;
19+
};
20+
21+
inline evaluation_functiod::~evaluation_functiod() {}
22+
23+
24+
25+
class constant : public evaluation_functiod{
26+
public:
27+
virtual double evaluate(double ){ return(mIntercept);}
28+
constant(double pIntercept)
29+
{
30+
mIntercept=pIntercept;
31+
mMaxE = std::numeric_limits<double>::max();
32+
}
33+
private:
34+
double mIntercept;
35+
36+
};
37+
38+
class linear : public evaluation_functiod{
39+
public:
40+
virtual double evaluate(double pEField){ return(mIntercept+mSlope*pEField);}
41+
linear(double pIntercept, double pSlope)
42+
{
43+
mIntercept=pIntercept;
44+
mSlope = pSlope;
45+
mMaxE = std::numeric_limits<double>::max();
46+
}
47+
private:
48+
double mIntercept;
49+
double mSlope;
50+
51+
};
52+
53+
class exponential : public evaluation_functiod{
54+
public:
55+
virtual double evaluate(double pEField){ return(m0+m1*exp(m2*pEField));}
56+
exponential (double p0, double p1, double p2)
57+
{
58+
m0 = p0;
59+
m1 = p1;
60+
m2 = p2;
61+
mMaxE = std::numeric_limits<double>::max();
62+
}
63+
private:
64+
double m0;
65+
double m1;
66+
double m2;
67+
68+
};
69+
70+
class pol4 : public evaluation_functiod{
71+
public:
72+
virtual double evaluate(double pEField){
73+
return(m0+m1*pEField+m2*pEField*pEField+m3*pEField*pEField*pEField+m4*pEField*pEField*pEField*pEField);
74+
}
75+
pol4 (double p0, double p1, double p2, double p3, double p4)
76+
{
77+
m0 = p0;
78+
m1 = p1;
79+
m2 = p2;
80+
m3 = p3;
81+
m4 = p4;
82+
mMaxE = std::numeric_limits<double>::max();
83+
}
84+
private:
85+
double m0;
86+
double m1;
87+
double m2;
88+
double m3;
89+
double m4;
90+
};
91+
92+
class pol5 : public evaluation_functiod{
93+
public:
94+
virtual double evaluate(double pEField){
95+
return(m0+m1*pEField+m2*pEField*pEField+m3*pEField*pEField*pEField+m4*pEField*pEField*pEField*pEField+m5*pEField*pEField*pEField*pEField*pEField);
96+
}
97+
pol5 (double p0, double p1, double p2, double p3, double p4, double p5)
98+
{
99+
m0 = p0;
100+
m1 = p1;
101+
m2 = p2;
102+
m3 = p3;
103+
m4 = p4;
104+
m5 = p5;
105+
mMaxE = std::numeric_limits<double>::max();
106+
}
107+
private:
108+
double m0;
109+
double m1;
110+
double m2;
111+
double m3;
112+
double m4;
113+
double m5;
114+
115+
};
116+
117+
class spline_eval_only : public evaluation_functiod{
118+
public:
119+
virtual double evaluate(double pEField){
120+
i = (size_t)((pEField-mX0)/mGridspacing);
121+
return (mA[i]*pEField*pEField*pEField+mB[i]*pEField*pEField+mC[i]*pEField+mD[i]);
122+
}
123+
spline_eval_only(std::ifstream&);
124+
~spline_eval_only();
125+
126+
private:
127+
double* mA;
128+
double* mB;
129+
double* mC;
130+
double* mD;
131+
double mGridspacing;
132+
double mX0;
133+
size_t i;
134+
};
135+
136+
137+
#endif

include/beam_model.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef BEAM_MODEL
2+
#define BEAM_MODEL
3+
/*
4+
describe the beam, for now either a conitnuous rate over the entire pulse duration or a micropulse structure like at ELBE
5+
*/
6+
#include "settings.hpp"
7+
8+
#include <string>
9+
10+
class beam_model{
11+
public:
12+
virtual double ionization(double, double) = 0; //=0 makes this an abstract class, i.e. method is not defined and needs to be defined in the children
13+
virtual void print_characeristics() = 0;
14+
virtual ~beam_model() = 0;
15+
protected:
16+
double mPulseDuration;
17+
};
18+
19+
inline beam_model::~beam_model() {}
20+
21+
class continuous_pulse : public beam_model{
22+
public:
23+
virtual double ionization(double, double);
24+
virtual void print_characeristics();
25+
continuous_pulse (double, double); //give the charge created per ns and bin and the pulse duration
26+
private:
27+
double mIonizationRate;
28+
};
29+
30+
31+
class elbe_micropulses : public beam_model{
32+
public:
33+
virtual double ionization(double , double );
34+
virtual void print_characeristics();
35+
elbe_micropulses (double, double); //give the charge created per micro pulse and bin and the pulse duration
36+
private:
37+
double mChargePerPulse;
38+
39+
40+
};
41+
42+
#endif // BEAM_MODEL

include/chamber.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef CHAMBER
2+
#define CHAMBER
3+
/*
4+
Takes care of loading the chamber file and returning the chamber parameters pertinent to the calculation
5+
*/
6+
7+
8+
#include <fstream>
9+
10+
const static double pi = 3.14159265358979323846;
11+
12+
class chamber
13+
{
14+
private:
15+
double plateDistance;
16+
double diameter;
17+
double kQ;
18+
double Nw;
19+
public:
20+
chamber(std::ifstream& );
21+
double calc_bin_size(int numberOfBins) {return (plateDistance*1.0e6/numberOfBins);} //in nm
22+
double calc_E0(double voltage) { return (voltage*10./plateDistance);} //in [Voltage]/cm
23+
double calc_charge_liberated(double dose) {return (1.0e9*dose/(Nw*kQ));} // in pC for a dose given in mGy
24+
double get_area() { return (pi/4.*diameter*diameter);} //in mm^2
25+
26+
};
27+
28+
#endif

include/functions.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef FUNCTIONS_H
2+
#define FUNCTIONS_H
3+
/*
4+
assorted helper functions, so far only the reading of the input paramters is here
5+
*/
6+
7+
8+
#include "active_medium.hpp"
9+
#include "beam_model.hpp"
10+
#include <stdexcept>
11+
12+
//struct to return all the user input variables from parse_cmd_parameters to main
13+
struct variable_package{
14+
double dose;
15+
double voltage;
16+
double pulseduration;
17+
int numberOfBins;
18+
double binSize;
19+
double rateLimit;
20+
double speedLimit;
21+
double electrodeArea;
22+
double Q;
23+
double E0;
24+
streambuf* logBuffer;
25+
string summaryFileName;
26+
int summaryIndepVar;
27+
string mediumName;
28+
active_medium* fillgas;
29+
beam_model* this_beam;
30+
string settingsLogFileName;
31+
};
32+
33+
//exceptions calls to signal an abort
34+
class aborted: public std::exception
35+
{};
36+
37+
//return the parsed command line arguments as a struct of the variable_package form
38+
variable_package parse_cmd_parameters(int, char**, ofstream &pLogStream, string);
39+
40+
#endif // FUNCTIONS_H

include/msvc_preheader.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#pragma execution_character_set("UTF-8")

include/settings.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef SETTINGS
2+
#define SETTINGS
3+
4+
//use to define some global preprocessor switches
5+
6+
//turn off the recalculation of the electric field, i.e. deactivate shield by charges
7+
//#define CONSTFIELD
8+
9+
// logging levels are 0, 1 and 2
10+
// at 0 only the inital settings and the results are outputted
11+
// at 1 a status every 1000 steps is added
12+
// at 2 the calculation of the stepsize is logged at every iteration
13+
// in order to allow a definition of DEBUGLEVEL at the compilation command line this is only defined if it has not happened already
14+
#ifndef DEBUGLEVEL
15+
#define DEBUGLEVEL 2
16+
#endif
17+
18+
//output files containing E-Field, electron and ion distributions, every 1000 steps
19+
//#define CHARGETIMELINE
20+
21+
//undefine saves computations compared to just setting electron recombination coefficient=0
22+
//#define ELECTRONCOMBO
23+
24+
25+
// define if using constant ion mobilities, constant ion recombination rate or constant electron recombination rate (no E-field dependence)
26+
// significantly speeds up the calculation
27+
#define CONSTIONMOB
28+
#define CONSTRECOMB
29+
#define CONSTELECTRONCOMBO
30+
31+
32+
33+
#endif // SETTINGS

input/AdvMarkus_kammer.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Dicke: 1.00 mm
2+
Durchmesser: 5.0 mm
3+
Nw: 1.385e+09 Gy/C
4+
kQ: 1.0 Strahlqualität*Tiefenkorrektur
5+

0 commit comments

Comments
 (0)