-
Notifications
You must be signed in to change notification settings - Fork 0
/
MohrCircle_stress.py
234 lines (214 loc) · 10.9 KB
/
MohrCircle_stress.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import numpy as np
import matplotlib.pyplot as plt
from sympy.solvers import solve
from sympy import Symbol
# reqAngle = 30
# isAngle = True
class Stress_MohrCircle():
def __init__(self, σxx,σyy,σxy,σzz = 0,σyz = 0,σzx = 0):
self.σxx = σxx
self.σyy = σyy
self.σzz = σzz
self.σxy = σxy
self.σyz = σyz
self.σzx = σzx
self.ndims = 3
self.isGraph = False
self.isAngle_stress = False
self.reqAngle_stress_2d = None
self.reqAngle_normal_3d = [0,0,0]
def update_annot(self, point, idx):
posx, posy = [point.get_xdata()[idx], point.get_ydata()[idx]]
self.annot.xy = (posx, posy)
text = f'({posx:.2f} , {posy:.2f})'
self.annot.set_text(text)
self.annot.get_bbox_patch().set_alpha(0.4)
def hover(self, event):
vis = self.annot.get_visible()
if event.inaxes == self.ax:
for point in self.pyg_pts:
cont, ind = point.contains(event)
if cont:
self.update_annot(point, ind['ind'][0])
self.annot.set_visible(True)
self.figs.canvas.draw_idle()
else:
if vis:
self.annot.set_visible(False)
self.figs.canvas.draw_idle()
def Find_Mohr_Circle(self):
# global isAngle, reqAngle
Stress = list(self.principal_stress)
Stress_tensor = self.σ_tensor
# print(Stress)
Stress.sort(reverse=True)
sigma1=Stress[0]
sigma2=Stress[1]
center1_2=round((sigma1+sigma2)/2, 4)
radius1_2=abs(sigma2-center1_2)
if self.ndims==3:
sigma3=Stress[2]
center1_3=round((sigma1+sigma3)/2, 4)
center2_3=round((sigma2+sigma3)/2, 4)
radius1_3=abs(sigma3-center1_3)
radius2_3=abs(sigma2-center2_3)
print("The Principal Stresses are: \nσ1: {0} \nσ2: {1} \nσ3: {2} \n".format(sigma1,sigma2,sigma3))
print("Maximum Shear Stress τ_max: " +str(round((sigma1-sigma3)/2, 3)))
print("\nThe centers of the circle are: \nC1: {0} \nC2: {1} \nC3: {2} \n".format(center1_3,center1_2,center2_3))
else:
print("The Principal Stresses are: \nσ1: {0} \nσ2: {1} \n".format(sigma1,sigma2))
print("Maximum Shear Stress τ_max: " +str(round((sigma1-sigma2)/2, 3)))
print("\nThe center of the circle are: \nC1: {0}".format(center1_2))
new_x_1, new_x_2,new_y_1,new_y_2 = None, None, None, None
sigma_NN,sigma_NS, princip_angle = None, None, None
radius = []
initial_pts = []
self.ax = None
self.figs = None
if self.isGraph:
self.figs, self.ax = plt.subplots()
if self.ndims == 3:
radius = [radius1_2,radius2_3,radius1_3]
mohr_center=[[center1_3,0],[center2_3,0],[center1_2,0]]
mohr_sigma=[[sigma1,0],[sigma2,0],[sigma3,0]]
if(self.isAngle_stress):
l = self.reqAngle_normal_3d[0]
m = self.reqAngle_normal_3d[1]
n2 = 1 - l**2 - m**2
print(l,m,n2)
if(n2<0):
print("Invalid Angle input!!!!!")
raise ValueError('Bad input!')
# else:
n = np.sqrt(n2)
sigma_NN = (l**2)*sigma1 + (m**2)*sigma2 + (n**2)*sigma3
sigma_NS = np.sqrt((l**2)*sigma1**2 + (m**2)*sigma2**2 + (n**2)*sigma3**2 - sigma_NN**2)
if(self.isGraph):
self.ax.set(xlim=(center1_3-(radius1_3+1), sigma1+1), ylim = (-(radius1_3+1), radius1_3+1))
self.ax.plot(*zip(*mohr_center), marker='o', color='r', ls='')
self.ax.plot(*zip(*mohr_sigma), marker='o', color='b', ls='')
for i in range(len(mohr_sigma)):
self.ax.annotate("σ"+str(i+1),tuple(mohr_sigma[i]),fontsize=12)
for i in range(len(mohr_center)):
self.ax.annotate("C"+str(i+1),tuple(mohr_center[i]),fontsize=12)
Circle1_3 = plt.Circle((center1_3, 0),abs(radius1_3),fill=False, color="red")
Circle2_3 = plt.Circle((center2_3, 0),abs(radius2_3),fill=False, color="blue")
Circle1_2 = plt.Circle((center1_2, 0),abs(radius1_2),fill=False, color="green")
if(self.isAngle_stress):
new_points = [[sigma_NN,sigma_NS]]
self.ax.annotate('(σNN,σNS)',tuple(new_points[0]),fontsize = 12)
self.ax.plot(*zip(*new_points),marker='o', color='purple', ls='')
# n = self.reqAngle_normal_3d[2]
self.ax.add_artist(Circle1_3)
self.ax.add_artist(Circle1_2)
self.ax.add_artist(Circle2_3)
self.ax.minorticks_on()
elif self.ndims ==2:
radius = [radius1_2]
mohr_center=[[center1_2,0]]
mohr_sigma=[[sigma1,0],[sigma2,0]]
try:
curr_angle = np.arctan((-Stress_tensor[0][1])/(Stress_tensor[0][0]-center1_2))
# princip_angle = np.arcsin(-Stress_tensor[0][1]/radius1_2)/2
princip_angle = np.arctan(-Stress_tensor[0][1]/(-Stress_tensor[0][0] +center1_2))/2
except:
if(Stress_tensor[0][1]>=0):
curr_angle = np.deg2rad(90)
princip_angle = np.arcsin(-Stress_tensor[0][1]/radius1_2)/2
else:
curr_angle = np.deg2rad(-90)
princip_angle = np.arcsin(-Stress_tensor[0][1]/radius1_2)/2
if(self.isAngle_stress):
total_angle = curr_angle + np.deg2rad(2*self.reqAngle_stress_2d)
# print(np.rad2deg(total_angle))
new_x_1 = radius1_2*np.cos(total_angle) + center1_2
new_y_1 = radius1_2*np.sin(total_angle)
new_x_2 = radius1_2*np.cos(total_angle + np.deg2rad(180))+center1_2
new_y_2 = radius1_2*np.sin(total_angle + np.deg2rad(180))
if(self.isGraph):
self.ax.set(xlim=(center1_2-(radius1_2+1), sigma1+1), ylim = (-(radius1_2+1), radius1_2+1))
self.ax.plot(*zip(*mohr_center), marker='o', color='r', ls='')
self.ax.plot(*zip(*mohr_sigma), marker='o', color='b', ls='')
initial_pts = [[Stress_tensor[0][0],-Stress_tensor[0][1]],[Stress_tensor[1][1],Stress_tensor[0][1]]]
self.ax.annotate('(σxx,-τxy)',tuple([Stress_tensor[0][0],-Stress_tensor[0][1]]),fontsize = 12)
self.ax.annotate('σyy,τxy)',tuple([Stress_tensor[1][1],Stress_tensor[0][1]]),fontsize = 12)
self.ax.plot(*zip(*initial_pts),marker='o', color='black', ls='')
self.ax.plot([Stress_tensor[0][0],Stress_tensor[1][1]],[-Stress_tensor[0][1],Stress_tensor[0][1]])
if(self.isAngle_stress):
new_points = [[new_x_1,new_y_1],[new_x_2,new_y_2]]
self.ax.annotate('(σ\'yy, τ\'xy)',tuple(new_points[0]),fontsize = 12)
self.ax.annotate('(σ\'xx,-τ\'xy)',tuple(new_points[1]),fontsize = 12)
self.ax.plot(*zip(*new_points),marker='o', color='black', ls='')
self.ax.plot([new_x_1,new_x_2],[new_y_1,new_y_2])
for i in range(len(mohr_sigma)):
self.ax.annotate("σ"+str(i+1),tuple(mohr_sigma[i]),fontsize=12)
for i in range(len(mohr_center)):
self.ax.annotate("C"+str(i+1),tuple(mohr_center[i]),fontsize=12)
Circle1_2 = plt.Circle((center1_2, 0),abs(radius1_2),fill=False, color="green")
self.ax.add_artist(Circle1_2)
if(self.isGraph):
if self.ndims==2:
points = mohr_center+mohr_sigma+[[new_x_1,new_y_1],[new_x_2,new_y_2]]+initial_pts
else:
points = mohr_center+mohr_sigma+[[sigma_NN,sigma_NS]]
self.pyg_pts = []
for i in range(len(points)):
l, = self.ax.plot(*zip(*points), marker='o', color='r', ls='')
self.pyg_pts.append(l)
self.annot = self.ax.annotate("", xy=(0, 0), xytext=(20, 20), textcoords="offset points",
bbox=dict(boxstyle="round", fc="w"),
arrowprops=dict(arrowstyle="->"))
self.annot.set_visible(False)
self.figs.canvas.mpl_connect("motion_notify_event", self.hover)
self.ax.minorticks_on()
self.ax.set_aspect('equal', adjustable='box')
self.ax.spines['bottom'].set_position('center')
self.ax.xaxis.set_ticks_position('bottom')
self.ax.yaxis.set_ticks_position('left')
self.ax.grid(which='major', axis='both', linestyle ='--')
plt.xlabel("σ Normal")
plt.ylabel("σ Shear")
plt.show()
plt.close('all')
if(self.ndims == 2):
return mohr_center, mohr_sigma, radius ,(new_x_1, new_y_1), (new_x_2, new_y_2), princip_angle
else:
return mohr_center, mohr_sigma, radius ,(sigma_NN, sigma_NS)
def find_Principal_Stress(self):
if self.σ_tensor.shape == (3,3):
a=self.σ_tensor.copy()
self.I1= a[0][0] + a[1][1] + a[2][2]
self.I2= a[0][0]*a[1][1] + a[1][1]*a[2][2] + a[0][0]*a[2][2] - a[0][1]**2 - a[0][2]**2 -a[1][2]**2
self.I3 = np.linalg.det(self.σ_tensor)
a=np.linalg.eig(a)[0]
self.principal_stress=np.round(a, 4)
return Stress_MohrCircle.Find_Mohr_Circle(self)
elif self.σ_tensor.shape == (2,2):
a=self.σ_tensor.copy()
self.I1= a[0][0] + a[1][1]
# print(a[0][1])
self.I2= a[0][0]*a[1][1] - a[0][1]**2
a=np.linalg.eig(a)[0]
self.principal_stress=np.round(a, 4)
return Stress_MohrCircle.Find_Mohr_Circle(self)
def stress_execute(self):
# print()
if self.ndims==2:
self.σ_tensor = [[self.σxx , self.σxy ],
[self.σxy , self.σyy ]]
else:
self.σ_tensor = [[self.σxx , self.σxy , self.σzx],
[self.σxy , self.σyy , self.σyz],
[self.σzx , self.σyz , self.σzz]]
self.σ_tensor= np.array(self.σ_tensor)
# print(σ_tensor.shape)
return Stress_MohrCircle.find_Principal_Stress(self)
# m = Stress_MohrCircle(σxx= 34.3, σyy= 74,σzz= 3, σxy= -83.9, σyz= 5, σzx= 6)
# m.ndims = 2
# m.isGraph = True
# # m.isAngle_stress = True
# # m.reqAngle_normal_3d = [np.cos(0), round(np.cos(0),3), np.cos(90)]
# # print(m.reqAngle_normal_3d)
# m.isAngle_stress = True
# m.reqAngle_stress_2d = 54.6
# m.stress_execute()