Changeset 5723


Ignore:
Timestamp:
Sep 3, 2008, 2:33:25 PM (16 years ago)
Author:
ole
Message:

Refactored get_flow_through_cross_section in preparation for
get_energy_through_cross_section. These function work only on sww files.
Runtime versions still need to be done.

Location:
anuga_core/source/anuga
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/fit_interpolate/interpolate.py

    r5657 r5723  
    721721                    if verbose is True:
    722722                        import sys
    723                         if sys.platform == 'win32':
     723                        if sys.platform == 'win32': # FIXME (Ole): Why only Windoze?
    724724                            from anuga.utilities.polygon import plot_polygons
    725725                            #out_interp_pts = take(interpolation_points,[indices])
    726726                            title = 'Interpolation points fall outside specified mesh'
    727                             plot_polygons([mesh_boundary_polygon,interpolation_points,out_interp_pts],
    728                                           ['line','point','outside'],figname='points_boundary_out',label=title,verbose=verbose)
     727                            plot_polygons([mesh_boundary_polygon,
     728                                           interpolation_points,
     729                                           out_interp_pts],
     730                                          ['line','point','outside'],
     731                                          figname='points_boundary_out',
     732                                          label=title,
     733                                          verbose=verbose)
    729734
    730735                    # Joaquim Luis suggested this as an Exception, so
     
    735740                        print msg
    736741                    #raise Exception(msg)
     742                   
    737743            elif triangles is None and vertex_coordinates is not None:#jj
    738744                #Dealing with sts file
     
    748754                    from anuga.utilities.polygon import plot_polygons
    749755                    title = 'Interpolation function: Polygon and interpolation points'
    750                     plot_polygons([mesh_boundary_polygon,interpolation_points],
    751                                          ['line','point'],figname='points_boundary',label=title,verbose=verbose)
     756                    plot_polygons([mesh_boundary_polygon,
     757                                   interpolation_points],
     758                                  ['line','point'],
     759                                  figname='points_boundary',
     760                                  label=title,
     761                                  verbose=verbose)
    752762
    753763            m = len(self.interpolation_points)
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r5661 r5723  
    62526252                                      quantities=None,
    62536253                                      verbose=False):
    6254     """Get and rebuild mesh structure and the associated quantities from sww file
    6255 
     6254    """Get and rebuild mesh structure and associated quantities from sww file
     6255   
    62566256    Input:
    62576257        filename - Name os sww file
     
    62636263        quantities - arrays with quantity values at each mesh node
    62646264        time - vector of stored timesteps
     6265       
     6266       
     6267    This function is used by e.g. get_interpolated_quantities_at_polyline_midpoints
    62656268    """
    62666269 
     
    63276330
    63286331
    6329 
    6330 def get_flow_through_cross_section(filename,
    6331                                    polyline,
    6332                                    verbose=False):
    6333     """Obtain flow (m^3/s) perpendicular to specified cross section.
    6334 
    6335     Inputs:
    6336         filename: Name of sww file
    6337         polyline: Representation of desired cross section - it may contain multiple
    6338                   sections allowing for complex shapes. Assume absolute UTM coordinates.
    6339                   Format [[x0, y0], [x1, y1], ...]
     6332   
     6333
     6334def get_interpolated_quantities_at_polyline_midpoints(filename,
     6335                                                      quantity_names=None,
     6336                                                      polyline=None,
     6337                                                      verbose=False):
     6338    """Get values for quantities interpolated to polyline midpoints from sww file
     6339   
     6340    Input:
     6341        filename - Name of sww file
     6342        quantity_names - Names of quantities to load
     6343        polyline: Representation of desired cross section - it may contain
     6344                  multiple sections allowing for complex shapes. Assume
     6345                  absolute UTM coordinates.
     6346                  Format [[x0, y0], [x1, y1], ...]             
    63406347
    63416348    Output:
    6342         time: All stored times in sww file
    6343         Q: Hydrograph of total flow across given segments for all stored times.
    6344 
    6345     The normal flow is computed for each triangle intersected by the polyline and
    6346     added up.  Multiple segments at different angles are specified the normal flows
    6347     may partially cancel each other.
    6348 
    6349     The typical usage of this function would be to get flow through a channel,
    6350     and the polyline would then be a cross section perpendicular to the flow.
    6351 
    6352     """
    6353 
     6349        segments: list of instances of class Triangle_intersection
     6350        interpolation_function: Instance of class Interpolation_function
     6351         
     6352         
     6353      This function is used by get_flow_through_cross_section and
     6354      get_energy_through_cross_section         
     6355    """
     6356   
    63546357    from anuga.fit_interpolate.interpolate import Interpolation_function
    6355 
    6356     quantity_names =['elevation',
    6357                      'stage',
    6358                      'xmomentum',
    6359                      'ymomentum']
    63606358
    63616359    # Get mesh and quantities from sww file
     
    63716369    # Find all intersections and associated triangles.
    63726370    segments = mesh.get_intersecting_segments(polyline, verbose=verbose)
    6373     #print
    6374     #for x in segments:
    6375     #    print x
    6376 
    6377    
     6371   
     6372       
    63786373    # Then store for each triangle the length of the intersecting segment(s),
    63796374    # right hand normal(s) and midpoints as interpolation_points.
     
    63886383        print 'total number of interpolation points = %d'\
    63896384              %len(interpolation_points)
    6390 
     6385             
     6386             
     6387   
    63916388    I = Interpolation_function(time,
    63926389                               quantities,
     
    63966393                               interpolation_points=interpolation_points,
    63976394                               verbose=verbose)
     6395                               
     6396    return segments, I
     6397   
     6398
     6399def get_flow_through_cross_section(filename,
     6400                                   polyline,
     6401                                   verbose=False):
     6402    """Obtain flow (m^3/s) perpendicular to specified cross section.
     6403
     6404    Inputs:
     6405        filename: Name of sww file
     6406        polyline: Representation of desired cross section - it may contain
     6407                  multiple sections allowing for complex shapes. Assume
     6408                  absolute UTM coordinates.
     6409                  Format [[x0, y0], [x1, y1], ...]
     6410
     6411    Output:
     6412        time: All stored times in sww file
     6413        Q: Hydrograph of total flow across given segments for all stored times.
     6414
     6415    The normal flow is computed for each triangle intersected by the polyline
     6416    and added up.  Multiple segments at different angles are specified the
     6417    normal flows may partially cancel each other.
     6418
     6419    The typical usage of this function would be to get flow through a channel,
     6420    and the polyline would then be a cross section perpendicular to the flow.
     6421
     6422    """
     6423
     6424    quantity_names =['elevation',
     6425                     'stage',
     6426                     'xmomentum',
     6427                     'ymomentum']
     6428
     6429
     6430    # Get values for quantities at each midpoint of poly line from sww file
     6431    X = get_interpolated_quantities_at_polyline_midpoints(filename,
     6432                                                          quantity_names=quantity_names,
     6433                                                          polyline=polyline,
     6434                                                          verbose=verbose)   
     6435    segments, interpolation_function = X
     6436
     6437   
     6438    # Get vectors for time and interpolation_points
     6439    time = interpolation_function.time
     6440    interpolation_points = interpolation_function.interpolation_points   
    63986441
    63996442    if verbose: print 'Computing hydrograph'
     
    64036446        total_flow=0
    64046447        for i, p in enumerate(interpolation_points):
    6405             elevation, stage, uh, vh = I(t, point_id=i)
     6448            elevation, stage, uh, vh = interpolation_function(t, point_id=i)
    64066449            normal = segments[i].normal
    64076450
     
    64186461        # Store flow at this timestep   
    64196462        Q.append(total_flow)
    6420    
    64216463
    64226464
Note: See TracChangeset for help on using the changeset viewer.