Skip to content

Commit 8d9ce91

Browse files
committed
Improve compute areas to cover quads as well as triangles in producing point data.
1 parent 1221327 commit 8d9ce91

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lyceanem/geometry/geometryfunctions.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,23 @@ def compute_areas(field_data):
335335
for inc, cell in enumerate(field_data.cells):
336336
if field_data.cells[inc].type == "triangle":
337337
for point_inc in range(field_data.points.shape[0]):
338-
field_data.point_data["Area"][point_inc] = np.sum(
339-
field_data.cell_data["Area"][inc][
340-
np.where(field_data.cells[inc].data == point_inc)[0]
341-
]
342-
/ 3
338+
valid_triangles = np.any(
339+
field_data.cells[inc].data == point_inc, axis=1
340+
).nonzero()[0]
341+
field_data.point_data["Area"][point_inc] = (
342+
np.sum(field_data.cell_data["Area"][inc][valid_triangles]) / 3
343343
)
344344

345+
elif field_data.cells[inc].type == "quad":
346+
for point_inc in range(field_data.points.shape[0]):
347+
for point_inc in range(field_data.points.shape[0]):
348+
valid_quads = np.any(
349+
field_data.cells[inc].data == point_inc, axis=1
350+
).nonzero()[0]
351+
field_data.point_data["Area"][point_inc] = (
352+
np.sum(field_data.cell_data["Area"][inc][valid_quads]) / 4
353+
)
354+
345355
return field_data
346356

347357

0 commit comments

Comments
 (0)