-
Notifications
You must be signed in to change notification settings - Fork 2
/
ReadData.py
executable file
·96 lines (85 loc) · 2.72 KB
/
ReadData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from odbAccess import*
odbFile = openOdb(path='./Direct_9grain.odb')
assembly = odbFile.rootAssembly
parts =assembly.instances
part =assembly.instances.values()[0]
#Define the output file for each part
#------------Stress strain, stress component, strenght, accumulated shear strain and vom-mises stress ------------------
StressStrainFile=open('./Sim.dat','w')
# get nodes number and nodal coordinates from the odb files
# Read the node locations for all nodes in all parts
lastStep=odbFile.steps['Step-1']
xs = []
ys = []
zs = []
# loop overeach node to get the dimension of the cubic and one node that lies in the specified surface
for key in parts.keys():
for n in parts[key].nodes:
x,y,z = n.coordinates
xs.append(x)
ys.append(y)
zs.append(z)
xmax = max(xs); xmin = min(xs)
ymax = max(ys); ymin = min(ys)
zmax = max(zs); zmin = min(zs)
width = xmax - xmin
thick = ymax - ymin
length = zmax - zmin
# get the node number to read the displacement
for key in parts.keys():
for n in parts[key].nodes:
y = n.coordinates[1]
if (y==ymax):
RFTargetNode=n.label
break
print ('Dimension of the model is:' , width, thick, length)
#Initialize the vectors for storing the data we are interested in.
DispVec=[]
RFVec=[]
XDisp=[]
YDisp=[]
laststepDisp=0.0
incr=0
#loop over each time step
totaltime=0.0;
lastStepTime=0.0;
for iStep in odbFile.steps.keys():
# start to extract the datat
print('Step: ', iStep)
lastStep=odbFile.steps[iStep]
for y in range(len(lastStep.frames)):
incr=incr+1
#print ('step increment', x)
#print ('total increment', incr)
lastFrame = lastStep.frames[y]
Time1=lastFrame.frameValue
#print('Time1', Time1)
ReactionForce = lastFrame.fieldOutputs['RF']
DisPlacement=lastFrame.fieldOutputs['U']
# apend zero value to the vectors
RFVec.append(0)
XDisp.append(0)
YDisp.append(0)
# start to read data.
# disp on the y+ face, all the nodes has the same value, one is enough
for v in DisPlacement.values:
if v.nodeLabel == RFTargetNode:
#DispVec.append(v.data[2]/width+laststepDisp)
Strain=v.data[1]/width
DispVec.append(Strain)
for v in ReactionForce.values:
if ys[v.nodeLabel-1] == ymax:
RFVec[incr-1]=RFVec[incr-1]+v.data[1]/length/thick
#---start to write data into files---
#---stress strain---
totalTime=lastStepTime+Time1
# StressStrainFile.write('%10.8E ' % totalTime)
StressStrainFile.write('%10.8E ' % DispVec[incr-1])
StressStrainFile.write('%10.8E\n' % RFVec[incr-1])
laststepDisp=Strain
lastStepTime=lastStepTime+Time1;
#print('laststepDisp is:', laststepDisp)
# start to close files
#---close odb files and stress strain file--
odbFile.close()
StressStrainFile.close()