Dolfin ignores 3rd coordinate when reading 2D manifold - 3D meshes

Hi,
I am working on a 3d surface mesh. so, i meshed the 3D surface in GMSH, and imported to dolfin using the dolfin-convert.

when i print the node coordinates, I see only two coordinates. Why is this happening?

For example, in fenics I see,

Node 0: [-0. -0.]
Node 1: [0.7 0.1]
Node 2: [0. 0.]
Node 3: [0.7 0.1]
Node 4: [0.08230965 0.04710366]
........... and so on...

GMSH file:

$MeshFormat
2.2 0 8
$EndMeshFormat
$PhysicalNames
4
1 5 "fixed"
1 7 "fixed2"
1 8 "load"
2 6 "domain"
$EndPhysicalNames
$Nodes
116
node 1 -0 -0 0
node 2 0.7 0.1 0
node 3 0 0 1
node 4 0.7 0.1 1
node 5 0.08230965019596791 0.04710365937903452 0
..........and so on ..............
i use the following lines to read the mesh,
mesh = Mesh()
h5_file = "../mesh_files/membrane-only.h5"
hdf = HDF5File(mesh.mpi_comm(), h5_file, "r")
hdf.read(mesh, "/mesh", False)

# define mesh parameters
nsd = mesh.geometry().dim()
n = FacetNormal(mesh)
I = Identity(nsd)
h = CellDiameter(mesh)
print(nsd)

# read mesh functions
boundaries = MeshFunction("size_t", mesh, nsd - 1)
ds = ds(metadata={'quadrature_degree': 2}, subdomain_data=boundaries)
hdf.read(boundaries, "/boundaries")

domains = MeshFunction("size_t", mesh, nsd)
dx = dx(metadata={'quadrature_degree': 2}, subdomain_data=domains)
hdf.read(domains, "/domains")

x_i = SpatialCoordinate(mesh)

# Get the coordinates of the nodes
coordinates = mesh.coordinates()

# Print the coordinates
for i, coord in enumerate(coordinates):
    print(f"Node {i}: {coord}")

This is far from a minimum working example. We don’t have any of your files and no one would be able to run your posted example.

dolfin-convert is no longer maintained. I would suggest switching to meshio: GitHub - nschloe/meshio: 🕸 input/output for many mesh formats

you can also use the dolfinx.io.gmshio package to convert a gmsh mesh to xdmf and read with the XDMFFile class. See this thread for example.

1 Like

Without supplying the actual mesh file h5 file, or the geo file + conversion script, there is no way to debug your issue

Sorry.
Here is the gmsh .geo script,

//+
SetFactory("OpenCASCADE");
//+
Point(1) = {-0, -0, 0, 1.0};
//+
Point(2) = {0.5, 0.3, 0, 1.0};
//+
Point(3) = {0.7, 0.1, 0, 1.0};
//+
BSpline(1) = {1, 2, 3};
//+
Extrude {0, 0, 1} {
  Curve{1}; 
}
//+
Physical Curve("fixed", 5) = {2};
//+
Physical Surface("domain", 6) = {1};
//+
Physical Curve("fixed2", 7) = {3};
//+
Physical Curve("load", 8) = {4};

Here is the script i used to convert .msh file to .h5 file, (found it online)
I just command,
python msh2h5.py /path/gmshfilename /path/h5filename

"""
Converter from msh-format to a mesh in h5-format.

Usage:

.. code-block:: bash

    Usage: python3 <path_to_mshToH5.py> <msh_file> <h5_file>
    E.g.:  python3 mshToH5.py lid lid5
"""

import os
import sys
import dolfin as df

def msh_to_h5():
    "Convert given geo-file to a h5-mesh."

    msh_input_file = sys.argv[1]
    h5_output_file = sys.argv[2]

    # Convert msh-mesh to xml-mesh
    os.system("dolfin-convert {0}.msh {0}.xml".format(msh_input_file))

    # Read xml-mesh
    mesh = df.Mesh("{}.xml".format(msh_input_file))
    domains = df.MeshFunction(
        "size_t", mesh, "{}_physical_region.xml".format(msh_input_file))
    df.File("domains.pvd") << domains
    boundaries = df.MeshFunction(
        "size_t", mesh, "{}_facet_region.xml".format(msh_input_file))
    df.File("boundaries.pvd") << boundaries

    # Delete xml-mesh
    os.remove("{}.xml".format(msh_input_file))
    os.remove("{}_physical_region.xml".format(msh_input_file))
    os.remove("{}_facet_region.xml".format(msh_input_file))

    # Write h5-mesh
    file = df.HDF5File(mesh.mpi_comm(), "{}.h5".format(h5_output_file), "w")
    file.write(mesh, "/mesh")
    file.write(domains, "/domains")
    file.write(boundaries, "/boundaries")


if __name__ == '__main__':
    msh_to_h5()

I couldn’t find a way to attach .h5 file.

Thank you very much for quick response.

dolfin-convert is long deprecated. Please use meshio as indicated in