Added test for openpnm_to_im method in IO module
-import porespy as ps
-import numpy as np
-import pytest
import os
import sys
+import pytest
+import numpy as np
+import porespy as ps
+import openpnm as op
+from numpy.testing import assert_allclose
class ExportTest():
@@ -51,6 +53,27 @@ class ExportTest():
assert a < b
os.remove('dictvtk.vti')
+ def test_openpnm_to_im(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)
+ geom.regenerate_models()
+
+ im = ps.io.openpnm_to_im(network=net, pore_shape="cube",
+ throat_shape="cylinder", rtol=0.01)
+ 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.05)
+
if __name__ == '__main__':
t = ExportTest()
