3

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:

  1. 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). The total medium must be continuum i.e. all spheres must have a connection path to other spheres; Not any separated sphere groups.
  2. 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:

pic


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)

pic

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:

pic

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

pic

Ali_Sh
  • 2,667
  • 3
  • 43
  • 66
  • Sometimes the difference between opensource and commercial solver is night and day. So worth a shot try a trial of commercial solver if you have it in right format already. – Willem Hendriks Dec 15 '21 at 07:58
  • 2
    Also, consider heuristics like Simulated Annealing. Can you add a smaller toy example as well? – Willem Hendriks Dec 15 '21 at 07:59
  • @WillemHendriks I used a commercial DEM software for making repulsion, but I have no idea how to control that. Because movement of each sphere depends on the rest of the spheres, and fixing some of them may close ways for other expansions (so. some spheres remain with overlaps). How much smaller? – Ali_Sh Dec 15 '21 at 11:57
  • What are the radii and no of spheres having the specific radii? – Tejas Shetty Dec 22 '21 at 08:57
  • 1
    Probably better to try to first solve the 2D version of this problem, ie circles in a rectangle – Tejas Shetty Dec 22 '21 at 08:58
  • @TejasShetty The number of spheres and their radii, by which the box must be filled, are specified before and must be imported as inputs. `No_spheres` list in the written code refer the number of spheres for each segments in the tried example. – Ali_Sh Dec 22 '21 at 22:58
  • 1
    This should be helpful: https://arxiv.org/pdf/1701.00541.pdf – Bilal Qandeel Dec 24 '21 at 20:08
  • @BilalQandeel Thanks for the paper. It is helpful. I'm not familiar enough by optimization methods (and also SciPy) and time-applicability of them for big data. It looks like that (from the paper) this problem can be handled by `scipy.optimize.basinhopping` and `scipy.optimize.minimize`; but I am not sure that they can satisfy the problem conditions like the minimum contact numbers for each sphere. As I have tagged SciPy and no answer was given, I guess perhaps this problem will not be as easy as it seems to solve in a satisfying runtime (for specified spheres in a rectangle cube). – Ali_Sh Dec 25 '21 at 03:51
  • 1
    One way to model this could be to treat your spheres as a set of "dimers" (connected spheres, as in diatomic molecules) with variable radii. By construction, this allows each sphere to "touch" at least its companion. Such a system could be simulated using [LAMMPS](https://www.lammps.org/) possibly using a long-range attractive and short-range repulsive potential between all monomers, varying the size of the simulation box during the run, enforcing constraints e.g. using https://docs.lammps.org/fix_shake.html Bottom line, maybe folks at https://physics.stackexchange.com/ could help here :) – Davide Fiocco Dec 26 '21 at 23:24
  • @DavideFiocco I had seen a lot `LAMMPS` in papers, but never used that and I forgot it. Thanks for reminding. I will read about it and its capabilities. I don't know if it can model a continuum model (have a connection path), in which all atoms are connected or if it can be used just within python with related packages (not coupling with its software) and ... . – Ali_Sh Dec 27 '21 at 01:32
  • I read your requirements and they are clear (although I think a requirement to contact at least n > 1 spheres could quickly make this unsolvable), but I am wondering whether you'd actually prefer the box to be filled from bottom to top with differently sized spheres affected by gravity, i.e., touching so many points that they cannot roll down any further? If so, I'd try to solve this with an iterative (one sphere after another) and more physical approach. – Marius Wallraff Dec 27 '21 at 11:22
  • @MariusWallraff What method do you mean for work on, Python or LAMMPS? Gravity and … make the model physical. I didn't mentioned that, but it is useful if can be considered (handled) in the code. Just filling the box rather uniformly and placing spheres randomly i.e. not radius sensitive and not such settlements where big spheres going to one side and … . I would be appreciated for any recommendations. – Ali_Sh Dec 28 '21 at 04:20

0 Answers0