How do I .mat() with OCC?

I have defined two dmains with the following.

from netgen.occ import *
from netgen.webgui import Draw as DrawGeo

x = [-1.00,-0.8, 1.0,-0.8]
y = [ 0.80,-1.0,-0.8, 1.0]

pnt = []
pnt.append(Pnt(x[0], y[0], 0))
pnt.append(Pnt(x[1], y[1], 0))
pnt.append(Pnt(x[2], y[2], 0))
pnt.append(Pnt(x[3], y[3], 0))
seg = []
seg.append(Segment(pnt[0], pnt[1]))
seg.append(Segment(pnt[1], pnt[2]))
seg.append(Segment(pnt[2], pnt[3]))
seg.append(Segment(pnt[3], pnt[0]))

wire = Wire (seg)
face1 = Face (wire)

face1.bc("mat1")
circle = WorkPlane().Circle(0,0,3).Face()
face2 = circle - face1
face2.bc("mat2")
face = Glue([face1, face2])
face.edges.Max(X).name="max_X"
face.edges.Min(X).name="min_X"
face.edges.Max(Y).name="max_Y"
face.edges.Min(Y).name="min_Y"
#DrawGeo(face)

from ngsolve import Mesh
from ngsolve.webgui import Draw
geo = OCCGeometry(face, dim=2)
mesh = Mesh(geo.GenerateMesh(maxh=0.5)).Curve(5)
Draw (mesh);
print(mesh.GetMaterials())
print(mesh.GetBoundaries())

I have generaetd the mesh, but matrials are named with “bc” names.
I want to specify the name of the materials.
How do I use .mat() methods? In dim=2, BC labels are used for materials?
BC labels are also strange.

(‘mat1’, ‘mat2’)
(‘default’, ‘min_Y’, ‘default’, ‘max_Y’, ‘default’)

I have modified my Python script as follows.

from netgen.occ import *
from netgen.webgui import Draw as DrawGeo

x = [-1.00,-0.8, 1.0,-0.8]
y = [ 0.80,-1.0,-0.8, 1.0]

pnt = []
pnt.append(Pnt(x[0], y[0], 0))
pnt.append(Pnt(x[1], y[1], 0))
pnt.append(Pnt(x[2], y[2], 0))
pnt.append(Pnt(x[3], y[3], 0))
seg = []
seg.append(Segment(pnt[0], pnt[1]))
seg.append(Segment(pnt[1], pnt[2]))
seg.append(Segment(pnt[2], pnt[3]))
seg.append(Segment(pnt[3], pnt[0]))

wire = Wire (seg)
face1 = Face (wire)

face1.bc("mat1")
circle = WorkPlane().Circle(0,0,3).Face()
face2 = circle - face1
face2.bc("mat2")
face = Glue([face1, face2])
face.edges.Nearest((3,0,0)).name="out"
#DrawGeo(face)

from ngsolve import *
from ngsolve import Mesh
from ngsolve.webgui import Draw
geo = OCCGeometry(face, dim=2)
mesh = Mesh(geo.GenerateMesh(maxh=0.5)).Curve(5)
#Draw (mesh);
print(mesh.GetMaterials())
print(mesh.GetBoundaries())

I checkd the BC labels with the following.

fes = H1(mesh, order=1, dirichlet='out')
bdry_values = {'out': 1}
cf = mesh.BoundaryCF(bdry_values, default=0)
gfu = GridFunction(fes)
gfu.Set(cf, definedon=mesh.Boundaries('out'))
Draw(gfu)

out

Hi Kengo,
I’ve simplified your script a bit, I like to work with the WorkPlane object. There you can name boundaries as you draw the lines, alternatively you can also use the Nearest like you did or something like Min Max
The occ shapes do not yet know in which dimension they are, this info is just added when you create the OCCGeometry object. So therefore we just name the faces and they will be materials afterwards in the mesh if dim == 2

from netgen.occ import *
from ngsolve import *
from ngsolve.webgui import Draw

x = [-1.00,-0.8, 1.0,-0.8]
y = [ 0.80,-1.0,-0.8, 1.0]

face1 = MoveTo(x[0], y[0]).LineTo(x[1], y[1], name="test").LineTo(x[2], y[2]).LineTo(x[3], y[3]).Close().Face()
face1.edges.Max(X).name = "out"
face1.faces.name = "mat1"
circle = Circle((0,0),3).Face()
face2 = circle - face1
face2.faces.name = "mat2"
face = Glue([face1, face2])

from ngsolve import *
from ngsolve import Mesh
from ngsolve.webgui import Draw
geo = OCCGeometry(face, dim=2)
mesh = Mesh(geo.GenerateMesh(maxh=0.5)).Curve(5)
#Draw (mesh);
print(mesh.GetMaterials())
print(mesh.GetBoundaries())

Thank you for the reply. So far, I have understood as follows.

dim = 3 dim = 2
material solid.name face.name
boundary face.name edge.name