forked from lanl/McPhD
/
Main-1000.hs
69 lines (61 loc) · 1.85 KB
/
Main-1000.hs
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
{-# LANGUAGE BangPatterns #-}
-- | Main with 1000 cells
module Main where
import Control.Parallel.Strategies
import Data.List as L
import Data.Vector as V
import System.Environment
import Cell
import Material
import MC
import Mesh
import Physical
import PRNG
import Source
import Sphere1D
import Tally
import TryNSave
import Sigma_HBFC (nuE)
main :: IO ()
main =
do
[n,fname] <- getArgs
writeTally fname (runManyParticles (read n) bigMesh)
-- | Perform the simulation for several (at least one) particles
-- in a given mesh.
runManyParticles :: Mesh m => Int -> m -> Tally
runManyParticles !n msh =
let
particles = genParticles n msh testRNG
tallies = L.map (runParticle nuE msh) particles
chunked = chunk 500 tallies
res = L.map (L.foldl1' merge) chunked
`using` parBuffer 10 rdeepseq
in
L.foldl1' merge res
-- | Splits a lists into chunks of the given size. TODO: Reuse
-- library functions, or move elsewhere.
chunk :: Int -> [a] -> [[a]]
chunk n = L.unfoldr go
where
go xs = case L.splitAt n xs of
([], []) -> Nothing
r -> Just r
bigMesh :: Sphere1D
bigMesh =
Sphere1D $ V.fromList $
[Cell (Position 0) (Position 1) Refl Transp
(Material (Opacity 0.1) (Opacity 2)
(Velocity 0) (Temperature 1)
(Density 1.0) (NDensity 0.5) (NDensity 0))]
L.++
[Cell (Position i) (Position $ i+1.0) Transp Transp
(Material (Opacity 1) (Opacity 0.5)
(Velocity 0) (Temperature 2)
(Density 1.0) (NDensity 0.5) (NDensity 0))
| i <- [1..998]]
L.++
[Cell (Position 999) (Position 1000) Transp Refl
(Material (Opacity 1) (Opacity 0.5)
(Velocity 0) (Temperature 2)
(Density 1.0) (NDensity 0.5) (NDensity 0))]