{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Lets have matplotlib \"inline\"\n",
    "%matplotlib inline\n",
    "\n",
    "# Add line profiler\n",
    "%load_ext line_profiler\n",
    "\n",
    "#Import packages we need\n",
    "import numpy as np\n",
    "from matplotlib import animation, rc\n",
    "from matplotlib import pyplot as plt\n",
    "\n",
    "import subprocess\n",
    "import os\n",
    "import gc\n",
    "import datetime\n",
    "import importlib\n",
    "import logging\n",
    "\n",
    "import pycuda.driver as cuda\n",
    "import pycuda.compiler\n",
    "\n",
    "try:\n",
    "    from StringIO import StringIO\n",
    "except ImportError:\n",
    "    from io import StringIO\n",
    "    \n",
    "#Set large figure sizes\n",
    "#Note, this prevents nice figures for articles...\n",
    "rc('figure', figsize=(16.0, 12.0))\n",
    "rc('animation', html='html5')\n",
    "\n",
    "from GPUSimulators import Common, IPythonMagic\n",
    "from GPUSimulators.helpers import InitialConditions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Console logger using level INFO\n",
      "File logger using level DEBUG to test_schemes.log\n",
      "Python version 3.6.7 |Anaconda custom (64-bit)| (default, Oct 28 2018, 19:44:12) [MSC v.1915 64 bit (AMD64)]\n"
     ]
    }
   ],
   "source": [
    "%setup_logging --out test_schemes.log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Registering my_context in user workspace\n",
      "PyCUDA version 2018.1.1\n",
      "CUDA version (10, 0, 0)\n",
      "Driver version 10000\n",
      "Using 'GeForce 840M' GPU\n",
      "Created context handle <266635220976>\n",
      "Using CUDA cache dir c:\\Users\\anbro\\Documents\\projects\\GPUSimulators\\GPUSimulators\\cuda_cache\n",
      "Autotuning enabled. It may take several minutes to run the code the first time: have patience\n"
     ]
    }
   ],
   "source": [
    "%cuda_context_handler my_context"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "nx = 256\n",
    "ny = 128\n",
    "g = 9.81\n",
    "\n",
    "h0, hu0, hv0, dx, dy = InitialConditions.bump(nx, ny, 100, 100, 15)\n",
    "\n",
    "arguments = {\n",
    "    'context': my_context,\n",
    "    'h0': h0, 'hu0': hu0, 'hv0': hv0,\n",
    "    'nx': nx, 'ny': ny,\n",
    "    'dx': dx, 'dy': dy, \n",
    "    'g': g\n",
    "} \n",
    "\n",
    "t_end = 20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot(sim):\n",
    "    h = sim.u0[0].download(sim.stream)\n",
    "    \n",
    "    plt.figure()\n",
    "    plt.title(str(sim) + \", t=\" + str(sim.simTime()) + \", nt=\" + str(sim.simSteps()))\n",
    "    extent = [0, sim.dx*sim.nx, 0, sim.dy*sim.ny]\n",
    "    plt.imshow(h, vmin=0.49, vmax=0.52, extent=extent)\n",
    "    plt.colorbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 46644 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from GPUSimulators import LxF\n",
    "importlib.reload(LxF)\n",
    "\n",
    "with Common.Timer(\"construct\") as t:\n",
    "    sim = LxF.LxF(**arguments)\n",
    "\n",
    "with Common.Timer(\"step\") as t:\n",
    "    t = sim.simulate(t_end)\n",
    "    \n",
    "with Common.Timer(\"download\") as t:\n",
    "    h1, hu1, hv1 = sim.download()\n",
    "\n",
    "plot(sim)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 44360 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from GPUSimulators import FORCE\n",
    "importlib.reload(FORCE)\n",
    "\n",
    "with Common.Timer(\"construct\") as t:\n",
    "    sim = FORCE.FORCE(**arguments)\n",
    "\n",
    "with Common.Timer(\"step\") as t:\n",
    "    t = sim.simulate(t_end)\n",
    "    \n",
    "with Common.Timer(\"download\") as t:\n",
    "    h1, hu1, hv1 = sim.download()\n",
    "\n",
    "plot(sim)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 43688 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from GPUSimulators import HLL\n",
    "importlib.reload(HLL)\n",
    "\n",
    "with Common.Timer(\"construct\") as t:\n",
    "    sim = HLL.HLL(**arguments)\n",
    "\n",
    "with Common.Timer(\"step\") as t:\n",
    "    t = sim.simulate(t_end)\n",
    "    \n",
    "with Common.Timer(\"download\") as t:\n",
    "    h1, hu1, hv1 = sim.download()\n",
    "\n",
    "plot(sim)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 48232 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from GPUSimulators import HLL2\n",
    "importlib.reload(HLL2)\n",
    "\n",
    "with Common.Timer(\"construct\") as t:\n",
    "    sim = HLL2.HLL2(**arguments)\n",
    "\n",
    "with Common.Timer(\"step\") as t:\n",
    "    t = sim.simulate(t_end)\n",
    "    \n",
    "with Common.Timer(\"download\") as t:\n",
    "    h1, hu1, hv1 = sim.download()\n",
    "\n",
    "plot(sim)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 48592 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from GPUSimulators import KP07\n",
    "importlib.reload(KP07)\n",
    "\n",
    "with Common.Timer(\"construct\") as t:\n",
    "    sim = KP07.KP07(**arguments)\n",
    "\n",
    "with Common.Timer(\"step\") as t:\n",
    "    t = sim.simulate(t_end)\n",
    "    \n",
    "with Common.Timer(\"download\") as t:\n",
    "    h1, hu1, hv1 = sim.download()\n",
    "\n",
    "plot(sim)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 49080 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from GPUSimulators import KP07_dimsplit\n",
    "importlib.reload(KP07_dimsplit)\n",
    "\n",
    "with Common.Timer(\"construct\") as t:\n",
    "    sim = KP07_dimsplit.KP07_dimsplit(**arguments)\n",
    "\n",
    "with Common.Timer(\"step\") as t:\n",
    "    t = sim.simulate(t_end)\n",
    "    \n",
    "with Common.Timer(\"download\") as t:\n",
    "    h1, hu1, hv1 = sim.download()\n",
    "\n",
    "plot(sim)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 48360 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from GPUSimulators import WAF\n",
    "importlib.reload(WAF)\n",
    "\n",
    "with Common.Timer(\"construct\") as t:\n",
    "    sim = WAF.WAF(**arguments)\n",
    "\n",
    "with Common.Timer(\"step\") as t:\n",
    "    t = sim.simulate(t_end)\n",
    "    \n",
    "with Common.Timer(\"download\") as t:\n",
    "    h1, hu1, hv1 = sim.download()\n",
    "\n",
    "plot(sim)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [default]",
   "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": 2
}
