Changeset 5726 for anuga_core/source/anuga/shallow_water/data_manager.py
- Timestamp:
- Sep 3, 2008, 4:44:23 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r5723 r5726 6466 6466 6467 6467 6468 def get_energy_through_cross_section(filename, 6469 polyline, 6470 kind = 'total', 6471 verbose=False): 6472 """Obtain flow (m^3/s) perpendicular to specified cross section. 6473 6474 Inputs: 6475 filename: Name of sww file 6476 polyline: Representation of desired cross section - it may contain 6477 multiple sections allowing for complex shapes. Assume 6478 absolute UTM coordinates. 6479 Format [[x0, y0], [x1, y1], ...] 6480 kind: Select which energy to compute. 6481 Options are 'specific' and 'total' (default) 6482 6483 Output: 6484 time: All stored times in sww file 6485 Q: Average energy [m] across given segments for all stored times. 6486 6487 The average velocity is computed for each triangle intersected by the polyline 6488 and averaged weigted by segment lengths. 6489 6490 The typical usage of this function would be to get average energy of flow in a channel, 6491 and the polyline would then be a cross section perpendicular to the flow. 6492 6493 6494 #FIXME (Ole) - need name for this energy reflecting that its dimension is [m]. 6495 """ 6496 6497 from anuga.config import g, epsilon, velocity_protection as h0 6498 6499 quantity_names =['elevation', 6500 'stage', 6501 'xmomentum', 6502 'ymomentum'] 6503 6504 6505 # Get values for quantities at each midpoint of poly line from sww file 6506 X = get_interpolated_quantities_at_polyline_midpoints(filename, 6507 quantity_names=quantity_names, 6508 polyline=polyline, 6509 verbose=verbose) 6510 segments, interpolation_function = X 6511 6512 6513 # Get vectors for time and interpolation_points 6514 time = interpolation_function.time 6515 interpolation_points = interpolation_function.interpolation_points 6516 6517 if verbose: print 'Computing %s energy' %kind 6518 6519 # Compute total length of polyline for use with weighted averages 6520 total_line_length = 0.0 6521 for segment in segments: 6522 total_line_length += segment.length 6523 6524 # Compute energy 6525 E = [] 6526 for t in time: 6527 average_energy=0.0 6528 for i, p in enumerate(interpolation_points): 6529 elevation, stage, uh, vh = interpolation_function(t, point_id=i) 6530 6531 # Depth 6532 h = depth = stage-elevation 6533 6534 # Average velocity across this segment 6535 if h > epsilon: 6536 # Use protection against degenerate velocities 6537 u = uh/(h + h0/h) 6538 v = vh/(h + h0/h) 6539 else: 6540 u = v = 0.0 6541 6542 speed_squared = u*u + v*v 6543 kinetic_energy = 0.5*speed_squared/g 6544 6545 if kind == 'specific': 6546 segment_energy = depth + kinetic_energy 6547 elif kind == 'total': 6548 segment_energy = stage + kinetic_energy 6549 else: 6550 msg = 'Energy kind must be either "specific" or "total".' 6551 msg += ' I got %s' %kind 6552 6553 6554 # Add to weighted average 6555 weigth = segments[i].length/total_line_length 6556 average_energy += segment_energy*weigth 6557 6558 6559 # Store energy at this timestep 6560 E.append(average_energy) 6561 6562 6563 return time, E 6564 6565 6468 6566 6469 6567
Note: See TracChangeset
for help on using the changeset viewer.