Generate quad mesh or convert abaqus mesh to use in FEniCS

Hi, How can we generate quad meshes with complicated geometry? or is there any workaround to use the Abaqus-mesh (quad) in FEniCS. I have tried using meshio but could not get success.

Thanks

Hi
FEniCS supports quad mesh as you can see in Cahn-Hilliard demo. However if you want to use quad elements for complex geometries it is better to generate the mesh in GMSH and then import it into the FEniCS.

1 Like

Thanks for the reply, Is there anyway we can use abaqus mesh in FEniCS?

You may want to try the dolfin-convert. I have never tried to import an abaqus mesh into the FEniCS. Open the terminal and type:

dolfin-convert abaqus_mesh.inp fenics_mesh.xml

If it does not work, you can try the other mesh converter tool meshio

I get the error: Exception: Element type not supported. meshio I have also tried but does not serves the purpose. Thanks for the help

Again, this is what I have not tried before. I know how to import quad mesh in complex geometries from GMSH (MSH format) to FEniCS (XML format) but I do not have experience with abaqus mesh.

Thanks for the reply. I have generated .geo file and quad mesh in gmsh but while converting (dolfin-convert da.msh da.xml) I dont get all the cells in 2016.1 (I get only 36 vertices and 36 cells) and get error in 2017.2
#----------------------------- .geo file----------------------------
DefineConstant[ lc = { 0.1, Path “Gmsh/Parameters”}];
Point(1) = {0, 0, 0, lc};
Point(2) = {1, 0, 0, lc};
Point(3) = {1, 1, 0, lc};
Point(4) = {0, 1, 0, lc};
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
Line Loop(5) = {3, 4, 1, 2};
Plane Surface(6) = {5};
Transfinite Surface{6} = {3,4,1,2};
Transfinite Line {4, 2} = 10 Using Progression 1;
Transfinite Line {3, 1} = 10 Using Progression 1;
Recombine Surface {6};

There is a workaround. You can follow my short tutorial:
Here is the mesh based on what you have provided as a geo file:

Save it as a MSH format. Then you can open it in excel. You need to modify it 2 times. First for the nodes and secondly for the elements and save them separately as text files. You need to keep only the nodes (or element) numbers and also the coordinates of the nodes in these two files. Please be aware that you need to delete everything else in these files. For example for the nodes you will have this (nodes.txt):

1 0 0
2 1 0
3 1 1
4 0 1
5 0.1111111111 0
6 0.2222222222 0
7 0.3333333333 0
8 0.4444444444 0
9 0.5555555556 0
10 0.6666666667 0
11 0.7777777778 0
12 0.8888888889 0
13 1 0.1111111111
14 1 0.2222222222
15 1 0.3333333333
16 1 0.4444444444
17 1 0.5555555556
18 1 0.6666666667
19 1 0.7777777778
20 1 0.8888888889
21 0.8888888889 1
22 0.7777777778 1
23 0.6666666667 1
24 0.5555555556 1
25 0.4444444444 1
26 0.3333333333 1
27 0.2222222222 1
28 0.1111111111 1
29 0 0.8888888889
30 0 0.7777777778
31 0 0.6666666667
32 0 0.5555555556
33 0 0.4444444444
34 0 0.3333333333
35 0 0.2222222222
36 0 0.1111111111
37 0.8888888889 0.8888888889
38 0.8888888889 0.7777777778
39 0.8888888889 0.6666666667
40 0.8888888889 0.5555555556
41 0.8888888889 0.4444444444
42 0.8888888889 0.3333333333
43 0.8888888889 0.2222222222
44 0.8888888889 0.1111111111
45 0.7777777778 0.8888888889
46 0.7777777778 0.7777777778
47 0.7777777778 0.6666666667
48 0.7777777778 0.5555555556
49 0.7777777778 0.4444444444
50 0.7777777778 0.3333333333
51 0.7777777778 0.2222222222
52 0.7777777778 0.1111111111
53 0.6666666667 0.8888888889
54 0.6666666667 0.7777777778
55 0.6666666667 0.6666666667
56 0.6666666667 0.5555555556
57 0.6666666667 0.4444444444
58 0.6666666667 0.3333333333
59 0.6666666667 0.2222222222
60 0.6666666667 0.1111111111
61 0.5555555556 0.8888888889
62 0.5555555556 0.7777777778
63 0.5555555556 0.6666666667
64 0.5555555556 0.5555555556
65 0.5555555556 0.4444444444
66 0.5555555556 0.3333333333
67 0.5555555556 0.2222222222
68 0.5555555556 0.1111111111
69 0.4444444444 0.8888888889
70 0.4444444444 0.7777777778
71 0.4444444444 0.6666666667
72 0.4444444444 0.5555555556
73 0.4444444444 0.4444444444
74 0.4444444444 0.3333333333
75 0.4444444444 0.2222222222
76 0.4444444444 0.1111111111
77 0.3333333333 0.8888888889
78 0.3333333333 0.7777777778
79 0.3333333333 0.6666666667
80 0.3333333333 0.5555555556
81 0.3333333333 0.4444444444
82 0.3333333333 0.3333333333
83 0.3333333333 0.2222222222
84 0.3333333333 0.1111111111
85 0.2222222222 0.8888888889
86 0.2222222222 0.7777777778
87 0.2222222222 0.6666666667
88 0.2222222222 0.5555555556
89 0.2222222222 0.4444444444
90 0.2222222222 0.3333333333
91 0.2222222222 0.2222222222
92 0.2222222222 0.1111111111
93 0.1111111111 0.8888888889
94 0.1111111111 0.7777777778
95 0.1111111111 0.6666666667
96 0.1111111111 0.5555555556
97 0.1111111111 0.4444444444
98 0.1111111111 0.3333333333
99 0.1111111111 0.2222222222
100 0.1111111111 0.1111111111

