Ignore:
Timestamp:
May 7, 2008, 4:01:52 PM (16 years ago)
Author:
ole
Message:

Implemeted and tested ticket:175 - flow_through_cross_section.
Also updated manual

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r5276 r5288  
    56215621        filename: Name of sww file
    56225622        polyline: Representation of desired cross section - it may contain multiple
    5623                   sections allowing for complex shapes.
     5623                  sections allowing for complex shapes. Assume absolute UTM coordinates.
     5624                  Format [[x0, y0], [x1, y1], ...]
    56245625
    56255626    Output:
    5626         time: All stored times
     5627        time: All stored times in sww file
    56275628        Q: Hydrograph of total flow across given segments for all stored times.
    56285629
    56295630    The normal flow is computed for each triangle intersected by the polyline and
    5630     added up.  multiple segments at different angles are specified the normal flows
     5631    added up.  Multiple segments at different angles are specified the normal flows
    56315632    may partially cancel each other.
    56325633
    5633     """
     5634    The typical usage of this function would be to get flow through a channel,
     5635    and the polyline would then be a cross section perpendicular to the flow.
     5636
     5637    """
     5638
     5639    from anuga.fit_interpolate.interpolate import Interpolation_function
     5640
     5641    quantity_names =['elevation',
     5642                     'stage',
     5643                     'xmomentum',
     5644                     'ymomentum']
    56345645
    56355646    # Get mesh and quantities from sww file
    56365647    X = get_mesh_and_quantities_from_file(filename,
    5637                                           quantities=['elevation',
    5638                                                       'stage',
    5639                                                       'xmomentum',
    5640                                                       'ymomentum'],
     5648                                          quantities=quantity_names,
    56415649                                          verbose=verbose)
    56425650    mesh, quantities, time = X
    56435651
    56445652
     5653    # Adjust polyline to mesh spatial origin
     5654    polyline = mesh.geo_reference.get_relative(polyline)
    56455655   
    56465656    # Find all intersections and associated triangles.
    5647    
    5648     mesh.get_intersecting_segments(polyline)
     5657    segments = mesh.get_intersecting_segments(polyline)
     5658    #print
     5659    #for x in segments:
     5660    #    print x
     5661
    56495662   
    56505663    # Then store for each triangle the length of the intersecting segment(s),
    5651     # right hand normal(s) and midpoints.
     5664    # right hand normal(s) and midpoints as interpolation_points.
     5665    interpolation_points = []
     5666    for segment in segments:
     5667        midpoint = sum(array(segment.segment))/2
     5668        interpolation_points.append(midpoint)
     5669
     5670
     5671    I = Interpolation_function(time,
     5672                               quantities,
     5673                               quantity_names=quantity_names,
     5674                               vertex_coordinates=mesh.nodes,
     5675                               triangles=mesh.triangles,
     5676                               interpolation_points=interpolation_points,
     5677                               verbose=verbose)
     5678
     5679    # Compute hydrograph
     5680    Q = []
     5681    for t in time:
     5682        total_flow=0
     5683        for i, p in enumerate(interpolation_points):
     5684            elevation, stage, uh, vh = I(t, point_id=i)
     5685            normal = segments[i].normal
     5686
     5687            # Inner product of momentum vector with segment normal [m^2/s]
     5688            normal_momentum = uh*normal[0] + vh*normal[1]
     5689
     5690            # Flow across this segment [m^3/s]
     5691            segment_flow = normal_momentum*segments[i].length
     5692
     5693            # Accumulate
     5694            total_flow += segment_flow
     5695             
     5696
     5697        # Store flow at this timestep   
     5698        Q.append(total_flow)
     5699   
     5700
    56525701
    56535702    return time, Q
Note: See TracChangeset for help on using the changeset viewer.