Changeset 5208
- Timestamp:
- Apr 11, 2008, 4:20:45 PM (16 years ago)
- Location:
- anuga_core/source/anuga/abstract_2d_finite_volumes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/region.py
r2491 r5208 1 """ boundary.py - Classes for implementing region conditions1 """region.py - Classes for implementing region conditions 2 2 3 3 NOTE: I've only set it up for testing X values of constants and functions. … … 8 8 # FIXME (DSG-DSG) add better comments 9 9 10 from Numeric import average 10 11 class Region: 11 12 """Base class for modifying quantities based on a region. … … 61 62 """ 62 63 Will add a value to the current quantity value. 64 65 quantity = initial_quantity + X. 66 67 This method does not work with functions 68 69 Use average to add X to a mean average of the quantity values. 70 eg if applying this to elevation this will give a flat roof. 63 71 """ 64 72 65 def __init__(self, tag, quantity, X, location='vertices', initial_quantity=None ):73 def __init__(self, tag, quantity, X, location='vertices', initial_quantity=None, average=False): 66 74 #I have to get this going! 67 75 #Region.__init__(self) … … 70 78 self.location = location 71 79 self.X = X 80 self.average = average 72 81 if initial_quantity is None: 73 82 self.quantity_initial_value = quantity … … 87 96 # indices=self.build_indices(elements, domain), 88 97 # location=self.location) + self.X 89 90 98 Q = domain.get_quantity(self.quantity_initial_value) 91 new_values = Q.get_values(indices=self.build_indices(elements, domain), 92 location=self.location) + self.X 99 if self.average is True: 100 # Average the points, and then the verts in the averaged point. 101 values = Q.get_values(indices=self.build_indices(elements, domain), 102 location=self.location) 103 av = average(values) 104 if self.location == "vertices": 105 av = average(av) 106 new_values = av + self.X 107 else: 108 new_values = Q.get_values(indices=self.build_indices(elements, domain), 109 location=self.location) + self.X 93 110 domain.set_quantity(self.quantity_answer, new_values, 94 111 indices=self.build_indices(elements, domain), … … 97 114 class Add_quantities(Region): 98 115 """ 99 Will add a valueto the current quantity value.116 Will add a quantity to the current quantity value. 100 117 """ 101 118 -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_region.py
r3514 r5208 7 7 from region import * 8 8 #from anuga.config import epsilon 9 from Numeric import allclose #, array, ones, Float9 from Numeric import allclose, average #, array, ones, Float 10 10 11 11 … … 174 174 [ 0.07, 0.07, 0.07], 175 175 [ 0.07, 0.07, 0.07]]) 176 177 def test_unique_vertices_average_loc_vert(self): 178 """ 179 get values based on triangle lists. 180 """ 181 from mesh_factory import rectangular 182 from shallow_water import Domain 183 from Numeric import zeros, Float 184 185 #Create basic mesh 186 points, vertices, boundary = rectangular(1, 3) 187 #Create shallow water domain 188 domain = Domain(points, vertices, boundary) 189 domain.build_tagged_elements_dictionary({'bottom':[0,1], 190 'top':[4,5], 191 'not_bottom':[2,3,4,5]}) 192 193 #Set friction 194 domain.set_quantity('friction', add_x_y) 195 av_bottom = 2.0/3.0 196 add = 60.0 197 calc_frict = av_bottom + add 198 domain.set_region(Add_value_to_region('bottom', 'friction', add, 199 initial_quantity='friction', 200 #location='unique vertices', 201 location='vertices', 202 average=True 203 )) 204 205 #print domain.quantities['friction'].get_values() 206 frict_points = domain.quantities['friction'].get_values() 207 assert allclose(frict_points[0],\ 208 [ calc_frict, calc_frict, calc_frict]) 209 assert allclose(frict_points[1],\ 210 [ calc_frict, calc_frict, calc_frict]) 211 212 def test_unique_vertices_average_loc_unique_vert(self): 213 """ 214 get values based on triangle lists. 215 """ 216 from mesh_factory import rectangular 217 from shallow_water import Domain 218 from Numeric import zeros, Float 219 220 #Create basic mesh 221 points, vertices, boundary = rectangular(1, 3) 222 #Create shallow water domain 223 domain = Domain(points, vertices, boundary) 224 domain.build_tagged_elements_dictionary({'bottom':[0,1], 225 'top':[4,5], 226 'not_bottom':[2,3,4,5]}) 227 228 #Set friction 229 domain.set_quantity('friction', add_x_y) 230 av_bottom = 2.0/3.0 231 add = 60.0 232 calc_frict = av_bottom + add 233 domain.set_region(Add_value_to_region('bottom', 'friction', add, 234 initial_quantity='friction', 235 location='unique vertices', 236 average=True 237 )) 238 239 #print domain.quantities['friction'].get_values() 240 frict_points = domain.quantities['friction'].get_values() 241 assert allclose(frict_points[0],\ 242 [ calc_frict, calc_frict, calc_frict]) 243 assert allclose(frict_points[1],\ 244 [ calc_frict, calc_frict, calc_frict]) 245 assert allclose(frict_points[2],\ 246 [ calc_frict, 1.0 + 2.0/3.0, calc_frict]) 247 assert allclose(frict_points[3],\ 248 [ 2.0/3.0,calc_frict, 1.0 + 2.0/3.0]) 249 250 176 251 #------------------------------------------------------------- 177 252 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.