经过长时间寻找答案后,我认为向社区询问可能会更好。
我遇到的问题是我需要将 STL 文件转换为网格文件。我知道我因此需要从 STL 文件向曲面添加一个体积。
当我在 gmsh 中手动操作时
模块->几何->基本实体->添加->体积->在表面网格上单击->按'e'->按'q')
效果很好。
由于我必须为数百个 .stl 文件执行此过程,因此我无法使用 gui 手动执行此过程。因此,我创建了一个脚本,它使用命令行参数来执行上述操作并避免打开 gui。到目前为止,我有:
gmsh input.stl -string "Surface Loop(2)={1}; Volume(3)={2};" -3 -o output.msh
当我运行它时,我得到了错误,即表面 1 是未知的。但是当我在 gui 中手动检查 STL 文件并且除了打开这个 STL 文件什么都不做时,它显示表面的 id 为 1。那么为什么脚本版本中的表面是未知的?是否有更好的方法可以使用 gmsh 向表面网格添加体积?
PS:我不能使用.geo
-file 来执行命令,因为我正在使用 shell 脚本来遍历我的文件(文件名中有变量)。使用.geo
-file 将不再允许我使用这些变量。
PPS:这是我现在使用的脚本:
#!/bin/bash
# amount of files to be processed
endVal=400
# amount of slices per timestep to be processed
sliceCount=2
# create output folders for .msh and remeshed .stl files, if necessary
cd Slices/
# save current working directory to a variable
cwd=$(pwd)
# folder structure should be:
# / the Slices folder, created by the user or another script
# MSH/ after running the script it should contain the meshes created by gmsh
# Remeshed/ after running the script it should contain the remeshed meshes generated by mmg
# STL/ should contain the .stl files
# STL_Remeshed/ after running it should contain the remeshed meshes converted back to the .stl format by gmsh
if [[ ! -d MSH/ ]]; then
mkdir -p MSH/Remeshed
fi
if [[ ! -d STL_Remeshed/ ]]; then
mkdir STL_Remeshed
fi
for ((a = 0; a < $sliceCount; a++))
do
for ((i = 0; i < $endVal; i++))
do
# convert .stl to .msh
/Volumes/User/Gmsh.app/Contents/MacOS/gmsh $cwd/STL/slice$a.$i.stl -string "Merge '$cwd/STL/slice$a.$i.stl'; Surface Loop(2)={1}; Volume(3)={2};" -3 -o $cwd/MSH/slice$a.$i.msh -format "msh22"
# remesh
/Volumes/User/mmg/mmg3d_debug -in $cwd/MSH/slice$a.$i.msh -out $cwd/MSH/Remeshed/slice$a.$i.msh -hausd 0.00005
# convert remeshed .msh to .stl
/Volumes/User/Gmsh.app/Contents/MacOS/gmsh $cwd/MSH/Remeshed/slice$a.$i.msh -0 -o $cwd/STL_Remeshed/slice$a.$i.stl
done
done