diff --git a/demos/larsen/plotting.ipynb b/demos/larsen/plotting.ipynb new file mode 100644 index 0000000..4e9dfc6 --- /dev/null +++ b/demos/larsen/plotting.ipynb @@ -0,0 +1,110 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "00b9d9b0-228c-4b3a-898f-310155884241", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "from matplotlib.animation import FuncAnimation\n", + "from IPython.display import HTML\n", + "import firedrake\n", + "from firedrake import assemble, Constant, dx" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "433b55e3-1adb-47c8-8c01-3f55f8b61731", + "metadata": {}, + "outputs": [], + "source": [ + "num_steps = 48\n", + "with firedrake.CheckpointFile(\"larsen-simulation.h5\", \"r\") as chk:\n", + " mesh = chk.load_mesh()\n", + " hs = []\n", + " for index in range(2 * num_steps + 1):\n", + " hs.append(chk.load_function(mesh, name=\"thickness\", idx=index))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bc119fed-1a80-47c5-a2e7-a600c79da05b", + "metadata": {}, + "outputs": [], + "source": [ + "volumes = np.array([firedrake.assemble(h * dx) for h in hs]) / 1e9" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "db139cb0-b44d-46cd-919a-8382bd475fe9", + "metadata": {}, + "outputs": [], + "source": [ + "fig, axes = plt.subplots()\n", + "axes.plot(volumes);" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "225cf777-e341-419e-984f-e2b63e94e0c3", + "metadata": {}, + "outputs": [], + "source": [ + "%%capture\n", + "\n", + "fn_plotter = firedrake.FunctionPlotter(mesh, num_sample_points=4)\n", + "\n", + "fig, axes = plt.subplots()\n", + "axes.set_aspect(\"equal\")\n", + "axes.set_xlim((-2250e3, -2025e3))\n", + "axes.set_ylim((1075e3, 1250e3))\n", + "colors = firedrake.tripcolor(hs[0], num_sample_points=4, axes=axes)\n", + "fig.colorbar(colors)\n", + "\n", + "def animate(h):\n", + " colors.set_array(fn_plotter(h))\n", + "\n", + "animation = FuncAnimation(fig, animate, hs, interval=1e3/24)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "74595562-ad1e-44ff-9a7e-dba0af9a31d2", + "metadata": {}, + "outputs": [], + "source": [ + "HTML(animation.to_html5_video())" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "firedrake", + "language": "python", + "name": "firedrake" + }, + "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.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}