\begin{Verbatim}[commandchars=\\\{\}]
\PY{c}{# Left Cauchy-Green tensor}
\PY{k}{def} \PY{n+nf}{LeftCauchyGreen}\PY{p}{(}\PY{n}{u}\PY{p}{)}\PY{p}{:}
    \PY{n}{F} \PY{o}{=} \PY{n}{DeformationGradient}\PY{p}{(}\PY{n}{u}\PY{p}{)}
    \PY{k}{return} \PY{n}{variable}\PY{p}{(}\PY{n}{F}\PY{o}{*}\PY{n}{F}\PY{o}{.}\PY{n}{T}\PY{p}{)}

\PY{c}{# Euler-Almansi strain tensor}
\PY{k}{def} \PY{n+nf}{EulerAlmansiStrain}\PY{p}{(}\PY{n}{u}\PY{p}{)}\PY{p}{:}
    \PY{n}{I} \PY{o}{=} \PY{n}{SecondOrderIdentity}\PY{p}{(}\PY{n}{u}\PY{p}{)}
    \PY{n}{b} \PY{o}{=} \PY{n}{LeftCauchyGreen}\PY{p}{(}\PY{n}{u}\PY{p}{)}
    \PY{k}{return} \PY{n}{variable}\PY{p}{(}\PY{l+m+mf}{0.5}\PY{o}{*}\PY{p}{(}\PY{n}{I} \PY{o}{-} \PY{n}{inv}\PY{p}{(}\PY{n}{b}\PY{p}{)}\PY{p}{)}\PY{p}{)}

\PY{c}{# Invariants of an arbitrary tensor, A}
\PY{k}{def} \PY{n+nf}{Invariants}\PY{p}{(}\PY{n}{A}\PY{p}{)}\PY{p}{:}
    \PY{n}{I1} \PY{o}{=} \PY{n}{tr}\PY{p}{(}\PY{n}{A}\PY{p}{)}
    \PY{n}{I2} \PY{o}{=} \PY{l+m+mf}{0.5}\PY{o}{*}\PY{p}{(}\PY{n}{tr}\PY{p}{(}\PY{n}{A}\PY{p}{)}\PY{o}{*}\PY{o}{*}\PY{l+m+mi}{2} \PY{o}{-} \PY{n}{tr}\PY{p}{(}\PY{n}{A}\PY{o}{*}\PY{n}{A}\PY{p}{)}\PY{p}{)}
    \PY{n}{I3} \PY{o}{=} \PY{n}{det}\PY{p}{(}\PY{n}{A}\PY{p}{)}
    \PY{k}{return} \PY{p}{[}\PY{n}{I1}\PY{p}{,} \PY{n}{I2}\PY{p}{,} \PY{n}{I3}\PY{p}{]}

\PY{c}{# Invariants of the (right/left) Cauchy-Green tensor}
\PY{k}{def} \PY{n+nf}{CauchyGreenInvariants}\PY{p}{(}\PY{n}{u}\PY{p}{)}\PY{p}{:}
    \PY{n}{C} \PY{o}{=} \PY{n}{RightCauchyGreen}\PY{p}{(}\PY{n}{u}\PY{p}{)}
    \PY{p}{[}\PY{n}{I1}\PY{p}{,} \PY{n}{I2}\PY{p}{,} \PY{n}{I3}\PY{p}{]} \PY{o}{=} \PY{n}{Invariants}\PY{p}{(}\PY{n}{C}\PY{p}{)}
    \PY{k}{return} \PY{p}{[}\PY{n}{variable}\PY{p}{(}\PY{n}{I1}\PY{p}{)}\PY{p}{,} \PY{n}{variable}\PY{p}{(}\PY{n}{I2}\PY{p}{)}\PY{p}{,} \PY{n}{variable}\PY{p}{(}\PY{n}{I3}\PY{p}{)}\PY{p}{]}

\PY{c}{# Isochoric part of the deformation gradient}
\PY{k}{def} \PY{n+nf}{IsochoricDeformationGradient}\PY{p}{(}\PY{n}{u}\PY{p}{)}\PY{p}{:}
    \PY{n}{F} \PY{o}{=} \PY{n}{DeformationGradient}\PY{p}{(}\PY{n}{u}\PY{p}{)}
    \PY{n}{J} \PY{o}{=} \PY{n}{Jacobian}\PY{p}{(}\PY{n}{u}\PY{p}{)}
    \PY{k}{return} \PY{n}{variable}\PY{p}{(}\PY{n}{J}\PY{o}{*}\PY{o}{*}\PY{p}{(}\PY{o}{-}\PY{l+m+mf}{1.0}\PY{o}{/}\PY{l+m+mf}{3.0}\PY{p}{)}\PY{o}{*}\PY{n}{F}\PY{p}{)}

\end{Verbatim}
