Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Orient mesh entities consistently and generalise entities_to_geometry #3209

Merged
merged 61 commits into from
May 17, 2024

Conversation

jpdean
Copy link
Member

@jpdean jpdean commented May 13, 2024

In main, the orientation of mesh entities is defined by whichever cell appears last in the entity-to-cell connectivity. This assumption is relied on in a few places in the code (see e.g. entities_to_geometry), despite the assumption not being well documented.

This PR ensures that mesh entities are created such that their local (to the process) orientation agrees with their global orientation, which is unique, can be computed locally, and is a more natural definition. It will also greatly simplify mixed-dimensional coupling.

This PR also generalises entities_to_geometry for high-order elements. In main, this function computes the geometric DOFs associates with the vertices of a particular entity, whereas in this PR, it computes the geometric DOFs associated with the closure of the entities. I've removed the option orient, which only worked for the facets of tets, but let me know if this is problematic. I've added an option permute; this permutes the DOFs so that they agree with the orientation of mesh entities, but it requires create_entity_permutations to be called. In many cases, you don't need to do this (e.g. when computing the diameter of an entity). Alternatively, this could be implemented as a separate function.

Thanks @jorgensd for the idea to deal with high-order geometry via closure DOFs and @mscroggs for help with permuting the DOFs.

jpdean and others added 9 commits May 14, 2024 13:35
Co-authored-by: Garth N. Wells <gnw20@cam.ac.uk>
Co-authored-by: Garth N. Wells <gnw20@cam.ac.uk>
Co-authored-by: Garth N. Wells <gnw20@cam.ac.uk>
Co-authored-by: Garth N. Wells <gnw20@cam.ac.uk>
@jpdean jpdean requested a review from garth-wells May 14, 2024 13:03
@jorgensd
Copy link
Sponsor Member

Example from: http://jsdokken.com/FEniCS23-tutorial/src/mesh_generation.html
now slightly modified:

from mpi4py import MPI
import dolfinx.mesh
import dolfinx.plot
import basix.ufl

import ufl
import numpy as np
import pyvista
pyvista.start_xvfb(wait=0.1)



def plot_mesh(mesh, dim):
    mesh.topology.create_connectivity(dim, mesh.topology.dim)
    mesh.topology.create_entity_permutations()
    vtk_mesh = dolfinx.plot.vtk_mesh(mesh, dim=dim)
    V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1))
    linear_grid = dolfinx.plot.vtk_mesh(V)
    lgrid = pyvista.UnstructuredGrid(*linear_grid)

    ugrid = pyvista.UnstructuredGrid(*vtk_mesh)
    tgrid = ugrid.tessellate()
    plotter = pyvista.Plotter()
    plotter.add_mesh(ugrid,style="points", color="b", point_size=10, render_points_as_spheres=True)
    plotter.add_mesh(tgrid, show_edges=False, opacity=0.5)
    plotter.add_mesh(lgrid, style="wireframe", color="b")

    plotter.show()
    plotter.screenshot(f"grid_{dim}.png")

nodes = np.array([[1., 0.], [2., 0.], [3., 2.],
                  [2.9, 1.3], [1.5, 1.5], [1.5, -0.2]], dtype=np.float64)
connectivity = np.array([[0, 1, 2, 3, 4, 5]], dtype=np.int64)
c_el = ufl.Mesh(basix.ufl.element("Lagrange", "triangle", 2, shape=(2, )))
domain = dolfinx.mesh.create_mesh(MPI.COMM_SELF, connectivity, nodes, c_el)
plot_mesh(domain, 1)
plot_mesh(domain, 2)

yields:
Facet plot:
grid_1
Cell plot:
grid_2

cpp/dolfinx/mesh/utils.h Outdated Show resolved Hide resolved
@garth-wells garth-wells added this pull request to the merge queue May 17, 2024
Merged via the queue into main with commit a186d6b May 17, 2024
28 checks passed
@garth-wells garth-wells deleted the jpdean/consistent_facet_orientation branch May 17, 2024 10:56
jorgensd added a commit to jorgensd/dolfinx_mpc that referenced this pull request May 28, 2024
- Also add some additional `create_connectivity(tdim, tdim)` calls prior to midpoint computations (consequence of FEniCS/dolfinx#3209)
- Switch to spdlog and move some logging to debug mode (FEniCS/dolfinx#3216)
- Support nanobind 2.0.0 (FEniCS/dolfinx#3105)
- Replace `dolfinx.Function.vector` with `dolfinx.Function.x.petsc_vec` (FEniCS/dolfinx#3092)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants