- 积分
- 0
- 注册时间
- 2024-9-17
- 仿真币
-
- 最后登录
- 1970-1-1
|
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" "Maximum Shear Stress" "SXZ" "SYZ" "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 Maximum Shear Stress
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(0.5*(zone.stress.max(p_z)-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 SXZ
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.xz(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 SYZ
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.yz(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
;;If you do not have saved this project before
;; Your output-file would be in C:\Windows\System32
|
|