{ "cells": [ { "cell_type": "markdown", "id": "e431b092-84fd-4f3b-81a2-ffdaa41c38b4", "metadata": {}, "source": [ "# Hugoniot equation for a calorically perfect gas" ] }, { "cell_type": "markdown", "id": "c161010c-7b40-4ead-86ce-6d9b95f78c67", "metadata": {}, "source": [ "The Hugoniot equation relates thermodynamic quantities (pressure $p$, specific volume $v$ and internal energy $e$) across a shock wave. \n", "\n", "The general form (shown below) holds for a perfect gas, chemically reacting gas, real gas, etc." ] }, { "cell_type": "code", "execution_count": 1, "id": "cc5df44f-34c8-422e-9505-aae5f39f9288", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle - e_{1} + e_{2} = \\left(\\frac{p_{1}}{2} + \\frac{p_{2}}{2}\\right) \\left(v_{1} - v_{2}\\right)$" ], "text/plain": [ "Equation(-e1 + e2, (p1/2 + p2/2)*(v1 - v2))" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from sympy import *\n", "from sympy_equation import (\n", " Eqn,\n", " table_of_expressions,\n", " process_arguments_of_add,\n", " divide_term_by_term,\n", ")\n", "\n", "e1, e2, p1, p2, v1, v2 = symbols(\"e1, e2, p1, p2, v1, v2\", real=True, positive=True)\n", "h = Eqn(e2 - e1, (p1 + p2) / 2 * (v1 - v2))\n", "h" ] }, { "cell_type": "markdown", "id": "7d74b2e1-87eb-4eec-b015-fc08e9581933", "metadata": {}, "source": [ "For a calorically perfect gas, $e = C_{v} T$ and $T = p v / R$, where:\n", "\n", "* $C_{v}$: specific heat at constant volume.\n", "* $T$: temperature.\n", "* $R$: specific gas constant.\n", "\n", "Also note that $\\gamma$ is the ratio of specific heats.\n", "\n", "Find a new form of the Hugoniot equation for a calorically perfect gas, which shows the relationship between the pressure ratio and the specific volume ratio." ] }, { "cell_type": "markdown", "id": "0b613e8e-b1b4-46bd-a723-5d5c7a4d2941", "metadata": {}, "source": [ "Let's define a few new equations:" ] }, { "cell_type": "code", "execution_count": 2, "id": "d4f8586f-b879-42d4-8b57-ad0c34f009d5", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle C_{v} = \\frac{R}{\\gamma - 1}$" ], "text/plain": [ "Equation(C_v, R/(gamma - 1))" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle e_{1} = C_{v} T_{1}$" ], "text/plain": [ "Equation(e1, C_v*T1)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle e_{2} = C_{v} T_{2}$" ], "text/plain": [ "Equation(e2, C_v*T2)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle T_{1} = \\frac{p_{1} v_{1}}{R}$" ], "text/plain": [ "Equation(T1, p1*v1/R)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/latex": [ "$\\displaystyle T_{2} = \\frac{p_{2} v_{2}}{R}$" ], "text/plain": [ "Equation(T2, p2*v2/R)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Cv, R, T1, T2, gamma = symbols(\"C_v, R, T1, T2, gamma\", real=True, positive=True)\n", "eq1 = Eqn(Cv, R / (gamma - 1))\n", "eq2 = Eqn(e1, Cv * T1)\n", "eq3 = Eqn(e2, Cv * T2)\n", "eq4 = Eqn(T1, p1 * v1 / R)\n", "eq5 = Eqn(T2, p2 * v2 / R)\n", "display(eq1, eq2, eq3, eq4, eq5)" ] }, { "cell_type": "markdown", "id": "1818e969-c185-4db2-ba8f-a8722201da45", "metadata": {}, "source": [ "Substitutes them into the Hugoniot equation:" ] }, { "cell_type": "code", "execution_count": 3, "id": "19056549-244a-43ff-a414-c136b60d1cba", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle - \\frac{p_{1} v_{1}}{\\gamma - 1} + \\frac{p_{2} v_{2}}{\\gamma - 1} = \\left(\\frac{p_{1}}{2} + \\frac{p_{2}}{2}\\right) \\left(v_{1} - v_{2}\\right)$" ], "text/plain": [ "Equation(-p1*v1/(gamma - 1) + p2*v2/(gamma - 1), (p1/2 + p2/2)*(v1 - v2))" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# multi step substitutions in order to achieve the desired form\n", "e = h.subs(eq2, eq3).subs(eq4, eq5).subs(eq1)\n", "e" ] }, { "cell_type": "markdown", "id": "b5894029-511c-4d4d-920d-31f03667853c", "metadata": {}, "source": [ "Let's move $\\gamma - 1$ from the denominator of the LHS to the numerator of the RHS:" ] }, { "cell_type": "code", "execution_count": 4, "id": "50bee31e-ed99-4dcd-8624-c37f18448d0a", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle - p_{1} v_{1} + p_{2} v_{2} = \\left(\\gamma - 1\\right) \\left(\\frac{p_{1}}{2} + \\frac{p_{2}}{2}\\right) \\left(v_{1} - v_{2}\\right)$" ], "text/plain": [ "Equation(-p1*v1 + p2*v2, (gamma - 1)*(p1/2 + p2/2)*(v1 - v2))" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = e.dolhs.collect(1 / (gamma - 1)) * (gamma - 1)\n", "e" ] }, { "cell_type": "markdown", "id": "5113dda6-4592-4d76-9787-b2f74187d340", "metadata": {}, "source": [ "Now we can start working with pressure ratios and specific volume ratios. First, let's expand the equation so it is easier to achieve the next steps:" ] }, { "cell_type": "code", "execution_count": 5, "id": "f7e8704f-69a1-48ff-b3ad-174dd8501042", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle - p_{1} v_{1} + p_{2} v_{2} = \\frac{\\gamma p_{1} v_{1}}{2} - \\frac{\\gamma p_{1} v_{2}}{2} + \\frac{\\gamma p_{2} v_{1}}{2} - \\frac{\\gamma p_{2} v_{2}}{2} - \\frac{p_{1} v_{1}}{2} + \\frac{p_{1} v_{2}}{2} - \\frac{p_{2} v_{1}}{2} + \\frac{p_{2} v_{2}}{2}$" ], "text/plain": [ "Equation(-p1*v1 + p2*v2, gamma*p1*v1/2 - gamma*p1*v2/2 + gamma*p2*v1/2 - gamma*p2*v2/2 - p1*v1/2 + p1*v2/2 - p2*v1/2 + p2*v2/2)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = e.expand()\n", "e" ] }, { "cell_type": "markdown", "id": "072f70f8-f8ca-4325-a728-e68e2062fb20", "metadata": {}, "source": [ "Let's divide both sides by $p_{1}$:" ] }, { "cell_type": "code", "execution_count": 6, "id": "60cd9b21-e2b6-499b-b64d-6364eb5633b4", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle - v_{1} + \\frac{p_{2} v_{2}}{p_{1}} = \\frac{\\gamma v_{1}}{2} - \\frac{\\gamma v_{2}}{2} + \\frac{\\gamma p_{2} v_{1}}{2 p_{1}} - \\frac{\\gamma p_{2} v_{2}}{2 p_{1}} - \\frac{v_{1}}{2} + \\frac{v_{2}}{2} - \\frac{p_{2} v_{1}}{2 p_{1}} + \\frac{p_{2} v_{2}}{2 p_{1}}$" ], "text/plain": [ "Equation(-v1 + p2*v2/p1, gamma*v1/2 - gamma*v2/2 + gamma*p2*v1/(2*p1) - gamma*p2*v2/(2*p1) - v1/2 + v2/2 - p2*v1/(2*p1) + p2*v2/(2*p1))" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = (e / p1).expand()\n", "e" ] }, { "cell_type": "markdown", "id": "f44e28d3-4fc9-4443-990e-ae22832b8186", "metadata": {}, "source": [ "and then by $v_{1}$:" ] }, { "cell_type": "code", "execution_count": 7, "id": "656b3d48-1aaf-4f4e-a773-53503d7ce19b", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle -1 + \\frac{p_{2} v_{2}}{p_{1} v_{1}} = \\frac{\\gamma}{2} - \\frac{\\gamma v_{2}}{2 v_{1}} + \\frac{\\gamma p_{2}}{2 p_{1}} - \\frac{\\gamma p_{2} v_{2}}{2 p_{1} v_{1}} - \\frac{1}{2} + \\frac{v_{2}}{2 v_{1}} - \\frac{p_{2}}{2 p_{1}} + \\frac{p_{2} v_{2}}{2 p_{1} v_{1}}$" ], "text/plain": [ "Equation(-1 + p2*v2/(p1*v1), gamma/2 - gamma*v2/(2*v1) + gamma*p2/(2*p1) - gamma*p2*v2/(2*p1*v1) - 1/2 + v2/(2*v1) - p2/(2*p1) + p2*v2/(2*p1*v1))" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = (e / v1).expand()\n", "e" ] }, { "cell_type": "markdown", "id": "b0491055-2be4-4109-828d-e49ff53941ca", "metadata": {}, "source": [ "Let's move the -1 constant from the LHS to the RHS:" ] }, { "cell_type": "code", "execution_count": 8, "id": "1181339a-1f9a-470b-be10-717a56a82575", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{p_{2} v_{2}}{p_{1} v_{1}} = \\frac{\\gamma}{2} - \\frac{\\gamma v_{2}}{2 v_{1}} + \\frac{\\gamma p_{2}}{2 p_{1}} - \\frac{\\gamma p_{2} v_{2}}{2 p_{1} v_{1}} + \\frac{1}{2} + \\frac{v_{2}}{2 v_{1}} - \\frac{p_{2}}{2 p_{1}} + \\frac{p_{2} v_{2}}{2 p_{1} v_{1}}$" ], "text/plain": [ "Equation(p2*v2/(p1*v1), gamma/2 - gamma*v2/(2*v1) + gamma*p2/(2*p1) - gamma*p2*v2/(2*p1*v1) + 1/2 + v2/(2*v1) - p2/(2*p1) + p2*v2/(2*p1*v1))" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = e + 1\n", "e" ] }, { "cell_type": "markdown", "id": "90356d90-99e4-4cb5-bdf5-6b29747e2841", "metadata": {}, "source": [ "Now, let's bring the following term from the RHS to the LHS:\n", "\n", "* $p_{2} v_{2} / (2 p_{1} v_{1})$\n", "* $\\gamma p_{2} v_{2} / (2 p_{1} v_{1})$\n", "\n", "In order to avoid typing errors, we are going to select those expressions from the arguments that compose the RHS:" ] }, { "cell_type": "code", "execution_count": 9, "id": "959c6e23-4584-4f92-8552-986d93bfd284", "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "| idx | args |\n", "|:-----:|:------|\n", "| 0 | $\\frac{1}{2}$ |\n", "| 1 | $\\frac{\\gamma}{2}$ |\n", "| 2 | $\\frac{v_{2}}{2 v_{1}}$ |\n", "| 3 | $- \\frac{p_{2}}{2 p_{1}}$ |\n", "| 4 | $\\frac{\\gamma p_{2}}{2 p_{1}}$ |\n", "| 5 | $- \\frac{\\gamma v_{2}}{2 v_{1}}$ |\n", "| 6 | $\\frac{p_{2} v_{2}}{2 p_{1} v_{1}}$ |\n", "| 7 | $- \\frac{\\gamma p_{2} v_{2}}{2 p_{1} v_{1}}$ |\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "toe = table_of_expressions(e.rhs)" ] }, { "cell_type": "code", "execution_count": 10, "id": "183da512-16ec-4c79-98d7-b88b5158bd36", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{\\gamma p_{2} v_{2}}{2 p_{1} v_{1}} + \\frac{p_{2} v_{2}}{2 p_{1} v_{1}} = \\frac{\\gamma}{2} - \\frac{\\gamma v_{2}}{2 v_{1}} + \\frac{\\gamma p_{2}}{2 p_{1}} + \\frac{1}{2} + \\frac{v_{2}}{2 v_{1}} - \\frac{p_{2}}{2 p_{1}}$" ], "text/plain": [ "Equation(gamma*p2*v2/(2*p1*v1) + p2*v2/(2*p1*v1), gamma/2 - gamma*v2/(2*v1) + gamma*p2/(2*p1) + 1/2 + v2/(2*v1) - p2/(2*p1))" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = e - toe[6] - toe[7]\n", "e" ] }, { "cell_type": "markdown", "id": "e8fc4022-54a7-474b-a0c6-ee8dc2e5c199", "metadata": {}, "source": [ "Let's get rid of the constant 2 at denominators:" ] }, { "cell_type": "code", "execution_count": 11, "id": "0db47673-a381-43b4-9084-96618c80b347", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{\\gamma p_{2} v_{2}}{p_{1} v_{1}} + \\frac{p_{2} v_{2}}{p_{1} v_{1}} = \\gamma - \\frac{\\gamma v_{2}}{v_{1}} + \\frac{\\gamma p_{2}}{p_{1}} + 1 + \\frac{v_{2}}{v_{1}} - \\frac{p_{2}}{p_{1}}$" ], "text/plain": [ "Equation(gamma*p2*v2/(p1*v1) + p2*v2/(p1*v1), gamma - gamma*v2/v1 + gamma*p2/p1 + 1 + v2/v1 - p2/p1)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = (e * 2).expand()\n", "e" ] }, { "cell_type": "markdown", "id": "a6ba4f2d-e815-420c-bd07-aaeb3c1f607e", "metadata": {}, "source": [ "At this point, it would be nice to factor terms sharing the same ratio. For example:\n", "\n", "$$\n", "\\begin{aligned}\n", "\\gamma \\frac{p_{2}v_{2}}{p_{1}v_{1}} + \\frac{p_{2}v_{2}}{p_{1}v_{1}} &= \\frac{p_{2}v_{2}}{p_{1}v_{1}} (\\gamma + 1) \\\\\n", "\\gamma \\frac{p_{2}}{p_{1}} - \\frac{p_{2}}{p_{1}} &= \\frac{p_{2}}{p_{1}} (\\gamma - 1) \\\\\n", "-\\gamma \\frac{v_{2}}{v_{1}} + \\frac{v_{2}}{v_{1}} &= -\\frac{v_{2}}{v_{1}} (\\gamma - 1) \\\\\n", "\\end{aligned}\n", "$$\n", "\n", "First, let's work on the LHS, which is an addition of two terms. If we were to explore its arguments with `e.lhs.args`, we would see that the index of the first term is 0, and the index of the second term is 1." ] }, { "cell_type": "code", "execution_count": 12, "id": "bca04a7a-e7f2-416d-8ecf-75eef8527eee", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{p_{2} v_{2} \\left(\\gamma + 1\\right)}{p_{1} v_{1}} = \\gamma - \\frac{\\gamma v_{2}}{v_{1}} + \\frac{\\gamma p_{2}}{p_{1}} + 1 + \\frac{v_{2}}{v_{1}} - \\frac{p_{2}}{p_{1}}$" ], "text/plain": [ "Equation(p2*v2*(gamma + 1)/(p1*v1), gamma - gamma*v2/v1 + gamma*p2/p1 + 1 + v2/v1 - p2/p1)" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = e.applylhs(factor)\n", "e" ] }, { "cell_type": "markdown", "id": "62e591a0-b0c2-42d3-a135-6e28379ba01e", "metadata": {}, "source": [ "On the RHS we can simply collect terms:" ] }, { "cell_type": "code", "execution_count": 13, "id": "1151ec3d-062e-4569-b8c0-70cbbccf3511", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{p_{2} v_{2} \\left(\\gamma + 1\\right)}{p_{1} v_{1}} = \\gamma + 1 + \\frac{v_{2} \\left(1 - \\gamma\\right)}{v_{1}} + \\frac{p_{2} \\left(\\gamma - 1\\right)}{p_{1}}$" ], "text/plain": [ "Equation(p2*v2*(gamma + 1)/(p1*v1), gamma + 1 + v2*(1 - gamma)/v1 + p2*(gamma - 1)/p1)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = e.dorhs.collect(p2 / p1).collect(v2 / v1)\n", "e" ] }, { "cell_type": "markdown", "id": "92cc0530-a704-442d-b86e-f39ece4eabea", "metadata": {}, "source": [ "Note, however, that we have two opposite terms: $(1 - \\gamma)$ and $(\\gamma - 1)$. It would be preferable to change $(1 - \\gamma) = -(\\gamma - 1)$." ] }, { "cell_type": "code", "execution_count": 14, "id": "966b8f39-9639-4896-a805-78c730d529e9", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{p_{2} v_{2} \\left(\\gamma + 1\\right)}{p_{1} v_{1}} = \\gamma + 1 - \\frac{v_{2} \\left(\\gamma - 1\\right)}{v_{1}} + \\frac{p_{2} \\left(\\gamma - 1\\right)}{p_{1}}$" ], "text/plain": [ "Equation(p2*v2*(gamma + 1)/(p1*v1), gamma + 1 - v2*(gamma - 1)/v1 + p2*(gamma - 1)/p1)" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = e.subs(1 - gamma, Mul(-1, gamma - 1, evaluate=False))\n", "e" ] }, { "cell_type": "markdown", "id": "b4e4ad6e-cb41-40de-88cb-a411df34d496", "metadata": {}, "source": [ "We can now divide both sides by $\\gamma - 1$:" ] }, { "cell_type": "code", "execution_count": 15, "id": "3db49892-510c-4a46-a2a8-28295702c52e", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{p_{2} v_{2} \\left(\\gamma + 1\\right)}{p_{1} v_{1} \\left(\\gamma - 1\\right)} = \\frac{\\gamma + 1 - \\frac{v_{2} \\left(\\gamma - 1\\right)}{v_{1}} + \\frac{p_{2} \\left(\\gamma - 1\\right)}{p_{1}}}{\\gamma - 1}$" ], "text/plain": [ "Equation(p2*v2*(gamma + 1)/(p1*v1*(gamma - 1)), (gamma + 1 - v2*(gamma - 1)/v1 + p2*(gamma - 1)/p1)/(gamma - 1))" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = e / (gamma - 1)\n", "e" ] }, { "cell_type": "markdown", "id": "93909776-9cf0-4fef-9ad2-239634e3b7a4", "metadata": {}, "source": [ "There is a small problem to be solved on the RHS: the division was not performed term by term. Right now, the RHS is a multiplication instead of an addition:" ] }, { "cell_type": "code", "execution_count": 16, "id": "df7d4013-5a12-443b-ad92-b70b147ac7a1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "sympy.core.mul.Mul" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e.rhs.func" ] }, { "cell_type": "code", "execution_count": 17, "id": "d365b463-c0f9-4339-8454-56051203f645", "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "| idx | args |\n", "|:-----:|:------|\n", "| 0 | $\\frac{1}{\\gamma - 1}$ |\n", "| 1 | $\\gamma + 1 - \\frac{v_{2} \\left(\\gamma - 1\\right)}{v_{1}} + \\frac{p_{2} \\left(\\gamma - 1\\right)}{p_{1}}$ |\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table_of_expressions(e.rhs)" ] }, { "cell_type": "markdown", "id": "cace8a3a-52ef-4ad1-a344-4f8a761aceb8", "metadata": {}, "source": [ "Let's evaluate that division term by term using `divide_term_by_term`, exposed by this module. This function automatically detects the deonominator:" ] }, { "cell_type": "code", "execution_count": 18, "id": "cac67b83-6ccf-4c85-a66e-e2d94a0e6658", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{p_{2} v_{2} \\left(\\gamma + 1\\right)}{p_{1} v_{1} \\left(\\gamma - 1\\right)} = \\frac{\\gamma}{\\gamma - 1} + \\frac{1}{\\gamma - 1} - \\frac{v_{2}}{v_{1}} + \\frac{p_{2}}{p_{1}}$" ], "text/plain": [ "Equation(p2*v2*(gamma + 1)/(p1*v1*(gamma - 1)), gamma/(gamma - 1) + 1/(gamma - 1) - v2/v1 + p2/p1)" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = e.applyrhs(divide_term_by_term)\n", "e" ] }, { "cell_type": "markdown", "id": "a4619cdd-12f2-41dc-9736-f7257d12beaf", "metadata": {}, "source": [ "Now we can combine the terms on the RHS where the denominator is $\\gamma - 1$. \n", "\n", "This is the perfect opportunity to showcase another function exposed by this module: `process_arguments_of_add`, which is going to replace the specified terms of an addition with the results of some user-provided function. First, let's get the indices of the terms we'd like to combine:" ] }, { "cell_type": "code", "execution_count": 19, "id": "dd07ad0c-7b14-49c4-8bc0-bd949dc39b51", "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "| idx | args |\n", "|:-----:|:------|\n", "| 0 | $\\frac{1}{\\gamma - 1}$ |\n", "| 1 | $\\frac{\\gamma}{\\gamma - 1}$ |\n", "| 2 | $\\frac{p_{2}}{p_{1}}$ |\n", "| 3 | $- \\frac{v_{2}}{v_{1}}$ |\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table_of_expressions(e.rhs, mode=\"args\")" ] }, { "cell_type": "markdown", "id": "a19cd907-0a57-4c5c-a7a4-41cb6a1dff26", "metadata": {}, "source": [ "The terms to be replaced are located at index 0 and 1. We are going to replace them with the result of SymPy's `together`:" ] }, { "cell_type": "code", "execution_count": 20, "id": "b9a0771f-1446-4a35-8606-11b68ad7a8dc", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{p_{2} v_{2} \\left(\\gamma + 1\\right)}{p_{1} v_{1} \\left(\\gamma - 1\\right)} = \\frac{\\gamma + 1}{\\gamma - 1} - \\frac{v_{2}}{v_{1}} + \\frac{p_{2}}{p_{1}}$" ], "text/plain": [ "Equation(p2*v2*(gamma + 1)/(p1*v1*(gamma - 1)), (gamma + 1)/(gamma - 1) - v2/v1 + p2/p1)" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = e.applyrhs(lambda expr: process_arguments_of_add(expr, [0, 1], together))\n", "e" ] }, { "cell_type": "markdown", "id": "1efea972-de2d-4582-ab2d-e6f7f277c481", "metadata": {}, "source": [ "Let's now bring the pressure ratio to the LHS:" ] }, { "cell_type": "code", "execution_count": 21, "id": "f3ce7f81-83b2-4be1-bcea-9ab8288df01d", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle - \\frac{p_{2}}{p_{1}} + \\frac{p_{2} v_{2} \\left(\\gamma + 1\\right)}{p_{1} v_{1} \\left(\\gamma - 1\\right)} = \\frac{\\gamma + 1}{\\gamma - 1} - \\frac{v_{2}}{v_{1}}$" ], "text/plain": [ "Equation(-p2/p1 + p2*v2*(gamma + 1)/(p1*v1*(gamma - 1)), (gamma + 1)/(gamma - 1) - v2/v1)" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = e - p2 / p1\n", "e" ] }, { "cell_type": "markdown", "id": "0f0bd0c6-159a-4ed1-886d-555b84cdab57", "metadata": {}, "source": [ "and collect it:" ] }, { "cell_type": "code", "execution_count": 22, "id": "43e7ef1e-6518-496e-bad4-d28d3c775526", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{p_{2} \\left(-1 + \\frac{v_{2} \\left(\\gamma + 1\\right)}{v_{1} \\left(\\gamma - 1\\right)}\\right)}{p_{1}} = \\frac{\\gamma + 1}{\\gamma - 1} - \\frac{v_{2}}{v_{1}}$" ], "text/plain": [ "Equation(p2*(-1 + v2*(gamma + 1)/(v1*(gamma - 1)))/p1, (gamma + 1)/(gamma - 1) - v2/v1)" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = e.dolhs.collect(p2 / p1)\n", "e" ] }, { "cell_type": "markdown", "id": "161a487a-25d8-45cc-be82-9ad3fc068bec", "metadata": {}, "source": [ "Finally, we can divide both side by the term in the parenthesys of the LHS. We can easily select it with:" ] }, { "cell_type": "code", "execution_count": 23, "id": "9f559d15-6ffb-40f4-9d55-afb9c6c04743", "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "| idx | args |\n", "|:-----:|:------|\n", "| 0 | $p_{2}$ |\n", "| 1 | $\\frac{1}{p_{1}}$ |\n", "| 2 | $-1 + \\frac{v_{2} \\left(\\gamma + 1\\right)}{v_{1} \\left(\\gamma - 1\\right)}$ |\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "toe = table_of_expressions(e.lhs)" ] }, { "cell_type": "code", "execution_count": 24, "id": "76bb015c-2dfa-4b8f-8d47-59862c3bd2ed", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{p_{2}}{p_{1}} = \\frac{\\frac{\\gamma + 1}{\\gamma - 1} - \\frac{v_{2}}{v_{1}}}{-1 + \\frac{v_{2} \\left(\\gamma + 1\\right)}{v_{1} \\left(\\gamma - 1\\right)}}$" ], "text/plain": [ "Equation(p2/p1, ((gamma + 1)/(gamma - 1) - v2/v1)/(-1 + v2*(gamma + 1)/(v1*(gamma - 1))))" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = e / toe[2]\n", "e" ] }, { "cell_type": "code", "execution_count": null, "id": "6b5fa4f1-030e-4909-bd36-f8169b8dfc52", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.7" } }, "nbformat": 4, "nbformat_minor": 5 }