I want to define a mesh with a subdomain. This is currently done by the following MWE and results in the plot below.
In my application I want to have a finer mesh around the boundary of the inner subdomain. One row of finer cells is enough. My idea of defining two extra rectangles (helper1 and helper2 in the code) is ignored, if I use the simple approach of adding helper1/2 to the domain.
Question: How do I force fenics/mshr to use my specified geometry in the inside of the domain?
Further thoughts:
- helper1/2 are ignored because the + operator is defined as the union. So in a mathematically sense the result is correct. The inner rectangle can be ignored because they are completely surrounded by the outer rectangle. Is there another command to combine/add two geometries but not as a union?
- I tried to use the set_subdomain method, but it is restricted in such a way that a subdomain number of 0 can not be assigned. So a workaround would to be use subdomain ids >0.
MWE
import fenics as fe
import mshr as mshr
#define geometry
domain = mshr.Rectangle( fe.Point(-1,-1), fe.Point(1,1) )
core = mshr.Rectangle( fe.Point(-0.5,-0.5), fe.Point(0.5,0.5) )
# this does not work
helper1 = mshr.Rectangle( fe.Point(-0.6,-0.6), fe.Point(0.6,0.6) )
helper2 = mshr.Rectangle( fe.Point(-0.4,-0.4), fe.Point(0.4,0.4) )
domain += helper1 + helper2
# mark subdomains
domain.set_subdomain(1, core)
# create mesh and meshfunction
mesh = mshr.generate_mesh(domain, 1)
marker_subdomain = fe.MeshFunction('size_t', mesh, 2, mesh.domains())
#plot
fe.plot(marker_subdomain)
fe.plot(mesh)
Plot for the desired outcome the red rectangles are missing in the MWE