For the elements, you should consider only the element start with number.3 in the second column in the msh file. (Number 3 correspond to the quad elements) and delete everything else. Here is the text file for the elements (element.txt):

41 3 21 37 20
42 20 37 38 19
43 19 38 39 18
44 18 39 40 17
45 17 40 41 16
46 16 41 42 15
47 15 42 43 14
48 14 43 44 13
49 13 44 12 2
50 21 22 45 37
51 37 45 46 38
52 38 46 47 39
53 39 47 48 40
54 40 48 49 41
55 41 49 50 42
56 42 50 51 43
57 43 51 52 44
58 44 52 11 12
59 22 23 53 45
60 45 53 54 46
61 46 54 55 47
62 47 55 56 48
63 48 56 57 49
64 49 57 58 50
65 50 58 59 51
66 51 59 60 52
67 52 60 10 11
68 23 24 61 53
69 53 61 62 54
70 54 62 63 55
71 55 63 64 56
72 56 64 65 57
73 57 65 66 58
74 58 66 67 59
75 59 67 68 60
76 60 68 9 10
77 24 25 69 61
78 61 69 70 62
79 62 70 71 63
80 63 71 72 64
81 64 72 73 65
82 65 73 74 66
83 66 74 75 67
84 67 75 76 68
85 68 76 8 9
86 25 26 77 69
87 69 77 78 70
88 70 78 79 71
89 71 79 80 72
90 72 80 81 73
91 73 81 82 74
92 74 82 83 75
93 75 83 84 76
94 76 84 7 8
95 26 27 85 77
96 77 85 86 78
97 78 86 87 79
98 79 87 88 80
99 80 88 89 81
100 81 89 90 82
101 82 90 91 83
102 83 91 92 84
103 84 92 6 7
104 27 28 93 85
105 85 93 94 86
106 86 94 95 87
107 87 95 96 88
108 88 96 97 89
109 89 97 98 90
110 90 98 99 91
111 91 99 100 92
112 92 100 5 6
113 28 4 29 93
114 93 29 30 94
115 94 30 31 95
116 95 31 32 96
117 96 32 33 97
118 97 33 34 98
119 98 34 35 99
120 99 35 36 100
121 100 36 1 5

Then you can run this code to generate a meshfile:

file = open('meshfile.py', 'w')

