Skip to content

Commit

Permalink
Update tests to use XDMF mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesring committed Aug 29, 2023
1 parent 3ed480e commit e46b777
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions tests/test_pre_processing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import vtk
from pathlib import Path
from dolfin import Mesh, HDF5File
from dolfin import Mesh, XDMFFile
from vampy.automatedPreprocessing.preprocessing_common import read_polydata
from fsipy.automatedPreprocessing.automated_preprocessing import read_command_line, \
run_pre_processing
Expand All @@ -13,7 +13,7 @@ def test_mesh_model_with_one_inlet():
# Define test data paths
model_path = Path("tests/test_data/tube/tube.stl")
mesh_path_vtu = model_path.with_suffix(".vtu")
mesh_path_hdf5 = model_path.with_suffix(".h5")
mesh_path_xdmf = model_path.with_suffix(".xdmf")

# Define expected values
expected_num_points = 3626
Expand All @@ -39,21 +39,21 @@ def test_mesh_model_with_one_inlet():

# Check that mesh files are created
assert mesh_path_vtu.is_file(), f"VTU mesh file not found at {mesh_path_vtu}"
assert mesh_path_hdf5.is_file(), f"HDF5 mesh file not found at {mesh_path_hdf5}"
assert mesh_path_xdmf.is_file(), f"XDMF mesh file not found at {mesh_path_xdmf}"

# Check that mesh files are not empty and have expected sizes
mesh_vtu = read_polydata(str(mesh_path_vtu))
mesh_hdf5 = Mesh()
mesh_xdmf = Mesh()
try:
hdf5_file = HDF5File(mesh_hdf5.mpi_comm(), str(mesh_path_hdf5), "r")
hdf5_file.read(mesh_hdf5, "/mesh", False)
with XDMFFile(str(mesh_path_xdmf)) as xdmf_file:
xdmf_file.read(mesh_xdmf)
except Exception as e:
print(f"Error reading HDF5 mesh: {e}")
print(f"Error reading XDMF mesh: {e}")

assert mesh_vtu.GetNumberOfPoints() == expected_num_points, \
f"VTU mesh has {mesh_vtu.GetNumberOfPoints()} points, expected {expected_num_points}"
assert mesh_hdf5.num_cells() == expected_num_cells, \
f"HDF5 mesh has {mesh_hdf5.num_cells()} cells, expected {expected_num_cells}"
assert mesh_xdmf.num_cells() == expected_num_cells, \
f"XDMF mesh has {mesh_xdmf.num_cells()} cells, expected {expected_num_cells}"


def test_mesh_model_with_one_inlet_and_one_outlet():
Expand All @@ -63,7 +63,7 @@ def test_mesh_model_with_one_inlet_and_one_outlet():
# Define test data paths
model_path = Path("tests/test_data/cylinder/cylinder.vtp")
mesh_path_vtu = model_path.with_suffix(".vtu")
mesh_path_hdf5 = model_path.with_suffix(".h5")
mesh_path_xdmf = model_path.with_suffix(".xdmf")

# Define expected values
expected_num_points = 2153
Expand All @@ -89,21 +89,21 @@ def test_mesh_model_with_one_inlet_and_one_outlet():

# Check that mesh files are created
assert mesh_path_vtu.is_file(), f"VTU mesh file not found at {mesh_path_vtu}"
assert mesh_path_hdf5.is_file(), f"HDF5 mesh file not found at {mesh_path_hdf5}"
assert mesh_path_xdmf.is_file(), f"XDMF mesh file not found at {mesh_path_xdmf}"

# Check that mesh files are not empty and have expected sizes
mesh_vtu = read_polydata(str(mesh_path_vtu))
mesh_hdf5 = Mesh()
mesh_xdmf = Mesh()
try:
hdf5_file = HDF5File(mesh_hdf5.mpi_comm(), str(mesh_path_hdf5), "r")
hdf5_file.read(mesh_hdf5, "/mesh", False)
with XDMFFile(str(mesh_path_xdmf)) as xdmf_file:
xdmf_file.read(mesh_xdmf)
except Exception as e:
print(f"Error reading HDF5 mesh: {e}")
print(f"Error reading XDMF mesh: {e}")

