Issue: A 3D mesh is being imported as 2D mesh

Hi Guys,

I am trying to import a 3D surface mesh of a ship using

mesh = Mesh('barge.xml')

but it is imported as a 2D file.

I also tried in the .xdmf format

mesh = Mesh()
with XDMFFile("barge_fenics.xdmf") as infile:
    infile.read(mesh)

But it also results in the same issue

I created this .xml and .xdmf files from a .stl file using freecad.

Can anyone tell me how to resolve this issue?

Thank you

Here is a part of the barge.xdmf file

<?xml version="1.0"?>
<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>
<Xdmf version="3.0"><Domain><Grid GridType="Uniform" Name="base_mesh"><Topology NodesPerElement="6" NumberOfElements="6107" TopologyType="TRIANGLE_6"><DataItem Dimensions="6107 6" Format="XML" NumberType="UInt">0 1 2 3172 3173 3174
0 2 3 3174 3175 3176
4 5 6 3177 3178 3179
4 6 7 3179 3180 3181
: : :  :    :     :
-191.391265 -35.300344</DataItem></Geometry></Grid></Domain></Xdmf>

You Need to prune the z-coordinate. See for instance Converting simple 2D mesh from gmsh to dolfin

I did run the code

meshio-convert barge.xml barge.xdmf -p -z

It outputted two files .xdmf and .h5

When I ran the above code

it still returning a 2D mesh. But what I need is a 3D surface mesh.

Then just do not run prune?

Even without pruning, the mesh is still 2D flattened mesh.

In xdmf or when using it in dolfin?

In the dolfin, it is reading to as 2D mesh but in .xdmf is 3D mesh.

it is reading it as a 2D mesh with or without pruning.

But the original mesh is a 3D surface mesh and I want it to read as a 3D mesh.

Could you print mesh.topology().dim() and mesh.geometry().dim()?
I do not have any issue loading a 3D mesh in 2D (also using a second order geometry).

<Xdmf Version="3.0"><Domain><Grid Name="Grid"><Information Name="Information" Value="0">
<![CDATA[<main />]]>
</Information><Geometry GeometryType="XYZ"><DataItem DataType="Float" Dimensions="23 3" Format="XML" Precision="8">
-7.000000000000000e-01 2.000000000000000e-01 0.000000000000000e+00
3.000000000000000e-01 2.000000000000000e-01 0.000000000000000e+00
3.000000000000000e-01 7.000000000000000e-01 0.000000000000000e+00
-7.000000000000000e-01 7.000000000000000e-01 0.000000000000000e+00
-2.000000000000000e-01 2.000000000000000e-01 0.000000000000000e+00
-4.500000000000000e-01 2.000000000000000e-01 0.000000000000000e+00
5.000000000000004e-02 2.000000000000000e-01 0.000000000000000e+00
3.000000000000000e-01 4.500000000000000e-01 0.000000000000000e+00
-2.000000000000000e-01 7.000000000000000e-01 0.000000000000000e+00
5.000000000000007e-02 7.000000000000000e-01 0.000000000000000e+00
-4.500000000000000e-01 7.000000000000000e-01 0.000000000000000e+00
-7.000000000000000e-01 4.500000000000000e-01 0.000000000000000e+00
-4.500000000000000e-01 4.500000000000000e-01 0.000000000000000e+00
5.000000000000004e-02 4.500000000000000e-01 0.000000000000000e+00
-3.250000000000000e-01 3.250000000000000e-01 0.000000000000000e+00
-5.750000000000000e-01 3.250000000000000e-01 0.000000000000000e+00
1.750000000000000e-01 5.750000000000000e-01 0.000000000000000e+00
1.750000000000000e-01 3.250000000000000e-01 0.000000000000000e+00
-7.499999999999996e-02 3.250000000000000e-01 0.000000000000000e+00
-7.499999999999996e-02 5.750000000000000e-01 0.000000000000000e+00
-5.750000000000000e-01 5.750000000000000e-01 0.000000000000000e+00
-3.250000000000000e-01 5.750000000000000e-01 0.000000000000000e+00
-2.000000000000000e-01 4.500000000000000e-01 0.000000000000000e+00
</DataItem></Geometry><Topology NodesPerElement="6" NumberOfElements="8" TopologyType="Triangle_6"><DataItem DataType="Int" Dimensions="8 6" Format="XML" Precision="8">
4 12 0 14 15 5
2 13 1 16 17 7
1 13 4 17 18 6
8 13 2 19 16 9
3 12 8 20 21 10
8 12 4 21 14 22
0 12 3 15 20 11
4 13 8 18 19 22
</DataItem></Topology></Grid></Domain></Xdmf>

Running:

from dolfin import *

mesh = Mesh()
with XDMFFile("mesh.xdmf") as infile:
    infile.read(mesh)
print(mesh.geometry().dim(), mesh.topology().dim())

yields the print 3, 2

mesh = Mesh()
with XDMFFile("barge.xdmf") as infile:
    infile.read(mesh)

mesh2 = Mesh('barge.xml')
print(mesh.geometry().dim(), mesh.topology().dim())
print(mesh2.geometry().dim(), mesh2.topology().dim())

Output

2 2
2 2

Then you are not writing your XML/XDMF-files correctly. For instance, what is in the corresponding: </Information><Geometry GeometryType="XYZ"><DataItem DataType="Float" Dimensions="23 3" Format="XML" Precision="8">

Also, what happens if you read in the file I sent you?

For your file I am getting 3, 2 output.

And what is the GeometryType=“XYZ” (as shown above in my case) in your case?

In my file, the information is
<Xdmf version="3.0"><Domain><Grid GridType="Uniform" Name="base_mesh"><Topology NodesPerElement="6" NumberOfElements="6107" TopologyType="TRIANGLE_6"><DataItem Dimensions="6107 6" Format="XML" NumberType="UInt">0 1 2 3172 3173 3174

@ckesanapalli

It has to have a geometry type as well, like:
</Information><Geometry GeometryType="XYZ"><DataItem DataType="Float" Dimensions="23 3" Format="XML" Precision="8">
This contains all the nodes of the mesh

when I added geometry <Geometry GeometryType="XYZ"> to the xdmf file, I am getting error saying

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***     fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to determine geometric dimension.
*** Reason:  GeometryType "" in XDMF file is unknown or unsupported.
*** Where:   This error was encountered inside XDMFFile.cpp.
*** Process: 0
*** 
*** DOLFIN version: 2019.1.0
*** Git changeset:  77c758717da1cb8017bf95109363bb1a91a4f8e5
*** -------------------------------------------------------------------------

I think I resolved the issue.

In .xml format, the dimension is saved as 2. I changed it to 3 and now it is importing as 3D mesh.

Maybe I should be careful and inspect the mesh files after converting them from one to another.

Thanks a lot for the help.

That is likely the issue. Above I gave you a reference mesh that contains the two parts of information that is required to read in a second order 2D geometry embedded in a 3D space. When converting from xmlto xdmf your xdmffile has to include a geometry (the nodes of the mesh), and a topology (the connectivity of the nodes where each row is a cell).