sfe_py的应力云图计算与显示step by step
1.依赖环境
首先是相关环境的安装,如果你使用wsl模式的linux环境,你还是趁此机会给ubuntu装个虚拟显示器。相关的一系列安装动作:
- pip install sfepy
- 如果你安装的是2025.2版,你需要:
- pip install jax
- 这是sfe_py矩阵运算的数学库依赖
- 大概率是numpy的速度不够快
- sudo apt update && sudo apt install libgl1-mesa-glx x11-apps -y
- 如果你使用了ubuntu 22.4以上的版本:
- sudo apt update && sudo apt install libglx-mesa0 x11-apps -y
- 如果你使用了ubuntu 22.4以上的版本:
- echo "export DISPLAY=$(grep nameserver /etc/resolv.conf | awk '{print $2}'):0.0" >> ~/.bashrc
source ~/.bashrc
注意这里只是一次性地得到了宿主机的ip,如果需要长期使用x11,需要修改~/.bashrc:# enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). #if [ -f /etc/bash_completion ] && ! shopt -oq posix; then # . /etc/bash_completion #fi #export DISPLAY=172.26.208.1:0.0 # 方法1:从路由表提取默认网关(宿主机IP) host_ip_via_route=$(ip route | awk '/default/ {print $3}' | head -n1)# 方法2:从 resolv.conf 提取DNS服务器(宿主机IP) host_ip_via_dns=$(grep -oP 'nameserver \K[\d.]+' /etc/resolv.conf | head -n1)# 优先使用路由表结果,失败则回退DNS解析 host_ip="${host_ip_via_route:-$host_ip_via_dns}" export DISPLAY="${host_ip}:0.0"
- windows环境安装:
- vcxsrv-64.1.20.14.0.installer.exe
2. 例程
代码不建议上来徒手做.mesh文件建模,可以先跑一下系统自带的例程:
比如:
sfepy-run ./mixed_mesh.py
...................... .mixed_mesh.py 在sfepy的安装目录,如果你的python启用了.venv,它位置很好找:
find .venv -name "mixed_mesh.py"
sfepy-view beam_h* -f u:s0:wu:e:p0 u:s1:wu:e:p0
............................显示生成的.vtk文件
例程里的beam:
- 这个还没有仔细校对参数,应该是匀质梁的单端固定的效果。
- 接下来可以先从改变外力,叠加外部载荷开始。
附录A 原始文档,例程位置
SfePy: Simple Finite Elements in Python — SfePy version: 2025.2+git.e2f7d954 documentation
有一篇关于mesh的文可能会用到:
mesh算法进化如何实现?这里是成功实例......_几何_三角形_数量
它给出了更少点数,更好的效果的一种实施例。
附录B 关于测点位置与剪力滞
实际埋点时,剪力滞的问题可能会影响误差,目前已知的解决方案是,把传感器放置在腹板,而不是上下翼板,避开这个问题。
附录C .mesh文件的格式
- Dimension 3 定义了这是一个3维结构
- Vertices是点,每个点因为是3维,所以有3个点,第4列是点类目标的标记。
- Hexahedra是六面体,由8个点组成,最后一列是类型标记,1.
- Tetrahedra是三棱锥,也就是4面体,由4个点组成,最后一列是类型标记,2.
- 六面体,三棱锥中的坐标都是顶点坐标,Vertices.单独的点没有意义。只能在纳入一个结构中才有意义。
MeshVersionFormatted 2
Dimension 3Vertices
32
0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0
0.0000000000000000e+00 1.0000000000000001e-01 0.0000000000000000e+00 0
0.0000000000000000e+00 1.0000000000000001e-01 1.0000000000000001e-01 0
0.0000000000000000e+00 0.0000000000000000e+00 1.0000000000000001e-01 0
1.0000000000000001e-01 0.0000000000000000e+00 0.0000000000000000e+00 0
1.0000000000000001e-01 1.0000000000000001e-01 0.0000000000000000e+00 0
1.0000000000000001e-01 1.0000000000000001e-01 1.0000000000000001e-01 0
1.0000000000000001e-01 0.0000000000000000e+00 1.0000000000000001e-01 0
2.0000000000000001e-01 0.0000000000000000e+00 0.0000000000000000e+00 0
2.0000000000000001e-01 1.0000000000000001e-01 0.0000000000000000e+00 0
2.0000000000000001e-01 1.0000000000000001e-01 1.0000000000000001e-01 0
2.0000000000000001e-01 0.0000000000000000e+00 1.0000000000000001e-01 0
2.9999999999999999e-01 0.0000000000000000e+00 0.0000000000000000e+00 0
2.9999999999999999e-01 1.0000000000000001e-01 0.0000000000000000e+00 0
2.9999999999999999e-01 1.0000000000000001e-01 1.0000000000000001e-01 0
2.9999999999999999e-01 0.0000000000000000e+00 1.0000000000000001e-01 0
4.0000000000000002e-01 0.0000000000000000e+00 0.0000000000000000e+00 0
4.0000000000000002e-01 1.0000000000000001e-01 0.0000000000000000e+00 0
4.0000000000000002e-01 1.0000000000000001e-01 1.0000000000000001e-01 0
4.0000000000000002e-01 0.0000000000000000e+00 1.0000000000000001e-01 0
5.0000000000000000e-01 0.0000000000000000e+00 0.0000000000000000e+00 0
5.0000000000000000e-01 1.0000000000000001e-01 0.0000000000000000e+00 0
5.0000000000000000e-01 1.0000000000000001e-01 1.0000000000000001e-01 0
5.0000000000000000e-01 0.0000000000000000e+00 1.0000000000000001e-01 0
5.9999999999999998e-01 0.0000000000000000e+00 0.0000000000000000e+00 0
5.9999999999999998e-01 1.0000000000000001e-01 0.0000000000000000e+00 0
5.9999999999999998e-01 1.0000000000000001e-01 1.0000000000000001e-01 0
5.9999999999999998e-01 0.0000000000000000e+00 1.0000000000000001e-01 0
6.9999999999999996e-01 0.0000000000000000e+00 0.0000000000000000e+00 0
6.9999999999999996e-01 1.0000000000000001e-01 0.0000000000000000e+00 0
6.9999999999999996e-01 1.0000000000000001e-01 1.0000000000000001e-01 0
6.9999999999999996e-01 0.0000000000000000e+00 1.0000000000000001e-01 0Hexahedra
5
1 2 3 4 5 6 7 8 1
5 6 7 8 9 10 11 12 1
9 10 11 12 13 14 15 16 1
13 14 15 16 17 18 19 20 1
21 22 23 24 25 26 27 28 1Tetrahedra
12
17 18 21 20 2
18 24 21 20 2
18 22 21 24 2
18 19 22 20 2
19 24 22 20 2
19 23 22 24 2
25 26 29 28 2
26 32 29 28 2
26 30 29 32 2
26 27 30 28 2
27 32 30 28 2
27 31 30 32 2End