我想看一级黄色大片_久久亚洲国产精品一区二区_久久精品免视看国产明星_91久久青青青国产免费

您的位置:網站首頁 > Ansys教程

ANSYS二次開發培訓練習題

時間:2010-11-14 11:11:38 來源:未知

UIDL

E.使用UIDL在ANSYS主菜單中增加一個菜單項,點擊后可以出現一個子菜單或激活一個對話框。

  

APDL

E. 使用APDL編制一個可以讀寫有限元模型的小程序,要求讀出所有節點號和單元號,節點坐標以及單元節點列表。

E. 使用DNSOL,DESOL定義計算結果

  

UPF

E. 使用ANSYS列表命令列出ANSYS某一結果文件的內容;編譯并連接ANSYS二進制文件讀寫程序BINTST.F,讀寫二進制文件并與列表方式相比較。

E. 編譯并連接ANSYS提供的示例程序USER01.F;在ANSYS命令行中使用/ MD給用戶命令賦新的名稱,并運行。

E. 編譯并連接ANSYS提供的示例程序USER03.F,使用動態數組保存有限元模型信息,如節點號、單元號、節點坐標、單元節點列表。使用UPF讀寫數據庫子程序,讀寫模型中的有限元模型信息和載荷信息,并打印。

E. 使用ANSYS提供子程序試驗矢量與矩陣的操作

E. 試驗用戶自定義材料

E. 試驗用戶單元

E. 使用/DEBUG命令調試ANSYS單元矩陣及載荷矢量

  

練習題答案:

說明:

1.  以下練習答案以ANSYS 5.5.1 UP199810001 Windows 95/98/NT的University Low版本(產品號為ansysul)為例,其它版本與此類似。

2.  假定機器中已經安裝了Digital Vis l Fortran 5.0C以上的版本 假設ANSYS安裝目錄為C:ANSYS55

3.  假設用戶工作目錄為D:user

4.  約定

DOS提示  D:user>

DOS輸入  copy c:ansys55docuUIFUNC2.GRN

ANSYS輸入框  ET,1,42

數據文件  :N Men_Training

  

UIDL E. 使用UIDL在ANSYS主菜單中增加一個菜單項,點擊后可以出現一個子菜單或激活一個對話框。 A.

1.  拷貝文件

D:user>copy c:ansys55documenulist55.ans

D:user>copy c:ansys55docuUIMENU.GRN

D:user>copy c:ansys55docuUIFUNC1.GRN

D:user>copy c:ansys55docuUIFUNC2.GRN

2.  在主菜單中加入自定義菜單項

D:user>edit UIMENU.GRN

在第4780應為

:A Main Menu

在第4803行插入以下幾行:

Men_Training

Sep_

所得到的結果如下:

Men_Aux12

Men_RunStat

K_LN(BETA)

Sep_

K_LN(BETA)

Fnc_UNDO

Sep_

Men_Training

Sep_

Fnc_FINISH

將光標移至第4812行,插入以下一段

:!

:N Men_Training

:S    413,    76,   330

:T Menu

:A Training Menu

:D ANSYS Training MENU

Fnc_Training

:E END

:!

刪除該行

:X INDEX ADDED BY ANSYS

以后的全部行

存盤退出

3.  編輯新的菜單文件

D:user>edit newmenu.grn

鍵入以下文字

:F UIMENU.GRN

:D Modified on 98/10/01, Revision (SID) = 5.181.1.68 - For use with ANSYS 5.5

:I      1,     759,     809

:!  

:N Fnc_Training

:S    627,   449,   170

:T Command

:A ANSYS Customizing Training  

:D Training Exercises

:C )*GET,_z1,ACTIVE,,TITLE,,START,1

:C )*GET,_z2,ACTIVE,,TITLE,,START,9

:C )*GET,_z3,ACTIVE,,TITLE,,START,17

:C )*GET,_z4,ACTIVE,,TITLE,,START,25

:C )*GET,_z5,ACTIVE,,TITLE,,START,33

:C )*GET,_z6,ACTIVE,,TITLE,,START,41

:C )*GET,_z7,ACTIVE,,TITLE,,START,49

:C )*GET,_z8,ACTIVE,,TITLE,,START,57

:C )*GET,_z9,ACTIVE,,TITLE,,START,65

Fmt_H

Inp_NoApply

Cmd_)/NOPR

Cmd_)/TITLE

Fld_2  

   Prm_[/TITLE] Welcome to ANSYS Training  

   Typ_Char,72,72

   Prm_[/TITLE] Welcome to ANSYS Training  

Cmd_)/Go

