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()
[20:04:37] 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);
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);
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);
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);
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);
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);
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);