1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | import unittest |
---|
4 | from math import sqrt, pi |
---|
5 | import numpy |
---|
6 | |
---|
7 | from anuga_1d.base.generic_domain import * |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | class Test_Generic_Domain(unittest.TestCase): |
---|
12 | def setUp(self): |
---|
13 | self.points = [0.0, 1.0, 2.0, 3.0] |
---|
14 | self.vertex_values = [[1.0,2.0],[4.0,5.0],[-1.0,2.0]] |
---|
15 | self.points2 = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0] |
---|
16 | |
---|
17 | def tearDown(self): |
---|
18 | pass |
---|
19 | #print " Tearing down" |
---|
20 | |
---|
21 | |
---|
22 | def test_creation(self): |
---|
23 | domain = Generic_domain(self.points) |
---|
24 | |
---|
25 | assert numpy.allclose(domain.neighbours, \ |
---|
26 | [[-1 , 1],[ 0 , 2],[ 1 ,-1]]) |
---|
27 | |
---|
28 | assert numpy.allclose(domain.neighbour_vertices, \ |
---|
29 | [[-1 , 0],[ 1 , 0],[ 1 ,-1]]) |
---|
30 | |
---|
31 | assert numpy.allclose(domain.number_of_boundaries, \ |
---|
32 | [1, 0, 1]) |
---|
33 | |
---|
34 | assert numpy.allclose(domain.surrogate_neighbours, \ |
---|
35 | [[0, 1],[0, 2],[1, 2]]) |
---|
36 | |
---|
37 | assert numpy.allclose(domain.vertices, \ |
---|
38 | [[ 0., 1.],[ 1., 2.],[ 2., 3.]]) |
---|
39 | |
---|
40 | |
---|
41 | assert numpy.allclose(domain.centroids, [0.5, 1.5, 2.5]) |
---|
42 | |
---|
43 | assert numpy.allclose(domain.areas, [ 1., 1., 1.]) |
---|
44 | |
---|
45 | assert numpy.allclose(domain.normals, \ |
---|
46 | [[-1., 1.],[-1., 1.],[-1., 1.]]) |
---|
47 | |
---|
48 | def test_set_timestepping_method(self): |
---|
49 | |
---|
50 | domain = Generic_domain(self.points) |
---|
51 | |
---|
52 | domain.set_timestepping_method('euler') |
---|
53 | assert domain.timestepping_method == 'euler' |
---|
54 | |
---|
55 | domain.set_timestepping_method('rk2') |
---|
56 | assert domain.timestepping_method == 'rk2' |
---|
57 | |
---|
58 | domain.set_timestepping_method('rk3') |
---|
59 | assert domain.timestepping_method == 'rk3' |
---|
60 | |
---|
61 | domain.set_timestepping_method(1) |
---|
62 | assert domain.timestepping_method == 'euler' |
---|
63 | |
---|
64 | domain.set_timestepping_method(2) |
---|
65 | assert domain.timestepping_method == 'rk2' |
---|
66 | |
---|
67 | domain.set_timestepping_method(3) |
---|
68 | assert domain.timestepping_method == 'rk3' |
---|
69 | |
---|
70 | try: |
---|
71 | domain.set_timestepping_method(4) |
---|
72 | except: |
---|
73 | pass |
---|
74 | else: |
---|
75 | raise Exception, 'Should have raised "wrong method" error' |
---|
76 | |
---|
77 | def test_set_spatial_order(self): |
---|
78 | |
---|
79 | domain = Generic_domain(self.points) |
---|
80 | |
---|
81 | domain.set_spatial_order(1) |
---|
82 | assert domain.order == 1 |
---|
83 | |
---|
84 | domain.set_spatial_order(2) |
---|
85 | assert domain.order == 2 |
---|
86 | |
---|
87 | |
---|
88 | try: |
---|
89 | domain.set_spatial_order(3) |
---|
90 | except: |
---|
91 | pass |
---|
92 | else: |
---|
93 | raise Exception, 'Should have raised "wrong order" error' |
---|
94 | |
---|
95 | |
---|
96 | #------------------------------------------------------------- |
---|
97 | if __name__ == "__main__": |
---|
98 | suite = unittest.makeSuite(Test_Generic_Domain, 'test') |
---|
99 | #suite = unittest.makeSuite(Test_Shallow_Water, 'test_evolve_first_order') |
---|
100 | |
---|
101 | |
---|
102 | runner = unittest.TextTestRunner() |
---|
103 | runner.run(suite) |
---|