Changeset 8482


Ignore:
Timestamp:
Jul 30, 2012, 9:52:58 AM (13 years ago)
Author:
steve
Message:

Testing prelim erosion operator

Location:
trunk/anuga_core/source/anuga/operators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/operators/erosion_operators.py

    r8481 r8482  
    8484        self.indices = indices
    8585
     86        #------------------------------------------
     87        # Need to turn off this optimization as it
     88        # doesn't fixup the relationship between
     89        # bed and stage vertex values in dry region
     90        #------------------------------------------
     91        self.domain.optimise_dry_cells = 0
    8692
    8793        #------------------------------------------
    8894        # Find vertex nodes
    8995        #------------------------------------------
    90         node_id = set()
     96        node_ids = set()
    9197
    9298        for ind in self.indices:
    9399            for k in [0,1,2]:
    94                 node_id.add(self.domain.triangles[ind,k])
    95 
    96         self.node_id = [ id for id in node_id ]
     100                node_ids.add(self.domain.triangles[ind,k])
     101
     102        self.node_ids = [ id for id in node_ids ]
    97103
    98104
     
    100106
    101107        k = 0
    102         node_index[0] = self.domain.number_of_triangles_per_node[0]
     108        node_index[0] = 0
    103109        for i in range(self.domain.number_of_nodes):
    104             if i == 0:
    105                 continue
    106 
    107             node_index[i] = node_index[i-1] + self.domain.number_of_triangles_per_node[i]
    108 
    109         n0 = self.node_id[0]
    110         i0 = node_index[n0]                                      # index of first vertex associated to node
    111         i1 = i0 + self.domain.number_of_triangles_per_node[i]    # index of last vertex associated to node
    112 
    113         print node_index
    114         print n0,i0,i1
    115         print len(node_index),self.domain.number_of_nodes
    116 
    117 
    118         print self.node_id
    119 
     110            node_index[i+1] = node_index[i] + self.domain.number_of_triangles_per_node[i]
     111
     112        self.node_index = node_index
     113
     114        vertex_ids =[]
     115        for nid in self.node_ids:
     116            print nid,self.domain.number_of_triangles_per_node[nid]
     117            for vid in range(node_index[nid], node_index[nid+1]):
     118                vidd = self.domain.vertex_value_indices[vid]
     119                vertex_ids.append(vidd)
     120                print '   ',nid, vid, vidd, vidd/3, vidd%3
     121
     122        self.vol_ids  = num.array(vertex_ids,dtype=num.int)/3
     123        self.vols = num.array(list(set(self.vol_ids)), dtype=num.int)
     124        self.vert_ids = num.array(vertex_ids,dtype=num.int)%3
     125
     126        print 'noe', self.domain.number_of_elements
     127        print 'non', self.domain.number_of_nodes
     128        #print self.vols
     129        #print self.domain.vertex_value_indic
     130        #print self.domain.number_of_triangles_per_node
     131        #print self.node_index
     132
     133        print 'self.node_ids'
     134        print self.node_ids
     135
     136        print 'self.indices'
     137        print self.indices
     138        #print self.domain.triangles[self.indices]
     139        #print self.vertex_ids
     140
     141        self.dump_triangulation()
    120142
    121143    def __call__(self):
     
    167189        #--------------------------------------------
    168190
    169         if t < 15.0 and t > 10.0:
     191        if t < 10.0 and t > 7.0:
    170192            if self.indices is None:
    171193                self.elev_v[:] = self.elev_v + 0.0
     
    174196
    175197
    176         for nid in self.node_id:
    177             print 'nid ', nid
    178             print 'vvi ', self.domain.vertex_value_indices[nid]
     198                #self.elev_v[self.vol_ids, self.vert_ids] = \
     199                #   num.maximum(self.elev_v[self.vol_ids, self.vert_ids] - 0.1*dt, 0.0)
     200
     201                #self.elev_c[self.vols] = num.mean(self.elev_v[self.vols],axis=1)
     202
     203        #for nid in self.node_id:
     204        #    print 'nid ', nid
     205        #    print 'vvi ', self.domain.vertex_value_indices[nid]
    179206
    180207
     
    202229
    203230
    204         old_flag = self.domain.optimise_dry_cells
    205         self.domain.optimise_dry_cells = 0
    206         self.domain.distribute_to_vertices_and_edges()
    207         self.domain.optimise_dry_cells = old_flag
     231        #old_flag = self.domain.optimise_dry_cells
     232        #self.domain.optimise_dry_cells = 0
     233        #self.domain.distribute_to_vertices_and_edges()
     234        #self.domain.optimise_dry_cells = old_flag
    208235
    209236        #stage_elev_info(self.domain)
     
    231258
    232259
     260    def dump_triangulation(self):
     261        # Get vertex coordinates, partition full and ghost triangles based on self.tri_full_flag
     262
     263        try:
     264            import matplotlib
     265            matplotlib.use('Agg')
     266            import matplotlib.pyplot as plt
     267            import matplotlib.tri as tri
     268        except:
     269            print "Couldn't import module from matplotlib, probably you need to update matplotlib"
     270            raise
     271
     272        domain = self.domain
     273
     274        vertices = domain.get_vertex_coordinates()
     275        #vertices = vertices.reshape((480,3,2))
     276        nodes = domain.get_nodes()
     277        Z = domain.get_quantity('elevation').get_values(location='unique vertices')
     278        #stage.shape = (1200, )
     279
     280        fx = nodes[:,0]
     281        fy = nodes[:,1]
     282        #gx = vertices[ghost_mask,0]
     283        #gy = vertices[ghost_mask,1]
     284
     285
     286
     287        ## Plot full triangles
     288        n = int(len(fx)/3)
     289        #triang = num.array(range(0,3*n))
     290        triang = domain.get_triangles()
     291        #triang.shape = (n, 3)
     292
     293        print triang.shape
     294        print fx.shape
     295        print Z.shape
     296
     297        #plt.tricontourf(fx, fy, triang, Z)
     298        plt.triplot(fx, fy, triang)
     299
     300        # now plot indices
     301
     302        #plt.tricontourf(fx, fy, triang, Z)
     303        #plt.triplot(fx, fy, triang)
     304        #plt.colorbar()
     305        #plt.tricontour(fx, fy, triang, Z, colors='k')
     306        #tripcolor
     307
     308
     309        #full_mask = num.repeat(self.tri_full_flag == 1, 3)
     310        #ghost_mask = num.repeat(self.tri_full_flag == 0, 3)
     311
     312        noe = self.domain.number_of_elements
     313
     314        fx = vertices[:,0].reshape(noe,3)
     315        fy = vertices[:,1].reshape(noe,3)
     316
     317
     318        fx = fx[self.indices].flatten()
     319        fy = fy[self.indices].flatten()
     320
     321        print 'fx', fx.shape
     322
     323        print self.indices
     324        #gx = vertices[ghost_mask,0]
     325        #gy = vertices[ghost_mask,1]
     326
     327
     328        ## Plot full triangles
     329        n = int(len(fx)/3)
     330
     331        Z = num.ones((3*n,),dtype=num.float)
     332        print Z.shape
     333
     334        triang = num.array(range(0,3*n))
     335        triang.shape = (n, 3)
     336        print triang
     337        plt.triplot(fx, fy, triang, 'o-')
     338        plt.tripcolor(fx,fy, triang, Z)
     339       
     340        ## Plot ghost triangles
     341        #n = int(len(gx)/3)
     342        #if n > 0:
     343            #triang = num.array(range(0,3*n))
     344            #triang.shape = (n, 3)
     345            #plt.triplot(gx, gy, triang, 'b--')
     346
     347        # Save triangulation to location pointed by filename
     348        plt.savefig('dump.svg')
     349
     350        plt.draw()
     351        plt.show()
     352
     353
     354
     355
    233356
    234357
     
    329452
    330453
    331        
    332 
    333 
    334 
    335 
     454
  • trunk/anuga_core/source/anuga/operators/run_polygon_erosion.py

    r8481 r8482  
    2020length = 24.
    2121width = 5.
    22 dx = dy = 0.5 #.1           # Resolution: Length of subdivisions on both axes
     22dx = dy = 1.0 #.1           # Resolution: Length of subdivisions on both axes
    2323
    2424points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
     
    6666# Setup boundary conditions
    6767#------------------------------------------------------------------------------
    68 Bi = Dirichlet_boundary([0.4, 0, 0])          # Inflow
     68Bi = Dirichlet_boundary([0.5, 0, 0])          # Inflow
    6969Br = Reflective_boundary(domain)              # Solid reflective wall
    7070Bo = Dirichlet_boundary([-5, 0, 0])           # Outflow
     
    7676#------------------------------------------------------------------------------
    7777
    78 polygon1 = [ [12.0, 2.0], [13.0, 2.0], [13.0, 3.0], [12.0, 3.0] ]
     78polygon1 = [ [12., 2.0], [13., 2.0], [13., 3.0], [12., 3.0] ]
    7979op1 = Polygonal_erosion_operator(domain, threshold=0.0, polygon=polygon1)
    8080
     
    8484#------------------------------------------------------------------------------
    8585
    86 for t in domain.evolve(yieldstep=0.2, finaltime=20.0):
     86for t in domain.evolve(yieldstep=0.2, finaltime=2.0):
    8787    domain.print_timestepping_statistics()
    8888    domain.print_operator_timestepping_statistics()
     
    106106
    107107
     108
Note: See TracChangeset for help on using the changeset viewer.