cylinders#

This creates a pile of overlapping cylinders, resembling fibrous mats.

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

The arguments and defaults for this function can be listed as follows:

inspect.signature(ps.generators.cylinders)
<Signature (shape: List[int], r: int, ncylinders: int = None, porosity: float = None, phi_max: float = 0, theta_max: float = 90, length: float = None, maxiter: int = 3, seed=None)>

shape#

The dimension of the image to create. This must be 3D since 2D overlapping cylinders don’t make much physical sense.

im = ps.generators.cylinders(shape=[250, 250, 250], r=8, ncylinders=100)

fig, ax = plt.subplots(1, 1, figsize=[6, 6])
ax.imshow(ps.visualization.show_planes(~im))
ax.axis(False);
../../../_images/6e7400834ff2c4cfd5ea5d9791a35bc2857f0068cd773e67ad9aaa18d6fc6426.png

r#

The radius of the cylinders to add

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

r = 8
im = ps.generators.cylinders(shape=[200, 200, 200], r=r, ncylinders=100)
ax[0].imshow(ps.visualization.sem(im, axis=2), cmap=plt.cm.bone)
ax[0].axis(False)

r = 16
im = ps.generators.cylinders(shape=[200, 200, 200], r=r, ncylinders=100)

ax[1].imshow(ps.visualization.sem(im, axis=2), cmap=plt.cm.bone)
ax[1].axis(False);
../../../_images/5517ca46e464fb1ebabfc947b083fec08f22b6f2f85aeb2ad79449419e760049.png

ncylinders#

Directly controls the number of cylinders that are added:

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

r = 8
ncylinders = 25
im = ps.generators.cylinders(shape=[200, 200, 200], r=r, ncylinders=ncylinders)
ax[0].imshow(ps.visualization.sem(im, axis=2), cmap=plt.cm.bone)
ax[0].axis(False)

ncylinders = 100
im = ps.generators.cylinders(shape=[200, 200, 200], r=r, ncylinders=ncylinders)

ax[1].imshow(ps.visualization.sem(im, axis=2), cmap=plt.cm.bone)
ax[1].axis(False);
../../../_images/58a46a965015820d95b150b6ddf544d7533a008d8c1754e1df3b00b88d243647.png

porosity#

Instead of specifying the number of cylinders, you can optional request a porosity which the function attempts to match iteratively:

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

r = 8
porosity = 0.4
im = ps.generators.cylinders(shape=[200, 200, 200], r=r, porosity=porosity)
ax[0].imshow(ps.visualization.sem(im, axis=2), cmap=plt.cm.bone)
ax[0].axis(False)
ax[0].set_title(f'Actual porosity is {im.sum()/im.size}')

porosity = 0.8
im = ps.generators.cylinders(shape=[200, 200, 200], r=r, porosity=porosity)

ax[1].imshow(ps.visualization.sem(im, axis=2), cmap=plt.cm.bone)
ax[1].axis(False)
ax[1].set_title(f'Actual porosity is {im.sum()/im.size}');
../../../_images/af6d8a30f53fbb13556f80f73584513dd85e579e8c0d089f855f2f6cf0ed0427.png

phi_max and theta_max#

Controls the amount of random rotation of the fibers. Orientations will be chosen randomly from between 0 and the given values.

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

im = ps.generators.cylinders(shape=[100, 100, 100], r=5, ncylinders=100, phi_max=0)
ax[0].imshow(ps.visualization.sem(im, axis=0))
ax[0].axis(False)

im = ps.generators.cylinders(shape=[100, 100, 100], r=5, ncylinders=100, phi_max=90)

ax[1].imshow(ps.visualization.sem(im, axis=0))
ax[1].axis(False);
../../../_images/03f9af98aacf4cdf39b9e38f686a892df7b432b4c5431866514f795d2316396a.png
fig, ax = plt.subplots(1, 2, figsize=[12, 6])

im = ps.generators.cylinders(shape=[100, 100, 100], r=5, ncylinders=100, theta_max=10)
ax[0].imshow(ps.visualization.sem(im, axis=2))
ax[0].axis(False)

im = ps.generators.cylinders(shape=[100, 100, 100], r=5, ncylinders=100, theta_max=90)

ax[1].imshow(ps.visualization.sem(im, axis=2))
ax[1].axis(False);
../../../_images/04c297a4538a0f4bd28c0b3bb37a6ed9727425b9939d25b7a2a12a194213305c.png

length#

Controls the length of the fibers. By default they always extend to the image edges, but they can be shortened.

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

im = ps.generators.cylinders(shape=[100, 100, 100], r=5, ncylinders=100, length=10)
ax[0].imshow(ps.visualization.sem(im, axis=2))
ax[0].axis(False)

im = ps.generators.cylinders(shape=[100, 100, 100], r=5, ncylinders=100, length=50)

ax[1].imshow(ps.visualization.sem(im, axis=2))
ax[1].axis(False);
../../../_images/c518eed917544e75cf0988b81a24e4b667af87688649428eced82e4209b53da1.png

maxiter#

Controls how many iterations the function uses to match the requested porosity. If ncylinders is given instead of porosity, then maxiter is ignored. The default is 3, which is usually fine.

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

porosity = 0.5
im = ps.generators.cylinders(shape=[200, 200, 200], r=8, porosity=porosity, maxiter=2)
ax[0].imshow(ps.visualization.sem(im, axis=2), cmap=plt.cm.bone)
ax[0].axis(False)
ax[0].set_title(f'Actual porosity is {im.sum()/im.size}')

im = ps.generators.cylinders(shape=[200, 200, 200], r=8, porosity=porosity, maxiter=5)

ax[1].imshow(ps.visualization.sem(im, axis=2), cmap=plt.cm.bone)
ax[1].axis(False)
ax[1].set_title(f'Actual porosity is {im.sum()/im.size}');
../../../_images/71d2a60ede426fae3983ee32b83807fa9dcde599e1a064298f493f48dc2d2e35.png