从坐标产生非结构化的表面网格

发布于 2025-02-06 17:50:32 字数 1659 浏览 1 评论 0 原文

问题摘要

我有一个矩形棱镜,如下图中,我知道顶点的坐标。

我想使用具有一定的客观侧长的四边形元素将棱镜的侧面分散在非结构化的表面网格中。更确切地说,我对将网格保存到文件不感兴趣,但是我想要一个代表网格元素的列表,并包括对构成每个元素的节点的引用(无论是在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.

enter image description here

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫卆 2025-02-13 17:50:32

pyvista 也可以使用 polydata()

由表面几何形状组成的数据集(例如顶点,线和
多边形)。

可以通过多种方式初始化:

  • 创建一个空网格
  • 从vtk.vtkpolydata初始化
  • 使用顶点
  • 使用顶点和面
  • 来自文件

进行初始化。 .org/api/Utilities/_autosummary/pyvista.box.html“ rel =“ nofollow noreferrer”> box box (默认使用Quadrilital Elements):

import pyvista
mesh = pyvista.Box((0, c, 0, b, -h/2, h/2), level=10, quads=True)

print(mesh)
#PolyData (0x197125e5f40)
#  N Cells: 726
#  N Points:    728
#  X Bounds:    0.000e+00, 1.000e+03
#  Y Bounds:    0.000e+00, 9.000e+03
#  Z Bounds:    -5.000e+01, 5.000e+01
#  N Arrays:    0

for i in range(mesh.number_of_cells):
    print(mesh.cell_points(i))
#[[  0.           0.         -50.        ]
# [  0.           0.         -40.90909195]
# [  0.         818.18182373 -40.90909195]
# [  0.         818.18182373 -50.        ]]
# ...

您可以施放 Polydata to UnscorturedGrid 使用 cast_to_unstructure_grid

有关更多信息,请参见数据模型用户指南的部分。

pyvista can also be used to generate meshes using Polydata():

Dataset consisting of surface geometry (e.g. vertices, lines, and
polygons).

Can be initialized in several ways:

  • Create an empty mesh
  • Initialize from a vtk.vtkPolyData
  • Using vertices
  • Using vertices and faces
  • From a file

There are also some helper functions for simple geometric objects, e.g. Box (it uses quadrilateral elements by default):

import pyvista
mesh = pyvista.Box((0, c, 0, b, -h/2, h/2), level=10, quads=True)

print(mesh)
#PolyData (0x197125e5f40)
#  N Cells: 726
#  N Points:    728
#  X Bounds:    0.000e+00, 1.000e+03
#  Y Bounds:    0.000e+00, 9.000e+03
#  Z Bounds:    -5.000e+01, 5.000e+01
#  N Arrays:    0

for i in range(mesh.number_of_cells):
    print(mesh.cell_points(i))
#[[  0.           0.         -50.        ]
# [  0.           0.         -40.90909195]
# [  0.         818.18182373 -40.90909195]
# [  0.         818.18182373 -50.        ]]
# ...

You can cast PolyData to UnstructuredGrid using cast_to_unstructured_grid.

For more information see the Data Model section of the user guide.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文