-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmohr diagram.py
127 lines (101 loc) · 3.84 KB
/
mohr diagram.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
import math
from random import randrange
import matplotlib.pyplot as plt
def stress_tensor(sigma_x, sigma_y, tau_xy, theta, twotheta):
print("-----RESULTS-----")
sigma_theta = sigma_x * math.cos(math.radians(theta))**2 + sigma_y * math.sin(math.radians(theta))**2 + tau_xy * math.sin(math.radians(twotheta))
print("sigma x' =", sigma_theta)
sigma_y_prime = sigma_x * math.sin(math.radians(theta))**2 + sigma_y * math.cos(math.radians(theta))**2 - tau_xy * math.sin(math.radians(twotheta))
print("sigma y' =", sigma_y_prime)
tau_theta = ((sigma_y - sigma_x)/2) * math.sin(math.radians(twotheta)) + tau_xy * math.cos(math.radians(twotheta))
print("Tau x'y' =", tau_theta)
theta_1 = 0.5 * math.degrees(math.atan(((2 * tau_xy) / (sigma_x - sigma_y))))
print("theta_1 =", theta_1)
sigma_max = 0.5 * (sigma_x + sigma_y) + math.sqrt(((sigma_x - sigma_y) / 2)**2 + (tau_xy)**2)
sigma_min = 0.5 * (sigma_x + sigma_y) - math.sqrt(((sigma_x - sigma_y) / 2)**2 + (tau_xy)**2)
if abs(sigma_max) > abs(sigma_min):
sigma_1 = sigma_max
sigma_3 = sigma_min
else:
sigma_1 = sigma_min
sigma_3 = sigma_max
print("sigma_1 =", sigma_1)
print("sigma_3 =", sigma_3)
#drawing the mohr circle
radius = (sigma_max - sigma_min) / 2
circle_center = sigma_max - radius
fig = plt.figure(figsize=(10, 6))
ax = fig.add_subplot()
mohr_circle = plt.Circle((circle_center, 0), radius, fill = False)
ax.add_patch(mohr_circle)
ax.axis('equal')
# Move the x-axis to y = 0
ax.spines['bottom'].set_position('zero')
ax.spines['left'].set_position('zero')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
#plotting the scatter points on the circle
x = [sigma_x, sigma_y]
y = [tau_xy, tau_xy * -1]
t = (sigma_theta, circle_center)
h = (tau_theta, 0)
# Create a line connecting the two points
plt.plot(x, y, linestyle='-')
plt.plot(t, h, linestyle='-')
plt.scatter(x, y)
plt.scatter(t, h)
plt.title('mohr diagram')
plt.show()
return {
"sigma_theta": sigma_theta,
"sigma_y_prime": sigma_y_prime,
"tau_theta": tau_theta,
"sigma_max": sigma_max,
"sigma_min": sigma_min,
"radius": radius,
"circle_center": circle_center,
"mohr_circle": mohr_circle,
"fig": fig,
"ax": ax,
"x": x,
"y": y,
"t": t,
"h": h,
"sigma_1": sigma_1,
"sigma_3": sigma_3,
"theta_1": theta_1,
}
def generator(sigma_x, sigma_y, tau_xy, theta, twotheta):
print("sigma x =", sigma_x)
print("sigma y =", sigma_y)
print("tau xy =", tau_xy)
print("theta =", theta)
print("2 * theta = ", twotheta)
result = stress_tensor(sigma_x, sigma_y, tau_xy, theta, twotheta)
return result
print("Select operation.")
print("1. question generator")
print("2. stress tensor by inputs")
while True:
#taking input
choice = input("Enter choice (1/2): ")
#checking the choice
if choice == '1':
sigma_x = randrange(-50, 50)
sigma_y = randrange(-50, 50)
tau_xy = randrange(-20, 20)
theta = randrange(1, 10) * 5
twotheta = theta * 2
qa = generator(sigma_x, sigma_y, tau_xy, theta, twotheta)
print(qa)
elif choice == '2':
sigma_x = float(input("Enter sigma_x: "))
sigma_y = float(input("Enter sigma_y: "))
tau_xy = float(input("Enter tau_xy: "))
theta = float(input("Enter theta: "))
twotheta = theta * 2
stress_tensor(sigma_x, sigma_y, tau_xy, theta, twotheta)
print(stress_tensor)
else:
print("invalid input")
break