问题摘要
我有一个矩形棱镜,如下图中,我知道顶点的坐标。
我想使用具有一定的客观侧长的四边形元素将棱镜的侧面分散在非结构化的表面网格中。更确切地说,我对将网格保存到文件不感兴趣,但是我想要一个代表网格元素的列表,并包括对构成每个元素的节点的引用(无论是在ID和坐标方面)。有可以做到这一点的Python库吗?
为什么是一个非结构化的网格?
对于像上图中图中的完美矩形棱镜,仅通过使用坐标和 numpy.linspace
获得结构化的表面网格非常简单。但是,我希望能够将棱镜与一些锥形或不同的碱基隔离。在那些情况下,结构化的网格可能会导致非常偏差的元素,而我希望这些元素尽可能接近与客观长度相等的正方形。
理想情况下
,Python脚本将从顶点坐标的定义和必须分配的面部的坐标开始:
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)])
然后它将继续进行面部离散化,并返回一个带有非结构性元素的列表网格,每个元素都有对其节点的引用(在ID和坐标方面)。
我已经看到有一些库,例如 pyvista
和 gmsh
,但我给人的印象是,它们更注重从文件中导入的网格,而不是实际产生网格和网格和网格来自某些坐标的网格连接信息,就像我想做的那样。
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.
发布评论
评论(1)
pyvista
也可以使用 polydata() :进行初始化。 .org/api/Utilities/_autosummary/pyvista.box.html“ rel =“ nofollow noreferrer”>
box
box (默认使用Quadrilital Elements):您可以施放
Polydata
toUnscorturedGrid
使用 cast_to_unstructure_grid 。有关更多信息,请参见数据模型用户指南的部分。
pyvista
can also be used to generate meshes usingPolydata()
:There are also some helper functions for simple geometric objects, e.g.
Box
(it uses quadrilateral elements by default):You can cast
PolyData
toUnstructuredGrid
usingcast_to_unstructured_grid
.For more information see the Data Model section of the user guide.