{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

KdV Solitons with Vpython

\n", "

\n", "Explict solution of the Korteweg and deVries (KdeV) equation (nonlinear and dispersive) for solitons with Vpython animation:\n", "$$\n", "\\frac{\\partial u(x,t)}{\\partial t} + \\varepsilon u(x,t)\\,\n", "\\frac{\\partial u(x,t)}{\\partial x} + \\mu \\, \\frac{\\partial ^3\n", "u(x,t)}{\\partial x^3} = 0. \n", "$$" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") { window.__context = { glowscript_container: $(\"#glowscript\").removeAttr(\"id\")};}else{ element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") { window.__context = { glowscript_container: $(\"#glowscript\").removeAttr(\"id\")};}else{ element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") {require.undef(\"nbextensions/vpython_libraries/glow.min\");}else{element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") {require.undef(\"nbextensions/vpython_libraries/glowcomm\");}else{element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") {require.undef(\"nbextensions/vpython_libraries/jquery-ui.custom.min\");}else{element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") {require([\"nbextensions/vpython_libraries/glow.min\"], function(){console.log(\"GLOW LOADED\");});}else{element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") {require([\"nbextensions/vpython_libraries/glowcomm\"], function(){console.log(\"GLOWCOMM LOADED\");});}else{element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "if (typeof Jupyter !== \"undefined\") {require([\"nbextensions/vpython_libraries/jquery-ui.custom.min\"], function(){console.log(\"JQUERY LOADED\");});}else{element.textContent = ' ';}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "finished\n" ] } ], "source": [ "\"\"\"From \"COMPUTATIONAL PHYSICS\" & \"COMPUTER PROBLEMS in PHYSICS\" \n", "by RH Landau, MJ Paez, and CC Bordeianu (deceased). Copyright R Landau, \n", "Oregon State Unv, MJ Paez, Univ Antioquia, C Bordeianu (deceased), \n", "Univ Bucharest, 2020. Please respect copyright & acknowledge our work.\"\"\"\n", "\n", "# KdVsolitonsVPmod.ipynb: Animated KdeV solitons with Vpython\n", "\n", "% matplotlib notebook\n", "from vpython import *\n", "import numpy as np\n", "\n", "g = canvas(width = 600, height = 300, title = 'Soliton')\n", "sol = curve(x = list(range(0, 131)), color = color.yellow)\n", "sol.radius = 1.0 # thickness of line\n", "ds = 0.4 # Delta x\n", "dt = 0.2 # Delta t\n", "max = 500 # Numb t steps\n", "mu = 0.1; # Mu from KdeV equation\n", "eps = 0.2; # Epsilon from KdeV eq\n", "mx = 131 # grid in x max\n", "fac = mu*dt/(ds**3) # combor\n", "u = np.zeros( (mx, 3), float) # Wave\n", "\n", "for i in range(0, mx): # Initial wave\n", " u[i, 0] = 0.5*(1.-((np.exp(2*(0.2*ds*i-5.))-1)\n", " \t /(np.exp(2*(0.2*ds*i-5.))+1)))\n", "u[0, 1] = 1.\n", "u[0, 2] = 1.\n", "u[mx-1, 1] = 0.\n", "u[mx-1, 2] = 0. # End point\n", "\n", "for i in range (1, mx - 1 ): # First time step\n", " a1 = eps*dt*(u[i + 1, 0] + u[i, 0] + u[i - 1, 0])/(ds*6.) \n", " if i>1 and i < 119: a2 = u[i+2,0] + 2.*u[i-1,0] - 2.*u[i+1,0] - u[i-2,0]\n", " else: a2 = u[i - 1, 0] - u[i + 1, 0]\n", " a3 = u[i + 1, 0] - u[i - 1, 0] \n", " u[i, 1] = u[i, 0] - a1*a3 - fac*a2/3. \n", "\n", "for j in range (1, max + 1):\n", " for i in range(1, mx - 2):\n", " a1 = eps*dt*(u[i + 1, 1] + u[i, 1] + u[i - 1, 1])/(3.*ds)\n", " if i>1 and i < mx-2: a2 = u[i+2,1] + 2*u[i-1,1]-2*u[i+1,1]-u[i-2,1]\n", " else: a2 = u[i-1, 1] - u[i+1, 1] \n", " a3 = u[i + 1, 1] - u[i - 1, 1] \n", " u[i, 2] = u[i, 0] - a1*a3 - 2.*fac*a2/3.\n", " sol.clear() \n", " for i in range (10, mx-20): sol.append(pos =vec( 2*i - mx, 50.*u[i, 2] - 30,0))\n", " rate(100)\n", " for k in range(0, mx): # Recycle array\n", " u[k, 0] = u[k, 1] \n", " u[k, 1] = u[k, 2] \n", "print(\"finished\") " ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 2 }