Changeset 4583


Ignore:
Timestamp:
Jul 4, 2007, 11:34:47 AM (17 years ago)
Author:
ole
Message:

Added code for restricting constant values to a polygon in set_quantity

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

Legend:

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

    r4579 r4583  
    1919
    2020from anuga.utilities.numerical_tools import ensure_numeric, is_scalar
     21from anuga.utilities.polygon import inside_polygon
     22
    2123from anuga.geospatial_data.geospatial_data import Geospatial_data
    2224from anuga.fit_interpolate.fit import fit_to_mesh
     
    267269                 inside polygon. Polygon works by selecting indices
    268270                 and calling set_values recursively.
     271                 Polygon mode has only been implemented for
     272                 constant values so far.
    269273
    270274        indices: Restrict update of quantity to locations that are
     
    290294
    291295
    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)
     296        # Treat special case: Polygon situation
     297        # FIXME (Ole): This needs to be generalised and
     298        # perhaps the notion of location and indices simplified
     299        if polygon is not None:
     300            if indices is not None:
     301                msg = 'Only one of polygon and indices can be specified'
     302                raise Exception, msg
     303
     304
     305            msg = 'With polygon selected, set_quantity must provide '
     306            msg += 'the keyword numeric and it must (currently) be '
     307            msg += 'a constant.'
     308            if numeric is None:
     309                raise Exception, msg           
     310            else:
     311                # Check that numeric is as constant
     312                assert type(numeric) in [FloatType, IntType, LongType], msg
     313
     314
     315            location = 'centroids'
     316
     317
     318            points = self.domain.get_centroid_coordinates()
     319            indices = inside_polygon(points, polygon)
     320           
     321            self.set_values_from_constant(numeric,
     322                                          location, indices, verbose)
     323           
     324            self.extrapolate_first_order()
     325            return
     326       
     327       
     328
    301329
    302330
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py

    r4579 r4583  
    401401
    402402
    403         # FIXME: Not done yet
    404403        # 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]])               
     404        polygon = [[0,2.1], [4,2.1], [4,7], [0,7]]
     405        quantity.set_values(0.0)
     406        quantity.set_values(3.14, polygon=polygon, location='vertices')
     407       
     408        # Indices refer to triangle numbers here - not vertices (why?)
     409        assert allclose(quantity.vertex_values,
     410                        [[0,0,0], [0,0,0], [0,0,0],
     411                         [3.14,3.14,3.14]])               
    415412
    416413       
Note: See TracChangeset for help on using the changeset viewer.