Changeset 7737
- Timestamp:
- May 24, 2010, 1:24:33 PM (15 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 15 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/generic_domain.py
r7734 r7737 18 18 import ( Boundary, File_boundary, AWI_boundary, 19 19 Dirichlet_boundary, Time_boundary, Transmissive_boundary ) 20 from anuga.abstract_2d_finite_volumes.pmesh2domain import pmesh_to_domain 21 from anuga.abstract_2d_finite_volumes.region \ 22 import Set_region as region_set_region 20 from pmesh2domain import pmesh_to_domain 21 from region import Set_region as region_set_region 23 22 from anuga.geometry.polygon import inside_polygon 24 23 from anuga.abstract_2d_finite_volumes.util import get_textual_float … … 31 30 ## 32 31 # @brief Generic Domain class 33 class Domain:32 class Generic_Domain: 34 33 35 34 ## … … 2048 2047 'you may want to consider installing it') 2049 2048 else: 2050 psyco.bind( Domain.update_boundary)2049 psyco.bind(Generic_Domain.update_boundary) 2051 2050 #psyco.bind(Domain.update_timestep) # Not worth it 2052 psyco.bind( Domain.update_conserved_quantities)2053 psyco.bind( Domain.distribute_to_vertices_and_edges)2051 psyco.bind(Generic_Domain.update_conserved_quantities) 2052 psyco.bind(Generic_Domain.distribute_to_vertices_and_edges) 2054 2053 2055 2054 -
anuga_core/source/anuga/abstract_2d_finite_volumes/pmesh2domain.py
r7276 r7737 11 11 12 12 13 ##14 # @brief Convert a pmesh instance to a domain instance.15 # @param mesh The pmesh instance to convert.16 # @param DomainClass The class to instantiate and return.17 # @return The converted pmesh instance (as a 'DomainClass' instance).18 def pmesh_instance_to_domain_instance(mesh, DomainClass):19 """Convert a pmesh instance/object into a domain instance.20 21 Uses pmesh_to_domain_instance to convert a mesh file to a domain instance.22 """23 24 (vertex_coordinates, vertices, tag_dict, vertex_quantity_dict,25 tagged_elements_dict, geo_reference) = pmesh_to_domain(mesh_instance=mesh)26 27 # NOTE(Ole): This import cannot be at the module level28 # due to mutual dependency with domain.py29 from anuga.abstract_2d_finite_volumes.domain import Domain30 31 # ensure that the required 'DomainClass' actually is an instance of Domain32 msg = ('The class %s is not a subclass of the generic domain class %s'33 % (DomainClass, Domain))34 assert issubclass(DomainClass, Domain), msg35 36 # instantiate the result class37 result = DomainClass(coordinates=vertex_coordinates,38 vertices=vertices,39 boundary=tag_dict,40 tagged_elements=tagged_elements_dict,41 geo_reference=geo_reference)42 43 # set the water stage to be the elevation44 if (vertex_quantity_dict.has_key('elevation') and45 not vertex_quantity_dict.has_key('stage')):46 vertex_quantity_dict['stage'] = vertex_quantity_dict['elevation']47 result.set_quantity_vertices_dict(vertex_quantity_dict)48 49 return result50 51 13 52 14 ## 53 15 # @brief Convert a mesh file to a Domain instance. 54 # @param file_name Name of the file to convert (TSH or MSH).16 # @param source Name of the file to convert (TSH or MSH), or a mesh. 55 17 # @param DomainClass Class of return instance. 56 18 # @param use_cache True if caching is to be used. 57 19 # @param verbose True if this function is to be verbose. 58 20 # @return An instance of 'DomainClass' containing the file data. 59 def pmesh_to_domain_instance( file_name, DomainClass, use_cache=False,21 def pmesh_to_domain_instance(source, DomainClass, use_cache=False, 60 22 verbose=False): 61 23 """Converts a mesh file(.tsh or .msh), to a Domain instance. … … 71 33 if use_cache is True: 72 34 from caching import cache 73 result = cache(_pmesh_to_domain_instance, ( file_name, DomainClass),35 result = cache(_pmesh_to_domain_instance, (source, DomainClass), 74 36 dependencies=[file_name], verbose=verbose) 75 37 else: 76 result = apply(_pmesh_to_domain_instance, ( file_name, DomainClass))38 result = apply(_pmesh_to_domain_instance, (source, DomainClass)) 77 39 78 40 return result … … 84 46 # @param DomainClass Class of return instance. 85 47 # @return The DomainClass instance containing the file data. 86 def _pmesh_to_domain_instance( file_name, DomainClass):48 def _pmesh_to_domain_instance(source, DomainClass): 87 49 """Converts a mesh file(.tsh or .msh), to a Domain instance. 88 50 89 51 Internal function. See public interface pmesh_to_domain_instance for details 90 52 """ 91 92 (vertex_coordinates, vertices, tag_dict, vertex_quantity_dict, 93 tagged_elements_dict, geo_reference) = pmesh_to_domain(file_name=file_name) 94 95 # NOTE(Ole): This import cannot be at the module level due to mutual 96 # dependency with domain.py 97 from anuga.abstract_2d_finite_volumes.domain import Domain 53 54 from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain 98 55 99 56 # ensure the required class is a subclass of Domain 100 57 msg = ('The class %s is not a subclass of the generic domain class %s' 101 % (DomainClass, Domain)) 102 assert issubclass(DomainClass, Domain), msg 58 % (DomainClass, Generic_Domain)) 59 assert issubclass(DomainClass, Generic_Domain), msg 60 61 if type(source).__name__ == 'str': 62 parm = {'file_name': source} 63 else: 64 parm = {'mesh_instance': source} 65 66 (vertex_coordinates, vertices, tag_dict, vertex_quantity_dict, 67 tagged_elements_dict, geo_reference) = pmesh_to_domain(**parm) 103 68 104 69 domain = DomainClass(coordinates = vertex_coordinates, -
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r7711 r7737 40 40 # @param vertex_values ?? 41 41 def __init__(self, domain, vertex_values=None): 42 from anuga.abstract_2d_finite_volumes.domain import Domain 43 44 msg = ('First argument in Quantity.__init__() must be of class Domain ' 45 '(or a subclass thereof). I got %s.' % str(domain.__class__)) 46 assert isinstance(domain, Domain), msg 42 from anuga.abstract_2d_finite_volumes.generic_domain \ 43 import Generic_Domain 44 45 msg = ('First argument in Quantity.__init__() must be of class %s ' 46 '(or a subclass thereof). I got %s.' 47 % (str(Generic_Domain.__name__),str(domain.__class__))) 48 assert isinstance(domain, Generic_Domain), msg 47 49 48 50 if vertex_values is None: -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py
r7725 r7737 4 4 from math import sqrt 5 5 6 from anuga.abstract_2d_finite_volumes. domain import *6 from anuga.abstract_2d_finite_volumes.generic_domain import * 7 7 from anuga.pmesh.mesh_interface import create_mesh_from_regions 8 8 from anuga.config import epsilon … … 18 18 19 19 20 def set_bottom_friction(tag, elements, domain):21 if tag == "bottom":22 domain.set_quantity('friction', 0.09, indices = elements)23 24 def set_top_friction(tag, elements, domain):25 if tag == "top":26 domain.set_quantity('friction', 1., indices = elements)27 28 29 def set_all_friction(tag, elements, domain):30 if tag == 'all':31 new_values = domain.get_quantity('friction').get_values(indices = elements) + 10.032 33 domain.set_quantity('friction', new_values, indices = elements)34 35 20 36 21 class Test_Domain(unittest.TestCase): … … 60 45 other_quantities = ['elevation', 'friction'] 61 46 62 domain = Domain(points, vertices, None,47 domain = Generic_Domain(points, vertices, None, 63 48 conserved_quantities, evolved_quantities, other_quantities) 64 49 domain.check_integrity() … … 89 74 other_quantities = ['elevation', 'friction'] 90 75 91 domain = Domain(points, vertices, None,76 domain = Generic_Domain(points, vertices, None, 92 77 conserved_quantities, evolved_quantities, other_quantities) 93 78 … … 126 111 vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]] 127 112 128 domain = Domain(points, vertices, boundary=None,113 domain = Generic_Domain(points, vertices, boundary=None, 129 114 conserved_quantities =\ 130 115 ['stage', 'xmomentum', 'ymomentum']) … … 200 185 vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]] 201 186 202 domain = Domain(points, vertices, boundary=None,187 domain = Generic_Domain(points, vertices, boundary=None, 203 188 conserved_quantities =\ 204 189 ['stage', 'xmomentum', 'ymomentum'], … … 254 239 255 240 256 domain = Domain(points, vertices, boundary=None,241 domain = Generic_Domain(points, vertices, boundary=None, 257 242 conserved_quantities =\ 258 243 ['stage', 'xmomentum', 'ymomentum'], … … 330 315 vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]] 331 316 332 domain = Domain(points, vertices, boundary=None,317 domain = Generic_Domain(points, vertices, boundary=None, 333 318 conserved_quantities =\ 334 319 ['stage', 'xmomentum', 'ymomentum'], … … 384 369 vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]] 385 370 386 domain = Domain(points, vertices, boundary=None,371 domain = Generic_Domain(points, vertices, boundary=None, 387 372 conserved_quantities =\ 388 373 ['stage', 'xmomentum', 'ymomentum'], … … 453 438 454 439 455 domain = Domain(points, vertices, boundary=None,440 domain = Generic_Domain(points, vertices, boundary=None, 456 441 conserved_quantities =\ 457 442 ['stage', 'xmomentum', 'ymomentum'], … … 497 482 points = [a, b, c] 498 483 vertices = [ [0,1,2] ] 499 domain = Domain(points, vertices)484 domain = Generic_Domain(points, vertices) 500 485 501 486 domain.set_boundary( {default_boundary_tag: Dirichlet_boundary([5,2,1])} ) … … 528 513 529 514 530 domain = Domain(points, vertices, boundary,515 domain = Generic_Domain(points, vertices, boundary, 531 516 conserved_quantities =\ 532 517 ['stage', 'xmomentum', 'ymomentum']) … … 584 569 585 570 try: 586 domain = Domain(points, vertices, boundary,571 domain = Generic_Domain(points, vertices, boundary, 587 572 conserved_quantities = ['stage', 'xmomentum', 'ymomentum'], 588 573 evolved_quantities =\ … … 595 580 596 581 597 domain = Domain(points, vertices, boundary,582 domain = Generic_Domain(points, vertices, boundary, 598 583 conserved_quantities = ['stage', 'xmomentum', 'ymomentum'], 599 584 evolved_quantities =\ … … 688 673 689 674 690 domain = Domain(points, vertices, boundary,675 domain = Generic_Domain(points, vertices, boundary, 691 676 conserved_quantities =\ 692 677 ['stage', 'xmomentum', 'ymomentum']) … … 739 724 740 725 741 domain = Domain(points, vertices, boundary,726 domain = Generic_Domain(points, vertices, boundary, 742 727 conserved_quantities =\ 743 728 ['stage', 'xmomentum', 'ymomentum']) … … 799 784 (3, 2): 'Third'} 800 785 801 domain = Domain(points, vertices, boundary,786 domain = Generic_Domain(points, vertices, boundary, 802 787 conserved_quantities =\ 803 788 ['stage', 'xmomentum', 'ymomentum']) … … 833 818 'set region failed') 834 819 835 836 def test_track_speeds(self):837 """838 get values based on triangle lists.839 """840 from mesh_factory import rectangular841 from shallow_water import Domain842 843 #Create basic mesh844 points, vertices, boundary = rectangular(1, 3)845 846 #Create shallow water domain847 domain = Domain(points, vertices, boundary)848 domain.timestepping_statistics(track_speeds=True)849 850 851 852 def test_region_tags(self):853 """854 get values based on triangle lists.855 """856 from mesh_factory import rectangular857 from shallow_water import Domain858 859 #Create basic mesh860 points, vertices, boundary = rectangular(1, 3)861 862 #Create shallow water domain863 domain = Domain(points, vertices, boundary)864 domain.build_tagged_elements_dictionary({'bottom':[0,1],865 'top':[4,5],866 'all':[0,1,2,3,4,5]})867 868 869 #Set friction870 manning = 0.07871 domain.set_quantity('friction', manning)872 873 domain.set_region([set_bottom_friction, set_top_friction])874 assert num.allclose(domain.quantities['friction'].get_values(),\875 [[ 0.09, 0.09, 0.09],876 [ 0.09, 0.09, 0.09],877 [ 0.07, 0.07, 0.07],878 [ 0.07, 0.07, 0.07],879 [ 1.0, 1.0, 1.0],880 [ 1.0, 1.0, 1.0]])881 882 domain.set_region([set_all_friction])883 assert num.allclose(domain.quantities['friction'].get_values(),884 [[ 10.09, 10.09, 10.09],885 [ 10.09, 10.09, 10.09],886 [ 10.07, 10.07, 10.07],887 [ 10.07, 10.07, 10.07],888 [ 11.0, 11.0, 11.0],889 [ 11.0, 11.0, 11.0]])890 891 892 def test_region_tags2(self):893 """894 get values based on triangle lists.895 """896 from mesh_factory import rectangular897 from shallow_water import Domain898 899 #Create basic mesh900 points, vertices, boundary = rectangular(1, 3)901 902 #Create shallow water domain903 domain = Domain(points, vertices, boundary)904 domain.build_tagged_elements_dictionary({'bottom':[0,1],905 'top':[4,5],906 'all':[0,1,2,3,4,5]})907 908 909 #Set friction910 manning = 0.07911 domain.set_quantity('friction', manning)912 913 domain.set_region('top', 'friction', 1.0)914 domain.set_region('bottom', 'friction', 0.09)915 916 msg = ("domain.quantities['friction'].get_values()=\n%s\n"917 'should equal\n'918 '[[ 0.09, 0.09, 0.09],\n'919 ' [ 0.09, 0.09, 0.09],\n'920 ' [ 0.07, 0.07, 0.07],\n'921 ' [ 0.07, 0.07, 0.07],\n'922 ' [ 1.0, 1.0, 1.0],\n'923 ' [ 1.0, 1.0, 1.0]]'924 % str(domain.quantities['friction'].get_values()))925 assert num.allclose(domain.quantities['friction'].get_values(),926 [[ 0.09, 0.09, 0.09],927 [ 0.09, 0.09, 0.09],928 [ 0.07, 0.07, 0.07],929 [ 0.07, 0.07, 0.07],930 [ 1.0, 1.0, 1.0],931 [ 1.0, 1.0, 1.0]]), msg932 933 domain.set_region([set_bottom_friction, set_top_friction])934 assert num.allclose(domain.quantities['friction'].get_values(),935 [[ 0.09, 0.09, 0.09],936 [ 0.09, 0.09, 0.09],937 [ 0.07, 0.07, 0.07],938 [ 0.07, 0.07, 0.07],939 [ 1.0, 1.0, 1.0],940 [ 1.0, 1.0, 1.0]])941 942 domain.set_region([set_all_friction])943 assert num.allclose(domain.quantities['friction'].get_values(),944 [[ 10.09, 10.09, 10.09],945 [ 10.09, 10.09, 10.09],946 [ 10.07, 10.07, 10.07],947 [ 10.07, 10.07, 10.07],948 [ 11.0, 11.0, 11.0],949 [ 11.0, 11.0, 11.0]])950 820 951 821 def test_rectangular_periodic_and_ghosts(self): … … 962 832 963 833 conserved_quantities = ['quant1', 'quant2'] 964 domain = Domain(points, vertices, boundary, conserved_quantities,834 domain = Generic_Domain(points, vertices, boundary, conserved_quantities, 965 835 full_send_dict=full_send_dict, 966 836 ghost_recv_dict=ghost_recv_dict) -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_generic_boundary_conditions.py
r7735 r7737 5 5 6 6 from generic_boundary_conditions import * 7 from anuga.abstract_2d_finite_volumes. domain importDomain7 from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain 8 8 from anuga.config import epsilon 9 9 … … 64 64 elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ] 65 65 66 domain = Domain(points, elements)66 domain = Generic_Domain(points, elements) 67 67 domain.check_integrity() 68 68 … … 130 130 elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ] 131 131 132 domain = Domain(points, elements)132 domain = Generic_Domain(points, elements) 133 133 domain.check_integrity() 134 134 … … 202 202 elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ] 203 203 204 domain = Domain(points, elements)204 domain = Generic_Domain(points, elements) 205 205 domain.check_integrity() 206 206 … … 281 281 elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ] 282 282 283 domain = Domain(points, elements)283 domain = Generic_Domain(points, elements) 284 284 domain.conserved_quantities = ['stage', 'ymomentum'] 285 285 domain.quantities['stage'] =\ … … 374 374 elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ] 375 375 376 domain = Domain(points, elements)376 domain = Generic_Domain(points, elements) 377 377 domain.conserved_quantities = ['stage', 'xmomentum', 'ymomentum'] 378 378 domain.evolved_quantities = ['stage', 'xmomentum', 'ymomentum'] -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_ghost.py
r7519 r7737 4 4 from math import sqrt 5 5 6 from anuga.abstract_2d_finite_volumes. domain import *6 from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain 7 7 from anuga.config import epsilon 8 8 … … 34 34 other_quantities = ['elevation', 'friction'] 35 35 36 domain = Domain(points, vertices, None,36 domain = Generic_Domain(points, vertices, None, 37 37 conserved_quantities, None, other_quantities) 38 38 domain.check_integrity() -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_pmesh2domain.py
r7276 r7737 4 4 import unittest 5 5 6 #from anuga.pyvolution.pmesh2domain import *7 6 from pmesh2domain import * 8 7 9 from anuga.shallow_water import Domain,\10 Reflective_boundary, Dirichlet_boundary,\11 Transmissive_boundary8 from anuga.shallow_water.shallow_water_domain import Domain 9 from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \ 10 import Dirichlet_boundary 12 11 13 12 from anuga.coordinate_transforms.geo_reference import Geo_reference … … 167 166 tags["3"] = b3 168 167 169 domain = pmesh_ instance_to_domain_instance(mesh_instance, Domain)168 domain = pmesh_to_domain_instance(mesh_instance, Domain) 170 169 171 170 os.remove(fileName) -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
r7711 r7737 10 10 from anuga.fit_interpolate.fit import fit_to_mesh 11 11 #from anuga.pyvolution.least_squares import fit_to_mesh 12 from anuga.abstract_2d_finite_volumes.domain import Domain 12 from anuga.abstract_2d_finite_volumes.generic_domain \ 13 import Generic_Domain 13 14 from anuga.geospatial_data.geospatial_data import Geospatial_data 14 15 from anuga.coordinate_transforms.geo_reference import Geo_reference … … 39 40 elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ] 40 41 41 self.mesh1 = Domain(points[:3], [elements[0]])42 self.mesh1 = Generic_Domain(points[:3], [elements[0]]) 42 43 self.mesh1.check_integrity() 43 44 … … 45 46 #print isinstance(self.mesh1, Domain) 46 47 47 self.mesh4 = Domain(points, elements)48 self.mesh4 = Generic_Domain(points, elements) 48 49 self.mesh4.check_integrity() 49 50 … … 56 57 elements = [[0,2,1]] 57 58 58 self.mesh_onslow = Domain(points, elements)59 self.mesh_onslow = Generic_Domain(points, elements) 59 60 self.mesh_onslow.check_integrity() 60 61 … … 174 175 vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] 175 176 176 domain = Domain(points, vertices)177 domain = Generic_Domain(points, vertices) 177 178 178 179 quantity = Quantity(domain) … … 575 576 576 577 mesh_georef = Geo_reference(56,-0.76,-0.76) 577 mesh1 = Domain(vertex_coordinates, triangles,578 mesh1 = Generic_Domain(vertex_coordinates, triangles, 578 579 geo_reference = mesh_georef) 579 580 mesh1.check_integrity() … … 1087 1088 1088 1089 #absolute going in .. 1089 mesh4 = Domain(points, elements,1090 mesh4 = Generic_Domain(points, elements, 1090 1091 geo_reference = Geo_reference(56, 0, 0)) 1091 1092 mesh4.check_integrity() … … 1167 1168 elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ] 1168 1169 1169 mesh4 = Domain(points, elements,1170 mesh4 = Generic_Domain(points, elements, 1170 1171 geo_reference = Geo_reference(56, x0, y0)) 1171 1172 mesh4.check_integrity() … … 1875 1876 1876 1877 1877 1878 #Test smoothing 1879 def test_smoothing(self): 1878 def set_array_values_by_index(self): 1880 1879 1881 1880 from mesh_factory import rectangular 1882 from shallow_water import Domain, Transmissive_boundary1883 from anuga.utilities.numerical_tools import mean1884 1885 #Create basic mesh1886 points, vertices, boundary = rectangular(2, 2)1887 1888 #Create shallow water domain1889 domain = Domain(points, vertices, boundary)1890 domain.default_order=21891 domain.reduction = mean1892 1893 1894 #Set some field values1895 domain.set_quantity('elevation', lambda x,y: x)1896 domain.set_quantity('friction', 0.03)1897 1898 1899 ######################1900 # Boundary conditions1901 B = Transmissive_boundary(domain)1902 domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B})1903 1904 1905 ######################1906 #Initial condition - with jumps1907 1908 bed = domain.quantities['elevation'].vertex_values1909 stage = num.zeros(bed.shape, num.float)1910 1911 h = 0.031912 for i in range(stage.shape[0]):1913 if i % 2 == 0:1914 stage[i,:] = bed[i,:] + h1915 else:1916 stage[i,:] = bed[i,:]1917 1918 domain.set_quantity('stage', stage)1919 1920 stage = domain.quantities['stage']1921 1922 #Get smoothed stage1923 A, V = stage.get_vertex_values(xy=False, smooth=True)1924 Q = stage.vertex_values1925 1926 1927 assert A.shape[0] == 91928 assert V.shape[0] == 81929 assert V.shape[1] == 31930 1931 #First four points1932 assert num.allclose(A[0], (Q[0,2] + Q[1,1])/2)1933 assert num.allclose(A[1], (Q[1,0] + Q[3,1] + Q[2,2])/3)1934 assert num.allclose(A[2], Q[3,0])1935 assert num.allclose(A[3], (Q[0,0] + Q[5,1] + Q[4,2])/3)1936 1937 #Center point1938 assert num.allclose(A[4], (Q[0,1] + Q[1,2] + Q[2,0] +\1939 Q[5,0] + Q[6,2] + Q[7,1])/6)1940 1941 1942 #Check V1943 assert num.allclose(V[0,:], [3,4,0])1944 assert num.allclose(V[1,:], [1,0,4])1945 assert num.allclose(V[2,:], [4,5,1])1946 assert num.allclose(V[3,:], [2,1,5])1947 assert num.allclose(V[4,:], [6,7,3])1948 assert num.allclose(V[5,:], [4,3,7])1949 assert num.allclose(V[6,:], [7,8,4])1950 assert num.allclose(V[7,:], [5,4,8])1951 1952 #Get smoothed stage with XY1953 X, Y, A1, V1 = stage.get_vertex_values(xy=True, smooth=True)1954 1955 assert num.allclose(A, A1)1956 assert num.allclose(V, V1)1957 1958 #Check XY1959 assert num.allclose(X[4], 0.5)1960 assert num.allclose(Y[4], 0.5)1961 1962 assert num.allclose(X[7], 1.0)1963 assert num.allclose(Y[7], 0.5)1964 1965 1966 1967 1968 def test_vertex_values_no_smoothing(self):1969 1970 from mesh_factory import rectangular1971 from shallow_water import Domain, Transmissive_boundary1972 from anuga.utilities.numerical_tools import mean1973 1974 1975 #Create basic mesh1976 points, vertices, boundary = rectangular(2, 2)1977 1978 #Create shallow water domain1979 domain = Domain(points, vertices, boundary)1980 domain.default_order=21981 domain.reduction = mean1982 1983 1984 #Set some field values1985 domain.set_quantity('elevation', lambda x,y: x)1986 domain.set_quantity('friction', 0.03)1987 1988 1989 ######################1990 #Initial condition - with jumps1991 1992 bed = domain.quantities['elevation'].vertex_values1993 stage = num.zeros(bed.shape, num.float)1994 1995 h = 0.031996 for i in range(stage.shape[0]):1997 if i % 2 == 0:1998 stage[i,:] = bed[i,:] + h1999 else:2000 stage[i,:] = bed[i,:]2001 2002 domain.set_quantity('stage', stage)2003 2004 #Get stage2005 stage = domain.quantities['stage']2006 A, V = stage.get_vertex_values(xy=False, smooth=False)2007 Q = stage.vertex_values.flatten()2008 2009 for k in range(8):2010 assert num.allclose(A[k], Q[k])2011 2012 2013 for k in range(8):2014 assert V[k, 0] == 3*k2015 assert V[k, 1] == 3*k+12016 assert V[k, 2] == 3*k+22017 2018 2019 2020 X, Y, A1, V1 = stage.get_vertex_values(xy=True, smooth=False)2021 2022 2023 assert num.allclose(A, A1)2024 assert num.allclose(V, V1)2025 2026 #Check XY2027 assert num.allclose(X[1], 0.5)2028 assert num.allclose(Y[1], 0.5)2029 assert num.allclose(X[4], 0.0)2030 assert num.allclose(Y[4], 0.0)2031 assert num.allclose(X[12], 1.0)2032 assert num.allclose(Y[12], 0.0)2033 2034 2035 2036 def set_array_values_by_index(self):2037 2038 from mesh_factory import rectangular2039 from shallow_water import Domain2040 1881 2041 1882 #Create basic mesh … … 2043 1884 2044 1885 #Create shallow water domain 2045 domain = Domain(points, vertices, boundary)1886 domain = Generic_Domain(points, vertices, boundary) 2046 1887 #print "domain.number_of_elements ",domain.number_of_elements 2047 1888 quantity = Quantity(domain,[[1,1,1],[2,2,2]]) … … 2066 1907 """ 2067 1908 from mesh_factory import rectangular 2068 from shallow_water import Domain2069 1909 2070 1910 #Create basic mesh … … 2072 1912 #print "vertices",vertices 2073 1913 #Create shallow water domain 2074 domain = Domain(points, vertices, boundary)1914 domain = Generic_Domain(points, vertices, boundary) 2075 1915 #print "domain.number_of_elements ",domain.number_of_elements 2076 1916 quantity = Quantity(domain,[[1,1,1],[2,2,2],[3,3,3], … … 2152 1992 """ 2153 1993 from mesh_factory import rectangular 2154 from shallow_water import Domain2155 1994 2156 1995 #Create basic mesh … … 2158 1997 #print "vertices",vertices 2159 1998 #Create shallow water domain 2160 domain = Domain(points, vertices, boundary)1999 domain = Generic_Domain(points, vertices, boundary) 2161 2000 #print "domain.number_of_elements ",domain.number_of_elements 2162 2001 quantity = Quantity(domain,[[0,0,0],[1,1,1],[2,2,2],[3,3,3], … … 2178 2017 """ 2179 2018 from mesh_factory import rectangular 2180 from shallow_water import Domain2181 2019 2182 2020 #Create basic mesh … … 2188 2026 2189 2027 #Create shallow water domain 2190 domain = Domain(points, vertices, boundary)2028 domain = Generic_Domain(points, vertices, boundary) 2191 2029 #print "domain.number_of_elements ",domain.number_of_elements 2192 2030 quantity = Quantity(domain,[[0,0,0],[1,1,1],[2,2,2],[3,3,3], … … 2232 2070 vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]] 2233 2071 2234 domain = Domain(points, vertices)2072 domain = Generic_Domain(points, vertices) 2235 2073 2236 2074 quantity = Quantity(domain) … … 2280 2118 2281 2119 from mesh_factory import rectangular 2282 from shallow_water import Domain2283 2120 2284 2121 #Create basic mesh 2285 2122 points, vertices, boundary = rectangular(1, 3) 2286 domain = Domain(points, vertices, boundary)2123 domain = Generic_Domain(points, vertices, boundary) 2287 2124 2288 2125 #Constant values … … 2338 2175 vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] 2339 2176 2340 domain = Domain(points, vertices)2177 domain = Generic_Domain(points, vertices) 2341 2178 2342 2179 quantity = Quantity(domain) … … 2372 2209 vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] 2373 2210 2374 domain = Domain(points, vertices,2211 domain = Generic_Domain(points, vertices, 2375 2212 geo_reference=Geo_reference(zone,xllcorner,yllcorner)) 2376 2213 … … 2416 2253 """ 2417 2254 from mesh_factory import rectangular 2418 from shallow_water import Domain2419 2255 2420 2256 #Create basic mesh … … 2426 2262 2427 2263 #Create shallow water domain 2428 domain = Domain(points, vertices, boundary)2264 domain = Generic_Domain(points, vertices, boundary) 2429 2265 #print "domain.number_of_elements ",domain.number_of_elements 2430 2266 quantity = Quantity(domain,[[1,1,1],[2,2,2],[3,3,3], … … 2473 2309 """ 2474 2310 from mesh_factory import rectangular 2475 from shallow_waterimport Domain2311 # from anuga.shallow_water.shallow_water_domain import Domain 2476 2312 2477 2313 #Create basic mesh … … 2483 2319 2484 2320 #Create shallow water domain 2485 domain = Domain(points, vertices, boundary)2321 domain = Generic_Domain(points, vertices, boundary) 2486 2322 #print "domain.number_of_elements ",domain.number_of_elements 2487 2323 quantity = Quantity(domain,[[0,0,0],[1,1,1],[2,2,2],[3,3,3], -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_region.py
r7276 r7737 4 4 from math import sqrt 5 5 6 from domain import *6 from generic_domain import Generic_Domain 7 7 from region import * 8 8 #from anuga.config import epsilon -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_util.py
r7735 r7737 987 987 from anuga.config import time_format 988 988 from math import sin, pi 989 from domain import Domain990 989 991 990 finaltime = 1200 … … 1085 1084 from anuga.config import time_format 1086 1085 from math import sin, pi 1087 from domain import Domain1088 1086 1089 1087 finaltime = 1200 … … 1170 1168 from anuga.config import time_format 1171 1169 from math import sin, pi 1172 from domain import Domain1173 1170 1174 1171 finaltime = 1200 -
anuga_core/source/anuga/abstract_2d_finite_volumes/util.py
r7735 r7737 15 15 16 16 from anuga.utilities.numerical_tools import ensure_numeric, angle, NAN 17 from anuga.utilities.file_utils import load_csv_as_dict 17 18 18 19 from math import sqrt, atan, degrees … … 731 732 732 733 dir_filename = join(directory,filename) 733 attribute_dic, title_index_dic = csv2dict(dir_filename + '.csv')734 attribute_dic, title_index_dic = load_csv_as_dict(dir_filename + '.csv') 734 735 directory_start_time = directories_dic[directory][1] 735 736 directory_add_tide = directories_dic[directory][2] … … 844 845 845 846 # create an if about the start time and tide height if don't exist 846 attribute_dic, title_index_dic = csv2dict(directory + sep847 attribute_dic, title_index_dic = load_csv_as_dict(directory + sep 847 848 + filename + '.csv') 848 849 #get data from dict in to list … … 956 957 957 958 from anuga.shallow_water.data_manager import \ 958 get_maximum_inundation_data , csv2dict959 get_maximum_inundation_data 959 960 960 961 file = open(runup_filename, "w") … … 963 964 964 965 #read gauge csv file to dictionary 965 attribute_dic, title_index_dic = csv2dict(gauge_filename)966 attribute_dic, title_index_dic = load_csv_as_dict(gauge_filename) 966 967 northing = [float(x) for x in attribute_dic["y"]] 967 968 easting = [float(x) for x in attribute_dic["x"]] -
anuga_core/source/anuga/advection/__init__.py
r5242 r7737 6 6 sys.path += __path__ 7 7 8 # Make selected classes available directly9 from advection import Domain,\10 Transmissive_boundary, Dirichlet_boundary11 8 12 9 -
anuga_core/source/anuga/advection/advection.py
r7317 r7737 31 31 32 32 33 from anuga.abstract_2d_finite_volumes.domain import * 33 from anuga.abstract_2d_finite_volumes.generic_domain \ 34 import Generic_Domain 34 35 import anuga.utilities.log as log 35 36 … … 37 38 38 39 39 Generic_domain = Domain # Rename 40 41 class Domain(Generic_domain): 40 class Advection_Domain(Generic_Domain): 42 41 43 42 def __init__(self, … … 57 56 conserved_quantities = ['stage'] 58 57 other_quantities = [] 59 Generic_ domain.__init__(self,58 Generic_Domain.__init__(self, 60 59 source=coordinates, 61 60 triangles=vertices, … … 83 82 84 83 def check_integrity(self): 85 Generic_ domain.check_integrity(self)84 Generic_Domain.check_integrity(self) 86 85 87 86 msg = 'Conserved quantity must be "stage"' -
anuga_core/source/anuga/advection/test_advection.py
r7276 r7737 6 6 7 7 from anuga.config import g, epsilon 8 from anuga.advection.advection import Domain, Transmissive_boundary, Dirichlet_boundary 8 from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain 9 from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import \ 10 Transmissive_boundary, Dirichlet_boundary 11 12 from anuga.advection.advection import Advection_Domain 9 13 10 14 import numpy as num … … 30 34 vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]] 31 35 32 domain = Domain(points, vertices)36 domain = Advection_Domain(points, vertices) 33 37 domain.check_integrity() 34 38 … … 45 49 points = [a, b, c] 46 50 vertices = [ [0,1,2] ] 47 domain = Domain(points, vertices)51 domain = Advection_Domain(points, vertices) 48 52 domain.check_integrity() 49 53 50 54 51 55 #Populate boundary array with dirichlet conditions. 52 56 domain.neighbours = num.array([[-1,-2,-3]]) 53 57 domain.quantities['stage'].boundary_values[:] = 1.0 54 58 55 59 domain.order = 1 56 60 57 61 domain.distribute_to_vertices_and_edges() #Use first order default 58 62 59 63 domain.check_integrity() 60 64 61 65 domain.compute_fluxes() 62 66 U = -domain.quantities['stage'].explicit_update 63 67 R = -0.5/domain.areas[0] … … 74 78 points = [a, b, c] 75 79 vertices = [ [0,1,2] ] 76 domain = Domain(points, vertices)80 domain = Advection_Domain(points, vertices) 77 81 domain.check_integrity() 78 82 79 83 domain.set_quantity('stage', [1.0], location='centroids') 80 84 81 85 domain.distribute_to_vertices_and_edges() 82 86 domain.check_integrity() 83 87 84 88 85 89 domain.compute_fluxes() 86 90 U = -domain.quantities['stage'].explicit_update 87 91 R = 0.5/domain.areas[0] … … 99 103 points = [a, b, c] 100 104 vertices = [ [0,1,2] ] 101 domain = Domain(points, vertices)105 domain = Advection_Domain(points, vertices) 102 106 domain.check_integrity() 103 107 … … 130 134 points = [a, b, c, d] 131 135 vertices = [ [0,1,2], [3,2,1] ] 132 domain = Domain(points, vertices)136 domain = Advection_Domain(points, vertices) 133 137 domain.check_integrity() 134 138 … … 153 157 154 158 #Create advection domain with direction (1,-1) 155 domain = Domain(points, vertices, boundary, velocity=[1.0, -1.0]) 159 domain = Advection_Domain(points, vertices, boundary, 160 velocity=[1.0, -1.0]) 156 161 157 162 # Initial condition is zero by default -
anuga_core/source/anuga/fit_interpolate/test_interpolate.py
r7735 r7737 25 25 from anuga.utilities.numerical_tools import mean, NAN 26 26 from anuga.shallow_water.sww_file import SWW_file 27 from anuga.shallow_water.shallow_water_domain import Domain 28 from abstract_2d_finite_volumes.quantity import Quantity 27 29 from anuga.geospatial_data.geospatial_data import Geospatial_data 28 30 from anuga.pmesh.mesh import Mesh … … 140 142 141 143 from mesh_factory import rectangular 142 from shallow_water import Domain143 from abstract_2d_finite_volumes.quantity import Quantity144 144 145 145 # Create basic mesh … … 193 193 194 194 from mesh_factory import rectangular 195 from shallow_water import Domain196 from abstract_2d_finite_volumes.quantity import Quantity197 195 198 196 # Create basic mesh … … 245 243 246 244 from mesh_factory import rectangular 247 from shallow_water import Domain248 from abstract_2d_finite_volumes.quantity import Quantity249 245 250 246 # Create basic mesh -
anuga_core/source/anuga/shallow_water/test_file_conversion.py
r7736 r7737 19 19 20 20 class Test_File_Conversion(unittest.TestCase): 21 # Class variable 21 """ A suite of tests to test file conversion functions. 22 These tests are quite coarse-grained: converting a file 23 and checking that its headers and some of its contents 24 are correct. 25 """ 22 26 verbose = False 23 27
Note: See TracChangeset
for help on using the changeset viewer.