Need help converting GMSH to FEniCS

What version of ubuntu?

ubuntu 20.04.2
dolfin 2019.2.0
gmsh 4.4.1

actually code is running correctly up to L=fvds(4), but when I used Function(V) then error came. please help me sir

Sir Any Solution for bellow error

*** This is disallowed by the MPI standard.
*** Your MPI job will now abort.
[gangadhar-Inspiron-3593:08320] Local abort after MPI_FINALIZE started completed successfully, but am not able to aggregate error messages, and not able to guarantee that all other processes were killed!

Have you tried uninstalling and then reinstalling fenics?
As I cannot reproduce your problem, it is quite tricky for me to be of any further assistance.

Also, do you experience the same issues running any of the standard tutorials of dolfin?

No sir, I did not tried uninstalling and then reinstalling the fenics.

I solved simple problems, in those problems I produced mesh by mshr. But when I used gmsh file in fenics and xdmf files i am getting this errors.
Any other way for importing mesh from gmsh with physical tag

Then this seems to be an issue with your HDF5 installation (as this is what dolfin) uses. How did you install meshio and h5py?

thank you for your replay sir,

pip3 install meshio
pip3 install h5py

Thank you sir,
I uninstalled h5py and then reinstalled . Now its working fine sir.
thank you for help sir and am learning so many things fro this group .

Hi @dokken,

I am having a similarly hard time to @avishmj when trying to convert a 2D MSH file to and XDMF file. I’m using a Linux Debian system. I basically have a channel with a hexagon placed in the middle for a fluid to flow around. However, when I run the code in your ‘Mesh generation and conversion with GMSH and PYGMSH’ example code I get the following error:

