Changeset 1928


Ignore:
Timestamp:
Oct 14, 2005, 5:08:29 PM (18 years ago)
Author:
ole
Message:

Made create_quantity_from_expression a method

Location:
inundation/pyvolution
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/domain.py

    r1924 r1928  
    155155        """
    156156
    157         #FIXME (Ole): Allow new quantities
    158 
    159        
     157        #FIXME (Ole): Allow new quantities here
    160158        #from quantity import Quantity, Conserved_quantity
    161 
    162159        #Create appropriate quantity object
    163160        ##if name in self.conserved_quantities:
     
    172169            del kwargs['expression']           
    173170
    174             Q = create_quantity_from_expression(self, expression)
    175 
     171            Q = self.create_quantity_from_expression(expression)
    176172            kwargs['quantity'] = Q
    177173
    178            
    179            
    180 
     174
     175        #Assign values   
    181176        self.quantities[name].set_values(*args, **kwargs)
    182177
     
    200195
    201196
     197    def create_quantity_from_expression(self, expression):
     198        """Create new quantity from other quantities using arbitrary expression
     199
     200        Combine existing quantities in domain using expression and return
     201        result as a new quantity.
     202
     203        Note, the new quantity could e.g. be used in set_quantity
     204
     205        Valid expressions are limited to operators defined in class Quantity
     206
     207        Example:
     208     
     209   
     210        """
     211
     212        from util import apply_expression_to_dictionary
     213        return apply_expression_to_dictionary(expression, self.quantities)
     214   
    202215
    203216
     
    707720
    708721
    709 def create_quantity_from_expression(domain, expression):
    710     """Create new quantity from other quantities using arbitrary expression
    711 
    712     Combine existing quantities in domain using expression and return
    713     result as a new quantity.
    714 
    715     Note, the new quantity could e.g. be used in set_quantity
    716 
    717     Valid expressions are limited to operators defined in class Quantity
    718 
    719     Example:
    720      
    721    
    722     """
    723 
    724     from util import apply_expression_to_dictionary
    725     return apply_expression_to_dictionary(expression, domain.quantities)
    726    
    727722
    728723
  • inundation/pyvolution/quantity.py

    r1924 r1928  
    255255        msg = 'Exactly one of the arguments '+\
    256256              'numeric, quantity, function, points, or filename '+\
    257               'must be present. L = %s' %str(L)
     257              'must be present.'
    258258        assert L.count(None) == len(L)-1, msg
    259259
  • inundation/pyvolution/test_domain.py

    r1924 r1928  
    177177
    178178        expression = 'stage - elevation'
    179         Q = create_quantity_from_expression(domain, expression)
     179        Q = domain.create_quantity_from_expression(expression)
    180180
    181181        assert allclose(Q.vertex_values, [[2,3,4], [6,6,6],
     
    183183
    184184        expression = '(xmomentum*xmomentum + ymomentum*ymomentum)**0.5'
    185         Q = create_quantity_from_expression(domain, expression)
     185        Q = domain.create_quantity_from_expression(expression)
    186186
    187187        X = domain.quantities['xmomentum'].vertex_values
Note: See TracChangeset for help on using the changeset viewer.