Ignore:
Timestamp:
Aug 8, 2007, 2:29:01 PM (18 years ago)
Author:
duncan
Message:

unverified solution to ticket#176

Location:
anuga_core/source/anuga/utilities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/quad.py

    r4655 r4666  
    2727    """
    2828 
    29     def __init__(self, southern, northern, western, eastern,
     29    def __init__(self, southern, northern, western, eastern, mesh,
    3030                 name = 'cell',
    3131                 max_points_per_cell = 4):
     
    3939        self.western = round(western,5)   
    4040        self.eastern = round(eastern,5)
     41        self.mesh = mesh
    4142
    4243        # The points in this cell     
     
    6364        cn = self.northern
    6465        cw = self.western   
    65         ce = self.eastern
     66        ce = self.eastern   
     67        mesh = self.mesh
    6668
    6769        # create 4 child cells
    68         self.AddChild(Cell((cn+cs)/2,cn,cw,(cw+ce)/2,self.name+'_nw'))
    69         self.AddChild(Cell((cn+cs)/2,cn,(cw+ce)/2,ce,self.name+'_ne'))
    70         self.AddChild(Cell(cs,(cn+cs)/2,(cw+ce)/2,ce,self.name+'_se'))
    71         self.AddChild(Cell(cs,(cn+cs)/2,cw,(cw+ce)/2,self.name+'_sw'))
     70        self.AddChild(Cell((cn+cs)/2,cn,cw,(cw+ce)/2,mesh,self.name+'_nw'))
     71        self.AddChild(Cell((cn+cs)/2,cn,(cw+ce)/2,ce,mesh,self.name+'_ne'))
     72        self.AddChild(Cell(cs,(cn+cs)/2,(cw+ce)/2,ce,mesh,self.name+'_se'))
     73        self.AddChild(Cell(cs,(cn+cs)/2,cw,(cw+ce)/2,mesh,self.name+'_sw'))
    7274       
    7375 
     
    140142        if len(args) == 2:
    141143            point_id = int(args[1])
    142             x, y = self.__class__.mesh.get_nodes()[point_id]
     144            x, y = self.mesh.get_nodes()[point_id]
    143145
    144146            #print point_id, x, y
     
    181183                    self.store(point)
    182184                else:
    183                     x = self.__class__.mesh.coordinates[point][0]
    184                     y = self.__class__.mesh.coordinates[point][1]
     185                    x = self.mesh.coordinates[point][0]
     186                    y = self.mesh.coordinates[point][1]
    185187                    print "(" + str(x) + "," + str(y) + ")"
    186188                    raise 'point not in region: %s' %str(point)
     
    223225            # print "verts", verts
    224226            for vert in verts:
    225                 triangle_list = self.__class__.mesh.get_triangles_and_vertices_per_node(vert)
     227                triangle_list = self.mesh.get_triangles_and_vertices_per_node(vert)
    226228                for k, _ in triangle_list:
    227229                    if not triangles.has_key(k):
    228230                        # print 'k',k
    229                         tri = self.__class__.mesh.get_vertex_coordinates(k)
    230                         n0 = self.__class__.mesh.get_normal(k, 0)
    231                         n1 = self.__class__.mesh.get_normal(k, 1)
    232                         n2 = self.__class__.mesh.get_normal(k, 2)
     231                        tri = self.mesh.get_vertex_coordinates(k)
     232                        n0 = self.mesh.get_normal(k, 0)
     233                        n1 = self.mesh.get_normal(k, 1)
     234                        n2 = self.mesh.get_normal(k, 2)
    233235                        triangles[k]=(tri, (n0, n1, n2))
    234236            self.triangles = triangles.items()
     
    418420       
    419421
    420     #Class initialisation method       
    421     def initialise(cls, mesh):
    422         cls.mesh = mesh
    423 
    424     initialise = classmethod(initialise)
     422    #Class initialisation method
     423    # this is bad.  It adds a huge memory structure to the class.
     424    # When the instance is deleted the mesh hangs round (leaks).
     425    #def initialise(cls, mesh):
     426    #    cls.mesh = mesh
     427
     428    #initialise = classmethod(initialise)
    425429
    426430def build_quadtree(mesh, max_points_per_cell = 4):
    427431    """Build quad tree for mesh.
    428432
    429     All vertices in mesh are stored in quadtree and a reference to the root is returned.
     433    All vertices in mesh are stored in quadtree and a reference
     434    to the root is returned.
    430435    """
    431436
    432437    from Numeric import minimum, maximum
    433438
    434     #Initialise
    435     Cell.initialise(mesh)
    436439
    437440    #Make root cell
     
    445448
    446449   
    447     #Ensure boundary points are fully contained in region
    448     #It is a property of the cell structure that points on xmax or ymax of any given cell
    449     #belong to the neighbouring cell.
    450     #Hence, the root cell needs to be expanded slightly
     450    # Ensure boundary points are fully contained in region
     451    # It is a property of the cell structure that
     452    # points on xmax or ymax of any given cell
     453    # belong to the neighbouring cell.
     454    # Hence, the root cell needs to be expanded slightly
    451455    ymax += (ymax-ymin)/10
    452456    xmax += (xmax-xmin)/10
     
    462466   
    463467    #FIXME: Use mesh.filename if it exists
    464     root = Cell(ymin, ymax, xmin, xmax,
     468    root = Cell(ymin, ymax, xmin, xmax,mesh,
    465469                #name = ....
    466470                max_points_per_cell = max_points_per_cell)
  • anuga_core/source/anuga/utilities/test_quad.py

    r4655 r4666  
    1212
    1313    def setUp(self):
    14         self.cell = Cell(100, 140, 0, 40, 'cell')
    1514
    1615        a = [3, 107]
     
    3029        mesh = Mesh(points, vertices)
    3130        self.mesh = mesh
    32         Cell.initialise(mesh)
     31        self.cell = Cell(100, 140, 0, 40, mesh, 'cell')
    3332
    3433    def tearDown(self):
Note: See TracChangeset for help on using the changeset viewer.