Hi all,
I am working on a 2D quad mesh into DOLFIN from two .txt files; one containing the nodal coordinates and one containing the element connectivity for 4-node quads.
The mesh looks correct in ParaView when exported directly from MATLAB, but when I reconstruct it in DOLFIN using the same node and connectivity files, I see“holes or missing elements along certain regions of the mesh.
Some information about my set up:
• Nodes are stored as (x, y) coordinates.
• Connectivity is 0-based indexed and each element has 4 node IDs.
• The total number of nodes and elements matches expectations.
• Bounding box looks correct after loading.
Since i only see this issue along certian regions of the mesh i am unsure if the reason for my issues are:
An issue with quad node ordering (clockwise vs counter-clockwise)
A problem with how DOLFIN computes quadrilaterals internally
Something related to how I’m constructing the mesh object from the connectivity arrays.
Has anyone seen similar behavior when importing quad meshes from custom text files? Any suggestions on diagnostics I should run.
Thank You!
It seems that new users cannot upload images or attach a link so i apologize i cannot upload an image of my mesh.
yes here is the first a sample of what my nodes file looks like
inode:
0.0000000E+00 9.8964456E+00
8.8817842E-16 1.1412958E+00
8.8817842E-16 2.1035544E+00
8.8817842E-16 2.9428473E+00
8.8817842E-16 3.6968158E+00
8.8817842E-16 4.3923048E+00
8.8817842E-16 5.0496934E+00
8.8817842E-16 6.9503066E+00
8.8817842E-16 7.6076952E+00
8.8817842E-16 8.3031842E+00
and here is an example of my element connectivities file
563 593 575 551
551 575 559 541
541 559 547 529
529 547 527 519
519 527 513 507
507 513 499 495
495 499 483 481
481 483 477 479
479 477 461 465
My geometry is a rectangular box with a circular hole, the issue i am facing is elements with bowtie shape in the mesh near the circle. The rest of the mesh seems to be fine in terms of not having any bowtie shapes or holes.
The two file i have used to create the mesh are my nodes file inode and my element connectivities file ielem.
the code i am using to create my mesh is below
def create_mesh(nodes_file="inode", cells_file="ielem"):
# 1. Load your current reordered data
nodes = np.loadtxt(nodes_file)
cells = np.loadtxt(cells_file, dtype=np.int32)
# 2. Create a "Spatial Sort": Sort all nodes by Y, then X
# This ensures that Global IDs increase as we move through the mesh
new_order = np.lexsort((nodes[:, 0], nodes[:, 1]))
# 3. Create a mapping from OLD index to NEW index
# old_to_new[old_id] = new_id
old_to_new = np.zeros(len(nodes), dtype=np.int32)
old_to_new[new_order] = np.arange(len(nodes))
# 4. Re-index the nodes and cells
sorted_nodes = nodes[new_order]
sorted_cells = old_to_new[cells]
# 5. Build the Mesh in DOLFIN
mesh = Mesh()
editor = MeshEditor()
editor.open(mesh, "quadrilateral", 2, 2)
editor.init_vertices(len(sorted_nodes))
for i, coords in enumerate(sorted_nodes):
editor.add_vertex(i, coords)
editor.init_cells(len(sorted_cells))
for i, cell_nodes in enumerate(sorted_cells):
# Sort the 4 nodes of this specific cell so they follow Z-order:
# [Bottom-Left, Bottom-Right, Top-Left, Top-Right]
c_coords = sorted_nodes[cell_nodes]
# Lexsort by Y then X for these 4 points
local_z_order = np.lexsort((c_coords[:, 0], c_coords[:, 1]))
z = cell_nodes[local_z_order] # [BL, BR, TL, TR]
#editor.add_cell(i, [int(z[0]), int(z[1]), int(z[3]), int(z[2])]) # -> [BL, BR, TR, TL]
editor.add_cell(i, cell_nodes[local_z_order])
editor.close()
# mesh.order()
return mesh
this code is able to create the mesh however has the bowtie issue
As we still don’t have the element files, it is a bit hard to figure out what is not working.
At least it seems like the ordering that you are going for: