FLAC3D 6.0/7.0 代码转换tecplot文件

在flac3d 6.0/7.0里面打开sav文件,并运行以下代码即可在相应文件夹下生成tecplot文件,再根据往期教程在tecplot里面处理云图及等值线。

fish automatic-create on
;set fish sa off
program echo off
program	log off	
def ini_Flac2tec
    global IO_READ  = 0;
    global IO_WRITE = 1;To overwrite the exist file
    global IO_ASCII = 1;To write the file in ASCII format
    global N_RECORD = 10;MODIFY to set the figure count of each line
	global i=0;To control the loop
	global j=0;To mark the new indices of Nodes
    array my_Point(8)
    array buf(1)
	global ScaleFactor = 0;MODIFY to scale the transform
    global tec_file = 'FLAC3DMesh_deformation.dat';To define the write file name
	command;create an output range with the name writeRange
		;MODIFY the group to define the range to deal with,Default the whole file,DON'T USE group XX not
		model range create 'writeRange';group v_fgc any group v_jy any group v_rtjc any
	endcommand
end;End of ini_Flac2tec
@ini_Flac2tec
;;
;;Write Tecplot File Head
def write_FileHead
	local p_gp=gp.head
	i=0
	loop while p_gp # null
		if range.isin('writeRange',p_gp) = 1  then
			i=i+1
		endif
		p_gp = gp.next(p_gp);next grid point
	endloop
	local p_z=zone.head
	j=0
	loop while p_z # null
		if range.isin('writeRange',p_z) = 1  then
		if zone.model(p_z) # 'NULL' then
			j=j+1
		endif
		endif
		p_z = z.next(p_z);next zone
	endloop
    buf(1) =          ' \n'
    buf(1) = buf(1) + 'VARIABLES = "X" "Y" "Z" "DISP" "XDISP" "YDISP" "ZDISP" "SXX" "SYY" "SZZ" "Sig1" "Sig2" "Sig3"\n'
    buf(1) = buf(1) + 'ZONE T="FLAC3D Data" \n'
    buf(1) = buf(1) + 'N='+string(i)+','+'E='+string(j)+','+'ZONETYPE=FEBrick '
	buf(1) = buf(1) + 'DATAPACKING=block\n'+'VARLOCATION=([8-13]=CELLCENTERED)\n'
    buf(1) = buf(1) + 'DT=(SINGLE SINGLE SINGLE SINGLE SINGLE SINGLE SINGLE SINGLE SINGLE SINGLE SINGLE SINGLE SINGLE)'
    status = file.write(buf,1)
    ii=io.out('File Head has been written!')
end;End of write_FileHead
;;
;;Write Nodes' Coordinates X Y Z
def write_node
    ;Write x position  
    p_gp = gp.head
    loop while p_gp # null
		buf(1)=''
		n=1
		loop while n <= N_RECORD
			if p_gp # null then
				if range.isin('writeRange',p_gp) = 1  then
					buf(1) = buf(1)+string(gp.pos.x(p_gp)+gp.disp.x(p_gp)*ScaleFactor)+ '  '
					n=n+1
				endif
				p_gp = gp.next(p_gp)
			else
				n=N_RECORD+1
			endif
		endloop
		status = file.write(buf,1)
    endloop
	;
	;Write y position  
    p_gp = gp.head
    loop while p_gp # null
		buf(1)=''
		n=1
		loop while n <= N_RECORD
			if p_gp # null then
				if range.isin('writeRange',p_gp) = 1  then
					buf(1) = buf(1)+string(gp.pos.y(p_gp)+gp.disp.y(p_gp)*ScaleFactor)+ '  '
					n=n+1
				endif
				p_gp = gp.next(p_gp)
			else
				n=N_RECORD+1
			endif
		endloop
		status = file.write(buf,1)
    endloop
	; 
	;Write z position  
    p_gp = gp.head
    loop while p_gp # null
		buf(1)=''
		n=1
		loop while n <= N_RECORD
			if p_gp # null then
				if range.isin('writeRange',p_gp) = 1  then
					buf(1) = buf(1)+string(gp.pos.z(p_gp)+gp.disp.z(p_gp)*ScaleFactor)+ '  '
					n=n+1
				endif
				p_gp = gp.next(p_gp)
			else
				n=N_RECORD+1
			endif
		endloop
		status = file.write(buf,1)
    endloop
