Changeset 9591


Ignore:
Timestamp:
Feb 3, 2015, 4:27:32 PM (9 years ago)
Author:
steve
Message:

added extra unit test for setting hole_tags when using create_mesh_from_regions

Location:
trunk/anuga_core
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/anuga/abstract_2d_finite_volumes/tests/test_pmesh2domain.py

    r9562 r9591  
    2525
    2626    def test_pmesh2Domain(self):
    27          import os
    28          import tempfile
    29 
    30          fileName = tempfile.mktemp(".tsh")
    31          file = open(fileName,"w")
    32          file.write("4 3 # <vertex #> <x> <y> [attributes]\n \
     27        import os
     28        import tempfile
     29
     30        fileName = tempfile.mktemp(".tsh")
     31        fid = open(fileName, "w")
     32        fid.write("4 3 # <vertex #> <x> <y> [attributes]\n \
    33330 0.0 0.0 0.0 0.0 0.01 \n \
    34341 1.0 0.0 10.0 10.0 0.02  \n \
     
    6262140 \n \
    6363120 \n")
    64          file.close()
    65 
    66          tags = {}
    67          b1 =  Dirichlet_boundary(dirichlet_values = num.array([0.0]))
    68          b2 =  Dirichlet_boundary(dirichlet_values = num.array([1.0]))
    69          b3 =  Dirichlet_boundary(dirichlet_values = num.array([2.0]))
    70          tags["1"] = b1
    71          tags["2"] = b2
    72          tags["3"] = b3
    73 
    74          domain = pmesh_to_domain_instance(fileName, Domain)
    75          os.remove(fileName)
    76          #print "domain.tagged_elements", domain.tagged_elements
    77          ## check the quantities
    78          #print domain.quantities['elevation'].vertex_values
    79          answer = [[0., 8., 0.],
    80                    [0., 10., 8.]]
    81          assert num.allclose(domain.quantities['elevation'].vertex_values,
    82                              answer)
    83 
    84          #print domain.quantities['stage'].vertex_values
    85          answer = [[0., 12., 10.],
    86                    [0., 10., 12.]]
    87          assert num.allclose(domain.quantities['stage'].vertex_values,
    88                              answer)
    89 
    90          #print domain.quantities['friction'].vertex_values
    91          answer = [[0.01, 0.04, 0.03],
    92                    [0.01, 0.02, 0.04]]
    93          assert num.allclose(domain.quantities['friction'].vertex_values,
    94                              answer)
    95 
    96          #print domain.quantities['friction'].vertex_values
    97          tagged_elements = domain.get_tagged_elements()
    98          assert num.allclose(tagged_elements['dsg'][0],0)
    99          assert num.allclose(tagged_elements['ole nielsen'][0],1)
    100 
    101          self.assertTrue( domain.boundary[(1, 0)] == '1',
    102                           "test_tags_to_boundaries  failed. Single boundary wasn't added.")
    103          self.assertTrue( domain.boundary[(1, 2)] == '2',
    104                           "test_tags_to_boundaries  failed. Single boundary wasn't added.")
    105          self.assertTrue( domain.boundary[(0, 1)] == '3',
    106                           "test_tags_to_boundaries  failed. Single boundary wasn't added.")
    107          self.assertTrue( domain.boundary[(0, 0)] == 'exterior',
    108                           "test_tags_to_boundaries  failed. Single boundary wasn't added.")
    109          #print "domain.boundary",domain.boundary
    110          self.assertTrue( len(domain.boundary) == 4,
    111                           "test_pmesh2Domain Too many boundaries")
    112          #FIXME change to use get_xllcorner
    113          #print "d.geo_reference.xllcorner",domain.geo_reference.xllcorner
    114          self.assertTrue(domain.geo_reference.xllcorner == 140.0,
    115                           "bad geo_referece")
     64        fid.close()
     65
     66        tags = {}
     67        b1 = Dirichlet_boundary(dirichlet_values=num.array([0.0]))
     68        b2 = Dirichlet_boundary(dirichlet_values=num.array([1.0]))
     69        b3 = Dirichlet_boundary(dirichlet_values=num.array([2.0]))
     70        tags["1"] = b1
     71        tags["2"] = b2
     72        tags["3"] = b3
     73
     74        domain = pmesh_to_domain_instance(fileName, Domain)
     75        os.remove(fileName)
     76        # print "domain.tagged_elements", domain.tagged_elements
     77        # # check the quantities
     78        # print domain.quantities['elevation'].vertex_values
     79        answer = [[0., 8., 0.],
     80               [0., 10., 8.]]
     81        assert num.allclose(domain.quantities['elevation'].vertex_values,
     82                         answer)
     83
     84        # print domain.quantities['stage'].vertex_values
     85        answer = [[0., 12., 10.],
     86               [0., 10., 12.]]
     87        assert num.allclose(domain.quantities['stage'].vertex_values,
     88                         answer)
     89
     90        # print domain.quantities['friction'].vertex_values
     91        answer = [[0.01, 0.04, 0.03],
     92               [0.01, 0.02, 0.04]]
     93        assert num.allclose(domain.quantities['friction'].vertex_values,
     94                         answer)
     95
     96        # print domain.quantities['friction'].vertex_values
     97        tagged_elements = domain.get_tagged_elements()
     98        assert num.allclose(tagged_elements['dsg'][0], 0)
     99        assert num.allclose(tagged_elements['ole nielsen'][0], 1)
     100
     101        self.assertTrue(domain.boundary[(1, 0)] == '1',
     102                      "test_tags_to_boundaries  failed. Single boundary wasn't added.")
     103        self.assertTrue(domain.boundary[(1, 2)] == '2',
     104                      "test_tags_to_boundaries  failed. Single boundary wasn't added.")
     105        self.assertTrue(domain.boundary[(0, 1)] == '3',
     106                      "test_tags_to_boundaries  failed. Single boundary wasn't added.")
     107        self.assertTrue(domain.boundary[(0, 0)] == 'exterior',
     108                      "test_tags_to_boundaries  failed. Single boundary wasn't added.")
     109        # print "domain.boundary",domain.boundary
     110        self.assertTrue(len(domain.boundary) == 4,
     111                      "test_pmesh2Domain Too many boundaries")
     112        # FIXME change to use get_xllcorner
     113        # print "d.geo_reference.xllcorner",domain.geo_reference.xllcorner
     114        self.assertTrue(domain.geo_reference.xllcorner == 140.0,
     115                      "bad geo_referece")
    116116    #************
    117117   
    118118    def test_pmesh2Domain_instance(self):
    119          import os
    120          import tempfile
    121 
    122          fileName = tempfile.mktemp(".tsh")
    123          file = open(fileName,"w")
    124          file.write("4 3 # <vertex #> <x> <y> [attributes]\n \
     119        import os
     120        import tempfile
     121
     122        fileName = tempfile.mktemp(".tsh")
     123        fid = open(fileName, "w")
     124        fid.write("4 3 # <vertex #> <x> <y> [attributes]\n \
    1251250 0.0 0.0 0.0 0.0 0.01 \n \
    1261261 1.0 0.0 10.0 10.0 0.02  \n \
     
    154154140 \n \
    155155120 \n")
    156          file.close()
    157 
    158          mesh_instance = importMeshFromFile(fileName)
    159        
    160          tags = {}
    161          b1 =  Dirichlet_boundary(dirichlet_values = num.array([0.0]))
    162          b2 =  Dirichlet_boundary(dirichlet_values = num.array([1.0]))
    163          b3 =  Dirichlet_boundary(dirichlet_values = num.array([2.0]))
    164          tags["1"] = b1
    165          tags["2"] = b2
    166          tags["3"] = b3
    167 
    168          domain = pmesh_to_domain_instance(mesh_instance, Domain)
    169 
    170          os.remove(fileName)
    171          #print "domain.tagged_elements", domain.tagged_elements
    172          ## check the quantities
    173          #print domain.quantities['elevation'].vertex_values
    174          answer = [[0., 8., 0.],
    175                    [0., 10., 8.]]
    176          assert num.allclose(domain.quantities['elevation'].vertex_values,
    177                              answer)
    178 
    179          #print domain.quantities['stage'].vertex_values
    180          answer = [[0., 12., 10.],
    181                    [0., 10., 12.]]
    182          assert num.allclose(domain.quantities['stage'].vertex_values,
    183                              answer)
    184 
    185          #print domain.quantities['friction'].vertex_values
    186          answer = [[0.01, 0.04, 0.03],
    187                    [0.01, 0.02, 0.04]]
    188          assert num.allclose(domain.quantities['friction'].vertex_values,
    189                              answer)
    190 
    191          #print domain.quantities['friction'].vertex_values
    192          tagged_elements = domain.get_tagged_elements()         
    193          assert num.allclose(tagged_elements['dsg'][0],0)
    194          assert num.allclose(tagged_elements['ole nielsen'][0],1)
    195 
    196          self.assertTrue( domain.boundary[(1, 0)] == '1',
    197                           "test_tags_to_boundaries  failed. Single boundary wasn't added.")
    198          self.assertTrue( domain.boundary[(1, 2)] == '2',
    199                           "test_tags_to_boundaries  failed. Single boundary wasn't added.")
    200          self.assertTrue( domain.boundary[(0, 1)] == '3',
    201                           "test_tags_to_boundaries  failed. Single boundary wasn't added.")
    202          self.assertTrue( domain.boundary[(0, 0)] == 'exterior',
    203                           "test_tags_to_boundaries  failed. Single boundary wasn't added.")
    204          #print "domain.boundary",domain.boundary
    205          self.assertTrue( len(domain.boundary) == 4,
    206                           "test_pmesh2Domain Too many boundaries")
    207          #FIXME change to use get_xllcorner
    208          #print "d.geo_reference.xllcorner",domain.geo_reference.xllcorner
    209          self.assertTrue(domain.geo_reference.xllcorner == 140.0,
    210                           "bad geo_referece")
    211          
     156        fid.close()
     157
     158        mesh_instance = importMeshFromFile(fileName)
     159
     160        tags = {}
     161        b1 = Dirichlet_boundary(dirichlet_values=num.array([0.0]))
     162        b2 = Dirichlet_boundary(dirichlet_values=num.array([1.0]))
     163        b3 = Dirichlet_boundary(dirichlet_values=num.array([2.0]))
     164        tags["1"] = b1
     165        tags["2"] = b2
     166        tags["3"] = b3
     167
     168        domain = pmesh_to_domain_instance(mesh_instance, Domain)
     169
     170        os.remove(fileName)
     171        # print "domain.tagged_elements", domain.tagged_elements
     172        # # check the quantities
     173        # print domain.quantities['elevation'].vertex_values
     174        answer = [[0., 8., 0.],
     175               [0., 10., 8.]]
     176        assert num.allclose(domain.quantities['elevation'].vertex_values,
     177                         answer)
     178
     179        # print domain.quantities['stage'].vertex_values
     180        answer = [[0., 12., 10.],
     181               [0., 10., 12.]]
     182        assert num.allclose(domain.quantities['stage'].vertex_values,
     183                         answer)
     184
     185        # print domain.quantities['friction'].vertex_values
     186        answer = [[0.01, 0.04, 0.03],
     187               [0.01, 0.02, 0.04]]
     188        assert num.allclose(domain.quantities['friction'].vertex_values,
     189                         answer)
     190
     191        # print domain.quantities['friction'].vertex_values
     192        tagged_elements = domain.get_tagged_elements()         
     193        assert num.allclose(tagged_elements['dsg'][0], 0)
     194        assert num.allclose(tagged_elements['ole nielsen'][0], 1)
     195
     196        self.assertTrue(domain.boundary[(1, 0)] == '1',
     197                      "test_tags_to_boundaries  failed. Single boundary wasn't added.")
     198        self.assertTrue(domain.boundary[(1, 2)] == '2',
     199                      "test_tags_to_boundaries  failed. Single boundary wasn't added.")
     200        self.assertTrue(domain.boundary[(0, 1)] == '3',
     201                      "test_tags_to_boundaries  failed. Single boundary wasn't added.")
     202        self.assertTrue(domain.boundary[(0, 0)] == 'exterior',
     203                      "test_tags_to_boundaries  failed. Single boundary wasn't added.")
     204        # print "domain.boundary",domain.boundary
     205        self.assertTrue(len(domain.boundary) == 4,
     206                      "test_pmesh2Domain Too many boundaries")
     207        # FIXME change to use get_xllcorner
     208        # print "d.geo_reference.xllcorner",domain.geo_reference.xllcorner
     209        self.assertTrue(domain.geo_reference.xllcorner == 140.0,
     210                      "bad geo_referece")
     211
    212212
    213213
  • trunk/anuga_core/anuga/extras.py

    r9579 r9591  
    4040# Create domain from file
    4141#----------------------------
    42 def create_domain_from_file(file, DomainClass=Domain):
     42def create_domain_from_file(filename, DomainClass=Domain):
    4343    """
    4444    Create a domain from a file
    4545    """
    46     return pmesh_to_domain_instance(file,DomainClass=DomainClass)
     46    return pmesh_to_domain_instance(filename,DomainClass=DomainClass)
    4747
    4848#---------------------------
     
    8585    throw an error
    8686   
    87     interior_holes is a list of ploygons for each hole. These polygons do not
     87    interior_holes is a list of polygons for each hole. These polygons do not
    8888    need to be closed, but their points must be specified in a counter-clockwise
    8989    order.
  • trunk/anuga_core/anuga/pmesh/mesh.py

    r9551 r9591  
    803803        factor = 2* math.pi/segment_count
    804804        for cut in range(segment_count):
    805              cuts.append(cut*factor)
     805            cuts.append(cut*factor)
    806806
    807807        polygon = []
     
    971971        self.alphaUserSegments = []
    972972
    973        #FIXME see where this is used. return an array instead
     973    #FIXME see where this is used. return an array instead
    974974    def getTriangulation(self):
    975975        #return self.meshTriangles
  • trunk/anuga_core/anuga/pmesh/tests/test_mesh_interface.py

    r9562 r9591  
    636636           
    637637    def test_create_mesh_with_breaklines(self):
    638          # These are the absolute values
     638        # These are the absolute values
    639639        polygon = [[100,100], [1000,100], [1000,1000], [100,1000]]
    640640
     
    645645                                     10000000,
    646646                                     breaklines=[[[50,50],[2000,2000]]])
    647                                                                          
     647
    648648        self.assertTrue(len(m.regions) == 1, 'FAILED!')
    649649        segs = m.getUserSegments()
     
    653653
    654654    def test_create_mesh_with_interior_holes(self):
    655          # These are the absolute values
     655        # These are the absolute values
    656656        polygon = [[100,100], [1000,100], [1000,1000], [100,1000]]
    657657       
     
    714714            msg = 'Passing a single polygon should have raised an error '
    715715            raise Exception, msg
    716 
    717                
     716       
     717       
     718    def test_create_mesh_with_interior_holes_and_tags(self):
     719        # These are the absolute values
     720        polygon = [[100,100], [1000,100], [1000,1000], [100,1000]]
     721       
     722        interior_poly1 = [[101,101],[200,200], [101,200]]
     723        interior_poly2 = [[300,300],[500,500], [400,200]]
     724
     725        boundary_tags = {'walls': [0,1], 'bom': [2,3]}
     726
     727
     728        # This should work with one hole
     729        m = create_mesh_from_regions(polygon,
     730                                     boundary_tags,
     731                                     10000000,
     732                                     interior_holes=[interior_poly1],
     733                                     hole_tags=[{'edge0' : [0], 'edge1': [1], 'edge2': [2]}])
     734
     735        self.assertTrue(len(m.getUserSegments()) == 7, 'FAILED!')
     736        self.assertTrue(len(m.userVertices) == 7, 'FAILED!')
     737
     738        m.generate_mesh()
     739       
     740        tags_list = m.getMeshSegmentTags()
     741       
     742        assert len([x for x in tags_list if x == 'edge0']) == 7
     743        assert len([x for x in tags_list if x == 'edge1']) == 6
     744        assert len([x for x in tags_list if x == 'edge2']) == 54             
     745
     746
    718747    def test_create_mesh_from_regions_with_duplicate_verts(self):
    719748        # These are the absolute values
     
    799828
    800829    def concept_ungenerateII(self):
    801         from anuga.shallow_water import Domain, Reflective_boundary, \
    802                             Dirichlet_boundary
     830        from anuga import Domain, Reflective_boundary, Dirichlet_boundary
    803831
    804832        x=0
     
    869897
    870898    def concept_ungenerateIII(self):
    871         from anuga.shallow_water import Domain, Reflective_boundary, \
     899        from anuga import Domain, Reflective_boundary, \
    872900                            Dirichlet_boundary
    873901        from anuga.pmesh.mesh_interface import create_mesh_from_regions
Note: See TracChangeset for help on using the changeset viewer.