Subdomains in 1D mesh

Hello,

I have an 1D mesh like that


xl = 0.
xr = 1.
mesh = IntervalMesh ( 100 , xl, xr )

How can I define the “ds” of the above mesh which are the node at x = 0 and the node at x= 1?

I don’t know exactly if it’s what your looking for but you could try something like this:

#Define both boundaries of the domain
class Left(SubDomain):  
    def inside(self, x, on_boundary):
        return on_boundary and x[0]<0.5

class Right(SubDomain):  
    def inside(self, x, on_boundary):
        return on_boundary and x[0]> 0.5

#Define meshfunction
mesh_function= MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
mesh_function.set_all(0)

Left_tag, Right_tag = 1, 2


# Mark left and right boundaries with their respective tags
left_instance = Left()
left_instance.mark(bound_mshfunc, Left_tag)

right_instance = Right()
right_instance.mark(bound_mshfunc, Right_tag)

ds = Measure('ds', domain=mesh, subdomain_data = mesh_function)
1 Like

Works. Thank you very much

1 Like