Changeset 4579


Ignore:
Timestamp:
Jul 3, 2007, 1:30:49 PM (17 years ago)
Author:
ole
Message:

Thoughts towards allowing 'polygon' to be specified in set_quantity.
This is far from done.

Location:
anuga_core/source/anuga
Files:
3 edited

Legend:

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

    r4569 r4579  
    179179                   alpha = None,
    180180                   location = 'vertices',
     181                   polygon = None,
    181182                   indices = None,
    182183                   verbose = False,
     
    262263                  will be left undefined.
    263264
     265
     266        polygon: Restrict update of quantity to locations that fall
     267                 inside polygon. Polygon works by selecting indices
     268                 and calling set_values recursively.
     269
     270        indices: Restrict update of quantity to locations that are
     271                 identified by indices (e.g. node ids if location
     272                 is 'vertices')       
     273       
    264274        verbose: True means that output to stdout is generated
    265275
     
    278288        from types import FloatType, IntType, LongType, ListType, NoneType
    279289        from Numeric import ArrayType
     290
     291
     292        # Polygon situation
     293        #if polygon is not None:
     294        #    if indices is not None:
     295        #        msg = 'Only one of polygon and indices can be specified'
     296        #        raise Exception, msg
     297        #
     298        #    Need to get candidate points. I think we should
     299        #    simplify this whole thing a bit. Do we really need location?
     300        #    point_indices = inside_polygon(points, polygon)
     301
     302
    280303
    281304        #General input checks
     
    388411        """
    389412
     413        # FIXME (Ole): Somehow indices refer to centroids
     414        # rather than vertices as default. See unit test
     415        # test_set_vertex_values_using_general_interface_with_subset(self):
     416       
    390417
    391418        if location == 'centroids':
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py

    r4252 r4579  
    377377
    378378
     379    def test_set_vertex_values_using_general_interface_with_subset(self):
     380        """test_set_vertex_values_using_general_interface_with_subset(self):
     381        Test that indices and polygon works
     382        """
     383       
     384        quantity = Quantity(self.mesh4)
     385
     386
     387        quantity.set_values([0,2,3,5], indices=[0,2,3,5])
     388        assert allclose(quantity.vertex_values,
     389                        [[0,0,2], [0,2,0], [0,2,5], [3,0,0]])
     390
     391
     392        # Constant
     393        quantity.set_values(0.0)
     394        quantity.set_values(3.14, indices=[0,2], location='vertices')
     395
     396        # Indices refer to triangle numbers here - not vertices (why?)
     397        assert allclose(quantity.vertex_values,
     398                        [[3.14,3.14,3.14], [0,0,0],
     399                         [3.14,3.14,3.14], [0,0,0]])       
     400       
     401
     402
     403        # FIXME: Not done yet
     404        # Now try with polygon (pick points where y>2)
     405        #polygon = [[0,2.1], [4,2.1], [4,7], [0,7]]
     406        #quantity.set_values(0.0)
     407        #quantity.set_values(3.14, polygon=polygon, location='vertices')
     408        #
     409        #print quantity.vertex_values
     410        #
     411        ## Indices refer to triangle numbers here - not vertices (why?)
     412        #assert allclose(quantity.vertex_values,
     413        #                [[0,0,0], [0,0,0], [0,0,0],
     414        #                 [3.14,3.14,3.14]])               
     415
     416       
    379417
    380418
  • anuga_core/source/anuga/utilities/polygon.py

    r4574 r4579  
    622622        return z
    623623
    624 def read_polygon(filename,split=','):
     624
     625def read_polygon(filename, split=','):
    625626    """Read points assumed to form a polygon.
    626627       There must be exactly two numbers in each line separated by a comma.
     
    639640    return polygon
    640641
    641 def populate_polygon(polygon, number_of_points, seed = None, exclude = None):
     642
     643def populate_polygon(polygon, number_of_points, seed=None, exclude=None):
    642644    """Populate given polygon with uniformly distributed points.
    643645
     
    694696
    695697    return points
     698
    696699
    697700def point_in_polygon(polygon, delta=1e-8):
     
    739742    return point
    740743
     744
    741745def number_mesh_triangles(interior_regions, bounding_poly, remainder_res):
    742     """Calcalutes the approximate number of triangles inside the bounding polygon
    743     and the other interior regions
     746    """Calcalutes the approximate number of triangles inside the
     747    bounding polygon and the other interior regions
    744748
    745749    Polygon areas are converted to square Kms
Note: See TracChangeset for help on using the changeset viewer.