前段时间找了点Matlab与ANSYS协同工作的资料,在我看来所谓协同是ANSYS将结果写到文件然后Matlab读,或者Matlab写数据到文件ANSYS读,协同是通过读写文件实现的。我找了个瞬态分析的例子,写了APDL,将网上找到的ANSYS结果输出部分代码加了进来,实现三个节点位移时间数据写到文件,然后Matlab读取该文件并作三节点位移-时间图。说明一下:ANSYS生成的文件都在Matlab当前工作目录下。
1 Matlab的代码(mat2ans.m)
!“D:\Program Files (x86)\Ansys Inc\v100\ANSYS\bin\intel\ansys100.exe” -b -i “E:\WP\m2a\transient.mac” -o “E:\WP\m2a\ans.out”
%save(‘E:\WP\m2a\matdat.dat’,‘data’,’-ascii’)
%load(’-ascii’,‘E:\WP\m2a\ans.rst’)
load ‘result1.txt’
t=result1(:,1);
u1=result1(:,2)*1e3;
u2=result1(:,3)*1e3;
u3=result1(:,4)*1e3;
plot(t,u1,‘k’,t,u2,‘c’,t,u3,‘g’)
legend(‘Node 100’,‘Node 146’,‘Node 200’)
xlabel(‘time/s’),ylabel(‘disp/mm’)
2 ANSYS APDL代码(transient.mac)
finish
/cwd,‘E:\WP\M2A\ans2mat’
/filename,ansys2matlab
/title,ansys result output formatted
/units,SI
/prep7
et,1,shell63
et,2,beam4
r,1,0.02
r,2,2e-4,2e-8,2e-8,0.01,0.02
mp,ex,1,2e11
mp,prxy,1,0.3
mp,dens,1,7.83e3
rectng,0,2,0,1
kgen,2,1,4,1,-1
do,i,1,4,1
l,i,i+4
enddo
lsel,all
lesize,all,0.1
asel,all
amesh,1
mat,1
real,2
lmesh,5,8,1
fini
!
/output,cp,out!Output Info to cp.out
/debug,-1,1 !element mass & stiff matrix
!
/solu
antype,trans
alphad,5
!dkdele,all,all
ksel,s,kp,5,8,1
dk,all,all
allsel
sbctran
outres,all,all
!
time,1
autots,on
deltim,0.2,0.05,0.5,1
kbc,0
sfa,1,1,pres,10000
lswrite,1
!
time,2
lswrite,2
!
time,4
kbc,1
sfa,1,1,pres,5000
lswrite,3
!
time,6
sfa,1,1,pres,0
lswrite,4
allsel
lssolve,1,4,1
!
fini
!*
/output,term !To output window
/post1
!file,ansys2matlab,rst !结果文件
set,last
*GET,N_SET,ACTIVE,0,SET,NSET
!n_set=5
*DIM,NODES,ARRAY,3
*DIM,TIMES,ARRAY,N_SET
*DIM,RESULT,ARRAY,3,N_SET
NODES(1)=100,146,200
*DO,I,1,N_SET,1
SET,I
*GET,TI,ACTIVE,0,SET,TIME
TIMES(I)=TI
*DO,J,1,3,1
*GET,RESULT(J,I),NODE,NODES(J),U,Z
*ENDDO
*ENDDO
*cfopen,result1,txt
!*vwrite
!(’ ')
!*vwrite,nodes(1),nodes(2),nodes(3)
!(‘Time Node’,f9.0,2f15.0)
*do,i,1,N_SET
*vwrite,times(i),result(1,i),result(2,i),result(3,i)
(f8.5,8x,3f15.10)
*enddo
*cfclose
fini
!*
!dump a matrix
!/aux2
!fileaux2,ansys2matlab,emat
!form,long
!dump,all
!*
3 运行过程概括
执行Matlab的mat2ans.m,由于第一条命令启动ANSYS,控制权由Matlab交给ANSYS,ANSYS以批处理执行transient.mac的APDL代码,并生成想要的结果文件result1.txt然后自动退出,Matlab得到控制权接着执行余下的命令。
matlab/ansys协同的一个例子
4 结果展示
4.1 有限元模型位移图
matlab/ansys协同的一个例子
4.2 ANSYS作三节点位移-时间曲线
matlab/ansys协同的一个例子
4.3 Matlab作三节点位移-时间曲线
matlab/ansys协同的一个例子http://blog.sina.com.cn/s/blog_c0d2007a0102vhf2.html
</div><link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet"><div class="more-toolbox"><div class="left-toolbox"><ul class="toolbox-list"><li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true"><use xlink:href="#csdnc-thumbsup"></use></svg><span class="name">点赞</span><span class="count"></span></a></li><li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-csdnc-Collection-G"></use></svg><span class="name">收藏</span></a></li><li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-csdnc-fenxiang"></use></svg>分享</a></li><!--打赏开始--><!--打赏结束--><li class="tool-item tool-more"><a><svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg></a><ul class="more-box"><li class="item"><a class="article-report">文章举报</a></li></ul></li></ul></div></div><div class="person-messagebox"><div class="left-message"><a href="https://blog.csdn.net/qq_33588707"><img src="https://profile.csdnimg.cn/F/A/8/3_qq_33588707" class="avatar_pic" username="qq_33588707"><img src="https://g.csdnimg.cn/static/user-reg-year/1x/4.png" class="user-years"></a></div><div class="middle-message"><div class="title"><span class="tit"><a href="https://blog.csdn.net/qq_33588707" data-report-click="{"mod":"popu_379"}" target="_blank">小黄三爷</a></span></div><div class="text"><span>发布了3 篇原创文章</span> · <span>获赞 2</span> · <span>访问量 2143</span></div></div><div class="right-message"><a href="https://im.csdn.net/im/main.html?userName=qq_33588707" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信</a><a class="btn btn-sm bt-button personal-watch" data-report-click="{"mod":"popu_379"}">关注</a></div></div></div>@[TOC](这里写自定义目录标题)