Problem summary
I have a rectangular prism like in the image below where I know the coordinates of the vertices.
I want to discretize the lateral faces of the prism into an unstructured surface mesh using quadrilateral elements with a certain objective side length. More precisely, I am not interested in saving the mesh to a file, but I want a list representing the elements of the mesh and including a reference to the nodes composing each element (both in terms of id and coordinates). Is there a python library that can do this?
Why an unstructured mesh?
For a perfect rectangular prism like the one in the image above, it is fairly simple to obtain a structured surface mesh just by playing with the coordinates and numpy.linspace
. However, I want to be able to mesh a prism with some taper or with different bases. In those cases, a structured mesh might lead to very skewed elements, while I would like the elements to be as close as possible to a square with side equal to the objective length.
Starting point
Ideally, the python script would start with the definition of the coordinates of the vertices and of the faces that have to be meshed:
import numpy as np
# Geometric properties
aspect_ratio = 9.
c = 1e3 # [mm]
b = aspect_ratio*c
non_dimensional_height = 0.1
h = c*non_dimensional_height # [mm]
non_dimensional_thickness = 0.001
t = c*non_dimensional_thickness # [mm]
# Objective length of the side of the quadrilateral elements
side_length = 10 # [mm]
# Define points coordinates
points_xyz = np.array([(0., 0., h/2), # 0 -> A
(c, 0., h/2), # 1 -> B
(0., 0., -h/2), # 2 -> C
(c, 0., -h/2), # 3 -> D
(0., b, h/2), # 4 -> A'
(c, b, h/2), # 5 -> B'
(0., b, -h/2), # 6 -> C'
(c, b, -h/2)]) # 7 -> D'
# Define faces by sequence of points
faces = np.array([(0,1,5,4), (1,2,6,5), (2,3,7,6), (3,0,4,7)])
and then it would continue with the discretization of the faces and returning a list with all the elements of the unstructured mesh, where each element has a reference to its nodes (both in terms of ids and coordinates).
I have seen that there are libraries like pyvista
and gmsh
, but I got the impression that they are more oriented towards working with meshes imported from files rather than actually produce a mesh and the mesh connectivity information from some coordinates like I want to do.