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

Functions

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

Function Documentation

◆ discretize_circle()

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

Definition at line 21 of file discretize_circle_equidist.py.

21def discretize_circle(radius, num_r_points, num_theta):
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 = num_theta
35 sim_theta_interval = 2. * np.pi / (float(sim_num_theta))
36 angle = 0.
37
38 # loop over internal points
39 for i in xrange(num_r_points+1):
40
41 x = [radius - i * radius / (float(num_r_points)), 0.]
42
43 sim_particles.append(x)
44
45 x_next = [0., 0.]
46 if i < num_r_points - 1:
47 x_next = [radius - (i+1.) * radius / (float(num_r_points)), 0.]
48
49 x_prev = [0., 0.]
50 if i > 0:
51 x_prev = [radius - (i-1.) * radius / (float(num_r_points)), 0.]
52
53 # compute area
54 area_new = 0.
55 if i == 0:
56 area_new = sim_theta_interval * (1. - (x[0] + x_next[0]) * (x[0] + x_next[0]) * 0.25)
57 elif i == num_r_points:
58 area_new = np.pi * ((x_prev[0] + x[0]) * (x_prev[0] + x[0]) * 0.25)
59 else:
60 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)
61
62 sim_particles_area.append(area_new)
63 print_point(x, area_new)
64
65 # rotate all points
66 sim_particles_new = []
67 sim_particles_area_new = []
68 for theta in xrange(sim_num_theta):
69 angle = theta * sim_theta_interval
70
71 # get matrix
72 matrix = []
73 a = [np.cos(angle), -np.sin(angle)]
74 matrix.append(a)
75 a = [np.sin(angle), np.cos(angle)]
76 matrix.append(a)
77
78 for i in xrange(len(sim_particles)):
79
80 x_old = [sim_particles[i][0], sim_particles[i][1]]
81 area = sim_particles_area[i]
82
83 x_new = mult(matrix, x_old)
84
85 continue_i = True
86 if i == len(sim_particles) - 1 and theta > 0:
87 continue_i = False
88
89 if continue_i == True:
90 sim_particles_new.append(x_new)
91 sim_particles_area_new.append(area)
92
93 # print points to csv file
94 # generate csv file
95 inpf = open('circle_mesh.csv','w')
96
97 # header
98 inpf.write("id, x, y, volume\n")
99
100 for i in xrange(len(sim_particles_new)):
101 inpf.write("%d, %Lf, %Lf,%Lf\n" % (i, sim_particles_new[i][0], sim_particles_new[i][1], sim_particles_area_new[i]))
102
103 inpf.close()
104

References mult(), and print_point().

Here is the call graph for this function:

◆ mult()

discretize_circle_equidist.mult (   matrix,
  vector 
)

Definition at line 18 of file discretize_circle_equidist.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_equidist.print_point (   point,
  area,
  prefix = "" 
)

Definition at line 6 of file discretize_circle_equidist.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: