Write a VTK file from an abaqus inp file

90 views Asked by At

I am trying to a write a VTK file from an abaqus .inp file using a python scirpt.The purpose of converting it to vtk is to visualise material properties varying according to the strains. As I am not experianced with VTK files, I created a small cube in abaqus and exported the .inp file. The FE model has 125 hex elements (C3D8) with 216 nodes. After writing the vtk, whenever I try to open the vtk file in paraview, there are several elements missing in the model.

I have written a python script that extracts all the nodal coordinates and the element connectivity with respect to its nodes from the inp and writes a vtk file. I followed the syntax mentioned in the vtk documentation but I am not able to figure where I am going wrong. It seems like I there is some mistakes in the section of writing the CELLS section of the VTK file.

with open('Job-1.inp','r') as f:
    contents = f.readlines()
node = '*Node'
node_conn = contents[9:225]

node_id, x, y, z = ([] for i in range(4))

for i in range(len(node_conn)):
    node_id.append(int(node_conn[i].split(',')[0].replace(' ','')))
    x.append(float(node_conn[i].split(',')[1].replace(' ','')))
    y.append(float(node_conn[i].split(',')[2].replace(' ','')))
    z.append(float(node_conn[i].split(',')[3].replace(' ','')))

elem_conn = contents[226:351]
elem_id,e1, e2, e3, e4, e5, e6, e7, e8 = ([] for i in range(9))

for i in range(len(elem_conn)):
    elem_id.append(int(elem_conn[i].split(',')[0].replace(' ', '')))
    e1.append(int(elem_conn[i].split(',')[1].replace(' ', '')) - 1)
    e2.append(int(elem_conn[i].split(',')[2].replace(' ', '')) - 1)
    e3.append(int(elem_conn[i].split(',')[3].replace(' ', '')) - 1)
    e4.append(int(elem_conn[i].split(',')[4].replace(' ', '')) - 1)
    e5.append(int(elem_conn[i].split(',')[5].replace(' ', '')) - 1)
    e6.append(int(elem_conn[i].split(',')[6].replace(' ', '')) - 1)
    e7.append(int(elem_conn[i].split(',')[7].replace(' ', '')) - 1)
    e8.append(int(elem_conn[i].split(',')[8].replace(' ', '')) - 1)

with open("test.vtk",'w') as f:
    f.write('# vtk DataFile Version 2.0\n')
    f.write('ASCII\n')
    f.write('DATASET UNSTRUCTURED_GRID\n')
    f.write('POINTS {} FLOAT\n'.format(len(node_id)))
    
    for i in range(len(node_id)):
        f.write('{} {} {}\n'.format(x[i],y[i],z[i]))
        
    f.write('CELLS {} {}\n'.format(len(elem_id),len(elem_id)*9))
    
    for i in range(len(elem_id)):
        f.write('8 {} {} {} {} {} {} {} {}\n'.format(e1[i],e2[i],e3[i],e4[i],
                                                     e5[i],e6[i],e7[i],e8[i]))
    
    f.write('CELL_TYPES {}\n'.format(len(elem_id)))
    for i in range(len(elem_id)):
        f.write('12\n')```

Your help is greatly appreciated.

P.S: 
The python code is not well written as I am a beginner.

Thank you
0

There are 0 answers