The main objective of this work is to fill a big box by specified number of spheres with specified radii by satisfying the following conditions:
- each sphere be in touch (not any overlaps just contacts) with at least one another sphere (minimum contact numbers for each sphere could be specified e.g. each sphere can contact with [1 to n] other spheres)
- spheres be randomly distributed (to avoid arranging them side by side such as in a row, so, avoiding severe differences in distribution of void spaces) to distribute fairly uniform in the total box volume not just filling some percentage from one side of the box and like that.
The expected model will be such as:
For this purpose, at first, I went to find out some optimization libraries such as pyomo, but using optimization methods for large data (about 100000 to 500000 spheres) are not suitable at all for this issue as I searched about those (in terms of time and …).
So, I try another innovative method:
For this purpose and for distributing spheres fairly uniform in the big box to have uniform distribution of voids among spheres, I segmented the big box to some thousands segments (with same sizes) with relatively the same containing sphere volumes (in terms of total volume of spheres in that segment). The number of spheres and their radii are specified for each box (So, I have created two groups of spheres in this example for each segment):
The sample radii file: https://drive.google.com/file/d/1RIL6n0yGSNBYmI-t_FmuW1vL29ncDUK8/view?usp=sharing
In my small example, I have two boxes stuck together (these boxes are examples of that segments), which I would fill by the spheres. Coordinate and ID of each vertex of the boxes are available e.g.:
IDs = np.array([np.array([9, 8, 7, 6, 3, 2, 1, 0]), np.array([11, 10, 9, 8, 5, 4, 3, 2])])
Vertices = [[np.array([0.1, 0., 0.1]), np.array([-0.1, 0., 0.1]), np.array([0.1, -0.2, 0.1]), np.array([-0.1, -0.2, 0.1]),
np.array([0.1, 0., -0.1]), np.array([-0.1, 0., -0.1]), np.array([0.1, -0.2, -0.1]), np.array([-0.1, -0.2, -0.1])],
[np.array([0.1, 0.2, 0.1]), np.array([-0.1, 0.2, 0.1]), np.array([0.1, 0., 0.1]), np.array([-0.1, 0., 0.1]),
np.array([0.1, 0.2, -0.1]), np.array([-0.1, 0.2, -0.1]), np.array([0.1, 0., -0.1]), np.array([-0.1, 0., -0.1])]]
To put the spheres in a specified distance of the boxes' walls (randomly); This step could be omitted if we could distribute spheres directly as expected:
rng = np.random.default_rng(85)
max_rad = 0.0375
Rand_Pos = []
No_Spheres = [542, 543]
for i, j in enumerate(IDs):
min_coord = np.amin(Vertices[i], axis=0)
max_coord = np.amax(Vertices[i], axis=0)
rand_pos_cell = []
for m in range(No_Spheres[i]):
rand_x = rng.uniform(min_coord[0] + max_rad, max_coord[0] - max_rad, 1)
rand_y = rng.uniform(min_coord[1] + max_rad, max_coord[1] - max_rad, 1)
rand_z = rng.uniform(min_coord[2] + max_rad, max_coord[2] - max_rad, 1)
rand_pos_cell.append([rand_x, rand_y, rand_z])
Rand_Pos.append(rand_pos_cell)
The resulted initial created coordinate file (Rand_Pos
): https://drive.google.com/file/d/1Aphl8ndEYnfv78cIUfiP-8vMi05Tjb8K/view?usp=sharing
After that, as I did not know any appropriate pythonic code to do so, I made repulsion among them (which were overlapped) by another software, but distances could not be controlled and they lose their contacts:
Distribution in this image is acceptable; spheres are distributed in all part of the boxes. But, as it is obvious, spheres are not in touch with each other (there is not any contacts among them).
I think this work is very similar to Voronoi tessellation, and perhaps, could be handled by such related algorithms in scipy and …. But, I don't know if it could.
I would be very appreciated if someone help to reach the aim. The proposed answers must be efficient in terms of time for large data.
Data for test just for curing overlaps, if needed, by 7 spheres (red disks showing spheres overlap positions)
radii: https://drive.google.com/file/d/1EJkYk8AuvJjtqFdFerAjFQtvMmGtrRfi/view?usp=sharing positions: https://drive.google.com/file/d/1ERzXZN79jxXnGbO3IhHfOgYtpcZN2STj/view?usp=sharing
from Placement of spheres in a specified medium with a specified condition
No comments:
Post a Comment