diff --git a/ogstools/meshlib/examples/__init__.py b/ogstools/meshlib/examples/__init__.py index 658c837bf1b505bbb9ab9f31536509ab9bd924aa..fee23029b35dd02300a89f203da3bf34a0ba51f3 100644 --- a/ogstools/meshlib/examples/__init__.py +++ b/ogstools/meshlib/examples/__init__.py @@ -3,4 +3,5 @@ from ogstools.definitions import ROOT_DIR # Will probably be replaced with some dynamically generated example examples = ROOT_DIR / "_examples" pvd_file = examples / "2D.pvd" +vtu_file = examples / "2D_ts_0_t_0e+00.vtu" xdmf_file = examples / "2D_single_fracture_HT_2D_single_fracture.xdmf" diff --git a/tests/test_meshlib.py b/tests/test_meshlib.py new file mode 100644 index 0000000000000000000000000000000000000000..ffc9e7f2944ac97ecfadb12623b09e2c622123ee --- /dev/null +++ b/tests/test_meshlib.py @@ -0,0 +1,47 @@ +"""Unit tests for meshlib.""" + +import unittest + +import numpy as np + +from ogstools.meshlib import MeshSeries, examples + + +class UtilsTest(unittest.TestCase): + """Test case for ogstools utilities.""" + + def test_all_types(self): + pvd = MeshSeries(examples.pvd_file) + vtu = MeshSeries(examples.vtu_file) + xdmf = MeshSeries(examples.xdmf_file) + self.assertRaises(TypeError, MeshSeries, __file__) + + for mesh_series in [pvd, xdmf, vtu]: + self.assertTrue( + mesh_series.read(0) == mesh_series.read_closest(1e-6) + ) + self.assertTrue(not np.any(np.isnan(mesh_series.timesteps))) + self.assertTrue( + not np.any(np.isnan(mesh_series.values("temperature"))) + ) + self.assertTrue( + mesh_series.timevalues[mesh_series.closest_timestep(1.0)] + == mesh_series.closest_timevalue(1.0) + ) + mesh_series.clear() + + def test_probe_pvd(self): + "Test point probing on pvd." + mesh_series = MeshSeries(examples.pvd_file) + points = mesh_series.read(0).cell_centers().points + for method in ["nearest", "probefilter"]: + values = mesh_series.probe(points, "temperature", method) + self.assertTrue(not np.any(np.isnan(values))) + + def test_probe_xdmf(self): + "Test point probing on xdmf." + mesh_series = MeshSeries(examples.xdmf_file) + points = mesh_series.read(0).cell_centers().points + for method in ["nearest", "linear", None]: + values = mesh_series.probe(points, "temperature", method) + self.assertTrue(not np.any(np.isnan(values)))