Ignore:
Timestamp:
Nov 8, 2006, 5:35:23 PM (17 years ago)
Author:
ole
Message:

One large step towards major cleanup. This has mainly to do with
the way vertex coordinates are handled internally.

File:
1 edited

Legend:

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

    r3928 r3945  
    1616
    1717from Numeric import array, zeros, Float, less, concatenate, NewAxis, argmax, allclose
    18 from anuga.utilities.numerical_tools import ensure_numeric
     18from anuga.utilities.numerical_tools import ensure_numeric, is_scalar
    1919
    2020class Quantity:
     
    558558            is_subset = True
    559559
     560
     561        # FIXME (Ole): Now we can compute the arrays once and for all
     562        # for both centroids and vertices and the use set_values_from_array
     563
    560564        if location == 'centroids':
    561             P = take(self.domain.centroid_coordinates, indices)
     565            V = take(self.domain.centroid_coordinates, indices)
    562566            if is_subset:
    563                 self.set_values(f(P[:,0], P[:,1]),
     567                self.set_values(f(V[:,0], V[:,1]),
    564568                                location = location,
    565569                                indices = indices)
    566570            else:
    567                 self.set_values(f(P[:,0], P[:,1]), location = location)
     571                self.set_values(f(V[:,0], V[:,1]), location = location)
    568572        elif location == 'vertices':
    569             P = self.domain.vertex_coordinates
     573            V = self.domain.get_vertex_coordinates()
     574
     575            x = V[:,0]; y = V[:,1];                     
     576            values = f(x, y)
     577
     578            if is_scalar(values):
     579                # Function returned a constant value
     580                self.set_values_from_constant(values,
     581                                              location, indices, verbose)
     582                return
     583               
     584           
    570585            if is_subset:
    571586                #Brute force
    572                 for e in indices:
    573                     for i in range(3):
    574                         self.vertex_values[e,i] = f(P[e,2*i], P[e,2*i+1])
     587                for i in indices:
     588                    for j in range(3):
     589                        self.vertex_values[i,j] = values[3*i+j]
    575590            else:
    576                 for i in range(3):
    577                     self.vertex_values[:,i] = f(P[:,2*i], P[:,2*i+1])
     591                for j in range(3):
     592                    self.vertex_values[:,j] = values[j::3]
    578593        else:
    579594            raise 'Not implemented: %s' %location
     
    625640            raise ms
    626641
    627         coordinates = self.domain.coordinates
    628         triangles = self.domain.triangles
     642        coordinates = self.domain.get_nodes()
     643        triangles = self.domain.triangles      #FIXME
    629644
    630645
     
    910925        elif location == 'unique vertices':
    911926            if (indices ==  None):
    912                 indices=range(self.domain.coordinates.shape[0])
     927                indices=range(self.domain.number_of_nodes)
    913928            vert_values = []
    914929            #Go through list of unique vertices
     
    958973
    959974        if indices == None:
    960             assert A.shape[0] == self.domain.coordinates.shape[0]
     975            assert A.shape[0] == self.domain.get_nodes().shape[0]
    961976            vertex_list = range(A.shape[0])
    962977        else:
     
    10851100
    10861101            if xy is True:
    1087                 X = self.domain.coordinates[:,0].astype(precision)
    1088                 Y = self.domain.coordinates[:,1].astype(precision)
     1102                X = self.domain.get_nodes()[:,0].astype(precision)
     1103                Y = self.domain.get_nodes()[:,1].astype(precision)
    10891104
    10901105                return X, Y, A, V
     
    13891404    from Numeric import zeros, Float
    13901405
    1391     N = len(quantity.domain)
     1406    N = quantity.domain.number_of_nodes
    13921407
    13931408    beta_w = quantity.domain.beta_w
Note: See TracChangeset for help on using the changeset viewer.