# How to generate four-node quadrilateral mesh and element?

**URL:** <https://fenicsproject.discourse.group/t/how-to-generate-four-node-quadrilateral-mesh-and-element/5412>\
**Category:** Uncategorized\
**Created:** [March 26, 2021, 11:22am UTC](https://fenicsproject.discourse.group/t/how-to-generate-four-node-quadrilateral-mesh-and-element/5412 "2021-03-26T11:22:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yingqi\_Jia](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/yingqi_jia/32/2316_2.png) [@Yingqi\_Jia](https://fenicsproject.discourse.group/u/Yingqi_Jia)\
**Post date:** [March 26, 2021, 11:22am UTC](https://fenicsproject.discourse.group/t/how-to-generate-four-node-quadrilateral-mesh-and-element/5412/1 "2021-03-26T11:22:19Z")

</div>

**Question 1: Q4 mesh**  
Suppose we have two matrices A and B describing Node and Coordinate relationships, and Element and Node relationships, respectively:

A: (Node and Coordinate relationships)  
Node1 x1 y1  
Node2 x2 y2  
Node3 x3 y3  
…

B: (Element and Node relationships)  
Element1 Node1 Node2 Node3 Node4  
Element2 Node1 Node2 Node3 Node4  
Element3 Node1 Node2 Node3 Node4  
…

How could we transfer these two relationships of four-node quadrilateral mesh (not just square or rectangle mesh) into `mesh` entities such as the one obtained from `RectangleMesh` in FEniCS?

**Question 2: Q4 element**  
Once we obtain a `mesh` entity containing the Q4 mesh, do we need to do some other modifications in the code?

---

<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:** [March 26, 2021, 11:49am UTC](https://fenicsproject.discourse.group/t/how-to-generate-four-node-quadrilateral-mesh-and-element/5412/2 "2021-03-26T11:49:03Z")

</div>

For quadrilateral and hexahedral elements, it is recommended to use dolfin-x, as the support for these elements has been vastly improved. See for instance: [dolfinx/test\_higher\_order\_mesh.py at main · FEniCS/dolfinx · GitHub](https://github.com/FEniCS/dolfinx/blob/main/python/test/unit/mesh/test_higher_order_mesh.py#L135)

---

<div class="post-metadata">

**Author:** ![Yingqi\_Jia](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/yingqi_jia/32/2316_2.png) [@Yingqi\_Jia](https://fenicsproject.discourse.group/u/Yingqi_Jia)\
**Post date:** [March 27, 2021, 5:09am UTC](https://fenicsproject.discourse.group/t/how-to-generate-four-node-quadrilateral-mesh-and-element/5412/3 "2021-03-27T05:09:31Z")

</div>

Hi Dokken, thanks for your reply very much, and I just have two follow-up questions:

(1) Does the dolfinx contain all the contents in dolfin? That is, can I use `from dolfinx import *` to replace `from dolfin import *`?

(2) I am a newcomer to docker and I have installed docker in the windows 10 system. I use docker command to download dolfinx (about 3.16 GB). But when I try to use `from dolfinx import *`, a warning appears that ‘no module named dolfinx’. What should I do then?  
I am using VScode and Ubuntu 18.04LTS, and the classical dofinx runs very smoothly.

---

<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:** [March 27, 2021, 10:13am UTC](https://fenicsproject.discourse.group/t/how-to-generate-four-node-quadrilateral-mesh-and-element/5412/4 "2021-03-27T10:13:55Z")

</div>

> [@Yingqi\_Jia](#):
>
> (1) Does the dolfinx contain all the contents in dolfin? That is, can I use `from dolfinx import *` to replace `from dolfin import *` ?

Dolfin-X is quite different from dolfin. They both use UFL, but the syntax has changed quite alot. See for instance: [The FEniCSx tutorial — FEniCSx tutorial](https://jorgensd.github.io/dolfinx-tutorial/) for an overview of the new syntax.

The docker image you should use is the `dolfinx/dolfinx` image on [Dockerhub](https://hub.docker.com/r/dolfinx/dolfinx). You shoul be able to pull the image, create a container and run `python3 -c "import dolfinx"` without any error message.

---

<div class="post-metadata">

**Author:** ![Yingqi\_Jia](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/yingqi_jia/32/2316_2.png) [@Yingqi\_Jia](https://fenicsproject.discourse.group/u/Yingqi_Jia)\
**Post date:** [March 28, 2021, 4:54am UTC](https://fenicsproject.discourse.group/t/how-to-generate-four-node-quadrilateral-mesh-and-element/5412/5 "2021-03-28T04:54:40Z")

</div>

Hi Dokken, I try to pull the image by using Docker, but the warning still exists. Could you please tell me how to deal with it?

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

This is my image list:

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

This is my container:

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/7/75bfd3225f6ec0ada0505b9ae40d8230e7a96588.png)

I think I can only run dolfinx in this way:  
 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/7/78fd3c3d80b98c1e01ed02b793cb4017f49e57e0.png)  
But it will change the file directory. Is there some elegant way to run it?

---

<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:** [March 28, 2021, 9:48am UTC](https://fenicsproject.discourse.group/t/how-to-generate-four-node-quadrilateral-mesh-and-element/5412/6 "2021-03-28T09:48:09Z")

</div>

The dolfinx docker image is like any other docker image. You need to start a container using `docker run` to be able to access a terminal that has dolfinx installed. A docker container always have its own file system, and you can share a folder with the container by running the following:

```auto
docker run -ti -v $(pwd):/root/shared -w /root/shared --rm dolfinx/dolfinx

```

---

<div class="post-metadata">

**Author:** ![Yingqi\_Jia](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/yingqi_jia/32/2316_2.png) [@Yingqi\_Jia](https://fenicsproject.discourse.group/u/Yingqi_Jia)\
**Post date:** [March 28, 2021, 3:14pm UTC](https://fenicsproject.discourse.group/t/how-to-generate-four-node-quadrilateral-mesh-and-element/5412/7 "2021-03-28T15:14:07Z")

</div>

Thank you, Dokken! You help me a lot. Now I can run my code with dolfinx.  
But when I try to reproduce the result in this tutorial: [Implementation — FEniCS-X tutorial (jorgensd.github.io)](https://jorgensd.github.io/dolfinx-tutorial/chapter2/linearelasticity_code.html), there is a warning: No module named ‘pyvista’. For other parts, they work well.

---

<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:** [March 28, 2021, 3:30pm UTC](https://fenicsproject.discourse.group/t/how-to-generate-four-node-quadrilateral-mesh-and-element/5412/8 "2021-03-28T15:30:23Z")

</div>

Pyvista has to be installed, as it is an optional dependency of dolfinx. You should run the following inside your container

```auto
apt-get -qq update && \
    apt-get -y install libgl1-mesa-dev \
    xvfb 
pip3 install pyvista matplotlib

```
