Skip to content

Commit

Permalink
Checkpoint, make plotting notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
danshapero committed Oct 16, 2023
1 parent c2c2b13 commit 9cae14b
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions demos/larsen/plotting.ipynb
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 9cae14b

Please sign in to comment.