GEM Geometry File¶
A SIMION geometry file (GEM) defines electrode geometries using constructive solid geometry (CSG) primitives. CSG operations define shapes using unions and intersections of other basic shapes (e.g. a rectangular slab with a cylinder hole cut through it), a bit similar in concept to machining. GEM files are text files and have the file name extension of ”.GEM”. SIMION can convert a GEM file to a PA file.
Macro Support (e.g. variable expansion and preprocessing)¶
As of SIMION 8.0.4, the GEM processor incorporates a preprocessor that allows things like variable expansion and loops (Issue-I296). which allows GEM files to be more maintainable and easily modified. (This new feature is not described in the 8.0.4 manual except in a footnote.)
A new example GEM file (examples\geometry\macro.lua) illustrates the use of this new feature:
; Example SIMION GEM file using preprocessing to expand Lua variables
; and macros.
; Preprocessing is a new feature SIMION 8.0.4.
;
; Lines starting with '#' or text inside $() are interpreted as Lua
; code and evaluated. If $() contains an expression (rather than a
; statement), the result is outputted. All other text is outputted
; verbatim.
; These variables are intended to be adjusted by the user.
; Note: both # and $ syntax are shown for demonstration.
# local ro = 45 -- outer radius, gu
# local ri = 40 -- inner radius, gi
$(local nshells = 4) ; number of shells
; Now do some calculations on those variables. Note: math.ceil(x) is
; the ceiling function: it returns the integer closest to but no
; greater than x.
# local hw = math.ceil(ro * 1.1) -- half width, gu
# local nx = hw * 2 + 1 -- num array points in x
; Define array size.
pa_define($(nx),$(nx),$(nx), planar, non-mirrored)
; Declare a function to be used later.
; This returns the voltage for electrode number n.
$( local function volts(n)
return n^2 * 10 + n + 1
end )
; This locate centers the shells in the array.
locate($(hw),$(hw),$(hw), 1, 0,0,0) {
; Now define a loop that creates each shell.
# for n=1,nshells do
# local rop = ro * n / nshells
# local rip = ri * n / nshells
electrode($(volts(n))) { ; example calling a function
fill {
within{sphere(0,0,0, $(rop))}
notin {sphere(0,0,0, $(rip - 1))}
}
}
# end
}
; Note: the following two lines are equivalent:
fill { within { box3d(0,0,0, $(nx),0,$(nx)) }}
# _put("fill { within { box3d(0,0,0, " .. nx .. ",0," .. nx .. ") }}")
; Print output to the log window. This can be
; useful for debugging.
# print("Hello from GEM file. nx=" .. nx)
When SIMION loads a GEM file containing macros (e.g. macro.gem), it processes those macros, writes the result to temporary file (e.g. macro.processed.gem), and loads that temporary file.
It also possible to do your own GEM file preprocessing outside of SIMION with your own programming tools. This was more popular prior to the introduction of the above feature but can still be useful in some cases.
