{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Symbolic Stress Notebook" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import sympy as sp\n", "\n", "\n", "from mechpy.core.symbolic.stress import (\n", " SymbolicStressTensor,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Symbolic Stress" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Init Method" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}\\sigma_{11} & \\sigma_{22} & \\sigma_{33} & \\sigma_{23} & \\sigma_{13} & \\sigma_{12}\\end{matrix}\\right]$" ], "text/plain": [ "[\\sigma_11, \\sigma_22, \\sigma_33, \\sigma_23, \\sigma_13, \\sigma_12]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "s_11, s_22, s_33, s_23, s_13, s_12 = sp.symbols(\n", " \"\\\\sigma_11 \\\\sigma_22 \\\\sigma_33 \\\\sigma_23 \\\\sigma_13 \\\\sigma_12\"\n", ")\n", "data = sp.NDimArray([s_11, s_22, s_33, s_23, s_13, s_12])\n", "sigma = SymbolicStressTensor(data)\n", "display(sigma.data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create Method" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Default Notation" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}\\sigma_{1} & \\sigma_{2} & \\sigma_{3} & \\sigma_{4} & \\sigma_{5} & \\sigma_{6}\\end{matrix}\\right]$" ], "text/plain": [ "[\\sigma_1, \\sigma_2, \\sigma_3, \\sigma_4, \\sigma_5, \\sigma_6]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "'standard'" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\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]$" ], "text/plain": [ "[[\\sigma_11, \\sigma_12, \\sigma_13], [\\sigma_12, \\sigma_22, \\sigma_23], [\\sigma_13, \\sigma_23, \\sigma_33]]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stress_tensor = SymbolicStressTensor.create()\n", "display(stress_tensor.data)\n", "display(stress_tensor.notation)\n", "display(stress_tensor.to_general().data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Voigt Notation" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}\\sigma_{11} & \\sigma_{22} & \\sigma_{33} & \\sigma_{23} & \\sigma_{13} & \\sigma_{12}\\end{matrix}\\right]$" ], "text/plain": [ "[\\sigma_11, \\sigma_22, \\sigma_33, \\sigma_23, \\sigma_13, \\sigma_12]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "'voigt'" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\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]$" ], "text/plain": [ "[[\\sigma_11, \\sigma_12, \\sigma_13], [\\sigma_12, \\sigma_22, \\sigma_23], [\\sigma_13, \\sigma_23, \\sigma_33]]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stress_tensor = SymbolicStressTensor.create(notation=\"voigt\")\n", "display(stress_tensor.data)\n", "display(stress_tensor.notation)\n", "display(stress_tensor.to_general().data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Custom name" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\sigma^{1}$" ], "text/plain": [ "\\sigma^1" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\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]$" ], "text/plain": [ "[[\\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]]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "name = sp.symbols(\"\\sigma^1\")\n", "display(name)\n", "stress_tensor = SymbolicStressTensor.create(name=name, notation=\"voigt\")\n", "display(stress_tensor.to_general().data)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}\\sigma^{1}_{11} & \\sigma^{1}_{22} & \\sigma^{1}_{33}\\end{matrix}\\right]$" ], "text/plain": [ "[\\sigma^1_11, \\sigma^1_22, \\sigma^1_33]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}\\sigma^{1}_{23} & \\sigma^{1}_{13} & \\sigma^{1}_{12}\\end{matrix}\\right]$" ], "text/plain": [ "[\\sigma^1_23, \\sigma^1_13, \\sigma^1_12]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle \\frac{\\sigma^{1}_{11} + \\sigma^{1}_{22} + \\sigma^{1}_{33}}{3}$" ], "text/plain": [ "(\\sigma^1_11 + \\sigma^1_22 + \\sigma^1_33)/3" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "display(stress_tensor.normal_components())\n", "display(stress_tensor.shear_components())\n", "display(stress_tensor.pressure())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Tresca and Von Mises" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}\\sigma_{11} & \\sigma_{22} & \\sigma_{33} & \\sigma_{23} & \\sigma_{13} & \\sigma_{12}\\end{matrix}\\right]$" ], "text/plain": [ "[\\sigma_11, \\sigma_22, \\sigma_33, \\sigma_23, \\sigma_13, \\sigma_12]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stress_tensor = SymbolicStressTensor.create(notation=\"voigt\")\n", "display(stress_tensor.data)\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "subs using keys" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}\\sigma_{11} & \\sigma_{11} & \\sigma_{11} & 0 & 1 & \\sigma_{12}\\end{matrix}\\right]$" ], "text/plain": [ "[\\sigma_11, \\sigma_11, \\sigma_11, 0, 1, \\sigma_12]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "s_11 = stress_tensor[0]\n", "subs = {\n", " 1: s_11,\n", " 2: s_11,\n", " 3: 0,\n", " 4: 1,\n", "}\n", "stress_tensor.subs_tensor_components(subs)\n", "display(stress_tensor.data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "subs using symbols" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}0 & 0 & 0 & 0 & 1 & \\sigma_{12}\\end{matrix}\\right]$" ], "text/plain": [ "[0, 0, 0, 0, 1, \\sigma_12]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "subs = {\n", " s_11: 0,\n", "}\n", "stress_tensor.subs(subs)\n", "display(stress_tensor.data)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 2 \\left|{\\sqrt{\\sigma_{12}^{2} + 1}}\\right|$" ], "text/plain": [ "2*Abs(sqrt(\\sigma_12**2 + 1))" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle \\sqrt{3 \\sigma_{12}^{2} + 3}$" ], "text/plain": [ "sqrt(3*\\sigma_12**2 + 3)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "display(stress_tensor.tresca())\n", "display(stress_tensor.von_mises())" ] } ], "metadata": { "kernelspec": { "display_name": "venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 2 }