Changeset 7699


Ignore:
Timestamp:
Apr 28, 2010, 5:32:21 PM (15 years ago)
Author:
James Hudson
Message:

Added breaklines to high level interface for task 305.

Location:
anuga_core/source/anuga
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/pmesh/mesh_interface.py

    r7317 r7699  
    55import numpy as num
    66from anuga.utilities.polygon import inside_polygon
     7from anuga.utilities.polygon import polylist2points_verts
    78import anuga.utilities.log as log
    89
     
    2930                             minimum_triangle_angle=28.0,
    3031                             fail_if_polygons_outside=True,
     32                             breaklines=None,
    3133                             use_cache=False,
    3234                             verbose=True):
     
    6567    the lower left hand corner of  bounding_polygon (absolute)
    6668    as the x and y values for the geo_ref.
     69
     70    breaklines is a list of polygons. These lines will be preserved by the
     71               triangulation algorithm - useful for coastlines, walls, etc.
     72               The polygons are not closed.                       
    6773   
    6874    Returns the mesh instance if no filename is given
     
    9096              'minimum_triangle_angle': minimum_triangle_angle,
    9197              'fail_if_polygons_outside': fail_if_polygons_outside,
     98              'breaklines': breaklines,
    9299              'verbose': verbose}   # FIXME (Ole): Should be bypassed one day. See ticket:14
    93100
     
    124131                              minimum_triangle_angle=28.0,
    125132                              fail_if_polygons_outside=True,
     133                              breaklines=None,
    126134                              verbose=True):
    127135    """_create_mesh_from_regions - internal function.
     
    216224#    print 'check %s in production directory' %figname
    217225#    import sys; sys.exit()
    218    
    219226
    220227    if interior_holes is not None:       
     
    246253
    247254    m = Mesh(geo_reference=mesh_geo_reference)
     255
     256    # build a list of discrete segments from the breakline polygons
     257    if breaklines is not None:
     258        points, verts = polylist2points_verts(breaklines)
     259        m.add_points_and_segments(points, verts)
    248260
    249261    # Do bounding polygon
     
    303315
    304316
    305 
    306317    # NOTE (Ole): This was moved here as it is annoying if mesh is always
    307318    # stored irrespective of whether the computation
  • anuga_core/source/anuga/pmesh/test_mesh_interface.py

    r7276 r7699  
    249249        self.failUnless(m.geo_reference.get_zone()==zone, 'FAILED!')
    250250        self.failUnless(m.geo_reference.get_xllcorner()==min_x, 'FAILED!')
    251         self.failUnless(m.geo_reference.get_yllcorner()==min_y, 'FAILED!')
    252 
     251        self.failUnless(m.geo_reference.get_yllcorner()==min_y, 'FAILED!')             
     252               
    253253    def test_create_mesh_from_regions3(self):
    254254        # These are the absolute values
     
    636636            raise Exception, msg
    637637           
    638                    
    639 
    640 
     638    def test_create_mesh_with_breaklines(self):
     639         # These are the absolute values
     640        polygon = [[100,100], [1000,100], [1000,1000], [100,1000]]
     641
     642        boundary_tags = {'walls': [0,1], 'bom': [2,3]}
     643
     644        m = create_mesh_from_regions(polygon,
     645                                     boundary_tags,
     646                                     10000000,
     647                                     breaklines=[[[50,50],[2000,2000]]])
     648                                                                         
     649        self.failUnless(len(m.regions) == 1, 'FAILED!')
     650        segs = m.getUserSegments()
     651        self.failUnless(len(segs) == 5, 'FAILED!')
     652        self.failUnless(len(m.userVertices) == 6, 'FAILED!')
     653               
    641654    def test_create_mesh_from_regions_with_duplicate_verts(self):
    642655        # These are the absolute values
  • anuga_core/source/anuga/utilities/polygon.py

    r7690 r7699  
    13551355                              atol)
    13561356
     1357
    13571358    return interpolated_values
    13581359
     1360   
     1361def polylist2points_verts(polylist):
     1362    """ Convert a list of polygons to discrete points and vertices.
     1363    """
     1364   
     1365    offset = 0
     1366    points = []
     1367    vertices = []
     1368    for poly in polylist:
     1369        points.extend(poly)
     1370        vertices.extend([[i, i+1] for i in range(offset, offset+len(poly)-1)])
     1371        offset += len(poly)
     1372               
     1373    return points, vertices
    13591374##
    13601375# @brief
Note: See TracChangeset for help on using the changeset viewer.