How to adapt mesh markers to refined mesh?
4 months ago by
After that I adapt mesh markers but it seems like they are not adapted and that mesh markers defining class koef are the same as they are in the original (nonrefined) mesh.
from fenics import * from mshr import * import matplotlib.pyplot as plt # Mesh R=0.2 domain = Rectangle(Point(0, 0), Point(1, 1)) patch = Circle(Point(0.5, 0.5), R) domain.set_subdomain(1, patch) mesh0 = generate_mesh(domain, 20) markers0 = MeshFunction('size_t', mesh0, 2, mesh0.domains()) $ Mesh refinement tol = 0.02 cell_markers = MeshFunction("bool", mesh0, 2) origin = Point(0.5, 0.5) for cell in cells(mesh0): p = cell.midpoint() if R - tol <= p.distance(origin) <= R + tol: cell_markers[cell] = True else: cell_markers[cell] = False mesh = refine(mesh0, cell_markers) # Update markers markers = adapt(markers0, mesh) # Function space V = FunctionSpace(mesh, "P", 1) # Mesh function class koef(Expression): def __init__(self, mesh, **kwargs): self.markers = markers def eval_cell(self, values, x, cell): if markers[cell.index] == 0: values = 1 else: values = 10 kappa = koef(mesh, degree=0) A = interpolate(kappa, V)
Using very coarse mesh at the beggining we get something like this:
and using finer mesh we get something like this:
In both cases class koef does not see updated mesh subdomain markers to refined mesh.
Community: FEniCS Project
4 months ago by
Try replacing the following lines in your code
with the following lines, and check out if this does what you want done.
mesh = refine(mesh0, cell_markers) # Update markers markers = adapt(markers0, mesh)
print("Size of cell_markers before refinement. %d \n" % cell_markers.size()) adapt(mesh) adapt(cell_markers, mesh.child()) mesh = mesh.child() cell_markers = cell_markers.child() print("Size of cell_markers after refinement. %d \n" % cell_markers.size())
Please login to add an answer/comment or follow this question.