Traceback (most recent call last):
File “/home/homeblue01/1/sdrb41/level_4/convert_msh.py”, line 16, in
triangle_mesh = create_mesh(mesh_from_file, “triangle”, prune_z=True)
File “/home/homeblue01/1/sdrb41/level_4/convert_msh.py”, line 7, in create_mesh
cell_data = mesh.get_cell_data(“gmsh:physical”, cell_type)
File “/home/homeblue01/1/sdrb41/.local/lib/python3.9/site-packages/meshio/_mesh.py”, line 239, in get_cell_data
return np.concatenate(
File “<array_function internals>”, line 5, in concatenate
ValueError: need at least one array to concatenate

I’m new to both GMSH and FEniCS, so this has led to some confusion. I’m not sure whether it’s because I drew my GMSH geometry using elementary entities instead of physical groups. Any clarification on the matter would be greatly appreciated. Of course I can attach my .msh file if needed.
Thanks,
Ben

You need to attach the geo file used to create the msh file for me to be of any assistance. In general, you need to tag the elementary entities with Physical tags for them to be read in correctly.
I have for instance showed this here;

Hi @dokken
Thanks for getting back to me so quickly. Here is the .geo file I produced with the GMSH.
Thanks,
Ben

Blockquote
// Gmsh project created on Thu Nov 18 16:23:27 2021
SetFactory(“OpenCASCADE”);
Rectangle(1) = {0, 0, 0, 18, 6, 0};
Point(5) = {3, 2.8, 0, 0.05};
Point(6) = {3, 3.2, 0, 0.05};
Point(7) = {3.3464, 3.4, 0, 0.05};
Point(8) = {3.3464, 2.6, 0, 0.05};
Point(9) = {3.6928, 2.8, 0, 0.05};
Point(10) = {3.6928, 3.2, 0, 0.05};
Point(11) = {3.6928, 3.2, 0, 0.05};
Line(5) = {6, 7};
Line(6) = {10, 9};
Line(7) = {9, 8};
Line(8) = {8, 5};
Line(9) = {5, 6};
Line(10) = {7, 7};
Line(10) = {7, 10};
Curve Loop(2) = {4, 1, 2, 3};
Curve Loop(3) = {5, 10, 6, 7, 8, 9};
Plane Surface(2) = {2, 3};
Physical Curve(“inlet”, 11) = {4};
Physical Curve(“outlet”, 12) = {2};
Physical Curve(“top”, 13) = {3};
Physical Curve(“bottom”, 14) = {1};
Physical Curve(“hex”, 15) = {5, 6, 7, 8, 9, 10};
Physical Point(“points”, 16) = {4, 1, 3, 2, 5, 6, 7, 10, 9, 8};
Physical Curve(“curves”, 17) = {4, 3, 1, 2, 9, 5, 8, 10, 6, 7};

Please note that you have some errors in your geo-file, i.e.

Correcting these, and adding

Physical Surface("surf", 1) = {2};

at the end, the following file (mesh.geo)

// Gmsh project created on Thu Nov 18 16:23:27 2021
SetFactory("OpenCASCADE");
Rectangle(1) = {0, 0, 0, 18, 6, 0};
Point(5) = {3, 2.8, 0, 0.05};
Point(6) = {3, 3.2, 0, 0.05};
Point(7) = {3.3464, 3.4, 0, 0.05};
Point(8) = {3.3464, 2.6, 0, 0.05};
Point(9) = {3.6928, 2.8, 0, 0.05};
Point(10) = {3.6928, 3.2, 0, 0.05};
Point(11) = {3.6928, 3.2, 0, 0.05};
Line(5) = {6, 7};
Line(6) = {10, 9};
Line(7) = {9, 8};
Line(8) = {8, 5};
Line(9) = {5, 6};
Line(10) = {7, 10};
Curve Loop(2) = {4, 1, 2, 3};
Curve Loop(3) = {5, 10, 6, 7, 8, 9};
Plane Surface(2) = {2, 3};
Physical Curve("inlet", 11) = {4};
Physical Curve("outlet", 12) = {2};
Physical Curve("top", 13) = {3};
Physical Curve("bottom", 14) = {1};
Physical Curve("hex", 15) = {5, 6, 7, 8, 9, 10};
Physical Point("points", 16) = {4, 1, 3, 2, 5, 6, 7, 10, 9, 8};
Physical Curve("curves", 17) = {4, 3, 1, 2, 9, 5, 8, 10, 6, 7};
Physical Surface("surf", 1) = {2};

can be read and converted with:

import meshio
import numpy
def create_mesh(mesh, cell_type, prune_z=False):
    cells = mesh.get_cells_type(cell_type)
    cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
    out_mesh = meshio.Mesh(points=mesh.points, cells={cell_type: cells}, cell_data={"name_to_read":[cell_data]})
    if prune_z:
        out_mesh.prune_z_0()
    return out_mesh


mesh = meshio.read("mesh.msh")

mesh_out = create_mesh(mesh, "triangle", prune_z=True)
meshio.write("mesh.xdmf", mesh_out)

Hello,

by transforming the meshfile

$MeshFormat
4.1 0 8
$EndMeshFormat
$Entities
5 5 1 0
1 0.0121 0 0 0 
2 0.01265 0.0005999999999999999 0 0 
3 0.0121 0.0023 0 0 
4 0.0121 0.0043 0 0 
5 0.009999999999999998 0.0043 0 0 
1 0.0121 0 0 0.01265 0.0005999999999999999 0 0 2 1 -2 
2 0.0121 0.0005999999999999999 0 0.01265 0.0023 0 0 2 2 -3 
3 0.0121 0.0023 0 0.0121 0.0043 0 0 2 3 -4 
4 0.009999999999999998 0.0043 0 0.0121 0.0043 0 0 2 4 -5 
5 0.009999999999999998 0 0 0.0121 0.0043 0 0 2 5 -1 
1 0.009999999999999998 0 0 0.01265 0.0043 0 0 5 1 2 3 4 5 
$EndEntities
$Nodes
11 5 1 5
0 1 0 1
1
0.0121 0 0
0 2 0 1
2
0.01265 0.0005999999999999999 0
0 3 0 1
3
0.0121 0.0023 0
0 4 0 1
4
0.0121 0.0043 0
0 5 0 1
5
0.009999999999999998 0.0043 0
1 1 0 0
1 2 0 0
1 3 0 0
1 4 0 0
1 5 0 0
2 1 0 0
$EndNodes
$Elements
11 13 1 13
0 1 15 1
1 1 
0 2 15 1
2 2 
0 3 15 1
3 3 
0 4 15 1
4 4 
0 5 15 1
5 5 
1 1 1 1
6 1 2 
1 2 1 1
7 2 3 
1 3 1 1
8 3 4 
1 4 1 1
9 4 5 
1 5 1 1
10 5 1 
2 1 2 3
11 4 5 3 
12 3 1 2 
13 1 3 5 
$EndElements

with

import meshio as ms
import numpy

msh= ms.read('mesh/mymesh.msh')
prune_z = True
cell_type = "triangle"
cells = msh.get_cells_type(cell_type)
#cell_data = msh.get_cell_data("gmsh:physical", cell_type)
points = msh.points[:,:2] if prune_z else mesh.points
triangle_msh = ms.Mesh(points=points, cells={cell_type: cells})

ms.write("mesh.xdmf", triangle_msh)

I get the error:

<generator object raw_from_cell_data.<locals>.<genexpr> at 0x7f9689d047b0>
Traceback (most recent call last):
  File "mesh/transformmesh.py", line 12, in <module>
    ms.write("mesh.xdmf", triangle_msh)
  File "/home/florian/anaconda3/envs/myenv/lib/python3.8/site-packages/meshio/_helpers.py", line 144, in write
    return writer(filename, mesh, **kwargs)
  File "/home/florian/anaconda3/envs/myenv/lib/python3.8/site-packages/meshio/xdmf/main.py", line 518, in write
    XdmfWriter(*args, **kwargs)
  File "/home/florian/anaconda3/envs/myenv/lib/python3.8/site-packages/meshio/xdmf/main.py", line 346, in __init__
    self.cell_data(mesh.cell_data, grid)
  File "/home/florian/anaconda3/envs/myenv/lib/python3.8/site-packages/meshio/xdmf/main.py", line 488, in cell_data
    for name, data in raw.items():
AttributeError: 'NoneType' object has no attribute 'items'

My fenics version is 2019.1.0 and meshio is version 4.0.4.

I have tried this with different ways to transform the mesh. But the error reappears. Can anyone help me?

Kind regards
Florian

I cannot reproduce this locally on my system. Could you report the output of print(triangle_msh).

Hello Dokken,

thank you for helping. The result is:

<meshio mesh object>
  Number of points: 5
  Number of cells:
    triangle: 3

This seems like a meshio issue, and I would recommend creating an issue at Issues ¡ nschloe/meshio ¡ GitHub
As I cannot see anything wrong with the triangle mesh

1 Like

solved by installing meschio 5.0.0…could have had this idea al little earlier :roll_eyes:

but I will report the bug of 4.0.4. on github.

Hello Dokken, I am trying to execute your code, but I get the following errors.

Blockquote
Traceback (most recent call last):
File “/home/gerard/Documentos/Python/Fenics Elemento Finito/pruebas2.py”, line 12, in
triangle_mesh = create_mesh(msh, “triangle”, True)
File “/home/gerard/Documentos/Python/Fenics Elemento Finito/pruebas2.py”, line 7, in create_mesh
out_mesh.prune_z_0()
AttributeError: ‘Mesh’ object has no attribute ‘prune_z_0’

This is the mesh

Blockquote
tm = 15.00000;
Point(1) = { 0.000000, 0.000000, 0, tm };
Point(2) = { 500.000000, 0.000000, 0, tm };
Point(3) = { 500.000000, 250.000000, 0, tm };
Point(4) = { 0.000000, 250.000000, 0, tm };
Point(5) = { 200.000000, 50.000000, 0, tm };
Point(6) = { 300.000000, 50.000000, 0, tm };
Point(7) = { 300.000000, 150.000000, 0, tm };
Point(8) = { 200.000000, 150.000000, 0, tm };
Line(1) = { 1, 2};
Line(2) = { 2, 3};
Line(3) = { 3, 4};
Line(4) = { 4, 1};
Line(5) = { 5, 6};
Line(6) = { 6, 7};
Line(7) = { 7, 8};
Line(8) = { 8, 5};
Line Loop(9) = { 1, 2, 3, 4 };
Line Loop(10) = { 5, 6, 7, 8 };
Plane Surface(11) = { 9, 10 };
Plane Surface(12) = { 10 };
//+
Physical Curve(13) = {4};
//+
Physical Curve(14) = {1, 3};
//+
Physical Curve(15) = {2};
//+
Physical Surface(16) = {11};
//+
Physical Surface(17) = {12};

Prune_z_0 was deprecated from meshio a while back. Consider: Gmsh import error - #5 by dokken
or
Mesh generation and conversion with GMSH and PYGMSH | Jørgen S. Dokken

Sorry, I was write in Spanish.

Thank you very much,

One last question, how can I define a discontinuous function whose function value depends on the physical region of the mesh?