Mark element inside domain


118
views
0
4 months ago by
Hi, I am trying to mark element along the circle (see Figure 1) but with my code I am able to mark all the elements inside the circle. How can I mark elements only on the circle.


Thanks for the time
Regards
from dolfin import *

mesh = UnitSquareMesh(20,20)
class ele_circle(SubDomain):
    def inside(self,x,on_boundary):
        tol = 1e-3
        return True if ((x[0]-0.5)**2 + (x[1]-0.5)**2 - 0.2**2) < tol else False

subdomains = CellFunction('size_t', mesh)
subdomains.set_all(0)

subdomain0 = ele_circle()
subdomain0.mark(subdomains,1)

plot(subdomains, interactive = True)
​

HSK
Community: FEniCS Project

1 Answer


3
4 months ago by
class ele_circle(SubDomain):
    def inside(self, x, on_boundary):
        tol = 2e-2
        return near((x[0]-0.5)**2 + (x[1]-0.5)**2, 0.2**2, tol)

Of course, it is highly sensitive to the chosen tolerance and the mesh resolution.

Please login to add an answer/comment or follow this question.

Similar posts:
Search »