Changeset 5717


Ignore:
Timestamp:
Aug 29, 2008, 4:40:31 PM (17 years ago)
Author:
duncan
Message:

adding a data check

Location:
anuga_core/source/anuga/pmesh
Files:
2 edited

Legend:

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

    r4888 r5717  
    55from Numeric import Float
    66from anuga.utilities.polygon import inside_polygon
     7
     8
    79
    810# This is due to pmesh being a package and a module and
     
    1517import exceptions
    1618class PolygonError(exceptions.Exception): pass
     19class SegmentError(exceptions.Exception): pass
    1720
    1821def create_mesh_from_regions(bounding_polygon,
     
    129132    See create_mesh_from_regions for documentation.
    130133    """
    131     #FIXME (OLE-DSG)
     134
     135   
    132136    # check the segment indexes - throw an error if they are out of bounds
    133     #(DSG) Yes!
     137    if boundary_tags is not None:
     138        max_segs = len(bounding_polygon)
     139        for key in boundary_tags.keys():
     140            if len([x for x in boundary_tags[key] if x > max_segs-1]) >= 1:
     141                msg = 'Boundary tag %s has segment out of bounds.'\
     142                      %(str(key))
     143                raise SegmentError, msg
     144
     145       
    134146
    135147   
    136148    #In addition I reckon the polygons could be of class Geospatial_data
    137149    #(DSG) If polygons were classes caching would break in places.
    138 
    139     # First check that interior polygons are fully contained in bounding
    140     # polygon
    141     #Note, Both poly's have the same geo_ref, therefore don't take into account
    142     # geo_ref
    143150
    144151    # Simple check
     
    149156
    150157    #
    151     if interior_regions is not None:       
    152         # Test that all the interior polygons are inside the bounding_poly
    153         # and throw out those that aren't fully included.
     158    if interior_regions is not None:
     159       
     160        # Test that all the interior polygons are inside the
     161        # bounding_poly and throw out those that aren't fully
     162        # included.  #Note, Both poly's have the same geo_ref,
     163        # therefore don't take into account # geo_ref
     164
    154165
    155166        polygons_inside_boundary = []
  • anuga_core/source/anuga/pmesh/test_mesh_interface.py

    r5638 r5717  
    930930        for t in domain.evolve(yieldstep, finaltime):   
    931931            domain.write_time()
     932
     933           
     934       
     935    def test_create_mesh_from_regions_check_segs(self):
     936        """Test that create_mesh_from_regions fails when an interior region is
     937         outside bounding polygon.       """
     938       
     939
     940        # These are the absolute values
     941        min_x = 10
     942        min_y = 88
     943        polygon = [[min_x,min_y],[1000,100],[1000,1000],[100,1000]]
     944       
     945        boundary_tags = {'walls':[0,1,3],'bom':[2]}
     946#        boundary_tags = {'walls':[0,1]}
     947        # This one is inside bounding polygon - should pass
     948        inner_polygon = [[800,400],[900,500],[800,600]]
     949
     950        interior_regions = [(inner_polygon, 5)]
     951        m = create_mesh_from_regions(polygon,
     952                                     boundary_tags,
     953                                     10000000,
     954                                     interior_regions=interior_regions)
     955
     956        boundary_tags = {'walls':[0,1,3,4],'bom':[2]}
     957       
     958        try:
     959            m = create_mesh_from_regions(polygon,
     960                                         boundary_tags,
     961                                         10000000,
     962                                         interior_regions=interior_regions)
     963        except:
     964            pass
     965        else:
     966            msg = 'segment out of bounds not caught '
     967            raise msg
     968
     969       
    932970#-------------------------------------------------------------
    933971if __name__ == "__main__":
    934972    suite = unittest.makeSuite(TestCase,'test')
    935     #suite = unittest.makeSuite(TestCase,'concept_ungenerateIII')
     973    #suite = unittest.makeSuite(TestCase,'test_create_mesh_from_regions_check_segs')
    936974    runner = unittest.TextTestRunner() #verbosity=2)
    937975    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.