Added test for generate_voxel_image
-import porespy as ps
-import numpy as np
import pytest
+import numpy as np
+import porespy as ps
+import openpnm as op
+from numpy.testing import assert_allclose
class NetExtractTest():
@@ -143,6 +145,27 @@ class NetExtractTest():
assert np.allclose(net1['pore.coords'][:, 0],
net3['pore.coords'][:, 1])
+ def test_generate_voxel_image(self):
+ net = op.network.Cubic(shape=[5, 5, 5])
+ geom = op.geometry.StickAndBall(network=net,
+ pores=net.Ps, throats=net.Ts)
+ geom.add_model(propname="pore.volume",
+ model=op.models.geometry.pore_volume.cube)
+ geom.add_model(propname="throat.volume",
+ model=op.models.geometry.throat_volume.cylinder)
+ im = ps.network_extraction.generate_voxel_image(network=net,
+ pore_shape="cube",
+ throat_shape="cylinder",
+ rtol=0.1)
+ porosity_actual = im.astype(bool).sum() / np.prod(im.shape)
+
+ volume_void = net["pore.volume"].sum() + net["throat.volume"].sum()
+ volume_total = np.prod(net.spacing * net.shape)
+ porosity_desired = volume_void / volume_total
+
+ assert_allclose(actual=porosity_actual, desired=porosity_desired,
+ rtol=0.1)
+
if __name__ == '__main__':
t = NetExtractTest()
