{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Symbolic Material Notebook" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import sympy as sp\n", "\n", "from mechpy.core.symbolic.material import (\n", " SymbolicIsotropicMaterial,\n", " SymbolicTransverseIsotropicMaterial,\n", " SymbolicOrthotropicMaterial,\n", " \n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Symbolic Material" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Isotropic Material" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "SymbolicIsotropicMaterial(E=E, nu=nu)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "E, nu = sp.symbols(\"E nu\")\n", "symbolic_isotropic_material = SymbolicIsotropicMaterial(E=E, nu=nu)\n", "display(symbolic_isotropic_material)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}\\frac{1}{E} & - \\frac{\\nu}{E} & - \\frac{\\nu}{E} & 0 & 0 & 0\\\\- \\frac{\\nu}{E} & \\frac{1}{E} & - \\frac{\\nu}{E} & 0 & 0 & 0\\\\- \\frac{\\nu}{E} & - \\frac{\\nu}{E} & \\frac{1}{E} & 0 & 0 & 0\\\\0 & 0 & 0 & \\frac{2 \\left(\\nu + 1\\right)}{E} & 0 & 0\\\\0 & 0 & 0 & 0 & \\frac{2 \\left(\\nu + 1\\right)}{E} & 0\\\\0 & 0 & 0 & 0 & 0 & \\frac{2 \\left(\\nu + 1\\right)}{E}\\end{matrix}\\right]$" ], "text/plain": [ "[[1/E, -nu/E, -nu/E, 0, 0, 0], [-nu/E, 1/E, -nu/E, 0, 0, 0], [-nu/E, -nu/E, 1/E, 0, 0, 0], [0, 0, 0, 2*(nu + 1)/E, 0, 0], [0, 0, 0, 0, 2*(nu + 1)/E, 0], [0, 0, 0, 0, 0, 2*(nu + 1)/E]]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compliance_tensor = symbolic_isotropic_material.compliance_tensor()\n", "display(compliance_tensor.data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using Lamé parameters" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "SymbolicIsotropicMaterial(lamda=lamda, mu=mu)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "lamda, mu = sp.symbols(\"lamda mu\")\n", "symbolic_isotropic_material = SymbolicIsotropicMaterial(lamda=lamda, mu=mu)\n", "display(symbolic_isotropic_material)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}\\lambda + 2 \\mu & \\lambda & \\lambda & 0 & 0 & 0\\\\\\lambda & \\lambda + 2 \\mu & \\lambda & 0 & 0 & 0\\\\\\lambda & \\lambda & \\lambda + 2 \\mu & 0 & 0 & 0\\\\0 & 0 & 0 & \\mu & 0 & 0\\\\0 & 0 & 0 & 0 & \\mu & 0\\\\0 & 0 & 0 & 0 & 0 & \\mu\\end{matrix}\\right]$" ], "text/plain": [ "[[lamda + 2*mu, lamda, lamda, 0, 0, 0], [lamda, lamda + 2*mu, lamda, 0, 0, 0], [lamda, lamda, lamda + 2*mu, 0, 0, 0], [0, 0, 0, mu, 0, 0], [0, 0, 0, 0, mu, 0], [0, 0, 0, 0, 0, mu]]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}\\frac{\\lambda + \\mu}{\\mu \\left(3 \\lambda + 2 \\mu\\right)} & - \\frac{\\lambda}{2 \\mu \\left(3 \\lambda + 2 \\mu\\right)} & - \\frac{\\lambda}{2 \\mu \\left(3 \\lambda + 2 \\mu\\right)} & 0 & 0 & 0\\\\- \\frac{\\lambda}{2 \\mu \\left(3 \\lambda + 2 \\mu\\right)} & \\frac{\\lambda + \\mu}{\\mu \\left(3 \\lambda + 2 \\mu\\right)} & - \\frac{\\lambda}{2 \\mu \\left(3 \\lambda + 2 \\mu\\right)} & 0 & 0 & 0\\\\- \\frac{\\lambda}{2 \\mu \\left(3 \\lambda + 2 \\mu\\right)} & - \\frac{\\lambda}{2 \\mu \\left(3 \\lambda + 2 \\mu\\right)} & \\frac{\\lambda + \\mu}{\\mu \\left(3 \\lambda + 2 \\mu\\right)} & 0 & 0 & 0\\\\0 & 0 & 0 & \\frac{1}{\\mu} & 0 & 0\\\\0 & 0 & 0 & 0 & \\frac{1}{\\mu} & 0\\\\0 & 0 & 0 & 0 & 0 & \\frac{1}{\\mu}\\end{matrix}\\right]$" ], "text/plain": [ "[[(lamda + mu)/(mu*(3*lamda + 2*mu)), -lamda/(2*mu*(3*lamda + 2*mu)), -lamda/(2*mu*(3*lamda + 2*mu)), 0, 0, 0], [-lamda/(2*mu*(3*lamda + 2*mu)), (lamda + mu)/(mu*(3*lamda + 2*mu)), -lamda/(2*mu*(3*lamda + 2*mu)), 0, 0, 0], [-lamda/(2*mu*(3*lamda + 2*mu)), -lamda/(2*mu*(3*lamda + 2*mu)), (lamda + mu)/(mu*(3*lamda + 2*mu)), 0, 0, 0], [0, 0, 0, 1/mu, 0, 0], [0, 0, 0, 0, 1/mu, 0], [0, 0, 0, 0, 0, 1/mu]]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stiffness_tensor = symbolic_isotropic_material.stiffness_tensor()\n", "display(stiffness_tensor.data)\n", "compliance_tensor = symbolic_isotropic_material.compliance_tensor()\n", "display(compliance_tensor.data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Transverse Isotropic Material" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'E_L': E_L, 'E_T': E_T, 'nu': nu, 'G_L': G_L, 'G_T': G_T}" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "SymbolicTransverseIsotropicMaterial(E_L=E_L, E_T=E_T, nu=nu, G_L=G_L, G_T=G_T)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "material_props = {\n", " \"E_L\": sp.symbols(\"E_L\"),\n", " \"E_T\": sp.symbols(\"E_T\"),\n", " \"nu\": sp.symbols(\"nu\"),\n", " \"G_L\": sp.symbols(\"G_L\"),\n", " \"G_T\": sp.symbols(\"G_T\"),\n", "}\n", "display(material_props)\n", "symbolic_transverse_isotropic_material = SymbolicTransverseIsotropicMaterial(**material_props)\n", "display(symbolic_transverse_isotropic_material)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}- \\frac{E_{L}}{\\nu^{2} - 1} & - \\frac{E_{L} \\nu}{\\nu - 1} & - \\frac{E_{L} \\nu}{\\nu - 1} & 0 & 0 & 0\\\\- \\frac{E_{L} \\nu}{\\nu - 1} & - \\frac{E_{L}}{\\nu^{2} - 1} & - \\frac{E_{L} \\nu}{\\nu - 1} & 0 & 0 & 0\\\\- \\frac{E_{L} \\nu}{\\nu - 1} & - \\frac{E_{L} \\nu}{\\nu - 1} & E_{T} & 0 & 0 & 0\\\\0 & 0 & 0 & G_{L} & 0 & 0\\\\0 & 0 & 0 & 0 & G_{L} & 0\\\\0 & 0 & 0 & 0 & 0 & G_{T}\\end{matrix}\\right]$" ], "text/plain": [ "[[-E_L/(nu**2 - 1), -E_L*nu/(nu - 1), -E_L*nu/(nu - 1), 0, 0, 0], [-E_L*nu/(nu - 1), -E_L/(nu**2 - 1), -E_L*nu/(nu - 1), 0, 0, 0], [-E_L*nu/(nu - 1), -E_L*nu/(nu - 1), E_T, 0, 0, 0], [0, 0, 0, G_L, 0, 0], [0, 0, 0, 0, G_L, 0], [0, 0, 0, 0, 0, G_T]]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stiffness_tensor = symbolic_transverse_isotropic_material.stiffness_tensor()\n", "display(stiffness_tensor.data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Orthotropic Material" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'E2': E2,\n", " 'nu23': nu23,\n", " 'G31': G31,\n", " 'G12': G12,\n", " 'nu12': nu12,\n", " 'E3': E3,\n", " 'G23': G23,\n", " 'nu31': nu31,\n", " 'E1': E1}" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "SymbolicOrthotropicMaterial(E1=E1, E2=E2, E3=E3, G12=G12, G23=G23, G31=G31, nu12=nu12, nu23=nu23, nu31=nu31)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "material_props = {_:sp.symbols(_) for _ in SymbolicOrthotropicMaterial.props_keys}\n", "display(material_props)\n", "symbolic_orthotropic_material = SymbolicOrthotropicMaterial(**material_props)\n", "display(symbolic_orthotropic_material)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}E_{1} & E_{2} \\nu_{12} & E_{1} \\nu_{31} & 0 & 0 & 0\\\\E_{2} \\nu_{12} & E_{2} & E_{3} \\nu_{23} & 0 & 0 & 0\\\\E_{1} \\nu_{31} & E_{3} \\nu_{23} & E_{3} & 0 & 0 & 0\\\\0 & 0 & 0 & G_{23} & 0 & 0\\\\0 & 0 & 0 & 0 & G_{31} & 0\\\\0 & 0 & 0 & 0 & 0 & G_{12}\\end{matrix}\\right]$" ], "text/plain": [ "[[E1, E2*nu12, E1*nu31, 0, 0, 0], [E2*nu12, E2, E3*nu23, 0, 0, 0], [E1*nu31, E3*nu23, E3, 0, 0, 0], [0, 0, 0, G23, 0, 0], [0, 0, 0, 0, G31, 0], [0, 0, 0, 0, 0, G12]]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}\\frac{E_{3} \\left(- E_{2} + E_{3} \\nu_{23}^{2}\\right)}{E_{1}^{2} E_{2} \\nu_{31}^{2} - 2 E_{1} E_{2} E_{3} \\nu_{12} \\nu_{23} \\nu_{31} - E_{1} E_{2} E_{3} + E_{1} E_{3}^{2} \\nu_{23}^{2} + E_{2}^{2} E_{3} \\nu_{12}^{2}} & \\frac{E_{3} \\left(- E_{1} \\nu_{23} \\nu_{31} + E_{2} \\nu_{12}\\right)}{E_{1}^{2} E_{2} \\nu_{31}^{2} - 2 E_{1} E_{2} E_{3} \\nu_{12} \\nu_{23} \\nu_{31} - E_{1} E_{2} E_{3} + E_{1} E_{3}^{2} \\nu_{23}^{2} + E_{2}^{2} E_{3} \\nu_{12}^{2}} & \\frac{E_{2} \\left(E_{1} \\nu_{31} - E_{3} \\nu_{12} \\nu_{23}\\right)}{E_{1}^{2} E_{2} \\nu_{31}^{2} - 2 E_{1} E_{2} E_{3} \\nu_{12} \\nu_{23} \\nu_{31} - E_{1} E_{2} E_{3} + E_{1} E_{3}^{2} \\nu_{23}^{2} + E_{2}^{2} E_{3} \\nu_{12}^{2}} & 0 & 0 & 0\\\\\\frac{E_{3} \\left(- E_{1} \\nu_{23} \\nu_{31} + E_{2} \\nu_{12}\\right)}{E_{1}^{2} E_{2} \\nu_{31}^{2} - 2 E_{1} E_{2} E_{3} \\nu_{12} \\nu_{23} \\nu_{31} - E_{1} E_{2} E_{3} + E_{1} E_{3}^{2} \\nu_{23}^{2} + E_{2}^{2} E_{3} \\nu_{12}^{2}} & \\frac{E_{1} \\left(E_{1} \\nu_{31}^{2} - E_{3}\\right)}{E_{1}^{2} E_{2} \\nu_{31}^{2} - 2 E_{1} E_{2} E_{3} \\nu_{12} \\nu_{23} \\nu_{31} - E_{1} E_{2} E_{3} + E_{1} E_{3}^{2} \\nu_{23}^{2} + E_{2}^{2} E_{3} \\nu_{12}^{2}} & \\frac{E_{1} \\left(- E_{2} \\nu_{12} \\nu_{31} + E_{3} \\nu_{23}\\right)}{E_{1}^{2} E_{2} \\nu_{31}^{2} - 2 E_{1} E_{2} E_{3} \\nu_{12} \\nu_{23} \\nu_{31} - E_{1} E_{2} E_{3} + E_{1} E_{3}^{2} \\nu_{23}^{2} + E_{2}^{2} E_{3} \\nu_{12}^{2}} & 0 & 0 & 0\\\\\\frac{E_{2} \\left(E_{1} \\nu_{31} - E_{3} \\nu_{12} \\nu_{23}\\right)}{E_{1}^{2} E_{2} \\nu_{31}^{2} - 2 E_{1} E_{2} E_{3} \\nu_{12} \\nu_{23} \\nu_{31} - E_{1} E_{2} E_{3} + E_{1} E_{3}^{2} \\nu_{23}^{2} + E_{2}^{2} E_{3} \\nu_{12}^{2}} & \\frac{E_{1} \\left(- E_{2} \\nu_{12} \\nu_{31} + E_{3} \\nu_{23}\\right)}{E_{1}^{2} E_{2} \\nu_{31}^{2} - 2 E_{1} E_{2} E_{3} \\nu_{12} \\nu_{23} \\nu_{31} - E_{1} E_{2} E_{3} + E_{1} E_{3}^{2} \\nu_{23}^{2} + E_{2}^{2} E_{3} \\nu_{12}^{2}} & \\frac{E_{2} \\left(- E_{1} + E_{2} \\nu_{12}^{2}\\right)}{E_{1}^{2} E_{2} \\nu_{31}^{2} - 2 E_{1} E_{2} E_{3} \\nu_{12} \\nu_{23} \\nu_{31} - E_{1} E_{2} E_{3} + E_{1} E_{3}^{2} \\nu_{23}^{2} + E_{2}^{2} E_{3} \\nu_{12}^{2}} & 0 & 0 & 0\\\\0 & 0 & 0 & \\frac{1}{G_{23}} & 0 & 0\\\\0 & 0 & 0 & 0 & \\frac{1}{G_{31}} & 0\\\\0 & 0 & 0 & 0 & 0 & \\frac{1}{G_{12}}\\end{matrix}\\right]$" ], "text/plain": [ "[[E3*(-E2 + E3*nu23**2)/(E1**2*E2*nu31**2 - 2*E1*E2*E3*nu12*nu23*nu31 - E1*E2*E3 + E1*E3**2*nu23**2 + E2**2*E3*nu12**2), E3*(-E1*nu23*nu31 + E2*nu12)/(E1**2*E2*nu31**2 - 2*E1*E2*E3*nu12*nu23*nu31 - E1*E2*E3 + E1*E3**2*nu23**2 + E2**2*E3*nu12**2), E2*(E1*nu31 - E3*nu12*nu23)/(E1**2*E2*nu31**2 - 2*E1*E2*E3*nu12*nu23*nu31 - E1*E2*E3 + E1*E3**2*nu23**2 + E2**2*E3*nu12**2), 0, 0, 0], [E3*(-E1*nu23*nu31 + E2*nu12)/(E1**2*E2*nu31**2 - 2*E1*E2*E3*nu12*nu23*nu31 - E1*E2*E3 + E1*E3**2*nu23**2 + E2**2*E3*nu12**2), E1*(E1*nu31**2 - E3)/(E1**2*E2*nu31**2 - 2*E1*E2*E3*nu12*nu23*nu31 - E1*E2*E3 + E1*E3**2*nu23**2 + E2**2*E3*nu12**2), E1*(-E2*nu12*nu31 + E3*nu23)/(E1**2*E2*nu31**2 - 2*E1*E2*E3*nu12*nu23*nu31 - E1*E2*E3 + E1*E3**2*nu23**2 + E2**2*E3*nu12**2), 0, 0, 0], [E2*(E1*nu31 - E3*nu12*nu23)/(E1**2*E2*nu31**2 - 2*E1*E2*E3*nu12*nu23*nu31 - E1*E2*E3 + E1*E3**2*nu23**2 + E2**2*E3*nu12**2), E1*(-E2*nu12*nu31 + E3*nu23)/(E1**2*E2*nu31**2 - 2*E1*E2*E3*nu12*nu23*nu31 - E1*E2*E3 + E1*E3**2*nu23**2 + E2**2*E3*nu12**2), E2*(-E1 + E2*nu12**2)/(E1**2*E2*nu31**2 - 2*E1*E2*E3*nu12*nu23*nu31 - E1*E2*E3 + E1*E3**2*nu23**2 + E2**2*E3*nu12**2), 0, 0, 0], [0, 0, 0, 1/G23, 0, 0], [0, 0, 0, 0, 1/G31, 0], [0, 0, 0, 0, 0, 1/G12]]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "stiffness_tensor = symbolic_orthotropic_material.stiffness_tensor()\n", "display(stiffness_tensor.data)\n", "compliance_tensor = symbolic_orthotropic_material.compliance_tensor()\n", "display(compliance_tensor.data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Custom Symbols" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'E': {..}\\atop{E}, 'nu': nu^°}" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "SymbolicIsotropicMaterial(E={..}\\atop{E}, nu=nu^°)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "material_props = {\n", " \"E\" : sp.symbols(\"{..}\\\\atop{E}\"),\n", " \"nu\": sp.symbols(\"nu^°\")\n", "}\n", "display(material_props)\n", "symbolic_isotropic_material = SymbolicIsotropicMaterial(**material_props)\n", "display(symbolic_isotropic_material)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}\\frac{1}{{..}\\atop{E}} & - \\frac{\\nu^{°}}{{..}\\atop{E}} & - \\frac{\\nu^{°}}{{..}\\atop{E}} & 0 & 0 & 0\\\\- \\frac{\\nu^{°}}{{..}\\atop{E}} & \\frac{1}{{..}\\atop{E}} & - \\frac{\\nu^{°}}{{..}\\atop{E}} & 0 & 0 & 0\\\\- \\frac{\\nu^{°}}{{..}\\atop{E}} & - \\frac{\\nu^{°}}{{..}\\atop{E}} & \\frac{1}{{..}\\atop{E}} & 0 & 0 & 0\\\\0 & 0 & 0 & \\frac{2 \\left(\\nu^{°} + 1\\right)}{{..}\\atop{E}} & 0 & 0\\\\0 & 0 & 0 & 0 & \\frac{2 \\left(\\nu^{°} + 1\\right)}{{..}\\atop{E}} & 0\\\\0 & 0 & 0 & 0 & 0 & \\frac{2 \\left(\\nu^{°} + 1\\right)}{{..}\\atop{E}}\\end{matrix}\\right]$" ], "text/plain": [ "[[1/{..}\\atop{E}, -nu^°/{..}\\atop{E}, -nu^°/{..}\\atop{E}, 0, 0, 0], [-nu^°/{..}\\atop{E}, 1/{..}\\atop{E}, -nu^°/{..}\\atop{E}, 0, 0, 0], [-nu^°/{..}\\atop{E}, -nu^°/{..}\\atop{E}, 1/{..}\\atop{E}, 0, 0, 0], [0, 0, 0, 2*(nu^° + 1)/{..}\\atop{E}, 0, 0], [0, 0, 0, 0, 2*(nu^° + 1)/{..}\\atop{E}, 0], [0, 0, 0, 0, 0, 2*(nu^° + 1)/{..}\\atop{E}]]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "compliance_tensor = symbolic_isotropic_material.compliance_tensor()\n", "display(compliance_tensor.data)" ] } ], "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 }