:E END

:!

存盤退出

4.  修改menulist55.ans文件

D:user>edit menulist55.ans

修改文件的前三行,使其指向用戶工作目錄下的文件

d:userUIMENU.GRN

d:userUIFUNC1.GRN

d:userUIFUNC2.GRN

d:usernewmenu.grn

c:ansys55DOCUUICMDS.HLP

c:ansys55DOCUUIELEM.HLP

c:ansys55DOCUUIGUID.HLP

c:ansys55DOCUUITHRY.HLP

c:ansys55DOCUUIOTHR.HLP

5.  啟動ANSYS的launcher

在Working Directory框中鍵入

d:user

按OK鍵,啟動ANSYS界面

  

APDL E. 使用APDL編制一個可以讀寫有限元模型的小程序,要求讀出所有節點號和單元號,節點坐標以及單元節點列表。

A.

1.  編輯文件a.dat

D:user>edit a.dat

*Get,nnod,NODE,0,COUNT

  

*Dim,xy,array,nnod,2

*Dim,nodes,array,nnod

  

*Get,nd,NODE,0,NUM,MIN

*Do,I,1,nnod,1

   nodes(I)= nd

   xy(I,1) = Nx(nd)

   xy(I,2) = Ny(nd)

   nd = Ndnext(nd)

*Enddo

  

*Get,nelm,ELEM,0,COUNT

  

*Dim,elems,array,nelm

*Dim,ndlst,array,nelm,4

  

*Get,el,ELEM,0,NUM,MIN

*Do,I,1,nelm,1

   elems(I)= el

   *Do,J,1,4

      ndlst(I,J) = Nelem(el,J)

   *Enddo

   el = Elnext(nd)

*Enddo

2.  啟動ANSYS,根據自己所熟悉的領域,建立一個有限元模型

3.  輸入文件a.dat

/input,a,dat

4.  檢查

分別列出節點數,節點號列表,坐標,單元數,單元號列表,單元節點列表,與nlist,elist等對比。

*status,nnod

*status,nodes

*status,xy

*status,nelm

*status,elems

*status,ndlst

  

E. 使用DNSOL,DESOL定義計算結果

1. 利用前面所建立或新建一個有限元模型  

2. 進入Post-processor  

/post26  

或  

Main Menu->General Postproc  

3.定義節點上的結果 手工定義 ->Nodal Results按對話框提示輸入各點的結果數據 程序自動定義

/PREP7   BLC4,0,0,4,2 et,1,42  esize,.5 amesh,1   

/POST1 dof,temp *Get,nnod,NODE,0,COUNT  

*Dim,xy,array,nnod,2 *Dim,nodes,array,nnod *Get,nd,NODE,0,NUM,MIN  

*Do,I,1,nnod,1    nodes(I)= nd    xy(I,1) = Nx(nd)    xy(I,2) = Ny(nd)    nd = Ndnext(nd) *Enddo  

*Do,i,1,nnod,1  

   dist = sqrt((xy(i,1)-2)*(xy(i,1)-2)+(xy(i,2)-1)*(xy(i,2)-1))    tmp = dist*100     Dnsol,nodes(i),temp,,tmp *Enddo  

nsel,all plnsol,temp  

UPF

E. 使用ANSYS列表命令列出ANSYS某一結果文件的內容;編譯并連接ANSYS二進制文件讀寫程序BINTST.F,讀寫二進制文件并與列表方式相比較。

1.  建立一個自己所熟悉的有限元模型,單元數3~5即可,加載、設置邊界條件并求解

6.  使用ANSYS列表命令

Utility Menu->File->List->Binary File

7.  在彈出的對話框中

[DUMP] Records to be list中選ALL Records

[FORM] Amt of output per record中選Entire Records

[FILEAUX2] binary file to list中選擇要顯示的.rst文件

按OK鍵確認后,可以得到.rst文件的列表窗口

使用列表窗口的菜單保存列表窗口中的輸出結果到文件list.txt

File->Save As

8.  拷貝以下文件到工作目錄

D:user>copy c:ansys55custommiscintelbintst.f D:user>copy c:ansys55custommiscintelbintrd.f D:user>copy c:ansys55custommiscintelbintwr.f D:user>copy c:ansys55custommiscintelCustom.bat D:user>copy c:ansys55custommiscintelMakefile D:user>copy c:ansys55custommiscintelbinlib.a

9.  運行Custom.bat,編譯并連接

D:user>custom

在工作目錄中可生成一個運行程序bintst.exe

10.  運行bintst.exe

D:user>bintst > out.txt

