From 3a58695c57f57c9adbc0fb2ca26e06e7da7bfd63 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 7 Apr 2014 12:57:37 -0400 Subject: [PATCH] Add Mat6 and Mat7 synonyms. Move the example FEM into its own FEM.R1.Exampl1 module. Use the new example FEM module in the FEM.R1 doctests. --- numerical-analysis.cabal | 1 + src/FEM/R1.hs | 87 ++++------------------ examples/fem1.hs => src/FEM/R1/Example1.hs | 2 +- src/Linear/Matrix.hs | 2 + 4 files changed, 20 insertions(+), 72 deletions(-) rename examples/fem1.hs => src/FEM/R1/Example1.hs (96%) diff --git a/numerical-analysis.cabal b/numerical-analysis.cabal index 8212344..6dfb498 100644 --- a/numerical-analysis.cabal +++ b/numerical-analysis.cabal @@ -19,6 +19,7 @@ data-files: makefile library exposed-modules: FEM.R1 + FEM.R1.Example1 Integration.Gaussian, Integration.Simpson, Integration.Trapezoid, diff --git a/src/FEM/R1.hs b/src/FEM/R1.hs index 4794a3c..ae7548a 100644 --- a/src/FEM/R1.hs +++ b/src/FEM/R1.hs @@ -281,22 +281,8 @@ big_Ns_matrix = -- -- Examples: -- --- >>> import Linear.Matrix ( Col4, frobenius_norm, fromList ) --- >>> import Naturals ( N3, N4, N7 ) --- --- >>> let big_A = const (1::Double) --- >>> let c x = sin x --- >>> let f x = x*(sin x) --- >>> let bdy = Left (Dirichlet (0,1::Double)) --- >>> let pde = PDE big_A c f bdy --- --- >>> let i1 = (0.0,1/3) --- >>> let i2 = (1/3,2/3) --- >>> let i3 = (2/3,4/5) --- >>> let i4 = (4/5,1.0) --- >>> let mesh = fromList [[i1], [i2], [i3], [i4]] :: Col4 (Double,Double) --- >>> let pvec = fromList [[2],[3],[2],[1]] :: Col4 Int --- >>> let params = Params mesh pvec :: Params N4 N3 N7 Double +-- >>> import Linear.Matrix ( Col7, frobenius_norm ) +-- >>> import FEM.R1.Example1 ( pde', params' ) -- -- >>> let f1 = [0.0418] -- >>> let f2 = [0.0805] @@ -305,8 +291,8 @@ big_Ns_matrix = -- >>> let f5 = [-0.0332] -- >>> let f6 = [-0.0054] -- >>> let f7 = [-0.0267] --- >>> let expected = fromList [f1,f2,f3,f4,f5,f6,f7] :: Col N7 Double --- >>> let actual = big_F pde params +-- >>> let expected = fromList [f1,f2,f3,f4,f5,f6,f7] :: Col7 Double +-- >>> let actual = big_F pde' params' -- >>> frobenius_norm (actual - expected) < 1e-4 -- True -- @@ -410,22 +396,8 @@ big_K_elem pde params _ k cur_K _ = -- -- Examples: -- --- >>> import Linear.Matrix ( Col4, frobenius_norm, fromList ) --- >>> import Naturals ( N3, N4, N7 ) --- --- >>> let big_A = const (1::Double) --- >>> let c x = sin x --- >>> let f x = x*(sin x) --- >>> let bdy = Left (Dirichlet (0,1::Double)) --- >>> let pde = PDE big_A c f bdy --- --- >>> let i1 = (0.0,1/3) --- >>> let i2 = (1/3,2/3) --- >>> let i3 = (2/3,4/5) --- >>> let i4 = (4/5,1.0) --- >>> let mesh = fromList [[i1], [i2], [i3], [i4]] :: Col4 (Double,Double) --- >>> let pvec = fromList [[2],[3],[2],[1]] :: Col4 Int --- >>> let params = Params mesh pvec :: Params N4 N3 N7 Double +-- >>> import Linear.Matrix ( Mat7, frobenius_norm ) +-- >>> import FEM.R1.Example1 ( pde', params' ) -- -- >>> let k1 = [6, -3, 0, 0, 0, 0, 0] :: [Double] -- >>> let k2 = [-3, 10.5, -7.5, 0, 0, 0, 0] :: [Double] @@ -434,8 +406,8 @@ big_K_elem pde params _ k cur_K _ = -- >>> let k5 = [0, 0, 0, 0, 6, 0, 0] :: [Double] -- >>> let k6 = [0, 0, 0, 0, 0, 6, 0] :: [Double] -- >>> let k7 = [0, 0, 0, 0, 0, 0, 15] :: [Double] --- >>> let expected = fromList [k1,k2,k3,k4,k5,k6,k7] :: Mat N7 N7 Double --- >>> let actual = big_K pde params +-- >>> let expected = fromList [k1,k2,k3,k4,k5,k6,k7] :: Mat7 Double +-- >>> let actual = big_K pde' params' -- >>> frobenius_norm (actual - expected) < 1e-10 -- True -- @@ -489,22 +461,8 @@ big_M_elem pde params _ k cur_M _ = -- -- Examples: -- --- >>> import Linear.Matrix ( Col4, frobenius_norm, fromList ) --- >>> import Naturals ( N3, N4, N7 ) --- --- >>> let big_A = const (1::Double) --- >>> let c x = sin x --- >>> let f x = x*(sin x) --- >>> let bdy = Left (Dirichlet (0,1::Double)) --- >>> let pde = PDE big_A c f bdy --- --- >>> let i1 = (0.0,1/3) --- >>> let i2 = (1/3,2/3) --- >>> let i3 = (2/3,4/5) --- >>> let i4 = (4/5,1.0) --- >>> let mesh = fromList [[i1], [i2], [i3], [i4]] :: Col4 (Double,Double) --- >>> let pvec = fromList [[2],[3],[2],[1]] :: Col4 Int --- >>> let params = Params mesh pvec :: Params N4 N3 N7 Double +-- >>> import Linear.Matrix ( Mat7, frobenius_norm ) +-- >>> import FEM.R1.Example1 ( pde', params' ) -- -- >>> let m1 = [0.0723,0.0266,0,-0.0135,-0.0305,0.0058,0] :: [Double] -- >>> let m2 = [0.0266,0.0897,0.0149,0,-0.0345,-0.0109,-0.0179] :: [Double] @@ -514,8 +472,8 @@ big_M_elem pde params _ k cur_M _ = -- >>> let m6 = [0.0058,-0.0109,0,0,0.0018,0.0076,0] :: [Double] -- >>> let m7 = [0,-0.0179,-0.0185,0,0,0,0.0178] :: [Double] -- --- >>> let expected = fromList [m1,m2,m3,m4,m5,m6,m7] :: Mat N7 N7 Double --- >>> let actual = big_M pde params +-- >>> let expected = fromList [m1,m2,m3,m4,m5,m6,m7] :: Mat7 Double +-- >>> let actual = big_M pde' params' -- >>> frobenius_norm (actual - expected) < 1e-3 -- True -- @@ -536,22 +494,8 @@ big_M pde params = -- -- Examples: -- --- >>> import Linear.Matrix ( Col4, Col7, frobenius_norm, fromList ) --- >>> import Naturals ( N3, N4, N7 ) --- --- >>> let big_A = const (1::Double) --- >>> let c x = sin x --- >>> let f x = x*(sin x) --- >>> let bdy = Left (Dirichlet (0,1::Double)) --- >>> let pde = PDE big_A c f bdy --- --- >>> let i1 = (0.0,1/3) --- >>> let i2 = (1/3,2/3) --- >>> let i3 = (2/3,4/5) --- >>> let i4 = (4/5,1.0) --- >>> let mesh = fromList [[i1], [i2], [i3], [i4]] :: Col4 (Double,Double) --- >>> let pvec = fromList [[2],[3],[2],[1]] :: Col4 Int --- >>> let params = Params mesh pvec :: Params N4 N3 N7 Double +-- >>> import Linear.Matrix ( Col7, frobenius_norm ) +-- >>> import FEM.R1.Example1 ( pde', params' ) -- -- >>> let c1 = [0.02366220347687] :: [Double] -- >>> let c2 = [0.03431630082636] :: [Double] @@ -560,8 +504,9 @@ big_M pde params = -- >>> let c5 = [-0.00518637005151] :: [Double] -- >>> let c6 = [-0.00085028505337] :: [Double] -- >>> let c7 = [-0.00170478210110] :: [Double] +-- >>> -- >>> let expected = fromList [c1,c2,c3,c4,c5,c6,c7] :: Col7 Double --- >>> let actual = coefficients pde params +-- >>> let actual = coefficients pde' params' -- >>> frobenius_norm (actual - expected) < 1e-8 -- True -- diff --git a/examples/fem1.hs b/src/FEM/R1/Example1.hs similarity index 96% rename from examples/fem1.hs rename to src/FEM/R1/Example1.hs index 59d48bb..ffdf639 100644 --- a/examples/fem1.hs +++ b/src/FEM/R1/Example1.hs @@ -1,4 +1,4 @@ -module Main +module FEM.R1.Example1 where import FEM.R1 diff --git a/src/Linear/Matrix.hs b/src/Linear/Matrix.hs index f6dbec0..3af2788 100644 --- a/src/Linear/Matrix.hs +++ b/src/Linear/Matrix.hs @@ -67,6 +67,8 @@ type Mat2 a = Mat N2 N2 a type Mat3 a = Mat N3 N3 a type Mat4 a = Mat N4 N4 a type Mat5 a = Mat N5 N5 a +type Mat6 a = Mat N6 N6 a +type Mat7 a = Mat N7 N7 a -- * Type synonyms for 1-by-n row "vectors". -- 2.43.2