Repository navigation
Conversation
…on-names # Conflicts: # demos/netgen/netgen_mesh.py.rst # firedrake/bcs.py # firedrake/mesh.py # firedrake/tsfc_interface.py
FEniCS/ufl#493 has been merged, so CI's UFL main already supports string subdomain ids. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Resolve region names once in compile_form, before the cached _compile_form, instead of in both the hashkey and the body. - Use UFL's integral type tables to find the entity dimension. - Share one entity dimension check between rename_subdomain and parse_subdomain_id, and flatten the parse_subdomain_id helpers. - Read Gmsh physical names on rank 0 only, stop at $Entities/$Nodes when there is no $PhysicalNames block, and gather names on the internal communicator. - Declare region_names on ExtrudedMeshTopology, which does not call AbstractMeshTopology.__init__. - Remove a leftover print(labels) from the Netgen demo. - Move the tests from test_region_names.py (deleted in the previous commit) into the existing test files for each feature. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: OpenAI Codex
Share one helper between the Gmsh and Exodus readers, give every rank the full CGNS name list, store region names in a plain dict, and read Netgen names next to the other readers. Wrap a string subdomain before the names are resolved in DirichletBC and RestrictedFunctionSpace, so that a name given to an already restricted space is also resolved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use the terms of the rest of the codebase: subdomain names and subdomain ids, not region names, tags or markers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ngsPETSc now marks each named Netgen region in a DMPlex label with that name, like the PETSc Gmsh reader does. Read these labels in the same way for Gmsh and Netgen meshes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop this commit once NGSolve/ngsPETSc#134 merges. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Convert point coordinates to a tuple before passing them to DirichletBC, and demonstrate vector-valued Constants in both demos. Assisted-by: OpenAI Codex
Assisted-by: OpenAI Codex
Assisted-by: OpenAI Codex
Assisted-by: OpenAI Codex
Assisted-by: OpenAI Codex
Assisted-by: OpenAI Codex
| @PETSc.Log.EventDecorator() | ||
| def _from_gmsh(filename: str, comm: MPI.Comm, geometric_dim: int | None) -> tuple[PETSc.DMPlex, list[tuple[int, int, str]]]: | ||
| """Read the mesh and physical names from a Gmsh file.""" | ||
| options = {"dm_plex_gmsh_use_regions": True, "dm_plex_gmsh_use_generic": True} |
There was a problem hiding this comment.
@connorjward It turns out that PETSc is able to load the string subdomain ids from gmsh as individual, single-valued DMLabels, so I opened NGSolve/ngsPETSc#134 to deal with string subdomain_id uniformly in netgen.
The approach in this PR is to pop all such single-valued labels and keep the usual multivalued "Facet Sets" label. subdomain_id consumers call mesh.parse_subdomain_ids() to turn user inputs into the standard tuple[int] format
connorjward
left a comment
There was a problem hiding this comment.
Questions about the API. This is nearly very nice.
| ''' | ||
| def __init__(self, V, g, bc_point): | ||
| super().__init__(V, g, bc_point) | ||
| super().__init__(V, g, tuple(bc_point)) |
There was a problem hiding this comment.
It seems like this might break user's code in a very subtle way. The DirichletBC constructor is definitely public API since we have demos encouraging users to subclass it.
There was a problem hiding this comment.
This can go away if as_tuple treated ufl.Expr as a sequence
| raise ValueError(f"Invalid entity dimension {dim} for mesh of dimension {mesh_dim}") | ||
| return dim | ||
|
|
||
| def rename_subdomain(self, dim, subdomain_id, subdomain_name): |
There was a problem hiding this comment.
"rename" indicates that the previous label is now invalid, which I don't think is the case.
There was a problem hiding this comment.
How about tag_subdomain?
There was a problem hiding this comment.
Could do. Pretty sure "label" is the predominant terminology for this sort of thing though.
This seems like it could basically be achieved with RelabeledMesh.
There was a problem hiding this comment.
I'm reading your last message as "don't use re- in the name because it might confuse users and they might associate this with RelabeledMesh, which creates a new Mesh"
| assert e.ierr == 56 | ||
| def exodus_mesh() -> MeshGeometry: | ||
| if "exodusii" not in get_external_packages(): | ||
| pytest.skip("PETSc was built without ExodusII support") |
There was a problem hiding this comment.
Should be @pytest.mark.skipexodusii in conftest.py. Otherwise we won't test this if CI stops install exodusii (which it must do already?)
If we aren't testing exodusii then we really should be.
| mesh.rename_subdomain(1, [1, 2], "vertical") | ||
| V = FunctionSpace(mesh, "CG", 1) | ||
|
|
||
| assert RestrictedFunctionSpace(V, "vertical").boundary_set == frozenset({1, 2}) |
There was a problem hiding this comment.
It seems strange to me that the strings just refer to the integer IDs. I would have expected that Vr.boundary_set == "vertical".
A much nicer API would be the ability to label an arbitrary portion of the domain with a new string label, rather than only be able to rename the union of existing integer labels.
There was a problem hiding this comment.
I think we can take baby steps towards that goal
There was a problem hiding this comment.
This PR is just adding a layer on top of the int labels. If we want to, we can change the internals as a separate refactor
There was a problem hiding this comment.
This PR just seems like, whilst it is moving in the right direction, it is also moving sideways and adding things that will have to be fixed later on. You are adding infrastructure that you later intend to remove.
The string stuff for netgen is really good. I wonder if that could land without touching the existing integer subdomain ID stuff. This is quite a complex PR as it stands.
There was a problem hiding this comment.
The existing subdomain id mechanism isn't really touched. What we have for netgen is exactly the same code path as gmsh.
Could you propose the redesign that you want?
There was a problem hiding this comment.
Maybe my suggestion is that rename_subdomain be made an internal API (as well as being renamed). I don't think it's at all natural for a user, but it does make sense when interfacing with gmsh.
There was a problem hiding this comment.
There was some discussion about this API at a meeting a while ago. The conclusion was that we also wanted to let the user be able to attach their own string IDs to any given mesh.
There was a problem hiding this comment.
The conclusion was that we also wanted to let the user be able to attach their own string IDs to any given mesh.
Absolutely. But us giving them an API where they have to have first labelled the IDs with (possibly multiple) integers, and only then can they assign a string, is bizarre IMO.
There was a problem hiding this comment.
That's not the intention. If they define their own mesh file, they can label it with string IDs. If they are using a utiility mesh, we let them override the integer IDs with their own strings.
|
|
||
| def test_dirichletbc_accepts_subdomain_name(): | ||
| mesh = UnitSquareMesh(2, 2) | ||
| mesh.rename_subdomain(1, [1, 2], "vertical") |
There was a problem hiding this comment.
Should we have something about this in the BC part of the manual?
Document which mesh formats load subdomain names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CI built PETSc without ExodusII, so the fixture in test_exodus_mesh.py skipped every ExodusII test. Download ExodusII and CGNS in the install action and mark the tests with skipexodusii, which never skips on CI. Treat every dependency that conftest.py does not import as an external package of PETSc, so that a new PETSc package needs only a new marker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No test read a Triangle or a CGNS mesh file. Check the volume and the boundary ids of a Triangle mesh of the unit square, and the volume of a unit square that PETSc writes to a CGNS file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… pbrubeck/feature/region-names # Conflicts: # tests/firedrake/regression/test_exodus_mesh.py
1fa82c0 to
acecfef
Compare
Mesh(coordinates, tolerance=...) returned before it read the tolerance, so the new mesh always had the default tolerance of 0.5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each utility mesh passes the keyword arguments that it does not use to Mesh, so that all Mesh options, for example the tolerance, can be set on a utility mesh. The annulus and solid torus meshes now call Mesh instead of make_mesh_from_coordinates, so that they also receive them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the public MeshGeometry.name_subdomain with the keyword
arguments cell_subdomain_names and facet_subdomain_names of Mesh and of
the utility meshes. Each argument maps a name to one subdomain id or a
sequence of them:
mesh = UnitSquareMesh(2, 2, facet_subdomain_names={"vertical": [1, 2]})
bc = DirichletBC(V, 0, "vertical")
Mesh stores these names together with the names that it loads from the
mesh file. If a name occurs in both, it refers to the ids from both.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Users can now refer to a subdomain by its name instead of its integer subdomain id. The names come from the mesh file, or from the
cell_subdomain_namesandfacet_subdomain_namesarguments ofMeshand of every utility mesh.The mesh readers put each name on the DMPlex as a label, and Firedrake stores the names on the mesh topology. Firedrake changes names into subdomain ids where each API reads them:
on_boundary,everywhere,otherwise,topandbottomkeep their meaning.ValueErrorthat lists the available names.compile_formchanges names into subdomain ids before the cache lookup. So the cache key holds the subdomain ids that the names map to when the form is compiled.GetRegionNames.Implementation details
-dm_plex_gmsh_use_regions -dm_plex_gmsh_use_generic. The generic labels (Cell Sets,Face Setsand so on) supply the subdomain ids as before. The name labels are removed before distribution.Cell Setslabel when all cells are in one named region. Without it,dx("fluid_domain")in the code block above resolves todx(1)and integrates over nothing.Limitations
CheckpointFiledoes not keep the names, because they are not on the DMPlex after distribution.Evidence
The tests compare assembled values or subdomain ids with values computed in a different way:
After: each test passes.
test_dirichletbc_facet_subdomain_namestest_restricted_function_space_accepts_subdomain_nametest_submesh_accepts_subdomain_nametest_measure_accepts_subdomain_name_with_domain,..._with_inferred_domaintest_cell_subdomain_names_name_cell_subdomain_ids,test_facet_subdomain_names_name_facet_subdomain_idstest_gmsh_subdomain_names_are_loaded,test_cgns_subdomain_names,test_netgen_subdomain_names_are_loaded,test_exodus_meshtest_netgen_subdomain_names_are_loadedfails with ngsPETScmainand passes with the ngsPETSc branch.Merge Danger
Door: two-way
Integer subdomain ids work as before. Names are new API. They can stay, or they can be removed later.
Blast Radius: mesh-loading
depth,celltype,marker,Cell Sets, ...) is not imported.DROP BEFORE MERGE: Install the ngsPETSc branch with region labelsinstalls the ngsPETSc branch in CI. Drop it after Add a label for each named Netgen region to the DMPlex NGSolve/ngsPETSc#134 merges, and run CI again.🤖 Generated with Claude Code