ii=io.out('Node coordinations have been written!')
end;End of write_node
;;
;;Write the data on Node
def write_nodeData
	;Write total displacement
	p_gp = gp.head
    loop while p_gp # null
		buf(1)=''
		n=1
		loop while n <= N_RECORD
			if p_gp # null then
				if range.isin('writeRange',p_gp) = 1 then
					buf(1) = buf(1)+string(math.sqrt(gp.disp.x(p_gp)^2+gp.disp.y(p_gp)^2+gp.disp.z(p_gp)^2))+ '  '
					n=n+1
				endif
				p_gp = gp.next(p_gp)
			else
				n=N_RECORD+1
			endif
		endloop
		status = file.write(buf,1)
    endloop
	;Write x-displacement
    p_gp = gp.head
    loop while p_gp # null
		buf(1)=''
		n=1
		loop while n <= N_RECORD
			if p_gp # null then
				if range.isin('writeRange',p_gp) = 1 then
					buf(1) = buf(1)+string(gp.disp.x(p_gp))+ '  '
					n=n+1
				endif
				p_gp = gp.next(p_gp)
			else
				n=N_RECORD+1
			endif
		endloop
		status = file.write(buf,1)
    endloop
	;
	;Write y-displcaement 
    p_gp = gp.head
    loop while p_gp # null
		buf(1)=''
		n=1
		loop while n <= N_RECORD
			if p_gp # null then
				if range.isin('writeRange',p_gp) = 1  then
					buf(1) = buf(1)+string(gp.disp.y(p_gp))+ '  '
					n=n+1
				endif
				p_gp = gp.next(p_gp)
			else
				n=N_RECORD+1
			endif
		endloop
		status = file.write(buf,1)
    endloop
	;  
	;write z-displacement
    p_gp = gp.head
    loop while p_gp # null
		buf(1)=''
		n=1
		loop while n <= N_RECORD
			if p_gp # null then
				if range.isin('writeRange',p_gp) = 1  then
					buf(1) = buf(1)+string(gp.disp.z(p_gp))+ '  '
					n=n+1
				endif
				p_gp = gp.next(p_gp)
			else
				n=N_RECORD+1
			endif
		endloop
		status = file.write(buf,1)
    endloop
