AMM
September 16, 2019, 11:44am
1
Hi,
I have some problem with the definition of normal when the mesh is imported from gmsh.
Indeed, taking a 2d mesh of gmsh (on my .msh file I have a component in z but which is worth 0 everywhere) and defining a normal like n = FacetNormal (mesh), I get len(n) = 3.
So I have the n_z component in addition.
For some other software, I have directly a normal of length 2.
Is it normal ? If not, what is the way to automatically obtain a normal of length 2 (without having to extract the first two components of the 3-dimensional one) ?
Thank you
1 Like
dokken
September 17, 2019, 8:11am
2
Hi,
meshio has an option for removing the z-coordinate, see:
Ok, meshio-convert was hiding in ~/.local/bin. In fact, I realized that meshio-convert offers flags for removing lower order cells and the third dimension. So, converting a 2D mesh is as simple as
~/.local/bin/meshio-convert mesh.msh mesh.xdmf -p -z
AMM
September 17, 2019, 8:15am
3
Hi dokken,
Thank you very much for your answer.
AMM
October 11, 2019, 8:53am
4
Hi,
Unfortunately, I have the same problem again.
Indeed, using the command meshio-convert TestPruning.msh TestPruning2.xdmf -p -z
on a terminal give me
Number of points: 1088
Number of elements:
line: 128
triangle: 2048
Cell data: gmsh:geometrical, gmsh:physical
Pruned cell types: line
This prunes all my lines !
In consequence, it is impossible to write the mf.xdmf file (since there is no line). The error (expected) from FEniCS is :
cells={"line": msh.cells["line"]},
KeyError: 'line'
.
I tried the command meshio-convert TestPruning.msh TestPruning2.xdmf -z
but here the FEniCS error message is :
File "/home/amoreno3/anaconda3/envs/fenicsproject/lib/python3.6/site-packages/meshio-2.1.0-py3.6.egg/meshio/xdmf_io.py", line 139, in _translate_mixed_cells
r += xdmf_idx_to_num_nodes[data[r]] + 1
KeyError: 2
Do you have this problem too ?
My .geo file is just a square with a hole (with some physical lines and surface).
Thank you in advance for your answer
hello,
I tried to convert my 2D mesh from .msh file to .xdmf file with the command you posted.
meshio-convert trial.msh mesh.xdmf -p -z
but then i encounted with this error.
File "/home/fenics/.local/bin/meshio-convert", line 8, in <module>
sys.exit(convert())
File "/home/fenics/.local/lib/python3.6/site-packages/meshio/_cli/_convert.py", line 18, in convert
mesh.prune()
AttributeError: 'Mesh' object has no attribute 'prune'
dokken
October 21, 2020, 7:24am
6
Please submit an issue at: https://github.com/nschloe/meshio
Please provide a minimal msh file that reproduces the issue.
the trial.msh file is shown as below:
4.1 0 8
$EndMeshFormat
$PhysicalNames
2
2 1 "coarse_circle"
2 2 "fine_circle"
$EndPhysicalNames
$Entities
6 7 2 0
5 0.5 0.0025 0 0
6 0.5024999999999999 6.123031769111886e-19 0 0
9 6.250039062905e-06 0.002499999999993405 0 0
10 1 1.224606353822377e-16 0 0
12 0.4000312548843391 0.002500000000003074 0 0
13 0.6 2.449212707644755e-17 0 0
3 0.4999999 -9.999999999940612e-08 -1e-07 0.5025000999999999 0.0025001 1e-07 0 2 5 -6
6 6.150039062957635e-06 -9.999999989185326e-08 -1e-07 1.0000001 0.5000000999999999 1e-07 0 2 9 -10
8 0.400031154884339 -9.999999997511999e-08 -1e-07 0.6000000999999999 0.1000001 1e-07 0 2 12 -13
9 0.4000311548843391 0.0024999 -1e-07 0.5000000999999999 0.002500100000003073 1e-07 0 2 5 -12
10 6.150039062902124e-06 0.002499899999993405 -1e-07 0.4000313548843391 0.002500100000003073 1e-07 0 2 12 -9
11 0.5024999 -9.99999999993877e-08 -1e-07 0.6000000999999999 1.000000000244921e-07 1e-07 0 2 6 -13
12 0.5999999 -9.999999997550788e-08 -1e-07 1.0000001 1.000000001224606e-07 1e-07 0 2 13 -10
1 6.150039062902124e-06 -9.999999997511999e-08 -1e-07 1.0000001 0.5000000999999999 1e-07 1 1 4 6 -12 -8 10
2 0.400031154884339 -9.999999999593667e-08 -1e-07 0.6000000999999999 0.1000001 1e-07 1 2 4 8 -11 -3 9
$EndEntities
$Nodes
15 162 1 162
0 5 0 1
1
0.5 0.0025 0
0 6 0 1
2
0.5024999999999999 6.123031769111886e-19 0
0 9 0 1
3
6.250039062905e-06 0.002499999999993405 0
0 10 0 1
4
1 1.224606353822377e-16 0
0 12 0 1
5
0.4000312548843391 0.002500000000003074 0
0 13 0 1
6
0.6 2.449212707644755e-17 0
1 3 0 3
7
8
9
0.5009567085809127 0.002309698831278217 0
0.5017677669529663 0.001767766952966369 0
0.5023096988312782 0.000956708580912726 0
1 6 0 8
10
11
12
13
14
15
16
17
0.03091837552306365 0.1730965903132655 0
0.1182305416250277 0.322880907846965 0
0.2514447679133314 0.4338436315106426 0
0.4145440386246124 0.492643155504477 0
0.5879181089467137 0.4922097176196685 0
0.7507213432843981 0.4325954322709233 0
0.8833790907661478 0.3209680245185209 0
0.9699412438715471 0.1707490184699842 0
1 8 0 8
18
19
20
21
22
23
24
25
0.4068140054719714 0.03628181946681035 0
0.424659956044562 0.06575619953124326 0
0.4514504049548708 0.08742389159122331 0
0.4840047444787144 0.09871247034092898 0
0.5184580679811993 0.09828173648446301 0
0.5507200182151342 0.08618282747889199 0
0.5769604015001218 0.06385214640824564 0
0.5940639148398901 0.03394082976289624 0
1 9 0 8
26
27
28
29
30
31
32
33
0.4888923616538154 0.002500000000000341 0
0.4777847233076309 0.002500000000000683 0
0.4666770849614463 0.002500000000001024 0
0.4555694466152618 0.002500000000001366 0
0.4444618082690772 0.002500000000001707 0
0.4333541699228927 0.002500000000002049 0
0.4222465315767081 0.002500000000002391 0
0.4111388932305236 0.002500000000002732 0
1 10 0 8
34
35
36
37
38
39
40
41
0.3555840321237528 0.002500000000001999 0
0.3111368093631666 0.002500000000000925 0
0.2666895866025802 0.00249999999999985 0
0.222242363841994 0.002499999999998776 0
0.1777951410814078 0.002499999999997702 0
0.1333479183208216 0.002499999999996628 0
0.08890069556023544 0.002499999999995553 0
0.04445347279964917 0.002499999999994479 0
1 11 0 8
42
43
44
45
46
47
48
49
0.5133333333333333 3.265616943526337e-18 0
0.5241666666666666 5.918930710141486e-18 0
0.5349999999999999 8.572244476756633e-18 0
0.5458333333333333 1.122555824337178e-17 0
0.5566666666666666 1.387887200998694e-17 0
0.5674999999999999 1.653218577660209e-17 0
0.5783333333333333 1.918549954321724e-17 0
0.5891666666666666 2.183881330983239e-17 0
1 12 0 8
50
51
52
53
54
55
56
57
0.6444444444444445 3.537751688820203e-17 0
0.688888888888889 4.626290669995652e-17 0
0.7333333333333336 5.7148296511711e-17 0
0.7777777777777779 6.803368632346544e-17 0
0.8222222222222224 7.891907613521991e-17 0
0.8666666666666669 8.980446594697439e-17 0
0.9111111111111112 1.006898557587288e-16 0
0.9555555555555556 1.115752455704833e-16 0
2 1 0 59
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
0.2938288228918129 0.03858191307010833 0
0.4149116682792006 0.09930925297102645 0
0.7111111111111112 0.03849001794597506 0
0.5817426769352743 0.101482536695556 0
0.4979696949692029 0.1354044658239948 0
0.7983351899301665 0.03484137280849922 0
0.2067464216212059 0.05821823832598738 0
0.366686015531232 0.3555672639856331 0
0.6176922405750881 0.3214108381905902 0
0.611026818994824 0.0721088612906932 0
0.6215885908105697 0.1167469753571633 0
0.5825710651648078 0.1472874176688649 0
0.6345649556564447 0.1735191920959626 0
0.6863529578607805 0.1329897050448827 0
0.7022831210806874 0.2046000381602948 0
0.7687567338275495 0.1519443960174498 0
0.4482159566118978 0.1249445311982985 0
0.4048057971731647 0.1440276438869013 0
0.4460902000589832 0.1772165680574679 0
0.3681596107925063 0.1096735108832702 0
0.3507040675574624 0.1666682797241802 0
0.5033076542342106 0.1987050514621014 0
0.8985379787677767 0.04780643168816706 0
0.1148282421705762 0.04882941966591919 0
0.3060572112165252 0.1249789760123237 0
0.2809879582195044 0.2001225552923028 0
0.2248888251979486 0.1322308738423242 0
0.5761362040674195 0.215443932800632 0
0.5251653327869946 0.2773877185781055 0
0.6299308417777356 0.03634223165088835 0
0.6665845256227767 0.07401988261002064 0
0.3875837632355745 0.0690876635023988 0
0.3375897572639753 0.06880771194897983 0
0.4917970882738458 0.3665923454680946 0
0.2600496996331848 0.3048105757941541 0
0.2016896204171312 0.228194125082492 0
0.2512393563120342 0.03759905960600965 0
0.1525377986101778 0.09417858978319418 0
0.5435006028325025 0.1209897781193703 0
0.3701605389538454 0.03514241903273027 0
0.7404415840759291 0.2957972804678071 0
0.7575944491894258 0.04284011034705928 0
0.7325556941232161 0.08729010496113689 0
0.3455221689573627 0.2460357273211093 0
0.4390718210101441 0.2594333491587369 0
0.2684083684808122 0.08136911712732209 0
0.06395133814024523 0.04841983355695825 0
0.09730536637081066 0.1090900291912101 0
0.1563264147315852 0.04112141664888583 0
0.8406841123173883 0.04663892989025292 0
0.8547064964672906 0.1195679390262034 0
0.8309823065445134 0.208443758156932 0
0.6694936946838745 0.03125857425904263 0
0.3336599921193106 0.02950640881036429 0
0.3972388109514234 0.1986763136296791 0
0.6443607912177721 0.2414880125993257 0
0.1310788378933422 0.1787247636774593 0
0.7921054459758393 0.08052047550843361 0
0.5375099155324194 0.1617757164291237 0
2 2 0 46
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
0.494714052702652 0.0105782740102309 0
0.4722309041345389 0.01211949698384685 0
0.5190761418318731 0.009505692794217608 0
0.5400073030520559 0.008067448712788805 0
0.4490899909133211 0.01262146960578057 0
0.5629861111111111 0.01050935044798258 0
0.5009875523857871 0.06986688322732935 0
0.5458476525914867 0.05308176713516284 0
0.4537249562013842 0.05504175172046984 0
0.4287259872786494 0.01351101860335294 0
0.5076371529609287 0.008339313711796768 0
0.512821961806688 0.01988388711382084 0
0.5257685650623645 0.02072297263103517 0
0.5187809070981653 0.03314480997298254 0
0.5016069343868688 0.0301643294101882 0
0.5845662080288705 0.01081247877282943 0
0.5105549246882874 0.04849923729450983 0
0.4913094228024246 0.04682841154739507 0
0.4836195826929265 0.03002978982109868 0
0.484461680933874 0.01165571697382187 0
0.524739932421041 0.06609481666387823 0
0.4756201552690293 0.06626663168779372 0
0.5016004563794431 0.01631052897393325 0
0.5346298700083923 0.03449985151779473 0
0.4609689930335462 0.01253911481372559 0
0.4684104549351073 0.02468982718881289 0
0.471378084438192 0.04321873826956933 0
0.5500883215705744 0.01048171281925605 0
0.5568736734433308 0.02418867047508551 0
0.5729601763882122 0.02205933331037867 0
0.5295833333333333 0.009381941874331404 0
0.5663001549029872 0.04191188949586121 0
0.5732691657723054 0.008676232506238144 0
0.4336562288531487 0.04089381767046434 0
0.4397406556695612 0.02405454440709017 0
0.4156268706889976 0.01352467376445393 0
0.4912237306656218 0.01978857423425886 0
0.5011126895961504 0.006967597080034232 0
0.4555839347282801 0.03645601765184577 0
0.5260177143784328 0.04683700119852365 0
0.4222465315767089 0.02722762879000506 0
0.4389929550728807 0.01156741001415278 0
0.4547588058559632 0.022072194733451 0
0.5393532271230475 0.02125171516526145 0
0.5500253348257719 0.03684044009507829 0
0.4786564725502018 0.02006765454718396 0
$EndNodes
$Elements
2 273 1 273
2 1 2 152
1 98 109 72
2 64 103 94
3 80 108 17
4 74 76 62
5 25 87 6
6 10 105 104
7 58 103 90
8 6 87 50
9 3 104 41
10 60 110 88
11 88 100 60
12 13 65 12
13 15 66 14
14 21 74 62
15 84 103 64
16 76 79 62
17 86 102 91
18 108 115 73
19 66 91 14
20 86 91 66
21 24 67 25
22 76 102 79
23 15 98 66
24 5 97 18
25 65 92 12
26 13 91 65
27 90 103 82
28 67 87 25
29 34 97 5
30 71 100 88
31 91 102 65
32 20 74 21
33 16 109 98
34 90 111 58
35 85 86 66
36 77 90 82
37 64 95 84
38 59 89 77
39 69 116 85
40 92 101 83
41 71 88 68
42 79 102 86
43 89 90 77
44 73 109 108
45 19 89 59
46 85 116 79
47 17 109 16
48 63 115 107
49 89 97 90
50 51 60 52
51 36 58 35
52 12 92 11
53 16 98 15
54 50 110 51
55 66 113 85
56 11 114 10
57 14 91 13
58 73 100 71
59 23 96 61
60 72 113 98
61 62 96 22
62 83 93 92
63 61 96 69
64 23 61 24
65 18 89 19
66 19 59 20
67 79 86 85
68 87 110 50
69 77 82 78
70 21 62 22
71 59 77 75
72 82 103 84
73 65 101 92
74 52 99 53
75 37 94 36
76 76 112 102
77 61 67 24
78 70 71 68
79 79 116 62
80 98 113 66
81 82 84 83
82 22 96 23
83 95 114 84
84 68 88 67
85 72 73 71
86 58 111 35
87 92 93 11
88 102 112 101
89 35 111 34
90 67 88 87
91 18 97 89
92 107 115 108
93 99 115 63
94 53 63 54
95 38 64 37
96 59 74 20
97 100 115 99
98 83 101 78
99 61 69 68
100 93 114 11
101 108 109 17
102 60 99 52
103 36 94 58
104 69 85 70
105 64 106 95
106 75 76 74
107 88 110 87
108 82 83 78
109 70 72 71
110 51 110 60
111 77 78 75
112 54 107 55
113 39 106 38
114 84 93 83
115 61 68 67
116 96 116 69
117 60 100 99
118 101 112 78
119 59 75 74
120 84 114 93
121 69 70 68
122 97 111 90
123 95 106 81
124 40 81 39
125 55 80 56
126 41 104 40
127 62 116 96
128 65 102 101
129 94 103 58
130 34 111 97
131 53 99 63
132 64 94 37
133 73 115 100
134 85 113 70
135 75 112 76
136 81 105 95
137 70 113 72
138 63 107 54
139 78 112 75
140 38 106 64
141 107 108 80
142 55 107 80
143 81 106 39
144 104 105 81
145 40 104 81
146 105 114 95
147 10 114 105
148 10 104 3
149 4 57 17
150 57 80 17
151 56 80 57
152 72 109 73
2 2 2 121
153 8 154 127
154 26 117 1
155 20 138 125
156 20 125 19
157 24 124 23
158 123 138 21
159 135 162 142
160 124 137 23
161 21 138 20
162 22 123 21
163 22 137 123
164 1 154 7
165 23 137 22
166 125 150 19
167 131 153 135
168 24 148 124
169 134 143 138
170 131 135 134
171 120 160 144
172 144 160 145
173 139 153 131
174 133 134 123
175 142 143 135
176 134 138 123
177 118 136 27
178 138 143 125
179 135 143 134
180 27 136 26
181 132 146 25
182 125 155 150
183 128 139 131
184 123 137 133
185 160 161 145
186 42 119 43
187 19 150 18
188 25 148 24
189 28 118 27
190 146 148 25
191 145 148 146
192 128 131 130
193 117 154 1
194 43 147 44
195 29 141 28
196 155 159 151
197 131 134 133
198 44 120 45
199 30 121 29
200 18 157 152
201 42 127 119
202 26 136 117
203 147 160 120
204 117 153 139
205 151 159 121
206 136 153 117
207 119 147 43
208 131 133 130
209 140 161 160
210 127 139 128
211 45 144 46
212 150 155 151
213 139 154 117
214 28 141 118
215 130 140 129
216 142 155 143
217 145 161 148
218 128 129 119
219 31 158 30
220 129 160 147
221 137 156 133
222 128 130 129
223 127 154 139
224 127 128 119
225 46 122 47
226 44 147 120
227 121 158 151
228 141 142 118
229 129 147 119
230 121 141 29
231 124 156 137
232 140 156 124
233 136 162 153
234 47 149 48
235 118 162 136
236 32 126 31
237 33 152 32
238 143 155 125
239 48 132 49
240 150 157 18
241 145 146 122
242 148 161 124
243 142 159 155
244 124 161 140
245 120 144 45
246 140 160 129
247 142 162 118
248 144 145 122
249 30 158 121
250 151 158 126
251 130 156 140
252 126 157 151
253 133 156 130
254 46 144 122
255 146 149 122
256 141 159 142
257 152 157 126
258 153 162 135
259 132 149 146
260 121 159 141
261 126 158 31
262 122 149 47
263 48 149 132
264 32 152 126
265 151 157 150
266 18 152 5
267 42 2 9
268 5 152 33
269 6 132 25
270 49 132 6
271 7 154 8
272 8 127 9
273 9 127 42
$EndElements
When i tried to convert it into xdmf file in docker command as below:
meshio-convert trial.msh mesh.xdmf -p -z
The error comes as:
Traceback (most recent call last):
File "/usr/bin/meshio-convert", line 135, in <module>
_main()
File "/usr/bin/meshio-convert", line 14, in _main
args = _parse_options()
File "/usr/bin/meshio-convert", line 100, in _parse_options
choices=meshio.input_filetypes,
AttributeError: module 'meshio' has no attribute 'input_filetypes'
Thank you.
dokken
October 21, 2020, 7:43am
8
As I said in the previous post, post this as an issue at the meshio page. That is where you should provide the minimal example, error message and which version of meshio you are using.
1 Like
Hi,
I used the gmsh.model.mesh.generate(2) command. Is that not enough for generating a 2D mesh?
Also, regarding the prune option I have two questions:
I need an xdmf file with the lines (facets) of the mesh. However, with this method I only export a mesh.xdmf file, while in the case where I import the whole .msh file into dolfin I can create two files with the triangles and facets separately. How can I do that here?
The prune command eshio-convert mesh.msh mesh_2D.xdmf -p -z
returns this warning: UserWarning: prune() will soon be deprecated. Use remove_lower_dimensional_cells(), remove_orphaned_nodes() instead.
AMM
January 16, 2021, 7:11pm
10
Hello,
For your first question, the thing to do is to look directly at the tables on the resulting msh files: if it’s in 2d, a pruning by meshio is not necessary.
I personally don’t use this command.
you must first create two xdmf files (which will be in 3d), from the msh file, containing the surface and line information.
Then, you will have to do a pruning on each of these xdmf files with the option “-z”.
You will then be able to make FEniCS read them.
I can only recommend you to use the new syntax even if I still use the old one.
Hi @AMM ,
Thank you for your reply.
The top of my mesh file looks like:
`
$MeshFormat
4.1 0 8
$EndMeshFormat
$PhysicalNames
3
1 1 "Inlet"
1 2 "Outlet"
1 3 "Walls"
$EndPhysicalNames
$Entities
4 4 1 0
1 0 0 0 0
2 0 1 0 0
3 100 1 0 0
4 100 0 0 0
1 0 0 0 0 1 0 1 1 2 1 -2
2 0 1 0 100 1 0 1 3 2 2 -3
3 100 0 0 100 1 0 1 2 2 3 -4
4 0 0 0 100 0 0 1 3 2 4 -1
1 0 0 0 100 1 0 1 1 4 1 2 3 4
$EndEntities
$Nodes
9 48231 1 48231
0 1 0 1
`
which then changes to 3 numbers per row, then one and then 4… It is very confusing.
I created these files within fenics. Is there any way to prune within fenics?
Many thanks!
dokken
January 17, 2021, 5:56pm
12
I suggest having a look at my updated pygmsh tutorial, specifically:
Personal web page