matlab/ansys協同的一個例子

前段時間找了點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="{&quot;mod&quot;:&quot;popu_824&quot;}"><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="{&quot;mod&quot;:&quot;popu_379&quot;}" 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="{&quot;mod&quot;:&quot;popu_379&quot;}">關注</a>
                                </div>
                        </div>
                </div>@[TOC](這裏寫自定義目錄標題)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章