source: codes/mesh_generation/test_scvt2.py @ 1048

Last change on this file since 1048 was 974, checked in by dubos, 5 years ago

mesh_generation : creation

File size: 2.1 KB
Line 
1import numpy as np
2import matplotlib.pyplot as plt
3from numba import jit
4
5from scvt import topology
6from scvt import sphere
7from scvt import delaunay
8from scvt import lloyd
9
10def test(a,b,c):
11    p=circum(a,b,c)
12    print(norm(a-p),norm(b-p),norm(c-p)) # should be equal
13
14@jit
15def weight(xyz):
16    y = xyz[:,1];
17    return 1.+15.*np.exp(-16.*y*y)
18
19def main(nbp,inner,outer,filename=None):
20    N=10*nbp*nbp+2
21    points=np.random.randn(N,3)
22    for i in range(outer):
23        verbose = True
24        print('Outer Lloyd iteration %d/%d'%(i,outer))
25        for j in range(inner):
26            points, vertices, edges = lloyd.lloyd(points, weight, verbose)
27            verbose = False
28    plt.figure(figsize=(10,10))
29    sphere.plot_mesh(vertices, topology.dual_edges(edges), orient, "k")
30    if N<1000:
31        sphere.plot_mesh(points,edges,orient,"r")
32    if filename is None:
33        plt.show()
34    else:
35        plt.savefig(filename)
36
37
38
39orient=np.asarray([0,0,1.])
40
41################## Manual tests with octahedron ####################
42
43points=np.asarray([[1.,0.,0.],[0.,1.,0.],[0.,0.,1.],
44                   [-1.,0.,0.],[0.,-1.,0.],[0.,0.,-1.]])
45simplices = delaunay.delaunay(points)
46print("== Simplices ==", simplices)
47edges, regions = topology.all_edges_regions(simplices)
48print('%d cells, %d edges, %d triangles'%(points.shape[0], len(edges), len(simplices)))
49print(edges)
50for n,region in enumerate(regions):
51    print("Voronoi cell %d :"%n, region)
52for n,region in enumerate(regions):
53    print("Voronoi cell %d :"%n, [edges[edge] for edge in region])
54 
55vertices = [sphere.circum(points[a,:],points[b,:],points[c,:]) for a,b,c in simplices]
56vertices = np.asarray(vertices)
57print("== Vertices ==", vertices)
58bary = sphere.barycenters(regions, points, edges, vertices)
59
60regions_size, vert = lloyd.flatten_regions(regions, edges)
61degree, counts = np.unique(regions_size, return_counts=True)
62print("Edge counts of Voronoi cells :", dict(zip(degree, counts)))
63
64####################### Larger grid #######################
65#main(8, 1,1)
66#main(8, 100,5)
67main(16, 100,5, 'nbp16.png')
68main(40, 100,10, 'nbp40.png')
Note: See TracBrowser for help on using the repository browser.