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

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)>

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/c0acf9baaeb173b17b595ad3fdc4797e21b47da306b8a98acd6f74d3305589d0.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/2dbbd68099329b3e523622130db49835318b721ac3ccbb4bb8484a74c8d6b694.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/ea1cc1c41fd44936ebbc35db51f147d9d4cbf36242bab82abf4def6203ae7310.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/4a67d76fd5a487fda4b4ebd17e868c7519d4391a8e49cb7cd1f3521ed58db468.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/784c200e2a09eac90be8f3148e9a5dfb3066b729c0fd08e1a316ffa7b354cb11.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/b0d35275ca6020aa6fd1956ea9ed23b87a2caa51c6c52385a4b4553232ed5bb4.png