-
-
Notifications
You must be signed in to change notification settings - Fork 174
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>
Example from: http://jsdokken.com/FEniCS23-tutorial/src/mesh_generation.html 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) |
garth-wells
approved these changes
May 16, 2024
jorgensd
approved these changes
May 16, 2024
jorgensd
reviewed
May 16, 2024
garth-wells
approved these changes
May 17, 2024
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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. Inmain
, 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 optionorient
, which only worked for the facets of tets, but let me know if this is problematic. I've added an optionpermute
; this permutes the DOFs so that they agree with the orientation of mesh entities, but it requirescreate_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.