sierpinski_foam#

The sierpinski gasket is a classic example of a fractal image with self-similar properties across all length scales. It has also been extensively analyzed so these properties are well know. The sierpinski_foam is a 3D version of the gasket.

import porespy as ps
import matplotlib.pyplot as plt
import numpy as np
import inspect
inspect.signature(ps.generators.sierpinski_foam)
<Signature (dmin, n, ndim=2, max_size=1000000000.0)>

dmin and n#

This generator does not accept size. Instead you specify the smallest hole to add with dmin and the number of scales to create with n:

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

dmin = 5
n = 3
im = ps.generators.sierpinski_foam(dmin=dmin, n=n)
ax[0].imshow(im, interpolation='none')
ax[0].axis(False)

dmin = 3
n = 5
im = ps.generators.sierpinski_foam(dmin=dmin, n=n)
ax[1].imshow(im, interpolation='none')
ax[1].axis(False);
../../../_images/4549c2a97c73eaeaed73ba50e4ae923cc41b8c65a2cc705e46b8f2b9d17da175.png

ndim#

The dimensionality of the image, either 2 or 3. A value of 2 (as above) technically makes a gasket while 3 makes a foam:

ndim = 3
dmin = 5
n = 3
im = ps.generators.sierpinski_foam(dmin=dmin, n=n, ndim=3)

ax = plt.figure().add_subplot(projection='3d')
ax.voxels(1-im[30:60, 30:60, 30:60]);
../../../_images/5c1e6c090cea8921aba50a45270853d2df0ccbefad5d0ab7778a2d7601eec642.png

max_size#

This puts a cap on the maximum number of voxel in the generated image so that it doesn’t get too large. The function will stop iterating if the image size exceeds this value.

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

max_size=1e4
im = ps.generators.sierpinski_foam(dmin=dmin, n=100, max_size=max_size)
ax[0].imshow(im, interpolation='none')
ax[0].axis(False)
ax[0].set_title(f'actual size = {im.size}')

max_size=1e6
im = ps.generators.sierpinski_foam(dmin=dmin, n=100, max_size=max_size)
ax[1].imshow(im, interpolation='none')
ax[1].axis(False)
ax[1].set_title(f'actual size = {im.size}');
../../../_images/1467054c5f595f637b690a3a7b789f28a3f9502d849934a3d5575bc769e183d6.png