Changeset 7737


Ignore:
Timestamp:
May 24, 2010, 1:24:33 PM (14 years ago)
Author:
hudson
Message:

Various refactorings, all unit tests pass.
Domain renamed to generic domain.

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  
    1818        import ( Boundary, File_boundary, AWI_boundary,
    1919                 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
     20from pmesh2domain import pmesh_to_domain
     21from region import Set_region as region_set_region
    2322from anuga.geometry.polygon import inside_polygon
    2423from anuga.abstract_2d_finite_volumes.util import get_textual_float
     
    3130##
    3231# @brief Generic Domain class
    33 class Domain:
     32class Generic_Domain:
    3433
    3534    ##
     
    20482047                         'you may want to consider installing it')
    20492048    else:
    2050         psyco.bind(Domain.update_boundary)
     2049        psyco.bind(Generic_Domain.update_boundary)
    20512050        #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)
    20542053
    20552054
  • anuga_core/source/anuga/abstract_2d_finite_volumes/pmesh2domain.py

    r7276 r7737  
    1111
    1212
    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 level
    28     #            due to mutual dependency with domain.py
    29     from anuga.abstract_2d_finite_volumes.domain import Domain
    30 
    31     # ensure that the required 'DomainClass' actually is an instance of Domain
    32     msg = ('The class %s is not a subclass of the generic domain class %s'
    33            % (DomainClass, Domain))
    34     assert issubclass(DomainClass, Domain), msg
    35 
    36     # instantiate the result class
    37     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 elevation
    44     if (vertex_quantity_dict.has_key('elevation') and
    45         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 result
    50 
    5113
    5214##
    5315# @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.
    5517# @param DomainClass Class of return instance.
    5618# @param use_cache True if caching is to be used.
    5719# @param verbose True if this function is to be verbose.
    5820# @return An instance of 'DomainClass' containing the file data.
    59 def pmesh_to_domain_instance(file_name, DomainClass, use_cache=False,
     21def pmesh_to_domain_instance(source, DomainClass, use_cache=False,
    6022                             verbose=False):
    6123    """Converts a mesh file(.tsh or .msh), to a Domain instance.
     
    7133    if use_cache is True:
    7234        from caching import cache
    73         result = cache(_pmesh_to_domain_instance, (file_name, DomainClass),
     35        result = cache(_pmesh_to_domain_instance, (source, DomainClass),
    7436                       dependencies=[file_name], verbose=verbose)
    7537    else:
    76         result = apply(_pmesh_to_domain_instance, (file_name, DomainClass))       
     38        result = apply(_pmesh_to_domain_instance, (source, DomainClass))       
    7739       
    7840    return result
     
    8446# @param DomainClass Class of return instance.
    8547# @return The DomainClass instance containing the file data.
    86 def _pmesh_to_domain_instance(file_name, DomainClass):
     48def _pmesh_to_domain_instance(source, DomainClass):
    8749    """Converts a mesh file(.tsh or .msh), to a Domain instance.
    8850
    8951    Internal function. See public interface pmesh_to_domain_instance for details
    9052    """
    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
    9855
    9956    # ensure the required class is a subclass of Domain
    10057    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)
    10368
    10469    domain = DomainClass(coordinates = vertex_coordinates,
  • anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py

    r7711 r7737  
    4040    # @param vertex_values ??
    4141    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
    4749
    4850        if vertex_values is None:
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py

    r7725 r7737  
    44from math import sqrt
    55
    6 from anuga.abstract_2d_finite_volumes.domain import *
     6from anuga.abstract_2d_finite_volumes.generic_domain import *
    77from anuga.pmesh.mesh_interface import create_mesh_from_regions
    88from anuga.config import epsilon
     
    1818
    1919
    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.0
    32 
    33         domain.set_quantity('friction', new_values, indices = elements)
    34 
    3520
    3621class Test_Domain(unittest.TestCase):
     
    6045        other_quantities = ['elevation', 'friction']
    6146
    62         domain = Domain(points, vertices, None,
     47        domain = Generic_Domain(points, vertices, None,
    6348                        conserved_quantities, evolved_quantities, other_quantities)
    6449        domain.check_integrity()
     
    8974        other_quantities = ['elevation', 'friction']
    9075
    91         domain = Domain(points, vertices, None,
     76        domain = Generic_Domain(points, vertices, None,
    9277                        conserved_quantities, evolved_quantities, other_quantities)
    9378
     
    126111        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    127112
    128         domain = Domain(points, vertices, boundary=None,
     113        domain = Generic_Domain(points, vertices, boundary=None,
    129114                        conserved_quantities =\
    130115                        ['stage', 'xmomentum', 'ymomentum'])
     
    200185        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    201186
    202         domain = Domain(points, vertices, boundary=None,
     187        domain = Generic_Domain(points, vertices, boundary=None,
    203188                        conserved_quantities =\
    204189                        ['stage', 'xmomentum', 'ymomentum'],
     
    254239
    255240
    256         domain = Domain(points, vertices, boundary=None,
     241        domain = Generic_Domain(points, vertices, boundary=None,
    257242                        conserved_quantities =\
    258243                        ['stage', 'xmomentum', 'ymomentum'],
     
    330315        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    331316
    332         domain = Domain(points, vertices, boundary=None,
     317        domain = Generic_Domain(points, vertices, boundary=None,
    333318                        conserved_quantities =\
    334319                        ['stage', 'xmomentum', 'ymomentum'],
     
    384369        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    385370
    386         domain = Domain(points, vertices, boundary=None,
     371        domain = Generic_Domain(points, vertices, boundary=None,
    387372                        conserved_quantities =\
    388373                        ['stage', 'xmomentum', 'ymomentum'],
     
    453438
    454439
    455         domain = Domain(points, vertices, boundary=None,
     440        domain = Generic_Domain(points, vertices, boundary=None,
    456441                        conserved_quantities =\
    457442                        ['stage', 'xmomentum', 'ymomentum'],
     
    497482        points = [a, b, c]
    498483        vertices = [ [0,1,2] ]
    499         domain = Domain(points, vertices)
     484        domain = Generic_Domain(points, vertices)
    500485
    501486        domain.set_boundary( {default_boundary_tag: Dirichlet_boundary([5,2,1])} )
     
    528513
    529514
    530         domain = Domain(points, vertices, boundary,
     515        domain = Generic_Domain(points, vertices, boundary,
    531516                        conserved_quantities =\
    532517                        ['stage', 'xmomentum', 'ymomentum'])
     
    584569 
    585570        try:
    586             domain = Domain(points, vertices, boundary,
     571            domain = Generic_Domain(points, vertices, boundary,
    587572                            conserved_quantities = ['stage', 'xmomentum', 'ymomentum'],
    588573                            evolved_quantities =\
     
    595580
    596581
    597         domain = Domain(points, vertices, boundary,
     582        domain = Generic_Domain(points, vertices, boundary,
    598583                        conserved_quantities = ['stage', 'xmomentum', 'ymomentum'],
    599584                        evolved_quantities =\
     
    688673
    689674
    690         domain = Domain(points, vertices, boundary,
     675        domain = Generic_Domain(points, vertices, boundary,
    691676                        conserved_quantities =\
    692677                        ['stage', 'xmomentum', 'ymomentum'])
     
    739724
    740725
    741         domain = Domain(points, vertices, boundary,
     726        domain = Generic_Domain(points, vertices, boundary,
    742727                        conserved_quantities =\
    743728                        ['stage', 'xmomentum', 'ymomentum'])
     
    799784                     (3, 2): 'Third'}
    800785
    801         domain = Domain(points, vertices, boundary,
     786        domain = Generic_Domain(points, vertices, boundary,
    802787                        conserved_quantities =\
    803788                        ['stage', 'xmomentum', 'ymomentum'])
     
    833818                        'set region failed')
    834819
    835 
    836     def test_track_speeds(self):
    837         """
    838         get values based on triangle lists.
    839         """
    840         from mesh_factory import rectangular
    841         from shallow_water import Domain
    842 
    843         #Create basic mesh
    844         points, vertices, boundary = rectangular(1, 3)
    845 
    846         #Create shallow water domain
    847         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 rectangular
    857         from shallow_water import Domain
    858 
    859         #Create basic mesh
    860         points, vertices, boundary = rectangular(1, 3)
    861 
    862         #Create shallow water domain
    863         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 friction
    870         manning = 0.07
    871         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 rectangular
    897         from shallow_water import Domain
    898 
    899         #Create basic mesh
    900         points, vertices, boundary = rectangular(1, 3)
    901 
    902         #Create shallow water domain
    903         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 friction
    910         manning = 0.07
    911         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]]), msg
    932        
    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]])
    950820                             
    951821    def test_rectangular_periodic_and_ghosts(self):
     
    962832
    963833        conserved_quantities = ['quant1', 'quant2']
    964         domain = Domain(points, vertices, boundary, conserved_quantities,
     834        domain = Generic_Domain(points, vertices, boundary, conserved_quantities,
    965835                        full_send_dict=full_send_dict,
    966836                        ghost_recv_dict=ghost_recv_dict)
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_generic_boundary_conditions.py

    r7735 r7737  
    55
    66from generic_boundary_conditions import *
    7 from anuga.abstract_2d_finite_volumes.domain import Domain
     7from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain
    88from anuga.config import epsilon
    99
     
    6464        elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ]
    6565
    66         domain = Domain(points, elements)
     66        domain = Generic_Domain(points, elements)
    6767        domain.check_integrity()
    6868
     
    130130        elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ]
    131131
    132         domain = Domain(points, elements)
     132        domain = Generic_Domain(points, elements)
    133133        domain.check_integrity()
    134134
     
    202202        elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ]
    203203
    204         domain = Domain(points, elements)
     204        domain = Generic_Domain(points, elements)
    205205        domain.check_integrity()
    206206
     
    281281        elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ]
    282282
    283         domain = Domain(points, elements)
     283        domain = Generic_Domain(points, elements)
    284284        domain.conserved_quantities = ['stage', 'ymomentum']
    285285        domain.quantities['stage'] =\
     
    374374        elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ]
    375375
    376         domain = Domain(points, elements)
     376        domain = Generic_Domain(points, elements)
    377377        domain.conserved_quantities = ['stage', 'xmomentum', 'ymomentum']
    378378        domain.evolved_quantities = ['stage', 'xmomentum', 'ymomentum']
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_ghost.py

    r7519 r7737  
    44from math import sqrt
    55
    6 from anuga.abstract_2d_finite_volumes.domain import *
     6from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain
    77from anuga.config import epsilon
    88
     
    3434        other_quantities = ['elevation', 'friction']
    3535
    36         domain = Domain(points, vertices, None,
     36        domain = Generic_Domain(points, vertices, None,
    3737                        conserved_quantities, None, other_quantities)
    3838        domain.check_integrity()
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_pmesh2domain.py

    r7276 r7737  
    44import unittest
    55
    6 #from anuga.pyvolution.pmesh2domain import *
    76from pmesh2domain import *
    87
    9 from anuga.shallow_water import Domain,\
    10      Reflective_boundary, Dirichlet_boundary,\
    11      Transmissive_boundary
     8from anuga.shallow_water.shallow_water_domain import Domain
     9from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
     10                        import Dirichlet_boundary
    1211
    1312from anuga.coordinate_transforms.geo_reference import Geo_reference
     
    167166         tags["3"] = b3
    168167
    169          domain = pmesh_instance_to_domain_instance(mesh_instance, Domain)
     168         domain = pmesh_to_domain_instance(mesh_instance, Domain)
    170169
    171170         os.remove(fileName)
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py

    r7711 r7737  
    1010from anuga.fit_interpolate.fit import fit_to_mesh
    1111#from anuga.pyvolution.least_squares import fit_to_mesh         
    12 from anuga.abstract_2d_finite_volumes.domain import Domain
     12from anuga.abstract_2d_finite_volumes.generic_domain \
     13                import Generic_Domain
    1314from anuga.geospatial_data.geospatial_data import Geospatial_data
    1415from anuga.coordinate_transforms.geo_reference import Geo_reference
     
    3940        elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ]
    4041
    41         self.mesh1 = Domain(points[:3], [elements[0]])
     42        self.mesh1 = Generic_Domain(points[:3], [elements[0]])
    4243        self.mesh1.check_integrity()
    4344       
     
    4546        #print isinstance(self.mesh1, Domain)
    4647
    47         self.mesh4 = Domain(points, elements)
     48        self.mesh4 = Generic_Domain(points, elements)
    4849        self.mesh4.check_integrity()
    4950
     
    5657        elements = [[0,2,1]]
    5758       
    58         self.mesh_onslow = Domain(points, elements)
     59        self.mesh_onslow = Generic_Domain(points, elements)
    5960        self.mesh_onslow.check_integrity()
    6061       
     
    174175        vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    175176
    176         domain = Domain(points, vertices)
     177        domain = Generic_Domain(points, vertices)
    177178
    178179        quantity = Quantity(domain)
     
    575576
    576577        mesh_georef = Geo_reference(56,-0.76,-0.76)
    577         mesh1 = Domain(vertex_coordinates, triangles,
     578        mesh1 = Generic_Domain(vertex_coordinates, triangles,
    578579                       geo_reference = mesh_georef)
    579580        mesh1.check_integrity()
     
    10871088
    10881089        #absolute going in ..
    1089         mesh4 = Domain(points, elements,
     1090        mesh4 = Generic_Domain(points, elements,
    10901091                       geo_reference = Geo_reference(56, 0, 0))
    10911092        mesh4.check_integrity()
     
    11671168        elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ]
    11681169
    1169         mesh4 = Domain(points, elements,
     1170        mesh4 = Generic_Domain(points, elements,
    11701171                       geo_reference = Geo_reference(56, x0, y0))
    11711172        mesh4.check_integrity()
     
    18751876
    18761877
    1877 
    1878     #Test smoothing
    1879     def test_smoothing(self):
     1878    def set_array_values_by_index(self):
    18801879
    18811880        from mesh_factory import rectangular
    1882         from shallow_water import Domain, Transmissive_boundary
    1883         from anuga.utilities.numerical_tools import mean
    1884 
    1885         #Create basic mesh
    1886         points, vertices, boundary = rectangular(2, 2)
    1887 
    1888         #Create shallow water domain
    1889         domain = Domain(points, vertices, boundary)
    1890         domain.default_order=2
    1891         domain.reduction = mean
    1892 
    1893 
    1894         #Set some field values
    1895         domain.set_quantity('elevation', lambda x,y: x)
    1896         domain.set_quantity('friction', 0.03)
    1897 
    1898 
    1899         ######################
    1900         # Boundary conditions
    1901         B = Transmissive_boundary(domain)
    1902         domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B})
    1903 
    1904 
    1905         ######################
    1906         #Initial condition - with jumps
    1907 
    1908         bed = domain.quantities['elevation'].vertex_values
    1909         stage = num.zeros(bed.shape, num.float)
    1910 
    1911         h = 0.03
    1912         for i in range(stage.shape[0]):
    1913             if i % 2 == 0:
    1914                 stage[i,:] = bed[i,:] + h
    1915             else:
    1916                 stage[i,:] = bed[i,:]
    1917 
    1918         domain.set_quantity('stage', stage)
    1919 
    1920         stage = domain.quantities['stage']
    1921 
    1922         #Get smoothed stage
    1923         A, V = stage.get_vertex_values(xy=False, smooth=True)
    1924         Q = stage.vertex_values
    1925 
    1926 
    1927         assert A.shape[0] == 9
    1928         assert V.shape[0] == 8
    1929         assert V.shape[1] == 3
    1930 
    1931         #First four points
    1932         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 point
    1938         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 V
    1943         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 XY
    1953         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 XY
    1959         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 rectangular
    1971         from shallow_water import Domain, Transmissive_boundary
    1972         from anuga.utilities.numerical_tools import mean
    1973 
    1974 
    1975         #Create basic mesh
    1976         points, vertices, boundary = rectangular(2, 2)
    1977 
    1978         #Create shallow water domain
    1979         domain = Domain(points, vertices, boundary)
    1980         domain.default_order=2
    1981         domain.reduction = mean
    1982 
    1983 
    1984         #Set some field values
    1985         domain.set_quantity('elevation', lambda x,y: x)
    1986         domain.set_quantity('friction', 0.03)
    1987 
    1988 
    1989         ######################
    1990         #Initial condition - with jumps
    1991 
    1992         bed = domain.quantities['elevation'].vertex_values
    1993         stage = num.zeros(bed.shape, num.float)
    1994 
    1995         h = 0.03
    1996         for i in range(stage.shape[0]):
    1997             if i % 2 == 0:
    1998                 stage[i,:] = bed[i,:] + h
    1999             else:
    2000                 stage[i,:] = bed[i,:]
    2001 
    2002         domain.set_quantity('stage', stage)
    2003 
    2004         #Get stage
    2005         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*k
    2015             assert V[k, 1] == 3*k+1
    2016             assert V[k, 2] == 3*k+2
    2017 
    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 XY
    2027         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 rectangular
    2039         from shallow_water import Domain
    20401881
    20411882        #Create basic mesh
     
    20431884
    20441885        #Create shallow water domain
    2045         domain = Domain(points, vertices, boundary)
     1886        domain = Generic_Domain(points, vertices, boundary)
    20461887        #print "domain.number_of_elements ",domain.number_of_elements
    20471888        quantity = Quantity(domain,[[1,1,1],[2,2,2]])
     
    20661907        """
    20671908        from mesh_factory import rectangular
    2068         from shallow_water import Domain
    20691909
    20701910        #Create basic mesh
     
    20721912        #print "vertices",vertices
    20731913        #Create shallow water domain
    2074         domain = Domain(points, vertices, boundary)
     1914        domain = Generic_Domain(points, vertices, boundary)
    20751915        #print "domain.number_of_elements ",domain.number_of_elements
    20761916        quantity = Quantity(domain,[[1,1,1],[2,2,2],[3,3,3],
     
    21521992        """
    21531993        from mesh_factory import rectangular
    2154         from shallow_water import Domain
    21551994
    21561995        #Create basic mesh
     
    21581997        #print "vertices",vertices
    21591998        #Create shallow water domain
    2160         domain = Domain(points, vertices, boundary)
     1999        domain = Generic_Domain(points, vertices, boundary)
    21612000        #print "domain.number_of_elements ",domain.number_of_elements
    21622001        quantity = Quantity(domain,[[0,0,0],[1,1,1],[2,2,2],[3,3,3],
     
    21782017        """
    21792018        from mesh_factory import rectangular
    2180         from shallow_water import Domain
    21812019
    21822020        #Create basic mesh
     
    21882026
    21892027        #Create shallow water domain
    2190         domain = Domain(points, vertices, boundary)
     2028        domain = Generic_Domain(points, vertices, boundary)
    21912029        #print "domain.number_of_elements ",domain.number_of_elements
    21922030        quantity = Quantity(domain,[[0,0,0],[1,1,1],[2,2,2],[3,3,3],
     
    22322070        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    22332071
    2234         domain = Domain(points, vertices)
     2072        domain = Generic_Domain(points, vertices)
    22352073
    22362074        quantity = Quantity(domain)
     
    22802118
    22812119        from mesh_factory import rectangular
    2282         from shallow_water import Domain
    22832120
    22842121        #Create basic mesh
    22852122        points, vertices, boundary = rectangular(1, 3)
    2286         domain = Domain(points, vertices, boundary)
     2123        domain = Generic_Domain(points, vertices, boundary)
    22872124
    22882125        #Constant values
     
    23382175        vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    23392176
    2340         domain = Domain(points, vertices)
     2177        domain = Generic_Domain(points, vertices)
    23412178
    23422179        quantity = Quantity(domain)
     
    23722209        vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    23732210
    2374         domain = Domain(points, vertices,
     2211        domain = Generic_Domain(points, vertices,
    23752212                        geo_reference=Geo_reference(zone,xllcorner,yllcorner))
    23762213
     
    24162253        """
    24172254        from mesh_factory import rectangular
    2418         from shallow_water import Domain
    24192255
    24202256        #Create basic mesh
     
    24262262
    24272263        #Create shallow water domain
    2428         domain = Domain(points, vertices, boundary)
     2264        domain = Generic_Domain(points, vertices, boundary)
    24292265        #print "domain.number_of_elements ",domain.number_of_elements
    24302266        quantity = Quantity(domain,[[1,1,1],[2,2,2],[3,3,3],
     
    24732309        """
    24742310        from mesh_factory import rectangular
    2475         from shallow_water import Domain
     2311      #  from anuga.shallow_water.shallow_water_domain import Domain
    24762312
    24772313        #Create basic mesh
     
    24832319
    24842320        #Create shallow water domain
    2485         domain = Domain(points, vertices, boundary)
     2321        domain = Generic_Domain(points, vertices, boundary)
    24862322        #print "domain.number_of_elements ",domain.number_of_elements
    24872323        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  
    44from math import sqrt
    55
    6 from domain import *
     6from generic_domain import Generic_Domain
    77from region import *
    88#from anuga.config import epsilon
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_util.py

    r7735 r7737  
    987987        from anuga.config import time_format
    988988        from math import sin, pi
    989         from domain import Domain
    990989
    991990        finaltime = 1200
     
    10851084        from anuga.config import time_format
    10861085        from math import sin, pi
    1087         from domain import Domain
    10881086
    10891087        finaltime = 1200
     
    11701168        from anuga.config import time_format
    11711169        from math import sin, pi
    1172         from domain import Domain
    11731170
    11741171        finaltime = 1200
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r7735 r7737  
    1515
    1616from anuga.utilities.numerical_tools import ensure_numeric, angle, NAN
     17from anuga.utilities.file_utils import load_csv_as_dict
    1718
    1819from math import sqrt, atan, degrees
     
    731732
    732733            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')
    734735            directory_start_time = directories_dic[directory][1]
    735736            directory_add_tide = directories_dic[directory][2]
     
    844845           
    845846            # create an if about the start time and tide height if don't exist
    846             attribute_dic, title_index_dic = csv2dict(directory + sep
     847            attribute_dic, title_index_dic = load_csv_as_dict(directory + sep
    847848                                                      + filename + '.csv')
    848849            #get data from dict in to list
     
    956957
    957958    from anuga.shallow_water.data_manager import \
    958         get_maximum_inundation_data, csv2dict
     959        get_maximum_inundation_data
    959960                                                 
    960961    file = open(runup_filename, "w")
     
    963964   
    964965    #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)
    966967    northing = [float(x) for x in attribute_dic["y"]]
    967968    easting = [float(x) for x in attribute_dic["x"]]
  • anuga_core/source/anuga/advection/__init__.py

    r5242 r7737  
    66sys.path += __path__
    77
    8 # Make selected classes available directly
    9 from advection import Domain,\
    10     Transmissive_boundary, Dirichlet_boundary
    118
    129
  • anuga_core/source/anuga/advection/advection.py

    r7317 r7737  
    3131
    3232
    33 from anuga.abstract_2d_finite_volumes.domain import *
     33from anuga.abstract_2d_finite_volumes.generic_domain \
     34                import Generic_Domain
    3435import anuga.utilities.log as log
    3536
     
    3738
    3839
    39 Generic_domain = Domain # Rename
    40 
    41 class Domain(Generic_domain):
     40class Advection_Domain(Generic_Domain):
    4241
    4342    def __init__(self,
     
    5756        conserved_quantities = ['stage']
    5857        other_quantities = []
    59         Generic_domain.__init__(self,
     58        Generic_Domain.__init__(self,
    6059                                source=coordinates,
    6160                                triangles=vertices,
     
    8382
    8483    def check_integrity(self):
    85         Generic_domain.check_integrity(self)
     84        Generic_Domain.check_integrity(self)
    8685
    8786        msg = 'Conserved quantity must be "stage"'
  • anuga_core/source/anuga/advection/test_advection.py

    r7276 r7737  
    66
    77from anuga.config import g, epsilon
    8 from anuga.advection.advection import Domain, Transmissive_boundary, Dirichlet_boundary
     8from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain
     9from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import \
     10                Transmissive_boundary, Dirichlet_boundary
     11
     12from anuga.advection.advection import Advection_Domain
    913
    1014import numpy as num
     
    3034        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    3135
    32         domain = Domain(points, vertices)
     36        domain = Advection_Domain(points, vertices)
    3337        domain.check_integrity()
    3438
     
    4549        points = [a, b, c]
    4650        vertices = [ [0,1,2] ]
    47         domain = Domain(points, vertices)
     51        domain = Advection_Domain(points, vertices)
    4852        domain.check_integrity()
    4953
    5054
    5155        #Populate boundary array with dirichlet conditions.
    52         domain.neighbours = num.array([[-1,-2,-3]])
     56        domain.neighbours = num.array([[-1,-2,-3]])
    5357        domain.quantities['stage'].boundary_values[:] = 1.0
    5458
    55         domain.order = 1
     59        domain.order = 1
    5660
    57         domain.distribute_to_vertices_and_edges() #Use first order default
     61        domain.distribute_to_vertices_and_edges() #Use first order default
    5862
    5963        domain.check_integrity()
    6064
    61         domain.compute_fluxes()
     65        domain.compute_fluxes()
    6266        U = -domain.quantities['stage'].explicit_update
    6367        R = -0.5/domain.areas[0]
     
    7478        points = [a, b, c]
    7579        vertices = [ [0,1,2] ]
    76         domain = Domain(points, vertices)
     80        domain = Advection_Domain(points, vertices)
    7781        domain.check_integrity()
    7882
    7983        domain.set_quantity('stage', [1.0], location='centroids')
    8084
    81         domain.distribute_to_vertices_and_edges()
     85        domain.distribute_to_vertices_and_edges()
    8286        domain.check_integrity()
    8387
    8488
    85         domain.compute_fluxes()
     89        domain.compute_fluxes()
    8690        U = -domain.quantities['stage'].explicit_update
    8791        R = 0.5/domain.areas[0]
     
    99103        points = [a, b, c]
    100104        vertices = [ [0,1,2] ]
    101         domain = Domain(points, vertices)
     105        domain = Advection_Domain(points, vertices)
    102106        domain.check_integrity()
    103107
     
    130134        points = [a, b, c, d]
    131135        vertices = [ [0,1,2], [3,2,1] ]
    132         domain = Domain(points, vertices)
     136        domain = Advection_Domain(points, vertices)
    133137        domain.check_integrity()
    134138
     
    153157
    154158        #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])
    156161
    157162        # Initial condition is zero by default
  • anuga_core/source/anuga/fit_interpolate/test_interpolate.py

    r7735 r7737  
    2525from anuga.utilities.numerical_tools import mean, NAN
    2626from anuga.shallow_water.sww_file import SWW_file
     27from anuga.shallow_water.shallow_water_domain import Domain
     28from abstract_2d_finite_volumes.quantity import Quantity
    2729from anuga.geospatial_data.geospatial_data import Geospatial_data
    2830from anuga.pmesh.mesh import Mesh
     
    140142       
    141143        from mesh_factory import rectangular
    142         from shallow_water import Domain
    143         from abstract_2d_finite_volumes.quantity import Quantity
    144144
    145145        # Create basic mesh
     
    193193       
    194194        from mesh_factory import rectangular
    195         from shallow_water import Domain
    196         from abstract_2d_finite_volumes.quantity import Quantity
    197195
    198196        # Create basic mesh
     
    245243       
    246244        from mesh_factory import rectangular
    247         from shallow_water import Domain
    248         from abstract_2d_finite_volumes.quantity import Quantity
    249245
    250246        # Create basic mesh
  • anuga_core/source/anuga/shallow_water/test_file_conversion.py

    r7736 r7737  
    1919
    2020class 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    """
    2226    verbose = False
    2327
Note: See TracChangeset for help on using the changeset viewer.