Multiple domains with GMSH: Any tutorial available?

Hello,

I have a basic Poisson solver (almost identical to tutorial code) and my goal is to solve for the field with multiple objects in the system.
These objects have different properties that are treated as a constant in the equation (e.g. permittivity for electric field).

For example, I’d like to set up a combination of two co-centric filled sphere which has different properties at the border r=a. (using the example of permittivity, \epsilon(r) = \epsilon_1 for r<a and \epsilon(r) = \epsilon_2 for r\ge a).

This is easy to do with simple if-statement, but when the system is consisted of many 3D objects such as the real experimental setup involving vacuum chamber and multiple objects, I’d rather like to import 3D CAD model to GMSH and generate physical domains for each of those objects including the air and vacuum.

However, I am very new to GMSH, and I keep getting issues over issues (e.g. mesh is not connected between objects). Is there any good tutorial for this? Or could someone provide a minimum working example to assign multiple physical domains for a system with multiple objects (without explicitly setting up boundaries with mathematical expression in the code)?

Thank you so much.

There are a vast amount of pygmsh examples on this forum, for instance Pygmsh Tutorial? (Which uses BooleanFragments to connect multiple domains).

Also have a look at Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio and the other Gmsh files i’ve posted in that thread.

1 Like

@dokken Thank you for the links. Operation of pygmsh is not too straightforward for a beginner and I haven’t quite reached to the point where I can test my code, but I am sure this is the way to achieve my goal.

FWIW you may check Joachim Schoeberl’s NetGen/NGSolve and the examples therein. It can import geometries from several CAD formats and then export to Gmsh/Abaqus format following which you can use meshio to convert these to xdmf to be imported in dolfin. (looks a bit tedious than simple Gmsh/pygmsh–>meshio route but it isn’t)

The I/O has proved to be a little more convenient for some applications than pygmsh, and since there is a python interface everything can be done in a single script.

Just a follow-up:
Apparently the solution is as simple as just to do boolean fragments in gmsh (or pygmsh). This solves the mesh issue at the intersection of two objects. Applying this to all of the objects (after proper boolean addition/subtraction) solved the main issue.
The method to import this mesh into a code can be found here.