Changeset 4702


Ignore:
Timestamp:
Sep 5, 2007, 10:06:48 AM (17 years ago)
Author:
ole
Message:

Work on ticket:192 (and untabify)

Location:
anuga_core/source/anuga/abstract_2d_finite_volumes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/domain.py

    r4701 r4702  
    573573        # FIXME (Ole): This is under construction. See ticket:192
    574574
     575        from anuga.abstract_2d_finite_volumes.util import\
     576             apply_expression_to_dictionary       
     577
    575578        if q is None:
    576579            self.quantities_to_be_monitored = None
     
    582585            q = [q] # Turn argument into a list
    583586
    584         # Check correcness
     587        # Check correcness and initialise
     588        self.quantities_to_be_monitored = {}
    585589        for quantity_name in q:
    586590            msg = 'Quantity %s is not a valid conserved quantity'\
    587591                  %quantity_name
    588592           
    589             assert quantity_name in self.conserved_quantities, msg
     593
     594            if not quantity_name in self.quantities:
     595                # See if this expression is valid
     596                apply_expression_to_dictionary(quantity_name, self.quantities)
     597
     598            # Initialise extrema
     599            self.quantities_to_be_monitored[quantity_name] = [None, None]
     600           
    590601
    591602        if polygon is not None:
     
    598609
    599610
    600         self.quantities_to_be_monitored = q
     611       
    601612        self.monitor_polygon = polygon
    602613        self.monitor_time_interval = time_interval       
     
    694705
    695706            x, y = self.get_centroid_coordinates()[k]
    696             radius = self.get_radii()[k]
    697             area = self.get_areas()[k]     
    698             max_speed = self.max_speed[k]          
     707            radius = self.get_radii()[k]
     708            area = self.get_areas()[k]     
     709            max_speed = self.max_speed[k]          
    699710
    700711            msg += '  Triangle #%d with centroid (%.4f, %.4f), ' %(k, x, y)
    701             msg += 'area = %.4f and radius = %.4f ' %(area, radius)
     712            msg += 'area = %.4f and radius = %.4f ' %(area, radius)
    702713            msg += 'had the largest computed speed: %.6f m/s ' %(max_speed)
    703             if max_speed > 0.0:
     714            if max_speed > 0.0:
    704715                msg += '(timestep=%.6f)\n' %(radius/max_speed)
    705716            else:
    706                 msg += '(timestep=%.6f)\n' %(0)    
     717                msg += '(timestep=%.6f)\n' %(0)    
    707718           
    708719            # Report all quantity values at vertices
     
    10151026        """Go through list of boundary objects and update boundary values
    10161027        for all conserved quantities on boundary.
    1017         It is assumed that the ordering of conserved quantities is
    1018         consistent between the domain and the boundary object, i.e.
    1019         the jth element of vector q must correspond to the jth conserved
    1020         quantity in domain.
     1028        It is assumed that the ordering of conserved quantities is
     1029        consistent between the domain and the boundary object, i.e.
     1030        the jth element of vector q must correspond to the jth conserved
     1031        quantity in domain.
    10211032        """
    10221033
     
    10241035        #FIXME: Boundary objects should not include ghost nodes.
    10251036        for i, ((vol_id, edge_id), B) in enumerate(self.boundary_objects):
    1026             if B is None:
    1027                 print 'WARNING: Ignored boundary segment %d (None)'
    1028             else:
     1037            if B is None:
     1038                print 'WARNING: Ignored boundary segment %d (None)'
     1039            else:
    10291040                q = B.evaluate(vol_id, edge_id)
    10301041
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py

    r4670 r4702  
    192192
    193193
    194 
     194    def test_set_quanitities_to_be_monitored(self):
     195        """test_set_quanitities_to_be_monitored
     196        """
     197
     198        a = [0.0, 0.0]
     199        b = [0.0, 2.0]
     200        c = [2.0,0.0]
     201        d = [0.0, 4.0]
     202        e = [2.0, 2.0]
     203        f = [4.0,0.0]
     204
     205        points = [a, b, c, d, e, f]
     206        #bac, bce, ecf, dbe, daf, dae
     207        vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4]]
     208
     209
     210        domain = Domain(points, vertices, boundary=None,
     211                        conserved_quantities =\
     212                        ['stage', 'xmomentum', 'ymomentum'],
     213                        other_quantities = ['elevation', 'friction', 'depth'])
     214
     215
     216        assert domain.quantities_to_be_monitored is None
     217        domain.set_quantities_to_be_monitored(['stage', 'stage-elevation'])
     218        assert len(domain.quantities_to_be_monitored) == 2
     219        assert domain.quantities_to_be_monitored.has_key('stage')
     220        assert domain.quantities_to_be_monitored.has_key('stage-elevation')
     221        assert domain.quantities_to_be_monitored['stage'][0] == None
     222        assert domain.quantities_to_be_monitored['stage'][1] == None               
     223       
     224
     225        # Check that invalid request are dealt with
     226        try:
     227            domain.set_quantities_to_be_monitored(['yyyyy'])       
     228        except:
     229            pass
     230        else:
     231            msg = 'Should have caught illegal quantity'
     232            raise Exception, msg
     233
     234        try:
     235            domain.set_quantities_to_be_monitored(['stage-xx'])       
     236        except NameError:
     237            pass
     238        else:
     239            msg = 'Should have caught illegal quantity'
     240            raise Exception, msg       
    195241
    196242    def test_set_quantity_from_expression(self):
Note: See TracChangeset for help on using the changeset viewer.