22 """Generates discretization of circle so that area of all nodes are same"""
23
24
25 sim_particle_r = radius
26
27
28 sim_particles = []
29
30
31 sim_particles_area = []
32
33
34 sim_num_theta = 8
35 sim_theta_interval = 2. * np.pi / (float(sim_num_theta))
36 angle = 0.
37
38
39 matrix = []
40 a = [np.cos(angle), -np.sin(angle)]
41 matrix.append(a)
42 a = [np.sin(angle), np.cos(angle)]
43 matrix.append(a)
44
45
46 p = [1., 0.]
47 p = mult(matrix, p)
48 sim_particles.append(p)
49 area = sim_theta_interval * (1. - (1. + x_one) * (1. + x_one) * 0.25)
50 sim_particles_area.append(area)
51 print_point(p, area, "angle = %4.6e\n" %(angle))
52
53
54 p = [x_one, 0.]
55 p = mult(matrix, p)
56 sim_particles.append(p)
57 sim_particles_area.append(area)
58 print_point(p, area, "angle = %4.6e\n" %(angle))
59
60 continue_add = True
61 x_pre_pre = 1.
62 x_pre = x_one
63 counter = 1
64
65 while continue_add == True:
66
67 val = (x_pre + x_pre_pre) * (x_pre + x_pre_pre) - 4. * area / (sim_theta_interval)
68
69 if val < 0.:
70 continue_add = False
71
72 if continue_add == True:
73
74 counter = counter + 1
75
76 if counter % 2 != 0:
77
78 print('counter %d\n' % (counter))
79
80
81 x_new = np.sqrt(val) - x_pre
82
83
84
85 p = [x_new, 0.]
86 p = mult(matrix, p)
87
88
89 sim_particles.append(p)
90 sim_particles_area.append(area)
91
92 area_new = sim_theta_interval * ((x_pre + x_pre_pre) * (x_pre + x_pre_pre) * 0.25 - (x_pre + x_new) * (x_pre + x_new) * 0.25)
93
94 print_point(p, area_new)
95
96 x_pre_pre = x_pre
97 x_pre = x_new
98
99
100
101 else:
102 print('skipped')
103
104
105
106
107
108 sim_particles_new = []
109 sim_particles_area_new = []
110 for i in xrange(len(sim_particles)):
111 continue_i = True
112
113 if i > 1:
114 if (i+1) % 2 != 0:
115 continue_i = False
116
117 if continue_i == True:
118
119 x = [sim_particles[i][0], sim_particles[i][1]]
120 sim_particles_new.append(x)
121 sim_particles_area_new.append(sim_particles_area[i])
122
123
124 sim_particles_nn = []
125 sim_particles_area_nn = []
126 for i in xrange(len(sim_particles_new)):
127
128 x = [sim_particles_new[i][0], sim_particles_new[i][1]]
129 sim_particles_nn.append(x)
130
131 x_next = [0., 0.]
132 if i < len(sim_particles_new) - 2:
133 x_next = [sim_particles_new[i+1][0], sim_particles_new[i+1][1]]
134
135 x_prev = [0., 0.]
136 if i > 0:
137 x_prev = [sim_particles_new[i-1][0], sim_particles_new[i-1][1]]
138
139
140 area_new = 0.
141 if i == 0:
142 area_new = sim_theta_interval * (1. * 1. - (1. + x[0]) * (1. + x[0]) * 0.25)
143 elif i == len(sim_particles) - 1:
144 area_new = sim_theta_interval * ((x_prev[0] + x[0]) * (x_prev[0] + x[0]) * 0.25)
145 else:
146 area_new = sim_theta_interval * ((x_prev[0] + x[0]) * (x_prev[0] + x[0]) * 0.25 - (x_next[0] + x[0]) * (x_next[0] + x[0]) * 0.25)
147
148 sim_particles_area_nn.append(area_new)
149
150
151 sim_particles_new_new = []
152 sim_particles_area_new_new = []
153 for theta in xrange(sim_num_theta):
154 angle = theta * sim_theta_interval
155
156
157 matrix = []
158 a = [np.cos(angle), -np.sin(angle)]
159 matrix.append(a)
160 a = [np.sin(angle), np.cos(angle)]
161 matrix.append(a)
162
163 for i in xrange(len(sim_particles_nn)):
164 x_old = [radius * sim_particles_nn[i][0], radius * sim_particles_nn[i][1]]
165 area = radius * radius * sim_particles_area_nn[i]
166
167 x_new = mult(matrix, x_old)
168
169 sim_particles_new_new.append(x_new)
170 sim_particles_area_new_new.append(area)
171
172
173
174
175
176
177
178 inpf = open('circle_mesh.csv','w')
179
180
181
182
183 for i in xrange(len(sim_particles_new_new)):
184 inpf.write("%d, %Lf, %Lf, %Lf, %Lf\n" % (i, sim_particles_new_new[i][0], sim_particles_new_new[i][1], 0., sim_particles_area_new_new[i]))
185
186 inpf.close()
187