Add the updateAll function add the Barnes-Hut threshold parameter
This commit is contained in:
parent
4354d167ed
commit
ed6a0c5bc1
2 changed files with 18 additions and 3 deletions
|
@ -64,22 +64,24 @@ csvFromBodies dt bs = concat $ map (csvFromBody dt) bs
|
||||||
|
|
||||||
-- | Compute all the steps of the simulation
|
-- | Compute all the steps of the simulation
|
||||||
steps :: Double -- ^ The time step
|
steps :: Double -- ^ The time step
|
||||||
|
-> Double -- ^ The Barnes-Hut threshold theta
|
||||||
-> [Body] -- ^ The initial state (list of bodies)
|
-> [Body] -- ^ The initial state (list of bodies)
|
||||||
-> [(Double, [Body])] -- ^ List of successive states with the
|
-> [(Double, [Body])] -- ^ List of successive states with the
|
||||||
-- corresponding time
|
-- corresponding time
|
||||||
steps dt b = zip (iterate (dt +) 0) (iterate (updateAll dt) b)
|
steps dt theta b = zip (iterate (dt +) 0) (iterate (updateAll dt theta) b)
|
||||||
|
|
||||||
-- | Show all the steps as CSV
|
-- | Show all the steps as CSV
|
||||||
csvFromInit :: Int -- ^ The number of time steps to keep
|
csvFromInit :: Int -- ^ The number of time steps to keep
|
||||||
-> Double -- ^ The time step
|
-> Double -- ^ The time step
|
||||||
|
-> Double -- ^ The Barnes-Hut threshold theta
|
||||||
-> [Body] -- ^ The initial state (list of bodies)
|
-> [Body] -- ^ The initial state (list of bodies)
|
||||||
-> String -- ^ CSV data
|
-> String -- ^ CSV data
|
||||||
csvFromInit n dt b = concat . take n $ map (uncurry csvFromBodies) (steps dt b)
|
csvFromInit n dt theta b = concat . take n $ map (uncurry csvFromBodies) (steps dt theta b)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
bodies <- replicateM 100 randomBody
|
bodies <- replicateM 100 randomBody
|
||||||
putStrLn $ csvFromInit 100000 60 bodies
|
putStrLn $ csvFromInit 100000 60 0.5 bodies
|
||||||
|
|
||||||
{-
|
{-
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
13
src/Lib.hs
13
src/Lib.hs
|
@ -28,6 +28,7 @@ module Lib (
|
||||||
acceleration,
|
acceleration,
|
||||||
-- * Simulation
|
-- * Simulation
|
||||||
update,
|
update,
|
||||||
|
updateAll,
|
||||||
-- * Examples
|
-- * Examples
|
||||||
au, sun, earth, moon, mercury, venus, mars
|
au, sun, earth, moon, mercury, venus, mars
|
||||||
) where
|
) where
|
||||||
|
@ -246,6 +247,18 @@ update dt theta tree (Body name r m pos speed) =
|
||||||
newpos = pos + dt *^ P newspeed
|
newpos = pos + dt *^ P newspeed
|
||||||
|
|
||||||
|
|
||||||
|
-- | Update all Bodies with a time step dt and a Barnes-Hut threshold
|
||||||
|
-- theta
|
||||||
|
updateAll :: Double -- ^ The time step
|
||||||
|
-> Double -- ^ The Barnes-Hut threshold theta
|
||||||
|
-> [Body] -- ^ A list of Bodies
|
||||||
|
-> [Body] -- ^ The updated list of Bodies
|
||||||
|
updateAll dt theta bs =
|
||||||
|
map (update dt theta tree) bs
|
||||||
|
where tree = buildTree bs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- EXAMPLES
|
-- EXAMPLES
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue