mirror of
https://github.com/smyalygames/FiniteVolumeGPU.git
synced 2025-11-27 22:16:14 +01:00
286 lines
6.6 KiB
Plaintext
286 lines
6.6 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"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",
|
|
"from matplotlib import animation, rc\n",
|
|
"from matplotlib import pyplot as plt\n",
|
|
"\n",
|
|
"import importlib\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.common import Timer\n",
|
|
"from GPUSimulators.helpers import InitialConditions"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": "%setup_logging --out=test_schemes.log TestSchemes"
|
|
},
|
|
{
|
|
"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 2024.1\n",
|
|
"CUDA version (11, 8, 0)\n",
|
|
"Driver version 12080\n",
|
|
"Using device 0/1 'NVIDIA GeForce GTX 970' (0000:07:00.0) GPU\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Created context handle <98151551869168>\n",
|
|
"Using CUDA cache dir /home/smyalygames/PycharmProjects/FiniteVolumeGPU/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",
|
|
"# print(my_context.autotuner.get)\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",
|
|
" 'compile_opts': ['-Wno-deprecated-gpu-targets', '-arch=sm_52']\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.sim_time()) + \", nt=\" + str(sim.sim_steps()))\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()"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": [
|
|
"from GPUSimulators.model import LxF\n",
|
|
"\n",
|
|
"with Timer(\"construct\") as t:\n",
|
|
" sim = LxF(**arguments)\n",
|
|
"\n",
|
|
"with Timer(\"step\") as t:\n",
|
|
" t = sim.simulate(t_end)\n",
|
|
" \n",
|
|
"with Timer(\"download\") as t:\n",
|
|
" h1, hu1, hv1 = sim.download()\n",
|
|
"\n",
|
|
"plot(sim)"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": [
|
|
"from GPUSimulators.model import Force\n",
|
|
"\n",
|
|
"with Timer(\"construct\") as t:\n",
|
|
" sim = Force(**arguments)\n",
|
|
"\n",
|
|
"with Timer(\"step\") as t:\n",
|
|
" t = sim.simulate(t_end)\n",
|
|
" \n",
|
|
"with Timer(\"download\") as t:\n",
|
|
" h1, hu1, hv1 = sim.download()\n",
|
|
"\n",
|
|
"plot(sim)"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": [
|
|
"from GPUSimulators.model import HLL\n",
|
|
"\n",
|
|
"with Timer(\"construct\") as t:\n",
|
|
" sim = HLL(**arguments)\n",
|
|
"\n",
|
|
"with Timer(\"step\") as t:\n",
|
|
" t = sim.simulate(t_end)\n",
|
|
" \n",
|
|
"with Timer(\"download\") as t:\n",
|
|
" h1, hu1, hv1 = sim.download()\n",
|
|
"\n",
|
|
"plot(sim)"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": [
|
|
"from GPUSimulators.model import HLL2\n",
|
|
"\n",
|
|
"with Timer(\"construct\") as t:\n",
|
|
" sim = HLL2(**arguments)\n",
|
|
"\n",
|
|
"with Timer(\"step\") as t:\n",
|
|
" t = sim.simulate(t_end)\n",
|
|
" \n",
|
|
"with Timer(\"download\") as t:\n",
|
|
" h1, hu1, hv1 = sim.download()\n",
|
|
"\n",
|
|
"plot(sim)"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": [
|
|
"from GPUSimulators.model import KP07\n",
|
|
"\n",
|
|
"with Timer(\"construct\") as t:\n",
|
|
" sim = KP07(**arguments)\n",
|
|
"\n",
|
|
"with Timer(\"step\") as t:\n",
|
|
" t = sim.simulate(t_end)\n",
|
|
" \n",
|
|
"with Timer(\"download\") as t:\n",
|
|
" h1, hu1, hv1 = sim.download()\n",
|
|
"\n",
|
|
"plot(sim)"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": [
|
|
"from GPUSimulators.model import KP07Dimsplit\n",
|
|
"\n",
|
|
"with Timer(\"construct\") as t:\n",
|
|
" sim = KP07Dimsplit(**arguments)\n",
|
|
"\n",
|
|
"with Timer(\"step\") as t:\n",
|
|
" t = sim.simulate(t_end)\n",
|
|
" \n",
|
|
"with Timer(\"download\") as t:\n",
|
|
" h1, hu1, hv1 = sim.download()\n",
|
|
"\n",
|
|
"plot(sim)"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": [
|
|
"from GPUSimulators.model import WAF\n",
|
|
"\n",
|
|
"with Timer(\"construct\") as t:\n",
|
|
" sim = WAF(**arguments)\n",
|
|
"\n",
|
|
"with Timer(\"step\") as t:\n",
|
|
" t = sim.simulate(t_end)\n",
|
|
" \n",
|
|
"with Timer(\"download\") as t:\n",
|
|
" h1, hu1, hv1 = sim.download()\n",
|
|
"\n",
|
|
"plot(sim)"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": ""
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "ShallowWaterGPU",
|
|
"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.9.19"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|