vtu passed FreeCAD test

main
harvo 2 years ago
parent 4002d4401a
commit c27d2feeea

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,267 @@
# import necessary modules to handle Abaqus output database, files and string
from odbAccess import *
from textRepr import *
from string import *
import os
import time
def ConvertOdb2Vtk(): # Modify the default value of filename here to specify the default configuration file
starttime = time.time()
# display the reading result of odb2vtk file
print("odb2vtk reading finished, time elapsed: "), time.time()-starttime
print("Basic Information:")
print("Model:", odb_path, "; Mesh type:",
mesh_name, "; Number of blocks:", 1)
print("Convert frames: ", input_frame[0], " to ", input_frame[-1])
print("Step & Instance : ", str(input_step), ", ", str(input_instance))
# open an ODB ( Abaqus output database )
odb = openOdb(os.path.join(odb_path), readOnly=True)
print("ODB opened")
# access geometry and topology information ( odb->rootAssembly->instances->(nodes, elements) )
rootassembly = odb.rootAssembly
instance = rootassembly.instances
# access attribute information
step = odb.steps
# get instance & step information : Quantity and all names
allinstancestr = str(instance)
autoins = allinstancestr.split("'")
inslen = len(autoins)/4
instance_N = range(0, inslen)
allstepstr = str(step)
autostep = allstepstr.split("'")
steplen = len(autostep)/4
step_N = range(0, steplen)
for i in input_step:
if (steplen < int(i)):
print("input step exceeds the range of steps")
os._exit(0)
for i in input_instance:
if (inslen < int(i)):
print("input instance exceeds the range of instances")
os._exit(0)
# step cycle
for step_i in input_step:
n = int(step_i)*4+1
stepname = autostep[n]
print("Step: ", stepname)
# instance cycle
for ins_i in input_instance:
n = int(ins_i)*4+1
instancename = autoins[n]
print("Instance: ", instancename)
# access nodes & elements
node = instance[instancename].nodes
element = instance[instancename].elements
n_nodes = len(node)
n_elements = len(element)
# access attribute(fieldOutputs) information
frame = step[stepname].frames
print('all frame',frame)
# compute the number of element of each block
p_elements = n_elements/1 + 1
lp_elements = n_elements - (p_elements*(1-1)) # last block
# match nodes' label and its order in sequence (for empty nodes in tetra mesh)
MLN = node[n_nodes-1].label
TOTAL = []
# read node in sequence, and get the largest label of node(non-empty)
# MLN is the max label of nodeset
for i in node:
TOTAL.append(i.label)
if (i.label > MLN):
MLN = i.label
# match (the key)
L = []
n = 0
for i in range(MLN):
L.append(0)
for i in TOTAL:
L[i-1] = n
n += 1
# frame cycle
for i_frame in input_frame:
# Detect whether the input frame is out of range
try:
odb.steps[stepname].frames[int(i_frame)]
except:
print("input frame exceeds the range of frames")
os._exit(0)
break
# Access a frame
N_Frame = odb.steps[stepname].frames[int(i_frame)]
print("Frame:", i_frame)
print("Partitionning model and writing vtk files ......")
# piece cycle, to partion the model and create each piece for vtk files
time1 = time.time()
print("frame:", i_frame, ";")
# Reorganization
# Control&Storage
# estimate whether the node has already existed
stg_p = []
# store the reorganized node for element
stg_e = []
# store the reorganized node for node
stg_n = []
for i in range(MLN):
stg_p.append(-1)
nodecount = 0
# reorganize the node and element (reconstruct the mesh)
M = range(0, n_elements)
for i in M:
for j in range(mesh_conner):
k = element[i].connectivity[j] - 1
if (stg_p[k] < 0):
stg_p[k] = nodecount
stg_n.append(L[k])
stg_e.append(nodecount)
nodecount += 1
else:
stg_e.append(stg_p[k])
# compute point quantity
n_reop = len(stg_n)
reop_N = range(0, len(stg_n))
# create and open a VTK(.vtu) files
outfile = open(os.path.join(vtk_path)+'_'+stepname +
'_'+instancename+'f%03d' % int(i_frame)+'.vtu', 'w')
# <VTKFile>, including the type of mesh, version, and byte_order
outfile.write(
'<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">'+'\n')
# <UnstructuredGrid>
outfile.write('<UnstructuredGrid>'+'\n')
# <Piece>, including the number of points and cells
outfile.write('<Piece NumberOfPoints="'+str(n_reop) +
'"'+' '+'NumberOfCells="'+str(lp_elements)+'">'+'\n')
print("Writing Nodes ......")
# <Points> Write nodes into vtk files
outfile.write('<Points>'+'\n')
outfile.write(
'<DataArray type="Float64" NumberOfComponents="3" format="ascii">'+'\n')
for i in reop_N:
nt = stg_n[i]
k = node[stg_n[i]].label-1
# base shape
X, Y, Z = node[nt].coordinates[0], node[nt].coordinates[1], node[nt].coordinates[2]
# modify shape
# X,Y,Z = node[nt].coordinates[0]+ux,node[nt].coordinates[1]+uy,node[nt].coordinates[2]+uz
outfile.write(' '+'%11.8e' % X+' '+'%11.8e' %
Y+' '+'%11.8e' % Z+'\n')
outfile.write('</DataArray>'+'\n')
outfile.write('</Points>'+'\n')
# </Points>
print("Writing Results data ......")
# <PointData> Write results data into vtk files
col = {"Scalars": [], "Vevtors": [], "Tensors": []}
# 'U','A', 'V', 'RF','PEEQ','S'
for var_id in ['NT11']:
try:
col["Scalars"].append("Temperature")
except:
print('jump', var_id)
con = "Scalars="+'"'+','.join(col["Scalars"])+'"'
# con = "Tensors="+'"'+','.join(col["Tensors"])+'"' + " "+ \
# "Vevtors="+'"'+','.join(col["Vevtors"])+'"' + " "+ \
# "Scalars="+'"'+','.join(col["Scalars"])+'"'
outfile.write("<"+"PointData"+" "+con+">"+'\n')
for var_id in ['NT11']:
fieldOutputs = N_Frame.fieldOutputs[var_id]
from utils_odb import NT11 as pq_class
pq_class(fieldOutputs,outfile,reop_N)
outfile.write("</PointData>"+'\n')
# </PointData>
print("Writing Cells ......")
# <Cells> Write cells into vtk files
outfile.write('<Cells>'+'\n')
# Connectivity 8 node
outfile.write(
'<DataArray type="Int32" Name="connectivity" format="ascii">'+'\n')
if (mesh_type == 12):
for i in range(len(stg_e)/8):
outfile.write(str(stg_e[i*8])+' '+str(stg_e[i*8+1])+' '+str(stg_e[i*8+2])+' '+str(stg_e[i*8+3])+' '+str(
stg_e[i*8+4])+' '+str(stg_e[i*8+5])+' '+str(stg_e[i*8+6])+' '+str(stg_e[i*8+7])+'\n')
if (mesh_type == 10):
for i in range(len(stg_e)/4):
outfile.write(str(
stg_e[i*4])+' '+str(stg_e[i*4+1])+' '+str(stg_e[i*4+2])+' '+str(stg_e[i*4+3])+'\n')
outfile.write('</DataArray>'+'\n')
# Offsets
outfile.write(
'<DataArray type="Int32" Name="offsets" format="ascii">'+'\n')
for i in range(len(stg_e)/mesh_conner):
outfile.write(str(i*mesh_conner+mesh_conner)+'\n')
outfile.write('</DataArray>'+'\n')
# Mesh Type
outfile.write(
'<DataArray type="UInt8" Name="types" format="ascii">'+'\n')
for i in range(len(stg_e)/mesh_conner):
outfile.write(str(mesh_type)+'\n')
outfile.write('</DataArray>'+'\n')
outfile.write('</Cells>'+'\n')
# </Cells>
# </Piece>
outfile.write('</Piece>'+'\n')
# </UnstructuredGrid>
outfile.write('</UnstructuredGrid>'+'\n')
# </VTKFile>
outfile.write('</VTKFile>'+'\n')
outfile.close()
print("Time elapsed: ", time.time() - time1, "s")
odb.close()
print("Total time elapsed: ", time.time() - starttime, "s")
# get odb file's path
odb_path = 'C:/Users/OPTX/Downloads/Digital-Twin/odb2vtk/Thermal.odb'
# get the output files' path
vtk_path = 'C:/Users/OPTX/Downloads/Digital-Twin/odb2vtk/' # not.vtu,.vtk
# get the mesh type
mesh_type = 12 # c3d8?
mesh_conner = 0
if (mesh_type == 12):
mesh_conner = 8
mesh_name = "Hexahedron"
if (mesh_type == 10):
mesh_conner = 4
mesh_name = "Tetra"
if (mesh_conner == 0):
print("Mesh type error or unidentified")
os._exit(0)
# get the frame
input_frame = range(1, 4+1)
# get the step
input_step = '0'.split(",")
# get the instance
input_instance = '0'.split(",")
# end reding and close odb2vtk file
ConvertOdb2Vtk()

@ -0,0 +1,337 @@
# Vector-U,A,V,RF
# Tensors-S
# Scalars-PEEQ
def U(displacement,outfile,reop_N):
#Access Spatial displacement
fieldValues = displacement.values
for valueX in fieldValues :
i = valueX.nodeLabel
ux = valueX.data[0]
uy = valueX.data[1]
uz = valueX.data[2]
#Spatial displacement, <DataArray>
outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Spatial_displacement"+'"'+" "+"NumberOfComponents="+'"'+"3"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
for i in reop_N:
X,Y,Z = ux,uy,uz
outfile.write('%11.8e'%X+' '+'%11.8e'%Y+' '+'%11.8e'%Z+'\n')
outfile.write("</DataArray>"+'\n')
#</DataArray>
def A(acceleration,outfile,reop_N):
#Access Spatial acceleration
fieldValues = acceleration.values
for valueX in fieldValues :
i = valueX.nodeLabel
ax = valueX.data[0]
ay = valueX.data[1]
az = valueX.data[2]
#Spatial acceleration, <DataArray>
outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Spatial_acceleration"+'"'+" "+"NumberOfComponents="+'"'+"3"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
for i in reop_N:
X,Y,Z = ax,ay,az
outfile.write('%11.8e'%X+' '+'%11.8e'%Y+' '+'%11.8e'%Z+'\n')
outfile.write("</DataArray>"+'\n')
#</DataArray>
def V(velocity,outfile,reop_N):
#Access Spatial velocity
fieldValues = velocity.values
for valueX in fieldValues :
i = valueX.nodeLabel
vx = valueX.data[0]
vy = valueX.data[1]
vz = valueX.data[2]
#Spatial velocity, <DataArray>
outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Spatial_velocity"+'"'+" "+"NumberOfComponents="+'"'+"3"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
for i in reop_N:
X,Y,Z = vx,vy,vz
outfile.write('%11.8e'%X+' '+'%11.8e'%Y+' '+'%11.8e'%Z+'\n')
outfile.write("</DataArray>"+'\n')
#</DataArray>
def RF(Reaction_force,outfile,reop_N):
#Access Reaction force
fieldValues = Reaction_force.values
for valueX in fieldValues :
i = valueX.nodeLabel
rfx = valueX.data[0]
rfy = valueX.data[1]
rfz = valueX.data[2]
#Reaction force
outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Reaction_force"+'"'+" "+"NumberOfComponents="+'"'+"3"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
for i in reop_N:
X,Y,Z = rfx,rfy,rfz
outfile.write('%11.8e'%X+' '+'%11.8e'%Y+' '+'%11.8e'%Z+'\n')
outfile.write("</DataArray>"+'\n')
#</DataArray>
def PEEQ(Equivalent_plastic_strain,outfile,reop_N):
#Equivalent plastic strain
node_Equivalent_plastic_strain = Equivalent_plastic_strain.getSubs(position=ELEMENT_NODAL)
fieldValues = node_Equivalent_plastic_strain.values
for valueX in fieldValues :
PEEQ_data= valueX.data
#Equivalent plastic strain, <DataArray>
outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Equivalent_plastic_strain"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
for i in reop_N:
pd = PEEQ_data
outfile.write('%11.8e'%pd+'\n')
outfile.write('</DataArray>'+'\n')
#</DataArray>
def Stress(Stress,outfile,reop_N):
#access Stress components
node_Stress = Stress.getSubset(position=ELEMENT_NODAL)
fieldValues = node_Stress.values
for valueX in fieldValues :
s11 = valueX.data[0]
s22 = valueX.data[1]
s33 = valueX.data[2]
s12 = valueX.data[3]
s23 = valueX.data[4]
s13 = valueX.data[5]
# L1[valueX.nodeLabel-1][7] += valueX.mises
# L1[valueX.nodeLabel-1][8] += valueX.maxPrincipal
# L1[valueX.nodeLabel-1][9] += valueX.midPrincipal
# L1[valueX.nodeLabel-1][10] += valueX.minPrincipal
# L1[valueX.nodeLabel-1][11] += valueX.press
# L1[valueX.nodeLabel-1][12] += valueX.tresca
# L1[valueX.nodeLabel-1][13] += valueX.inv3
#Stress components, <DataArray>
outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Stress_Components"+'"'+" "+"NumberOfComponents="+'"'+"9"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
for i in reop_N:
XX,XY,XZ,YX,YY,YZ,ZX,ZY,ZZ = s11,s12,s13,s12,s22,s23,s13,s23,s33
outfile.write('%11.8e'%XX+' '+'%11.8e'%XY+' '+'%11.8e'%XZ+' '+'%11.8e'%YX+' '+'%11.8e'%YY+' '+'%11.8e'%YZ+' '+'%11.8e'%ZX+' '+'%11.8e'%ZY+' '+'%11.8e'%ZZ+'\n')
outfile.write("</DataArray>"+'\n')
#</DataArray>
def NT11(Temperature,outfile,reop_N):
#Equivalent plastic strain
fieldValues = Temperature.values
for valueX in fieldValues :
NT11_data= valueX.data
#Equivalent plastic strain, <DataArray>
outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Temperature"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
for i in reop_N:
temp = NT11_data
outfile.write('%11.8e'%temp+'\n')
outfile.write('</DataArray>'+'\n')
#</DataArray>
# print "Reading U, A, V, RF ......"
# time1 = time()
# #Access Spatial displacement
# displacement = N_Frame.fieldOutputs['U']
# fieldValues = displacement.values
# for valueX in fieldValues :
# i = valueX.nodeLabel
# L0[i-1][0] = valueX.data[0] ux
# L0[i-1][1] = valueX.data[1] uy
# L0[i-1][2] = valueX.data[2] uz
# #Access Spatial acceleration
# acceleration = N_Frame.fieldOutputs['A']
# fieldValues = acceleration.values
# for valueX in fieldValues :
# i = valueX.nodeLabel
# L0[i-1][3] = valueX.data[0] ax
# L0[i-1][4] = valueX.data[1] ay
# L0[i-1][5] = valueX.data[2] az
# #Access Spatial velocity
# velocity = N_Frame.fieldOutputs['V']
# fieldValues = velocity.values
# for valueX in fieldValues :
# i = valueX.nodeLabel
# L0[i-1][6] = valueX.data[0] vx
# L0[i-1][7] = valueX.data[1] vy
# L0[i-1][8] = valueX.data[2] vz
# #Access Reaction force
# Reaction_force = N_Frame.fieldOutputs['RF']
# fieldValues = Reaction_force.values
# for valueX in fieldValues :
# i = valueX.nodeLabel
# L0[i-1][9] = valueX.data[0] rfx
# L0[i-1][10] = valueX.data[1] rfy
# L0[i-1][11] = valueX.data[2] rfz
# print "Time elapsed: ", time() - time1, "s"
# print "Reading Stress ......"
# time1 = time()
# #access Stress components
# Stress = N_Frame.fieldOutputs['S']
# node_Stress = Stress.getSubset(position=ELEMENT_NODAL)
# fieldValues = node_Stress.values
# for valueX in fieldValues :
# L1[valueX.nodeLabel-1][0] += 1
# L1[valueX.nodeLabel-1][1] += valueX.data[0] s11
# L1[valueX.nodeLabel-1][2] += valueX.data[1] s22
# L1[valueX.nodeLabel-1][3] += valueX.data[2] s33
# L1[valueX.nodeLabel-1][4] += valueX.data[3] s12
# L1[valueX.nodeLabel-1][5] += valueX.data[4] s23
# L1[valueX.nodeLabel-1][6] += valueX.data[5] s13
# L1[valueX.nodeLabel-1][7] += valueX.mises
# L1[valueX.nodeLabel-1][8] += valueX.maxPrincipal
# L1[valueX.nodeLabel-1][9] += valueX.midPrincipal
# L1[valueX.nodeLabel-1][10] += valueX.minPrincipal
# L1[valueX.nodeLabel-1][11] += valueX.press
# L1[valueX.nodeLabel-1][12] += valueX.tresca
# L1[valueX.nodeLabel-1][13] += valueX.inv3
# # can first ave
# print "Time elapsed: ", time() - time1, "s"
# print "Reading Equivalent plastic strain ......"
# time1 = time()
# #Equivalent plastic strain
# Equivalent_plastic_strain = N_Frame.fieldOutputs['PEEQ']
# node_Equivalent_plastic_strain = Equivalent_plastic_strain.getSubset(position=ELEMENT_NODAL)
# fieldValues = node_Equivalent_plastic_strain.values
# for valueX in fieldValues :
# L4[valueX.nodeLabel-1][0] += 1
# L4[valueX.nodeLabel-1][1] += valueX.data
# print "Time elapsed: ", time() - time1, "s"
# print "Reading Logarithmic strain ......"
# time1 = time()
# #Logarithmic strain components
# Logarithmic_strain = N_Frame.fieldOutputs['LE']
# node_Logarithmic_strain = Logarithmic_strain.getSubset(position=ELEMENT_NODAL)
# fieldValues = node_Logarithmic_strain.values
# for valueX in fieldValues :
# L2[valueX.nodeLabel-1][0] += 1
# L2[valueX.nodeLabel-1][1] += valueX.data[0]
# L2[valueX.nodeLabel-1][2] += valueX.data[1]
# L2[valueX.nodeLabel-1][3] += valueX.data[2]
# L2[valueX.nodeLabel-1][4] += valueX.data[3]
# L2[valueX.nodeLabel-1][5] += valueX.data[4]
# L2[valueX.nodeLabel-1][6] += valueX.data[5]
# L2[valueX.nodeLabel-1][7] += valueX.maxPrincipal
# L2[valueX.nodeLabel-1][8] += valueX.minPrincipal
# print "Time elapsed: ", time() - time1, "s"
# print "Reading Plastic strain ......"
# time1 = time()
# #Plastic strain components
# Plastic_strain = N_Frame.fieldOutputs['PE']
# node_Plastic_strain = Plastic_strain.getSubset(position=ELEMENT_NODAL)
# fieldValues = node_Plastic_strain.values
# for valueX in fieldValues :
# L3[valueX.nodeLabel-1][0] += 1
# L3[valueX.nodeLabel-1][1] += valueX.data[0]
# L3[valueX.nodeLabel-1][2] += valueX.data[1]
# L3[valueX.nodeLabel-1][3] += valueX.data[2]
# L3[valueX.nodeLabel-1][4] += valueX.data[3]
# L3[valueX.nodeLabel-1][5] += valueX.data[4]
# L3[valueX.nodeLabel-1][6] += valueX.data[5]
# L3[valueX.nodeLabel-1][7] += valueX.maxPrincipal
# L3[valueX.nodeLabel-1][8] += valueX.minPrincipal
# print "Time elapsed: ", time() - time1, "s"
#Logarithmic_strain_Max_Principal, <DataArray>
# outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Logarithmic_strain_Max_Principal"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
# for i in reop_N:
# k = node[stg_n[i]].label-1
# X = L2[k][7]
# outfile.write('%11.8e'%X+'\n')
# outfile.write('</DataArray>'+'\n')
# #</DataArray>
# #Logarithmic strain Min.Principal, <DataArray>
# outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Logarithmic_strain_Min_Principal"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
# for i in reop_N:
# k = node[stg_n[i]].label-1
# X = L2[k][8]
# outfile.write('%11.8e'%X+'\n')
# outfile.write('</DataArray>'+'\n')
# #</DataArray>'''
#Plastic strain Max.Principal, <DataArray>
# outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Plastic_strain_Max_Principal"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
# for i in reop_N:
# k = node[stg_n[i]].label-1
# X = L3[k][7]
# outfile.write('%11.8e'%X+'\n')
# outfile.write('</DataArray>'+'\n')
# #</DataArray>
# #Plastic strain Min.Principal, <DataArray>
# outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Plastic_strain_Min_Principal"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
# for i in reop_N:
# k = node[stg_n[i]].label-1
# X = L3[k][8]
# outfile.write('%11.8e'%X+'\n')
# outfile.write('</DataArray>'+'\n')
# #</DataArray>
# #Stress Mises, <DataArray>
# outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Stress_Mises"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
# for i in reop_N:
# k = node[stg_n[i]].label-1
# X = smises
# outfile.write('%11.8e'%X+'\n')
# outfile.write('</DataArray>'+'\n')
# #</DataArray>
# #Stress Max.Principal, <DataArray>
# outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Stress_Max_Principal"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
# for i in reop_N:
# k = node[stg_n[i]].label-1
# X = maxPrincipal
# outfile.write('%11.8e'%X+'\n')
# outfile.write('</DataArray>'+'\n')
# #</DataArray>
# #Stress Mid.Principal, <DataArray>
# outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Stress_Mid_Principal"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
# for i in reop_N:
# k = node[stg_n[i]].label-1
# X = midPrincipal
# outfile.write('%11.8e'%X+'\n')
# outfile.write('</DataArray>'+'\n')
# #</DataArray>
# #Stress Min.Principal, <DataArray>
# outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Stress_Min_Principal"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
# for i in reop_N:
# k = node[stg_n[i]].label-1
# X = minPrincipal
# outfile.write('%11.8e'%X+'\n')
# outfile.write('</DataArray>'+'\n')
# #</DataArray>
# #Stress Pressure, <DataArray>
# outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Stress_Pressure"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
# for i in reop_N:
# k = node[stg_n[i]].label-1
# X = press
# outfile.write('%11.8e'%X+'\n')
# outfile.write('</DataArray>'+'\n')
# #</DataArray>
# #Stress Tresca, <DataArray>
# outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Stress_Tresca"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
# for i in reop_N:
# k = node[stg_n[i]].label-1
# X = tresca
# outfile.write('%11.8e'%X+'\n')
# outfile.write('</DataArray>'+'\n')
# #</DataArray>
# #Stress Third_Invariant, <DataArray>
# outfile.write("<"+"DataArray"+" "+"type="+'"'+"Float32"+'"'+" "+"Name="+'"'+"Stress_Third_Invariant"+'"'+" "+"format="+'"'+"ascii"+'"'+">"+'\n')
# for i in reop_N:
# k = node[stg_n[i]].label-1
# X = inv3
# outfile.write('%11.8e'%X+'\n')
# outfile.write('</DataArray>'+'\n')
# #</DataArray>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,96 @@
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
<UnstructuredGrid>
<Piece NumberOfPoints="9758" NumberOfCells="7720">
<Points>
<DataArray type="Float64" NumberOfComponents="3" format="ascii">
1.14142670e+02 1.94950455e+02 2.09956284e+01
1.14148987e+02 1.94973007e+02 1.66398163e+01
</DataArray>
</Points>
<PointData Tensors="Stress_Components,Plastic_strain_components" Vevtors="Spatial_displacement,Reaction_force" Scalars="Equivalent_plastic_strain,Stress_Mises,Stress_Max_Principal,Stress_Mid_Principal,Stress_Min_Principal,Stress_Pressure,Stress_Tresca,Stress_Third_Invariant,Plastic_strain_Max_Principal,Plastic_strain_Min_Principal">
<DataArray type="Float32" Name="Stress_Components" NumberOfComponents="9" format="ascii">
2.59650444e+02 9.11758537e+01 -2.31648428e+01 9.11758537e+01 3.66732831e+01 -2.31251527e+01 -2.31648428e+01 -2.31251527e+01 1.77810198e+01
2.48385765e+02 6.00162227e+01 -4.26037811e+01 6.00162227e+01 6.46214383e+01 -6.27090860e+01 -4.26037811e+01 -6.27090860e+01 2.54560731e+01
-2.03744248e-01 7.47108243e-01 1.95734284e+01 7.77507272e-01 1.95734284e+01 7.11013520e+00
</DataArray>
<DataArray type="Float32" Name="Plastic_strain_components" NumberOfComponents="9" format="ascii">
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
</DataArray>
<DataArray type="Float32" Name="Spatial_displacement" NumberOfComponents="3" format="ascii">
-6.99003635e-04 2.12240557e-04 1.89813087e-04
4.31050546e-03 1.76074437e-03 8.81935412e-04
</DataArray>
<DataArray type="Float32" Name="Equivalent_plastic_strain" format="ascii">
1.26715872e-03
1.42574357e-03
1.44796711e-03
</DataArray>
<DataArray type="Float32" Name="Stress_Mises" format="ascii">
2.99598320e+02
3.09799160e+02
3.05079208e+02
</DataArray>
<DataArray type="Float32" Name="Stress_Max_Principal" format="ascii">
3.00398270e+02
3.03094946e+02
3.30113873e+02
</DataArray>
<DataArray type="Float32" Name="Stress_Mid_Principal" format="ascii">
4.01155953e+01
7.05121019e+01
1.44226957e+02
</DataArray>
<DataArray type="Float32" Name="Stress_Min_Principal" format="ascii">
-2.64091141e+01
-3.51437670e+01
-4.76601553e+00
</DataArray>
<DataArray type="Float32" Name="Stress_Pressure" format="ascii">
-1.04701582e+02
-1.12821091e+02
-1.56524935e+02
</DataArray>
<DataArray type="Float32" Name="Stress_Tresca" format="ascii">
3.26807388e+02
3.38238712e+02
3.34879887e+02
</DataArray>
<DataArray type="Float32" Name="Stress_Third_Invariant" format="ascii">
2.80547337e+02
1.61356241e+02
2.08437462e+01
</DataArray>
<DataArray type="Float32" Name="Plastic_strain_Max_Principal" format="ascii">
1.24045811e-03
1.27121818e-03
1.06240633e-03
</DataArray>
<DataArray type="Float32" Name="Plastic_strain_Min_Principal" format="ascii">
-8.33233353e-04
-1.06111002e-03
-1.34513313e-03
</DataArray>
</PointData>
<Cells>
<DataArray type="Int32" Name="connectivity" format="ascii">
0 1 2 3 4 5 6 7
1 8 9 2 5 10 11 6
3 2 12 13 7 6 14 15
</DataArray>
<DataArray type="Int32" Name="offsets" format="ascii">
8
16
24
32
</DataArray>
<DataArray type="UInt8" Name="types" format="ascii">
12
12
12
12
</DataArray>
</Cells>
</Piece>
</UnstructuredGrid>
</VTKFile>

