source: branches/source_numpy_conversion/anuga/shallow_water/test_smf.py @ 7177

Last change on this file since 7177 was 5900, checked in by rwilson, 16 years ago

NumPy? conversion.

  • Property svn:executable set to *
File size: 4.3 KB
Line 
1import unittest
2import numpy
3from smf import slide_tsunami, slump_tsunami, Double_gaussian
4
5class Test_smf(unittest.TestCase):
6    def setUp(self):
7        pass
8
9    def tearDown(self):
10        pass
11
12
13    def test_Double_gaussian(self):
14        a3D = 5.6
15        wavelength = 10.2
16        width = 6.6
17        x0 = 0.0
18        y0 = 0.0
19        alpha = 0.0
20        kappa = 3.0
21        kappad = 0.8
22        dx = 0.5
23        zsmall = 0.01
24        scale = 1.0
25
26        dg = Double_gaussian(a3D, wavelength, width, \
27                             x0, y0, alpha, \
28                             kappa, kappad, zsmall, dx, scale)
29
30        assert numpy.allclose(dg.a3D, a3D)
31        assert numpy.allclose(dg.wavelength, wavelength)
32        assert numpy.allclose(dg.width, width)
33        assert numpy.allclose(dg.x0, x0)
34        assert numpy.allclose(dg.y0, y0)
35        assert numpy.allclose(dg.alpha, alpha)
36        assert numpy.allclose(dg.kappa, kappa)
37        assert numpy.allclose(dg.kappad, kappad)
38        assert numpy.allclose(dg.dx, dx)
39
40   
41    def test_slide_tsunami(self):
42
43        len = 600.0
44        dep = 150.0
45        th = 9.0
46        thk = 15.0
47        wid = 340.0
48        kappa = 3.0
49        kappad = 0.8
50        x0 = 100000.
51
52        slide = slide_tsunami(length=len, depth=dep, slope=th, x0=x0, \
53                              width = wid, thickness=thk, kappa=kappa, kappad=kappad, \
54                              verbose=False)
55
56        assert numpy.allclose(slide.a3D, 0.07775819)
57        assert numpy.allclose(slide.wavelength, 2938.66695708)
58        assert numpy.allclose(slide.width, 340.0)
59        assert numpy.allclose(slide.y0, 0.0)
60        assert numpy.allclose(slide.alpha, 0.0)
61
62
63    def test_slump_tsunami(self):
64
65        length = 4500.0
66        thk = 760.0
67        wid = 4500.0
68        dep = 1200.0
69        rad = 3330
70        dp = 0.23
71        th = 12
72        alpha = 0.0
73        x0 = 0
74        y0 = 0
75        gamma = 1.85
76
77        slump = slump_tsunami(length, dep, th, wid, thk, rad, dp, x0, y0, alpha, gamma, scale=1.0)
78
79        assert numpy.allclose(slump.a3D, 9.82538623)
80        assert numpy.allclose(slump.wavelength, 3660.37606554)
81        assert numpy.allclose(slump.width, 4500.0)
82        assert numpy.allclose(slump.x0, 0.0)
83        assert numpy.allclose(slump.y0, 0.0)
84        assert numpy.allclose(slump.alpha, 0.0)
85        assert numpy.allclose(slump.kappa, 3.0)
86        assert numpy.allclose(slump.kappad, 1.0)
87
88    def test_slide_tsunami_domain(self):
89
90        length = 600.0
91        dep = 150.0
92        th = 9.0
93        thk = 15.0
94        wid = 340.0
95        kappa = 3.0
96        kappad = 0.8
97        x0 = 100000.
98        y0 = x0
99       
100        from anuga.pmesh.mesh_interface import create_mesh_from_regions
101        polygon = [[0,0],[200000,0],[200000,200000],[0,200000]]
102        create_mesh_from_regions(polygon,
103                                 {'e0': [0], 'e1': [1], 'e2': [2], 'e3': [3]},
104                                 maximum_triangle_area=5000000000,
105                                 filename='test.msh',
106                                 verbose = False)
107
108        from anuga.shallow_water import Domain
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 numpy.allclose(min(min(w)), -517.877771593)
129        assert numpy.allclose(max(max(w)), 0.0)
130        assert numpy.allclose(slide.a3D, 518.38797486)
131
132
133#-------------------------------------------------------------
134if __name__ == "__main__":
135    #suite = unittest.makeSuite(Test_smf,'test_Double_gaussian')
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.