Skip to content

Commit ecf0fa3

Browse files
authored
Fix issue in model without faces (#1494)
* Fix issue in model without faces * assert right error message
1 parent 43a3e10 commit ecf0fa3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/ansys/dpf/core/faces.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,12 @@ def __get_face(self, faceindex=None, faceid=None):
296296
"""
297297
if faceindex is None:
298298
faceindex = self._mesh.property_field(face_properties.faces_type).scoping.index(faceid)
299+
if (faceindex < 0):
300+
raise ValueError('face not found')
299301
elif faceid is None:
300302
faceid = self._mesh.property_field(face_properties.faces_type).scoping.id(faceindex)
303+
if (faceid < 0):
304+
raise ValueError('face not found')
301305
nodeIdx = self._mesh.property_field(
302306
face_properties.faces_nodes_connectivity
303307
).get_entity_data(faceindex)

tests/test_faces.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ def model_faces(fluent_axial_comp):
1111
faces = model.metadata.meshed_region.faces
1212
return faces
1313

14+
@pytest.fixture()
15+
def mesh_wo_faces(simple_bar):
16+
model = dpf.Model(simple_bar)
17+
return model.metadata.meshed_region
18+
1419

1520
@pytest.mark.skipif(
1621
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
@@ -73,3 +78,19 @@ def test_face_scoping():
7378
assert faces_sco.location == dpf.locations.faces
7479
assert faces_sco.size == 3
7580
assert faces_sco.ids[2] == 4
81+
82+
@pytest.mark.skipif(
83+
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
84+
reason="faces location was not supported before 7.0",
85+
)
86+
def test_mesh_without_faces(mesh_wo_faces):
87+
assert mesh_wo_faces.faces.n_faces == 0
88+
assert mesh_wo_faces.faces.scoping.size == 0
89+
assert mesh_wo_faces.faces.faces_type_field.size == 0
90+
assert mesh_wo_faces.faces.faces_nodes_connectivity_field.size == 0
91+
with pytest.raises(ValueError) as e:
92+
mesh_wo_faces.faces.face_by_id(1)
93+
assert 'face not found' in e
94+
with pytest.raises(ValueError) as e:
95+
mesh_wo_faces.faces.face_by_index(1)
96+
assert 'face not found' in e

0 commit comments

Comments
 (0)