Hexahedral mesh elements for an L Bracket?

Is it possible to create a hexahedral mesh in FEniCS for an L Bracket geometry?

I can do the following to obtain a mesh with tet elements using mshr:

b1 = Box(Point(0, 0, 0), Point(3, 3, 1))
b2 = Box(Point(1, 1, 0), Point(3, 3, 1))
geometry = b1-b2
mesh = generate_mesh(geometry, 70)

But i am unsure how to use this method for hex elements.

Thanks

Hi,
Mshr does not support hexahedral cells as far as I know. You can use Gmsh or pygmsh to generate a hexhedral mesh and load it using XDMFFile , see Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio for many examples on how to do that

Hey dokken,

Thanks for the reply.

I have created my mesh using pygmsh with hex elements and it exits without error. I have also visually checked the mesh in paraview and happy with the result.

I export the mesh as follows:

meshio.write("hex.xdmf", meshio.Mesh(points=mesh.points, cells={"hexahedron": mesh.cells["hexahedron"]}))

However, this is the following error i get when i try to read it in:

*** Error: Unable to order hexahedron cell.
*** Reason: Cell is not orderable.
*** Where: This error was encountered inside HexahedronCell.cpp.
*** Process: 0

when i used this command:

mesh = Mesh()
with XDMFFile("hex.xdmf") as infile:
    infile.read(mesh)

Do you know why this might be?

Thanks

The support for hexahedron cells in dolfin is quite limited, and require specific ordering of the cells in the mesh to be able to load it. This has been removed in dolfinx and there you can read in hexahedron meshes that are not ordered (for most Finite elements, see The issue tracker for info on current limitations.)

Hey dokken,

Again, thank you for the reply.

Do you know when this will be pushed to a stable version of dolfin? I have always struggled to install FEniCS from source on my mac.

Or how I can request this? Or if there is anyway I can manipulate the mesh such that it works?

Thanks

Hi Dave,

There’s some information on ordering quad/hex meshes in the papers: https://doi.org/10.1137/15M1021325 and https://doi.org/10.1145/3061708. This is much more involved than ordering a triangle/tetrahedron mesh, and isn’t implemented in (old) dolfin, but you could do this to your meshes to make them work.

In dolfinx, we’ve been working on permuting the DoF numbering on each element to avoid the need for ordered meshes. It currently works for continuous polynomial spaces, and other spaces are in development, as the issue tracker link in dokken’s reply says. You can run dolfinx using docker, which is much easier than installing from source; I’d recommend trying this before implementing hex reordering.

Running the following commands will launch a docker container from the current master branch of dolfinx:

docker pull quay.io/fenicsproject/dolfinx:real
docker run -ti --rm quay.io/fenicsproject/dolfinx:real
1 Like

I try to import a hex mesh into fenics using the method as suggested in:
https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412/3?u=reinhardt

This did not work yet.

*** Error:   Unable to order quadrilateral cell.
*** Reason:  Cell is not orderable.
*** Where:   This error was encountered inside QuadrilateralCell.cpp.
*** Process: 0
*** 
*** DOLFIN version: 2019.1.0
*** Git changeset:  74d7efe1e84d65e9433fd96c50f1d278fa3e3f3f

But if I pull the dolfinx docker and say “import dolfinx”, I still get the error message

ModuleNotFoundError: No module named 'dolfinx'

What would currently be the best way to work with a hex mesh?

Which dolfinx docker image are you pulling? Sounds like you might be putting the testing environment, instead of the image with everything installed

I pulled
dolfinx/dolfinx:latest

Could you post the full set of commands you are using, i.e.:

  1. How did you activate the docker container
  2. What is the output of python3 -c "import dolfinx; print(dolfinx.__version__)"?

I use docker for windows and configured the interpreter in pycharm the same way as before in the fenics tutorials. This config worked fine.
Doing the same in dolfinx does not work.

  1. In the docker for windows application I simply run the image.
  2. The defined interpreter shows the versions. Is it this what you asked for? grafik
    My problem is, that the code already fails at “import dolfinx”

By the way, how doe fenicsx and dolfinx relate to eachother?

As I do not use windows (or pycharm), Im not sure how to proceed to help you.

fenicsx is just the collective term for all the packages (ufl, ffcx, basix, dolfinx) in the software.
In the old version of dolfin/fenics, it was an alias for importing from dolfin, i.e.
from dolfin import * produced the same as from fenics import *.
In FEniCSx, we have kept the packages separately, so if you need anything from ufl you do
from ufl import ..., as shown in The FEniCSx tutorial — FEniCSx tutorial

So the pycharm interpreter are at least listing the python packages (and it is therefore strange that it cannot import from the dolfinx one).

Could you specify how you have configured the pycharm interpreter?

After pulling the image I configured the interpreter
grafik
And then configured the environment as follows

But at least

docker pull dolfinx/dolfinx:latest 

should pull the correct (not development) environment, right?

Yes, that is correct.

Could you try to set the Python interpreter path to /usr/bin/python3, and then the enviroment should show Python Interpreter: Remote Python 3.9.5 Docker (dolfinx/dolfinx:latest) docker://dolfinx/dolfinx:latest/usr/bin/python3

Unfortunately, this did not change the behaviour. Interestingly, there is no error if I e.g. “import ffcx” or numpy but dolfinx causes problems.

Could you run

import os
os.system("echo $PYTHONPATH")

as a Python script and post the result?

/opt/project:/opt/.pycharm_helpers/pycharm_matplotlib_backend:/opt/.pycharm_helpers/pycharm_display:/opt/.pycharm_helpers/third_party/thriftpy:/opt/.pycharm_helpers/pydev:C:/Users/reseidel/AppData/Local/JetBrains/PyCharm2021.1/cythonExtensions:/opt/project

Running the docker image through a terminal gives me the following python paths:

docker run -ti -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $(pwd):/root/shared -w /root/shared --rm dolfinx/dolfinx
root@32a104823c5e:~/shared# python3 -c "import os; os.system('echo $PYTHONPATH')"
/usr/local/dolfinx-real/lib/python3.8/dist-packages:/usr/local/lib:

Thus, you need to add /usr/local/dolfinx-real/lib/python3.8/dist-packages to the Pycharm python path (maybe in Pycharm helpers path)

1 Like

Strange, inside my interpreter path this is actually already added.
Is this the path inside the docker?

If I pull the docker like suggested here:

the "echo $PYTHONPATH" gives me

/usr/local/dolfinx-real/lib/python3.8/dist-packages :/opt/project:/opt/.pycharm_helpers/pycharm_matplotlib_backend:/opt/.pycharm_helpers/pycharm_display:/opt/.pycharm_helpers/third_party/thriftpy:/opt/.pycharm_helpers/pydev:C:/Users/reseidel/AppData/Local/JetBrains/PyCharm2021.1/cythonExtensions:/opt/project

but still does not find dolfinx

Yes, this path is inside the docker environment. If you spawn the dolfinx/dolfinx docker image in a terminal, you can observe that:
root@9cee74de15fc:~# ls /usr/local/dolfinx-real/lib/python3.8/dist-packages
produces:

dolfinx  dolfinx_utils  fenics_dolfinx-0.1.1.dev0.dist-info

which is where the python3 dolfinx installation is located. i.e. running:

root@9cee74de15fc:~# python3 -c "import dolfinx; print(dolfinx)"
<module 'dolfinx' from '/usr/local/dolfinx-real/lib/python3.8/dist-packages/dolfinx/__init__.py'>

in the dolfinx/dolfinx image shows you where dolfinx is installed.

1 Like