def fill_the_void(roundOfInfilling, totalvolume, occupation, ideal_volume, roundRadius, rangeRadius, maximum): gridnum = list(range(0, gridnumbers1)) #remove the fully filled cells _remove_grid.remove_cells(roundRadius, Circles, w1, grid1, cols1, rows1) # the loop will stop if the mass of this round of infilling reaches the target or it runs out of void grids # the size of divided grids is 5, which can normally covers all round of infilling while totalvolume < ideal_volume and len(gridnum) > 0: #randomly select a void grid and try to add particles q = np.random.randint(len(gridnum)) # decide the particle radius if roundRadius != maximum: n = _radii.radii(gridnum[q], roundRadius, rangeRadius, maximum, Circles, cols1, w1, width, height) else: n = _single_radius.single_radius(gridnum[q], roundRadius, rangeRadius, maximum, Circles, cols1, w1, width, height) # insert the particle in the canvas if n is False: gridnum.remove(gridnum[q]) else: grid1[q] = 1 totalvolume = totalvolume + math.floor(3.1415926 * n * n) occupation = occupation + 1 gridnum.remove(gridnum[q]) if len(gridnum) == 0: print('round of infilling:', roundOfInfilling, 'infilling and add:', occupation, totalvolume, ideal_volume) fill_the_void(roundOfInfilling, totalvolume, occupation, ideal_volume, roundRadius, rangeRadius, maximum) # adjust the volume of particles print( maximum > roundRadius, totalvolume > ideal_volume * 1.02, not _mini_radius.particles_mini( maximums[roundOfInfilling], roundRadius, Circles)) if maximum > roundRadius and totalvolume > ideal_volume * 1.02 and not _mini_radius.particles_mini( maximums[roundOfInfilling], roundRadius, Circles): maximum -= 1 _adjustment.remove_particles(maximums[roundOfInfilling], roundRadius, Circles) print('volume surpasses the target by 2%', 'round of infilling:', roundOfInfilling, 'infilling and add:', occupation, totalvolume, ideal_volume) fill_the_void(roundOfInfilling, 0, 0, ideal_volume, roundRadius, rangeRadius, maximum) print('round of infilling:', roundOfInfilling, 'infilling and add:', occupation, totalvolume, ideal_volume)
def fill_the_void(roundOfInfilling, totalvolume, occupation, ideal_volume, roundRadius, rangeRadius, maximum): gridnum = list(range(0, gridnumbers1)) # remove the fully filled cells _remove_grid.remove_cells(roundRadius, Circles, w1, grid1, cols1, rows1, depths1) while totalvolume < ideal_volume and len(gridnum) > 0: #randomly select a void grid and try to add particles q = np.random.randint(len(gridnum)) # decide the particle radius if roundRadius != maximum: n = _radii.radii(gridnum[q], roundRadius, rangeRadius, maximum, Circles, cols1, depths1, w1, width, height, depth) else: n = _single_radius.single_radius(gridnum[q], roundRadius, rangeRadius, maximum, Circles, cols1, depths1, w1, width, height, depth) # insert the particle in the canvas if n is False: gridnum.remove(gridnum[q]) else: grid1[q] = 1 totalvolume = totalvolume + math.floor((4 / 3) * pi * n**3) occupation = occupation + 1 gridnum.remove(gridnum[q]) if len(gridnum) == 0: print('round of infilling:', roundOfInfilling, 'infilling and add:', occupation, totalvolume, ideal_volume) fill_the_void(roundOfInfilling, totalvolume, occupation, ideal_volume, roundRadius, rangeRadius, maximum) # adjust the volume of particles if maximum > roundRadius and totalvolume > ideal_volume * 1.02 and not _mini_radius.particles_mini( maximums[roundOfInfilling], roundRadius, Circles): maximum -= 1 _adjustment.remove_particles(maximums[roundOfInfilling], roundRadius, Circles) print('volume surpasses the target by 2%', 'round of infilling:', roundOfInfilling, 'infilling and add:', occupation, totalvolume, ideal_volume) fill_the_void(roundOfInfilling, 0, 0, ideal_volume, roundRadius, rangeRadius, maximum) print('round of infilling:', roundOfInfilling, 'infilling and add:', occupation, totalvolume, ideal_volume)
def poisson(r): setup_poisson(gridnumbers, cols, rows) if _adjustment.surpass_volume_poisson(1.02, Circles, ideal_volumes): while _adjustment.surpass_volume_poisson( 1.02, Circles, ideal_volumes) and _adjustment.stop_recursion( Circles, roundRadius): _adjustment.adjust_radius(-1, Circles, roundRadius) if not _adjustment.surpass_volume_poisson(1, Circles, ideal_volumes): _adjustment.adjust_radius(1, Circles, roundRadius) elif not _adjustment.surpass_volume_poisson(1, Circles, ideal_volumes): _adjustment.remove_particles(maximums[0], roundRadius[0], Circles) r = r - 10 poisson(r)
def poisson(r): gradient = width / 100 setup_poisson(gridnumbers, cols, rows) if _adjustment.surpass_volume_poisson(5, Circles, ideal_volumes): # volume surpasses the target by more than 20%, remove the particle and regenerate with a larger minimum radius _adjustment.remove_particles(maximums[0], roundRadius[0], Circles) if r + gradient < width: r = r + gradient poisson(r) elif _adjustment.surpass_volume_poisson(2, Circles, ideal_volumes): # volume surpasses the target by more than 2%, shrink the radius while _adjustment.surpass_volume_poisson(1.02, Circles, ideal_volumes) and _adjustment.stop_recursion(Circles, roundRadius): _adjustment.adjust_radius(-1, Circles, roundRadius) if not _adjustment.surpass_volume_poisson(1, Circles, ideal_volumes): _adjustment.adjust_radius(1, Circles, roundRadius) elif not _adjustment.surpass_volume_poisson(1, Circles, ideal_volumes): # volume does not reach the target, remove the particle and regenerate with a smaller minimum radius _adjustment.remove_particles(maximums[0], roundRadius[0], Circles) r = r - gradient poisson(r)