I have a very simple FE model, a cube created in abaqus meshed with 3D linear tetrahedral elements (C3D4 elements). I am trying to write a VTK file from an abaqus .inp file and visualise it Paraview. I want to do this because I have many complicated FE models for which I have run simulation iteratively and will have various element output which is not possible to make a contour plot of the model in abaqus. But When I open the VTK file several elements in the model are missing and I am not able to solve the issue.
I wrote a python script which reads the .inp file, extract all the elements, nodes and its connectivity and writes a VTK file.
inp_file = r'Job-1.inp'
with open(inp_file,'r') as f:
contents = f.readlines()
part = r'*Part, name=CUBE'
total_nodes = 156
for i,line in enumerate(contents):
if part in line:
node_idx = i
node_connection = contents[node_idx+2:node_idx+2+total_nodes]
element_type = r'*Element, type=C3D4'
total_elements = 576
for i,line in enumerate(contents):
if element_type in line:
element_idx = i
element_connection = contents[element_idx + 1 : element_idx + total_elements + 1]
x = []
y = []
z = []
node_num = []
for i in range(total_nodes):
node_num.append(float(node_connection[i].replace(',','').split()[0]))
x.append(float(node_connection[i].replace(',','').split()[1]))
y.append(float(node_connection[i].replace(',','').split()[2]))
z.append(float(node_connection[i].replace(',','').split()[3]))
node_coordinates = np.column_stack((x,y,z))
elements, node1, node2, node3, node4, = ([] for i in range(5))
for i in range(total_elements):
elements.append(int(element_connection[i].replace(',','').split()[0]))
node1.append(int(element_connection[i].replace(',','').split()[1]))
node2.append(int(element_connection[i].replace(',','').split()[2]))
node3.append(int(element_connection[i].replace(',','').split()[3]))
node4.append(int(element_connection[i].replace(',','').split()[4]))
element_connect = np.column_stack((node1, node2, node3, node4))
with open('mesh.vtk','w') as f:
f.write('# vtk DataFile Version 2.0\n')
f.write('Unstructured Grid\n')
f.write('ASCII\n')
f.write('DATASET UNSTRUCTURED_GRID\n')
f.write('POINTS {} FLOAT\n'.format(np.shape(node_coordinates)[0]))
for i in range(len(x)):
f.write('{} '.format(x[i]))
f.write('{} '.format(y[i]))
f.write('{}'.format(z[i]))
f.write('\n')
f.write('CELLS {} {}\n'.format(total_elements, total_elements*5))
for i in range(len(node1)):
f.write('4 {} {} {} {}\n'.format(node1[i], node2[i], node3[i], node4[i]))
f.write('CELL_TYPES {}\n'.format(len(node1)))
for i in range(total_elements):
f.write('10\n')
But the open the VTK file in paraview, there are many elements missing. I do not see where I went wrong. I used meshio to convert the inp file directly to VTK and it works. But for my purpose, meshio is not a good solution as the geometry and simulations results is not consistent because of that I want to write a VTK file. I have been stuck in creating a VTK file for a long time and I cannot find out where I went wrong. So any help is very much appreciated.
Thank you
Regards