#!/usr/bin/env python import unittest from math import sqrt from domain import * from region import * #from config import epsilon from Numeric import allclose #, array, ones, Float def add_x_y(x, y): return x+y class TestCase(unittest.TestCase): def setUp(self): pass def tearDown(self): pass def test_region_tags(self): """ get values based on triangle lists. """ from mesh_factory import rectangular from shallow_water import Domain from Numeric import zeros, Float #Create basic mesh points, vertices, boundary = rectangular(1, 3) #Create shallow water domain domain = Domain(points, vertices, boundary) domain.build_tagged_elements_dictionary({'bottom':[0,1], 'top':[4,5], 'all':[0,1,2,3,4,5]}) #Set friction manning = 0.07 domain.set_quantity('friction', manning) a = Set_Region('bottom', 'friction', 0.09) b = Set_Region('top', 'friction', 1.0) domain.set_region([a, b]) #print domain.quantities['friction'].get_values() assert allclose(domain.quantities['friction'].get_values(), [[ 0.09, 0.09, 0.09], [ 0.09, 0.09, 0.09], [ 0.07, 0.07, 0.07], [ 0.07, 0.07, 0.07], [ 1.0, 1.0, 1.0], [ 1.0, 1.0, 1.0]]) #c = Add_Value_To_Region('all', 'friction', 10.0) domain.set_region(Add_Value_To_Region('all', 'friction', 10.0)) #print domain.quantities['friction'].get_values() assert allclose(domain.quantities['friction'].get_values(), [[ 10.09, 10.09, 10.09], [ 10.09, 10.09, 10.09], [ 10.07, 10.07, 10.07], [ 10.07, 10.07, 10.07], [ 11.0, 11.0, 11.0], [ 11.0, 11.0, 11.0]]) # trying a function domain.set_region(Set_Region('top', 'friction', add_x_y)) #print domain.quantities['friction'].get_values() assert allclose(domain.quantities['friction'].get_values(), [[ 10.09, 10.09, 10.09], [ 10.09, 10.09, 10.09], [ 10.07, 10.07, 10.07], [ 10.07, 10.07, 10.07], [ 5./3, 2.0, 2./3], [ 1.0, 2./3, 2.0]]) #------------------------------------------------------------- if __name__ == "__main__": suite = unittest.makeSuite(TestCase,'test') runner = unittest.TextTestRunner() runner.run(suite)