source: anuga_core/source/anuga/culvert_flows/culvert_polygons.py @ 6126

Last change on this file since 6126 was 6121, checked in by ole, 15 years ago

Changed culvert polygons to compute enquiry points and verify that they are always outside exchange area.
Worked on volumetric conservation of culverts - not succeeding. Test is disabled.

File size: 3.8 KB
Line 
1"""Functions for geometries related to culvert flows
2"""
3
4# Import necessary modules
5from math import sqrt
6from Numeric import array, sum
7from anuga.utilities.polygon import inside_polygon, polygon_area
8
9def create_culvert_polygons(end_point0,
10                            end_point1, 
11                            width, height=None,
12                            enquiry_gap_factor=0.2,
13                            number_of_barrels=1):
14    """Create polygons at the end of a culvert inlet and outlet.
15    At either end two polygons will be created; one for the actual flow to pass through and one a little further away
16    for enquiring the total energy at both ends of the culvert and transferring flow.
17
18    Input (mandatory):
19        end_point0 - one end of the culvert (x,y)
20        end_point1 - other end of the culvert (x,y)       
21        width - culvert width
22
23    Input (optional):       
24        height - culvert height, defaults to width making a square culvert
25        enquiry_gap_factor - sets the distance to the enquiry point as fraction of the height
26        number_of_barrels - number of identical pipes.
27       
28    Output:
29
30        Dictionary of four polygons. The dictionary keys are:
31            'exchange_polygon0' - polygon defining the flow area at end_point0
32            'exchange_polygon1' - polygon defining the flow area at end_point1
33            'enquiry_point0' - point beyond exchange_polygon0
34            'enquiry_point1' - point beyond exchange_polygon1           
35            'vector'
36            'length'
37            'normal'
38    """   
39
40
41    # Input check
42    if height is None:
43        height = width
44
45    # Dictionary for calculated polygons
46    culvert_polygons = {}
47   
48
49    # Calculate geometry
50    x0, y0 = end_point0
51    x1, y1 = end_point1
52
53    dx = x1-x0
54    dy = y1-y0
55
56    vector = array([dx, dy])
57    length = sqrt(sum(vector**2))
58
59    # Adjust polygon width to number of barrels in this culvert
60    width *= number_of_barrels
61   
62   
63    # Unit direction vector and normal
64    vector /= length                 # Unit vector in culvert direction
65    normal = array([-dy, dx])/length # Normal vector
66   
67    culvert_polygons['vector'] = vector
68    culvert_polygons['length'] = length
69    culvert_polygons['normal'] = normal   
70
71    # Short hands
72    w = 0.5*width*normal # Perpendicular vector of 1/2 width
73    h = height*vector    # Vector of length=height in the
74                         # direction of the culvert
75    gap = (1 + enquiry_gap_factor)*h
76                         
77
78    # Build exchange polygon and enquiry point for opening 0
79    p0 = end_point0 + w
80    p1 = end_point0 - w
81    p2 = p1 - h
82    p3 = p0 - h
83    culvert_polygons['exchange_polygon0'] = array([p0,p1,p2,p3])
84    culvert_polygons['enquiry_point0'] = end_point0 - gap
85   
86
87    # Build exchange polygon and enquiry point for opening 1
88    p0 = end_point1 + w
89    p1 = end_point1 - w
90    p2 = p1 + h
91    p3 = p0 + h
92    culvert_polygons['exchange_polygon1'] = array([p0,p1,p2,p3])
93    culvert_polygons['enquiry_point1'] = end_point1 + gap 
94
95    # Check that enquiry polygons are outside exchange polygons
96    for key1 in ['exchange_polygon0',
97                 'exchange_polygon1']:
98        polygon = culvert_polygons[key1]
99        area = polygon_area(polygon)
100       
101        msg = 'Polygon %s ' %(polygon)
102        msg += ' has area = %f' % area
103        assert area > 0.0, msg
104
105        for key2 in ['enquiry_point0', 'enquiry_point1']:
106            point = culvert_polygons[key2]
107            msg = 'Enquiry point falls inside an enquiry point.'
108            msg += 'Email Ole.Nielsen@ga.gov.au'
109            assert not inside_polygon(point, polygon), msg
110
111    # Return results
112    return culvert_polygons
Note: See TracBrowser for help on using the repository browser.