Ignore:
Timestamp:
Jun 9, 2010, 5:34:19 PM (13 years ago)
Author:
steve
Message:

Almost got the unit test working for 1d quantity

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_work/development/anuga_1d/quantity.py

    r7793 r7815  
    271271            self.centroid_values[i] = (v0 + v1)/2.0
    272272
     273
     274
     275
    273276    def set_values(self, X, location='vertices'):
    274277        """Set values for quantity
     
    294297        """
    295298
    296         if location not in ['vertices', 'centroids']:
    297             msg = 'Invalid location: %s, (possible choices vertices, centroids)' %location
     299        if location not in ['vertices', 'centroids', 'unique_vertices']:
     300            msg = 'Invalid location: %s, (possible choices vertices, centroids, unique_vertices)' %location
    298301            raise msg
    299302
     
    309312         
    310313        elif type(X) in [types.FloatType, types.IntType, types.LongType]:
    311             if location == 'centroids':
    312                 self.centroid_values[:] = X
    313             else:
    314                 self.vertex_values[:] = X
     314           
     315            self.centroid_values[:,] = float(X)
     316            self.vertex_values[:,:] = float(X)
     317
     318        elif isinstance(X, Quantity):
     319            self.set_array_values(X.vertex_values, location)
    315320
    316321        else:
     
    318323            self.set_array_values(X, location)
    319324
    320         if location == 'vertices':
    321             #Intialise centroid and edge values
     325        if location == 'vertices' or location == 'unique_vertices':
     326            #Intialise centroid
    322327            self.interpolate()
     328
     329        if location == 'centroid':
     330            self.extrapolate_first_order()
    323331
    324332
     
    353361        values: Numeric array
    354362        location: Where values are to be stored.
    355                   Permissible options are: vertices, centroid, edges
     363                  Permissible options are: vertices, centroid, unique_vertices
    356364                  Default is "vertices"
    357365
    358366        In case of location == 'centroid' the dimension values must
    359367        be a list of a Numerical array of length N, N being the number
    360         of elements in the mesh. Otherwise it must be of dimension Nx2
     368        of elements in the mesh. If location == 'unique_vertices' the
     369        dimension values must be a list or a Numeric array of length N+1.
     370        Otherwise it must be of dimension Nx2
    361371
    362372        The values will be stored in elements following their
     
    375385        N = self.centroid_values.shape[0]
    376386
    377         msg = 'Number of values must match number of elements'
    378         assert values.shape[0] == N, msg
    379387
    380388        if location == 'centroids':
     389            msg = 'Number of values must match number of elements'
     390            assert values.shape[0] == N, msg
    381391            assert len(values.shape) == 1, 'Values array must be 1d'
    382             self.centroid_values = values
    383         #elif location == 'edges':
    384         #    assert len(values.shape) == 2, 'Values array must be 2d'
    385         #    msg = 'Array must be N x 2'
    386         #    self.edge_values = values
    387         else:
     392
     393            for i in range(N):
     394                self.centroid_values[i] = values[i]
     395
     396            self.vertex_values[:,0] = values
     397            self.vertex_values[:,1] = values
     398 
     399        if location == 'vertices':
     400            msg = 'Number of values must match number of elements'
     401            assert values.shape[0] == N, msg
    388402            assert len(values.shape) == 2, 'Values array must be 2d'
    389403            msg = 'Array must be N x 2'
    390404            assert values.shape[1] == 2, msg
    391405
    392             self.vertex_values[:] = values
     406            self.vertex_values[:,:] = values[:,:]
     407
     408        if location == 'unique_vertices':
     409            msg = 'Number of values must match number of elements +1'
     410            assert values.shape[0] == N+1, msg
     411            assert len(values.shape) == 1, 'Values array must be 1d'
     412
     413            self.vertex_values[:,0] = values[0:-1]
     414            self.vertex_values[:,1] = values[1:N+1] 
     415
     416
     417           
    393418
    394419
Note: See TracChangeset for help on using the changeset viewer.