Open duarte-jfs opened 1 month ago
Thanks for the report. Based on this, all named boundaries should be removed from the mesh during adaptive refine: https://github.com/kinnala/scikit-fem/blob/c6b36757a2ba3ebb048abfc9d49a9a9205155a35/skfem/mesh/mesh_tri_1.py#L389
What is check_mesh doing?
Anyhow, don’t expect this to be fixed any time soon. It is a somewhat challenging indexing problem to solve in general.
Sorry, the check_boundary
is just taking care of the plots. Getting elements coordinates and normal vectors and plotting.
Based on this, all named boundaries should be removed from the mesh during adaptive refine:
The thing is, the named boundaries are not preserved already. What is preserved is the sub domains, but the ordering may be messed up. I don't know
Anyhow, don’t expect this to be fixed any time soon. It is a somewhat challenging indexing problem to solve in general.
Yes, I can only imagine. It would be a great feature though
I don't quite follow what happens in this issue. Can you provide the code of check_mesh
?
I don't quite follow what happens in this issue. Can you provide the code of
check_mesh
?
def check_boundary(mesh):
plt.figure()
plt.scatter(*mesh.p, marker = 'o', facecolor = 'None', edgecolor = 'black', s = 15)
# boundary = mesh.boundaries['square___clad']
boundary = mesh.facets_around(mesh.subdomains['square'])
facet_basis = basis0.boundary(boundary)
facets = mesh.facets[:,boundary]
colors = plt.cm.jet(np.linspace(0,1,facets.shape[1]))
for i in range(facets.shape[1]):
# plt.text(*data[:,i], f'{i}')
x = [mesh.p[0,facets[0,i]], mesh.p[0,facets[1,i]]]
y = [mesh.p[1,facets[0,i]], mesh.p[1,facets[1,i]]]
norm = np.asarray([facet_basis.normals[0,i,0],
facet_basis.normals[1,i,0]])
norm = norm/np.sqrt(np.sum(np.abs(norm)**2)) * 0.1
plt.arrow(np.mean(x), np.mean(y), dx = norm[0], dy = norm[1], color = colors[i],
head_width = 0.03,
head_length = 0.01,
length_includes_head = True)
plt.plot(x, y, color = colors[i])
# plt.text(np.mean(x), np.mean(y), f"{i}")
plt.scatter(mesh.p[0,facets[0]], mesh.p[1,facets[0]], c = colors, s = 20)
plt.scatter(mesh.p[0,facets[1]], mesh.p[1,facets[1]], c = colors, s = 20)
I'm unable to reproduce this with my own minimal example, perhaps it was fixed by another issue, or then I misunderstood the issue:
from skfem import *
import numpy as np
m = MeshTri().refined(4).with_subdomains({'test': lambda x: (x[0] < 0.5) * (x[0] > 0.3) * (x[1] < 0.5) * (x[1] > 0.3)})
m = m.with_boundaries({'test': m.facets_around('test')})
m.draw(boundaries=True).show()
m = m.refined(np.arange(200))
m = m.with_boundaries({'test': m.facets_around('test')})
m.draw(boundaries=True).show()
Before refine:
After refine:
The normal vector should be pointing opposite to the red triangle.
I was working on the mesh refinement, trying to understand how can boundaries be kept, and came across the issue of the
mesh.facets_around()
not working properly after a refinement.Before refinement:
After refinement: