-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphite_ring.py
executable file
·147 lines (105 loc) · 3.62 KB
/
graphite_ring.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"""
Example: 2D graphite ring under compression
Zhang, X, et al. "Measurement of tensile strength of nuclear graphite based on
ring compression test." Journal of Nuclear Materials 511 (2018): 134-140.
-------------------------------------------
Run the following command from the root folder:
python -m examples.graphite_ring
"""
import numpy as np
import pypd
def build_particle_coordinates(dx, n_div_x, n_div_y):
"""
Build particle coordinates
Parameters
----------
Returns
-------
Notes
-----
"""
particle_coordinates = np.zeros([n_div_x * n_div_y, 2])
counter = 0
for i_y in range(n_div_y): # Depth
for i_x in range(n_div_x): # Length
coord_x = dx * i_x
coord_y = dx * i_y
particle_coordinates[counter, 0] = coord_x
particle_coordinates[counter, 1] = coord_y
counter += 1
return translate_particles(particle_coordinates)
def build_boundary_conditions(particles, dx):
bc_flag = np.zeros((len(particles), 2), dtype=np.intc)
bc_unit_vector = np.zeros((len(particles), 2), dtype=np.intc)
tol = 1e-6
for i, particle in enumerate(particles):
if particle[1] < (-0.024 + tol):
bc_flag[i, 1] = 1
bc_unit_vector[i, 1] = 1
if particle[1] > (0.024 - dx - tol):
bc_flag[i, 1] = 1
bc_unit_vector[i, 1] = -1
return bc_flag, bc_unit_vector
def mask_particles_circle(particles, centre, radius, opt):
"""
Mask particles inside or outside of a circle
Parameters
----------
opt : str
Select if particles inside or outside of a circle are deleted
["inside" / "outside"]
Returns
-------
Notes
-----
"""
counter = 0
mask = []
for particle in particles:
distance = np.sqrt(
(particle[0] - centre[0]) ** 2 + (particle[1] - centre[1]) ** 2
)
if opt == "inside":
if distance <= radius:
mask.append(counter)
elif opt == "outside":
if distance >= radius:
mask.append(counter)
counter += 1
return np.delete(particles, mask, axis=0)
def translate_particles(particles, origin=np.array([0, 0])):
"""
Translate a set of points to a new origin
Parameters
----------
origin : str
Translate a set of points to the origin (a, b)
Returns
-------
Notes
-----
https://math.stackexchange.com/questions/1801867/finding-the-centre-of-an-abritary-set-of-points-in-two-dimensions
"""
centroid = np.average(particles, axis=0)
return origin - particles + centroid
def main():
dx = 0.1875e-3 # 3 / 1.5 / 0.75 / 0.375 / 0.1875
n_div_x = np.rint(0.05 / dx).astype(int)
n_div_y = np.rint(0.05 / dx).astype(int)
hole_centre_x = 0.0 # 0.025 - dx/2
hole_centre_y = 0.0 # 0.025 - dx/2
x = build_particle_coordinates(dx, n_div_x, n_div_y)
x = mask_particles_circle(x, [hole_centre_x, hole_centre_y], 0.025 / 2, "inside")
x = mask_particles_circle(x, [hole_centre_x, hole_centre_y], 0.05 / 2, "outside")
flag, unit_vector = build_boundary_conditions(x, dx)
material = pypd.Material(
name="graphite", E=10e9, Gf=100, density=1780, ft=27.6 # Gf=190
)
bc = pypd.BoundaryConditions(flag, unit_vector, magnitude=1e-4)
particles = pypd.ParticleSet(x, dx, bc, material)
bonds = pypd.BondSet(particles)
model = pypd.Model(particles, bonds)
simulation = pypd.Simulation(n_time_steps=50000, damping=0)
simulation.run(model)
model.save_final_state_fig(sz=0.5, dsf=0, fig_title="graphite-ring")
main()