source: anuga_core/source/anuga/pyvolution/test_region.py @ 3514

Last change on this file since 3514 was 3514, checked in by duncan, 18 years ago

Hi all,
I'm doing a change in the anuga structure, moving the code to

\anuga_core\source\anuga

After you have done an svn update, the PYTHONPATH has to be changed to;
PYTHONPATH = anuga_core/source/

This is part of changes required to make installation of anuga quicker and reducing the size of our sandpits.

If any imports are broken, try fixing them. With adding anuga. to them for example. If this seems to have really broken things, email/phone me.

Cheers
Duncan

File size: 6.8 KB
Line 
1#!/usr/bin/env python
2
3import unittest
4from math import sqrt
5
6from domain import *
7from region import *
8#from anuga.config import epsilon
9from Numeric import allclose #, array, ones, Float
10
11
12def add_x_y(x, y):
13    return x+y
14
15def give_me_23(x, y):
16    return 23.0
17
18class Test_Region(unittest.TestCase):
19    def setUp(self):
20        pass
21
22
23    def tearDown(self):
24        pass
25
26
27    def test_region_tags(self):
28        """
29        get values based on triangle lists.
30        """
31        from mesh_factory import rectangular
32        from shallow_water import Domain
33        from Numeric import zeros, Float
34
35        #Create basic mesh
36        points, vertices, boundary = rectangular(1, 3)
37
38        #Create shallow water domain
39        domain = Domain(points, vertices, boundary)
40        domain.build_tagged_elements_dictionary({'bottom':[0,1],
41                                                 'top':[4,5],
42                                                 'all':[0,1,2,3,4,5]})
43
44
45        #Set friction
46        manning = 0.07
47        domain.set_quantity('friction', manning)
48
49        a = Set_region('bottom', 'friction', 0.09)
50        b = Set_region('top', 'friction', 1.0)
51        domain.set_region([a, b])
52        #print domain.quantities['friction'].get_values()
53        assert allclose(domain.quantities['friction'].get_values(),\
54                        [[ 0.09,  0.09,  0.09],
55                         [ 0.09,  0.09,  0.09],
56                         [ 0.07,  0.07,  0.07],
57                         [ 0.07,  0.07,  0.07],
58                         [ 1.0,  1.0,  1.0],
59                         [ 1.0,  1.0,  1.0]])
60
61        #c = Add_Value_To_region('all', 'friction', 10.0)
62        domain.set_region(Add_value_to_region('all', 'friction', 10.0))
63        #print domain.quantities['friction'].get_values()
64        assert allclose(domain.quantities['friction'].get_values(),
65                        [[ 10.09, 10.09, 10.09],
66                         [ 10.09, 10.09, 10.09],
67                         [ 10.07, 10.07, 10.07],
68                         [ 10.07, 10.07, 10.07],
69                         [ 11.0,  11.0,  11.0],
70                         [ 11.0,  11.0,  11.0]])
71
72        # trying a function
73        domain.set_region(Set_region('top', 'friction', add_x_y))
74        #print domain.quantities['friction'].get_values()
75        assert allclose(domain.quantities['friction'].get_values(),
76                        [[ 10.09, 10.09, 10.09],
77                         [ 10.09, 10.09, 10.09],
78                         [ 10.07, 10.07, 10.07],
79                         [ 10.07, 10.07, 10.07],
80                         [ 5./3,  2.0,  2./3],
81                         [ 1.0,  2./3,  2.0]])
82
83        domain.set_quantity('elevation', 10.0)
84        domain.set_quantity('stage', 10.0)
85        domain.set_region(Add_value_to_region('top', 'stage', 1.0,initial_quantity='elevation'))
86        #print domain.quantities['stage'].get_values()
87        assert allclose(domain.quantities['stage'].get_values(),
88                        [[ 10., 10., 10.],
89                         [ 10., 10., 10.],
90                         [ 10., 10., 10.],
91                         [ 10., 10., 10.],
92                         [ 11.0,  11.0,  11.0],
93                         [ 11.0,  11.0,  11.0]])
94
95       
96        domain.set_quantity('elevation', 10.0)
97        domain.set_quantity('stage', give_me_23)
98        #this works as well, (is cleaner, but doesn't work for regions)
99        #domain.set_quantity('stage',
100        #                    domain.quantities['stage'].vertex_values+ \
101        #                    domain.quantities['elevation'].vertex_values)
102        domain.set_region(Add_quantities('top', 'elevation','stage'))
103        #print domain.quantities['stage'].get_values()
104        assert allclose(domain.quantities['elevation'].get_values(),
105                        [[ 10., 10., 10.],
106                         [ 10., 10., 10.],
107                         [ 10., 10., 10.],
108                         [ 10., 10., 10.],
109                         [ 33.,  33.0,  33.],
110                         [ 33.0,  33.,  33.]])
111       
112    def test_unique_vertices(self):
113        """
114        get values based on triangle lists.
115        """
116        from mesh_factory import rectangular
117        from shallow_water import Domain
118        from Numeric import zeros, Float
119
120        #Create basic mesh
121        points, vertices, boundary = rectangular(1, 3)
122
123        #Create shallow water domain
124        domain = Domain(points, vertices, boundary)
125        domain.build_tagged_elements_dictionary({'bottom':[0,1],
126                                                 'top':[4,5],
127                                                 'all':[0,1,2,3,4,5]})
128
129        #Set friction
130        manning = 0.07
131        domain.set_quantity('friction', manning)
132
133        a = Set_region('bottom', 'friction', 0.09, location = 'unique vertices')
134        domain.set_region(a)
135        #print domain.quantities['friction'].get_values()
136        assert allclose(domain.quantities['friction'].get_values(),\
137                        [[ 0.09,  0.09,  0.09],
138                         [ 0.09,  0.09,  0.09],
139                         [ 0.09,  0.07,  0.09],
140                         [ 0.07,  0.09,  0.07],
141                         [ 0.07,  0.07,  0.07],
142                         [ 0.07,  0.07,  0.07]])
143
144
145    def test_unique_verticesII(self):
146        """
147        get values based on triangle lists.
148        """
149        from mesh_factory import rectangular
150        from shallow_water import Domain
151        from Numeric import zeros, Float
152
153        #Create basic mesh
154        points, vertices, boundary = rectangular(1, 3)
155
156        #Create shallow water domain
157        domain = Domain(points, vertices, boundary)
158        domain.build_tagged_elements_dictionary({'bottom':[0,1],
159                                                 'top':[4,5],
160                                                 'all':[0,1,2,3,4,5]})
161
162        #Set friction
163        manning = 0.07
164        domain.set_quantity('friction', manning)
165
166        domain.set_region(Add_value_to_region('bottom', 'friction', 1.0,initial_quantity='friction', location = 'unique vertices'))
167
168        #print domain.quantities['friction'].get_values()
169        assert allclose(domain.quantities['friction'].get_values(),\
170                        [[ 1.07,  1.07,  1.07],
171                         [ 1.07,  1.07,  1.07],
172                         [ 1.07,  0.07,  1.07],
173                         [ 0.07,  1.07,  0.07],
174                         [ 0.07,  0.07,  0.07],
175                         [ 0.07,  0.07,  0.07]])
176#-------------------------------------------------------------
177if __name__ == "__main__":
178    suite = unittest.makeSuite(Test_Region,'test')
179    runner = unittest.TextTestRunner()
180    runner.run(suite)
Note: See TracBrowser for help on using the repository browser.