@ -0,0 +1,12 @@
----------input and output path----------
odb_path = 'C:\Users\OPTX\Downloads\plate'
odb_name = 'Inherent'
vtk_path = 'C:\Users\OPTX\Downloads\plate'
--------------type of mesh--------------
mesh_type = '12'
-------------number of piece-------------
piecenum = '1'
----setting frame, step and instance----
frame = '1-4'
step = '0'
instance = '0'

Binary file not shown.

File diff suppressed because it is too large Load Diff

@ -1,7 +1,6 @@
<?xml version="1.0"?>
<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian" header_type="UInt32">
<StructuredGrid>
WholeExtent="x1 x2 x3 y1 y2 y3 z1 z2 z3">
<StructuredGrid> WholeExtent="x1 x2 x3 y1 y2 y3 z1 z2 z3">
<Piece Extent="x1 x2 x3 y1 y2 y3 z1 z2 z3">
<Points>
<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="ascii">

@ -0,0 +1,27 @@
SUBROUTINE DFLUX(FLUX,SOL,KSTEP,KINC,TIME,NOEL,NPT,COORDS,JLTYP, TEMP, PRESS, SNAME)
INCLUDE 'ABA_PARAM.INC'
DIMENSION COORDS(3),FLUX(2),TIME(2)
CHARACTER*80 SNAME
real U,AI,v,yita,R0,qm
U=16.5
AI=60.
v=250./60.
yita=0.75
R0=5.
qm=yita*U*AI*1000./3.14/R0/R0
dx=v*TIME(1)
dy=0.
rr= (COORDS(1)-dx)**2 + (COORDS(2)-dy)**2
FLUX(1)=3.*qm*exp(-3.*rr/R0/R0)
! write(*,*) time,dx
! write(*,*) COORDS,rr
! write(*,*) FLUX
! write(*,*)
RETURN
END

