source: trunk/anuga_core/source/anuga/shallow_water/test_smf.py @ 7844

Last change on this file since 7844 was 7780, checked in by hudson, 14 years ago

Almost all failing tests fixed.

  • Property svn:executable set to *
File size: 4.1 KB
Line 
1import unittest
2import numpy as num
3from smf import slide_tsunami, slump_tsunami, Double_gaussian
4from shallow_water_domain import Domain
5
6class Test_smf(unittest.TestCase):
7    def setUp(self):
8        pass
9
10    def tearDown(self):
11        pass
12
13
14    def test_Double_gaussian(self):
15        a3D = 5.6
16        wavelength = 10.2
17        width = 6.6
18        x0 = 0.0
19        y0 = 0.0
20        alpha = 0.0
21        kappa = 3.0
22        kappad = 0.8
23        dx = 0.5
24        zsmall = 0.01
25        scale = 1.0
26
27        dg = Double_gaussian(a3D, wavelength, width, \
28                             x0, y0, alpha, \
29                             kappa, kappad, zsmall, dx, scale)
30
31        assert num.allclose(dg.a3D, a3D)
32        assert num.allclose(dg.wavelength, wavelength)
33        assert num.allclose(dg.width, width)
34        assert num.allclose(dg.x0, x0)
35        assert num.allclose(dg.y0, y0)
36        assert num.allclose(dg.alpha, alpha)
37        assert num.allclose(dg.kappa, kappa)
38        assert num.allclose(dg.kappad, kappad)
39        assert num.allclose(dg.dx, dx)
40
41   
42    def test_slide_tsunami(self):
43
44        len = 600.0
45        dep = 150.0
46        th = 9.0
47        thk = 15.0
48        wid = 340.0
49        kappa = 3.0
50        kappad = 0.8
51        x0 = 100000.
52
53        slide = slide_tsunami(length=len, depth=dep, slope=th, x0=x0, \
54                              width = wid, thickness=thk, kappa=kappa, kappad=kappad, \
55                              verbose=False)
56
57        assert num.allclose(slide.a3D, 0.07775819)
58        assert num.allclose(slide.wavelength, 2938.66695708)
59        assert num.allclose(slide.width, 340.0)
60        assert num.allclose(slide.y0, 0.0)
61        assert num.allclose(slide.alpha, 0.0)
62
63
64    def test_slump_tsunami(self):
65
66        length = 4500.0
67        thk = 760.0
68        wid = 4500.0
69        dep = 1200.0
70        rad = 3330
71        dp = 0.23
72        th = 12
73        alpha = 0.0
74        x0 = 0
75        y0 = 0
76        gamma = 1.85
77
78        slump = slump_tsunami(length, dep, th, wid, thk, rad, dp, x0, y0, alpha, gamma, scale=1.0)
79
80        assert num.allclose(slump.a3D, 9.82538623)
81        assert num.allclose(slump.wavelength, 3660.37606554)
82        assert num.allclose(slump.width, 4500.0)
83        assert num.allclose(slump.x0, 0.0)
84        assert num.allclose(slump.y0, 0.0)
85        assert num.allclose(slump.alpha, 0.0)
86        assert num.allclose(slump.kappa, 3.0)
87        assert num.allclose(slump.kappad, 1.0)
88
89    def test_slide_tsunami_domain(self):
90
91        length = 600.0
92        dep = 150.0
93        th = 9.0
94        thk = 15.0
95        wid = 340.0
96        kappa = 3.0
97        kappad = 0.8
98        x0 = 100000.
99        y0 = x0
100       
101        from anuga.pmesh.mesh_interface import create_mesh_from_regions
102        polygon = [[0,0],[200000,0],[200000,200000],[0,200000]]
103        create_mesh_from_regions(polygon,
104                                 {'e0': [0], 'e1': [1], 'e2': [2], 'e3': [3]},
105                                 maximum_triangle_area=5000000000,
106                                 filename='test.msh',
107                                 verbose = False)
108
109        domain = Domain('test.msh', use_cache = True, verbose = False)
110
111        slide = slide_tsunami(length, dep, th, x0, y0, \
112                              wid, thk, kappa, kappad, \
113                              domain=domain,verbose=False)
114
115        domain.set_quantity('stage', slide)
116        stage = domain.get_quantity('stage')
117        w = stage.get_values()
118
119##        check = [[-0.0 -0.0 -0.0],
120##                 [-.189709745 -517.877716 -0.0],
121##                 [-0.0 -0.0 -2.7695931e-08],
122##                 [-0.0 -2.7695931e-08 -1.897097e-01]
123##                 [-0.0 -517.877716 -0.0],
124##                 [-0.0 -0.0 -0.0],
125##                 [-0.0 -0.0 -0.0],
126##                 [-0.0 -0.0 -0.0]]
127
128        assert num.allclose(num.min(w), -517.877771593)
129        assert num.allclose(num.max(w), 0.0)
130        assert num.allclose(slide.a3D, 518.38797486)
131
132
133#-------------------------------------------------------------
134
135if __name__ == "__main__":
136    suite = unittest.makeSuite(Test_smf,'test')
137    runner = unittest.TextTestRunner()
138    runner.run(suite)
139
Note: See TracBrowser for help on using the repository browser.