Changeset 8578


Ignore:
Timestamp:
Sep 14, 2012, 9:56:39 PM (13 years ago)
Author:
steve
Message:

Added extra unit tests for set_stage and set_elevation operators

Location:
trunk/anuga_core/source/anuga
Files:
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/__init__.py

    r8572 r8578  
    7373from anuga.shallow_water.boundaries import \
    7474                    Transmissive_n_momentum_zero_t_momentum_set_stage_boundary
     75from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import \
     76                    Compute_fluxes_boundary
    7577
    7678
     
    172174    """
    173175
    174     if 'verbose' in kwargs:
    175         verbose = kwargs['verbose']
    176         kwargs.pop('verbose')
    177     else:
     176    try:
     177        verbose = kwargs.pop('verbose')
     178    except:
    178179        verbose = False
     180
    179181
    180182    points, vertices, boundary = rectangular_cross(*args, **kwargs)
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/generic_boundary_conditions.py

    r8538 r8578  
    208208            Q.boundary_values[ids] = q_bdry[j]
    209209
     210class Compute_fluxes_boundary(Boundary):
     211    """ Associate the Compute_fluxes_boundary BC
     212    to each boundary segment where a special calculation
     213    of the fluxes will occur.
     214    """
     215
     216    def __init__(self):
     217        Boundary.__init__(self)
     218        """ Instantiate a Compute_fluxes_boundary.
     219            domain: underlying domain
     220            """
     221
     222
     223    def __repr__(self):
     224        """ Return a representation of this instance. """
     225        return 'Compute_fluxes_boundary(%s)' % self.domain
     226
     227    def evaluate(self, vol_id, edge_id):
     228        """Do something basic"""
     229
     230        return None
     231
     232    def evaluate_segment(self, domain, segment_edges):
     233        """Don't do any calculation when applying this BC.
     234        The work will be done in compute_fluxes.
     235        """
     236
     237        return
    210238
    211239
     
    601629    def evaluate(self, vol_id=None, edge_id=None):
    602630        """Return linearly interpolated values based on domain.time
    603         at midpoint of segment defined by vol_id and edge_id.
     631        at midpoint of segment defined by vol_id and edge_id.
    604632        """
    605633
     
    828856
    829857
     858
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/generic_domain.py

    r8574 r8578  
    809809                raise Exception(msg)
    810810
     811
     812
     813        # Add a flag which can be used to distinguish flux boundaries within
     814        # compute_fluxes_central
     815        # Initialise to zero (which means 'not a flux_boundary')
     816        self.boundary_flux_type = self.boundary_edges*0
     817
     818        # HACK to set the values of domain.boundary_flux
     819        for k, ((vol_id, edge_id), B) in enumerate(self.boundary_objects):
     820            # If Boundary set to Compute_fluxes_boundary identify as flux boundary
     821            #print vol_id, edge_id, B
     822
     823            import anuga
     824            if ( isinstance(B,anuga.Compute_fluxes_boundary) ):
     825                self.boundary_flux_type[k]=1
     826
     827
    811828    ##
    812829    # @brief Set quantities based on a regional tag.
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/neighbour_mesh.py

    r8570 r8578  
    553553
    554554
    555         for j in range(self.boundary_length):
     555        for j in xrange(self.boundary_length):
    556556            id  = self.boundary_cells[j]
    557557            edge = self.boundary_edges[j]
  • trunk/anuga_core/source/anuga/fit_interpolate/fit.py

    r8536 r8578  
    4646
    4747import numpy as num
     48import sys
    4849
    4950
     
    100101                 triangles,
    101102                 mesh,
    102                  mesh_origin,
    103                  verbose)
     103                 mesh_origin=mesh_origin,
     104                 verbose=verbose)
    104105       
    105106        m = self.mesh.number_of_nodes # Nbr of basis functions (vertices)
     
    110111        self.point_count = 0
    111112        if self.alpha <> 0:
    112             if verbose: log.critical('Building smoothing matrix')
    113             self._build_smoothing_matrix_D()
    114            
     113            if verbose: log.critical('Fit: Building smoothing matrix')
     114            self._build_smoothing_matrix_D(verbose=verbose)
     115
     116        if verbose: log.critical('Fit: Get Boundary Polygon')
    115117        bd_poly = self.mesh.get_boundary_polygon()   
    116118        self.mesh_boundary_polygon = ensure_numeric(bd_poly)
     119
     120        if verbose: log.critical('Fit: Done')
     121
    117122           
    118123    def _build_coefficient_matrix_B(self,
     
    126131        """
    127132
     133        if verbose:
     134            print 'Fit: Build Coefficient Matrix B'
     135
     136
    128137        if self.alpha <> 0:
    129138            #if verbose: log.critical('Building smoothing matrix')
    130139            #self._build_smoothing_matrix_D()
     140            # FIXME SR: This is quite time consuming.
     141            # As AtA and D have same structure it should be possible
     142            # to speed this up.
    131143            self.B = self.AtA + self.alpha*self.D
    132144        else:
    133145            self.B = self.AtA
    134146
     147
     148        if verbose:
     149            print 'Fit: Convert Coefficient Matrix B to Sparse_CSR'
     150           
    135151        # Convert self.B matrix to CSR format for faster matrix vector
    136152        self.B = Sparse_CSR(self.B)
    137153
    138     def _build_smoothing_matrix_D(self):
     154    def _build_smoothing_matrix_D(self, verbose=False):
    139155        """Build m x m smoothing matrix, where
    140156        m is the number of basis functions phi_k (one per vertex)
     
    169185        self.D = Sparse(m,m)
    170186
     187        if verbose :
     188            print '['+60*' '+']',
     189            sys.stdout.flush()
     190
     191        N = len(self.mesh)
     192        M = N/60
     193
    171194        # For each triangle compute contributions to D = D1+D2
    172         for i in range(len(self.mesh)):
     195        for i in xrange(N):
     196
     197            if verbose and i%M == 0 :
     198                #restart_line()
     199                print '\r['+(i/M)*'.'+(60-(i/M))*' ' +']',
     200                sys.stdout.flush()
    173201
    174202            # Get area
     
    212240            self.D[v2,v0] += e20
    213241            self.D[v0,v2] += e20
     242
     243        if verbose:
     244            print ''
    214245
    215246    def get_D(self):
     
    242273        The number of attributes of the data points does not change
    243274        """
    244        
     275
     276
     277        if verbose:
     278            print 'Fit: Build Matrix AtA Atz'
     279
    245280        # Build n x m interpolation matrix
    246281        if self.AtA == None:
     
    271306        # Compute matrix elements for points inside the mesh
    272307        triangles = self.mesh.triangles # Shorthand
    273         for d, i in enumerate(inside_indices):
     308
     309
     310        if verbose :
     311            print '['+60*' '+']',
     312            sys.stdout.flush()
     313
     314        m = n/60
     315
     316
     317        for i in xrange(n):
     318            d = inside_indices[i]
    274319            # For each data_coordinate point
    275320            # if verbose and d%((n+10)/10)==0: log.critical('Doing %d of %d'
    276321                                                            # %(d, n))
    277             x = point_coordinates[i]
     322
     323
     324            if verbose and i%m == 0 :
     325                print '\r['+(i/m)*'.'+(60-(i/m))*' '+']',
     326                sys.stdout.flush()
     327
     328
     329            x = point_coordinates[d]
    278330           
    279331            element_found, sigma0, sigma1, sigma2, k = \
     
    302354               
    303355                # data point has fallen within a hole - so ignore it.
    304                
     356
     357
     358        if verbose:
     359            print ''
     360           
    305361        self.AtA = AtA
    306362
     
    324380         
    325381        """
    326        
     382
     383
     384        if verbose:
     385            print 'Fit.fit: Initializing'
     386
    327387        # Use blocking to load in the point info
    328388        if isinstance(point_coordinates_or_filename, basestring):
     
    357417                points = geo_block.get_data_points(absolute=True)
    358418                z = geo_block.get_attributes(attribute_name=attribute_name)
    359                 self.build_fit_subset(points, z, verbose=verbose)
     419                self.build_fit_subset(points, z, attribute_name, verbose)
    360420
    361421                # FIXME(Ole): I thought this test would make sense here
     
    368428        else:
    369429            point_coordinates =  point_coordinates_or_filename
    370            
     430
     431
     432
    371433        if point_coordinates is None:
    372             if verbose: log.critical('Warning: no data points in fit')
     434            if verbose: log.critical('Fit.fit: Warning: no data points in fit')
    373435            msg = 'No interpolation matrix.'
    374436            assert self.AtA is not None, msg
     
    381443            # if isinstance(point_coordinates,Geospatial_data) and z is None:
    382444            # z will come from the geo-ref
    383             self.build_fit_subset(point_coordinates, z, verbose)
     445            self.build_fit_subset(point_coordinates, z, verbose=verbose)
     446
     447
     448
     449
    384450
    385451        # Check sanity
     
    393459            msg += 'positive value,\ne.g. 1.0e-3.'
    394460            raise TooFewPointsError(msg)
     461
    395462
    396463        self._build_coefficient_matrix_B(verbose)
     
    408475            #raise VertsWithNoTrianglesError(msg)
    409476       
    410        
     477        if verbose:
     478            print 'Fit.fit: Solve Fitting Equation'
     479
    411480        return conjugate_gradient(self.B, self.Atz, self.Atz,
    412481                                  imax=2*len(self.Atz) )
     
    575644
    576645        if verbose: log.critical('FitInterpolate: Building mesh')
    577         mesh = Mesh(vertex_coordinates, triangles)
    578         mesh.check_integrity()
     646        mesh = Mesh(vertex_coordinates, triangles, verbose=verbose)
     647        #mesh.check_integrity() # expensive
    579648   
    580649   
     
    648717        old_title_list = mesh_dict['vertex_attribute_titles']
    649718
    650     if verbose: log.critical('tsh file %s loaded' % mesh_file)
     719    if verbose: log.critical('Fit_to_Mesh_File: tsh file %s loaded' % mesh_file)
    651720
    652721    # load in the points file
     
    668737        mesh_origin = None
    669738
    670     if verbose: log.critical("points file loaded")
    671     if verbose: log.critical("fitting to mesh")
     739    if verbose: log.critical("Fit_to_Mesh_File: points file loaded")
     740    if verbose: log.critical("Fit_to_Mesh_File: fitting to mesh")
    672741    f = fit_to_mesh(point_coordinates,
    673742                    vertex_coordinates,
     
    679748                    data_origin = None,
    680749                    mesh_origin = mesh_origin)
    681     if verbose: log.critical("finished fitting to mesh")
     750    if verbose: log.critical("Fit_to_Mesh_File: finished fitting to mesh")
    682751
    683752    # convert array to list of lists
     
    688757        old_title_list.extend(title_list)
    689758        #FIXME can this be done a faster way? - DSG
    690         for i in range(len(old_point_attributes)):
     759        for i in xrange(len(old_point_attributes)):
    691760            old_point_attributes[i].extend(new_point_attributes[i])
    692761        mesh_dict['vertex_attributes'] = old_point_attributes
     
    696765        mesh_dict['vertex_attribute_titles'] = title_list
    697766
    698     if verbose: log.critical("exporting to file %s" % mesh_output_file)
     767    if verbose: log.critical("Fit_to_Mesh_File: exporting to file %s" % mesh_output_file)
    699768
    700769    try:
  • trunk/anuga_core/source/anuga/fit_interpolate/general_fit_interpolate.py

    r7751 r8578  
    9191
    9292                if verbose: log.critical('FitInterpolate: Building mesh')
    93                 self.mesh = Mesh(vertex_coordinates, triangles)
     93                self.mesh = Mesh(vertex_coordinates, triangles, verbose=verbose)
    9494                #self.mesh.check_integrity() # Time consuming
    9595            else:
     
    102102            #This stores indices of vertices
    103103            t0 = time.time()
    104             self.root = MeshQuadtree(self.mesh)
     104            self.root = MeshQuadtree(self.mesh, verbose=verbose)
    105105       
    106106            build_quadtree_time =  time.time()-t0
  • trunk/anuga_core/source/anuga/operators/test_set_stage_operators.py

    r8577 r8578  
    2121
    2222
    23 class Test_set_operators(unittest.TestCase):
     23class Test_set_stage_operators(unittest.TestCase):
    2424    def setUp(self):
    2525        pass
     
    142142
    143143
    144 
    145 
    146            
     144    def test_set_stage_operator_function(self):
     145        from anuga.config import rho_a, rho_w, eta_w
     146        from math import pi, cos, sin
     147
     148        a = [0.0, 0.0]
     149        b = [0.0, 2.0]
     150        c = [2.0, 0.0]
     151        d = [0.0, 4.0]
     152        e = [2.0, 2.0]
     153        f = [4.0, 0.0]
     154
     155
     156
     157
     158
     159        points = [a, b, c, d, e, f]
     160        #             bac,     bce,     ecf,     dbe
     161        vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]
     162
     163        domain = Domain(points, vertices)
     164
     165        #Flat surface with 1m of water
     166        domain.set_quantity('elevation', 0)
     167        domain.set_quantity('stage', 1.0)
     168        domain.set_quantity('friction', 0)
     169
     170        Br = Reflective_boundary(domain)
     171        domain.set_boundary({'exterior': Br})
     172
     173
     174#        print domain.quantities['stage'].centroid_values
     175#        print domain.quantities['xmomentum'].centroid_values
     176#        print domain.quantities['ymomentum'].centroid_values
     177
     178        # Apply operator to these triangles
     179        indices = [0,1,3]
     180
     181
     182        def stage(t):
     183            if t < 10.0:
     184                return 5.0
     185            else:
     186                return 10.0
     187
     188        operator = Set_stage_operator(domain, stage=stage, indices=indices)
     189
     190        # Apply Operator at time t=1.0
     191        domain.set_time(1.0)
     192        operator()
     193
     194        stage_ex = [ 5.,  5.,   1.,  5.]
     195
     196
     197#        print domain.quantities['stage'].centroid_values
     198#        print domain.quantities['xmomentum'].centroid_values
     199#        print domain.quantities['ymomentum'].centroid_values
     200
     201        assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
     202        assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
     203        assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
     204
     205        # Apply Operator at time t=15.0
     206        domain.set_time(15.0)
     207        operator()
     208
     209        stage_ex = [ 10.,  10.,   1.,  10.]
     210
     211
     212#        print domain.quantities['stage'].centroid_values
     213#        print domain.quantities['xmomentum'].centroid_values
     214#        print domain.quantities['ymomentum'].centroid_values
     215
     216        assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
     217        assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
     218        assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
     219
     220
     221    def test_set_stage_operator_large_function(self):
     222        from anuga.config import rho_a, rho_w, eta_w
     223        from math import pi, cos, sin
     224
     225
     226        length = 2.0
     227        width = 2.0
     228        dx = dy = 0.5
     229        domain = rectangular_cross_domain(int(length/dx), int(width/dy),
     230                                              len1=length, len2=width)
     231
     232
     233        #Flat surface with 1m of water
     234        domain.set_quantity('elevation', 0.0)
     235        domain.set_quantity('stage', 1.0)
     236        domain.set_quantity('friction', 0)
     237
     238        R = Reflective_boundary(domain)
     239        domain.set_boundary( {'left': R, 'right': R, 'bottom': R, 'top': R} )
     240
     241
     242#        print domain.quantities['stage'].centroid_values
     243#        print domain.quantities['xmomentum'].centroid_values
     244#        print domain.quantities['ymomentum'].centroid_values
     245
     246
     247
     248        def stage(t):
     249            if t < 10.0:
     250                return 5.0
     251            else:
     252                return 7.0
     253
     254        polygon = [(0.5,0.5), (1.5,0.5), (1.5,1.5), (0.5,1.5)]
     255        operator = Polygonal_set_stage_operator(domain, stage=stage, polygon=polygon)
     256
     257        # Apply Operator at time t=1.0
     258        domain.set_time(1.0)
     259        operator()
     260
     261        stage_ex = [ 1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,
     262                     1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,
     263                     5.0,  5.0,  5.0,  5.0,  5.0,  5.0,  5.0,  5.0,  1.0,  1.0,
     264                     1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  5.0,  5.0,  5.0,  5.0,
     265                     5.0,  5.0,  5.0,  5.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,
     266                     1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,
     267                     1.0,  1.0,  1.0,  1.0]
     268
     269
     270#        print domain.quantities['elevation'].centroid_values
     271#        print domain.quantities['stage'].centroid_values
     272#        print domain.quantities['xmomentum'].centroid_values
     273#        print domain.quantities['ymomentum'].centroid_values
     274
     275        assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
     276        assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
     277        assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
     278
     279        # Apply Operator at time t=15.0
     280        domain.set_time(15.0)
     281        operator()
     282
     283        stage_ex = [ 1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,
     284                     1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,
     285                     7.0,  7.0,  7.0,  7.0,  7.0,  7.0,  7.0,  7.0,  1.0,  1.0,
     286                     1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  7.0,  7.0,  7.0,  7.0,
     287                     7.0,  7.0,  7.0,  7.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,
     288                     1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,
     289                     1.0,  1.0,  1.0,  1.0]
     290
     291
     292#        print domain.quantities['stage'].centroid_values
     293#        print domain.quantities['xmomentum'].centroid_values
     294#        print domain.quantities['ymomentum'].centroid_values
     295
     296        assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
     297        assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
     298        assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
     299
     300
     301
     302
    147303if __name__ == "__main__":
    148     suite = unittest.makeSuite(Test_set_operators, 'test')
     304    suite = unittest.makeSuite(Test_set_stage_operators, 'test')
    149305    runner = unittest.TextTestRunner(verbosity=1)
    150306    runner.run(suite)
  • trunk/anuga_core/source/anuga/pmesh/mesh_quadtree.py

    r7872 r8578  
    2424
    2525import numpy as num
     26import sys
    2627 
    2728
     
    4142        It contains optimisations and search patterns specific to meshes.
    4243    """
    43     def __init__(self, mesh):
     44    def __init__(self, mesh, verbose=False):
    4445        """Build quad tree for mesh.
    4546
     
    6061       
    6162        normals = mesh.get_normals()
    62        
     63
     64        if verbose :
     65            print '['+60*' '+']',
     66            sys.stdout.flush()
     67
     68        M = N/60
     69
    6370        # Check each triangle
    64         for i in range(N):
     71        for i in xrange(N):
     72
     73            if verbose and i%M == 0 :
     74                #restart_line()
     75                print '\r['+(i/M)*'.'+(60-(i/M))*' ' +']',
     76                sys.stdout.flush()
     77
    6578            i3 = 3*i
    6679            x0, y0 = V[i3, :]
     
    6881            x2, y2 = V[i3+2, :]
    6982
     83            #FIXME SR: Should save memory by just using triangle id!
    7084            node_data = [i, V[i3:i3+3, :], normals[i, :]]
    7185
     
    7488                             min([y0, y1, y2]), max([y0, y1, y2])), \
    7589                             node_data))
     90
     91        if verbose:
     92            print ''
    7693
    7794    def search_fast(self, point):
  • trunk/anuga_core/source/anuga/shallow_water/boundaries.py

    r8538 r8578  
    477477           
    478478        # Assign conserved quantities and return
    479         q = num.array([elevation + depth, xmomentum, ymomentum], num.Float)
     479        q = num.array([elevation + depth, xmomentum, ymomentum], num.float)
    480480        return q
    481481
     
    580580                q[j] += self.mean_stage
    581581        return q
     582
     583
     584
     585
     586
  • trunk/anuga_core/source/anuga/shallow_water/shallow_water_domain.py

    r8570 r8578  
    10421042
    10431043        elif self.compute_fluxes_method == 'tsunami':
    1044             # Using Gareth Davies well nbalanced scheme
     1044            # Using Gareth Davies well balanced scheme
    10451045            # Flux calculation and gravity incorporated in same
    10461046            # procedure
     
    10541054
    10551055            # Shortcuts
    1056             Stage = domain.quantities['stage']
    1057             Xmom = domain.quantities['xmomentum']
    1058             Ymom = domain.quantities['ymomentum']
    1059             Bed = domain.quantities['elevation']
     1056            Stage = self.quantities['stage']
     1057            Xmom = self.quantities['xmomentum']
     1058            Ymom = self.quantities['ymomentum']
     1059            Bed = self.quantities['elevation']
    10601060
    10611061            timestep = self.evolve_max_timestep
     
    11091109        if self.compute_fluxes_method == 'tsunami':
    11101110
     1111
     1112            # FIXME SR: Clean up code to just take self (domain) as
     1113            # input argument
    11111114            from swb2_domain_ext import protect
    11121115
     
    11201123            areas = self.areas
    11211124
    1122             protect(self.minimum_allowed_height, domain.maximum_allowed_speed,
    1123                 domain.epsilon, wc, wv, zc,zv, xmomc, ymomc, areas)
    1124 
    1125 
    1126             from swb2_domain_ext import extrapolate_second_order_edge_sw as extrapol2
     1125            protect(self.minimum_allowed_height, self.maximum_allowed_speed,
     1126                self.epsilon, wc, wv, zc,zv, xmomc, ymomc, areas)
     1127
     1128
     1129            from swb2_domain_ext import extrapolate_second_order_edge_sw as extrapol2_ext
    11271130
    11281131            # Shortcuts
     
    11321135            Elevation = self.quantities['elevation']
    11331136
    1134             extrapol2(self,
     1137            extrapol2_ext(self,
    11351138                  self.surrogate_neighbours,
    11361139                  self.number_of_boundaries,
     
    11541157
    11551158        else:
     1159            # Code for original method
    11561160            if self.use_edge_limiter:
    11571161                self.distribute_using_edge_limiter()
    11581162            else:
    1159                 #distribute_using_vertex_limiter(self)
    11601163                self.distribute_using_vertex_limiter()
    11611164
     
    11931196                raise Exception('Unknown order')
    11941197
    1195         balance_deep_and_shallow(self)
     1198        self.balance_deep_and_shallow()
    11961199
    11971200        # Compute edge values by interpolation
     
    12001203            Q.interpolate_from_vertices_to_edges()
    12011204
    1202     def distribute_using_vertex_limiter(domain):
     1205    def distribute_using_vertex_limiter(self):
    12031206        """Distribution from centroids to vertices specific to the SWW equation.
    12041207
     
    12211224
    12221225        # Remove very thin layers of water
    1223         domain.protect_against_infinitesimal_and_negative_heights()
     1226        self.protect_against_infinitesimal_and_negative_heights()
    12241227
    12251228        # Extrapolate all conserved quantities
    1226         if domain.optimised_gradient_limiter:
     1229        if self.optimised_gradient_limiter:
    12271230            # MH090605 if second order,
    12281231            # perform the extrapolation and limiting on
    12291232            # all of the conserved quantities
    12301233
    1231             if (domain._order_ == 1):
    1232                 for name in domain.conserved_quantities:
    1233                     Q = domain.quantities[name]
     1234            if (self._order_ == 1):
     1235                for name in self.conserved_quantities:
     1236                    Q = self.quantities[name]
    12341237                    Q.extrapolate_first_order()
    1235             elif domain._order_ == 2:
    1236                 domain.extrapolate_second_order_sw()
     1238            elif self._order_ == 2:
     1239                self.extrapolate_second_order_sw()
    12371240            else:
    12381241                raise Exception('Unknown order')
     
    12401243            # Old code:
    12411244            for name in domain.conserved_quantities:
    1242                 Q = domain.quantities[name]
    1243 
    1244                 if domain._order_ == 1:
     1245                Q = self.quantities[name]
     1246
     1247                if self._order_ == 1:
    12451248                    Q.extrapolate_first_order()
    1246                 elif domain._order_ == 2:
     1249                elif self._order_ == 2:
    12471250                    Q.extrapolate_second_order_and_limit_by_vertex()
    12481251                else:
     
    12501253
    12511254        # Take bed elevation into account when water heights are small
    1252         balance_deep_and_shallow(domain)
     1255        self.balance_deep_and_shallow()
    12531256
    12541257        # Compute edge values by interpolation
    1255         for name in domain.conserved_quantities:
    1256             Q = domain.quantities[name]
     1258        for name in self.conserved_quantities:
     1259            Q = self.quantities[name]
    12571260            Q.interpolate_from_vertices_to_edges()
    12581261
     
    12671270
    12681271            # shortcuts
    1269             wc = domain.quantities['stage'].centroid_values
    1270             wv = domain.quantities['stage'].vertex_values
    1271             zc = domain.quantities['elevation'].centroid_values
    1272             zv = domain.quantities['elevation'].vertex_values
    1273             xmomc = domain.quantities['xmomentum'].centroid_values
    1274             ymomc = domain.quantities['ymomentum'].centroid_values
    1275             areas = domain.areas
    1276 
    1277             protect(domain.minimum_allowed_height, domain.maximum_allowed_speed,
    1278                 domain.epsilon, wc, wv, zc,zv, xmomc, ymomc, areas)
     1272            wc = self.quantities['stage'].centroid_values
     1273            wv = self.quantities['stage'].vertex_values
     1274            zc = self.quantities['elevation'].centroid_values
     1275            zv = self.quantities['elevation'].vertex_values
     1276            xmomc = self.quantities['xmomentum'].centroid_values
     1277            ymomc = self.quantities['ymomentum'].centroid_values
     1278            areas = self.areas
     1279
     1280            protect(self.minimum_allowed_height, self.maximum_allowed_speed,
     1281                self.epsilon, wc, wv, zc,zv, xmomc, ymomc, areas)
    12791282
    12801283        else:
     
    12901293                    self.epsilon, wc, zc, xmomc, ymomc)
    12911294
    1292        
     1295
     1296    def balance_deep_and_shallow(self):
     1297        """Compute linear combination between stage as computed by
     1298        gradient-limiters limiting using w, and stage computed by
     1299        gradient-limiters limiting using h (h-limiter).
     1300        The former takes precedence when heights are large compared to the
     1301        bed slope while the latter takes precedence when heights are
     1302        relatively small.  Anything in between is computed as a balanced
     1303        linear combination in order to avoid numerical disturbances which
     1304        would otherwise appear as a result of hard switching between
     1305        modes.
     1306
     1307        Wrapper for C implementation
     1308        """
     1309
     1310        from shallow_water_ext import balance_deep_and_shallow \
     1311                                      as balance_deep_and_shallow_ext
     1312
     1313        # Shortcuts
     1314        wc = self.quantities['stage'].centroid_values
     1315        zc = self.quantities['elevation'].centroid_values
     1316        wv = self.quantities['stage'].vertex_values
     1317        zv = self.quantities['elevation'].vertex_values
     1318
     1319        # Momentums at centroids
     1320        xmomc = self.quantities['xmomentum'].centroid_values
     1321        ymomc = self.quantities['ymomentum'].centroid_values
     1322
     1323        # Momentums at vertices
     1324        xmomv = self.quantities['xmomentum'].vertex_values
     1325        ymomv = self.quantities['ymomentum'].vertex_values
     1326
     1327        balance_deep_and_shallow_ext(self,
     1328                                   wc, zc, wv, zv, wc,
     1329                                   xmomc, ymomc, xmomv, ymomv)
    12931330
    12941331    def update_other_quantities(self):
     
    19902027##            domain.epsilon, wc, zc, xmomc, ymomc)
    19912028
    1992 def balance_deep_and_shallow(domain):
    1993     """Compute linear combination between stage as computed by
    1994     gradient-limiters limiting using w, and stage computed by
    1995     gradient-limiters limiting using h (h-limiter).
    1996     The former takes precedence when heights are large compared to the
    1997     bed slope while the latter takes precedence when heights are
    1998     relatively small.  Anything in between is computed as a balanced
    1999     linear combination in order to avoid numerical disturbances which
    2000     would otherwise appear as a result of hard switching between
    2001     modes.
    2002 
    2003     Wrapper for C implementation
    2004     """
    2005 
    2006     from anuga.shallow_water.shallow_water_ext import balance_deep_and_shallow \
    2007                                   as balance_deep_and_shallow_c
    2008 
    2009     # Shortcuts
    2010     wc = domain.quantities['stage'].centroid_values
    2011     zc = domain.quantities['elevation'].centroid_values
    2012     wv = domain.quantities['stage'].vertex_values
    2013     zv = domain.quantities['elevation'].vertex_values
    2014 
    2015     # Momentums at centroids
    2016     xmomc = domain.quantities['xmomentum'].centroid_values
    2017     ymomc = domain.quantities['ymomentum'].centroid_values
    2018 
    2019     # Momentums at vertices
    2020     xmomv = domain.quantities['xmomentum'].vertex_values
    2021     ymomv = domain.quantities['ymomentum'].vertex_values
    2022 
    2023     balance_deep_and_shallow_c(domain,
    2024                                wc, zc, wv, zv, wc,
    2025                                xmomc, ymomc, xmomv, ymomv)
     2029
    20262030
    20272031
  • trunk/anuga_core/source/anuga/shallow_water/test_shallow_water_domain.py

    r8539 r8578  
    70127012        # Large test set revealed one problem
    70137013        points_file = os.path.join(path, 'test_points_large.csv')
     7014
     7015        domain.set_quantity('elevation', filename=points_file,
     7016                                use_cache=False, verbose=verbose)
    70147017        try:
    70157018            domain.set_quantity('elevation', filename=points_file,
Note: See TracChangeset for help on using the changeset viewer.