# Hexahedral mesh elements for an L Bracket?

**URL:** <https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410>\
**Category:** mesh\
**Created:** [February 11, 2020, 1:40pm UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410 "2020-02-11T13:40:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dave](https://fenicsproject.discourse.group/u/Dave)\
**Post date:** [February 11, 2020, 1:40pm UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/1 "2020-02-11T13:40:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [February 11, 2020, 2:34pm UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/2 "2020-02-11T14:34:01Z")

</div>

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](https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412) for many examples on how to do that

---

<div class="post-metadata">

**Author:** ![Dave](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dave](https://fenicsproject.discourse.group/u/Dave)\
**Post date:** [February 11, 2020, 6:54pm UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/3 "2020-02-11T18:54:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [February 11, 2020, 7:00pm UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/4 "2020-02-11T19:00:13Z")

</div>

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](https://github.com/FEniCS/dolfinx) and there you can read in hexahedron meshes that are not ordered (for most Finite elements, see [The issue tracker](https://github.com/FEniCS/dolfinx/issues/742) for info on current limitations.)

---

<div class="post-metadata">

**Author:** ![Dave](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dave](https://fenicsproject.discourse.group/u/Dave)\
**Post date:** [February 12, 2020, 10:29am UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/5 "2020-02-12T10:29:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mscroggs](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/mscroggs/32/757_2.png) [@mscroggs](https://fenicsproject.discourse.group/u/mscroggs)\
**Post date:** [February 12, 2020, 10:44am UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/6 "2020-02-12T10:44:30Z")

</div>

Hi Dave,

There’s some information on ordering quad/hex meshes in the papers: [https://doi.org/10.1137/15M1021325](https://doi.org/10.1137/15M1021325) and [https://doi.org/10.1145/3061708](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
```

---

<div class="post-metadata">

**Author:** ![Reinhardt](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@Reinhardt](https://fenicsproject.discourse.group/u/Reinhardt)\
**Post date:** [August 25, 2021, 9:55am UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/7 "2021-08-25T09:55:11Z")

</div>

> [@mscroggs](#):
>
> `quay.io/fenicsproject/dolfinx:real`

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](https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412/3)

This did not work yet.

```auto
*** 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

```auto
ModuleNotFoundError: No module named 'dolfinx'

```

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

---

<div class="post-metadata">

**Author:** ![mscroggs](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/mscroggs/32/757_2.png) [@mscroggs](https://fenicsproject.discourse.group/u/mscroggs)\
**Post date:** [August 25, 2021, 10:12am UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/8 "2021-08-25T10:12:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Reinhardt](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@Reinhardt](https://fenicsproject.discourse.group/u/Reinhardt)\
**Post date:** [August 25, 2021, 10:14am UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/9 "2021-08-25T10:14:36Z")

</div>

I pulled  
dolfinx/dolfinx:latest

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [August 25, 2021, 10:16am UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/10 "2021-08-25T10:16:09Z")

</div>

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__ )"`?

---

<div class="post-metadata">

**Author:** ![Reinhardt](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@Reinhardt](https://fenicsproject.discourse.group/u/Reinhardt)\
**Post date:** [August 25, 2021, 2:55pm UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/11 "2021-08-25T14:55:41Z")

</div>

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](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/a/aa9974032be027e4e5fdad4a0b0a73521ba020c9.png)  
My problem is, that the code already fails at “import dolfinx”

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

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [August 25, 2021, 3:01pm UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/12 "2021-08-25T15:01:05Z")

</div>

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](https://jorgensd.github.io/dolfinx-tutorial/)

> [@Reinhardt](#):
>
> The defined interpreter shows the versions. Is it this what you asked for?

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?

---

<div class="post-metadata">

**Author:** ![Reinhardt](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@Reinhardt](https://fenicsproject.discourse.group/u/Reinhardt)\
**Post date:** [August 25, 2021, 3:33pm UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/13 "2021-08-25T15:33:03Z")

</div>

After pulling the image I configured the interpreter  
 ![grafik](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/3/316f1805f47fdfebed3fc9b12e0a89856b9d898c.png)  
And then configured the environment as follows

 ![grafik](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/a/a36fcf38294d499f24e07637ff78bde6133df403.png)

But at least

```auto
docker pull dolfinx/dolfinx:latest 

```

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

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [August 25, 2021, 3:53pm UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/14 "2021-08-25T15:53:21Z")

</div>

> [@Reinhardt](#):
>
> ```auto
> 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`

---

<div class="post-metadata">

**Author:** ![Reinhardt](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@Reinhardt](https://fenicsproject.discourse.group/u/Reinhardt)\
**Post date:** [August 26, 2021, 8:35am UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/15 "2021-08-26T08:35:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [August 26, 2021, 9:13am UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/16 "2021-08-26T09:13:49Z")

</div>

Could you run

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

```

as a Python script and post the result?

---

<div class="post-metadata">

**Author:** ![Reinhardt](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@Reinhardt](https://fenicsproject.discourse.group/u/Reinhardt)\
**Post date:** [August 26, 2021, 9:16am UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/17 "2021-08-26T09:16:07Z")

</div>

> [@dokken](#):
>
> ```auto
> import os
> os.system("echo $PYTHONPATH")
> 
> ```

```auto
/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

```

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [August 26, 2021, 10:37am UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/18 "2021-08-26T10:37:35Z")

</div>

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

```python
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`)

---

<div class="post-metadata">

**Author:** ![Reinhardt](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@Reinhardt](https://fenicsproject.discourse.group/u/Reinhardt)\
**Post date:** [August 30, 2021, 9:19am UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/19 "2021-08-30T09:19:01Z")

</div>

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

> [@dokken](#):
>
> `/usr/local/dolfinx-real/lib/python3.8/dist-packages:/usr/local/lib:`

 ![grafik](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/2/2f6a197ee4a9c9d461258e4f1f543594ef3a8e68.png)

If I pull the docker like suggested here:

> [@FeniCs on Apple silicon M1](https://fenicsproject.discourse.group/t/fenics-on-apple-silicon-m1/5471/23):
>
> You cant update pythonpath inside a running notebook, as this has to be done prior to running the container. An example of how to do this is shown below (spawning the complex build of PETSc/dolfin with gmsh) docker run -v $(pwd):/root/shared -w "/root/shared" --rm --env LD\_LIBRARY\_PATH=/usr/local/dolfinx-complex/lib --env PATH=/usr/local/dolfinx-complex/bin:/usr/local/gmsh-4.6.0-Linux64-sdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --env PKG\_CONFIG\_PATH=/usr/local/dolfinx…

the` "echo $PYTHONPATH"` gives me

```auto
/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

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [August 31, 2021, 2:37pm UTC](https://fenicsproject.discourse.group/t/hexahedral-mesh-elements-for-an-l-bracket/2410/20 "2021-08-31T14:37:34Z")

</div>

> [@Reinhardt](#):
>
> Is this the path inside the docker?

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:

```bash
dolfinx dolfinx_utils fenics_dolfinx-0.1.1.dev0.dist-info

```

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

```bash
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.
