Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue in model without faces #1494

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading