-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSymplecticMain.hs
80 lines (61 loc) · 2.42 KB
/
SymplecticMain.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
70
71
72
73
74
75
76
77
78
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
import Graphics.Rendering.Chart
import Graphics.Rendering.Chart.Backend.Diagrams
import Diagrams.Backend.Cairo.CmdLine
import Diagrams.Prelude hiding ( render, Renderable, (*~), Time )
import Diagrams.Backend.CmdLine
import System.IO.Unsafe
import Symplectic
import qualified Data.Array.Accelerate as A hiding ((^))
import qualified Linear as L
import Text.Printf
denv :: DEnv Double
denv = unsafePerformIO $ defaultEnv vectorAlignmentFns 600 500
displayHeader :: FilePath -> Diagram B -> IO ()
displayHeader fn =
mainRender ( DiagramOpts (Just 900) (Just 700) fn
, DiagramLoopOpts False Nothing 0
)
chart :: String ->
String ->
[[(Double, Double)]] ->
Renderable ()
chart t l obss = toRenderable layout
where
actual x l c = plot_lines_values .~ [x]
$ plot_lines_style . line_color .~ opaque c
-- $ plot_lines_title .~ l
$ plot_lines_style . line_width .~ 1.0
$ def
ls = map (\n -> "Path " ++ show n) [1..]
cs = cycle [blue, green, red, brown, crimson]
actuals' :: [PlotLines Double Double]
actuals' = zipWith3 actual obss ls cs
layout = layout_title .~ t
$ layout_plots .~ (map toPlot actuals')
$ layout_y_axis . laxis_title .~ l
$ layout_y_axis . laxis_override .~ axisGridHide
$ layout_x_axis . laxis_title .~ "Positions"
$ layout_x_axis . laxis_override .~ axisGridHide
$ def
diagrm :: String -> String -> [[(Double, Double)]] -> Diagram Cairo
diagrm t l xss = fst $ runBackendR denv (chart t l xss)
diagrmM :: String -> String -> [[(Double, Double)]] -> IO (Diagram Cairo)
diagrmM t l xss = do
denv <- defaultEnv vectorAlignmentFns 600 500
return $ fst $ runBackendR denv (chart t l xss)
main = do
let pqs = A.toList runSteps
pq1s = map (^. L._x) pqs
pq2s = map (^. L._y) pqs
p1s = map (^. L._x) pq1s
q1s = map (^. L._y) pq1s
p2s = map (^. L._x) pq2s
q2s = map (^. L._y) pq2s
d <- diagrmM "Orbits" "Momenta" [zip q1s p1s, zip q2s p2s]
displayHeader "diagrams/symplectic.png" d