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

Help for suggestion to convert .msh to .xml

+1 vote

Hi all,

I am trying to read a 2d mesh converted from .msh document. But I do not know why each time I just got a straight line here. The file, "test.geo", I used to generate the mesh is simple and as following,

cl__1 = 0.5;
Point(1) = {0, 0, 0, 0.5};
Point(2) = {0, 4, 0, 0.5};
Point(3) = {3.8, 4, 0, 0.5};
Point(4) = {3.8, 1, 0, 0.5};
Point(5) = {4, 1, 0, 0.5};
Point(6) = {4, 4, 0, 0.5};
Point(7) = {8, 4, 0, 0.5};
Point(8) = {8, 0, 0, 0.5};
Line(1) = {2, 1};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 5};
Line(5) = {5, 6};
Line(6) = {6, 7};
Line(7) = {7, 8};
Line(8) = {8, 1};
Line Loop(10) = {2, 3, 4, 5, 6, 7, 8, -1};
Plane Surface(10) = {10};
Physical Line(0) = {1, 2, 3, 4, 5, 6, 7, 8};

The command I used to generate the 2D mesh is,

gmsh test.geo -2

And the command I used to get file file.xml is,

dolfin-convert test.msh test.xml

But when I read the mesh in dolfin like,

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

I just got a line there.
Could I ask about what is wrong for my mesh? Thanks a lot!

asked Jan 9, 2015 by Hrunx FEniCS Novice (910 points)

I am guessing the problem is due to the last line in file "test.geo",

Physical Line(0) = {1, 2, 3, 4, 5, 6, 7, 8};

Since when I removed it, I can get a correct mesh in dolfin. But how can I define boundary in gmsh? I defined some boundary conditions in my program such like,

mesh = RectangleMesh(0,0,4,4,10,10)
class wall(SubDomain):
        def inside(self,x,on_boundary):
                 ....
gamma_wall = wall()
gamma_wall.mark(boundary_parts,0)

How can I define the variable on_boundary in my test.geo?

Thanks again!

on_boundary is something which is not set explicitly in the mesh. It is just true whenever a facet has only one neighboring element.

1 Answer

+2 votes
 
Best answer

Hi, adding line

Physical Surface(0) = {10};

to the end of your geo file should fix the problem.

answered Jan 9, 2015 by MiroK FEniCS Expert (80,920 points)
selected Jan 9, 2015 by Hrunx
...