-
79.63%
Rate
-
43
Hits
-
11
Missed
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
-
-
-
-
-
- 1x
- 1x
- 1x
- 1x
- 1x
- 1x
- 1x
-
- 1x
-
-
-
-
-
- 1x
- 1x
-
-
- 1x
- 17x
- 3x
- 14x
- 12x
-
- 2x
-
-
-
-
- 1x
- 3x
- 2x
- 1x
-
- 1x
-
-
-
- 2x
- 4x
- 2x
- 2x
-
-
-
-
-
-
-
-
-
-
-
-
- 1x
- 1x
-
-
- 1x
-
-
- 7x
-
-
-
-
- 7x
-
- 7x
- 1x
-
-
-
-
- 6x
- 6x
- 6x
-
-
-
-
-
- 7x
- 1x
- 1x
- 1x
-
-
-
-
-
- 7x
-
- 7x
-
-
- 1x
-
-
-
-
-
-
- 1x
- -------------------------------------------------------------------------------
- -- Uniform medium for PUMAS
- -- Author: Valentin Niess
- -- License: GNU LGPL-3.0
- -------------------------------------------------------------------------------
- local ffi = require('ffi')
- local clib = require('pumas.clib')
- local coordinates = require('pumas.coordinates')
- local error = require('pumas.error')
- local material_ = require('pumas.material')
- local base = require('pumas.medium.base')
- local metatype = require('pumas.metatype')
-
- local uniform = {}
-
-
- -------------------------------------------------------------------------------
- -- The uniform medium metatype
- -------------------------------------------------------------------------------
- local UniformMedium = {}
- local strtype = 'UniformMedium'
-
-
- function UniformMedium:__index (k)
- if k == 'density' then
- return tonumber(self._c.locals.density)
- elseif k == 'magnet' then
- return self._c.locals.magnet
- else
- return base.BaseMedium.__index(self, k, strtype)
- end
- end
-
-
- function UniformMedium:__newindex (k, v)
- if k == 'density' then
- local ok, description = pcall(function ()
- self._c.locals.density = v
- end)
- if not ok then
- error.raise{fname = 'UniformMedium', argname = 'magnet',
- description = description:match(':%d+:(.+)$')}
- end
- elseif k == 'magnet' then
- local ok, description = coordinates.set_double3(
- self._c.locals, 'magnet', v)
- if not ok then
- error.raise{fname = 'UniformMedium', argname = 'magnet',
- description = description}
- end
- else
- base.BaseMedium.__newindex(self, k, v, strtype)
- end
- end
-
-
- -------------------------------------------------------------------------------
- -- The uniform medium constructor
- -------------------------------------------------------------------------------
- local ctype = ffi.typeof('struct pumas_medium_uniform')
- local ctype_ptr = ffi.typeof('struct pumas_medium_uniform *')
-
- do
- local raise_error = error.ErrorFunction{fname = 'UniformMedium'}
-
- local function new (cls, material, density, magnet)
- if material == nil then
- raise_error{
- argnum = 1, expected = 'a string', got = metatype.a(material)}
- end
-
- local self = base.BaseMedium.new(ctype, ctype_ptr, material)
-
- if density then
- if type(density) ~= 'number' then
- raise_error{argnum = 2, expected = 'a number',
- got = metatype.a(density)}
- end
- else
- local m = material_.materials[material]
- if m then
- density = m.density
- else
- raise_error{argnum = 2, expected = 'a number', got = 'nil'}
- end
- end
-
- if magnet then
- local ok, tmp = coordinates.to_double3(magnet)
- if ok then
- magnet = tmp
- else
- raise_error{argnum = 3, description = tmp}
- end
- end
-
- clib.pumas_medium_uniform_initialise(self._c, -1, density, magnet)
-
- return setmetatable(self, cls)
- end
-
- uniform.UniformMedium = setmetatable(UniformMedium, {__call = new})
- end
-
-
- -------------------------------------------------------------------------------
- -- Return the package
- -------------------------------------------------------------------------------
- return uniform