Python-Fluent coupled simulation:
Python equals to a client(客户端), and Fluent equals to a server( 服务器 ), combined as a CS model.
First define the working directory of the fluent. *Note the working directory should include the *.msh and *.py file.
Launch the Fluent as a server. FLUENT_AAS=1&OK
Then, the three .txt files are generated automatically in the working directory.
ICoFluentUnit provide a set of functions: load and save case or data, set iterations, calculate and so on.
————————————————
Python
import time
import pathlib
import os
import sys
import io
from fluent_corba import CORBA
import AAS_CORBA #import the AAS_CORBA module compiled from CoFluentUnit.idl
import subprocess
from functools import partial
Matlab
orb=initialize_orb();
load_ansys_aas;
FluetnPath = 'Your own fluent work path';
aaS_Path = char(FluetnPath+"aaS_FluentId.txt");
ICoFluentUnit = actfluentserver(orb,aaS_Path);
iFluentTuiInterpreter = ICoFluentUnit.getSchemeControllerInstance();
ICoFluentUnit.loadCase('XX.cas');
iFluentTuiInterpreter.doMenuCommand('/display/mesh');
% 任务1、获取流体力
fileId = fopen(FluetnPath+"force.txt", 'r');
[force, count] = fscanf(fileId, '%f') ;
fclose(fileId);
% 任务2、运动方程求解位移
[vel_n, dis_n] = calculate_y_motion(force(end), vel, dis);
dis_history = [dis_history,dis_n];
% 任务3、将位移传递到fluent中进行迭代求解
set_dis_commnd = strcat("(rpsetvar 'vel_n ", num2str(vel_n), ").");
iFluentTuiInterpreter.execScheme(set_dis_commnd)
————————————————
此代码为CSDN博主「小碗拉面不加香菜~」原文链接:https://blog.csdn.net/weixin_42130488/article/details/122920156
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删