Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

How to manually generate a rectangular mesh with subdomains

More
4 years 11 months ago #1589 by Guosheng Fu
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
ngsolve.org/docu/latest/netgen_tutorials...e_2d_geometries.html

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...
ngsolve.org/docu/latest/netgen_tutorials...mesh_generation.html
More
4 years 11 months ago #1590 by christopher
Hi. In the source code folder python/meshes.py there are some examples of structured meshes. These should be easy to modify to contain multiple subdomains.
Best Christopher
More
4 years 11 months ago #1591 by Guosheng Fu
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
mesh.Add(FaceDescriptor(surfnr=1,domin=1,bc=1))
mesh.Add(FaceDescriptor(surfnr=2,domin=1,bc=1))

which apparently didn't workout.
More
4 years 11 months ago #1592 by christopher
The facedescriptor describe boundary conditions, to add another domain you just have to add elements with index 2:
Code:
Element2D(2, points)
You can name the domains with:
Code:
mesh.SetMaterial(index, name)
Indices are 1-based here.

Best
Christopher
More
4 years 11 months ago #1593 by Guosheng Fu
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....
Attachments:
More
4 years 11 months ago #1594 by matthiash
For a 2d mesh, you need to set the boundary condition of the face descriptors accordingly:
Code:
ngmesh.Add (FaceDescriptor(bc=3))
Time to create page: 0.189 seconds