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

How to define a boundary condition for a mesh is generated by gmsh

+5 votes

Hi,

I want to create a complex 3d mesh in the gmsh, than define Physical Surface, convert the mesh to the Fenics (using a commang "python dolfin-convert [name].msh [name].xml"), then import the mesh in the dolfin and define boundary conditions.

The problem due to the "dolfin-convert" command doesn't convert suites mesh (XML format) for the dolfin, like in demo_bcs.py example (mesh file aneurysm.xml.gz).

demo_bcs.py example link:
http://fenicsproject.org/documentation/dolfin/1.3.0/python/demo/documented/bcs/python/documentation.html

Also the gmsh mark each boundary with a tag (integer digit). How to use these tags to define boundary conditions in the dolfin.

So the question is how to set up a boundary condition in the dolfin, which were defined in the gmsh?

Or how to property convert suites (for the dolfin) mesh is generated by gmsh?

Thanks in advance!

Regards, Maksim

asked Mar 18, 2014 by Maks FEniCS User (2,430 points)

1 Answer

+5 votes
 
Best answer

I think this appeared as an old Launchpad question (#224015) referring both to BCs and to subdomains from GMSH, but to avoid posting a link and so it ends up under Q&A too, I'll quote Michael Waste from there (with thanks):

In the "geo file" you have to rename manually the subdomains with 0 and 1. Also the volumes need integer numbers beginning from 0.

then you can reference to the corresponding boundaries and subdomains in the python file.

mesh = Mesh("yourmeshfile.xml")
subdomains = MeshFunction("size_t", mesh, "yourmeshfile_physical_region.xml")
boundaries = MeshFunction("size_t", mesh, "yourmeshfile_facet_region.xml")
bcs = [DirichletBC(V, 5.0, boundaries, 1),# of course with your boundary
    DirichletBC(V, 0.0, boundaries, 0)]

That approach has worked for me.

answered Mar 18, 2014 by Phil Weir FEniCS Novice (540 points)
selected Mar 18, 2014 by Maks

Are you definitely using the "Physical Volume" constructs to create sudomains in the original .geo file? You can also check the .msh by opening it in GMSH and viewing the list of regions under Tools->Visibility. Select 'Physical Groups' from the drop down at the bottom left of the pop-up, and if there is more than one volume shown then you should get a "yourmeshfile_physical_region.xml" produced on conversion with dolfin-convert. IIRC, when only one region exists (i.e. the mesh contains no subdomains), no additional region XML is produced.

I have 6 physical surfaces and 1 physical volume. I did what you said and I saw only 1 volume. Is that the reason I didn't get a physical.xml? Will my 6 physical surfaces not classify as subdomains or will they be only called boundaries?

So, I have a question about usage of the term 'subdomain'.

  1. Are subdomains representation of only 3D volume partitions or can they be used to represent a 2D surface/ boundary too?

  2. For eg. in the following link:

http://fenicsproject.org/documentation/dolfin/dev/python/demo/pde/hyperelasticity/python/documentation.html

Here, they don't use gmsh. They create a 3D cube mesh in Fenics and classify its boundary at opposite ends (x=0 & x=1) as left and right 'subdomains' through the following statement.

left, right = compile_subdomains(["(std::abs(x[0]) < DOLFIN_EPS) && on_boundary",
                              "(std::abs(x[0] - 1.0) < DOLFIN_EPS) && on_boundary"])

So, when I import my cube from gmsh to fenics, should I just import main .xml and facet file and use the gmsh tags to represent the left and right surfaces (as in the above eg.)?

I have 6 physical surfaces and 1 physical volume. I did what you said and I saw only 1 volume. Is that the reason I didn't get a physical.xml?

I think so - it's been a while since I looked through dolfin-convert code, but that is the behaviour I would expect (but any devs may want to correct me!).

Wrt your questions:

  1. Perhaps "subdomain" is confusing, as, in 3D, it can be either a (volumetric) subdomain of the whole simulation domain, or a boundary subdomain, i.e. a (piecewise-2D) subdomain of the boundary. In 3D, GMSH has the terms Physical Surface and Physical Volume which distinguish between labels for facet subdomains and volumetric subdomains, respectively.
  2. Yes, that sounds right - here they mean boundary subdomain, so you should only need the mesh and the *_facet_region.xml file to produce the same result with a MeshFunction.

The compile_subdomains function produces an instance of the SubDomain class, which is a general construct used to represent criteria for taking a subset of cells. See, for example, the Marking subdomains of a mesh demo where a pure-Python instance is used for marking boundaries.

Thanks Phil Weir for your time and help!

Hey, I just produced a normal cube in gmsh without a hole and converted it and it gave me a physical.xml this time, unlike last time when i created the cube with the hole. This cube also has only 1 volume.

So, something must be wrong in the way i defined physical surface and volume in the cube with the hole. Atleast we can conclude that, the absence of physical file after conversion has nothing to do with defining of only 1 volume.

...