Skip to content

Commit

Permalink
Fix issue in model without faces (#1494)
Browse files Browse the repository at this point in the history
* Fix issue in model without faces

* assert right error message
  • Loading branch information
rafacanton authored Apr 10, 2024
1 parent 43a3e10 commit ecf0fa3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ansys/dpf/core/faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,12 @@ def __get_face(self, faceindex=None, faceid=None):
"""
if faceindex is None:
faceindex = self._mesh.property_field(face_properties.faces_type).scoping.index(faceid)
if (faceindex < 0):
raise ValueError('face not found')
elif faceid is None:
faceid = self._mesh.property_field(face_properties.faces_type).scoping.id(faceindex)
if (faceid < 0):
raise ValueError('face not found')
nodeIdx = self._mesh.property_field(
face_properties.faces_nodes_connectivity
).get_entity_data(faceindex)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ def model_faces(fluent_axial_comp):
faces = model.metadata.meshed_region.faces
return faces

@pytest.fixture()
def mesh_wo_faces(simple_bar):
model = dpf.Model(simple_bar)
return model.metadata.meshed_region


@pytest.mark.skipif(
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
Expand Down Expand Up @@ -73,3 +78,19 @@ def test_face_scoping():
assert faces_sco.location == dpf.locations.faces
assert faces_sco.size == 3
assert faces_sco.ids[2] == 4

@pytest.mark.skipif(
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
reason="faces location was not supported before 7.0",
)
def test_mesh_without_faces(mesh_wo_faces):
assert mesh_wo_faces.faces.n_faces == 0
assert mesh_wo_faces.faces.scoping.size == 0
assert mesh_wo_faces.faces.faces_type_field.size == 0
assert mesh_wo_faces.faces.faces_nodes_connectivity_field.size == 0
with pytest.raises(ValueError) as e:
mesh_wo_faces.faces.face_by_id(1)
assert 'face not found' in e
with pytest.raises(ValueError) as e:
mesh_wo_faces.faces.face_by_index(1)
assert 'face not found' in e

0 comments on commit ecf0fa3

Please sign in to comment.