@ -0,0 +1,145 @@
from odbAccess import openOdb
from abaqus import *
from abaqusConstants import *
from utils_odb2vtk import Physical_Quantity
class CAE_Model(Physical_Quantity, object):
def __init__(self):
super(CAE_Model, self).__init__()
# print('self.var_type', self.var_type)
self.nodes = {}
self.elements = {}
self.physical_quantity = {}
def read_inp(self, INPPATH):
# 0 - nothing
# 1 - node
# 2 - hexahedron
state = 0
# read input file
with open(INPPATH, 'r') as input_file:
for line in input_file:
if line.strip() == '*Node':
state = 1
elif line.startswith('*Element, type=C3D8R'):
state = 2
else:
if line.startswith("*") and (not line.startswith("**")):
state = 0
elif state == 1:
nid, x, y, z = line.strip().split(',')
# insertNode(uid, x, y, z)
self.nodes[int(nid)] = [float(x), float(y), float(z)]
elif state == 2:
eid, n0, n1, n2, n3, n4, n5, n6, n7 = line.strip().split(',')
# insertHexa(el, n0, n1, n2, n3, n4, n5, n6, n7)
self.elements[int(eid)] = [int(n0), int(n1), int(
n2), int(n3), int(n4), int(n5), int(n6), int(n7)]
else:
pass
def read_odb(self, ODBPATH):
# Open the odb
myodb = openOdb(ODBPATH)
# Get the frame repository for the step, find number of frames (starts at frame 0)
stepName = myodb.steps.keys()[0]
frames = myodb.steps[stepName].frames
numFrames = len(frames)
print("num Frame %d" % (numFrames))
# Isolate the instance, get the number of nodes and elements
instanceName = myodb.rootAssembly.instances.keys()[0]
myInstance = myodb.rootAssembly.instances[instanceName]
numNodes = len(myInstance.nodes)
numElements = len(myInstance.elements)
print("num Element %d, num Node %d" % (numElements, numNodes))
for var_id in ['U', 'A', 'V', 'RF', 'S', 'LE', 'PE', 'PEEQ', 'NT11', 'HFL', 'RFL11']:
# try:
if var_id == 'NT11':
# S=myodb.steps[stepName].frames[-1].fieldOutputs['S'].getSubset(position=INTEGRATION_POINT)
var_data = myodb.steps[stepName].frames[-1].fieldOutputs[var_id].values
print(var_id+": %d" % (len(var_data)))
self.pq_update(var_id)
self.physical_quantity[var_id] = self.insert(var_data)
# except:
# print('jump ', var_id)
def write_vtk(self, OUTPATH, var_ids):
self.nids = sorted(self.nodes.keys())
self.eids = sorted(self.elements.keys())
with open(OUTPATH, 'w') as ofs:
ofs.write('<?xml version="1.0"?>')
ofs.write(
'<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian" header_type="UInt32">')
ofs.write(
'<StructuredGrid> WholeExtent="x1 x2 x3 y1 y2 y3 z1 z2 z3">')
ofs.write('<Piece Extent="x1 x2 x3 y1 y2 y3 z1 z2 z3">')
### define Points element ###
ofs.write('<Points>')
ofs.write(
'<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="ascii">')
for key in self.nids:
x, y, z = self.nodes[key]
ofs.write("%f %f %f " % (x, y, z))
ofs.write('</DataArray>')
ofs.write('</Points>')
### define Cells element ###
ofs.write('<Cells>')
ofs.write(
'<DataArray type="Int64" Name="connectivity" format="ascii">')
for key in self.eids:
ns = self.elements[key]
nns = map(lambda x: str(x - 1), ns)
cons = " ".join(nns)
ofs.write(cons + ' ')
ofs.write('</DataArray>')
ofs.write('<DataArray type="Int64" Name="offsets" format="ascii">')
for key in self.eids:
ofs.write("%d " % (key * 8))
ofs.write('</DataArray>')
ofs.write('<DataArray type="UInt8" Name="types" format="ascii">')
for key in self.eids:
ofs.write("10 ")
ofs.write('</DataArray>')
ofs.write('</Cells>')
# node data/element data
for var_id in var_ids:
self.pq_update(var_id)
# var_name = var_stress.__name__
var_name = var_id
var_type = self.var_type
NumberOfComponents = str(self.NumberOfComponents)
ofs.write('<'+var_type+'Data '+var_type+'="' + var_name + '">')
ofs.write('<DataArray type="Float32" format="ascii" Name="' +
var_name+'" NumberOfComponents="'+NumberOfComponents+'" >')
self.write(self.physical_quantity[var_id], ofs)
ofs.write('</DataArray>')
ofs.write('</'+var_type+'Data>')
# finshed
ofs.write('</Piece>')
ofs.write('</StructuredGrid>')
ofs.write('</VTKFile>')
ofs.close()
INPPATH = 'C:/Users/Harvo/Downloads/Digital-Twin/thermal/Thermal.inp'
ODBPATH = 'C:/Users/Harvo/Downloads/Digital-Twin/thermal/Thermal.odb'
OUTPATH = 'C:/Users/Harvo/Downloads/Digital-Twin/thermal/Thermal.vtk'
my_model = CAE_Model()
my_model.read_inp(INPPATH)
print('finish read_inp')
my_model.read_odb(ODBPATH)
print('finish read_odb')
my_model.write_vtk(OUTPATH, var_ids=['NT11'])
print('finish write_vtk')

