From: Michael Orlitzky Date: Fri, 2 Sep 2011 15:03:12 +0000 (-0400) Subject: Finish the precomputed_volume optimization. X-Git-Tag: 0.0.1~175 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=b2e1c440b9b1bb99ae564d6600230bbd1f7d204c;p=spline3.git Finish the precomputed_volume optimization. --- diff --git a/src/Cube.hs b/src/Cube.hs index 1e83a3e..ef2d9ce 100644 --- a/src/Cube.hs +++ b/src/Cube.hs @@ -15,7 +15,8 @@ data Cube = Cube { h :: Double, i :: Int, j :: Int, k :: Int, - fv :: FunctionValues } + fv :: FunctionValues, + tetrahedra_volume :: Double } deriving (Eq) @@ -26,7 +27,8 @@ instance Arbitrary Cube where j' <- choose (coordmin, coordmax) k' <- choose (coordmin, coordmax) fv' <- arbitrary :: Gen FunctionValues - return (Cube h' i' j' k' fv') + (Positive tet_vol) <- arbitrary :: Gen (Positive Double) + return (Cube h' i' j' k' fv' tet_vol) where coordmin = -268435456 -- -(2^29 / 2) coordmax = 268435456 -- +(2^29 / 2) @@ -51,7 +53,7 @@ instance Show Cube where -- | Returns an empty 'Cube'. empty_cube :: Cube -empty_cube = Cube 0 0 0 0 empty_values +empty_cube = Cube 0 0 0 0 empty_values 0 -- | The left-side boundary of the cube. See Sorokina and Zeilfelder, @@ -205,7 +207,7 @@ tetrahedron0 c = v1' = center (front_face c) v2' = Face.v0 (front_face c) v3' = Face.v1 (front_face c) - vol = 0 + vol = tetrahedra_volume c tetrahedron1 :: Cube -> Tetrahedron tetrahedron1 c = @@ -216,7 +218,7 @@ tetrahedron1 c = v2' = Face.v1 (front_face c) v3' = Face.v2 (front_face c) fv' = rotate ccwx (Cube.fv c) - vol = 0 + vol = tetrahedra_volume c tetrahedron2 :: Cube -> Tetrahedron tetrahedron2 c = @@ -227,7 +229,7 @@ tetrahedron2 c = v2' = Face.v2 (front_face c) v3' = Face.v3 (front_face c) fv' = rotate ccwx $ rotate ccwx $ Cube.fv c - vol = 0 + vol = tetrahedra_volume c tetrahedron3 :: Cube -> Tetrahedron tetrahedron3 c = @@ -238,7 +240,7 @@ tetrahedron3 c = v2' = Face.v3 (front_face c) v3' = Face.v0 (front_face c) fv' = rotate cwx (Cube.fv c) - vol = 0 + vol = tetrahedra_volume c tetrahedron4 :: Cube -> Tetrahedron tetrahedron4 c = @@ -249,7 +251,7 @@ tetrahedron4 c = v2' = Face.v0 (top_face c) v3' = Face.v1 (top_face c) fv' = rotate cwy (Cube.fv c) - vol = 0 + vol = tetrahedra_volume c tetrahedron5 :: Cube -> Tetrahedron tetrahedron5 c = @@ -260,7 +262,7 @@ tetrahedron5 c = v2' = Face.v1 (top_face c) v3' = Face.v2 (top_face c) fv' = rotate cwy $ rotate cwz $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron6 :: Cube -> Tetrahedron tetrahedron6 c = @@ -273,7 +275,7 @@ tetrahedron6 c = fv' = rotate cwy $ rotate cwz $ rotate cwz $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron7 :: Cube -> Tetrahedron tetrahedron7 c = @@ -284,7 +286,7 @@ tetrahedron7 c = v2' = Face.v3 (top_face c) v3' = Face.v0 (top_face c) fv' = rotate cwy $ rotate ccwz $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron8 :: Cube -> Tetrahedron tetrahedron8 c = @@ -295,7 +297,7 @@ tetrahedron8 c = v2' = Face.v0 (back_face c) v3' = Face.v1 (back_face c) fv' = rotate cwy $ rotate cwy $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron9 :: Cube -> Tetrahedron tetrahedron9 c = @@ -308,7 +310,7 @@ tetrahedron9 c = fv' = rotate cwy $ rotate cwy $ rotate cwx $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron10 :: Cube -> Tetrahedron tetrahedron10 c = @@ -323,7 +325,7 @@ tetrahedron10 c = $ rotate cwx $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron11 :: Cube -> Tetrahedron tetrahedron11 c = @@ -336,7 +338,7 @@ tetrahedron11 c = fv' = rotate cwy $ rotate cwy $ rotate ccwx $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron12 :: Cube -> Tetrahedron @@ -348,7 +350,7 @@ tetrahedron12 c = v2' = Face.v0 (down_face c) v3' = Face.v1 (down_face c) fv' = rotate ccwy (Tetrahedron.fv (tetrahedron0 c)) - vol = 0 + vol = tetrahedra_volume c tetrahedron13 :: Cube -> Tetrahedron @@ -360,7 +362,7 @@ tetrahedron13 c = v2' = Face.v1 (down_face c) v3' = Face.v2 (down_face c) fv' = rotate ccwy $ rotate ccwz $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron14 :: Cube -> Tetrahedron @@ -374,7 +376,7 @@ tetrahedron14 c = fv' = rotate ccwy $ rotate ccwz $ rotate ccwz $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron15 :: Cube -> Tetrahedron @@ -386,7 +388,7 @@ tetrahedron15 c = v2' = Face.v3 (down_face c) v3' = Face.v0 (down_face c) fv' = rotate ccwy $ rotate cwz $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron16 :: Cube -> Tetrahedron @@ -398,7 +400,7 @@ tetrahedron16 c = v2' = Face.v0 (right_face c) v3' = Face.v1 (right_face c) fv' = rotate ccwz (Tetrahedron.fv (tetrahedron0 c)) - vol = 0 + vol = tetrahedra_volume c tetrahedron17 :: Cube -> Tetrahedron @@ -410,7 +412,7 @@ tetrahedron17 c = v2' = Face.v1 (right_face c) v3' = Face.v2 (right_face c) fv' = rotate ccwz $ rotate cwy $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron18 :: Cube -> Tetrahedron @@ -424,7 +426,7 @@ tetrahedron18 c = fv' = rotate ccwz $ rotate cwy $ rotate cwy $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron19 :: Cube -> Tetrahedron @@ -437,7 +439,7 @@ tetrahedron19 c = v3' = Face.v0 (right_face c) fv' = rotate ccwz $ rotate ccwy $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron20 :: Cube -> Tetrahedron @@ -449,7 +451,7 @@ tetrahedron20 c = v2' = Face.v0 (left_face c) v3' = Face.v1 (left_face c) fv' = rotate cwz (Tetrahedron.fv (tetrahedron0 c)) - vol = 0 + vol = tetrahedra_volume c tetrahedron21 :: Cube -> Tetrahedron @@ -461,7 +463,7 @@ tetrahedron21 c = v2' = Face.v1 (left_face c) v3' = Face.v2 (left_face c) fv' = rotate cwz $ rotate ccwy $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron22 :: Cube -> Tetrahedron @@ -475,7 +477,7 @@ tetrahedron22 c = fv' = rotate cwz $ rotate ccwy $ rotate ccwy $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedron23 :: Cube -> Tetrahedron @@ -488,7 +490,7 @@ tetrahedron23 c = v3' = Face.v0 (left_face c) fv' = rotate cwz $ rotate cwy $ Tetrahedron.fv (tetrahedron0 c) - vol = 0 + vol = tetrahedra_volume c tetrahedra :: Cube -> [Tetrahedron] diff --git a/src/Grid.hs b/src/Grid.hs index 7325d2b..d9fa975 100644 --- a/src/Grid.hs +++ b/src/Grid.hs @@ -57,7 +57,10 @@ cubes g | i <- [0..xmax], j <- [0..ymax], k <- [0..zmax], - let cube_ijk = Cube (h g) i j k (make_values fvs i j k)] + let delta = h g, + let tet_vol = (1/24)*(delta^(3::Int)), + let cube_ijk = + Cube delta i j k (make_values fvs i j k) tet_vol] where xmax = xsize - 1 ymax = ysize - 1 diff --git a/src/Tetrahedron.hs b/src/Tetrahedron.hs index eef1656..1f7c22b 100644 --- a/src/Tetrahedron.hs +++ b/src/Tetrahedron.hs @@ -29,8 +29,11 @@ instance Arbitrary Tetrahedron where rnd_v2 <- arbitrary :: Gen Point rnd_v3 <- arbitrary :: Gen Point rnd_fv <- arbitrary :: Gen FunctionValues - rnd_vol <- arbitrary :: Gen Double - return (Tetrahedron rnd_fv rnd_v0 rnd_v1 rnd_v2 rnd_v3 rnd_vol) + -- We can't assign an incorrect precomputed volume, + -- so we have to calculate the correct one here. + let t' = Tetrahedron rnd_fv rnd_v0 rnd_v1 rnd_v2 rnd_v3 0 + let vol = volume t' + return (Tetrahedron rnd_fv rnd_v0 rnd_v1 rnd_v2 rnd_v3 vol) instance Show Tetrahedron where @@ -267,27 +270,27 @@ volume t -- | The barycentric coordinates of a point with respect to v0. b0 :: Tetrahedron -> (RealFunction Point) -b0 t point = (volume inner_tetrahedron) / (volume t) +b0 t point = (volume inner_tetrahedron) / (precomputed_volume t) where inner_tetrahedron = t { v0 = point } -- | The barycentric coordinates of a point with respect to v1. b1 :: Tetrahedron -> (RealFunction Point) -b1 t point = (volume inner_tetrahedron) / (volume t) +b1 t point = (volume inner_tetrahedron) / (precomputed_volume t) where inner_tetrahedron = t { v1 = point } -- | The barycentric coordinates of a point with respect to v2. b2 :: Tetrahedron -> (RealFunction Point) -b2 t point = (volume inner_tetrahedron) / (volume t) +b2 t point = (volume inner_tetrahedron) / (precomputed_volume t) where inner_tetrahedron = t { v2 = point } -- | The barycentric coordinates of a point with respect to v3. b3 :: Tetrahedron -> (RealFunction Point) -b3 t point = (volume inner_tetrahedron) / (volume t) +b3 t point = (volume inner_tetrahedron) / (precomputed_volume t) where inner_tetrahedron = t { v3 = point }