ii=io.out('Displacement data have been written!')
end;End of write_nodeData
;;
;;Write the data in Elements
def write_zoneData
	;Write SXX
    p_z = zone.head
    loop while p_z # null
		buf(1)=''
		n=1
		loop while n<=N_RECORD
			if p_z # null then
				if range.isin('writeRange',p_z) = 1 then
				if zone.model(p_z) # 'NULL' then
					buf(1) = buf(1)+string(zone.stress.xx(p_z))+ '  '
					n=n+1
				endif
				endif
				p_z = zone.next(p_z)
			else
				n=N_RECORD+1
			endif
		endloop
		status = file.write(buf,1)
    endloop
	;Write SYY
    p_z = zone.head
    loop while p_z # null
		buf(1)=''
		n=1
		loop while n<=N_RECORD
			if p_z # null then
				if range.isin('writeRange',p_z) = 1 then
				if zone.model(p_z) # 'NULL' then
					buf(1) = buf(1)+string(zone.stress.yy(p_z))+ '  '
					n=n+1
				endif
				endif
				p_z = zone.next(p_z)
			else
				n=N_RECORD+1
			endif
		endloop
		status = file.write(buf,1)
    endloop
	;Write SZZ
    p_z = zone.head
    loop while p_z # null
		buf(1)=''
		n=1
		loop while n<=N_RECORD
			if p_z # null then
				if range.isin('writeRange',p_z) = 1 then
				if zone.model(p_z) # 'NULL' then
					buf(1) = buf(1)+string(zone.stress.zz(p_z))+ '  '
					n=n+1
				endif
				endif
				p_z = z.next(p_z)
			else
				n=N_RECORD+1
			endif
		endloop
		status = file.write(buf,1)
    endloop
	;Write Sig1 Max Princinple
    p_z = zone.head
    loop while p_z # null
		buf(1)=''
		n=1
		loop while n<=N_RECORD
			if p_z # null then
				if range.isin('writeRange',p_z) = 1 then
				if zone.model(p_z) # 'NULL' then
					buf(1) = buf(1)+string(zone.stress.min(p_z))+ '  '
					n=n+1
				endif
				endif
				p_z = zone.next(p_z)
			else
				n=N_RECORD+1
			endif
		endloop
		status = file.write(buf,1)
    endloop
	;Write Sig2 Mid Princinple
    p_z = zone.head
    loop while p_z # null
		buf(1)=''
		n=1
		loop while n<=N_RECORD
			if p_z # null then
				if range.isin('writeRange',p_z) = 1 then
				if zone.model(p_z) # 'NULL' then
					buf(1) = buf(1)+string(zone.stress.int(p_z))+ '  '
					n=n+1
				endif
				endif
				p_z = zone.next(p_z)
			else
				n=N_RECORD+1
			endif
		endloop
		status = file.write(buf,1)
    endloop
	;Write Sig3 Min Princinple
    p_z = zone.head
    loop while p_z # null
		buf(1)=''
		n=1
		loop while n<=N_RECORD
			if p_z # null then
				if range.isin('writeRange',p_z) = 1 then
				if zone.model(p_z) # 'NULL' then
					buf(1) = buf(1)+string(zone.stress.max(p_z))+ '  '
					n=n+1
				endif
				endif
				p_z = zone.next(p_z)
			else
				n=N_RECORD+1
			endif
		endloop
		status = file.write(buf,1)
    endloop
ii=io.out('Element stress data have been written!')
end;End of write_zoneData
;;
;;Zone Connectivity List
;Calculate the maximum index of the array my_Grid()
def my_array
	p_gp=gp.head
	loop while p_gp # null
		ski=gp.id(p_gp)
		p_gp=gp.next(p_gp)
	endloop
