pseudo_electrostatic_packing#

This is a form of random sequential addition (rsa) where spheres are inserted as close to the specified points as possible without overlapping.

import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
import inspect
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/openpnm/algorithms/_invasion_percolation.py:358: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.
  def _find_trapped_pores(inv_seq, indices, indptr, outlets):  # pragma: no cover

The arguments and their defaults for this function are:

inspect.signature(ps.generators.pseudo_electrostatic_packing)
<Signature (im, r, sites=None, clearance=0, protrusion=0, edges='extended', maxiter=1000, seed=None)>

im#

The image into which the spheres should be inserted. Spheres will be inserted into the True locations, as if these indicate void space.

im = ~ps.generators.borders(shape=[200, 200], mode='faces')
packing = ps.generators.pseudo_electrostatic_packing(im=im, r=8, maxiter=100)

fig, ax = plt.subplots(1, 2, figsize=[12, 6])
ax[0].imshow(im, interpolation='none', origin='lower')
ax[0].axis(False)
ax[1].imshow(packing, interpolation='none', origin='lower')
ax[1].axis(False);
../../../_images/2e3f3e04b7c4c3ab08cf6201a96c6c4d32c570ed68d25df5c473b4d13bca9d6d.png

sites#

A boolean array with True values indicating the point where shperes should be clustered. If not given, the function performs a distance transform of the image and uses all peaks.

sites = ps.generators.borders(shape=[200, 200], mode='corners', thickness=30)
im = np.ones_like(sites, dtype=bool)
packing = ps.generators.pseudo_electrostatic_packing(im=im, sites=sites, r=8, maxiter=100)

fig, ax = plt.subplots(1, 2, figsize=[12, 6])
ax[0].imshow(sites, interpolation='none', origin='lower')
ax[0].axis(False)
ax[1].imshow(packing, interpolation='none', origin='lower')
ax[1].axis(False);
../../../_images/8d8503a385618f8342315ab513e9d0ad0fb38650385f19d95cff363595370c30.png

r#

The radius of the spheres to add:

fig, ax = plt.subplots(1, 2, figsize=[12, 6])

r = 5
im = ~ps.generators.borders(shape=[151, 151], mode='faces')
packing = ps.generators.pseudo_electrostatic_packing(im=im, r=r)
ax[0].imshow(packing, interpolation='none', origin='lower')
ax[0].axis(False)

r = 10
im = ~ps.generators.borders(shape=[151, 151], mode='faces')
packing = ps.generators.pseudo_electrostatic_packing(im=im, r=r)
ax[1].imshow(packing, interpolation='none', origin='lower')
ax[1].axis(False);
../../../_images/9c7205283ef9e047f4ce6b2466048ce37380913cc8958fc370b505ffaf269309.png

clearance#

The spheres can be forced to have some spacing between them by setting clearance > 0, or they can overlap if clearance < 0:

fig, ax = plt.subplots(1, 2, figsize=[12, 6])

im = ~ps.generators.borders(shape=[151, 151], mode='faces')
packing = ps.generators.pseudo_electrostatic_packing(im=im, r=r, clearance=-2)
ax[0].imshow(packing, interpolation='none', origin='lower')
ax[0].axis(False)

im = ~ps.generators.borders(shape=[151, 151], mode='faces')
packing = ps.generators.pseudo_electrostatic_packing(im=im, r=r, clearance=5)
ax[1].imshow(packing, interpolation='none', origin='lower')
ax[1].axis(False);
../../../_images/98a4137df1e3ed87b8d97cd9544fa65489eebf4850ab6bd944c247c3b9a4e6c3.png

protrusion#

One of the uses of this function is to insert spheres like carbon particles into a matrix, like polymer. In these cases it may be desirable to have the spheres protrude slightly.

fig, ax = plt.subplots(1, 2, figsize=[12, 5])

im = ~ps.generators.borders(shape=[151, 151], mode='faces', thickness=20)
packing = ps.generators.pseudo_electrostatic_packing(im=im, r=10, protrusion=0)
ax[0].imshow(packing + 0.5*im, interpolation='none', origin='lower')
ax[0].axis(False)

im = ~ps.generators.borders(shape=[151, 151], mode='faces', thickness=20)
packing = ps.generators.pseudo_electrostatic_packing(im=im, r=10, protrusion=8)
ax[1].imshow(packing + 0.5*im, interpolation='none', origin='lower')
ax[1].axis(False);
../../../_images/d895b731606ba482243e8dcb55534c70bcb3e51bf961be826d4f936333b830fc.png

maxiter#

The maximum number of spheres to add. Limiting this number can ensure the process does not take too long if the image is large, as well allow for partial filling of the image.

fig, ax = plt.subplots(1, 2, figsize=[12, 5])

im = ~ps.generators.borders(shape=[151, 151], mode='faces', thickness=1)
packing = ps.generators.pseudo_electrostatic_packing(im=im, r=10, maxiter=20)
ax[0].imshow(packing, interpolation='none', origin='lower')
ax[0].axis(False)

im = ~ps.generators.borders(shape=[151, 151], mode='faces', thickness=1)
packing = ps.generators.pseudo_electrostatic_packing(im=im, r=10, maxiter=200)
ax[1].imshow(packing, interpolation='none', origin='lower')
ax[1].axis(False);
../../../_images/7a3e33a007a0d15c011ad80a9ff720d3c09d700ba5e33341d798b0837cdde474.png