Changeset 8505


Ignore:
Timestamp:
Aug 12, 2012, 6:36:21 PM (13 years ago)
Author:
steve
Message:

Small memory gains by changing from flatten() to flat

Location:
trunk/anuga_core/source/anuga
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/general_mesh.py

    r8503 r8505  
    363363
    364364        # Build structure listing which triangles belong to which node.
    365         if verbose: log.critical('Building inverted triangle structure')
     365        if verbose: log.critical('General Mesh: Building inverted triangle structure')
    366366        self.build_inverted_triangle_structure()
    367367       
     
    774774        #number_of_triangles_per_node = num.zeros(self.number_of_nodes, num.int)
    775775
    776         number_of_triangles_per_node = num.bincount(self.triangles.flatten())
     776        number_of_triangles_per_node = num.bincount(self.triangles.flat)
    777777
    778778        number_of_lone_nodes = self.number_of_nodes - len(number_of_triangles_per_node)
     
    796796        # find vertices associated with a node.
    797797        # ie There are  number_of_triangles_per_node[i] vertices
    798         vertex_value_indices = num.argsort(self.triangles.flatten())
     798        vertex_value_indices = num.argsort(self.triangles.flat)
     799        #vertex_value_indices = num.argsort(self.triangles.flatten())
     800
     801#        node_index = num.zeros((self.number_of_nodes)+1, dtype = num.int)
     802#        node_index[0] = 0
     803#        for i in xrange(self.number_of_nodes):
     804#            node_index[i+1] = node_index[i] + number_of_triangles_per_node[i]
    799805
    800806        node_index = num.zeros((self.number_of_nodes)+1, dtype = num.int)
    801 
    802         k = 0
    803         node_index[0] = 0
    804         for i in range(self.number_of_nodes):
    805             node_index[i+1] = node_index[i] + number_of_triangles_per_node[i]
     807        node_index[1:] = num.cumsum(number_of_triangles_per_node)
     808
     809        #assert num.allclose(node_index,node_index_new)
     810
     811
    806812
    807813
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/generic_domain.py

    r8503 r8505  
    3333    Generic computational Domain constructor.
    3434    '''
     35
    3536
    3637    def __init__(self, source=None,
     
    7273        """
    7374
     75
     76        if verbose: log.critical('Domain: Initialising')
     77
    7478        # FIXME SR: This is a bug
    7579        number_of_full_nodes=None
     
    8286            coordinates = source
    8387
    84         if verbose: log.critical('Domain: Initialising')
     88
    8589
    8690        # In case a filename has been specified, extract content
    8791        if mesh_filename is not None:
     92
    8893            coordinates, triangles, boundary, vertex_quantity_dict, \
    8994                         tagged_elements, geo_reference = \
     
    101106                         #number_of_full_triangles=number_of_full_triangles,
    102107                         verbose=verbose)
     108
     109        if verbose: log.critical('Domain: Expose mesh attributes')
    103110
    104111        # Expose Mesh attributes (FIXME: Maybe turn into methods)
     
    134141
    135142
    136 
     143        if verbose: log.critical('Domain: Expose quantity names and types')
    137144        # List of quantity names entering the conservation equations
    138145        if conserved_quantities is None:
     
    160167           
    161168
     169        if verbose: log.critical('Domain: Build Quantities')
    162170        # Build dictionary of Quantity instances keyed by quantity names
    163171        self.quantities = {}
     
    198206
    199207        # Setup Communication Buffers
    200         if verbose: log.critical('Domain: Set up communication buffers '
    201                                  '(parallel)')
     208        if verbose: log.critical('Domain: Set up communication buffers ')
    202209        self.nsys = len(self.conserved_quantities)
    203210        for key in self.full_send_dict:
     
    213220
    214221
    215 
     222        # Setup triangle full flag
     223        if verbose: log.critical('Domain: Set up triangle/node full flags ')
    216224        N = len(self) #number_of_elements
    217225        self.number_of_elements = N
    218226
    219         # Setup cell full flag
     227       
    220228        # =1 for full
    221229        # =0 for ghost
     
    229237
    230238
    231         # Identify full nodes as thosethat intersect a full triangle.
     239        # Identify full nodes as those that intersect a full triangle.
    232240
    233241        Vol_ids  = self.vertex_value_indices/3
    234242        W = num.repeat(self.tri_full_flag, 3)
    235243
    236         self.node_full_flag = num.minimum(num.bincount(self.triangles.flatten(), weights = W).astype(num.int), 1)
     244        self.node_full_flag = num.minimum(num.bincount(self.triangles.flat, weights = W).astype(num.int), 1)
    237245
    238246
     
    250258
    251259        # Defaults
     260        if verbose: log.critical('Domain: Set defaults')
     261
    252262        from anuga.config import max_smallsteps, beta_w, epsilon
    253263        from anuga.config import CFL
     
    301311        self.simulation_name = 'domain'
    302312        self.checkpoint = False
     313
     314        if verbose: log.critical('Domain: Set work arrays')
     315
    303316
    304317        # To avoid calculating the flux across each edge twice, keep an integer
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/pmesh2domain.py

    r8148 r8505  
    99import sys
    1010import numpy as num
     11import anuga.utilities.log as log
    1112
    1213
     
    8990    use_cache: True means that caching is attempted for the computed domain.   
    9091    """
    91  
     92
     93    if verbose: log.critical('Pmesh_to_Domain: Initialising')
     94   
    9295    if use_cache is True:
    9396        from caching import cache
     
    97100    else:
    98101        result = apply(_pmesh_to_domain, (file_name, mesh_instance))       
    99        
     102
     103    if verbose: log.critical('Pmesh_to_Domain: Done')
     104
    100105    return result
    101106
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py

    r8503 r8505  
    673673            assert len(values.shape) == 1 or num.allclose(values.shape[1:], 1), msg
    674674
    675             self.set_vertex_values(values.flatten(), indices=indices,
     675            self.set_vertex_values(values.flat, indices=indices,
    676676                                   use_cache=use_cache, verbose=verbose)
    677677        else:
  • trunk/anuga_core/source/anuga/pmesh/mesh_interface.py

    r8340 r8505  
    243243
    244244            # Test that we have a polygon
    245             if len(num.array(interior_polygon).flatten()) < 6:
     245            if len(num.array(interior_polygon).flat) < 6:
    246246                msg = 'Interior hole polygon %s has too few (<3) points.\n' \
    247247                    %(str(interior_polygon))
Note: See TracChangeset for help on using the changeset viewer.