# Different methods in defining subdomains

Hi,

I’m new with FENICS and struggling with subdomains as they pop up in different ways, as far as I understand. Lets look at the following example

``````  import fenics as fe
import mshr as ms

DO = ms.Circle(fe.Point(0,0),1)-ms.Rectangle(fe.Point(-1,-1),fe.Point(0,1))
#
P1 = fe.Point(0,-0.5); P2=fe.Point(0.2,0.1)
Pdomain= ms.Rectangle(P1,P2)
DO.set_subdomain(1,Pdomain)
my_mesh=ms.generate_mesh(DO,15)
fe.plot(my_mesh)
plt.show()
file=fe.File("thismesh.xml")
file<<my_mesh
``````

I understand, that a subdomain is generated (and with it also an inner rectangle line which can be seen in the plot) and index 1 is assigned to cells within the inner rectangle. This can also be seen in the xml file. Fine.

In the documentation however the subdomains or boundaries are often done
(e.g. Handling Domains with Different Materials — A FEniCS Tutorial 1.0 documentation )
by a class defintions like

``````  class PDomain(fe.SubDomain):
def inside(self, x, on_boundary):
if x<=0.2 and -0.5 <= x <= 0.1:
return True
else:
return False

subdomainPD = PDomain()
materials = fe.MeshFunction('size_t', my_mesh , 2)
subdomainPD.mark(materials, 1)
``````

Is this subdomain “the same” as above? Is there some connection between them, as both have index 1. Is it possible to use the definition of the subdomain in the first example and omit the class definition of PDomain? Is there a simple way to see the cell numbers or coordinates of the subdomain in the second example? I understand that the second method is quit flexible also on defining material parameters on subdomains which might be not possible in the first example.

One subdomain is defined by labels attached to topological entities. The other generates topological entity labels based on a geometric search.

The documentation and code you’re looking at is around 10 (perhaps more) years out of date. Consider the dolfinx tutorial and @dokken’s very helpful meshing tutorials with gmsh.

tanks, i will have a look on it.

" … labels attached to topological entities "
" … generates topological entity labels based … "

So are the label conceptually different ?