assert mesh_vtu.GetNumberOfPoints() == expected_num_points, \
f"VTU mesh has {mesh_vtu.GetNumberOfPoints()} points, expected {expected_num_points}"
assert mesh_hdf5.num_cells() == expected_num_cells, \
f"HDF5 mesh has {mesh_hdf5.num_cells()} cells, expected {expected_num_cells}"
assert mesh_xdmf.num_cells() == expected_num_cells, \
f"XDMF mesh has {mesh_xdmf.num_cells()} cells, expected {expected_num_cells}"


def test_mesh_model_with_one_inlet_and_two_outlets():
Expand All @@ -113,7 +113,7 @@ def test_mesh_model_with_one_inlet_and_two_outlets():
# Define test data paths
model_path = Path("tests/test_data/artery/artery.stl")
mesh_path_vtu = model_path.with_suffix(".vtu")
mesh_path_hdf5 = model_path.with_suffix(".h5")
mesh_path_xdmf = model_path.with_suffix(".xdmf")

# Define expected values
expected_num_points = 5860
Expand All @@ -139,21 +139,21 @@ def test_mesh_model_with_one_inlet_and_two_outlets():

# Check that mesh files are created
assert mesh_path_vtu.is_file(), f"VTU mesh file not found at {mesh_path_vtu}"
assert mesh_path_hdf5.is_file(), f"HDF5 mesh file not found at {mesh_path_hdf5}"
assert mesh_path_xdmf.is_file(), f"XDMF mesh file not found at {mesh_path_xdmf}"

# Check that mesh files are not empty and have expected sizes
mesh_vtu = read_polydata(str(mesh_path_vtu))
mesh_hdf5 = Mesh()
mesh_xdmf = Mesh()
try:
hdf5_file = HDF5File(mesh_hdf5.mpi_comm(), str(mesh_path_hdf5), "r")
hdf5_file.read(mesh_hdf5, "/mesh", False)
with XDMFFile(str(mesh_path_xdmf)) as xdmf_file:
xdmf_file.read(mesh_xdmf)
except Exception as e:
print(f"Error reading HDF5 mesh: {e}")
print(f"Error reading XDMF mesh: {e}")

assert mesh_vtu.GetNumberOfPoints() == expected_num_points, \
f"VTU mesh has {mesh_vtu.GetNumberOfPoints()} points, expected {expected_num_points}"
assert mesh_hdf5.num_cells() == expected_num_cells, \
f"HDF5 mesh has {mesh_hdf5.num_cells()} cells, expected {expected_num_cells}"
assert mesh_xdmf.num_cells() == expected_num_cells, \
f"XDMF mesh has {mesh_xdmf.num_cells()} cells, expected {expected_num_cells}"


def test_mesh_model_with_variable_mesh_density():
Expand All @@ -167,7 +167,7 @@ def test_mesh_model_with_variable_mesh_density():
copied_sphere_file_path = sphere_file_path.with_name(model_path.stem + "_distance_to_sphere_spheres.vtp")

mesh_path_vtu = model_path.with_suffix(".vtu")
mesh_path_hdf5 = model_path.with_suffix(".h5")
mesh_path_xdmf = model_path.with_suffix(".xdmf")

# Make copies of the original model and sphere files using pathlib
model_path.write_text(original_model_path.read_text())
Expand Down Expand Up @@ -197,21 +197,21 @@ def test_mesh_model_with_variable_mesh_density():

# Check that mesh files are created
assert mesh_path_vtu.is_file(), f"VTU mesh file not found at {mesh_path_vtu}"
assert mesh_path_hdf5.is_file(), f"HDF5 mesh file not found at {mesh_path_hdf5}"
assert mesh_path_xdmf.is_file(), f"XDMF mesh file not found at {mesh_path_xdmf}"

