ANSYS二次开发:Python解析ANSYS结果文件(PyAnsys库)

🍺相关文章汇总如下🍺:

  1. 🎈ANSYS二次开发:APDL开发入门准备🎈
  2. 🎈ANSYS二次开发:后处理使用APDL命令流解析结果文件🎈
  3. 🎈ANSYS二次开发:Python解析ANSYS结果文件(PyAnsys库)🎈
  4. 🎈ANSYS二次开发:Python和ANSYS进行交互操作(PyAnsys库,PyDPF)🎈
  5. 🎈ANSYS二次开发:Python解析ANSYS FLUENT结果文件🎈


在这里插入图片描述

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,并且已经扩展到五个主要包:

  1. PyMAPDL:MAPDL 的 Pythonic 接口
  2. PyAEDT : AEDT 的 Pythonic 接口
  3. PyDPF-Core:使用数据处理框架 (DPF) 进行后处理。更复杂但更强大的后处理 API。
  4. PyDPF-Post:流线型和简化的 DPF 后处理。更高级别的包和用途ansys-dpf-core。
  5. Legacy PyMAPDL Reader:旧版结果文件阅读器。支持从 MAPDL v14.5 到当前版本的结果文件。
    在这里插入图片描述

2.1 PyMAPDL

  • 安装此软件包:
pip install ansys-mapdl-core
  1. All the features of the original module (e.g. pythonic commands, interactive sessions).
  2. Remote connections to MAPDL from anywhere via gRPC.
  3. Direct access to MAPDL arrays, meshes, and geometry as Python objects.
  4. 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) 模块,

评论 104
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值