Python Code for Mohr’s Circle, – Stresses at a given angle theta, Principal stresses and their Planes, Maximum Shear Stress and its Plane

Hi,
You can use the Python to draw Mohr's Circle. In Structure Mechanics, taught to Civil Engineering and Mechanical engineering students, one has to find the stresses at given oblique planes.   Principal stresses and maximum shear stresses are important to find, and also their corresponding planes. One can use the stress transformation equations or Mohr's circle method to  find them. The following Python language code is prepared to be run on your IDE like Pycharm on your Computer. 

Elite Version of the Code:

There is an Elite version of this program, that comes with a beautiful GUI. It also gives you a properly annotated Mohr's Circle, and also it draws the oblique plane as a 2D element and shows the direction of stresses on it.  Check the images below to know what I am talking about. You can buy the Elite version of the Code, click on the link below.
Buy Here: Python Code for Mohr's Circle of Stresses
Typical Output of the Elite Version of Python Program for Mohr's Circle:
GUI for Mohr’s Circle Program (Python Tkinter)
A typical Mohr’s Circle drawn using Elite Version of the Python Code
2D stress element showing, Stresses on an Oblique Plane
Stress element showing Stresses on Maximum Shear Stress Plane.

If you want to get all the outputs as shown in the images above, Please go to the buy link.

Buy Here: 
Python Code for Mohr's Circle of Stresses

Please note the it also gives all the step by step calculations for radius, centre, principal stresses and orientations, and the stresses on the oblique plane. All these calculations with step by step explanations will be shown as output in the console window.

If you don’t need all that, just need to draw a simple Mohr’s Circle, please get the free version of the code. It is given below, for free.

Free Version of the code: 
def mohcircle():
import numpy as np
import matplotlib.pyplot as plt
import math

σx = float(input('σx = '))
σy = float(input('σy = '))
Ï„xy = float(input('Ï„xy = '))
u = input('stress unit = ')
w = float(input("Angle( in degrees) of plane's axis from x axis(+ve counter clockwise), θ = "))
θ = math.radians(w)
R = np.sqrt(0.25 * (σx - σy) ** 2 + (τxy) ** 2)
σavg = (σx + σy) / 2
ψ = np.linspace(0, 2 * np.pi, 360)
x = σavg + R * np.cos(ψ)
y = R * (np.sin(ψ))
φ1 = math.degrees(0.5 * math.atan(2 * τxy / (σx - σy)))
φ2 = φ1 + 90
σθ1 = σavg + R * np.cos(2 * np.radians(φ1) + 2 * θ)
σθ2 = σavg + R * np.cos(2 * np.radians(φ1) + 2 * θ + np.pi)
τθ = R * np.sin(2 * np.radians(φ1) + 2 * θ)
print(f'''
Radius, R = √(0.25*(σx-σy)^2 + τxy^2)
= √(0.25*({σx}-{σy})^2 + {τxy}^2) ={R} {u}

Average Stress,(acts at the Center of Mohr's Circle)
= σavg = (σx + σy)/2 = ({σx} + {σy})/2 = {σavg} {u}

Principal Stresses
σ1 = σavg + R = {σavg} + {R} = {σavg + R} {u}
σ2 = σavg - R = {σavg} - {R} = {σavg - R} {u}
Angle φ1 it makes with x-axis,
φ1 = 0.5(atan(2*τxy/(σx - σy)) = 0.5 * atan(2*{τxy}/({σx} - {σy})) = {φ1} degrees
Angle σ2 makes with x-axis = φ2 = φ1 + 90 = {φ2} degrees

Maximum Shear Stress = Ï„max = R = {R} {u}
It occurs at, α = φ1 + 45 = {φ1 + 45} degrees

Stresses at a plane with axis at θ anticlockwise from x axis,
σθ1 = σavg + R* Cos(2φ1 + 2θ) = {σavg} + {R}* Cos({2 * φ1 + 2 * θ})
= {σθ1}, {u}
σθ2 = σavg + R* Cos(2φ1 + 2θ + pi) =
{σθ2} {u}
τθ = R*Sin(2*φ1 + 2*θ) = {R * np.sin(2 * np.radians(φ1) + 2 * θ)} {u}

''')

plt.plot(x, y)
plt.plot([σavg - R - 10, σavg + R + 10], [0, 0], linestyle='--', color='black')
plt.plot([σavg, σavg], [-R - 10, R + 10], linestyle='--', color='black')
plt.plot([σx, σy], [τxy, -τxy], [σx, σx], [0, τxy], [σy, σy], [0, -τxy], linestyle='-', color='brown')
plt.plot([σθ1, σθ2], [τθ, -τθ], [σθ1, σθ1], [0, τθ], [σθ2, σθ2], [0, -τθ], linestyle='--', color='red')
plt.xlabel('σ (MPa)')
plt.ylabel('Ï„ (MPa)')
plt.title("Mohr's Circle")
plt.show()

mohcircle()
v = input('Exit? y/n ')
while v == "n":
mohcircle()
v = input('Exit? y/n ')
exit()

---- --------------
Thanks!

Leave a Comment

Your email address will not be published. Required fields are marked *

PHP Code Snippets Powered By : XYZScripts.com