Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Skip negative cell indices when packing coefficients #3361

Merged
merged 7 commits into from
Sep 11, 2024

Conversation

jorgensd
Copy link
Member

@jorgensd jorgensd commented Aug 21, 2024

Continuation of #3260.

If one has multiple disjoint sub-meshes in a variational form, then restricting packing by enabled_coefficients per integral type is not sufficient.

Example follows:
Divide an interval mesh in three disjoint cell sets (left, center, right).
If we want to create a coupling from the right submesh to the parent mesh at the interface between center and right),
we can add an integral (u_parent("+")-u_parent("-"))*v_right("+")*dS(interface_rc) to our variational form.
Similarly we could do the same for the left integral: (u_parent("+")-u_parent("-"))*v_left("+")*dS(interface_lc).

However, now both coefficient v_right and v_left will be packed for all facets marked with either interface_rc or interface_lc, which leads to undefined behavior (segfaults).

The following PR adds a check after fetching the cell during packing, and only packs coefficients if the cell index is positive.

Issue reported by @RemDelaporteMathurin when trying to adapt my example: https://gist.github.com/jorgensd/8a5c32f491195e838f5863ca88b27bce#file-problem-py to multiple surfaces.

Copy link
Contributor

@RemDelaporteMathurin RemDelaporteMathurin left a comment

Choose a reason for hiding this comment

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

Tested it locally with this script and everything runs fine. The SEGV I was previously having doesn't appear anymore.

Thanks @jorgensd ! 🎉

@jorgensd
Copy link
Member Author

@jpdean do you have time to look at this?

@jorgensd jorgensd added this to the 0.9.0 milestone Sep 3, 2024
Copy link
Member

@garth-wells garth-wells left a comment

Choose a reason for hiding this comment

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

@jorgensd Is there a change we could make to avoid this check? I haven't looked at the details for a long time . . .

@jorgensd
Copy link
Member Author

@jorgensd Is there a change we could make to avoid this check? I haven't looked at the details for a long time . . .

Yes, I have proposed a redesign of the entity_maps concept, see: #3371 for details

@garth-wells garth-wells added this pull request to the merge queue Sep 11, 2024
Merged via the queue into main with commit 442117b Sep 11, 2024
27 of 28 checks passed
@garth-wells garth-wells deleted the dokken/improve-mixed-packing branch September 11, 2024 11:45
schnellerhase pushed a commit to schnellerhase/fenics-dolfinx that referenced this pull request Sep 11, 2024
* Skip negative cell indices when packing coefficients

* Simplify MPI send recv

* Ruff formatting

* Small logic simplification

---------

Co-authored-by: Garth N. Wells <gnw20@cam.ac.uk>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
backport? Suggest PR for backporting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants