EGSnrc C++ class library
Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
|
A base class for input loops. Basic functionality for input loops is provided by this class. Input loops can be used whenever a large number of similar input blocks are needed. More...
Public Member Functions | |
EGS_InputLoopVariable (const string &var) | |
const char * | getVarNameReplacement () const |
const char * | getVarReplacement () const |
virtual void | setVarReplacement (int)=0 |
Static Public Member Functions | |
static EGS_InputLoopVariable * | getInputLoopVariable (const char *input) |
Public Attributes | |
bool | is_list |
True if input loop type is 2, else it is set to false. | |
string | vname |
Loop variable name. | |
string | vr |
Loop variable replacement string. | |
char | buf [128] |
A base class for input loops. Basic functionality for input loops is provided by this class. Input loops can be used whenever a large number of similar input blocks are needed.
Input loops are handy to define several geometries or/and sources in the input files which require only small variations in their definitions. This way cumbersome repetition of identical information is avoided minimizing the length of the input file. Loop variables can be of type 0 (integer) or 1 (real) or 2 (strings) specified by the first number in the loop variable input. Now one can have in the input file the following construct:
:start input loop: loop count = N loop variable = 0 var1 v1min v1delta loop variable = 1 var2 v2min v2delta loop variable = 2 var3 v3_1 v3_2 ... v3_N some other input ... :stop input loop:
Then, everything in the input loop block except for the definition of loop count and loop variable will be repeated N times, replacing all occurrences of $(var1) with v1min+v1delta*i, of $(var2) with v2min+v2delta*i and of $(var3) with v3_1, v3_2 ... v3_N. The index i runs from 0 to N-1.
For real input variable (type 1), one can add a c style printf format string at the end of the loop variable input line to specify the format to use when replacing the variable with its values. By default, the format is "%lg". For example:
:start input loop: loop count = 3 loop variable = 1 var1 0 0.1 %.3f $(var1) :stop input loop:
specifies that when replacing the variable in the instances of the loop, the value of var1 should be printed with a "%.3f" format, so this loop would yield:
0.000 0.100 0.200
For string valued lists, a check is done to make sure that the list size is not smaller than the loop size. In principle, a list loop doesn't need a loop count entry, but if one wants to have non-list variables as well, then the loop count must be there.
Input loops can also be nested. For instance:
:start input loop: loop count = 2 loop variable = 0 var1 10 5 :start input loop: loop count = 5 loop variable = 0 var2 1 1 key = $(var2) $(var1) :stop input loop: :stop input loop:
will produce
key = 1 10 key = 2 10 key = 3 10 key = 4 10 key = 5 10 key = 1 15 key = 2 15 key = 3 15 key = 4 15 key = 5 15
in the input tree after the input loops have been processed. This can be used to do 2D and even 3D array replicas.
Definition at line 668 of file egs_input.cpp.