-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticle_maker.py
185 lines (156 loc) · 8.22 KB
/
particle_maker.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
from numpy import linspace, array,ceil,around
import sys
def make_prism(x,y,z,num_x,num_y,num_z,radius,mass,rho_0,type_,vx=0.,vy=0.,vz=0.,dict_index=0,prism={}):
''' returns a prism given the initial coordinates and the number of particles in each axis \n
x, y and z are the coordinates of the first particle of the prism. \n
num_x, num_y and num_z are the numbers of particles for each axis (first particle included).
They can be either positive or negative. Negative numbers plot particles in the oposite direction of the global axis. \n
radius, mass and type stands for the radius, mass and type for all particles in the prism. \n
vx, vy and vz are the velocity coordinates for all the particles in the prism. This is optional and the dafult value is 0. \n
dict_index is the first index of the dictionary if one wants to continue to build from a previous dictionary \n
prism is a previous dictionary'''
vx = float(vx)
vy = float(vy)
vz = float(vz)
rho_0 = float(rho_0)
x_array = [float(x)]
for i in range(1,abs(num_x)):
x_array.append(float(x_array[-1]+2*radius))
y_array = [float(y)]
for i in range(1,abs(num_y)):
y_array.append(float(y_array[-1]+2*radius))
z_array = [float(z)]
for i in range(1,abs(num_z)):
z_array.append(float(z_array[-1]+2*radius))
for i in x_array:
for j in y_array:
for k in z_array:
prism[dict_index] = {'X': i,
'Y': j,
'Z': k,
'X Velocity':vx,
'Y Velocity':vy,
'Z Velocity':vz,
'Pressure': 0.,
'Density': rho_0,
'Mass':mass,
'Type':type_}
dict_index = dict_index + 1
return prism
def make_prism2(coord_init,coord_final,radius,mass,rho_0,type_,vx=0.,vy=0.,vz=0.,dict_index=0,prism={}):
''' returns a prism given the initial and final coordinates \n
coord_init -> array(x,y,z) of the initial coordinates \n
coord_final -> array(x,y,z) of the final coordinates \n
See make_prism function for the other variables'''
distance = array(coord_final) - array(coord_init)
if distance[0]/(2*radius)%1 != 0 and distance[1]/(2*radius)%1 != 0 and distance[2]/(2*radius)%1 != 0:
print()
print("-" * 40)
print('Division by radius did not return a whole number while trying to make a prism')
sys.exit(1)
else:
num_x = int((coord_final[0] - coord_init[0])/(2*radius))
num_y = int((coord_final[1] - coord_init[1])/(2*radius))
num_z = int((coord_final[2] - coord_init[2])/(2*radius))
return make_prism(coord_init[0],coord_init[1],coord_init[2],num_x,num_y,num_z,radius,mass,rho_0,type_,vx,vy,vz,dict_index,prism)
def make_box(coord_init,coord_final,radius,mass,rho_0,type_,vx=0.,vy=0.,vz=0.,dict_index=0,box={}):
''' returns an empty box given the initial and final coordinates \n
coord_init -> array(x,y,z) of the initial coordinates \n
coord_final -> array(x,y,z) of the final coordinates across main diagonal \n
See make_prism function for the other variables'''
distance = around(array(coord_final).astype(float) - array(coord_init).astype(float),5)
if distance[0]/(2*radius)%1 != 0 and distance[1]/(2*radius)%1 != 0 and distance[2]/(2*radius)%1 != 0:
print()
print("-" * 40)
print('Division by radius did not return a whole number while trying to make a prism, raising up the cube size to fit boundary particle radii')
for i in range(0,len(distance)):
fac = ceil(distance[i]/(2*radius))
distance[i] = round(fac*2*radius - distance[i],5)
coord_final = coord_final + distance
num_x = int(ceil((coord_final[0] - coord_init[0])/(2*radius)))
num_y = int(ceil((coord_final[1] - coord_init[1])/(2*radius)))
num_z = int(ceil((coord_final[2] - coord_init[2])/(2*radius)))
vx = float(vx)
vy = float(vy)
vz = float(vz)
rho_0 = float(rho_0)
x_array = [float(coord_init[0])]
for i in range(1,abs(num_x)):
x_array.append(float(x_array[-1]+2*radius))
y_array = [float(coord_init[1])]
for i in range(1,abs(num_y)):
y_array.append(float(y_array[-1]+2*radius))
z_array = [float(coord_init[2])]
for i in range(1,abs(num_z)):
z_array.append(float(z_array[-1]+2*radius))
for i in x_array:
for j in y_array:
for k in z_array:
if round(i,3) in coord_init or round(j,3) in coord_init or round(k,3) in coord_init:
box[dict_index] = {'X': i,
'Y': j,
'Z': k,
'X Velocity':vx,
'Y Velocity':vy,
'Z Velocity':vz,
'Pressure': 0.,
'Density': rho_0,
'Mass':mass,
'Type':type_}
dict_index = dict_index + 1
for i in x_array:
for j in y_array:
for k in z_array:
if (round(i+2*radius,5) in coord_final or round(j+2*radius,5) in coord_final or round(k+2*radius,5) in coord_final) and \
(round(i,5) not in coord_init and round(j,5) not in coord_init and round(k,5) not in coord_init):
box[dict_index] = {'X': i,
'Y': j,
'Z': k,
'X Velocity':vx,
'Y Velocity':vy,
'Z Velocity':vz,
'Pressure': 0.,
'Density': rho_0,
'Mass':mass,
'Type':type_}
dict_index = dict_index + 1
return box
# def make_sphere(coord_init,radius_sphere,radius_particle,mass,rho_0,type_,vx=0.,vy=0.,vz=0.,dict_index=0,sphere={})
# distance = radius_sphere - radius_particle - array(coord_init)
# if distance[0]/(2*radius)%1 != 0 and distance[1]/(2*radius)%1 != 0 and distance[2]/(2*radius)%1 != 0:
# print()
# print("-" * 40)
# print('Division by radius did not return a whole number while trying to make a prism')
# sys.exit(1)
# else:
# num_x = int((coord_final[0] - coord_init[0])/(2*radius))
# num_y = int((coord_final[1] - coord_init[1])/(2*radius))
# num_z = int((coord_final[2] - coord_init[2])/(2*radius))
# vx = float(vx)
# vy = float(vy)
# vz = float(vz)
# rho_0 = float(rho_0)
# x_array = [float(coord_init[0])]
# for i in range(1,abs(num_x)):
# x_array.append(float(x_array[-1]+2*radius))
# y_array = [float(coord_init[1])]
# for i in range(1,abs(num_y)):
# y_array.append(float(y_array[-1]+2*radius))
# z_array = [float(coord_init[2])]
# for i in range(1,abs(num_z)):
# z_array.append(float(z_array[-1]+2*radius))
# for i in x_array:
# for j in y_array:
# for k in z_array:
# if round(i,3) in coord_init or round(j,3) in coord_init or round(k,3) in coord_init:
# box[dict_index] = {'X': i,
# 'Y': j,
# 'Z': k,
# 'X Velocity':vx,
# 'Y Velocity':vy,
# 'Z Velocity':vz,
# 'Pressure': 0.,
# 'Density': rho_0,
# 'Mass':mass,
# 'Type':type_}
# dict_index = dict_index + 1