Define a boundary for DG elements

Hello,

I have a 2D mesh. I want to make a boundary by marking the centroids of specific elements. I have already exported those centroids, so I just want to make a boundary with them.

Thank you

Please read the guidelines: Read before posting: How do I get my question answered?
To me it is unclear what you mean by “making a boundary”. Do you mean you would like to mark facets of a set of elements based on the value of the centroid of the element?

Please post a minimal working example as illustrated in the subsequent post in the thread I link to above.

Let me explain myself. I have a 2D mesh using DG elements for an unknown. I want to impose a Dirichlet BC for this unknown. As it is a DG unknown, I have to impose this BC on a boundary that contains the centroids of the elements. To this end, I export all the centorids of the mesh and I store those I care for in the list “inlet”.

centroid = []

for cell_no in range(mesh.num_cells()):
	coc = Cell(mesh, cell_no).midpoint()

coo = []
	coo.append(coc.x())
	coo.append(coc.y())
	coo.append(coc.z())

	centroid.append(coo)

inlet = []

for i in range(len(centroid)):
	if (abs(centroid[i][0]-0.0041)<1.e-4):
		inlet.append(i)

Now I want to make a boundary which contains the centroids of the inlet list. I made the following code but it did not work.

class boundary(SubDomain):
	def inside(self, x, on_boundary):
 	       tol = 1.e-4
           for i in inlet:
 		    p = near( x[0], centroid[i][0] , tol) and near(x[1],  centroid[i][1]  , tol) 
 		    if ( p is True):
 			return (p)


sub_boundaries = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
sub_boundaries.set_all(0)

inletBD = boundary()
inletBD.mark(sub_boundaries, 1)

 inletBC = DirichletBC(VP.sub(1), pIn , sub_boundaries ,  1)

I hope now it is clear.

Thank you