```python
# https://colab.research.google.com/github/kassbohm/tm-snippets/blob/master/ipynb/TM_A/TM_0/trafo_tensor/trafo_tensor_1.ipynb

from sympy.physics.units import *
from sympy import *

"""
    Find normal stress using quantities wrt two different frames:

    1) The (x,y)-frame and
    2) The (xbar, ybar)-frame, with the (xbar, ybar)-placement specified
       by an angle.
    3) phi: This angle, measured from x to xbar, counted positive about the z-axis.

    This program shows, that:

    * The stress tensor is a bilinear form.
    * The stress is found by applying this form to vectors.
    * The result is independent on which frame is used.

"""

# Shortcuts for cos(phi) and sin(phi):
C, S = var("C, S")

sxx, syy, txy = var("sigma_{xx}, sigma_{yy}, tau_{xy}")
vx, vy = var("vx, vy")

T = Matrix([[sxx, txy],[txy, syy]])

prec = 2
phi_deg = 90

sub_list=[
    (C, cos(phi_deg*pi/180)),
    (S, sin(phi_deg*pi/180)),
    (sxx, -1 *Pa),
    (syy,  5 *Pa),
    (txy, 4 *Pa),
    ]

# Rotation matrix:
R = Matrix([[C, S],[-S, C]])

pprint("\nphi in deg:")
tmp = phi_deg
pprint(tmp)


pprint("\n\nComponents wrt (x,y):")
pprint("---------------------")

pprint("\nStress tensor in Pa:")
tmp = T
tmp = tmp.subs(sub_list)
tmp /= Pa
pprint(tmp)

n = Matrix([C,S])
t = Matrix([-S,C])
nt = n.transpose()
tt = t.transpose()

pprint("\nNormal vector n:")
tmp = n
pprint(tmp)
pprint("\nTangent vector t:")
tmp = t
pprint(tmp)
pprint("\nTranspose n' of n:")
tmp = nt
pprint(tmp)
pprint("\nTranspose t' of t:")
tmp = tt
pprint(tmp)

pprint(u"\nσ = n' T n in Pa:")
tmp = nt*(T*n)
tmp = tmp[0]
tmp = tmp.subs(sub_list)
tmp /= Pa
pprint(N(tmp,prec))

pprint("\nτ = t' T n in Pa:")
tmp = tt*T*n
tmp = tmp[0]
tmp = tmp.subs(sub_list)
tmp /= Pa
pprint(N(tmp,prec))

# unicode utf overbar xbar ybar is \u0304:
pprint("\nComponents wrt (x\u0304,y\u0304):")
pprint("---------------------")

n = Matrix([1,0])
nt = n.transpose()
t = Matrix([0,1])
tt = t.transpose()
T = R*T*R.transpose()

pprint("\nStress tensor in Pa:")
tmp = T
tmp = tmp.subs(sub_list)
tmp /= Pa
pprint(tmp)

pprint("\nNormal vector n:")
tmp = n
pprint(tmp)
pprint("\nTranspose n' of n:")
tmp = nt
pprint(tmp)
pprint("\nTangent vector t:")
tmp = t
pprint(tmp)
pprint("\nTranspose t' of t:")
tmp = tt
pprint(tmp)

pprint(u"\nσ = n' T n in Pa:")
tmp = nt*(T*n)
tmp = tmp[0]
tmp = tmp.subs(sub_list)
tmp /= Pa
pprint(N(tmp,prec))

pprint("\nτ = t' T n in Pa:")
tmp = tt*T*n
tmp = tmp[0]
tmp = tmp.subs(sub_list)
tmp /= Pa
pprint(N(tmp,prec))

```

8393d1e690899f9b237f703cd1969080ebd91da8
ipynb
Jupyter Notebook
ipynb/TM_A/TM_0/trafo_tensor/trafo_tensor_1.ipynb
kassbohm/tm-snippets
5e0621ba2470116e54643b740d1b68b9f28bff12
MIT
ipynb/TM_A/TM_0/trafo_tensor/trafo_tensor_1.ipynb
kassbohm/tm-snippets
5e0621ba2470116e54643b740d1b68b9f28bff12
MIT
ipynb/TM_A/TM_0/trafo_tensor/trafo_tensor_1.ipynb
kassbohm/tm-snippets
5e0621ba2470116e54643b740d1b68b9f28bff12
MIT
Qwen/Qwen-72B
1. YES
2. YES