將bintst的運行結果轉存到文件out.txt中

比較out.txt 與list.txt文件中的結果,并參考手冊Guide to interfacing to ANSYS中Format of Binary Data Files的Format of the Results File分析文件結構。  

E. 用戶命令:編譯并連接ANSYS提供的示例程序USER01.F;在ANSYS命令行中使用/ MD給用戶命令賦新的名稱,并運行。

1.  清理用戶工作目錄下的文件

如果在用戶工作目錄下存在ANSYS二進制文件讀取等程序,請全部刪除

2.  拷貝以下文件到用戶工作目錄

D:user>copy c:ansys55customuserinteluser01.F

D:user>copy c:ansys55customuserintelAnscust.bat

D:user>copy c:ansys55customuserintelMakefile

1.  修改user01.F

修改以下幾行

c

c          *****  user'S CODE IS INSERTED HERE *****

      write (iott,2000)

  2000 format (//' *****  CALL TO ANSYS,INC DUMMY USER01  *****'//)

c

c          *****  do not return this result code in a real user routine

      user01 = -654321

c         *****  instead return a zero   *****

c     user01 = 0

c

c

c          *****  user'S CODE IS INSERTED HERE *****       write (iott,2000)  2000 format (//' wby***  CALL TO ANSYS,INC DUMMY USER01  *****'//) c c          *****  do not return this result code in a real user   

c      user01 = -654321 c         *****  instead return a zero   *****       user01 = 0 c

  在format語句中增加的字符是為了在ANSYS運行時表明user01.F確實是自己修改過的版本

將user01的值設成0,是為了使ANSYS給出正確信息,而不是警告  

2.  修改Makefile

修改ansys55_dir的值使其指向ANSYS主目錄

ansys55_dir=C:ansys55

修改下面這一行

            siappst.lib     

$(ansys55_dir)customlibintelsiappst.lib     

  

3.  運行ANSCUST.BAT編譯并連接

忽略掉如下WARNING提示信息

LINK : warning LNK4049: locally defined symbol "_free" imported

LINK : warning LNK4049: locally defined symbol "_malloc" imported

LINK : warning LNK4049: locally defined symbol "_fflush" imported

LINK : warning LNK4049: locally defined symbol "_fread" imported

LINK : warning LNK4049: locally defined symbol "_fwrite" imported

LINK : warning LNK4049: locally defined symbol "_ftell" imported

LINK : warning LNK4049: locally defined symbol "_fseek" imported

當出現goto end時表明編譯、連接完成,這時應該在用戶工作目錄下出現一個可執行程序ansys.exe,約為34MB  

4.  運行編譯連接生成的ANSYS

在用戶工作目錄下

D:user>ansys -p ansysul

D:user>ansys55cust -custom .ansys.exe -p ansysul

如果在其它目錄下運行

D:otherdir>set path=c:ansys55binintel

D:otherdir>ansys55cust -custom d:useransys.exe -p ansysul

D:otherdir>set path=d:user

D:otherdir>ansys -p ansysul

  

5.  執行用戶命令

執行用戶命令可以在字符界面下,也可在圖形界面下

在出現

BEGIN:

提示信息后,鍵入以下命令

usr1

或者輸入以下命令進行到圖形用戶界面

/show,win32

/menu,on

在工作站上的用戶可以選擇

/show,x11

/show,x11c

/show,3D 詳細說明可以參見ANSYS命令手冊中關于/show的說明

  

在輸入框中,鍵入命令

usr1

  

6.  用/ MD命令自定義用戶命令名

在ANSYS BEGIN提示信息后

/ MD,aaa,1

aaa  

E. 編譯并連接ANSYS提供的示例程序USER03.F,使用動態數組保存有限元模型信息,如節點號、單元號、節點坐標、單元節點列表。使用UPF讀寫數據庫子程序,讀寫模型中的有限元模型信息和載荷信息,并打印。

以下是一個完整的程序,可由user03.F修改得到

*deck,user03           user                                             ANSYS,INC

c sid 5.1 copy of file s.user03.F last changed by jtm on 98/03/09

      function  user03 (intin,dpin,ch4in,ch8in)

#incl? "impcom.inc"

      external  wrinqr,ndinqr,ndgxyz,ndnext,HeapAllocPtr,

     x          HeapDealloc,erhandler

      integer   wrinqr,ndinqr,ndgxyz,ndnext,HeapAllocPtr

  

      integer   user03, intin(12), iott, i, ksel, xcptr, hXcptr, ycptr,  

     x          hYcptr, zcptr, hZcptr, ndptr, hNdptr, numnp, node

      do le precision  dpin(12),xyz(3), xmean, ymean, zmean, stdxyz(3),

     x          sodx, sody, sodz

      character*4  ch4in(12)

      character*8  ch8in(12)

  

#incl? "ansysdef.inc"

#incl? "stack.inc"

  

c

c     Get nodal xyz locations and calculate standard deviation of

c     x coordinates, y coordinates, & z coordinates

c

  

c     get number of currently selected nodes

      numnp = ndinqr (0,DB_NUMSELECTED)

  

      if (numnp .le. 0) go to 999

  

c     allocate memory for x, y, & z coordinates of nodes

      xcptr = HeapAllocPtr(numnp,'XCoords ',HEAP_DO LE,hXcptr)

      ycptr = HeapAllocPtr(numnp,'YCoords ',HEAP_DO LE,hYcptr)

      zcptr = HeapAllocPtr(numnp,'ZCoords ',HEAP_DO LE,hZcptr)

      ndptr = HEapAllocPtr(numnp,'Nodes   ',HEAP_INTEGER,hNdptr)

  

c     loop through all selected nodes

      i=1

      node = 0

      xmean = 0.0d0

      ymean = 0.0d0

      zmean = 0.0d0

  10   node = ndnext(node)

  

      if (node .gt. 0) then

  

c         get xyz coordinates

          ksel = ndgxyz (node,xyz(1))

  

c         store this node's xyz coordinates

          dstack(xcptr + i) = xyz(1)

          dstack(ycptr + i) = xyz(2)

          dstack(zcptr + i) = xyz(3)

          istack(ndptr + i) = node

  

c         while we're looping, accumulate sums to calculate means

          xmean = xmean + xyz(1)

          ymean = ymean + xyz(2)

          zmean = zmean + xyz(3)

  

c         increment index

          i = i + 1

  

c         loop back up for next selected node

          goto 10

  

      endif

  

      call wrdisp (numnp, istack(ndptr+1))

  

c     node = 0, at the end of node list

  

c     calculate mean of xyz coordinates

      xmean = xmean / numnp

      ymean = ymean / numnp

      zmean = zmean / numnp

  

c     calculate standard deviation for xyz coordinates

      sodx = 0

      sody = 0

      sodz = 0

      do i=1, numnp

         sodx = sodx + (dstack(xcptr+i) - xmean)**2

         sody = sody + (dstack(ycptr+i) - ymean)**2

         sodz = sodz + (dstack(zcptr+i) - zmean)**2

      enddo

  

      stdxyz(1) = sqrt(sodx / (numnp-1))

      stdxyz(2) = sqrt(sody / (numnp-1))

      stdxyz(3) = sqrt(sodz / (numnp-1))

  

c     *****  write to output file  *****

      iott = wrinqr(WR_OUTPUT)

      write (iott,2000) stdxyz(1),stdxyz(2),stdxyz(3)

  2000 format (/' STD FOR X COORDINATES:',G12.5,/,

     X         ' STD FOR Y COORDINATES:',G12.5,/,

     X         ' STD FOR Z COORDINATES:',G12.5)

  

c     *****  write to GUI window  *****

      call erhandler ('user03',5000,2,

     x 'STD FOR X COORDINATES: %G %/ STD FOR Y  

     x COORDINATES: %G %/ STD FOR Z COORDINATES: %G',stdxyz(1),' ')

  

c     release dynamically allocated memory

      call HeapDealloc(hXcptr)

      call HeapDealloc(hYcptr)

      call HeapDealloc(hZcptr)

      call HeapDealloc(hNdptr)

  

c     *****  required return val  *****

  999  user03 = 0

  

      return

      end

  

      s routine wrdisp (nnod, nodes)

#incl? "impcom.inc"

#incl? "ansysdef.inc"

      integer nnod, nodes(nnod)

  

      external wrinqr, disget

      integer wrinqr, disget

  

      integer iott,i,rc,k

      do le precision val(4)

  

      iott = wrinqr(WR_OUTPUT)

      do i=1,nnod

         rc = disget(nodes(i), 1, val(1))

         if (rc .eq. 0) then

            write (iott,1000) nodes(i)

  1000      format ('Nodes=',i3,'   No x displacement constraint')

         else

            write (iott,1010) nodes(i), (val(k), k=1,4)

  1010      format ('Nodes=',i3,'   UX=',4(F8.2,','))

         endif

      enddo

  

      return

      end

將上面程序編譯并連接,

啟動ANSYS,并輸入下面的命令流,觀察OUTPUT窗口的輸出信息

/prep7

blc4,0,0,4,2

et,1,42

esize,.5

amesh,1

nsel,s,loc,x,4

d,all,ux,8

nsel,s,loc,x,0

d,all,ux,-9

nsel,all

usr3

  

E. 使用ANSYS提供子程序試驗矢量與矩陣的操作

   以下是一個完整的程序用來說明矢量矩陣操作{c}={a}

*deck,user01           user   parallel                                ANSYS,INC

      function  user01 (intin,dpin,ch4in,ch8in)

#incl? "impcom.inc"

  

      external  wrinqr

      integer   wrinqr

  

      integer  user01,intin(12), iott

      do le precision  dpin(12)

      character*4  ch4in(12)

      character*8  ch8in(12)

c

      do le precision a(3), b(4,3), c(4)

      integer i,j,k

      data a /5,6,7/

      data b /3,3,9,8, 4,7,4,3, 5,9,5,2/

  

      iott = wrinqr(2)

  

      call vzero (c(1), 4)

      write (iott, *) '*** matrix b ='

      do i=1,4

         write (iott, 101) (b(i,k), k=1,3)

      enddo

      write (iott, *) '*** vector a='

      do i=1,3

         write (iott, 100) a(i)

      enddo

      call maxv(b(1,1),a(1),c(1), 4,3)

      write (iott, *) '*** vector c='

      do i=1,4

         write (iott, 100) c(i)

      enddo

  100 format (F9.2, 3x)

  101 format (3(F9.2, 3x))

      user01 = 0

c

      return

      end

  

E. 用戶自定義材料

1.  拷貝相關文件

D:user>copy c:ansys55customuserinteluserpl.F

2.  運行編譯連接(參見用戶命令)

3.  啟動ANSYS(參見用戶命令)

D:user>ansys55cust -custom .ansys.exe -p ansysul

4.  編輯命令流文件a.dat

D:user>edit a.dat

/PREP7   

et,1,42

mp,ex,1,2e6

mp,nuxy,1,.3

r,1,100,0

tb,user,1

tbdata,1,100,2e3

  

blc4,0,0,4,2

esize,.5

type,1

mat,1

real,1

amesh,1

  

nsel,s,loc,x,0

d,all,all,0

nsel,s,loc,x,4

nsel,r,loc,y,0

f,all,fy,-1000

nsel,all

  

/solu

antype,static

  

time,1

solve

5.  啟動ANSYS(參見用戶命令)

D:user>ansys55cust -custom .ansys.exe -p ansysul

6.  輸入a.dat,記錄結果

/input,a,dat

  

E. 用戶單元

1.  拷貝相關文件

D:user>copy c:ansys55customuserintelc101.F

D:user>copy c:ansys55customuserintell101.F

2.  編輯l101.F

將下面的程序段

c

      call TrackBegin ('l101')

c

c --- define initial data

c     --- elmdat pointers defined in elparm

      mat = elmdat(PMAT)

修改為:

c

      call TrackBegin ('l101')

      iott=wrinqr(2)

      write (iott, *) 'In user element',elem

c

c --- define initial data

c     --- elmdat pointers defined in elparm

      mat = elmdat(PMAT)

3.  運行編譯連接(參見用戶命令)

4.  編輯命令流文件a.dat

D:user>edit a.dat

/PREP7   

et,1,USER101

mp,ex,1,2e6

mp,nuxy,1,.3

r,1,100,0

  

k

k,,100,0

l,1,2

esize,10

type,1

mat,1

real,1

lmesh,1

  

nsel,s,loc,x,0

d,all,all,0

nsel,s,loc,x,100

f,all,fx,1000

nsel,all

  

/solu

antype,static

  

time,1

solve

5.  啟動ANSYS(參見用戶命令)

D:user>ansys55cust -custom .ansys.exe -p ansysul

6.  輸入a.dat,注意OUTPUT窗口中打印出來的信息,記錄結果

/input,a,dat

7.  修改命令流文件a.dat,將單元類型換成LINK8,重新分析,并與LINK8對比

D:user>edit a.dat

/PREP7   

et,1,LINK8

mp,ex,1,2e6

  

E. 使用/DEBUG命令調試ANSYS單元矩陣及載荷矢量

1.  在ANSYS中以自己最熟悉的單元建立一個有限元模型,然后加載荷、邊界條件,設定求解參數,如Time, Deltime等

2.  在ANSYS Input Box框中輸入以下命令

/DEBUG,-3,,,1

3.  求解,鍵入求解命令

SOLVE

4.  觀察OUTPUT窗口的輸出