Changeset 7350


Ignore:
Timestamp:
Aug 11, 2009, 8:00:45 AM (15 years ago)
Author:
steve
Message:

Introducing cross section class for culverts.

File:
1 edited

Legend:

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

    r7342 r7350  
    457457                   get_maximum_location(indices=wet_elements)
    458458
     459
     460
    459461    ##
    460462    # @brief Get the total flow through an arbitrary poly line.
     
    464466    # @note Assume absolute UTM coordinates.
    465467    def get_flow_through_cross_section(self, polyline, verbose=False):
     468        """Get the total flow through an arbitrary poly line.
     469
     470        This is a run-time equivalent of the function with same name
     471        in data_manager.py
     472
     473        Input:
     474            polyline: Representation of desired cross section - it may contain
     475                      multiple sections allowing for complex shapes. Assume
     476                      absolute UTM coordinates.
     477                      Format [[x0, y0], [x1, y1], ...]
     478
     479        Output:
     480            Q: Total flow [m^3/s] across given segments.
     481        """
     482
     483
     484        cross_section = Cross_section(self, polyline, verbose)
     485
     486        return cross_section.get_flow_through_cross_section()
     487
     488
     489
     490
     491
     492    ##
     493    # @brief Get the total flow through an arbitrary poly line.
     494    # @param polyline Representation of desired cross section.
     495    # @param verbose True if this method is to be verbose.
     496    # @note 'polyline' may contain multiple sections allowing complex shapes.
     497    # @note Assume absolute UTM coordinates.
     498    def old_get_flow_through_cross_section(self, polyline, verbose=False):
    466499        """Get the total flow through an arbitrary poly line.
    467500
     
    26662699
    26672700
     2701##
     2702# @brief A class for creating cross sections.
     2703# @note Inherits from General_forcing.
     2704class Cross_section:
     2705    """Class Cross_section - a class to setup a cross section from
     2706    which you can then calculate flow and energy through cross section
     2707
     2708
     2709    Cross_section(domain, polyline)
     2710
     2711    domain:
     2712    polyline: Representation of desired cross section - it may contain
     2713              multiple sections allowing for complex shapes. Assume
     2714              absolute UTM coordinates.
     2715              Format [[x0, y0], [x1, y1], ...]
     2716    verbose:
     2717    """
     2718
     2719    ##
     2720    # @brief Create an instance of the class.
     2721    # @param domain Domain of interest.
     2722    # @param polyline Polyline defining cross section
     2723    # @param verbose True if this instance is to be verbose.
     2724    def __init__(self,
     2725                 domain,
     2726                 polyline=None,
     2727                 verbose=False):
     2728       
     2729        self.domain = domain
     2730        self.polyline = polyline
     2731        self.verbose = verbose
     2732       
     2733        # Find all intersections and associated triangles.
     2734        self.segments = self.domain.get_intersecting_segments(self.polyline,
     2735                                                              use_cache=True,
     2736                                                              verbose=self.verbose)
     2737       
     2738        # Get midpoints
     2739        self.midpoints = segment_midpoints(self.segments)
     2740
     2741        # Make midpoints Geospatial instances
     2742        self.midpoints = ensure_geospatial(self.midpoints, self.domain.geo_reference)
     2743
     2744
     2745    ##
     2746    # @brief calculate current flow through cross section
     2747    def get_flow_through_cross_section(self):
     2748        """ Output: Total flow [m^3/s] across cross section.
     2749        """
     2750
     2751        # Get interpolated values
     2752        xmomentum = self.domain.get_quantity('xmomentum')
     2753        ymomentum = self.domain.get_quantity('ymomentum')
     2754
     2755        uh = xmomentum.get_values(interpolation_points=self.midpoints,
     2756                                  use_cache=True)
     2757        vh = ymomentum.get_values(interpolation_points=self.midpoints,
     2758                                  use_cache=True)
     2759
     2760        # Compute and sum flows across each segment
     2761        total_flow = 0
     2762        for i in range(len(uh)):
     2763            # Inner product of momentum vector with segment normal [m^2/s]
     2764            normal = self.segments[i].normal
     2765            normal_momentum = uh[i]*normal[0] + vh[i]*normal[1]
     2766
     2767            # Flow across this segment [m^3/s]
     2768            segment_flow = normal_momentum*self.segments[i].length
     2769
     2770            # Accumulate
     2771            total_flow += segment_flow
     2772
     2773        return total_flow
     2774 
     2775
     2776
     2777
    26682778################################################################################
    26692779# Initialise module
Note: See TracChangeset for help on using the changeset viewer.