Skip to content

Commit

Permalink
[field] Fix mean() for unstructured meshes
Browse files Browse the repository at this point in the history
  • Loading branch information
holl- committed Jan 4, 2025
1 parent bf23842 commit e181b87
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion phi/field/_field_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,10 @@ def mean(field: Field, dim=lambda s: s.non_channel.non_batch) -> Tensor:
Returns:
`phi.Tensor`
"""
result = math.mean(field.values, dim=dim)
if field.is_grid:
result = math.mean(field.values, dim=dim)
else:
result = math.mean(field.values, dim=dim, weight=field.geometry.volume)
if (instance(field.geometry) & spatial(field.geometry)) in result.shape:
return field.with_values(result)
return result
Expand Down

0 comments on commit e181b87

Please sign in to comment.