{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Advection using the k-Scheme\n", "## CH EN 6355 - Computational Fluid Dynamics\n", "**Prof. Tony Saad (www.tsaad.net)
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here, we will implement the k-scheme or kappa-schemes for advection. It is easiest to implement this scheme since for different values of k, we recover all sorts of high-order flux approximations. We will assume a positive advecting velocity for illustration purposes.\n", "\n", "We are solving the constant speed advection equation given by\n", "\$$\n", "u_t = - c u_x = - F_x;\\quad F = cu\n", "\$$\n", "We will use a simple Forward Euler explicit method. Using a finite volume integration, we get\n", "\$$\n", "u_i^{n+1} = u_i^n - \\frac{\\Delta t}{\\Delta x} (F_{i+\\tfrac{1}{2}}^n - F_{i-\\tfrac{1}{2}}^n)\n", "\$$\n", "For constant grid spacing, the k-Scheme is given by\n", "\$$\n", "{\\phi _f} = {\\phi _{\\rm{C}}} + \\frac{{1 - k}}{4}({\\phi _{\\rm{C}}} - {\\phi _{\\rm{U}}}) + \\frac{{1 + k}}{4}({\\phi _{\\rm{D}}} - {\\phi _{\\rm{C}}})\n", "\$$\n", "which, for a positive advecting velocity, gives us\n", "\$$\n", "F_{i + {\\textstyle{1 \\over 2}}}^n = c\\phi _{i + {\\textstyle{1 \\over 2}}}^n = c{\\phi _i} + c\\frac{{1 - k}}{4}({\\phi _i} - {\\phi _{i - 1}}) + c\\frac{{1 + k}}{4}({\\phi _{i + 1}} - {\\phi _i})\n", "\$$" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "%matplotlib inline\n", "%config InlineBackend.figure_format = 'svg'\n", "import matplotlib.pyplot as plt\n", "import matplotlib.animation as animation\n", "plt.rcParams['animation.html'] = 'html5'\n", "from matplotlib import cm" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def step(x,x0):\n", " x0 = 0.6\n", " x1 = 0.8\n", " result = x - x0\n", " result[x-x1x1] = 0.0 \n", " return result\n", "\n", "def gaussian(x,x0):\n", " s = 0.08\n", " s = s*s\n", " result = np.exp( -(x-x0)**2/s)\n", " return result" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n" ], "text/plain": [ "