Changeset 1108


Ignore:
Timestamp:
Mar 18, 2005, 4:21:58 PM (20 years ago)
Author:
duncan
Message:

add_quantities added

Location:
inundation/ga/storm_surge/pyvolution
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/region.py

    r715 r1108  
    9191                                location=self.location)
    9292
     93class Add_quantities(Region):
     94    """
     95    Will add a value to the current quantity value.
     96    """
     97   
     98    def __init__(self, tag, quantity_answer, adding_quantity, location='vertices'):
     99        #I have to get this going!
     100        #Region.__init__(self)
     101        self.tag = tag
     102        self.quantity_answer = quantity_answer
     103        self.adding_quantity = adding_quantity
     104        self.location = location
     105
     106    def __repr__(self):
     107        pass
     108   
     109    def __call__(self, tag, elements, domain):
     110        """
     111        """   
     112        if tag == self.tag:
     113           
     114            new_values = domain.get_quantity(self.quantity_answer,
     115                          indexes=self.build_indexes(elements, domain),
     116                          location=self.location) \
     117                          + domain.get_quantity(self.adding_quantity,
     118                          indexes=self.build_indexes(elements, domain),
     119                          location=self.location)
     120            domain.set_quantity(self.quantity_answer, new_values,
     121                                indexes=self.build_indexes(elements, domain),
     122                                location=self.location)
     123
    93124
    94125class Stage_no_less_than_elevation(Region):
  • inundation/ga/storm_surge/pyvolution/test_region.py

    r1018 r1108  
    1212def add_x_y(x, y):
    1313    return x+y
     14
     15def give_me_23(x, y):
     16    return 23.0
    1417
    1518class Test_Region(unittest.TestCase):
     
    9093                         [ 11.0,  11.0,  11.0]])
    9194
     95       
     96        domain.set_quantity('elevation', 10.0)
     97        domain.set_quantity('stage', give_me_23)
     98        domain.set_region(Add_quantities('top', 'elevation','stage'))
     99        #print domain.quantities['elevation'].get_values()
     100        assert allclose(domain.quantities['elevation'].get_values(),
     101                        [[ 10., 10., 10.],
     102                         [ 10., 10., 10.],
     103                         [ 10., 10., 10.],
     104                         [ 10., 10., 10.],
     105                         [ 33.,  33.0,  33.],
     106                         [ 33.0,  33.,  33.]])
     107       
    92108    def test_unique_vertices(self):
    93109        """
Note: See TracChangeset for help on using the changeset viewer.