file.write('from dolfin import *;\n')
file.write('mesh = Mesh();\n')
file.write('editor = MeshEditor();\n')
file.write("editor.open(mesh,'quadrilateral', 2, 2);\n")
file.write('editor.init_vertices(100);\n')   #100 is number of nodes
file.write('editor.init_cells(121);\n')        # 121 is number of elements

file.close()

lines = [line.rstrip('\n') for line in open('nodes.txt')]
output = open('meshfile.py', 'a')

for line in lines:
    line = line.split()
    line[0] = int(line[0]) - 1

    output.write('editor.add_vertex({},{},{});\n'.format(line[0], line[1], line[2]))

output.close()

lines = [line.rstrip('\n') for line in open('element.txt')]
output = open('meshfile.py', 'a')

for line in lines:
    line = line.split()
    line[0] = int(line[0]) - 41  # 41 is the number of the first element in the element.txt file

    for i in range (1,5):

        line[i] =int(line[i]) - 1

    output.write('editor.add_cell({},{},{},{},{});\n'.format(line[0], line[1], line[2], line[4], line[3]))

output.close()

file = open('meshfile.py', 'a')

file.write('editor.close()\n')
file.write("File('mesh.pvd') << mesh\n")
file.close()

So you can open the meshfile and simply run it. It creates a mesh which is readable for FEniCS. If you open the mesh.pvd, here is what you can see:

fenics

Which is the same mesh in GMSH!

1 Like

Thanks for the help, I am able to get that in 2017.2. but when I try running the code in 2019.1, I am getting error in add_vertex:

Traceback (most recent call last):
File “/home/hsk/Desktop/Hd/quad_test.py”, line 16, in
editor.add_vertex(0,0,0);
TypeError: add_vertex(): incompatible function arguments. The following argument types are supported:
1. (self: dolfin.cpp.mesh.MeshEditor, arg0: int, arg1: dolfin::Point) -> None
2. (self: dolfin.cpp.mesh.MeshEditor, arg0: int, arg1: List[float]) -> None

Invoked with: <dolfin.cpp.mesh.MeshEditor object at 0x7f93f1202068>, 0, 0, 0

is there any function change in dolfin 2019.1?

I have not tried it in 2019. I am using 2017.2 and it works fine on this version.

I had the same question some time ago. As far as I could find out at that time Quad meshes (2D) and also hex meshes (3D) were supported only for unit square meshes (2D) and unit cube meshes (3D) respectively but not for rectangular/complex meshes. I was not aware that the missing functionalities had been implemented in the meantime. See the discussion here:

https://groups.google.com/forum/#!topic/fenics-support/pkyLn__93jM

I’m happy to read that its apparently possible by now…

Were you able to work it out successfully in 2019.1.0 ? I made the necessary formatting changes here but I’m getting a weird cell reordering issue after that (which was apparently resolved in late 2018: see this )

Dear @Leo,
I am trying to use the quad mesh which is generated by using gmsh. I read the mentioned tutorial and tried to follow it.
The output of proposed tutorial is meshfile.py, so the question is how could I import this file in FEniCS as mesh file.

Thanks

Hi Karo
I made this long time ago when I was working with 2017.2 version of dolfin. As far as I remember you can import the mesh in your code by:

from dolfin import *
from meshfile import mesh

Hi Leo,
I tried the tutorial but finally it didn’t run properly.
Thank you for your reply and information.

Hi,
To make it possible for other people than Leo to help you, it would be nice if you could add the following:
Which version of dolfin are you using?
What error message do you get?
Are you running the script as exactly given above?

Hi dokken,
I am using 2019.1.0. The proposed tutorial is about generating quad mesh and as I said before, it works properly. But the problem arises when I want to use this file as a quad mesh in my code.
In fact, the basic question is if dolfin fully supports quad mesh in any geometries?

The quad support is dolfin is quite limited. In the development version of dolfin, dolfinx this support has been enhanced, see for instance: https://github.com/FEniCS/dolfinx/blob/master/python/demo/gmsh/demo_gmsh.py

Thanks for your guidance @dokken ,
Now I am trying to install dolfinx but I faced some challenges in it. I have posted my question here: “Problem with installation of dolfin-x”.