Skip to content

Add real element to DOLFINx#4170

Open
jorgensd wants to merge 12 commits intomainfrom
dokken/real-element
Open

Add real element to DOLFINx#4170
jorgensd wants to merge 12 commits intomainfrom
dokken/real-element

Conversation

@jorgensd
Copy link
Copy Markdown
Member

@jorgensd jorgensd commented Apr 21, 2026

Add the notion of real element to DOLFINx. Implemented based on https://github.com/scientificcomputing/scifem/blob/main/src/scifem.cpp
Relies on FEniCS/basix#1001

One should not be able to make a mixed_element with real element. One should use the block constructor (i.e. MixedFunctionSpace or manually block it).

The real element is now:

  • A DG-0 element in basix, gives the exact same kernel as with a DG-0/Constant.
  • Gives the ownership of the DOF to the first process that has a cell (sometimes rank 0 has no cell).

@jorgensd
Copy link
Copy Markdown
Member Author

Resolves: #225

@jorgensd jorgensd requested a review from michalhabera April 21, 2026 14:35
@jorgensd jorgensd added the enhancement New feature or request label Apr 21, 2026
@michalhabera
Copy link
Copy Markdown
Contributor

One should not be able to make a mixed_element with real element. One should use the block constructor (i.e. MixedFunctionSpace or manually block it).

You mean that you cannot create a Real element with nontrivial shape, but should work in MFS?

@jorgensd
Copy link
Copy Markdown
Member Author

jorgensd commented Apr 22, 2026

One should not be able to make a mixed_element with real element. One should use the block constructor (i.e. MixedFunctionSpace or manually block it).

You mean that you cannot create a Real element with nontrivial shape, but should work in MFS?

No, one should not be able to do:

el = basix.ufl.element("Lagrange", mesh.basix_cell(), 2)
r_el = basix.ufl.real_element(mesh.basix_cell(), shape=(2,))
me = basix.ufl.mixed_element([el, r_el])

but one can do:

el = basix.ufl.element("Lagrange", mesh.basix_cell(), 2)
V = dolfinx.fem.functionspace(mesh, el)
r_el = basix.ufl.real_element(mesh.basix_cell(), shape=(2,))
R = dolfinx.fem.functionspace(mesh, r_el)
W = ufl.MixedFunctionSpace(V, R)
u, lmbd = ufl.TrialFunctions(W)
v, mu = ufl.TestFunctions(W)

Copy link
Copy Markdown
Contributor

@michalhabera michalhabera left a comment

Choose a reason for hiding this comment

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

This change is minimal and nicely isolated. I like you've added custom dofmap builder and did not try to tweak the existing one -- which was the bad design in legacy FEniCS if I remember well.

I still believe we should follow matrix-free/MATSHELL approach for all these extremely skew spaces, but this is a good solution until we have more time to work on the alternative.

@jorgensd
Copy link
Copy Markdown
Member Author

This change is minimal and nicely isolated. I like you've added custom dofmap builder and did not try to tweak the existing one -- which was the bad design in legacy FEniCS if I remember well.

I still believe we should follow matrix-free/MATSHELL approach for all these extremely skew spaces, but this is a good solution until we have more time to work on the alternative.

In combination with:
#3938
we should be able to use matrix free approach with this element with no changes to the core.

Comment thread cpp/dolfinx/fem/dofmapbuilder.cpp Outdated
Comment thread cpp/dolfinx/fem/dofmapbuilder.cpp Outdated
Comment thread cpp/dolfinx/fem/dofmapbuilder.cpp Outdated
Comment thread python/dolfinx/fem/element.py Outdated
Co-authored-by: Matthew Scroggs <matthew.w.scroggs@gmail.com>
Comment thread cpp/dolfinx/fem/dofmapbuilder.cpp Outdated
Comment thread cpp/dolfinx/fem/dofmapbuilder.cpp Outdated
Comment thread cpp/dolfinx/fem/dofmapbuilder.cpp Outdated
topology.comm(), num_dofs, ghosts, owners);

// Create element dof layout
dolfinx::fem::ElementDofLayout dof_layout(value_size, entity_dofs,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can use auto, type explicit in use of make_shared

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But we are not using a make_shared pointer here as it is not used further down the line?

Comment thread cpp/dolfinx/fem/dofmapbuilder.cpp Outdated
Comment thread cpp/dolfinx/fem/dofmapbuilder.cpp Outdated
Co-authored-by: Jack S. Hale <mail@jackhale.co.uk>
Co-authored-by: Jørgen Schartum Dokken <dokken92@gmail.com>
@jorgensd jorgensd requested a review from jhale April 28, 2026 09:04
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.

5 participants