ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

[python]pyfluent安装和测试

[python]pyfluent安装和测试 pyfluent支持Python 3.7到Python 3.10Fluent版本最低为2022R2。1. 安装命令利用下面的命令可以安装最新版的pyfluentpip install ansys-fluent-core0.41.0(支持2024R2,2025R1如需支持2024R1在0.35.0测试通过)在CFD之道中还提到了“为方便使用可以配套安装Fluent参数化模块及可视化、后处理模块。利用下面的命令安装”pip install ansys-fluent-parametricpip install ansys-fluent-visualization这两个pyfluent的库相关文档可以访问参考资料[3]查询详细信息。2. 测试可以直接在Python中输入下面的命令也可以将其写入一个文档中再使用Python运行import ansys.fluent.core as pyfluentsolver_session pyfluent.launch_fluent(modesolver)print(solver_session.health_check_service.is_serving)测试对于Fluent 2023R1是没有问题的但对于老版本的Fluent 2022R2会报错。KeyError: AWP_ROOT231Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] on win32 Type help, copyright, credits or license for more information. import ansys.fluent.core as pyfluent solver_session pyfluent.launch_fluent(modesolver) Traceback (most recent call last): File stdin, line 1, in module File C:\Users\Ding\AppData\Local\Programs\Python\Python310\lib\site-packages\ansys\fluent\core\launcher\launcher.py, line 579, in launch_fluent launch_string _generate_launch_string( File C:\Users\Ding\AppData\Local\Programs\Python\Python310\lib\site-packages\ansys\fluent\core\launcher\launcher.py, line 421, in _generate_launch_string exe_path _get_fluent_exe_path(**argvals) File C:\Users\Ding\AppData\Local\Programs\Python\Python310\lib\site-packages\ansys\fluent\core\launcher\launcher.py, line 143, in _get_fluent_exe_path return get_exe_path() File C:\Users\Ding\AppData\Local\Programs\Python\Python310\lib\site-packages\ansys\fluent\core\launcher\launcher.py, line 128, in get_exe_path exe_path get_fluent_path() File C:\Users\Ding\AppData\Local\Programs\Python\Python310\lib\site-packages\ansys\fluent\core\launcher\launcher.py, line 122, in get_fluent_path path os.environ[AWP_ROOT .join(FLUENT_VERSION.split(.))[:-1]] File C:\Users\Ding\AppData\Local\Programs\Python\Python310\lib\os.py, line 679, in __getitem__ raise KeyError(key) from None KeyError: AWP_ROOT2313. 错误解决对于上述错误我们通过官方的GitHub 帮助可以发现是环境变量设置的不对但问题是我们安装好Fluent2022R2 的时候是自动设置了一个AWP_ROOT222的环境变量。3.1 解决方案1我们设置一个环境变量AWP_ROOT231值同样指向AWP_ROOT222的位置C:\Program Files\ANSYS Inc\v222。此时就可以通过测试了。3.2 解决方案2C:\Users\Ding\AppData\Local\Programs\Python\Python310\lib\site-packages\ansys\fluent\core\launcher\launcher.py我们直接打开pyfluent的launcher.py这个文件可以发现是通过 FLUENT_VERSION这个参数来获取fluent版本的从而去环境变量中找相关的路径。但在最新版pyfluent库中默认设置了:FLUENT_VERSION 23.1.0我们可以通过直接修改这个参数从而改变默认的fluent版本FLUENT_VERSION 22.2.0以及我们在launcher.py中发现了一个设置版本的函数def set_ansys_version(version: Union[str, float, FluentVersion]) - None: Set the Fluent version manually. This method only works if the provided Fluent version is installed and the environment variables are updated properly. This supersedes the Fluent path set in the environment variable. global FLUENT_VERSION FLUENT_VERSION str(FluentVersion(version))那么就可以通过这个函数来设置fluent版本import ansys.fluent.core as pyfluent pyfluent.set_ansys_version(22.2.0) solver_session pyfluent.launch_fluent(modesolver) solver_session.health_check_service.is_serving #注意新版本是solver_session.health_check.is_serving参考资料[1] CFD之道 pyFluent利用python控制Fluent[2] pyfluent github 仓库[3] pyANSYS
返回列表