Stress Transform Example¶
This example demonstrates a symbolic and numeric 3D stress transformation.
Overview¶
The 3D stress transformation uses direction cosines to rotate the stress tensor:
\[\sigma' = L \cdot \sigma \cdot L^T\]
where L is the transformation matrix of direction cosines.
Code¶
1"""3D stress transformation example (symbolic + numeric)."""
2
3import sympy as sp
4
5from mechlab.mechanics.statics.stress import StressTransform
6
7
8def main() -> None:
9 st = StressTransform()
10
11 # Symbolic transform
12 sigma_xyz = st.transform()
13 print("Symbolic σ' = L σ Lᵀ:")
14 print(sigma_xyz)
15
16 # Numerical substitution
17 values = {
18 st.sxx: 100,
19 st.syy: 50,
20 st.szz: 75,
21 st.sxy: 20,
22 st.syz: 15,
23 st.sxz: 10,
24 st.l1: 1,
25 st.m1: 0,
26 st.n1: 0,
27 st.l2: 0,
28 st.m2: 1,
29 st.n2: 0,
30 st.l3: 0,
31 st.m3: 0,
32 st.n3: 1,
33 }
34
35 sigma_numeric = sp.Matrix(sigma_xyz).subs(values)
36 print("\nNumerical Transformed Stress Tensor:")
37 print(sigma_numeric)
38
39
40if __name__ == "__main__":
41 main()
Running¶
python examples/stress_transform.py
Output¶
The script outputs both symbolic and numeric results:
Symbolic: General transformation formula with SymPy symbols
Numeric: Concrete values after substituting specific direction cosines