Binary file not shown.

Binary file not shown.

@ -0,0 +1,144 @@
class Physical_Quantity(object):
def __init__(self):
pass
# Scalars NT11,RFL11
# Vectors displacement,HFL
# Tensors Stress,spstress
def pq_update(self, var_id):
if var_id == 'S':
self.pq_class = Stress()
if var_id == 'SPS':
self.pq_class = Spstress()
if var_id == 'DISP':
self.pq_class = Displacement()
if var_id == 'NT11':
self.pq_class = Temperature()
self.var_type = self.pq_class.var_type
self.NumberOfComponents = self.pq_class.NumberOfComponents
def insert(self, var_data):
return self.pq_class.insertData(var_data)
def write(self, *args):
# print(args)
self.pq_class.writeData(self.nids, self.eids, args)
class Stress:
def __init__(self):
self.var_type = 'Tensors'
self.NumberOfComponents = 9
def insertData(self, var_data):
this_pq = {}
for var_line in var_data:
eid = var_line.elementLabel
sxx = var_line.data[0]
syy = var_line.data[1]
szz = var_line.data[2]
sxy = var_line.data[3]
sxz = var_line.data[4]
syz = var_line.data[5]
this_pq[int(eid)] = [float(sxx), float(syy), float(
szz), float(sxy), float(sxz), float(syz)]
return this_pq
def writeData(self, stress, ofs):
for key in self.eids:
s11, s22, s33, s12, s13, s23 = stress[key][0:]
ofs.write("%f %f %f %f %f %f %f %f %f " %
(s11, s12, s13, s12, s22, s23, s13, s23, s33))
class Spstress:
def __init__(self):
self.var_type = 'Vectors'
self.NumberOfComponents = 3
def insertData(self, var_data):
this_pq = {}
for var_line in var_data:
eid = var_line.elementLabel
smin = var_line.maxPrincipal
smin = var_line.midPrincipal
smin = var_line.minPrincipal
this_pq[int(eid)] = [float(smin), float(smin), float(smin)]
return this_pq
def writeData(self, nids, eids, args):
spstress, ofs = args
for key in eids:
sp1, sp2, sp3 = spstress[key][0:]
ofs.write("%f %f %f " % (sp1, sp2, sp3))
class Displacement:
def __init__(self):
self.var_type = 'Vectors'
self.NumberOfComponents = 3
def insertData(self, var_data):
this_pq = {}
for var_line in var_data:
nid = var_line.nodeLabel
ux = var_line.data[0]
uy = var_line.data[1]
uz = var_line.data[2]
this_pq[int(nid)] = [float(ux), float(uy), float(uz)]
return this_pq
def writeData(self, nids, eids, args):
displacement, ofs = args
for key in nids:
ux, uy, uz = displacement[key]
ofs.write("%f %f %f " % (ux, uy, uz))
class Temperature(object):
def __init__(self):
self.var_type = 'Scalars'
self.NumberOfComponents = 1
def insertData(self, var_data):
this_pq = {}
for var_line in var_data:
nid = var_line.nodeLabel
temp = var_line.data
this_pq[int(nid)] = [float(temp)]
return this_pq
def writeData(self, nids, eids, args):
temperature, ofs = args
for key in nids:
temp = temperature[key][0]
# print(temp)
ofs.write("%f " % (temp,))
# ### define PointsData element ###
# ofs.write('<PointData Vectors="displacement">')
# ofs.write('<DataArray type="Float32" NumberOfComponents="3" format="ascii" Name="displacement">')
# for key in self.nids:
# ux, uy, uz = self.displacement[key]
# ofs.write("%f %f %f " % (ux, uy, uz))
# ofs.write('</DataArray>')
# ofs.write('</PointData>')
# ### define CellData element ###
# ofs.write('<CellData Vectors="PrincipalStress" Tensors="Stress">')
# ofs.write('<DataArray type="Float32" Name="PrincipalStress" NumberOfComponents="3" format="ascii">')
# for key in self.eids:
# sp1, sp2, sp3 = self.spstress[key][0:]
# ofs.write("%f %f %f " % (sp1, sp2, sp3))
# ofs.write('</DataArray>')
# ofs.write('<DataArray type="Float32" Name="Stress" NumberOfComponents="9" format="ascii">')
# for key in self.eids:
# s11, s22, s33, s12, s13, s23 = self.stress[key][0:]
# ofs.write("%f %f %f %f %f %f %f %f %f " % (s11, s12, s13, s12, s22, s23, s13, s23, s33))
# ofs.write('</DataArray>')
# ofs.write('</CellData>')
# ofs.write('</Piece>')
# ofs.write('</StructuredGrid>')
# ofs.write('</VTKFile>')
# ofs.close()

