diff options
author | Herbert Valerio Riedel <hvr@gnu.org> | 2014-01-12 11:40:09 +0100 |
---|---|---|
committer | Herbert Valerio Riedel <hvr@gnu.org> | 2014-01-12 12:47:17 +0100 |
commit | 66693401b98cb5aa912948af7bbd2182474f50c4 (patch) | |
tree | ab176320c561668c9ac13e684c9cc8ae6e4535f6 /testsuite/tests/dph/nbody/Body.hs | |
parent | a924debcbb3dc5c004f988fcc1b480a01ba276dd (diff) | |
parent | ad233cf68ea436c84e931c5bdb9f803308708e09 (diff) | |
download | haskell-66693401b98cb5aa912948af7bbd2182474f50c4.tar.gz |
Fold testsuite.git into ghc.git (re #8545)
This commit performs a subtree merge of testsuite.git into ghc.git;
The next commit will adapt `sync-all` et al. to the new situation.
At the time of merge, testsuite.git was at commit
[998a816ae89c4fd573f4abd7c6abb346cf7ee9af/testsuite]
The following steps have been used to accomplish this merge:
1. Clone a fresh testsuite.git copy (& cd into)
2. Remove accidentally committed binary files from history
git filter-branch \
--index-filter "git rm -r --cached --ignore-unmatch \
tests/haddock/should_compile_flag_nohaddock/a.out \
tests/haddock/should_compile_noflag_nohaddock/a.out \
tests/ghc-regress/haddock/should_compile_flag_nohaddock/a.out \
tests/ghc-regress/haddock/should_compile_noflag_nohaddock/a.out \
tests/ghc-regress/dph/diophantine/dph-diophantine-fast \
tests/ghc-regress/dph/diophantine/dph-diophantine-opt \
tests/ghc-regress/dph/primespj/dph-primespj-fast \
tests/ghc-regress/dph/quickhull/dph-quickhull-fast \
tests/ghc-regress/dph/smvm/dph-smvm \
tests/ghc-regress/dph/sumnats/dph-sumnats \
tests/ghc-regress/dph/words/dph-words-fast \
tests/ghc-regress/plugins/plugins01" \
HEAD
3. Rename all paths in testsuite.git to be prefixed with `testsuite/`
git filter-branch -f --prune-empty --tree-filter \
"mkdir -p testsuite; \
git ls-tree --name-only \$GIT_COMMIT | xargs -I files mv files testsuite/"
4. cd into ghc/ checkout, and perform subtree merge of testsuite into ghc
(see also http://nuclearsquid.com/writings/subtree-merging-and-you/)
cd ../ghc/
git remote add -f testsuite ../testsuite/.git
git merge -s ours --no-commit testsuite/master
git read-tree --prefix=/ -u testsuite/master
git commit
Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
Diffstat (limited to 'testsuite/tests/dph/nbody/Body.hs')
-rw-r--r-- | testsuite/tests/dph/nbody/Body.hs | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/testsuite/tests/dph/nbody/Body.hs b/testsuite/tests/dph/nbody/Body.hs new file mode 100644 index 0000000000..3ba2149533 --- /dev/null +++ b/testsuite/tests/dph/nbody/Body.hs @@ -0,0 +1,85 @@ +{-# LANGUAGE BangPatterns #-} + +-- | Massful bodies in the simulation. +module Body + ( Velocity + , Accel + , MassPoint + , Body + + , unitBody + , massPointOfBody + , setMassOfBody + , setAccelOfBody + , setStartVelOfBody + , advanceBody) +where +import Util + + +-- Types ---------------------------------------------------------------------- +-- We're using tuples instead of ADTs so we can put them in unboxed vectors. + +-- | The velocity of a point. +type Velocity = (Double, Double) + +-- | The acceleration of a point. +type Accel = (Double, Double) + +-- | A point in 2D space with its mass. +type MassPoint = (Double, Double, Double) + +-- | Bodies consist of a MassPoint, but also carry their velocity +-- and acceleration between steps of the simulation. +type Body = (MassPoint, Velocity, Accel) + + +-- Body ----------------------------------------------------------------------- +-- | Make a body with unit mass and zero vel and acc. +unitBody :: Double -> Double -> Body +unitBody x y + = ((x, y, 1), (0, 0), (0, 0)) + + +-- | Take the MassPoint of a body. +massPointOfBody :: Body -> MassPoint +massPointOfBody (mp, vel, acc) + = mp + + +-- | Set the mass of a body. +setMassOfBody :: Double -> Body -> Body +setMassOfBody mass ((x, y, _), vel, acc) + = ((x, y, mass), vel, acc) + + +-- | Set the acceleration of a body. +setAccelOfBody :: Accel -> Body -> Body +setAccelOfBody acc' (mp, vel, _) + = (mp, vel, acc') + + +-- | Set the starting velocity of a body. +-- It is set to rotate around the origin, with the speed proportional +-- to the sqrt of the distance from it. This seems to make nice simulations. +setStartVelOfBody :: Double -> Body -> Body +setStartVelOfBody startVel (mp@(x, y, mass), vel, acc) + = let pos = (x, y) + (x', y') = normaliseV (x, y) + vel' = (y', -x') + vel'' = mulSV (sqrt (magV pos) * startVel) vel' + + in (mp, vel'', acc) + + +-- | Advance a body forwards in time. +advanceBody :: Double -> Body -> Body +advanceBody time + ( (px, py, mass) + , (vx, vy) + , acc@(ax, ay)) + + = ( (px + time * vx, py + time * vy, mass) + , (vx + time * ax, vy + time * ay) + , acc) + |