### modified inside function to generate submesh

79

views

0

Dear all,

I would like to generate a sub mesh using sub domains. Subdomain is defined by a circle with unit radius. I want all the elements which is crossing the circle boundary to be included in the subdomain. The following code creates a submesh but if anyone of the nodes of an element is outside the circle, that element is not included. I think this related to the inside() function. Can we modify this function so that what I need is done? Where can I find this function in Ubuntu folders to check? Or, any other suggestions?

Note: I donot want to use tolerance which is sensitive to mesh size.

Here is the code:

I would like to generate a sub mesh using sub domains. Subdomain is defined by a circle with unit radius. I want all the elements which is crossing the circle boundary to be included in the subdomain. The following code creates a submesh but if anyone of the nodes of an element is outside the circle, that element is not included. I think this related to the inside() function. Can we modify this function so that what I need is done? Where can I find this function in Ubuntu folders to check? Or, any other suggestions?

Note: I donot want to use tolerance which is sensitive to mesh size.

Here is the code:

```
from fenics import *
# Generate mesh
mesh = RectangleMesh(Point(-1.1,-1.1), Point(1.1,1.1), 32, 32,'crossed')
# Define subdomains
class innerbound(SubDomain):
def inside(self, x, on_boundary):
return (sqrt(x[0]*x[0] + x[1]*x[1])<1.0)
sub_domains=MeshFunction('size_t', mesh, mesh.topology().dim() - 1)
sub_domains.set_all(0)
ibound=innerbound()
ibound.mark(sub_domains,1)
# Generate submesh
smesh=SubMesh(mesh,ibound)
```

Here is the subdomain generated by this function which does not include all the elements crossing the white circle:

Thank you

Birkan

Community: FEniCS Project

### 1 Answer

0

What about

?

You already know how to mark

`set_of_crossed_cells = all_cells - strictly_interior_cells - strictly_exterior_cells`

?

You already know how to mark

`strictly_interior_cells`

and `strictly_exterior_cells`

is its simple modification.
That was pseudo-code. You can mark the mesh function in several steps. I let it to you as an exercise.

written
8 weeks ago by
Jan Blechta

Worked like this for who is interested. Thank you.

```
# Define subdomains
class outerbound(SubDomain):
def inside(self, x, on_boundary):
return (sqrt(x[0]*x[0] + x[1]*x[1])>1.0)
sub_domains=MeshFunction('size_t', mesh, mesh.topology().dim() - 0)
sub_domains.set_all(0)
obound=outerbound()
obound.mark(sub_domains,1)
# Generate submesh
smesh=SubMesh(mesh,sub_domains,0)
```

written
8 weeks ago by
Birkan

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

Can I combine or substract subdomains? Your suggestion works of this can be done. Do you know how to do this?

Thank you