Skip to content

Commit

Permalink
feat(py): Use *weighted* average for coarse barycenters
Browse files Browse the repository at this point in the history
  • Loading branch information
Riccardo Milani committed Apr 11, 2024
1 parent f2d29c7 commit e84eda5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions examples/scripts/comma_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def build_coarse_graph(
:obj:`np.ndarray` of `int`
Vector telling how many boundary faces each cell of the coarse graph has
:obj:`np.ndarray` of `float`
Cell centers of the coarse graph"""
Cell centers of the coarse graph (weighted average of the fine one)"""
fc2cc = np.asarray(fc2cc, dtype=int)
CSR_row = np.asarray(CSR_row, dtype=int)
CSR_col = np.asarray(CSR_col, dtype=int)
Expand All @@ -236,7 +236,9 @@ def build_coarse_graph(
coarse_n_bnd[cc] = np.max(n_bnd[mask_fc])
coarse_volumes[cc] = np.sum(volumes[mask_fc])
# This is not actually very good, but still...
coarse_centers[cc, :] = centers[mask_fc, :].mean(axis=0)
coarse_centers[cc, :] = np.average(
centers[mask_fc, :], axis=0, weights=volumes[mask_fc]
)
neighs_cc = {}
# for every (previous) fine cell composing the current coarse cell...
for fc in fcs:
Expand Down

0 comments on commit e84eda5

Please sign in to comment.