Changeset 7751


Ignore:
Timestamp:
May 28, 2010, 1:24:10 PM (14 years ago)
Author:
hudson
Message:

Refactorings from May ANUGA meeting.

Location:
anuga_core/source/anuga
Files:
1 added
10 edited
2 copied

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/__init__.py

    r3518 r7751  
    77import sys
    88sys.path += __path__
     9
     10
     11# Make selected classes available directly
     12
     13# Boundaries specific to shallow water domain.
     14from anuga.shallow_water.boundaries import Reflective_boundary,\
     15     Transmissive_momentum_set_stage_boundary,\
     16     Dirichlet_discharge_boundary,\
     17     Field_boundary,\
     18     Transmissive_stage_zero_momentum_boundary,\
     19     Transmissive_n_momentum_zero_t_momentum_set_stage_boundary
     20
     21# Boundaries generic across all forms of domain.
     22from anuga.abstract_2d_finite_volumes.generic_boundary_conditions\
     23     import Transmissive_boundary, Dirichlet_boundary, \
     24            Time_boundary, File_boundary, AWI_boundary
     25
     26# Shallow water domain is the standard
     27from anuga.shallow_water.shallow_water_domain import Domain
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r7745 r7751  
    308308    return degrees(angle([uh, vh], [0, -1]))   
    309309
    310 
    311 def copy_code_files(dir_name, filename1, filename2, verbose=False):
    312     """Copies "filename1" and "filename2" to "dir_name".
    313 
    314     Each 'filename' may be a string or list of filename strings.
    315 
    316     Filenames must be absolute pathnames
    317     """
    318 
    319     ##
    320     # @brief copies a file or sequence to destination directory.
    321     # @param dest The destination directory to copy to.
    322     # @param file A filename string or sequence of filename strings.
    323     def copy_file_or_sequence(dest, file):
    324         if hasattr(file, '__iter__'):
    325             for f in file:
    326                 shutil.copy(f, dir_name)
    327                 if verbose:
    328                     log.critical('File %s copied' % f)
    329         else:
    330             shutil.copy(file, dir_name)
    331             if verbose:
    332                 log.critical('File %s copied' % file)
    333 
    334     # check we have a destination directory, create if necessary
    335     if not os.path.isdir(dir_name):
    336         if verbose:
    337             log.critical('Make directory %s' % dir_name)
    338         mkdir(dir_name, 0777)
    339 
    340     if verbose:
    341         log.critical('Output directory: %s' % dir_name)       
    342 
    343     copy_file_or_sequence(dir_name, filename1)
    344 
    345     if not filename2 is None:
    346         copy_file_or_sequence(dir_name, filename2)
    347310
    348311##
  • anuga_core/source/anuga/file_conversion/__init__.py

    r7742 r7751  
    66sys.path += __path__
    77
    8 # Make selected classes available directly
    9 from boundaries import Reflective_boundary,\
    10      Transmissive_momentum_set_stage_boundary,\
    11      Dirichlet_discharge_boundary,\
    12      Field_boundary,\
    13      Transmissive_stage_zero_momentum_boundary,\
    14      Transmissive_n_momentum_zero_t_momentum_set_stage_boundary
    15 
    16 from anuga.abstract_2d_finite_volumes.generic_boundary_conditions\
    17      import Transmissive_boundary, Dirichlet_boundary, \
    18             Time_boundary, File_boundary, AWI_boundary
    19 
    20 from shallow_water_domain import Domain
    21 
    228
    239#from shallow_water_balanced_domain import Swb_domain
  • anuga_core/source/anuga/fit_interpolate/fit.py

    r7717 r7751  
    3535from anuga.utilities.sparse import Sparse, Sparse_CSR
    3636from anuga.geometry.polygon import inside_polygon, is_inside_polygon
    37 from anuga.geometry.mesh_quadtree import MeshQuadtree
     37from anuga.pmesh.mesh_quadtree import MeshQuadtree
    3838
    3939from anuga.utilities.cg_solve import conjugate_gradient
  • anuga_core/source/anuga/fit_interpolate/general_fit_interpolate.py

    r7717 r7751  
    3131from anuga.geospatial_data.geospatial_data import Geospatial_data, \
    3232     ensure_absolute
    33 from anuga.geometry.mesh_quadtree import MeshQuadtree
     33from anuga.pmesh.mesh_quadtree import MeshQuadtree
    3434import anuga.utilities.log as log
    3535
  • anuga_core/source/anuga/geometry/aabb.py

    r7721 r7751  
    1 # Allow children to be slightly bigger than their parents to prevent straddling of a boundary
     1"""
     2    Axially aligned bounding box.
     3    Contains a class describing a bounding box. It contains methods
     4    to split itself and return child boxes.
     5"""
     6
     7# Allow children to be slightly bigger than their parents to prevent
     8# straddling of a boundary
    29SPLIT_BORDER_RATIO    = 0.55
    310
     
    2330    def __repr__(self):
    2431        return 'AABB(xmin:%f, xmax:%f, ymin:%f, ymax:%f)' \
    25                % (round(self.xmin,1), round(self.xmax,1), round(self.ymin,1), round(self.ymax, 1))
     32               % (round(self.xmin,1), round(self.xmax,1), \
     33                  round(self.ymin,1), round(self.ymax, 1))
    2634
    2735
     
    5664        if (width > height):
    5765            # split vertically
    58             return AABB(self.xmin, self.xmin+width*border, self.ymin, self.ymax), \
    59                    AABB(self.xmax-width*border, self.xmax, self.ymin, self.ymax)
     66            split1 = self.xmin+width*border
     67            split2 = self.xmax-width*border
     68            return AABB(self.xmin, split1, self.ymin, self.ymax), \
     69                   AABB(split2, self.xmax, self.ymin, self.ymax)
    6070        else:
    6171            # split horizontally       
    62             return AABB(self.xmin, self.xmax, self.ymin, self.ymin+height*border), \
    63                    AABB(self.xmin, self.xmax, self.ymax-height*border, self.ymax)   
     72            split1 = self.ymin+height*border
     73            split2 = self.ymax-height*border
     74            return AABB(self.xmin, self.xmax, self.ymin, split1), \
     75                   AABB(self.xmin, self.xmax, split2, self.ymax)   
    6476
    6577   
     
    7688        return True
    7789 
    78     def contains(self, x):
     90    def contains(self, point):
    7991        """ is point within box
    80             x is a test point
     92            point is a test point
    8193            return True if the point is contained within the box.
    8294        """
    83         return (self.xmin <= x[0] <= self.xmax) and (self.ymin <= x[1] <= self.ymax)
     95        return (self.xmin <= point[0] <= self.xmax) \
     96                and (self.ymin <= point[1] <= self.ymax)
    8497       
  • anuga_core/source/anuga/geometry/quad.py

    r7721 r7751  
    11"""quad.py - quad tree data structure for fast indexing of regions in the plane.
    22
    3 This is a generic structure that can be used to store any geometry in a quadtree.
    4 It is naive, and does not exploit any coherency - it merely tests a bounding
    5 box against all other bounding boxes in its heirarchy.
    6 
    7 It returns a list of bounding boxes which intersect with the test box, which
    8 must then be iterated over to detect actual intersections.
     3This generic structure can be used to store any geometry in a quadtree.
     4It is naive, and does not exploit any coherency - it merely tests a point
     5against all bounding boxes in its heirarchy.
     6
     7It returns a list of bounding boxes which intersect with the test point, which
     8may then be iterated over with a proper intersection test to detect actual
     9geometry intersections.
    910
    1011"""
    1112
    1213from anuga.utilities.treenode import TreeNode
    13 import string, types, sys
    1414import anuga.utilities.log as log
    15 from aabb import AABB
    1615
    1716           
     
    3029 
    3130        # Initialise base classes
    32         TreeNode.__init__(self, string.lower(name))
     31        TreeNode.__init__(self, name)
    3332   
    3433        self.extents = extents
     
    4140   
    4241    def __repr__(self):
    43         str = '%s: leaves: %d' \
     42        ret_str = '%s: leaves: %d' \
    4443               % (self.name , len(self.leaves))   
    4544        if self.children:
    46             str += ', children: %d' % (len(self.children))
    47         return str
     45            ret_str += ', children: %d' % (len(self.children))
     46        return ret_str
    4847
    4948   
    5049
    5150    def clear(self):
     51        """ Remove all leaves from this node.
     52        """
    5253        self.Prune()   # TreeNode method
    5354
    5455
    5556    def clear_leaf_node(self):
    56         """Clears storage in leaf node.
    57     Called from Treenode.
    58     Must exist.   
    59     """
     57        """ Clears storage in leaf node.
     58            Called from Treenode.
     59            Must exist.   
     60        """
    6061        self.leaves = []
    6162   
     
    7576        if type(new_leaf)==type(list()):
    7677            for leaf in new_leaf:
    77                 self._insert(leaf)
     78                self.insert_item(leaf)
    7879        else:
    79             self._insert(new_leaf)
    80 
    81 
    82     def _insert(self, new_leaf):   
    83         """ Internal recursive insert.
     80            self.insert_item(new_leaf)
     81
     82
     83    def insert_item(self, new_leaf):   
     84        """ Internal recursive insert a single item.
    8485            new_leaf is a tuple of (AABB extents, data), where data can
    8586                     be any user data (geometry, triangle index, etc.).       
    8687        """
    87         new_region, data = new_leaf
     88        new_region, _ = new_leaf
    8889       
    8990        # recurse down to any children until we get an intersection
     
    9192            for child in self.children:
    9293                if child.extents.is_trivial_in(new_region):
    93                     child._insert(new_leaf)
     94                    child.insert_item(new_leaf)
    9495                    return
    9596        else:           
     
    9899           
    99100            # option 1 - try splitting 4 ways
    100             #subregion11, subregion12 = subregion1.split()                               
     101            #subregion11, subregion12 = subregion1.split()   
    101102            #subregion21, subregion22 = subregion2.split()
    102103            #regions = [subregion11, subregion12, subregion21, subregion22]
     
    104105                #if region.is_trivial_in(new_region):
    105106                    #self.children = [Cell(x, parent=self) for x in regions]
    106                     #self._insert(new_leaf)
     107                    #self.insert_item(new_leaf)
    107108                    #return               
    108109
    109110            # option 2 - try splitting 2 ways - no diff noticed in practise
    110111            if subregion1.is_trivial_in(new_region):
    111                 self.children = [Cell(subregion1, self), Cell(subregion2, self)]   
    112                 self.children[0]._insert(new_leaf)
     112                self.children = [Cell(subregion1, self), \
     113                                 Cell(subregion2, self)]   
     114                self.children[0].insert_item(new_leaf)
    113115                return
    114116            elif subregion2.is_trivial_in(new_region):
    115                 self.children = [Cell(subregion1, self), Cell(subregion2, self)]   
    116                 self.children[1]._insert(new_leaf)
     117                self.children = [Cell(subregion1, self), \
     118                                 Cell(subregion2, self)]   
     119                self.children[1].insert_item(new_leaf)
    117120                return               
    118121   
     
    156159        if depth == 0:
    157160            log.critical()
    158         print '%s%s'  % ('  '*depth, self.name), self.extents,' [', self.leaves, ']'
     161        print '%s%s'  % ('  '*depth, self.name), self.extents, ' [', \
     162            self.leaves, ']'
    159163        if self.children:
    160164            log.critical()
     
    162166                child.show(depth+1)
    163167
    164     def search(self, x):
    165         """return a list of possible intersections with geometry"""
    166      
    167         intersecting_regions = self.test_leaves(x)
     168    def search(self, point):
     169        """
     170            Search the tree for intersection with leaves
     171            point is a test point.
     172            return a list of possible intersections with geometry.
     173        """
     174        intersecting_regions = self.test_leaves(point)
    168175       
    169176        # recurse down into nodes that the point passes through
    170177        if self.children:
    171178            for child in self.children:   
    172                 if child.extents.contains(x):
    173                     intersecting_regions.extend(child.search(x))
     179                if child.extents.contains(point):
     180                    intersecting_regions.extend(child.search(point))
    174181             
    175182        return intersecting_regions
    176183 
    177184 
    178     def test_leaves(self, x):
     185    def test_leaves(self, point):
    179186        """ Test all leaves to see if they intersect x.
    180187            x is a point to test
     
    186193        for leaf in self.leaves:
    187194            aabb, data = leaf
    188             if aabb.contains(x):
     195            if aabb.contains(point):
    189196                intersecting_regions.append([data, self])
    190197               
  • anuga_core/source/anuga/pmesh/mesh_quadtree.py

    r7743 r7751  
    7171
    7272            # insert a tuple with an AABB, and the triangle index as data
    73             self._insert((AABB(min([x0, x1, x2]), max([x0, x1, x2]), \
     73            self.insert_item((AABB(min([x0, x1, x2]), max([x0, x1, x2]), \
    7474                             min([y0, y1, y2]), max([y0, y1, y2])), \
    7575                             node_data))
     
    146146
    147147        for node_data in triangles:             
    148             if bool(_is_inside_triangle(x, node_data[0][1], int(True), 1.0e-12, 1.0e-12)):
     148            if bool(_is_inside_triangle(x, node_data[0][1], \
     149                        int(True), 1.0e-12, 1.0e-12)):
    149150                normals = node_data[0][2]     
    150151                n0 = normals[0:2]
     
    155156                sigma0 = num.dot((x-xi1), n0)/num.dot((xi0-xi1), n0)
    156157                sigma1 = num.dot((x-xi2), n1)/num.dot((xi1-xi2), n1)
    157                 sigma2 = num.dot((x-xi0), n2)/num.dot((xi2-xi0), n2)             
     158                sigma2 = num.dot((x-xi0), n2)/num.dot((xi2-xi0), n2)
    158159
    159160                # Don't look for any other triangles in the triangle list
    160161                self.last_triangle = [node_data]
    161                 return True, sigma0, sigma1, sigma2, node_data[0][0] # tri index                     
     162                return True, sigma0, sigma1, sigma2, node_data[0][0] # tri index
    162163        return False, -1, -1, -1, -10
    163164
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r7744 r7751  
    7979from anuga.utilities.numerical_tools import ensure_numeric,  mean
    8080from anuga.caching.caching import myhash
    81 from anuga.shallow_water import Domain
     81from anuga.shallow_water.shallow_water_domain import Domain
    8282from anuga.abstract_2d_finite_volumes.pmesh2domain import \
    8383     pmesh_to_domain_instance
  • anuga_core/source/anuga/utilities/file_utils.py

    r7745 r7751  
    393393
    394394
     395
     396def copy_code_files(dir_name, filename1, filename2, verbose=False):
     397    """Copies "filename1" and "filename2" to "dir_name".
     398
     399    Each 'filename' may be a string or list of filename strings.
     400
     401    Filenames must be absolute pathnames
     402    """
     403
     404    ##
     405    # @brief copies a file or sequence to destination directory.
     406    # @param dest The destination directory to copy to.
     407    # @param file A filename string or sequence of filename strings.
     408    def copy_file_or_sequence(dest, file):
     409        if hasattr(file, '__iter__'):
     410            for f in file:
     411                shutil.copy(f, dir_name)
     412                if verbose:
     413                    log.critical('File %s copied' % f)
     414        else:
     415            shutil.copy(file, dir_name)
     416            if verbose:
     417                log.critical('File %s copied' % file)
     418
     419    # check we have a destination directory, create if necessary
     420    if not os.path.isdir(dir_name):
     421        if verbose:
     422            log.critical('Make directory %s' % dir_name)
     423        mkdir(dir_name, 0777)
     424
     425    if verbose:
     426        log.critical('Output directory: %s' % dir_name)       
     427
     428    copy_file_or_sequence(dir_name, filename1)
     429
     430    if not filename2 is None:
     431        copy_file_or_sequence(dir_name, filename2)
  • anuga_core/source/anuga/utilities/interp.py

    r7276 r7751  
    138138    """
    139139    import arrayfns
    140     import numpy.ma MA
     140    import numpy.ma as MA
    141141    import numpy as N
    142142    from where_close import where_close
Note: See TracChangeset for help on using the changeset viewer.