1 | import unittest |
---|
2 | from Numeric import allclose |
---|
3 | from smf import slide_tsunami, slump_tsunami, Double_gaussian |
---|
4 | |
---|
5 | class 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 allclose(dg.a3D, a3D) |
---|
31 | assert allclose(dg.wavelength, wavelength) |
---|
32 | assert allclose(dg.width, width) |
---|
33 | assert allclose(dg.x0, x0) |
---|
34 | assert allclose(dg.y0, y0) |
---|
35 | assert allclose(dg.alpha, alpha) |
---|
36 | assert allclose(dg.kappa, kappa) |
---|
37 | assert allclose(dg.kappad, kappad) |
---|
38 | assert 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 allclose(slide.a3D, 0.07775819) |
---|
57 | assert allclose(slide.wavelength, 2938.66695708) |
---|
58 | assert allclose(slide.width, 340.0) |
---|
59 | assert allclose(slide.y0, 0.0) |
---|
60 | assert 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 allclose(slump.a3D, 9.82538623) |
---|
80 | assert allclose(slump.wavelength, 3660.37606554) |
---|
81 | assert allclose(slump.width, 4500.0) |
---|
82 | assert allclose(slump.x0, 0.0) |
---|
83 | assert allclose(slump.y0, 0.0) |
---|
84 | assert allclose(slump.alpha, 0.0) |
---|
85 | assert allclose(slump.kappa, 3.0) |
---|
86 | assert 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 allclose(min(min(w)), -517.877771593) |
---|
129 | assert allclose(max(max(w)), 0.0) |
---|
130 | assert allclose(slide.a3D, 518.38797486) |
---|
131 | |
---|
132 | |
---|
133 | #------------------------------------------------------------- |
---|
134 | if __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 | |
---|