1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | import unittest |
---|
4 | from math import sqrt |
---|
5 | |
---|
6 | from domain import * |
---|
7 | from region import * |
---|
8 | #from config import epsilon |
---|
9 | from Numeric import allclose #, array, ones, Float |
---|
10 | |
---|
11 | |
---|
12 | def add_x_y(x, y): |
---|
13 | return x+y |
---|
14 | |
---|
15 | class TestCase(unittest.TestCase): |
---|
16 | def setUp(self): |
---|
17 | pass |
---|
18 | |
---|
19 | |
---|
20 | def tearDown(self): |
---|
21 | pass |
---|
22 | |
---|
23 | |
---|
24 | def test_region_tags(self): |
---|
25 | """ |
---|
26 | get values based on triangle lists. |
---|
27 | """ |
---|
28 | from mesh_factory import rectangular |
---|
29 | from shallow_water import Domain |
---|
30 | from Numeric import zeros, Float |
---|
31 | |
---|
32 | #Create basic mesh |
---|
33 | points, vertices, boundary = rectangular(1, 3) |
---|
34 | |
---|
35 | #Create shallow water domain |
---|
36 | domain = Domain(points, vertices, boundary) |
---|
37 | domain.build_tagged_elements_dictionary({'bottom':[0,1], |
---|
38 | 'top':[4,5], |
---|
39 | 'all':[0,1,2,3,4,5]}) |
---|
40 | |
---|
41 | |
---|
42 | #Set friction |
---|
43 | manning = 0.07 |
---|
44 | domain.set_quantity('friction', manning) |
---|
45 | |
---|
46 | a = Set_Region('bottom', 'friction', 0.09) |
---|
47 | b = Set_Region('top', 'friction', 1.0) |
---|
48 | domain.set_region([a, b]) |
---|
49 | #print domain.quantities['friction'].get_values() |
---|
50 | assert allclose(domain.quantities['friction'].get_values(), [[ 0.09, 0.09, 0.09], |
---|
51 | [ 0.09, 0.09, 0.09], |
---|
52 | [ 0.07, 0.07, 0.07], |
---|
53 | [ 0.07, 0.07, 0.07], |
---|
54 | [ 1.0, 1.0, 1.0], |
---|
55 | [ 1.0, 1.0, 1.0]]) |
---|
56 | |
---|
57 | #c = Add_Value_To_Region('all', 'friction', 10.0) |
---|
58 | domain.set_region(Add_Value_To_Region('all', 'friction', 10.0)) |
---|
59 | #print domain.quantities['friction'].get_values() |
---|
60 | assert allclose(domain.quantities['friction'].get_values(), |
---|
61 | [[ 10.09, 10.09, 10.09], |
---|
62 | [ 10.09, 10.09, 10.09], |
---|
63 | [ 10.07, 10.07, 10.07], |
---|
64 | [ 10.07, 10.07, 10.07], |
---|
65 | [ 11.0, 11.0, 11.0], |
---|
66 | [ 11.0, 11.0, 11.0]]) |
---|
67 | |
---|
68 | # trying a function |
---|
69 | domain.set_region(Set_Region('top', 'friction', add_x_y)) |
---|
70 | #print domain.quantities['friction'].get_values() |
---|
71 | assert allclose(domain.quantities['friction'].get_values(), |
---|
72 | [[ 10.09, 10.09, 10.09], |
---|
73 | [ 10.09, 10.09, 10.09], |
---|
74 | [ 10.07, 10.07, 10.07], |
---|
75 | [ 10.07, 10.07, 10.07], |
---|
76 | [ 5./3, 2.0, 2./3], |
---|
77 | [ 1.0, 2./3, 2.0]]) |
---|
78 | |
---|
79 | #------------------------------------------------------------- |
---|
80 | if __name__ == "__main__": |
---|
81 | suite = unittest.makeSuite(TestCase,'test') |
---|
82 | runner = unittest.TextTestRunner() |
---|
83 | runner.run(suite) |
---|