module DSMC.Motion
( motion
)
where
import Control.Parallel.Stochastic
import qualified Data.Strict.Maybe as S
import qualified Data.Array.Repa as R
import qualified Data.Vector.Unboxed as VU
import System.Random.MWC
import DSMC.Particles
import DSMC.Surface
import DSMC.Traceables hiding (trace)
import DSMC.Util
import Control.Monad.ST
reflect :: GenST s
-> Body
-> Time
-> Reflector s
-> VU.Vector Particle
-> ST s (VU.Vector Particle)
reflect g body dt reflector ens = do
VU.forM ens $ \pcl -> do
let movedPcl = move dt pcl
case (hitPoint dt body movedPcl) of
S.Just (HitPoint th (S.Just n)) ->
let
(pos', v) = move th pcl
in do
vR <- reflector g n v
return $ move (th) (pos', vR)
_ -> return $ movedPcl
motion :: ParallelSeeds
-> Body
-> Time
-> Surface
-> Ensemble
-> (Ensemble, ParallelSeeds)
motion gs b dt surf ens =
let
reflector = makeReflector surf
!(v', newSeeds) =
splitParMapST (\g e -> reflect g b dt reflector e)
(R.toUnboxed ens) gs
in
(fromUnboxed1 v', newSeeds)