Skip to content

Submesh: support tuple subdomain_id#5004

Open
pbrubeck wants to merge 7 commits intomainfrom
pbrubeck/submesh-tuple
Open

Submesh: support tuple subdomain_id#5004
pbrubeck wants to merge 7 commits intomainfrom
pbrubeck/submesh-tuple

Conversation

@pbrubeck
Copy link
Copy Markdown
Contributor

@pbrubeck pbrubeck commented Mar 31, 2026

Enhances the valid values for subdomain_id for Submesh, so it matches closely the behaivor of the DirichletBC's subdomain kwarg. This spares users from relabeling the mesh themselves.

  • Submesh(mesh, ..., subdomain_id=[1, 2]) takes the union of subdomains 1 and 2 (this works for codim-0 and codim-1)
  • Submesh(mesh, ..., subdomain_id=[(1, 2)]) takes the intersection of subdomains 1 and 2 (this works for codim-0 and codim-1)

Fixes #5001

@pbrubeck pbrubeck force-pushed the pbrubeck/submesh-tuple branch from 8f6011e to 65502ac Compare March 31, 2026 16:32
@pbrubeck pbrubeck force-pushed the pbrubeck/submesh-tuple branch from 65502ac to 926925d Compare March 31, 2026 16:58
@pbrubeck pbrubeck requested a review from connorjward April 1, 2026 10:14
Copy link
Copy Markdown
Contributor

@connorjward connorjward left a comment

Choose a reason for hiding this comment

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

In #5001 (comment) I've figured out a much nicer way to do this. I'm not sure if we should be adding this very unintuitive API if a better solution exists with only a tiny amount more work.

@pbrubeck
Copy link
Copy Markdown
Contributor Author

pbrubeck commented Apr 1, 2026

In #5001 (comment) I've figured out a much nicer way to do this. I'm not sure if we should be adding this very unintuitive API if a better solution exists with only a tiny amount more work.

Even after parsing, we need to implement a mechanism to traverse the expression tree. I don't agree that the amount of work is tiny.

I suggest we keep this PR to support the same format used by DirichletBC. If you want to you can open a PR where you implement the logic to process the parsed tree for both DirichletBC and Submesh, in a backwards compatible way.

@pbrubeck pbrubeck force-pushed the pbrubeck/submesh-tuple branch from 7804ba6 to 95b1219 Compare April 6, 2026 19:48
@pbrubeck pbrubeck requested a review from connorjward April 7, 2026 07:33
@connorjward
Copy link
Copy Markdown
Contributor

Even after parsing, we need to implement a mechanism to traverse the expression tree. I don't agree that the amount of work is tiny.

I suggest we keep this PR to support the same format used by DirichletBC. If you want to you can open a PR where you implement the logic to process the parsed tree for both DirichletBC and Submesh, in a backwards compatible way.

I disagree that we should be adding a known-to-be-confusing interface to a new a feature just because it's what's already been done. The logic really is very simple. You need:

def myrecursion(expr):
  if isinstance(expr, str | int):
    return dm.getLabel(label_name, expr)
  
  lexpr, op, rexpr = expr
  liset = myrecursion(lexpr)
  riset = myrecursion(rexpr)
  if op == "&":
    return ISIntersect(liset, riset)
  else:
    assert op == "|"
    return ISUnion(liset, riset)

@pbrubeck
Copy link
Copy Markdown
Contributor Author

pbrubeck commented Apr 9, 2026

I disagree that we should be adding a known-to-be-confusing interface to a new a feature just because it's what's already been done.

Intuitively, many users would try to pass a list of subdomains, as they already do for DirichletBC. I think we should support this

@connorjward
Copy link
Copy Markdown
Contributor

I disagree that we should be adding a known-to-be-confusing interface to a new a feature just because it's what's already been done.

Intuitively, many users would try to pass a list of subdomains, as they already do for DirichletBC. I think we should support this

I am very happy with the API for a union. It's the intersection behaviour that I don't like.

@connorjward
Copy link
Copy Markdown
Contributor

I am not the overlord however and this is subjective. If you can get agreement from other members of the team I will happily concede.

@pbrubeck pbrubeck force-pushed the pbrubeck/submesh-tuple branch from cb24fa8 to df1eb17 Compare April 10, 2026 10:21
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.

Submesh subdomain ID union

2 participants