Ignore:
Timestamp:
Jan 7, 2009, 4:34:45 PM (15 years ago)
Author:
ole
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/culvert_flows/culvert_polygons.py

    r6098 r6121  
    55from math import sqrt
    66from Numeric import array, sum
     7from anuga.utilities.polygon import inside_polygon, polygon_area
    78
    89def create_culvert_polygons(end_point0,
    910                            end_point1,
    1011                            width, height=None,
    11                             enquiry_gap_factor=1.0,
    12                             enquiry_shape_factor=2.0,
     12                            enquiry_gap_factor=0.2,
    1313                            number_of_barrels=1):
    1414    """Create polygons at the end of a culvert inlet and outlet.
     
    2323    Input (optional):       
    2424        height - culvert height, defaults to width making a square culvert
    25         enquiry_gap_factor - sets the distance to the enquiry polygon
    26         enquiry_shape_factor - sets the shape of the enquiry polygon
    27                                (large value widens polygon but reduces height
    28                                to preserve same area as exchange polygon)
     25        enquiry_gap_factor - sets the distance to the enquiry point as fraction of the height
    2926        number_of_barrels - number of identical pipes.
    3027       
     
    3431            'exchange_polygon0' - polygon defining the flow area at end_point0
    3532            'exchange_polygon1' - polygon defining the flow area at end_point1
    36             'enquiry_polygon0' - polygon defining the enquiry field near end_point0
    37             'enquiry_polygon1' - polygon defining the enquiry field near end_point1           
     33            'enquiry_point0' - point beyond exchange_polygon0
     34            'enquiry_point1' - point beyond exchange_polygon1           
     35            'vector'
     36            'length'
     37            'normal'
    3838    """   
    3939
     
    6262   
    6363    # Unit direction vector and normal
    64     vector /= length
    65     normal = array([-dy, dx])/length
     64    vector /= length                 # Unit vector in culvert direction
     65    normal = array([-dy, dx])/length # Normal vector
    6666   
     67    culvert_polygons['vector'] = vector
     68    culvert_polygons['length'] = length
     69    culvert_polygons['normal'] = normal   
    6770
    6871    # Short hands
    6972    w = 0.5*width*normal # Perpendicular vector of 1/2 width
    70     h = height*vector  # Vector of length=height in the
    71                        # direction of the culvert
     73    h = height*vector    # Vector of length=height in the
     74                         # direction of the culvert
     75    gap = (1 + enquiry_gap_factor)*h
     76                         
    7277
    73     # Build exchange polygon 0
     78    # Build exchange polygon and enquiry point for opening 0
    7479    p0 = end_point0 + w
    7580    p1 = end_point0 - w
     
    7782    p3 = p0 - h
    7883    culvert_polygons['exchange_polygon0'] = array([p0,p1,p2,p3])
     84    culvert_polygons['enquiry_point0'] = end_point0 - gap
     85   
    7986
    80     # Build exchange polygon 1
     87    # Build exchange polygon and enquiry point for opening 1
    8188    p0 = end_point1 + w
    8289    p1 = end_point1 - w
     
    8491    p3 = p0 + h
    8592    culvert_polygons['exchange_polygon1'] = array([p0,p1,p2,p3])
     93    culvert_polygons['enquiry_point1'] = end_point1 + gap 
    8694
     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
    87104
    88 
    89     # Redefine shorthands for enquiry polygons
    90     w = w*enquiry_shape_factor
    91     h = h/enquiry_shape_factor
    92     gap = (enquiry_gap_factor + h)*vector
    93    
    94     # Build enquiry polygon 0
    95     p0 = end_point0 + w - gap
    96     p1 = end_point0 - w - gap
    97     p2 = p1 - h
    98     p3 = p0 - h
    99     culvert_polygons['enquiry_polygon0'] = array([p0,p1,p2,p3])
    100 
    101     # Build enquiry polygon 1
    102     p0 = end_point1 + w + gap
    103     p1 = end_point1 - w + gap
    104     p2 = p1 + h
    105     p3 = p0 + h
    106     culvert_polygons['enquiry_polygon1'] = array([p0,p1,p2,p3])   
     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
    107110
    108111    # Return results
    109     culvert_polygons['vector'] = vector
    110     culvert_polygons['length'] = length
    111     culvert_polygons['normal'] = normal   
    112112    return culvert_polygons
Note: See TracChangeset for help on using the changeset viewer.