1、ANSYS2次开发实例chm问:二次 开发 的例题 _chm?UPFE. 使用ANSYS列表命令列出ANSYS某一结果文件的内容;编译并连接ANSYS二进制文件读写程序BINTST.F,读写二进制文件并与列表方式相比较。1. 建立一个自己所熟悉的有限元模型,单元数35即可,加载、设置边界条件并求解6. 使用ANSYS列表命令Utility Menu-File-List-Binary File7. 在弹出的对话框中DUMP Records to be list中选ALL RecordsFORM Amt of output per record中选Entire RecordsFILEAUX2 bi
2、nary file to list中选择要显示的.rst文件按OK键确认后,可以得到.rst文件的列表窗口使用列表窗口的菜单保存列表窗口中的输出结果到文件list.txtFile-Save As8. 拷贝以下文件到工作目录D:usercopy c:ansys55custommiscintelbintst.f D:usercopy c:ansys55custommiscintelbintrd.f D:usercopy c:ansys55custommiscintelbintwr.f D:usercopy c:ansys55custommiscintelCustom.bat D:usercopy
3、c:ansys55custommiscintelMakefile D:usercopy c:ansys55custommiscintelbinlib.a9. 运行Custom.bat,编译并连接D:usercustom在工作目录中可生成一个运行程序bintst.exe10. 运行bintst.exeD:userbintst out.txt将bintst的运行结果转存到文件out.txt中比较out.txt 与list.txt文件中的结果,并参考手册Guide to interfacing to ANSYS中Format of Binary Data Files的Format of the Re
4、sults File分析文件结构。 E. 用户命令:编译并连接ANSYS提供的示例程序USER01.F;在ANSYS命令行中使用/UCMD给用户命令赋新的名称,并运行。1. 清理用户工作目录下的文件如果在用户工作目录下存在ANSYS二进制文件读取等程序,请全部删除2. 拷贝以下文件到用户工作目录D:usercopy c:ansys55customuserinteluser01.FD:usercopy c:ansys55customuserintelAnscust.batD:usercopy c:ansys55customuserintelMakefile1. 修改user01.F修改以下几行c
5、c *userS CODE IS INSERTED HERE * write (iott,2000)2000 format (/ *CALL TO ANSYS,INC DUMMY USER01*/)cc *do not return this result code in a real user routine user01 = -654321c *instead return a zero *c user01 = 0c为cc *userS CODE IS INSERTED HERE * write (iott,2000)2000 format (/ wby*CALL TO ANSYS,INC
6、 DUMMY USER01*/) c c *do not return this result code in a real userc 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_
7、dir)customlibintelsiappst.lib 3. 运行ANSCUST.BAT编译并连接忽略掉如下WARNING提示信息LINK : warning LNK4049: locally defined symbol _free importedLINK : warning LNK4049: locally defined symbol _malloc importedLINK : warning LNK4049: locally defined symbol _fflush importedLINK : warning LNK4049: locally defined symbol
8、 _fread importedLINK : warning LNK4049: locally defined symbol _fwrite importedLINK : warning LNK4049: locally defined symbol _ftell importedLINK : warning LNK4049: locally defined symbol _fseek imported当出现goto end时表明编译、连接完成,这时应该在用户工作目录下出现一个可执行程序ansys.exe,约为34MB 4. 运行编译连接生成的ANSYS在用户工作目录下D:useransys
9、-p ansysul或D:useransys55cust -custom .ansys.exe -p ansysul如果在其它目录下运行D:otherdirset path=c:ansys55binintelD:otherdiransys55cust -custom d:useransys.exe -p ansysul或D:otherdirset path=d:userD:otherdiransys -p ansysul5. 执行用户命令执行用户命令可以在字符界面下,也可在图形界面下在出现BEGIN:提示信息后,键入以下命令usr1或者输入以下命令进行到图形用户界面/show,win32/me
10、nu,on在工作站上的用户可以选择/show,x11/show,x11c/show,3D 详细说明可以参见ANSYS命令手册中关于/show的说明在输入框中,键入命令usr16. 用/UCMD命令自定义用户命令名在ANSYS BEGIN提示信息后/UCMD,aaa,1aaa E. 编译并连接ANSYS提供的示例程序USER03.F,使用动态数组保存有限元模型信息,如节点号、单元号、节点坐标、单元节点列表。使用UPF读写数据库子程序,读写模型中的有限元模型信息和载荷信息,并打印。以下是一个完整的程序,可由user03.F修改得到*deck,user03 user ANSYS,INCc sid 5
11、.1 copy of file s.user03.F last changed by jtm on 98/03/09 functionuser03 (intin,dpin,ch4in,ch8in)#include impcom.inc externalwrinqr,ndinqr,ndgxyz,ndnext,HeapAllocPtr, x HeapDealloc,erhandler integer wrinqr,ndinqr,ndgxyz,ndnext,HeapAllocPtr integer user03, intin(12), iott, i, ksel, xcptr, hXcptr, yc
12、ptr, x hYcptr, zcptr, hZcptr, ndptr, hNdptr, numnp, node double precisiondpin(12),xyz(3), xmean, ymean, zmean, stdxyz(3), x sodx, sody, sodz character*4ch4in(12) character*8ch8in(12)#include ansysdef.inc#include stack.inccc Get nodal xyz locations and calculate standard deviation ofc x coordinates,
13、y coordinates, & z coordinatescc get number of currently selected nodes numnp = ndinqr (0,DB_NUMSELECTED) if (numnp .le. 0) go to 999c allocate memory for x, y, & z coordinates of nodes xcptr = HeapAllocPtr(numnp,XCoords ,HEAP_DOUBLE,hXcptr) ycptr = HeapAllocPtr(numnp,YCoords ,HEAP_DOUBLE,hYcptr) zc
14、ptr = HeapAllocPtr(numnp,ZCoords ,HEAP_DOUBLE,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.0d010 node = ndnext(node) if (node .gt. 0) thenc get xyz coordinates ksel = ndgxyz (node,xyz(1)c store this
15、 nodes xyz coordinates dstack(xcptr + i) = xyz(1) dstack(ycptr + i) = xyz(2) dstack(zcptr + i) = xyz(3) istack(ndptr + i) = nodec while were looping, accumulate sums to calculate means xmean = xmean + xyz(1) ymean = ymean + xyz(2) zmean = zmean + xyz(3)c increment index i = i + 1c loop back up for n
16、ext selected node goto 10 endif call wrdisp (numnp, istack(ndptr+1)c node = 0, at the end of node listc calculate mean of xyz coordinates xmean = xmean / numnp ymean = ymean / numnp zmean = zmean / numnpc calculate standard deviation for xyz coordinates sodx = 0 sody = 0 sodz = 0 do i=1, numnp sodx
17、= 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) stdx
18、yz(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 releas
19、e dynamically allocated memory call HeapDealloc(hXcptr) call HeapDealloc(hYcptr) call HeapDealloc(hZcptr) call HeapDealloc(hNdptr)c *required return value*999user03 = 0 return end subroutine wrdisp (nnod, nodes)#include impcom.inc#include ansysdef.inc integer nnod, nodes(nnod) external wrinqr, disge
20、t integer wrinqr, disget integer iott,i,rc,k double precision value(4) iott = wrinqr(WR_OUTPUT) do i=1,nnod rc = disget(nodes(i), 1, value(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), (value(k), k=1,4)1010 for
21、mat (Nodes=,i3, UX=,4(F8.2,) endif enddo return end将上面程序编译并连接,启动ANSYS,并输入下面的命令流,观察OUTPUT窗口的输出信息/prep7blc4,0,0,4,2et,1,42esize,.5amesh,1nsel,s,loc,x,4d,all,ux,8nsel,s,loc,x,0d,all,ux,-9nsel,allusr3E. 使用ANSYS提供子程序试验矢量与矩阵的操作 以下是一个完整的程序用来说明矢量矩阵操作c=a*deck,user01 user parallel ANSYS,INC functionuser01 (in
22、tin,dpin,ch4in,ch8in)#include impcom.inc externalwrinqr integer wrinqr integeruser01,intin(12), iott double precisiondpin(12) character*4ch4in(12) character*8ch8in(12)c double 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(
23、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) enddo100 format (F9.2, 3x)101 format (3(F9.2, 3x) user01
24、 = 0c return endE. 用户自定义材料1. 拷贝相关文件D:usercopy c:ansys55customuserinteluserpl.F2. 运行编译连接(参见用户命令)3. 启动ANSYS(参见用户命令)D:useransys55cust -custom .ansys.exe -p ansysul4. 编辑命令流文件a.datD:useredit a.dat/PREP7et,1,42mp,ex,1,2e6mp,nuxy,1,.3r,1,100,0tb,user,1tbdata,1,100,2e3blc4,0,0,4,2esize,.5type,1mat,1real,1am
25、esh,1nsel,s,loc,x,0d,all,all,0nsel,s,loc,x,4nsel,r,loc,y,0f,all,fy,-1000nsel,all/soluantype,statictime,1solve5. 启动ANSYS(参见用户命令)D:useransys55cust -custom .ansys.exe -p ansysul6. 输入a.dat,记录结果/input,a,datE. 用户单元1. 拷贝相关文件D:usercopy c:ansys55customuserinteluec101.FD:usercopy c:ansys55customuserinteluel101.F2. 编辑uel101.F将下面的程序段c call TrackBegin (uel101)cc - define initial datac - elmdat pointers defined in elparm mat = elmdat(PMAT)修改为:c call TrackBegin (uel101) iott=wrinqr(2) write (iott, *) In user element,elemcc - define initial datac - elmd
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1