5 type Vector
= (Float, Float, Float)
6 type Fermion
= (Vector
, Vector
, Mass
, Charge
)
8 inBox
:: Fermion
-> Bool
9 inBox
((x
, y
, z
), _
, _
, _
) = x
<= boxSpan
&& x
>= (-boxSpan
) && y
<= boxSpan
&& y
>= (-boxSpan
) && z
<= boxSpan
&& z
>= (-boxSpan
)
14 initialState
:: Float -> [Fermion
]
15 initialState n
= map (\k
-> (((k
* boxSpan
/ (n
+1)) - boxSpan
/2, (sin(pi*k
/n
)) / 6 * boxSpan
, 0), (0, 0, 0), 2, (if (odd (round k
::Integer)) then 1 else -1))) [1..n
]
17 getFermionPos
:: Fermion
-> Vector
18 getFermionPos
(pos
, _
, _
, _
) = pos
20 addVectors
:: Vector
-> Vector
-> Vector
21 addVectors
(x
,y
,z
) (a
,b
,c
) = (x
+a
, y
+b
, z
+c
)
23 mulVector
:: Float -> Vector
-> Vector
24 mulVector n
(x
,y
,z
) = (n
*x
, n
*y
, n
*z
)
26 advanceState
:: [Fermion
] -> [Fermion
]
27 advanceState fermions
= filter inBox
(map update fermions
)
29 update this
@(pos
, v
, mass
, charge
) = (newPos
, newVelocity
, mass
, charge
)
31 newPos
= pos `addVectors` v
32 newVelocity
= updatedVelocity
--`addVectors` (forceFromBlackHole this)
33 updatedVelocity
= (foldl addVectors v
(map (forceBetween this
) fermions
))
35 forceBetween
:: Fermion
-> Fermion
-> Vector
36 forceBetween
(pos1
@(x1
, y1
, z1
), _
, mass1
, charge1
) (pos2
@(x2
, y2
, z2
), _
, mass2
, charge2
)
37 | pos1
== pos2
= (0, 0, 0)
38 |
otherwise = (factor
* x
, factor
* y
, factor
* z
)
40 factor
= (-charge1
) * charge2
/ dist
+ mass1
* mass2
/ dist
41 dist
= x
*x
+ y
*y
+ z
*z
46 --forceFromBlackHole :: Fermion -> Vector
47 --forceFromBlackHole ((x, y, z), _, _, _) = (factor * x, factor * y, factor * z)
49 -- factor = if dist > boxSpan then -0.1 else 0
50 ---- factor = if factor' == 1/0 then 10000 else factor'
51 ---- factor' = (-(exp ((dist - boxSpan)/boxSpan)))
52 -- dist = sqrt(x*x + y*y + z*z)