Symbolic Stress Notebook
[1]:
import sympy as sp
from mechpy.core.symbolic.stress import (
SymbolicStressTensor,
)
Symbolic Stress
Init Method
[2]:
s_11, s_22, s_33, s_23, s_13, s_12 = sp.symbols(
"\\sigma_11 \\sigma_22 \\sigma_33 \\sigma_23 \\sigma_13 \\sigma_12"
)
data = sp.NDimArray([s_11, s_22, s_33, s_23, s_13, s_12])
sigma = SymbolicStressTensor(data)
display(sigma.data)
$\displaystyle \left[\begin{matrix}\sigma_{11} & \sigma_{22} & \sigma_{33} & \sigma_{23} & \sigma_{13} & \sigma_{12}\end{matrix}\right]$
Create Method
Default Notation
[3]:
stress_tensor = SymbolicStressTensor.create()
display(stress_tensor.data)
display(stress_tensor.notation)
display(stress_tensor.to_general().data)
$\displaystyle \left[\begin{matrix}\sigma_{1} & \sigma_{2} & \sigma_{3} & \sigma_{4} & \sigma_{5} & \sigma_{6}\end{matrix}\right]$
'standard'
$\displaystyle \left[\begin{matrix}\sigma_{11} & \sigma_{12} & \sigma_{13}\\\sigma_{12} & \sigma_{22} & \sigma_{23}\\\sigma_{13} & \sigma_{23} & \sigma_{33}\end{matrix}\right]$
Voigt Notation
[4]:
stress_tensor = SymbolicStressTensor.create(notation="voigt")
display(stress_tensor.data)
display(stress_tensor.notation)
display(stress_tensor.to_general().data)
$\displaystyle \left[\begin{matrix}\sigma_{11} & \sigma_{22} & \sigma_{33} & \sigma_{23} & \sigma_{13} & \sigma_{12}\end{matrix}\right]$
'voigt'
$\displaystyle \left[\begin{matrix}\sigma_{11} & \sigma_{12} & \sigma_{13}\\\sigma_{12} & \sigma_{22} & \sigma_{23}\\\sigma_{13} & \sigma_{23} & \sigma_{33}\end{matrix}\right]$
Custom name
[5]:
name = sp.symbols("\sigma^1")
display(name)
stress_tensor = SymbolicStressTensor.create(name=name, notation="voigt")
display(stress_tensor.to_general().data)
$\displaystyle \sigma^{1}$
$\displaystyle \left[\begin{matrix}\sigma^{1}_{11} & \sigma^{1}_{12} & \sigma^{1}_{13}\\\sigma^{1}_{12} & \sigma^{1}_{22} & \sigma^{1}_{23}\\\sigma^{1}_{13} & \sigma^{1}_{23} & \sigma^{1}_{33}\end{matrix}\right]$
[6]:
display(stress_tensor.normal_components())
display(stress_tensor.shear_components())
display(stress_tensor.pressure())
$\displaystyle \left[\begin{matrix}\sigma^{1}_{11} & \sigma^{1}_{22} & \sigma^{1}_{33}\end{matrix}\right]$
$\displaystyle \left[\begin{matrix}\sigma^{1}_{23} & \sigma^{1}_{13} & \sigma^{1}_{12}\end{matrix}\right]$
$\displaystyle \frac{\sigma^{1}_{11} + \sigma^{1}_{22} + \sigma^{1}_{33}}{3}$
Tresca and Von Mises
[7]:
stress_tensor = SymbolicStressTensor.create(notation="voigt")
display(stress_tensor.data)
$\displaystyle \left[\begin{matrix}\sigma_{11} & \sigma_{22} & \sigma_{33} & \sigma_{23} & \sigma_{13} & \sigma_{12}\end{matrix}\right]$
subs using keys
[8]:
s_11 = stress_tensor[0]
subs = {
1: s_11,
2: s_11,
3: 0,
4: 1,
}
stress_tensor.subs_tensor_components(subs)
display(stress_tensor.data)
$\displaystyle \left[\begin{matrix}\sigma_{11} & \sigma_{11} & \sigma_{11} & 0 & 1 & \sigma_{12}\end{matrix}\right]$
subs using symbols
[9]:
subs = {
s_11: 0,
}
stress_tensor.subs(subs)
display(stress_tensor.data)
$\displaystyle \left[\begin{matrix}0 & 0 & 0 & 0 & 1 & \sigma_{12}\end{matrix}\right]$
[10]:
display(stress_tensor.tresca())
display(stress_tensor.von_mises())
$\displaystyle 2 \left|{\sqrt{\sigma_{12}^{2} + 1}}\right|$
$\displaystyle \sqrt{3 \sigma_{12}^{2} + 3}$