I’ve regarded the following problem:
I have a domain (unit square) and an included subdomain (a smaller rectangle inside). Now I want to refine only the elements inside the subdomain, whose faces are on the boundary of the subdomain. To this end I created the following attempt
from dolfin import * from mshr import * from fenics import * # Constants related to the geometry sw = Point ( 0.0, 0.0 ) ne = Point ( 1.0, 1.0 ) domain = Rectangle ( sw, ne ) #domain.set_subdomain(1, domain) smalldomain = Rectangle(Point(0.25,0.25),Point(0.75,0.75)) domain.set_subdomain(2, smalldomain) # Mesh the region. # # mesh = generate_mesh ( domain, 5) #mesh= RectangleMesh(sw,ne, 2, 2,"crossed") #mesh = UnitSquareMesh(20, 20, "crossed") #mesh = generate_mesh(domain, 20,"cgal") # Define boundaries # Define boundaries boundary_markers = MeshFunction('size_t', mesh, 2, mesh.domains()) boundaries = MeshFunction('size_t', mesh, 1, mesh.domains()) # Use the cell domains associated with each facet to set the boundary for j in range(4): mesh.init(1, 2) # Initialise facet to cell connectivity markers = CellFunction('bool', mesh, False) for f in facets(mesh): domains =  for c in cells(f): domains.append(boundary_markers[c]) domains = list(set(domains)) if len(domains) > 1: boundaries[f] = 2 markers[c]=True mesh = refine(mesh, markers)
My questions are:
- The code above works if I use “generate_mesh()” to create a mesh. If I use “RectangleMesh()” or somethin else, then
if len(domains) > 1:is always false. Why do we have this different behaviour?
Unfortunately, I have to use a structured mesh instead of the unstructered mesh coming from “create_mesh”, so I want this attempt to work by using “RectangleMesh(,“crossed”)”.
- The same thing occurs after refinement: If I refine the mesh one time, then we have again
if len(domains) > 1:is always false. What’s happening here?
I know that my solution is by far not elegant but in principle it should work.
Many thanks in advance,