How to manually generate a rectangular mesh with subdomains

Hello, I would like to manually generate a rectangular mesh with two subdomains, one square on the left and another on the right, like the domain in this link

But the following link only show a manual one-domain rectangular mesh, is there an easy way to modify it to include multiple subdomains? I can’t figure it out…

Hi. In the source code folder python/ there are some examples of structured meshes. These should be easy to modify to contain multiple subdomains.
Best Christopher

I noticed that file.
But the only 2D mesh therein is MakeStructured2DMesh, which is a one-domain mesh. I simply don’t know how to add another domain…
I tried to use

which apparently didn’t workout.

The facedescriptor describe boundary conditions, to add another domain you just have to add elements with index 2:

Element2D(2, points)

You can name the domains with:

mesh.SetMaterial(index, name)

Indices are 1-based here.


That’s exactly what I did. I am definitely missing something here.
Attached code is my implementation of a square pml domain, with four domains, inner should be in the inner rectangle, pmlx should be the left and right middle rectangles, pmly should be the top and bottom rectangles, and pmlxy should be the four corners.
But the mesh didn’t have material set properly…
V1.FreeDofs() should give me 1, and V2.FreeDofs() should give me 2…


For a 2d mesh, you need to set the boundary condition of the face descriptors accordingly:

ngmesh.Add (FaceDescriptor(bc=3))

Ah-ha, that’s the cause…I was very puzzled by this FaceDescriptor…
So, domin, domout, and surfnr flags are never used in 2D mesh, right?

domin and domout are used if you have a 2D surface mesh in 3D. In your case they are not used.