# Check that mesh files are not empty and have expected sizes
mesh_vtu = read_polydata(str(mesh_path_vtu))
mesh_hdf5 = Mesh()
mesh_xdmf = Mesh()
try:
hdf5_file = HDF5File(mesh_hdf5.mpi_comm(), str(mesh_path_hdf5), "r")
hdf5_file.read(mesh_hdf5, "/mesh", False)
with XDMFFile(str(mesh_path_xdmf)) as xdmf_file:
xdmf_file.read(mesh_xdmf)
except Exception as e:
print(f"Error reading HDF5 mesh: {e}")
print(f"Error reading XDMF mesh: {e}")

assert mesh_vtu.GetNumberOfPoints() == expected_num_points, \
f"VTU mesh has {mesh_vtu.GetNumberOfPoints()} points, expected {expected_num_points} points"
assert mesh_hdf5.num_cells() == expected_num_cells, \
f"HDF5 mesh has {mesh_hdf5.num_cells()} cells, expected {expected_num_cells} cells"
assert mesh_xdmf.num_cells() == expected_num_cells, \
f"XDMF mesh has {mesh_xdmf.num_cells()} cells, expected {expected_num_cells} cells"


def compute_cylinder_diameter_at_cut(mesh, point_coords, plane_normal):
Expand Down Expand Up @@ -252,7 +252,7 @@ def test_mesh_model_with_variable_solid_thickness():
copied_sphere_file_path = sphere_file_path.with_name(model_path.stem + "_distance_to_sphere_solid_thickness.vtp")

mesh_path_vtu = model_path.with_suffix(".vtu")
mesh_path_hdf5 = model_path.with_suffix(".h5")
mesh_path_xdmf = model_path.with_suffix(".xdmf")

# Make copies of the original model and sphere files using pathlib
model_path.write_text(original_model_path.read_text())
Expand Down Expand Up @@ -286,21 +286,21 @@ def test_mesh_model_with_variable_solid_thickness():

# Check that mesh files are created
assert mesh_path_vtu.is_file(), f"VTU mesh file not found at {mesh_path_vtu}"
assert mesh_path_hdf5.is_file(), f"HDF5 mesh file not found at {mesh_path_hdf5}"
assert mesh_path_xdmf.is_file(), f"XDMF mesh file not found at {mesh_path_xdmf}"

# Check that mesh files are not empty and have expected sizes
mesh_vtu = read_polydata(str(mesh_path_vtu))
mesh_hdf5 = Mesh()
mesh_xdmf = Mesh()
try:
hdf5_file = HDF5File(mesh_hdf5.mpi_comm(), str(mesh_path_hdf5), "r")
hdf5_file.read(mesh_hdf5, "/mesh", False)
with XDMFFile(str(mesh_path_xdmf)) as xdmf_file:
xdmf_file.read(mesh_xdmf)
except Exception as e:
print(f"Error reading HDF5 mesh: {e}")
print(f"Error reading XDMF mesh: {e}")

assert mesh_vtu.GetNumberOfPoints() == expected_num_points, \
f"VTU mesh has {mesh_vtu.GetNumberOfPoints()} points, expected {expected_num_points} points"
assert mesh_hdf5.num_cells() == expected_num_cells, \
f"HDF5 mesh has {mesh_hdf5.num_cells()} cells, expected {expected_num_cells} cells"
assert mesh_xdmf.num_cells() == expected_num_cells, \
f"XDMF mesh has {mesh_xdmf.num_cells()} cells, expected {expected_num_cells} cells"

# Compute diameter at inlet and outlet
diameter_at_inlet = compute_cylinder_diameter_at_cut(mesh_vtu, [0, -3.1, 0], [0, 1, 0])
Expand Down

0 comments on commit e46b777

Please sign in to comment.