Repository navigation
Refactor mesh closures - #5719
connorjward wants to merge 28 commits into
Conversation
4d3a9b0 to
357ff88
Compare
The separation of closures and permutations is approximately working.
Approach appears to work for simplices, quads, extruded intervals, and extruded prisms. Only missing pieces are extruded quads and hexes. Substantial cleanup and performance fixes required.
…ions Ultimately it isn't a big deal. It just affects a specific subset of meshes that we cannot orient. Most tests should now work I think, but substantial cleanup is necessary.
efd0bf3 to
0782b7b
Compare
|
|
||
| map_data_renum = np.empty_like(map_data) | ||
| for i, (from_pt, to_pts) in enumerate(zip(from_dm_indices, map_data, strict=True)): | ||
| from_pt = from_dm_indices[i] |
| from_dim = self.cell_label | ||
|
|
||
| map_components = defaultdict(list) | ||
| for to_dim, size in self._closure_sizes[from_dim].items(): |
There was a problem hiding this comment.
| for to_dim, size in self._closure_sizes[from_dim].items(): | |
| for to_dim in self._closure_sizes[from_dim]: |
|
|
||
| CHKERR(PetscMalloc1(nverts_per_cell, &verts)) | ||
| CHKERR(PetscMalloc1(nedges_per_cell, &edges)) | ||
| CHKERR(PetscMalloc1(nfacets_per_cell, &facets)) |
There was a problem hiding this comment.
dead code
| PetscInt tdim, cell, v_start, v_end | ||
| PetscInt nverts_per_cell, nedges_per_cell, nfacets_per_cell | ||
| PetscInt *verts=NULL | ||
| PetscInt *facets=NULL |
There was a problem hiding this comment.
Dead code
| # orientable submeshes. The practical implications of this are merely | ||
| # that one cannot have an oriented mesh that was first submeshed and | ||
| # then extruded. | ||
| assert not self._is_submesh_inheriting_parent_orientation, \ |
There was a problem hiding this comment.
Should this be a NotImplementedError?
There was a problem hiding this comment.
Meh. It's private code that a user will never touch.
There was a problem hiding this comment.
Then catch the error earlier if you want to disallow extruded Submesh
| orient them. | ||
|
|
||
| """ | ||
| cdef: |
There was a problem hiding this comment.
We need to declare here vi, vj, ei, ej, fi, vert, edge and facet, and all the *_offset_* values. Without this, the cell loop runs at Python speed.
| closures = np.empty((ncells, nclosure), dtype=IntType) | ||
| closure_perms = np.empty_like(closures) |
| cell_closure = np.empty((ncells, 9), dtype=IntType) | ||
| closure_perms = np.empty_like(cell_closure) |
| assert fi == 4 | ||
|
|
||
| # The first vertex is given by the entry in cell_orientations. | ||
| cell = mesh._dm_to_entity_numbering_sec("cell").getOffset(c) |
There was a problem hiding this comment.
Get the Section outside the loop and call PetscSectionGetOffset.
| # return readonly(map_data_renum) | ||
| return map_data_renum # FIXME |
| @@ -1572,7 +1831,8 @@ | |||
| else: | |||
| to_pt_renum = to_numbering_sec.getOffset(to_pt) | |||
There was a problem hiding this comment.
This is inside a double Python loop and is really slow. The loops can go away if you vectorize it with dmcommon.section_offsets.
Renumber the rows through the source section and the values through the target section, and keep -1 entries as they are.
| dtype=IntType, | ||
| ) | ||
|
|
||
| # Am I unit periodic in any direction? (only implemented for quads) |
There was a problem hiding this comment.
There's a segfault for ExtrudedMesh(PeriodicRectangleMesh(4, 1, quadrilateral=True), 3).
-
Cause: in
flat_cell_closures_extruded,get_transitive_closureoverwritesnclosurewith the DMPlex closure size. For these meshes that size is 19, not 27. The loopfor i in range(nclosure)at dmcommon.pyx:796 then fills only 19 of the 27 columns, and the other 8 stay as np.empty garbage. -
Fix: loop over
range(closure_perm.shape[0]). With that one-line change all three cases build correctly: x-periodic, y-periodic and doubly periodic. -
The new
test_one_element_advection[x/y]probably passes on CI only by luck, because np.empty happens to return clean memory there.
| nclosure = closure_perm.size | ||
| closures = np.empty((ncells, nclosure), dtype=IntType) | ||
| for cell in range(ncells): | ||
| get_transitive_closure(dm.dm, cell, PETSC_TRUE, &nclosure, &closure) |
| closures[cell, i] = closure_tmp[closure_perm[i]] | ||
|
|
||
| else: | ||
| for i in range(nclosure): |
There was a problem hiding this comment.
| for i in range(nclosure): | |
| for i in range(closure_perm.size): |
Co-authored-by: Pablo Brubeck <brubeck@protonmail.com> Co-authored-by: Connor Ward <c.ward20@imperial.ac.uk>
Co-authored-by: Connor Ward <c.ward20@imperial.ac.uk>
These changes unify the approaches used to determine cell closures for regular and extruded meshes. The previous approach was not very nicely designed. This is going to be useful for #5685.
The fundamental idea is to split the closure generation into two stages:
For non-extruded meshes the permutations can be collected at the same time as the closures themselves (e.g.
dmcommon.cell_closures_and_perms_simplex). However, for extruded meshes this is not the case because the closures come from the extruded DM, but the permutations come from extruding the base permutation.In addition to just being a lot more readable and unified, the approach here substantially decouples the connection between the extruded mesh and its base mesh, which will facilitate more general extruded meshes (e.g. submeshing, distribution in the extruded direction) where the base mesh needn't exist.