Skip to content

Fix bug in mesh refinement with multiple points - #416

Open
santisoler wants to merge 7 commits into
mainfrom
fix-bug-refine-points
Open

Fix bug in mesh refinement with multiple points#416
santisoler wants to merge 7 commits into
mainfrom
fix-bug-refine-points

Conversation

@santisoler

Copy link
Copy Markdown
Member

Patch insert_cells to consider multiple points: fix how the total number of iterations are defined in insert_cells to extend the support to multiple points even if a single int is passed to levels. Update docs of the method.

Closes #415

Fix how the total number of iterations are defined in `insert_cells` to
extend the support to multiple points even if a single int is passed to
`levels`.
Comment thread discretize/_extensions/tree_ext.pyx Outdated
diagonal_balance = self._diagonal_balance
cdef bool diag_balance = diagonal_balance

cdef int_t n_iters = max(ls.size, cs.shape[0])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just repeat a single integer up to the number of points. Otherwise this would allow you to pass more levels than points and cause a memory error.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jcapriot! Yes, I agree. I polished the code a bit.

The _check_first_dim_broadcast(points=points, levels=levels) will ensure that there cannot be more levels than points (unless a single point is passed). I added an extra error message when a single point and multiple levels are passed, just to let the user know that there might be something off in their inputs.

@santisoler
santisoler marked this pull request as ready for review July 8, 2026 16:44
@santisoler
santisoler requested a review from jcapriot July 8, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Unexpected behaviour on TreeMesh.refine_points

2 participants