pseudo_gravity_packing#

This is a form of random sequential addition (rsa) that mimics gravity by always putting the next sphere at the lowest possible location.

import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
ps.visualization.set_mpl_style()
[17:46:40] ERROR    PARDISO solver not installed, run `pip install pypardiso`. Otherwise,          _workspace.py:56
                    simulations will be slow. Apple M chips not supported.                                         

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.cylindrical_plug(shape=[151, 101, 101], axis=0)
packing = ps.generators.pseudo_gravity_packing(im=~im, r=8, maxiter=100)

fig, ax = plt.subplots(1, 2, figsize=[8, 4])
ax[0].imshow(packing[40, ...], interpolation='none', origin='lower')
ax[0].axis(False)
ax[1].imshow(packing[..., 50], interpolation='none', origin='lower')
ax[1].axis(False);
../../../_images/43a25938aebb98d148cf7d3a5599df1c32481a6395a1106554ddf3e82b3cd3e3.png

r#

The radius of the spheres to add:

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

r = 5
im = ps.generators.cylindrical_plug(shape=[151, 101, 101], axis=0)
packing = ps.generators.pseudo_gravity_packing(im=~im, r=r, maxiter=500)
ax[0].imshow(ps.visualization.xray(~packing, axis=2).T, interpolation='none', origin='lower')
ax[0].axis(False)

r = 10
im = ps.generators.cylindrical_plug(shape=[151, 101, 101], axis=0)
packing = ps.generators.pseudo_gravity_packing(im=~im, r=r, maxiter=100)
ax[1].imshow(ps.visualization.xray(~packing, axis=2).T, interpolation='none', origin='lower')
ax[1].axis(False);
../../../_images/c6b4abd625d05e8035e13504d09d259917d39be06052de2df8230e06611fc6b5.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, 5])

im = np.zeros([300, 300], dtype=bool)
packing = ps.generators.pseudo_gravity_packing(im=im, r=r, clearance=3, maxiter=500)
ax[0].imshow(packing, interpolation='none', origin='lower')
ax[0].axis(False)

im = np.zeros([300, 300], dtype=bool)
packing = ps.generators.pseudo_gravity_packing(im=im, r=r, clearance=-1, maxiter=100)
ax[1].imshow(packing, interpolation='none', origin='lower')
ax[1].axis(False);
../../../_images/01324b12c228288e15e2f1dc4de17825b0387b667d30f2e09658c3e38190f8b0.png

protrusion#

The spheres can be allowed to protrude into the foreground, or displaced away from the foreground by using a positive or negative value, respectively:

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

im = ps.generators.blobs([300, 300], porosity=0.2, seed=0)
packing = ps.generators.pseudo_gravity_packing(im=im, r=r, protrusion=3)
ax[0].imshow(packing + im*2.0, interpolation='none', origin='lower')
ax[0].axis(False)

im = ps.generators.blobs([300, 300], porosity=0.1, seed=0)
packing = ps.generators.pseudo_gravity_packing(im=im, r=r, protrusion=-5, maxiter=100)
ax[1].imshow(packing + im*2.0, interpolation='none', origin='lower')
ax[1].axis(False);
../../../_images/72037a8843f67fa51a721b1e67782153f43f26af93e871b08101c6b77b6f9412.png

axis#

Controls the direction of gravity. The default is 0, which means the spheres fall towards the x=0 axis.

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

packing = ps.generators.pseudo_gravity_packing(shape=[300, 300], r=r, axis=0, maxiter=100)
ax[0].imshow(packing, interpolation='none', origin='lower')
ax[0].axis(False)

packing = ps.generators.pseudo_gravity_packing(shape=[300, 300], r=r, axis=1, maxiter=100)
ax[1].imshow(packing, interpolation='none', origin='lower')
ax[1].axis(False);
../../../_images/9c135b595424cc6a8d82a8c96d37296a826aa3dfeaef0eb5a023231b0226b789.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])

packing = ps.generators.pseudo_gravity_packing(shape=[300, 300], r=r, maxiter=50)
ax[0].imshow(packing, interpolation='none', origin='lower')
ax[0].axis(False)

packing = ps.generators.pseudo_gravity_packing(shape=[300, 300], r=r, maxiter=150)
ax[1].imshow(packing, interpolation='none', origin='lower')
ax[1].axis(False);
../../../_images/91acb828b52782b63f11a62beced0c7fee79544f6dd160ea7828e2c6cd8f3c70.png

value#

The value of the used to fill the spheres can be specified, which is helpful for finding spheres adding a different steps:

im = ps.generators.random_spheres(
    shape=[200, 200],
    r=16,
    clearance=5,
    edges='extended',
    seed=0,
    phi=.25,
    smooth=False,
    value=3,
)
im = ps.generators.random_spheres(
    im=im,
    r=8,
    clearance=5,
    protrusion=5,
    edges='contained',
    seed=0,
    phi=0.1,
    maxiter=1000,
    smooth=False,
    value=2,
)
im = ps.generators.random_spheres(
    im=im,
    r=12,
    clearance=5,
    protrusion=5,
    edges='contained',
    seed=0,
    smooth=True,
    value=1
)
fig, ax = plt.subplots()
ax.imshow(im)
ax.axis(False);
../../../_images/1389cc73795938253798240b348a9df6a1934d64b2c040e8fe97d878391eeca3.png