PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
discretize_circle Namespace Reference

Functions

 print_point (point, area, prefix="")
 
 mult (matrix, vector)
 
 discretize_circle (radius, x_one)
 

Function Documentation

◆ discretize_circle()

discretize_circle.discretize_circle (   radius,
  x_one 
)
Generates discretization of circle so that area of all nodes are same

Definition at line 21 of file discretize_circle.py.

21def discretize_circle(radius, x_one):
22 """Generates discretization of circle so that area of all nodes are same"""
23
24 # particle data
25 sim_particle_r = radius
26
27 # store location of nodes
28 sim_particles = []
29
30 # store area of nodes
31 sim_particles_area = []
32
33 # get angle
34 sim_num_theta = 8
35 sim_theta_interval = 2. * np.pi / (float(sim_num_theta))
36 angle = 0.
37
38 # get matrix
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 # add first point
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 # add first point
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 # loop over internal points
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 # get next internal point
81 x_new = np.sqrt(val) - x_pre
82
83
84 #
85 p = [x_new, 0.]
86 p = mult(matrix, p)
87
88 # add point and area
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 # if len(sim_particles) > 20:
100 # continue_add = False
101 else:
102 print('skipped')
103
104
105 # end of while loop
106
107 # skip some points
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 # skip some points
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 # area
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 # rotate all points
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 # get matrix
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 # loop points in y=0 line
173
174 # loop over angles
175
176 # print points to csv file
177 # generate csv file
178 inpf = open('circle_mesh.csv','w')
179
180 # header
181 # inpf.write("i, x, y, z, area\n")
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

References mult(), and print_point().

Here is the call graph for this function:

◆ mult()

discretize_circle.mult (   matrix,
  vector 
)

Definition at line 18 of file discretize_circle.py.

18def mult(matrix, vector):
19 return [matrix[0][0] * vector[0] + matrix[0][1] * vector[1], matrix[1][0] * vector[0] + matrix[1][1] * vector[1]]
20

Referenced by discretize_circle().

Here is the caller graph for this function:

◆ print_point()

discretize_circle.print_point (   point,
  area,
  prefix = "" 
)

Definition at line 6 of file discretize_circle.py.

6def print_point(point, area, prefix = ""):
7 str = prefix + " area = " + "%4.6e" %(area) + ", point = ["
8 N = 2
9 for i in xrange(N):
10 str += "%4.6e" % (point[i])
11 if i < N - 1:
12 str += ", "
13 else:
14 str += "]\n"
15
16 print(str)
17

Referenced by discretize_circle().

Here is the caller graph for this function: