{ "cells": [ { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "# Boundary Conditions: Deduction for the Lattice D2Q5 - Poisson Equation" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "from __future__ import division\n", "from sympy import *\n", "import numpy as np\n", "from sympy import S, collect, expand, factor, Wild\n", "from sympy import fraction, Rational, Symbol\n", "from sympy import solve\n", "#-------------------------------------------------Symbols----------------------------------------------\n", "p, dpx, dpy = symbols('\\widehat{p} \\\\partial_{x}\\widehat{p} \\\\partial_{y}\\widehat{p}')\n", "ux, uy, tau, cs = symbols('u_{x} u_{y} \\\\tau c_{s}')\n", "wi, cx, cy = symbols('w_{i} c_{x} c_{y}')\n", "fi, f0, f1, f2, f3, f4 = symbols('f_{i} f_{0} f_{1} f_{2} f_{3} f_{4}')\n", "#-------------------------------------------------Functions----------------------------------------------\n", "feq = Function('feq')(wi, cx, cy)\n", "f = Function('f')(fi)\n", "#-------------------------------------------------Arrays----------------------------------------------\n", "fi=np.array([f0,f1,f2,f3,f4])\n", "wi=np.array([Rational(2,6),Rational(1,6),Rational(1,6),Rational(1,6),Rational(1,6)])\n", "cx=np.array([0,1,0,-1,0])\n", "cy=np.array([0,0,1,0,-1])\n", "#-------------------------------------------------Calc.Func------------------------------------------------\n", "f= fi\n", "feq=p*wi\n", "feq[0]=p*(wi[0]-1)" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## Boundary Layers" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "### Pressure Moment" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle - \\widehat{p} + \\frac{3 f_{1}}{2} + \\frac{3 f_{2}}{2} + \\frac{3 f_{3}}{2} + \\frac{3 f_{4}}{2}$" ], "text/plain": [ "-\\widehat{p} + 3*f_{1}/2 + 3*f_{2}/2 + 3*f_{3}/2 + 3*f_{4}/2" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "An0=simplify(sum(f[1:])/(1-wi[0])-p)\n", "An0\n", "#print(latex(An2))" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "### Camada Norte " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "editable": true, "scrolled": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle f_{4} = \\frac{2 \\widehat{p}}{3} - f_{1} - f_{2} - f_{3}$" ], "text/plain": [ "Eq(f_{4}, 2*\\widehat{p}/3 - f_{1} - f_{2} - f_{3})" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sols = solve([An0], [f4], dict=True)\n", "# sols\n", "b1=Array(sols[0][f4])\n", "b0 = Array(f4)\n", "Eq(b0,b1)" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "### Camada Sul" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle f_{2} = \\frac{2 \\widehat{p}}{3} - f_{1} - f_{3} - f_{4}$" ], "text/plain": [ "Eq(f_{2}, 2*\\widehat{p}/3 - f_{1} - f_{3} - f_{4})" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sols = solve([An0], [f2], dict=True)\n", "# sols\n", "b1=Array(sols[0][f2])\n", "b0 = Array(f2)\n", "Eq(b0,b1)" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "### Camada Oeste" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "editable": true, "scrolled": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle f_{1} = \\frac{2 \\widehat{p}}{3} - f_{2} - f_{3} - f_{4}$" ], "text/plain": [ "Eq(f_{1}, 2*\\widehat{p}/3 - f_{2} - f_{3} - f_{4})" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sols = solve([An0], [f1], dict=True)\n", "# sols\n", "b1=Array(sols[0][f1])\n", "b0 = Array(f1)\n", "Eq(b0,b1)" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "### Camada Leste " ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "editable": true, "scrolled": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle f_{3} = \\frac{2 \\widehat{p}}{3} - f_{1} - f_{2} - f_{4}$" ], "text/plain": [ "Eq(f_{3}, 2*\\widehat{p}/3 - f_{1} - f_{2} - f_{4})" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sols = solve([An0], [f3], dict=True)\n", "# sols\n", "b1=Array(sols[0][f3])\n", "b0 = Array(f3)\n", "Eq(b0,b1)" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## Corner Boundaries" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "### Camada Noroeste" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\tau c_{s}^{2} \\left(\\partial_{x}\\widehat{p} + \\partial_{y}\\widehat{p}\\right) + f_{1} + f_{2} - f_{3} - f_{4}$" ], "text/plain": [ "\\tau*c_{s}**2*(\\partial_{x}\\widehat{p} + \\partial_{y}\\widehat{p}) + f_{1} + f_{2} - f_{3} - f_{4}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Bn0=simplify(sum(f*(cx+cy))+(dpx+dpy)*cs**2*tau)\n", "Bn0\n", "#print(latex(An2))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "editable": true, "scrolled": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}f_{1}\\\\f_{4}\\end{matrix}\\right] = \\left[\\begin{matrix}- \\frac{\\partial_{x}\\widehat{p} \\tau c_{s}^{2}}{2} - \\frac{\\partial_{y}\\widehat{p} \\tau c_{s}^{2}}{2} + \\frac{\\widehat{p}}{3} - f_{2}\\\\\\frac{\\partial_{x}\\widehat{p} \\tau c_{s}^{2}}{2} + \\frac{\\partial_{y}\\widehat{p} \\tau c_{s}^{2}}{2} + \\frac{\\widehat{p}}{3} - f_{3}\\end{matrix}\\right]$" ], "text/plain": [ "Eq([[f_{1}], [f_{4}]], Matrix([\n", "[-\\partial_{x}\\widehat{p}*\\tau*c_{s}**2/2 - \\partial_{y}\\widehat{p}*\\tau*c_{s}**2/2 + \\widehat{p}/3 - f_{2}],\n", "[ \\partial_{x}\\widehat{p}*\\tau*c_{s}**2/2 + \\partial_{y}\\widehat{p}*\\tau*c_{s}**2/2 + \\widehat{p}/3 - f_{3}]]))" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sols = solve([An0, Bn0], [f1,f4], dict=True)\n", "# sols\n", "b1=Matrix([[sols[0][f1]],[sols[0][f4]]])\n", "b0 = Array([[f1],[f4]])\n", "Eq(b0,b1)" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## Camada Nordeste" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\tau c_{s}^{2} \\left(\\partial_{x}\\widehat{p} - \\partial_{y}\\widehat{p}\\right) + f_{1} - f_{2} - f_{3} + f_{4}$" ], "text/plain": [ "\\tau*c_{s}**2*(\\partial_{x}\\widehat{p} - \\partial_{y}\\widehat{p}) + f_{1} - f_{2} - f_{3} + f_{4}" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Bn0=simplify(sum(f*(cx-cy))+(dpx-dpy)*cs**2*tau)\n", "Bn0\n", "#print(latex(An2))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "editable": true, "scrolled": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}f_{3}\\\\f_{4}\\end{matrix}\\right] = \\left[\\begin{matrix}\\frac{\\partial_{x}\\widehat{p} \\tau c_{s}^{2}}{2} - \\frac{\\partial_{y}\\widehat{p} \\tau c_{s}^{2}}{2} + \\frac{\\widehat{p}}{3} - f_{2}\\\\- \\frac{\\partial_{x}\\widehat{p} \\tau c_{s}^{2}}{2} + \\frac{\\partial_{y}\\widehat{p} \\tau c_{s}^{2}}{2} + \\frac{\\widehat{p}}{3} - f_{1}\\end{matrix}\\right]$" ], "text/plain": [ "Eq([[f_{3}], [f_{4}]], Matrix([\n", "[ \\partial_{x}\\widehat{p}*\\tau*c_{s}**2/2 - \\partial_{y}\\widehat{p}*\\tau*c_{s}**2/2 + \\widehat{p}/3 - f_{2}],\n", "[-\\partial_{x}\\widehat{p}*\\tau*c_{s}**2/2 + \\partial_{y}\\widehat{p}*\\tau*c_{s}**2/2 + \\widehat{p}/3 - f_{1}]]))" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sols = solve([An0, Bn0], [f3,f4], dict=True)\n", "# sols\n", "b1=Matrix([[sols[0][f3]],[sols[0][f4]]])\n", "b0 = Array([[f3],[f4]])\n", "Eq(b0,b1)" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## Camada Sudoeste" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\tau c_{s}^{2} \\left(\\partial_{x}\\widehat{p} - \\partial_{y}\\widehat{p}\\right) + f_{1} - f_{2} - f_{3} + f_{4}$" ], "text/plain": [ "\\tau*c_{s}**2*(\\partial_{x}\\widehat{p} - \\partial_{y}\\widehat{p}) + f_{1} - f_{2} - f_{3} + f_{4}" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Bn0=simplify(sum(f*(cx-cy))+(dpx-dpy)*cs**2*tau)\n", "Bn0\n", "#print(latex(An2))" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "editable": true, "scrolled": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}f_{1}\\\\f_{2}\\end{matrix}\\right] = \\left[\\begin{matrix}- \\frac{\\partial_{x}\\widehat{p} \\tau c_{s}^{2}}{2} + \\frac{\\partial_{y}\\widehat{p} \\tau c_{s}^{2}}{2} + \\frac{\\widehat{p}}{3} - f_{4}\\\\\\frac{\\partial_{x}\\widehat{p} \\tau c_{s}^{2}}{2} - \\frac{\\partial_{y}\\widehat{p} \\tau c_{s}^{2}}{2} + \\frac{\\widehat{p}}{3} - f_{3}\\end{matrix}\\right]$" ], "text/plain": [ "Eq([[f_{1}], [f_{2}]], Matrix([\n", "[-\\partial_{x}\\widehat{p}*\\tau*c_{s}**2/2 + \\partial_{y}\\widehat{p}*\\tau*c_{s}**2/2 + \\widehat{p}/3 - f_{4}],\n", "[ \\partial_{x}\\widehat{p}*\\tau*c_{s}**2/2 - \\partial_{y}\\widehat{p}*\\tau*c_{s}**2/2 + \\widehat{p}/3 - f_{3}]]))" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sols = solve([An0, Bn0], [f1,f2], dict=True)\n", "# sols\n", "b1=Matrix([[sols[0][f1]],[sols[0][f2]]])\n", "b0 = Array([[f1],[f2]])\n", "Eq(b0,b1)" ] }, { "cell_type": "markdown", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## Camada Sudeste " ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\tau c_{s}^{2} \\left(\\partial_{x}\\widehat{p} + \\partial_{y}\\widehat{p}\\right) + f_{1} + f_{2} - f_{3} - f_{4}$" ], "text/plain": [ "\\tau*c_{s}**2*(\\partial_{x}\\widehat{p} + \\partial_{y}\\widehat{p}) + f_{1} + f_{2} - f_{3} - f_{4}" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Bn0=simplify(sum(f*(cx+cy))+(dpx+dpy)*cs**2*tau)\n", "Bn0\n", "#print(latex(An2))" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "editable": true, "scrolled": true, "slideshow": { "slide_type": "" }, "tags": [ "hide-input" ] }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}f_{2}\\\\f_{3}\\end{matrix}\\right] = \\left[\\begin{matrix}- \\frac{\\partial_{x}\\widehat{p} \\tau c_{s}^{2}}{2} - \\frac{\\partial_{y}\\widehat{p} \\tau c_{s}^{2}}{2} + \\frac{\\widehat{p}}{3} - f_{1}\\\\\\frac{\\partial_{x}\\widehat{p} \\tau c_{s}^{2}}{2} + \\frac{\\partial_{y}\\widehat{p} \\tau c_{s}^{2}}{2} + \\frac{\\widehat{p}}{3} - f_{4}\\end{matrix}\\right]$" ], "text/plain": [ "Eq([[f_{2}], [f_{3}]], Matrix([\n", "[-\\partial_{x}\\widehat{p}*\\tau*c_{s}**2/2 - \\partial_{y}\\widehat{p}*\\tau*c_{s}**2/2 + \\widehat{p}/3 - f_{1}],\n", "[ \\partial_{x}\\widehat{p}*\\tau*c_{s}**2/2 + \\partial_{y}\\widehat{p}*\\tau*c_{s}**2/2 + \\widehat{p}/3 - f_{4}]]))" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sols = solve([An0, Bn0], [f2,f3], dict=True)\n", "# sols\n", "b1=Matrix([[sols[0][f2]],[sols[0][f3]]])\n", "b0 = Array([[f2],[f3]])\n", "Eq(b0,b1)" ] } ], "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.10.12" } }, "nbformat": 4, "nbformat_minor": 4 }