Changeset 4592


Ignore:
Timestamp:
Jul 5, 2007, 9:43:02 AM (17 years ago)
Author:
ole
Message:

Allowed set_quantity restriction by polygon to observe geo_referencing.

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

Legend:

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

    r4515 r4592  
    769769        return self.lone_vertices
    770770
    771     def get_centroid_coordinates(self):
     771    def get_centroid_coordinates(self, absolute=False):
    772772        """Return all centroid coordinates.
    773773        Return all centroid coordinates for all triangles as an Nx2 array
    774774        (ordered as x0, y0 for each triangle)
    775         """
    776         return self.centroid_coordinates
    777        
    778        
     775
     776        Boolean keyword argument absolute determines whether coordinates
     777        are to be made absolute by taking georeference into account
     778        Default is False as many parts of ANUGA expects relative coordinates.
     779        """
     780
     781        V = self.centroid_coordinates
     782        if absolute is True:
     783            if not self.geo_reference.is_absolute():
     784                V = self.geo_reference.get_absolute(V)
     785           
     786        return V
     787
     788       
    779789    def get_radii(self):
    780790        """Return all radii.
  • anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py

    r4584 r4592  
    317317
    318318
    319             points = self.domain.get_centroid_coordinates()
     319            points = self.domain.get_centroid_coordinates(absolute=True)
    320320            indices = inside_polygon(points, polygon)
    321321           
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py

    r4584 r4592  
    433433            raise msg
    434434
    435            
     435
     436
     437
     438
     439    def test_set_vertex_values_using_general_interface_subset_and_geo(self):
     440        """test_set_vertex_values_using_general_interface_with_subset(self):
     441        Test that indices and polygon works using georeferencing
     442        """
     443       
     444        quantity = Quantity(self.mesh4)
     445        G = Geo_reference(56, 10, 100)
     446        quantity.domain.geo_reference = G
     447
     448        #print quantity.domain.get_nodes(absolute=True)
     449
     450
     451        # Constant
     452        quantity.set_values(0.0)
     453        quantity.set_values(3.14, indices=[0,2], location='vertices')
     454
     455        # Indices refer to triangle numbers here - not vertices (why?)
     456        assert allclose(quantity.vertex_values,
     457                        [[3.14,3.14,3.14], [0,0,0],
     458                         [3.14,3.14,3.14], [0,0,0]])       
     459       
     460
     461
     462        # Now try with polygon (pick points where y>2)
     463        polygon = array([[0,2.1], [4,2.1], [4,7], [0,7]])
     464        polygon += [G.xllcorner, G.yllcorner]
     465       
     466        quantity.set_values(0.0)
     467        quantity.set_values(3.14, polygon=polygon)
     468       
     469        assert allclose(quantity.vertex_values,
     470                        [[0,0,0], [0,0,0], [0,0,0],
     471                         [3.14,3.14,3.14]])               
     472
     473
     474        # Another polygon (pick triangle 1 and 2 (rightmost triangles)
     475        polygon = array([[2.1, 0.0], [3.5,0.1], [2,2.2], [0.2,2]])
     476        polygon += [G.xllcorner, G.yllcorner]
     477       
     478        quantity.set_values(0.0)
     479        quantity.set_values(3.14, polygon=polygon)
     480
     481        assert allclose(quantity.vertex_values,
     482                        [[0,0,0],
     483                         [3.14,3.14,3.14],
     484                         [3.14,3.14,3.14],                         
     485                         [0,0,0]])               
     486
     487
    436488
    437489    def test_set_values_using_fit(self):
Note: See TracChangeset for help on using the changeset viewer.