🍺相关文章汇总如下🍺:
- 🎈ANSYS二次开发:APDL开发入门准备🎈
- 🎈ANSYS二次开发:后处理使用APDL命令流解析结果文件🎈
- 🎈ANSYS二次开发:Python解析ANSYS结果文件(PyAnsys库)🎈
- 🎈ANSYS二次开发:Python和ANSYS进行交互操作(PyAnsys库,PyDPF)🎈
- 🎈ANSYS二次开发:Python解析ANSYS FLUENT结果文件🎈
文章目录
- 1、下载PyAnsys库
- 2、安装PyAnsys
- 3、官网入门示例
- 4、官网进阶示例
-
- 4.1 Custom Scalar Visualization(自定义标量可视化)
- 4.2 Cylindrical Nodal Stress(圆柱节点应力)
- 4.3 Shaft Modal Analysis(可视化轴模态分析)
- 4.4 Thermal Analysis(热分析)
- 4.5 Shell Static Analysis(壳静态分析)
- 4.6 Understanding Nodal Diameters from a Cyclic Model Analysis
- 4.7 Stress and Strain from a Cyclic Modal Analysis(循环模态分析中的应力和应变)
- 4.8 Cyclic Model Visualization(动画完整的循环模型)
- 5、个人测试示例
- 结语

1、下载PyAnsys库
1.1 PyAnsys Project(legacy)
https://pypi.org/project/pyansys/
pip install pyansys
pip install pyvista
1.2 PyAnsys Project(recommended)
https://docs.pyansys.com/
https://github.com/pyansys
This is the legacy module for reading in binary and ASCII files generated from MAPDL.
This Python module allows you to extract data directly from binary ANSYS v14.5+ files and to display or animate them rapidly using a straightforward API coupled with C libraries based on header files provided by ANSYS.
To use PyAnsys you need to install the applicable packages for your product:
- MAPDL:
pip install ansys-mapdl-core
- AEDT:
pip install pyaedt
- MAPDL Post-Processing:
pip install ansys-dpf-core
pip install ansys-dpf-post
pip install ansys-mapdl-reader
2、安装PyAnsys
这里测试环境是:
- Win10 x64位,
- Python 3.9.7 x64位,
- VsCode代码编辑器。
这个项目最初是作为一个单独的包开始的pyansys,并且已经扩展到五个主要包:
- PyMAPDL:MAPDL 的 Pythonic 接口
- PyAEDT : AEDT 的 Pythonic 接口
- PyDPF-Core:使用数据处理框架 (DPF) 进行后处理。更复杂但更强大的后处理 API。
- PyDPF-Post:流线型和简化的 DPF 后处理。更高级别的包和用途ansys-dpf-core。
- Legacy PyMAPDL Reader:旧版结果文件阅读器。支持从 MAPDL v14.5 到当前版本的结果文件。
2.1 PyMAPDL
- 安装此软件包:
pip install ansys-mapdl-core
- All the features of the original module (e.g. pythonic commands, interactive sessions).
- Remote connections to MAPDL from anywhere via gRPC.
- Direct access to MAPDL arrays, meshes, and geometry as Python objects.
- Low level access to the MAPDL solver through APDL math in a scipy like interface.
- 直接从 Python 与 MAPDL 进程进行通信。
from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl()
print(mapdl)
Cached ANSYS executable not found
Enter location of ANSYS executable:
提示:输出信息说明这个子库的功能需要电脑上安装ANSYS软件。
- 补充1:
在一台Win8.1 64位的计算机上安装了Python3.8、Ansys17.2版本之后,子库“ansys-mapdl-core”测试脚本运行通过,截图如下:
- 补充2:
(1)“The ansys-mapdl-core package currently supports Python 3.6 through Python 3.8 on Windows, Mac OS, and Linux.”
(2)“You will need a local licenced copy of ANSYS to run MAPDL prior and including 2021R1. If you have the latest version of 2021R1 you do not need MAPDL installed locally and can connect to a remote instance via gRPC.”
以上(1)、(2)两段文字来自官网:https://pypi.org/project/ansys-mapdl-core/
2.2 PyAEDT
- 安装此软件包:
pip install pyaedt
2.3 PyDPF-Core
- 安装此软件包:
pip install ansys-dpf-core
ValueError: Unable to automatically locate the Ansys path for version 221.Manually enter one when starting the server or set it as the environment variable “ANSYS_PATH”
提示:输出信息说明这个子库的功能需要电脑上安装ANSYS软件。
- 补充1:
在一台Win8.1 64位的计算机上安装了Python3.8、Ansys17.2版本之后,子库“ansys-dpf-core”和“ansys-dpf-post”测试脚本运行失败,截图如下:
- 补充2:
“Provided you have ANSYS 2021R1 or higher installed, a DPF server will start automatically once you start using DPF.”
以上这段文字来自官网:https://pypi.org/project/ansys-dpf-core/
2.4 PyDPF-Post
- 安装此软件包:
pip install ansys-dpf-post
ValueError: Unable to automatically locate the Ansys path for version 221.Manually enter one when starting the server or set it as the environment variable “ANSYS_PATH”
提示:输出信息说明这个子库的功能需要电脑上安装ANSYS软件。
- 补充1:
“Provided you have ANSYS 2021R1 installed, a DPF server will start automatically once you start using DPF-Post. Should you wish to use DPF-Post without 2020R1, see the DPF Docker documentation.”
以上这段文字来自官网:https://pypi.org/project/ansys-dpf-post/
2.5 Legacy PyMAPDL Reader
This module will likely change or be depreciated in the future.
You are encouraged to use the new Data Processing Framework (DPF) modules at DPF-Core and DPF-Post as they provide a modern interface to ANSYS result files using a client/server interface using the same software used within ANSYS Workbench, but via a Python client.
- 安装此软件包:
pip install ansys-mapdl-reader
测试代码如下:
- 过时的写法:
import pyansys
from pyansys import examples
rst = pyansys.read_binary(examples.rstfile)
freqs = rst.time_values
print(freqs)
print(rst.mesh)
print(rst.mesh.nnum)
print(rst.mesh.enum)
rst.plot_nodal_solution(0)
rst.plot_nodal_solution(1)
rst.plot_nodal_solution(2)
rst.plot_nodal_solution(3)
rst.plot_nodal_solution(4)
rst.plot_nodal_solution(5)
- 推荐的写法:
from ansys.mapdl import reader as pymapdl_reader
from ansys.mapdl.reader import examples
# Sample result file
rstfile = examples.rstfile
# Create result object by loading the result file
result = pymapdl_reader.read_binary(rstfile)
result.plot_nodal_solution(0)
result.plot_nodal_solution(1)
result.plot_nodal_solution(2)
result.plot_nodal_solution(3)
result.plot_nodal_solution(4)
result.plot_nodal_solution(5)






运行没有报错!!!
提示:输出信息说明这个子库的功能不需要电脑上安装ANSYS软件!!!
(1)这是用于读取从 MAPDL 生成的二进制和 ASCII 文件的遗留模块。
这个 Python 模块允许您直接从二进制 ANSYS v14.5+ 文件中提取数据,并使用简单的 API 以及基于 ANSYS 提供的头文件的 C 库快速显示或动画化它们。
(2)该模块将来可能会更改或废弃。
我们鼓励您在DPF-Core和 DPF-Post上查看新的数据处理框架 (DPF) 模块,