{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nOne dimension Korteweg\u2013de Vries study case.\n===========================================\n\nThe `Korteweg\u2013de Vries <https://en.wikipedia.org/wiki/Korteweg%E2%80%93de_Vries_equation>`_\nequation is a non-linear PDE modeling wave on shallow water surfaces.\nIt reads\n\n\\begin{align}\\frac{\\partial U}{\\partial t} + U\\,\\frac{\\partial U}{\\partial x} = a\\,\\frac{\\partial^2 U}{\\partial x^2} + b\\,\\frac{\\partial^3 U}{\\partial x^3}\\end{align}\n\nThe initial conditions is taken as a smoothed triangle. The discontinuity occuring usually in Burger equation results here\nin a train of capillary wave after the wave front.\n\nThis example can be compeared with this `Dedalus Project example <https://dedalus-project.readthedocs\n.io/en/latest/notebooks/dedalus_tutorial_problems_solvers.html>`_ where the same model is solved with\npseudo-spectral method.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport pylab as pl\nfrom skfdiff import Model, Simulation\n\nmodel = Model(\"-U * dxU + a * dxxU + b * dxxxU\", \"U(x)\", [\"a\", \"b\"])\n\nx = np.linspace(-2, 6, 1000)\n\nn = 20\nU = np.log(1 + np.cosh(n) ** 2 / np.cosh(n * x) ** 2) / (2 * n)\n\ninitial_fields = model.fields_template(x=x, U=U, a=2e-4, b=1e-4)\n\nsimulation = Simulation(model, initial_fields, dt=0.05, tmax=10)\ncontainer = simulation.attach_container()\n\nsimulation.run()\n(\n    container.data.U[: -2 : container.data.t.size // 6].plot(\n        col=\"t\", col_wrap=3, color=\"black\"\n    )\n)\npl.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "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.6.7"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}