Skip to content

GlowingTrash/TPMS-toolkits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TPMS Toolkit

三周期极小曲面(TPMS)点阵结构的生成、重网格化与四面体剖分工具包。可输出 Abaqus INP 文件用于有限元分析。

本项目参考了 MATLAB GIBBON 工具箱中的 TPMS 生成与网格处理流程,将其核心功能迁移至 Python 并做了优化和扩展。

本项目的代码在生成式人工智能(DeepSeek V4 Pro)的辅助下完成开发。

English version: README_EN.md

功能

  • 6 种曲面类型 — Gyroid、Diamond、Schwarz P/D、F-RD、I-WP
  • Sheet / Solid 双形态 — 双壁多孔结构或单实体/空隙结构
  • 自动端盖 — 直接输出水密封闭曲面
  • Geogram 重网格化 — 高质量均匀各向同性三角形
  • TetGen 四面体剖分 — 输出 Abaqus INP(C3D4 单元)
  • 管状 TPMS — 柱坐标变换生成环形结构

安装

pip install -r requirements.txt

bin/ 目录内已附带 Windows x64 的 vorpalite.exe(Geogram)和 tetgen.exe。其他平台需自行下载对应二进制文件放入 bin/

快速开始

from tpms import generate_tpms, remesh_surface, surface_to_tet4

# 1. 生成 Gyroid 单胞
result = generate_tpms(
    surface_case="Gyroid",
    L=(5, 5, 5),           # 单胞 5×5×5 mm
    N=50,                   # 网格分辨率
    volume_fraction=0.3,    # 体积分数 30%
    period=(1, 1, 1),       # 单周期
    form="sheet",           # 双壁结构
)

# 2. 重网格化,获得均匀三角形
faces, vertices = remesh_surface(
    result["F"], result["V"],
    point_spacing=0.4,      # 目标边长 ~0.4 mm
    filename="gyroid_remeshed.stl",
)

# 3. 四面体剖分 → Abaqus INP
mesh = surface_to_tet4(
    faces, vertices,
    filename="gyroid_mesh.inp",
)
print(f"已写入 {mesh['elements'].shape[0]:,} 个 C3D4 单元")

运行示例:python examples/basic_pipeline.py

API

generate_tpms(**kwargs) → dict

参数 类型 默认值 说明
surface_case str "Gyroid" Gyroid, Diamond, Schwarz_P, Schwarz_D, F_RD, IW_P
L (3,) float (1,1,1) 单胞尺寸 (x, y, z)
N int 50 各轴网格点数,越大越精细
volume_fraction float 0.3 体积分数 0~1;0 = 纯零级等值面(不加端盖)
period (3,) int (1,1,1) 各方向周期数
form str "sheet" "sheet" (S=方程², 双壁) 或 "solid" (S=方程)
isocap str "below" "below" (S≤阈值 为内部) 或 "above"
open_axis str None 不封口的方向:"x"/"y"/"z",用于环形变换

返回 {"F", "V", "Fi", "Vi", "S", "x", "y", "z", "threshold"}

remesh_surface(faces, vertices, point_spacing, anisotropy=0, filename=None) → (F, V)

调用 Geogram vorpalite 进行曲面重网格化。anisotropy=0 生成各向同性均匀三角形;非零值捕捉几何特征。filename 可选保存为 STL。

surface_to_tet4(faces, vertices, filename, string_opt="-pq1.2aY") → dict

调用 TetGen 将水密表面网格转换为四面体体积网格,输出 Abaqus INP 文件(C3D4 单元)。返回 {"nodes", "elements"}

write_stl(filename, faces, vertices, mode="binary")

STL 文件写入。

管状 TPMS(环形结构)

通过柱坐标变换将方盒域 TPMS 映射为环形:

import numpy as np
from tpms import generate_tpms, remesh_surface

# 方盒域 TPMS,x 方向不封口(留给环形闭合)
result = generate_tpms(
    L=(1, 1, 1), N=100, volume_fraction=0.45,
    period=(12, 4, 12),   # [周长, 壁厚, 高度]
    form="solid",
    open_axis="x",
)
F, V = result["F"], result["V"]

# 平移到 [0, L*P] 域
shift = np.array([6, 2, 6])
V_s = V + shift

# 柱坐标变换:x→角度, y→半径
phi = 2 * np.pi / 12
r = V_s[:, 1] + 2.0       # 内径 R_inner = 2
theta = V_s[:, 0] * phi
V_ring = np.column_stack([
    r * np.cos(theta),
    r * np.sin(theta),
    V_s[:, 2],
])

# 之后正常进行重网格化和四面体剖分
F_r, V_r = remesh_surface(F, V_ring, point_spacing=0.15)

依赖

Python 包

numpy>=1.24
scipy>=1.10
trimesh>=4.0
scikit-image>=0.20

外部程序

已附带于 bin/(Windows x64):

  • vorpalite (Geogram) — 曲面重网格化
  • tetgen — 四面体网格生成

其他平台请自行下载放入 bin/

参考文献

关于管状TPMS的更多信息,参考以下文献:

Wan L, Hu D, Wan M, et al. Lateral crushing behavior of tubular lattice structures with triply periodic minimal surface architectures[J]. Thin-Walled Structures, 2023, 189: 110905.

License

MIT

About

三周期极小曲面(TPMS)点阵结构生成、重网格化与四面体剖分工具包 | TPMS lattice generation, remeshing & tetrahedral meshing toolkits

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages