Changeset 8056
- Timestamp:
- Oct 29, 2010, 11:08:43 AM (12 years ago)
- Location:
- trunk/anuga_core/source/anuga/structures
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/structures/boyd_box_operator.py
r8035 r8056 17 17 def __init__(self, 18 18 domain, 19 end_point0,20 end_point1,21 19 losses, 22 20 width, 23 21 height=None, 24 apron=None, 22 end_points=None, 23 exchange_lines=None, 24 enquiry_points=None, 25 apron=0.1, 25 26 manning=0.013, 26 27 enquiry_gap=0.0, … … 32 33 logging=False, 33 34 verbose=False): 34 35 35 36 36 anuga.Structure_operator.__init__(self, 37 37 domain, 38 end_point0,39 end_point1,40 38 width, 41 39 height, 40 end_points, 41 exchange_lines, 42 enquiry_points, 42 43 apron, 43 44 manning, -
trunk/anuga_core/source/anuga/structures/boyd_pipe_operator.py
r8034 r8056 16 16 def __init__(self, 17 17 domain, 18 end_point0,19 end_point1,20 18 losses, 19 end_points=None, 20 exchange_lines=None, 21 enquiry_points=None, 21 22 diameter=None, 22 apron= None,23 apron=0.1, 23 24 manning=0.013, 24 25 enquiry_gap=0.2, … … 30 31 logging=False, 31 32 verbose=False): 32 33 34 33 35 34 anuga.Structure_operator.__init__(self, 36 35 domain, 37 end_point0, 38 end_point1, 36 end_points, 37 exchange_lines, 38 enquiry_points, 39 39 width=diameter, 40 40 height=None, -
trunk/anuga_core/source/anuga/structures/inlet.py
r8050 r8056 1 from anuga.geometry.polygon import inside_polygon, is_inside_polygon, polyline_overlap1 from anuga.geometry.polygon import inside_polygon, is_inside_polygon, line_intersect 2 2 from anuga.config import velocity_protection, g 3 3 import math … … 9 9 """ 10 10 11 def __init__(self, domain, polyline, verbose=False):11 def __init__(self, domain, line, verbose=False): 12 12 13 13 self.domain = domain 14 14 self.domain_bounding_polygon = self.domain.get_boundary_polygon() 15 self. polyline = polyline15 self.line = line 16 16 self.verbose = verbose 17 17 … … 27 27 vertex_coordinates = self.domain.get_vertex_coordinates(absolute=True) 28 28 29 # Check that polyline lies within the mesh.30 for point in self. polyline:29 # Check that line lies within the mesh. 30 for point in self.line: 31 31 msg = 'Point %s ' % str(point) 32 32 msg += ' did not fall within the domain boundary.' … … 35 35 36 36 37 self.triangle_indices = polyline_overlap(vertex_coordinates, self.polyline)37 self.triangle_indices = line_intersect(vertex_coordinates, self.line) 38 38 39 39 if len(self.triangle_indices) == 0: 40 msg = 'Inlet polyline=%s ' % (self.polyline)41 msg += 'No triangles intersecting polyline '40 msg = 'Inlet line=%s ' % (self.line) 41 msg += 'No triangles intersecting line ' 42 42 raise Exception, msg 43 43 … … 47 47 48 48 # Compute inlet area as the sum of areas of triangles identified 49 # by polyline. Must be called after compute_inlet_triangle_indices().49 # by line. Must be called after compute_inlet_triangle_indices(). 50 50 if len(self.triangle_indices) == 0: 51 region = 'Inlet polyline=%s' % (self.inlet_polyline)51 region = 'Inlet line=%s' % (self.inlet_line) 52 52 msg = 'No triangles have been identified in region ' 53 53 raise Exception, msg -
trunk/anuga_core/source/anuga/structures/inlet_enquiry.py
r8050 r8056 1 from anuga.geometry.polygon import inside_polygon, is_inside_polygon, polyline_overlap1 from anuga.geometry.polygon import inside_polygon, is_inside_polygon, line_intersect 2 2 from anuga.config import velocity_protection, g 3 3 import math -
trunk/anuga_core/source/anuga/structures/structure_operator.py
r8050 r8056 22 22 def __init__(self, 23 23 domain, 24 end_point0,25 end_point1,26 24 width, 27 25 height, 26 end_points, 27 exchange_lines, 28 enquiry_points, 28 29 apron, 29 30 manning, … … 37 38 self.domain = domain 38 39 self.domain.set_fractional_step_operator(self) 39 self.end_points = [end_point0, end_point1]40 41 40 self.end_points = end_points 41 self.exchange_lines = exchange_lines 42 self.enquiry_points = enquiry_points 42 43 43 44 if height is None: … … 58 59 self.description = description 59 60 60 61 61 if label == None: 62 62 self.label = "structure_%g" % Structure_operator.counter … … 64 64 self.label = label + '_%g' % Structure_operator.counter 65 65 66 67 66 if structure_type == None: 68 67 self.structure_type = 'generic structure' … … 70 69 self.structure_type = structure_type 71 70 72 self.verbose = verbose 73 74 71 self.verbose = verbose 75 72 76 73 # Keep count of structures … … 83 80 self.driving_energy = 0.0 84 81 85 self.__create_exchange_polylines() 86 82 if exchange_lines is not None: 83 self.__process_skew_culvert() 84 elif end_points is not None: 85 self.__process_non_skew_culvert() 86 else: 87 raise Exception, 'Define either exchange_lines or end_points' 88 87 89 self.inlets = [] 88 polyline0 = self.inlet_polylines[0]89 enquiry_point0 = self. inlet_equiry_points[0]90 line0 = self.exchange_lines[0] #self.inlet_lines[0] 91 enquiry_point0 = self.enquiry_points[0] 90 92 outward_vector0 = self.culvert_vector 91 self.inlets.append(inlet_enquiry.Inlet_enquiry(self.domain, polyline0,93 self.inlets.append(inlet_enquiry.Inlet_enquiry(self.domain, line0, 92 94 enquiry_point0, outward_vector0, self.verbose)) 93 95 94 polyline1 = self.inlet_polylines[1]95 enquiry_point1 = self. inlet_equiry_points[1]96 line1 = self.exchange_lines[1] 97 enquiry_point1 = self.enquiry_points[1] 96 98 outward_vector1 = - self.culvert_vector 97 self.inlets.append(inlet_enquiry.Inlet_enquiry(self.domain, polyline1,99 self.inlets.append(inlet_enquiry.Inlet_enquiry(self.domain, line1, 98 100 enquiry_point1, outward_vector1, self.verbose)) 99 101 … … 185 187 self.delta_total_energy = self.inlets[0].get_enquiry_stage() - self.inlets[1].get_enquiry_stage() 186 188 187 188 189 self.inflow = self.inlets[0] 189 190 self.outflow = self.inlets[1] 190 191 191 192 192 if self.delta_total_energy < 0: … … 196 196 197 197 198 def __ create_exchange_polylines(self):199 200 """Create polylines at the end of a culvert inlet and outlet.201 At either end two polylines will be created; one for the actual flow to pass through and one a little further away198 def __process_non_skew_culvert(self): 199 200 """Create lines at the end of a culvert inlet and outlet. 201 At either end two lines will be created; one for the actual flow to pass through and one a little further away 202 202 for enquiring the total energy at both ends of the culvert and transferring flow. 203 203 """ 204 205 # Calculate geometry 206 x0, y0 = self.end_points[0] 207 x1, y1 = self.end_points[1] 208 209 dx = x1 - x0 210 dy = y1 - y0 211 212 self.culvert_vector = num.array([dx, dy]) 213 self.culvert_length = math.sqrt(num.sum(self.culvert_vector**2)) 204 205 self.culvert_vector = self.end_points[1] - self.end_points[0] 206 self.culvert_length = math.sqrt(num.sum(self.culvert_vector**2)) 214 207 assert self.culvert_length > 0.0, 'The length of culvert is less than 0' 215 216 # Unit direction vector and normal 217 self.culvert_vector /= self.culvert_length # Unit vector in culvert direction 218 self.culvert_normal = num.array([-dy, dx])/self.culvert_length # Normal vector 219 220 # Short hands 221 w = 0.5*self.width*self.culvert_normal # Perpendicular vector of 1/2 width 222 #h = self.apron*self.culvert_vector # Vector of length=height in the 223 # direction of the culvert 224 225 #gap = 1.5*h + self.enquiry_gap 226 gap = (self.apron+ self.enquiry_gap)*self.culvert_vector 227 228 self.inlet_polylines = [] 229 self.inlet_equiry_points = [] 208 209 self.culvert_vector /= self.culvert_length 210 211 culvert_normal = num.array([-self.culvert_vector[1], self.culvert_vector[0]]) # Normal vector 212 w = 0.5*self.width*culvert_normal # Perpendicular vector of 1/2 width 213 214 self.exchange_lines = [] 230 215 231 216 # Build exchange polyline and enquiry point 232 for i in [0, 1]: 233 i0 = (2*i-1) #i0 determines the sign of the points 234 p0 = self.end_points[i] + w 235 p1 = self.end_points[i] - w 236 ep = self.end_points[i] + i0*gap 237 238 self.inlet_polylines.append(num.array([p0, p1])) 239 self.inlet_equiry_points.append(ep) 240 217 if self.enquiry_points is None: 218 219 gap = (self.apron + self.enquiry_gap)*self.culvert_vector 220 self.enquiry_points = [] 221 222 for i in [0, 1]: 223 p0 = self.end_points[i] + w 224 p1 = self.end_points[i] - w 225 self.exchange_lines.append(num.array([p0, p1])) 226 ep = self.end_points[i] + (2*i - 1)*gap #(2*i - 1) determines the sign of the points 227 self.enquiry_points.append(ep) 228 229 else: 230 for i in [0, 1]: 231 p0 = self.end_points[i] + w 232 p1 = self.end_points[i] - w 233 self.exchange_lines.append(num.array([p0, p1])) 234 235 236 def __process_skew_culvert(self): 237 238 """Compute skew culvert. 239 If exchange lines are given, the enquiry points are determined. This is for enquiring 240 the total energy at both ends of the culvert and transferring flow. 241 """ 242 243 centre_point0 = 0.5*(self.exchange_lines[0][0] + self.exchange_lines[0][1]) 244 centre_point1 = 0.5*(self.exchange_lines[1][0] + self.exchange_lines[1][1]) 245 246 if self.end_points is None: 247 self.culvert_vector = centre_point1 - centre_point0 248 else: 249 self.culvert_vector = self.end_points[1] - end_points[0] 250 251 self.culvert_length = math.sqrt(num.sum(self.culvert_vector**2)) 252 assert self.culvert_length > 0.0, 'The length of culvert is less than 0' 253 254 if self.enquiry_points is None: 255 256 self.culvert_vector /= self.culvert_length 257 gap = (self.apron + self.enquiry_gap)*self.culvert_vector 258 259 self.enquiry_points = [] 260 261 self.enquiry_points.append(centre_point0 - gap) 262 self.enquiry_points.append(centre_point1 + gap) 263 264 241 265 def discharge_routine(self): 242 266 … … 269 293 message += '\n' 270 294 271 message += ' polyline\n'272 message += '%s' % inlet. polyline295 message += 'line\n' 296 message += '%s' % inlet.line 273 297 message += '\n' 274 298 -
trunk/anuga_core/source/anuga/structures/test_boyd_box_operator.py
r8036 r8056 26 26 27 27 28 def test_boyd_ 1(self):29 """test_boyd_ 128 def test_boyd_non_skew(self): 29 """test_boyd_non_skew 30 30 31 31 This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer BD Parkinson, … … 44 44 culvert_mannings = 0.013 45 45 46 culvert_apron = 0.0 0147 enquiry_gap = 1 .046 culvert_apron = 0.0 47 enquiry_gap = 10.0 48 48 49 49 expected_Q = 4.55 … … 56 56 domain_length = 200. #x-Dir 57 57 domain_width = 200. #y-dir 58 dx = dy = 10.0 # Resolution: Length of subdivisions on both axes58 dx = dy = 5.0 # Resolution: Length of subdivisions on both axes 59 59 60 60 … … 101 101 print 'Defining Structures' 102 102 103 ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0]) 104 ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0]) 105 106 103 107 culvert = Boyd_box_operator(domain, 104 label='3.6x3.6RCBC', 105 end_point0=[domain_length/2-culvert_length/2, 100.0], 106 end_point1=[domain_length/2+culvert_length/2, 100.0], 107 losses=culvert_losses, 108 width=culvert_width, 109 height=culvert_height, 110 apron=culvert_apron, 111 enquiry_gap=enquiry_gap, 112 use_momentum_jet=False, 113 use_velocity_head=False, 114 manning=culvert_mannings, 115 verbose=False) 116 108 losses=culvert_losses, 109 width=culvert_width, 110 end_points=[ep0, ep1], 111 height=culvert_height, 112 apron=culvert_apron, 113 enquiry_gap=enquiry_gap, 114 use_momentum_jet=False, 115 use_velocity_head=False, 116 manning=culvert_mannings, 117 label='3.6x3.6RCBC', 118 verbose=False) 117 119 118 120 culvert.determine_inflow_outflow() 119 121 120 122 ( Q, v, d ) = culvert.discharge_routine() 123 124 print 'test_boyd_non_skew' 125 print 'Q: ', Q, 'expected_Q: ', expected_Q 121 126 122 127 … … 125 130 assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v 126 131 132 133 def test_boyd_skew(self): 134 """test_boyd_skew 135 136 This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer BD Parkinson, 137 calculation code by MJ Boyd 138 """ 139 140 stage_0 = 11.0 141 stage_1 = 10.0 142 elevation_0 = 10.0 143 elevation_1 = 10.0 144 145 culvert_length = 20.0 146 culvert_width = 3.66 147 culvert_height = 3.66 148 culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0} 149 culvert_mannings = 0.013 150 151 culvert_apron = 0.0 152 enquiry_gap = 10.0 153 154 expected_Q = 4.55 155 expected_v = 2.3 156 expected_d = 0.54 157 158 159 # Probably no need to change below here 160 161 domain_length = 200. #x-Dir 162 domain_width = 200. #y-dir 163 dx = dy = 5.0 # Resolution: Length of subdivisions on both axes 164 165 166 points, vertices, boundary = rectangular_cross(int(domain_length/dx), int(domain_width/dy), 167 len1=domain_length, len2=domain_width) 168 domain = Domain(points, vertices, boundary) 169 domain.set_name('Test_Outlet_Inlet') # Output name 170 domain.set_default_order(2) 171 domain.H0 = 0.01 172 domain.tight_slope_limiters = 1 173 174 print 'Size', len(domain) 175 176 #------------------------------------------------------------------------------ 177 # Setup initial conditions 178 #------------------------------------------------------------------------------ 179 180 def elevation(x, y): 181 """Set up a elevation 182 """ 183 184 z = numpy.zeros(x.shape,dtype='d') 185 z[:] = elevation_0 186 187 numpy.putmask(z, x > domain_length/2, elevation_1) 188 189 return z 190 191 def stage(x,y): 192 """Set up stage 193 """ 194 z = numpy.zeros(x.shape,dtype='d') 195 z[:] = stage_0 196 197 numpy.putmask(z, x > domain_length/2, stage_1) 198 199 return z 200 201 print 'Setting Quantities....' 202 domain.set_quantity('elevation', elevation) # Use function for elevation 203 domain.set_quantity('stage', stage) # Use function for elevation 204 205 206 print 'Defining Structures' 207 208 a = domain_length/2 - culvert_length/2 209 b = domain_length/2 + culvert_length/2 210 211 el0 = numpy.array([[a, 100.0 - culvert_width/2], [a, 100.0 + culvert_width/2]]) 212 el1 = numpy.array([[b, 100.0 - culvert_width/2], [b, 100.0 + culvert_width/2]]) 213 214 culvert = Boyd_box_operator(domain, 215 losses=culvert_losses, 216 width=culvert_width, 217 exchange_lines=[el0, el1], 218 height=culvert_height, 219 apron=culvert_apron, 220 enquiry_gap=enquiry_gap, 221 use_momentum_jet=False, 222 use_velocity_head=False, 223 manning=culvert_mannings, 224 label='3.6x3.6RCBC', 225 verbose=False) 226 227 culvert.determine_inflow_outflow() 228 229 ( Q, v, d ) = culvert.discharge_routine() 230 231 print 'test_boyd_skew' 232 print 'Q: ', Q, 'expected_Q: ', expected_Q 233 234 assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow 235 assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity 236 assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v 237 238 239 def test_boyd_non_skew_enquiry_points(self): 240 """test_boyd_skew_enquiry_points 241 242 This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer BD Parkinson, 243 calculation code by MJ Boyd 244 """ 245 246 stage_0 = 11.0 247 stage_1 = 10.0 248 elevation_0 = 10.0 249 elevation_1 = 10.0 250 251 culvert_length = 20.0 252 culvert_width = 3.66 253 culvert_height = 3.66 254 culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0} 255 culvert_mannings = 0.013 256 257 culvert_apron = 0.0 258 enquiry_gap = 10.0 259 260 expected_Q = 4.55 261 expected_v = 2.3 262 expected_d = 0.54 263 264 265 # Probably no need to change below here 266 267 domain_length = 200. #x-Dir 268 domain_width = 200. #y-dir 269 dx = dy = 5.0 # Resolution: Length of subdivisions on both axes 270 271 272 points, vertices, boundary = rectangular_cross(int(domain_length/dx), int(domain_width/dy), 273 len1=domain_length, len2=domain_width) 274 domain = Domain(points, vertices, boundary) 275 domain.set_name('Test_Outlet_Inlet') # Output name 276 domain.set_default_order(2) 277 domain.H0 = 0.01 278 domain.tight_slope_limiters = 1 279 280 print 'Size', len(domain) 281 282 #------------------------------------------------------------------------------ 283 # Setup initial conditions 284 #------------------------------------------------------------------------------ 285 286 def elevation(x, y): 287 """Set up a elevation 288 """ 289 290 z = numpy.zeros(x.shape,dtype='d') 291 z[:] = elevation_0 292 293 numpy.putmask(z, x > domain_length/2, elevation_1) 294 295 return z 296 297 def stage(x,y): 298 """Set up stage 299 """ 300 z = numpy.zeros(x.shape,dtype='d') 301 z[:] = stage_0 302 303 numpy.putmask(z, x > domain_length/2, stage_1) 304 305 return z 306 307 print 'Setting Quantities....' 308 domain.set_quantity('elevation', elevation) # Use function for elevation 309 domain.set_quantity('stage', stage) # Use function for elevation 310 311 312 print 'Defining Structures' 313 314 a = domain_length/2 - culvert_length/2 315 b = domain_length/2 + culvert_length/2 316 317 el0 = numpy.array([[a, 100.0 - culvert_width/2], [a, 100.0 + culvert_width/2]]) 318 el1 = numpy.array([[b, 100.0 - culvert_width/2], [b, 100.0 + culvert_width/2]]) 319 320 enquiry_points = (numpy.array([85, 100]), numpy.array([115, 100])) 321 322 culvert = Boyd_box_operator(domain, 323 losses=culvert_losses, 324 width=culvert_width, 325 exchange_lines=[el0, el1], 326 enquiry_points=enquiry_points, 327 height=culvert_height, 328 apron=culvert_apron, 329 enquiry_gap=enquiry_gap, 330 use_momentum_jet=False, 331 use_velocity_head=False, 332 manning=culvert_mannings, 333 label='3.6x3.6RCBC', 334 verbose=False) 335 336 culvert.determine_inflow_outflow() 337 338 ( Q, v, d ) = culvert.discharge_routine() 339 340 print test_boyd_non_skew_enquiry_points 341 print 'Q: ', Q, 'expected_Q: ', expected_Q 342 343 assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow 344 assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity 345 assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v 346 127 347 128 348 # =========================================================================
Note: See TracChangeset
for help on using the changeset viewer.