This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Importing 2D mesh converted from GMSH

+1 vote

Hi,

I have constructed a simple mesh in GMSH. Below is the .geo file

Point(1) = {0, 0, 0, 0.1};
Point(2) = {1, 0, 0, 0.1};
Line(1) = {1, 2}; 
Extrude {{0, 1, 0}, {0, 0, 0}, Pi/2} {
  Line{1};
} 
Extrude {{0, 1, 0}, {0, 0, 0}, Pi/2} {
  Line{2};
}
Extrude {{0, 1, 0}, {0, 0, 0}, Pi/2} {
  Line{5};
}
Extrude {{0, 1, 0}, {0, 0, 0}, Pi/2} {
  Line{8};
}

I have converted the .msh file into a .xml file using dolfin-convert, but the result is mesh that is nothing but a line. I.e.:

mesh = Mesh("test.xml")
plot(mesh,interactive=True)

Thanks in advance

asked Sep 2, 2014 by sixtysymbols FEniCS User (2,280 points)

Hi, at the moment you rotate around y-axis so that the vertices have coordinates [x, 0, z]. FEniCS thinks that geometry of the mesh is 2 and looks only on the first 2 coordinates. Therefore you get the line plot. So the first step is to rotate around z-axis. This way you'll get a mesh with triangles some of them are strange. Are you sure your code is the way to create triangulation of each quadrant such that the elements are aligned with x and y axes?

Hi, rotating around the z axis worked. Thanks. By strange do you mean an irregular pattern? The mesh imports without error.

Hi. I said strange because for me gmsh -2 mesh.geo produces a mesh that looks like this.

Interesting. This does not happen with me ( http://i.imgur.com/3UVcXqn.png ). Perhaps the script behaves differently for different versions of gmsh. To be on the safe side I will avoid using extrude.

Interesting indeed. What's your gmsh version? For completeness mine is 2.8.3

This seems to be a bug in older versions. See here. After I upgraded to 2.8.5 the mesh looks like yours.

1 Answer

+1 vote
 
Best answer

Mirok's suggestion was correct: rotate about the z axis so that all coordinates are (x,y)

Point(1) = {0, 0, 0, 0.1};
Point(2) = {1, 0, 0, 0.1};
Line(1) = {1, 2};   
Extrude {{0, 0, 1}, {0, 0, 0}, Pi/2} {
  Line{1};
} 
Extrude {{0, 0, 1}, {0, 0, 0}, Pi/2} {
  Line{2};
}
Extrude {{0, 0, 1}, {0, 0, 0}, Pi/2} {
  Line{5};
}
Extrude {{0, 0, 1}, {0, 0, 0}, Pi/2} {
  Line{8};
}
answered Sep 4, 2014 by sixtysymbols FEniCS User (2,280 points)
...