Changeset 531


Ignore:
Timestamp:
Nov 12, 2004, 3:56:50 PM (20 years ago)
Author:
duncan
Message:

basic quantity.get_values as a list of triangles

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

Legend:

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

    r529 r531  
    147147            self.interpolate()
    148148           
     149         
     150    def get_values(self, location='vertices', indexes = None):
     151        """get values for quantity
     152
     153        return X, Compatible list, Numeric array (see below)
     154        location: Where values are to be stored.
     155                  Permissible options are: vertices, edges, centroid
     156                  Default is "vertices"
     157
     158        In case of location == 'centroid' the dimension values must
     159        be a list of a Numerical array of length N, N being the number
     160        of elements in the mesh. Otherwise it must be of dimension Nx3
     161
     162        The values will be stored in elements following their
     163        internal ordering.
     164
     165        If values are described a function, it will be evaluated at specified points
     166
     167        If selected location is vertices, values for centroid and edges
     168        will be assigned interpolated values.
     169        In any other case, only values for the specified locations
     170        will be assigned and the others will be left undefined.
     171        """
     172        from Numeric import take
     173
     174        if location not in ['vertices', 'centroids', 'edges']:
     175            msg = 'Invalid location: %s' %location
     176            raise msg         
     177       
     178        if (indexes ==  None):
     179            indexes = range(len(self))
     180           
     181        if location == 'centroids':
     182            return take(self.centroid_values,indexes)                       
     183        elif location == 'edges':
     184            return take(self.edge_values,indexes)
     185        else:
     186            return take(self.vertex_values,indexes)
    149187
    150188
  • inundation/ga/storm_surge/pyvolution/test_quantity.py

    r517 r531  
    690690        quantity.interpolate()
    691691        assert allclose(quantity.centroid_values, [10,100,3,400,5,999])
     692
     693       
     694    def test_getting_some_vertex_values(self):
     695        """
     696        get values based on triangle lists.
     697        """
     698        from mesh_factory import rectangular
     699        from shallow_water import Domain
     700        from Numeric import zeros, Float
     701       
     702        #Create basic mesh
     703        points, vertices, boundary = rectangular(1, 3)
     704
     705        #Create shallow water domain
     706        domain = Domain(points, vertices, boundary)
     707        #print "domain.number_of_elements ",domain.number_of_elements
     708        quantity = Quantity(domain,[[1,1,1],[2,2,2],[3,3,3],
     709                                    [4,4,4],[5,5,5],[6,6,6]])
     710        value = [7]
     711        indexes = [1]
     712        quantity.set_values(value,
     713                                  location = 'centroids',
     714                                  indexes = indexes)
     715        #print "quantity.centroid_values",quantity.centroid_values
     716        #print "quantity.get_values(location = 'centroids') ",\
     717        #      quantity.get_values(location = 'centroids')
     718        assert allclose(quantity.centroid_values,
     719                        quantity.get_values(location = 'centroids'))
     720
     721       
     722        value = [[15,20,25]]
     723        quantity.set_values(value, indexes = indexes)
     724        #print "1 quantity.vertex_values",quantity.vertex_values
     725        assert allclose(quantity.vertex_values, quantity.get_values())
     726
     727        assert allclose(quantity.edge_values,
     728                        quantity.get_values(location = 'edges'))
     729
     730        # get a subset of elements
     731        subset = quantity.get_values(location='centroids', indexes=[0,5])
     732        answer = [quantity.centroid_values[0],quantity.centroid_values[5]]
     733        assert allclose(subset, answer)
     734
     735
     736        subset = quantity.get_values(location='edges', indexes=[0,5])
     737        answer = [quantity.edge_values[0],quantity.edge_values[5]]
     738        #print "subset",subset
     739        #print "answer",answer
     740        assert allclose(subset, answer)
     741
     742        subset = quantity.get_values( indexes=[1,5])
     743        answer = [quantity.vertex_values[1],quantity.vertex_values[5]]
     744        #print "subset",subset
     745        #print "answer",answer
     746        assert allclose(subset, answer)
     747       
     748##############################################
     749
     750        values = [10,100,50]
     751        quantity.set_values(values, indexes = [0,1,5])
     752        #print "2 quantity.vertex_values",quantity.vertex_values
     753        assert allclose(quantity.vertex_values[0], [10,10,10])
     754        assert allclose(quantity.vertex_values[5], [50,50,50])
     755        quantity.interpolate()
     756        #print "quantity.centroid_values",quantity.centroid_values
     757        assert allclose(quantity.centroid_values, [10,100,3,4,5,50])
     758       
     759        values = [[31,30,29],[400,400,400],[1000,999,998]]
     760        quantity.set_values(values, indexes = [3,3,5])
     761        quantity.interpolate()
     762        assert allclose(quantity.centroid_values, [10,100,3,400,5,999])
     763       
    692764#-------------------------------------------------------------
    693765if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.