Ignore:
Timestamp:
Nov 16, 2004, 10:40:37 AM (20 years ago)
Author:
duncan
Message:

geting and setting values with a set of triangles - used with region tags

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/test_domain.py

    r486 r546  
    1212    if tag == "mound":
    1313        domain.test = "Mound"
    14        
    15 
    16 
     14
     15
     16def set_bottom_friction(tag, elements, domain):
     17    if tag == "bottom":
     18        #print 'bottom - indexes',elements
     19        domain.set_quantity('friction', 0.09, indexes = elements)
     20 
     21def set_top_friction(tag, elements, domain):
     22    if tag == "top":
     23        #print 'top - indexes',elements
     24        domain.set_quantity('friction', 1., indexes = elements)
     25       
     26 
     27def set_all_friction(tag, elements, domain):
     28    if tag == "all":
     29        new_values = domain.get_quantity('friction', indexes = elements) + 10.0
     30       
     31        domain.set_quantity('friction', new_values, indexes = elements)
     32                 
     33     
    1734class TestCase(unittest.TestCase):
    1835    def setUp(self):
     
    276293
    277294
    278     def testz_set_region(self):
     295    def test_set_region(self):
    279296        """Set quantities for sub region
    280297        """
     
    330347                        'set region failed')
    331348       
     349
     350
     351    def test_region_tags(self):
     352        """
     353        get values based on triangle lists.
     354        """
     355        from mesh_factory import rectangular
     356        from shallow_water import Domain
     357        from Numeric import zeros, Float
     358       
     359        #Create basic mesh
     360        points, vertices, boundary = rectangular(1, 3)
     361
     362        #Create shallow water domain
     363        domain = Domain(points, vertices, boundary)
     364        domain.build_tagged_elements_dictionary({'bottom':[0,1],
     365                                                 'top':[4,5],
     366                                                 'all':[0,1,2,3,4,5]})
     367
     368       
     369        #Set friction
     370        manning = 0.07
     371        domain.set_quantity('friction', manning)
     372
     373        domain.set_region([set_bottom_friction, set_top_friction])
     374        #print domain.quantities['friction'].get_values()
     375        assert allclose(domain.quantities['friction'].get_values(), [[ 0.09,  0.09,  0.09],
     376[ 0.09,  0.09,  0.09],
     377[ 0.07,  0.07,  0.07],
     378[ 0.07,  0.07,  0.07],
     379[ 1.0,  1.0,  1.0],
     380[ 1.0,  1.0,  1.0]])
     381       
     382        domain.set_region([set_all_friction])
     383        #print domain.quantities['friction'].get_values()
     384        assert allclose(domain.quantities['friction'].get_values(),
     385                        [[ 10.09, 10.09, 10.09],
     386                         [ 10.09, 10.09, 10.09],
     387                         [ 10.07, 10.07, 10.07],
     388                         [ 10.07, 10.07, 10.07],
     389                         [ 11.0,  11.0,  11.0],
     390                         [ 11.0,  11.0,  11.0]])
    332391#-------------------------------------------------------------
    333392if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.