Binary file not shown.

Binary file not shown.

@ -115,30 +115,3 @@ class Temperature(object):
# print(temp)
ofs.write("%f " % (temp,))
# ### define PointsData element ###
# ofs.write('<PointData Vectors="displacement">')
# ofs.write('<DataArray type="Float32" NumberOfComponents="3" format="ascii" Name="displacement">')
# for key in self.nids:
# ux, uy, uz = self.displacement[key]
# ofs.write("%f %f %f " % (ux, uy, uz))
# ofs.write('</DataArray>')
# ofs.write('</PointData>')
# ### define CellData element ###
# ofs.write('<CellData Vectors="PrincipalStress" Tensors="Stress">')
# ofs.write('<DataArray type="Float32" Name="PrincipalStress" NumberOfComponents="3" format="ascii">')
# for key in self.eids:
# sp1, sp2, sp3 = self.spstress[key][0:]
# ofs.write("%f %f %f " % (sp1, sp2, sp3))
# ofs.write('</DataArray>')
# ofs.write('<DataArray type="Float32" Name="Stress" NumberOfComponents="9" format="ascii">')
# for key in self.eids:
# s11, s22, s33, s12, s13, s23 = self.stress[key][0:]
# ofs.write("%f %f %f %f %f %f %f %f %f " % (s11, s12, s13, s12, s22, s23, s13, s23, s33))
# ofs.write('</DataArray>')
# ofs.write('</CellData>')
# ofs.write('</Piece>')
# ofs.write('</StructuredGrid>')
# ofs.write('</VTKFile>')
# ofs.close()

Loading…
Cancel
Save