├── README.md ├── ReadField.py ├── ReadFields_to_History.py ├── ReadHistory.py └── ReadHistory2.0.py /README.md: -------------------------------------------------------------------------------- 1 | # Python_Abaqus 2 | Codes to extract data from Abaqus ODBs with Python scripts 3 | History >> Extract data from all the frames in a step. 4 | Field >> Extract data from 1 given frame for all the nodes. 5 | All the outputs from Python are written into .DAT files 6 | -------------------------------------------------------------------------------- /ReadField.py: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy as np 3 | from odbAccess import * 4 | homedir = os.getcwd() 5 | t = 'C13_010_20' 6 | f=40 7 | odb = openOdb(path=homedir+'/'+ t +'.odb') 8 | #step_name = 'Transition' 9 | step_name ='TANG_DISPL' 10 | 11 | frame = odb.steps[step_name].frames[f] 12 | CN_F=frame.fieldOutputs['CNORMF'] 13 | Copen=frame.fieldOutputs['COPEN'] 14 | Cpress=frame.fieldOutputs['CPRESS'] 15 | U=frame.fieldOutputs['U'] 16 | CSLIP1 = frame.fieldOutputs['CSLIP1'] 17 | CNAREA=frame.fieldOutputs['CNAREA'] 18 | 19 | #sets 20 | nodeset1=odb.rootAssembly.nodeSets['PLATE_CONTACT'] 21 | 22 | #node_left=odb.rootAssembly.nodeSets['PLATE_LEFT'] 23 | #node_right=odb.rootAssembly.nodeSets['PLATE_RIGHT'] 24 | 25 | #Get data 26 | CnFV= CN_F.getSubset(region=nodeset1).values 27 | CopV= Copen.getSubset(region=nodeset1).values 28 | CPV= Cpress.getSubset(region=nodeset1).values 29 | UV = U.getSubset(region=nodeset1).values 30 | CSLIP1 = CSLIP1.getSubset(region=nodeset1).values 31 | CnAV= CNAREA.getSubset(region=nodeset1).values 32 | #Write coordinates 33 | file_con = t +'_Fields_' +step_name +'_Frame_' + str(f) + '.dat' 34 | file_contact = homedir+'/' + file_con 35 | file_coordinates = t +'_Coordinates_' +step_name +'_Frame_'+ str(f) + '.dat' 36 | dispFile = open(file_contact,'w') 37 | 38 | nodes_array = nodeset1.nodes[0] 39 | map = np.zeros((len(nodes_array),4)) 40 | 41 | for iii in range(len(nodes_array)): 42 | map[iii][0] = nodes_array[iii].label 43 | map[iii][1] = nodes_array[iii].coordinates[0] 44 | map[iii][2] = nodes_array[iii].coordinates[1] 45 | map[iii][3] = nodes_array[iii].coordinates[2] 46 | 47 | 48 | dispFile.write('Ind,Node,N0_real,N0_gap,PRESS,U1, U2,U3, CSLIP1, CNAREA \n') 49 | for v in range(len(CnFV)): 50 | slip1 = CSLIP1[v].data 51 | cnarea = CnAV[v].data 52 | normalforce = np.sqrt(CnFV[v].data[0]**2+CnFV[v].data[1]**2+CnFV[v].data[2]**2) 53 | press_read = CPV[v].data; u1 = UV[v].data[0];u2 = UV[v].data[1];u3 = UV[v].data[2];n0_print = normalforce 54 | if normalforce< 1e-7: n0_print = -np.abs(CopV[v].data) 55 | dispFile.write('%10d, %10d, %15.10f, %15.10f, %15.10f, %15.10f, %15.10f, %15.10f, %15.10f, %15.10f \n' % \ 56 | (v+1, CnFV[v].nodeLabel, normalforce, n0_print, press_read, u1, u2, u3, slip1, cnarea)) 57 | 58 | print (file_coordinates) 59 | print (file_con) 60 | 61 | np.savetxt(file_coordinates,map) 62 | dispFile.close() 63 | # Write a matrix with the sorted valued of CPress and U2 64 | #cont_surf = np.zeros((len(nodes_array),4)) -------------------------------------------------------------------------------- /ReadFields_to_History.py: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy as np 3 | #import cv2 4 | from odbAccess import * 5 | homedir = os.getcwd() 6 | 7 | t = 't_82_adj' 8 | 9 | odb = openOdb(path=homedir+'/'+ t +'.odb') 10 | new_folder = homedir + '\\' + t + '_frames' 11 | if not (os.path.exists(new_folder)):#if the file does not exist 12 | os.mkdir(new_folder)#Create the writing directory 13 | ##step_name = 'Transition' 14 | step_name ='TANG_DISPL' 15 | frames = odb.steps['TANG_DISPL'].frames#get the number of frames for the for loop 16 | #for f in odb.steps['TANG_DISPL'].frames: 17 | for f in range(0,len(frames)): 18 | frame = odb.steps[step_name].frames[f] 19 | CN_F=frame.fieldOutputs['CNORMF'] 20 | Copen=frame.fieldOutputs['COPEN'] 21 | Cpress=frame.fieldOutputs['CPRESS'] 22 | U=frame.fieldOutputs['U'] 23 | CSLIP1 = frame.fieldOutputs['CSLIP1'] 24 | CNAREA=frame.fieldOutputs['CNAREA'] 25 | 26 | #sets 27 | nodeset1=odb.rootAssembly.nodeSets['PLATE_CONTACT'] 28 | 29 | #node_left=odb.rootAssembly.nodeSets['PLATE_LEFT'] 30 | #node_right=odb.rootAssembly.nodeSets['PLATE_RIGHT'] 31 | 32 | #Get data 33 | CnFV= CN_F.getSubset(region=nodeset1).values 34 | CopV= Copen.getSubset(region=nodeset1).values 35 | CPV= Cpress.getSubset(region=nodeset1).values 36 | UV = U.getSubset(region=nodeset1).values 37 | CSLIP1 = CSLIP1.getSubset(region=nodeset1).values 38 | CnAV= CNAREA.getSubset(region=nodeset1).values 39 | #Write coordinates 40 | file_con = t +'_Fields_' +step_name +'_Frame_' + str(f) + '.dat' 41 | file_contact = new_folder +'/' + file_con 42 | file_coordinates = new_folder + '/' + t +'_Coordinates_' +step_name +'_Frame_'+ str(f) + '.dat' 43 | dispFile = open(file_contact,'w') 44 | dispFile.write('Ind,Node,N0_real,N0_gap,PRESS,U1, U2,U3, CSLIP1, CNAREA \n') 45 | 46 | 47 | nodes_array = nodeset1.nodes[0] 48 | map = np.zeros((len(nodes_array),4)) 49 | 50 | for iii in range(len(nodes_array)): 51 | map[iii][0] = nodes_array[iii].label 52 | map[iii][1] = nodes_array[iii].coordinates[0] 53 | map[iii][2] = nodes_array[iii].coordinates[1] 54 | map[iii][3] = nodes_array[iii].coordinates[2] 55 | 56 | 57 | for v in range(len(CnFV)): 58 | slip1 = CSLIP1[v].data 59 | cnarea = CnAV[v].data 60 | normalforce = np.sqrt(CnFV[v].data[0]**2+CnFV[v].data[1]**2+CnFV[v].data[2]**2) 61 | press_read = CPV[v].data; u1 = UV[v].data[0];u2 = UV[v].data[1];u3 = UV[v].data[2];n0_print = normalforce 62 | if normalforce< 1e-7: n0_print = -np.abs(CopV[v].data) 63 | dispFile.write('%10d, %10d, %15.10f, %15.10f, %15.10f, %15.10f, %15.10f, %15.10f, %15.10f, %15.10f \n' % \ 64 | (v+1, CnFV[v].nodeLabel, normalforce, n0_print, press_read, u1, u2, u3, slip1, cnarea)) 65 | # 66 | # print (file_coordinates) 67 | # print (file_con) 68 | # 69 | np.savetxt(file_coordinates,map) 70 | dispFile.close() 71 | 72 | print(int(f)) 73 | print (file_con) 74 | 75 | dispFile.close() 76 | -------------------------------------------------------------------------------- /ReadHistory.py: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy as np 3 | from odbAccess import * 4 | homedir = os.getcwd() 5 | t = 't_82' 6 | odb = openOdb(path=homedir+'/'+ t +'.odb') 7 | frames = odb.steps['TANG_DISPL'].frames 8 | file_con = t +'_History.dat' 9 | #file_con = t +'_History.dat' 10 | file_contact = homedir+'/' + file_con 11 | dispFile = open(file_contact,'w') 12 | dispFile.write('Ind_frame,RF1_LEFT,RF1_right,U1_punch,CSLIP1_ave_contact, CNAREA_sum_contact, dt, U2_tip_center, U2_tip_right, U2_tip_left, U2_active_base \n') 13 | 14 | #for f in odb.steps['TANG_DISPL'].frames: 15 | for f in range(0,len(frames)): 16 | 17 | frame = odb.steps['TANG_DISPL'].frames[f] 18 | #Fields output 19 | U=frame.fieldOutputs['U'] 20 | #U2=frame.fieldOutputs['U.U2'] 21 | RF=frame.fieldOutputs['RF'] 22 | CSLIP1 = frame.fieldOutputs['CSLIP1'] 23 | COPEN = frame.fieldOutputs['COPEN'] 24 | CNAREA=frame.fieldOutputs['CNAREA'] 25 | #regions-sets 26 | nodeset1=odb.rootAssembly.nodeSets['PLATE_CONTACT'] 27 | node_punch=odb.rootAssembly.nodeSets['PUNCH_RP'] 28 | node_left=odb.rootAssembly.nodeSets['PLATE_LEFT'] 29 | node_right=odb.rootAssembly.nodeSets['PLATE_RIGHT'] 30 | tip_center = odb.rootAssembly.instances['TIP-1'].nodes[1]#any node in tip Does the job cause it is a rigid body 31 | tip_right = odb.rootAssembly.instances['TIP-2'].nodes[1]#any node in tip Does the job cause it is a rigid body 32 | tip_left = odb.rootAssembly.instances['TIP-3'].nodes[1]#any node in tip Does the job cause it is a rigid body 33 | active_bases=odb.rootAssembly.nodeSets['PIEZO_BASES_ACTIVE'] 34 | #tip_center = odb.rootAssembly.nodes[5] for some reason this does not work 35 | 36 | 37 | #time 38 | dt = frame.frameValue 39 | 40 | #Get Fields from regions - sets 41 | #UV_contact = U.getSubset(region=nodeset1).values 42 | UV_punch = U.getSubset(region=node_punch).values 43 | RF_left = RF.getSubset(region=node_left).values 44 | RF_right = RF.getSubset(region=node_right).values 45 | CSLIP_contact = CSLIP1.getSubset(region=nodeset1).values 46 | COPEN_contact = COPEN.getSubset(region=nodeset1).values 47 | CNAREA_contact = CNAREA.getSubset(region=nodeset1).values 48 | 49 | U_tip_center = U.getSubset(region=tip_center).values 50 | U_tip_right = U.getSubset(region=tip_right).values 51 | U_tip_left = U.getSubset(region=tip_left).values 52 | U_active_bases = U.getSubset(region=active_bases).values 53 | 54 | 55 | #Write coordinates 56 | #u1 = np.zeros(((len(UV_contact)),1)) 57 | cslip1 = np.zeros(((len(CSLIP_contact)),1)) 58 | cnarea = np.zeros(((len(CNAREA_contact)),1)) 59 | copen = np.zeros(((len(COPEN_contact)),1)) 60 | cslip1_adj = np.empty(((len(CSLIP_contact)),1)) 61 | cslip1_adj[:] = np.nan 62 | cnarea_adj = np.empty(((len(CNAREA_contact)),1)) 63 | cnarea_adj[:] = np.nan 64 | for n in range(len(CSLIP_contact)): 65 | #u1[n,0] = UV_contact[n].data[0] 66 | cslip1[n,0] = CSLIP_contact[n].data 67 | cnarea[n,0] = CNAREA_contact[n].data 68 | copen[n,0] = COPEN_contact[n].data 69 | 70 | U1_punch = UV_punch[0].data[0]# 0==>U1; 1==>U2;2==>U3 71 | U2_tip_center = U_tip_center[0].data[1] 72 | U2_tip_right = U_tip_right[0].data[1] 73 | U2_tip_left = U_tip_left[0].data[1] 74 | U2_active_bases = U_active_bases[0].data[1] 75 | 76 | cslip1_adj = cslip1[copen<=0]#just consider the values that are in contact copen negative 77 | cnarea_adj = cnarea[copen<=0] 78 | aux_cslip1 = np.abs(cslip1_adj) 79 | aux_cnarea = np.abs(cnarea_adj) 80 | cslip1_ave =np.mean(aux_cslip1[~np.isnan(aux_cslip1)]) 81 | cnarea_sum =np.sum(aux_cnarea[~np.isnan(aux_cnarea)]) 82 | RF1_left = RF_left[0].data[0] 83 | RF1_right = RF_right[0].data[0] 84 | 85 | 86 | 87 | dispFile.write('%10d, %15.10f, %15.10f, %15.10f, %15.10f, %15.10f , %15.10f , %15.10f , %15.10f , %15.10f , %15.10f\n' % \ 88 | (f+1, RF1_left, RF1_right, U1_punch, cslip1_ave, cnarea_sum, dt, U2_tip_center, U2_tip_right, U2_tip_left, U2_active_bases)) 89 | print(int(f)) 90 | 91 | print (file_contact) 92 | dispFile.close() 93 | -------------------------------------------------------------------------------- /ReadHistory2.0.py: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy as np 3 | from odbAccess import * 4 | homedir = os.getcwd() 5 | t = 'C13_101_2' 6 | odb = openOdb(path=homedir+'/'+ t +'.odb') 7 | frames = odb.steps['TANG_DISPL'].frames 8 | file_con = t +'_History_without_residual_CSLIP1_v2.dat' 9 | #file_con = t +'_History.dat' 10 | file_contact = homedir+'/' + file_con 11 | dispFile = open(file_contact,'w') 12 | dispFile.write('Ind_frame,RF1_LEFT,RF1_right,U1_punch,CSLIP1_ave_contact, CNAREA_sum_contact, dt, U2_tip_center, U2_tip_right, U2_tip_left, U2_active_base, U2_punch \n') 13 | #get the right dimension 14 | frame = odb.steps['TANG_DISPL'].frames[0] 15 | CSLIP1 = frame.fieldOutputs['CSLIP1'] 16 | COPEN = frame.fieldOutputs['COPEN'] 17 | nodeset1=odb.rootAssembly.nodeSets['PLATE_CONTACT'] 18 | CSLIP_contact = CSLIP1.getSubset(region=nodeset1).values 19 | COPEN_contact = COPEN.getSubset(region=nodeset1).values 20 | dim = len(CSLIP_contact) 21 | 22 | cslip1 = np.zeros((dim, 2))#store both: current(2) and previous(1) nodal info. 23 | cslip1_res = np.zeros(dim) 24 | copen = np.zeros((dim, 2))#store both: current(2) and previous(1) nodal info. 25 | 26 | 27 | #regions-sets 28 | nodeset1=odb.rootAssembly.nodeSets['PLATE_CONTACT'] 29 | node_punch=odb.rootAssembly.nodeSets['PUNCH_RP'] 30 | node_left=odb.rootAssembly.nodeSets['PLATE_LEFT'] 31 | node_right=odb.rootAssembly.nodeSets['PLATE_RIGHT'] 32 | tip_center = odb.rootAssembly.instances['TIP-1'].nodes[1]#any node in tip Does the job cause it is a rigid body 33 | tip_right = odb.rootAssembly.instances['TIP-2'].nodes[1]#any node in tip Does the job cause it is a rigid body 34 | tip_left = odb.rootAssembly.instances['TIP-3'].nodes[1]#any node in tip Does the job cause it is a rigid body 35 | active_bases=odb.rootAssembly.nodeSets['PIEZO_BASES_ACTIVE'] 36 | #tip_center = odb.rootAssembly.nodes[5] for some reason this does not work 37 | 38 | #for f in odb.steps['TANG_DISPL'].frames: 39 | for f in range(0,len(frames)): 40 | 41 | 42 | frame = odb.steps['TANG_DISPL'].frames[f] 43 | #Fields output 44 | U=frame.fieldOutputs['U'] 45 | RF=frame.fieldOutputs['RF'] 46 | CSLIP1 = frame.fieldOutputs['CSLIP1'] 47 | COPEN = frame.fieldOutputs['COPEN'] 48 | CNAREA=frame.fieldOutputs['CNAREA'] 49 | 50 | #time 51 | dt = frame.frameValue 52 | 53 | #Get Fields from regions - sets 54 | UV_punch = U.getSubset(region=node_punch).values 55 | RF_left = RF.getSubset(region=node_left).values 56 | RF_right = RF.getSubset(region=node_right).values 57 | CSLIP_contact = CSLIP1.getSubset(region=nodeset1).values 58 | COPEN_contact = COPEN.getSubset(region=nodeset1).values 59 | CNAREA_contact = CNAREA.getSubset(region=nodeset1).values 60 | 61 | U_tip_center = U.getSubset(region=tip_center).values 62 | U_tip_right = U.getSubset(region=tip_right).values 63 | U_tip_left = U.getSubset(region=tip_left).values 64 | U_active_bases = U.getSubset(region=active_bases).values 65 | 66 | #Initialise output variables 67 | cnarea = np.zeros(dim) 68 | cslip1_adj = np.empty(dim) 69 | cslip1_adj[:] = np.nan 70 | cnarea_adj = np.empty(dim) 71 | cnarea_adj[:] = np.nan 72 | if f==0: 73 | for n in range(dim): 74 | cnarea[n] = CNAREA_contact[n].data 75 | copen[n, 1] = COPEN_contact[n].data 76 | cslip1[n, 1] = CSLIP_contact[n].data 77 | if f>0: 78 | copen[:,0] = copen[:,1] 79 | cslip1[:,0] = cslip1[:,1] 80 | for n in range(dim): 81 | cnarea[n] = CNAREA_contact[n].data 82 | copen[n,1] = COPEN_contact[n].data 83 | cslip1[n,1] = CSLIP_contact[n].data 84 | if copen[n,1]<0 and copen[n,0]>0: #now(1) in contact and before(0)not in contact 85 | #if copen[n,1]>0 and copen[n,0]<0: #now(1) not in contact and before(0) in contact 86 | cslip1_res[n] = cslip1[n,0] 87 | cslip1[n,1]= cslip1[n,1]-cslip1_res[n]#substract the residual left from the previous step 88 | if copen[n,1]<0 and copen[n,0]<0: #now (1) in contact and before(0) in contact too 89 | cslip1[n,1]= cslip1[n,1]-cslip1_res[n]#the residual applies to the entire time the node is in contact 90 | 91 | #just consider current values now: 92 | cslip1_curr = cslip1[:,1]#second column 93 | copen_curr = copen[:,1] 94 | U1_punch = UV_punch[0].data[0]# 0==>U1; 1==>U2;2==>U3 95 | U2_punch = UV_punch[0].data[1] 96 | U2_tip_center = U_tip_center[0].data[1] 97 | U2_tip_right = U_tip_right[0].data[1] 98 | U2_tip_left = U_tip_left[0].data[1] 99 | U2_active_bases = U_active_bases[0].data[1] 100 | 101 | cslip1_adj = cslip1_curr[copen_curr<0]#just consider the values that are in contact: copen negative 102 | cnarea_adj = cnarea[copen_curr<0] 103 | #aux_cslip1 = np.abs(cslip1_adj) 104 | aux_cnarea = np.abs(cnarea_adj) 105 | #cslip1_ave =np.mean(aux_cslip1[~np.isnan(aux_cslip1)]) 106 | cslip1_ave =np.mean(cslip1_adj[~np.isnan(cslip1_adj)]) 107 | cnarea_sum =np.sum(aux_cnarea[~np.isnan(aux_cnarea)]) 108 | RF1_left = RF_left[0].data[0] 109 | RF1_right = RF_right[0].data[0] 110 | 111 | 112 | 113 | dispFile.write('%10d, %15.10f, %15.10f, %15.10f, %15.10f, %15.10f , %15.10f , %15.10f , %15.10f , %15.10f , %15.10f , %15.10f\n' % \ 114 | (f+1, RF1_left, RF1_right, U1_punch, cslip1_ave, cnarea_sum, dt, U2_tip_center, U2_tip_right, U2_tip_left, U2_active_bases, U2_punch)) 115 | print(int(f)) 116 | 117 | print (file_contact) 118 | dispFile.close() 119 | --------------------------------------------------------------------------------