end;End of my_array
@my_array
;
def write_zone
	;create an array to store the grid point data
	array my_Grid(ski) 
	;initialize the grid point array
	p_gp=gp.head
	i=1
	loop while p_gp # null
		if range.isin('writeRange',p_gp) = 1  then
			my_Grid(gp.id(p_gp))=i
			i=i+1
		endif
		p_gp=gp.next(p_gp)
	endloop
	;Write Zone Connectivity List
	p_z = zone.head
	loop while p_z # null
	if range.isin('writeRange',p_z) = 1  then
	if zone.model(p_z) # 'NULL' then
		if zone.gp.num(p_z) = 8 then;A
		;1 2 5 3 4 7 8 6
			my_Point(1)=string(my_Grid(gp.id(z.gp(p_z, 1))))
			my_Point(2)=string(my_Grid(gp.id(z.gp(p_z, 2))))
			my_Point(3)=string(my_Grid(gp.id(z.gp(p_z, 3))))
			my_Point(4)=string(my_Grid(gp.id(z.gp(p_z, 4))))
			my_Point(5)=string(my_Grid(gp.id(z.gp(p_z, 5))))
			my_Point(6)=string(my_Grid(gp.id(z.gp(p_z, 6))))
			my_Point(7)=string(my_Grid(gp.id(z.gp(p_z, 7))))
			my_Point(8)=string(my_Grid(gp.id(z.gp(p_z, 8))))
			;
			buf(1) = my_Point(1) + '  ' + my_Point(2)+ '  ' + my_Point(5)+ '  ' + my_Point(3)
			buf(1) = buf(1)+ '  ' +my_Point(4) + '  ' + my_Point(7)+ '  ' + my_Point(8)+ '  ' + my_Point(6)
		else 
		if zone.gp.num(p_z) = 4 then;B
		;1 2 3 3 4 4 4 4
			my_Point(1)=string(my_Grid(gp.id(z.gp(p_z, 1))))
			my_Point(2)=string(my_Grid(gp.id(z.gp(p_z, 2))))
			my_Point(3)=string(my_Grid(gp.id(z.gp(p_z, 3))))
			my_Point(4)=string(my_Grid(gp.id(z.gp(p_z, 4))))
			;
            	buf(1) = my_Point(1) + '  ' + my_Point(2)+ '  ' + my_Point(3)+ '  ' + my_Point(3)
	    		buf(1) = buf(1)+ '  ' +my_Point(4) + '  ' + my_Point(4)+ '  ' + my_Point(4)+ '  ' + my_Point(4)
		else  
		if zone.gp.num(p_z) = 6 then;C
		;1 2 5 3 4 4 6 6 or 1 2 4 4 3 5 6 6
			my_Point(1)=string(my_Grid(gp.id(z.gp(p_z, 1))))
			my_Point(2)=string(my_Grid(gp.id(z.gp(p_z, 2))))
			my_Point(3)=string(my_Grid(gp.id(z.gp(p_z, 3))))
			my_Point(4)=string(my_Grid(gp.id(z.gp(p_z, 4))))
			my_Point(5)=string(my_Grid(gp.id(z.gp(p_z, 5))))
			my_Point(6)=string(my_Grid(gp.id(z.gp(p_z, 6))))
			;
            	buf(1) = my_Point(1) + '  ' + my_Point(2)+ '  ' + my_Point(4)+ '  ' + my_Point(4)
	    		buf(1) = buf(1)+ '  ' +my_Point(3) + '  ' + my_Point(5)+ '  ' + my_Point(6)+ '  ' + my_Point(6)    
		else
		if zone.gp.num(p_z) = 5 then;D
		;1 2 5 3 4 4 4 4
			my_Point(1)=string(my_Grid(gp.id(z.gp(p_z, 1))))
			my_Point(2)=string(my_Grid(gp.id(z.gp(p_z, 2))))
			my_Point(3)=string(my_Grid(gp.id(z.gp(p_z, 3))))
			my_Point(4)=string(my_Grid(gp.id(z.gp(p_z, 4))))
			my_Point(5)=string(my_Grid(gp.id(z.gp(p_z, 5))))
			;
            	buf(1) = my_Point(1) + '  ' + my_Point(2)+ '  ' + my_Point(5)+ '  ' + my_Point(3)
	    		buf(1) = buf(1)+ '  ' +my_Point(4) + '  ' + my_Point(4)+ '  ' + my_Point(4)+ '  ' + my_Point(4)  
		endif;A
		endif;B
		endif;C
		endif;D
        	status = file.write(buf,1)
	endif
	endif;if inrange('writeRange',p_z) = 1 then
		p_z = zone.next(p_z);next zone
	endloop;loop while p_z # null
ii=io.out('Zone Connectivity List has been written!')
end;End of write_zone
;;
;;Main Function
def Flac2tec	
    status = file.close
	status = file.open(tec_file,IO_WRITE,IO_ASCII)
	if status = 0 then
	    write_FileHead
	    write_node
		write_nodeData
		write_zoneData
	    write_zone
	    status = file.close
	    ii = io.out('Data File for Tecplot has been created!  ' + tec_file)
	else
	    ii = io.out('Open File Error! Status = ' + string(status))			
	endif
end;End of Flac2tec	
@Flac2tec
program system("preplot FLAC3DMesh_deformation.dat")
program echo on

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值