DOF ordering paramater for UFL element (vs basix)

Hello!

I am trying to change the default ordering of degrees of freedom in each individual element to align with an external numbering scheme that I imposed (in a custom assembly function).

I found the function basix.create_element which fits my needs (from basix — Basix 0.7.0 documentation)

However, I did not find a matching function to impose the ordering for the UFL finite element type, which I then use to create a function space on a mesh with dolfinx.fem.functionspace.

Is there some neat way to impose a custom ordering, because I could not find a dedicated function? Or should I just change the underlying element after the function space has been created?

Thank you!

Hello,

If you create your element using the function basix.ufl.custom_element it will be a Basix custom element directly wrapped as a UFL element which you can then pass into dolfinx.fem.functionspace.

Let me know if you have any issues using this,
Matthew

Dear Matthew,

Thank you for your very prompt reply (and please excuse my very late one…).

I am not quite certain how to use basix.ufl.custom_element to reorder the degrees of freedom. Here is an example of what I have tried to do:

element = basix.create_element(
      basix.ElementFamily.P,
      basix.CellType.quadrilateral,
      2,
      basix.LagrangeVariant.equispaced,
      basix.DPCVariant.unset,
      False,
      [0, 2, 6, 8, 1, 3, 5, 7, 4]
  )

  ufl_element = basix.ufl.custom_element(
      element.cell_type,
      element.value_shape,
      element.wcoeffs,
      element.x,
      element.M,
      element.interpolation_nderivs,
      element.map_type,
      element.sobolev_space,
      element.discontinuous,
      element.highest_complete_degree,
      element.highest_degree,
      element.polyset_type,
      2
  )

When stepping thorugh with my debugger, I still find that the UFL element has an incorrect DOF ordering. I realized that just switching the underlying basix element (inside of the UFL element) is not enough, I have to change some other stuff too.

Thank you very much and sorry if I missed something!

Hello,

Sorry I linked to the wrong function. I meant to send you basix.ufl.element

Hello,

No problem, thank you!
However, I do not understand how to use this function to permute the local DOFs.

If it is not too much to ask, could you please give me an example of how to create a UFL element with permuted local DOFs, because I really cannot grasp how to do it on my own. In the code above, I managed to do it on the Basix side, but I do not know how to transfer it to UFL.

Thank you in advance!

Hello, I took another look, and the reordering input isn’t wrapped in the basix.ufl.element function, so I’ve opened an issue for adding that: Add dof ordering input to basix.ufl.element · Issue #846 · FEniCS/basix · GitHub.

In the meantime, you can wrap the element directly using basix.ufl._BasixElement, like this:

import basix.ufl

ufl_element = basix.ufl._BasixElement(element)
2 Likes

Thank you very much, that indeed solves the problem!

The solution however raised a new question for me - how can I create a vector element this way? This functionality already exists in basix.ufl.element, so adding the ordering input will fix this in the future, but I am not sure how to do it in the context of version 0.7.0 that I am using right now.

Thank you in advance for any suggestions in this regard :slight_smile:

Call basix.ufl.blocked_element(ufl_element, shape=(M,)) where M is the size of the vector space: basix/python/basix/ufl.py at de0bd730b39c20e434a9ac61a8c19cca2c6032d8 · FEniCS/basix · GitHub

1 Like

Thank you very much, that indeed constructs the correct element :slight_smile:

I encountered one final hurdle. I want to space which adheres to custom ordering so I pass the blocked element to the function dolfinx.fem.functionspace (version 0.7.3) and it seems to “forget” the custom ordering. By this I mean that the underlying element.basix_element has an empty dof_ordering field. The ordering is the same as if I had built the space with a “regular” element. Is this expected behaviour? If yes, can it be circumvented?

Thank you in advance!

P.S. Sorry if this thread turned out to be very long, I just wanted to clear a bunch of permutation steps that are in various places throughout the code I am working on… I am still quite new to FEniCS, so any help means a lot.

This is likely a bug, as elements with a DOF ordering haven’t been tested very thoroughly yet. I’ve linked to this thread from the issue about this (Support different dof orderings on a cell · Issue #557 · FEniCS/ffcx · GitHub) to remind me to post here once I’ve had time to work on fixing these

Dear Matthew,

Thank you very much for looking into it and in general I would like to thank you (and Dokken) for all the help :slight_smile:

I will mark the message above as a solution for now since one can follow the link to ascertain whether it has been resolved.

Thanks again and good luck!