From 260d64a25727678f9109f3664bcbd460ae8dce86 Mon Sep 17 00:00:00 2001 From: Angus Gibson Date: Mon, 12 Feb 2024 09:36:40 +1100 Subject: [PATCH 1/5] Work only on 01-spd-helmholtz.ipynb to start with --- .github/workflows/test.yml | 4 ++-- docs/_toc.yml | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b74ae03..c99928f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,13 +33,13 @@ jobs: export PYVISTA_OFF_SCREEN=true Xvfb $DISPLAY -screen 0 1024x768x24 > /dev/null 2>&1 & sleep 3 - pytest --nbval *.ipynb + pytest --nbval 01-*.ipynb - name: Build Jupyter Book run: | . /home/firedrake/firedrake/bin/activate python3 -m pip install jupyter-book - for f in *.ipynb; do ln -s ../$f docs; done + for f in 01-*.ipynb; do ln -s ../$f docs; done ln -s ../stokes-control.msh docs export DISPLAY=:99 export PYVISTA_OFF_SCREEN=true diff --git a/docs/_toc.yml b/docs/_toc.yml index 97aea14..bdb179f 100644 --- a/docs/_toc.yml +++ b/docs/_toc.yml @@ -2,9 +2,3 @@ format: jb-book root: index chapters: - file: 01-spd-helmholtz - - file: 02-poisson - - file: 03-elasticity - - file: 04-burgers - - file: 05-pde-constrained-optimisation - - file: 06-GD-2D-convection - - file: 07-GD-2D-cylindrical From 2cb6d306c1a01a10ceb8751a9633870f2e155286 Mon Sep 17 00:00:00 2001 From: Angus Gibson Date: Mon, 12 Feb 2024 09:44:04 +1100 Subject: [PATCH 2/5] Explicitly import triplot from firedrake --- 01-spd-helmholtz.ipynb | 5 +++-- 02-poisson.ipynb | 1 + 03-elasticity.ipynb | 1 + 04-burgers.ipynb | 1 + 05-pde-constrained-optimisation.ipynb | 3 ++- 06-GD-2D-convection.ipynb | 9 +++++---- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/01-spd-helmholtz.ipynb b/01-spd-helmholtz.ipynb index dbef946..329308a 100644 --- a/01-spd-helmholtz.ipynb +++ b/01-spd-helmholtz.ipynb @@ -122,7 +122,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "To start, we must make Firedrake available in the notebook. It is available as a normal Python package, named `firedrake`. To save on typing, we will import all of the public API into the current namespace" + "To start, we must make Firedrake available in the notebook. We will import it through the `gadopt` package. To save on typing, we will import all of the public API into the current namespace. For plotting within this notebook, we also explicitly import the `triplot` function." ] }, { @@ -131,7 +131,8 @@ "metadata": {}, "outputs": [], "source": [ - "from gadopt import *" + "from gadopt import *\n", + "from firedrake.pyplot import triplot, tripcolor" ] }, { diff --git a/02-poisson.ipynb b/02-poisson.ipynb index 68278c4..513d7f7 100644 --- a/02-poisson.ipynb +++ b/02-poisson.ipynb @@ -60,6 +60,7 @@ " !wget \"https://github.com/g-adopt/tutorials/releases/latest/download/firedrake-install-real.sh\" -O \"/tmp/firedrake-install.sh\" && bash \"/tmp/firedrake-install.sh\"\n", " import firedrake\n", "from gadopt import *\n", + "from firedrake.pyplot import tripcolor\n", "mesh = UnitSquareMesh(10, 10)\n", "V = FunctionSpace(mesh, \"Lagrange\", 1)" ] diff --git a/03-elasticity.ipynb b/03-elasticity.ipynb index 936b697..fe6cc04 100644 --- a/03-elasticity.ipynb +++ b/03-elasticity.ipynb @@ -56,6 +56,7 @@ " !wget \"https://github.com/g-adopt/tutorials/releases/latest/download/firedrake-install-real.sh\" -O \"/tmp/firedrake-install.sh\" && bash \"/tmp/firedrake-install.sh\"\n", " import firedrake\n", "from gadopt import *\n", + "from firedrake.pyplot import triplot\n", "length = 1\n", "width = 0.2\n", "mesh = RectangleMesh(40, 20, length, width)" diff --git a/04-burgers.ipynb b/04-burgers.ipynb index ade8e18..c6fe0b9 100644 --- a/04-burgers.ipynb +++ b/04-burgers.ipynb @@ -58,6 +58,7 @@ " !wget \"https://github.com/g-adopt/tutorials/releases/latest/download/firedrake-install-real.sh\" -O \"/tmp/firedrake-install.sh\" && bash \"/tmp/firedrake-install.sh\"\n", " import firedrake\n", "from gadopt import *\n", + "from firedrake.pyplot import plot\n", "\n", "n = 100\n", "mesh = PeriodicIntervalMesh(n, length=2)\n", diff --git a/05-pde-constrained-optimisation.ipynb b/05-pde-constrained-optimisation.ipynb index 76370b3..f8d41a5 100644 --- a/05-pde-constrained-optimisation.ipynb +++ b/05-pde-constrained-optimisation.ipynb @@ -49,7 +49,8 @@ "outputs": [], "source": [ "from gadopt import *\n", - "from gadopt.inverse import *" + "from gadopt.inverse import *\n", + "from firedrake.pyplot import quiver, streamplot, tricontourf, triplot" ] }, { diff --git a/06-GD-2D-convection.ipynb b/06-GD-2D-convection.ipynb index 3399f14..71dfabc 100644 --- a/06-GD-2D-convection.ipynb +++ b/06-GD-2D-convection.ipynb @@ -141,7 +141,8 @@ "metadata": {}, "outputs": [], "source": [ - "from gadopt import *" + "from gadopt import *\n", + "from firedrake.pyplot import tripcolor" ] }, { @@ -290,7 +291,7 @@ "Ra, delta_t = Constant(1e4), Constant(1e-3)\n", "\n", "approximation = BoussinesqApproximation(Ra)\n", - "t_adapt = TimestepAdaptor(delta_t, V, maximum_timestep=0.1, increase_tolerance=1.5)" + "t_adapt = TimestepAdaptor(delta_t, u, V, maximum_timestep=0.1, increase_tolerance=1.5)" ] }, { @@ -377,7 +378,7 @@ "gd = GeodynamicalDiagnostics(u, p, T, bottom, top)\n", "\n", "for timestep in range(0, no_timesteps+1):\n", - " dt = t_adapt.update_timestep(u)\n", + " dt = t_adapt.update_timestep()\n", " time += dt\n", "\n", " stokes_solver.solve()\n", @@ -521,7 +522,7 @@ "gd = GeodynamicalDiagnostics(u, p, T, bottom, top)\n", "\n", "for timestep in range(0, no_timesteps+1):\n", - " dt = t_adapt.update_timestep(u)\n", + " dt = t_adapt.update_timestep()\n", " time += dt\n", "\n", " stokes_solver.solve()\n", From 80c48f9b28985b50fe2b378c319fa662c36134b2 Mon Sep 17 00:00:00 2001 From: Rhodri Davies Date: Thu, 22 Feb 2024 13:19:57 +1100 Subject: [PATCH 3/5] Ensure that tutorials 6 and 7 are valid after recent changes. --- 06-GD-2D-convection.ipynb | 2 +- 07-GD-2D-cylindrical.ipynb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/06-GD-2D-convection.ipynb b/06-GD-2D-convection.ipynb index 71dfabc..fd10bd3 100644 --- a/06-GD-2D-convection.ipynb +++ b/06-GD-2D-convection.ipynb @@ -489,7 +489,7 @@ "Ra, delta_t = Constant(100), Constant(1.5e-4)\n", "\n", "approximation = BoussinesqApproximation(Ra)\n", - "t_adapt = TimestepAdaptor(delta_t, V, maximum_timestep=0.1, increase_tolerance=1.5)\n", + "t_adapt = TimestepAdaptor(delta_t, u, V, maximum_timestep=0.1, increase_tolerance=1.5)\n", "\n", "gamma_T, gamma_Z = Constant(ln(10**5)), Constant(ln(10))\n", "mu_star, sigma_y = Constant(0.001), Constant(1.0)\n", diff --git a/07-GD-2D-cylindrical.ipynb b/07-GD-2D-cylindrical.ipynb index 9eb13af..952ffca 100644 --- a/07-GD-2D-cylindrical.ipynb +++ b/07-GD-2D-cylindrical.ipynb @@ -100,7 +100,7 @@ "source": [ "V = FunctionSpace(mesh, \"CG\", 1)\n", "File(\"mesh.pvd\").write(Function(V))\n", - "mesh_data = pv.read(\"mesh_0.vtu\")\n", + "mesh_data = pv.read(\"mesh/mesh_0.vtu\")\n", "edges = mesh_data.extract_all_edges()\n", "\n", "plotter = pv.Plotter(notebook=True)\n", @@ -163,7 +163,7 @@ "# Set up temperature field and initialise:\n", "X = SpatialCoordinate(mesh)\n", "r = sqrt(X[0]**2 + X[1]**2)\n", - "T.interpolate(rmax - r + 0.02*cos(4*atan_2(X[1], X[0])) * sin((r - rmin) * pi))\n" + "T.interpolate(rmax - r + 0.02*cos(4*atan2(X[1], X[0])) * sin((r - rmin) * pi))\n" ] }, { @@ -184,7 +184,7 @@ "outputs": [], "source": [ "File(\"temp.pvd\").write(T)\n", - "temp_data = pv.read(\"temp_0.vtu\")\n", + "temp_data = pv.read(\"temp/temp_0.vtu\")\n", "plotter = pv.Plotter(notebook=True)\n", "plotter.add_mesh(temp_data)\n", "plotter.camera_position = \"xy\"\n", @@ -210,7 +210,7 @@ "Ra, delta_t = Constant(1e5), Constant(1e-6)\n", "\n", "approximation = BoussinesqApproximation(Ra)\n", - "t_adapt = TimestepAdaptor(delta_t, V, maximum_timestep=0.1, increase_tolerance=1.5)" + "t_adapt = TimestepAdaptor(delta_t, u, V, maximum_timestep=0.1, increase_tolerance=1.5)" ] }, { @@ -297,7 +297,7 @@ "time = 0\n", "\n", "for timestep in range(0, no_timesteps):\n", - " dt = t_adapt.update_timestep(u)\n", + " dt = t_adapt.update_timestep()\n", " time += dt\n", "\n", " stokes_solver.solve()\n", @@ -333,7 +333,7 @@ "outputs": [], "source": [ "File(\"temp.pvd\").write(T)\n", - "temp_data = pv.read(\"temp_0.vtu\")\n", + "temp_data = pv.read(\"temp/temp_0.vtu\")\n", "plotter = pv.Plotter(notebook=True)\n", "plotter.add_mesh(temp_data)\n", "plotter.camera_position = \"xy\"\n", From 574068255e0bfbee1ce12025944af3dd83ef3dfe Mon Sep 17 00:00:00 2001 From: Angus Gibson Date: Wed, 17 Apr 2024 18:53:20 +1000 Subject: [PATCH 4/5] Disable non-rendered tutorials for now --- 01-spd-helmholtz.ipynb | 10 +++++++++- 06-GD-2D-convection.ipynb | 10 +++++++++- .../08-GD-2D-pde-constrained1.ipynb | 0 .../09-GD-2D-pde-constrained2.ipynb | 0 .../10-GD-2D-Adjoint.ipynb | 0 5 files changed, 18 insertions(+), 2 deletions(-) rename 08-GD-2D-pde-constrained1.ipynb => disabled/08-GD-2D-pde-constrained1.ipynb (100%) rename 09-GD-2D-pde-constrained2.ipynb => disabled/09-GD-2D-pde-constrained2.ipynb (100%) rename 10-GD-2D-Adjoint.ipynb => disabled/10-GD-2D-Adjoint.ipynb (100%) diff --git a/01-spd-helmholtz.ipynb b/01-spd-helmholtz.ipynb index 329308a..1218b31 100644 --- a/01-spd-helmholtz.ipynb +++ b/01-spd-helmholtz.ipynb @@ -412,7 +412,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "skip-execution" + ] + }, "outputs": [], "source": [ "mesh = UnitSquareMesh(10, 10)\n", diff --git a/06-GD-2D-convection.ipynb b/06-GD-2D-convection.ipynb index fd10bd3..0f136bb 100644 --- a/06-GD-2D-convection.ipynb +++ b/06-GD-2D-convection.ipynb @@ -468,7 +468,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "skip-execution" + ] + }, "outputs": [], "source": [ "mesh = UnitSquareMesh(40, 40, quadrilateral=True)\n", diff --git a/08-GD-2D-pde-constrained1.ipynb b/disabled/08-GD-2D-pde-constrained1.ipynb similarity index 100% rename from 08-GD-2D-pde-constrained1.ipynb rename to disabled/08-GD-2D-pde-constrained1.ipynb diff --git a/09-GD-2D-pde-constrained2.ipynb b/disabled/09-GD-2D-pde-constrained2.ipynb similarity index 100% rename from 09-GD-2D-pde-constrained2.ipynb rename to disabled/09-GD-2D-pde-constrained2.ipynb diff --git a/10-GD-2D-Adjoint.ipynb b/disabled/10-GD-2D-Adjoint.ipynb similarity index 100% rename from 10-GD-2D-Adjoint.ipynb rename to disabled/10-GD-2D-Adjoint.ipynb From 522c4a0f0f36c9d2e0130349eac697375ea97495 Mon Sep 17 00:00:00 2001 From: Angus Gibson Date: Thu, 18 Apr 2024 11:02:32 +1000 Subject: [PATCH 5/5] Hide exercise cells from rendering --- 01-spd-helmholtz.ipynb | 43 +++++++++++++++++++++++---- 02-poisson.ipynb | 20 +++++++++++-- 03-elasticity.ipynb | 40 ++++++++++++++++++++++--- 04-burgers.ipynb | 40 ++++++++++++++++++++++--- 05-pde-constrained-optimisation.ipynb | 10 ++++++- 06-GD-2D-convection.ipynb | 20 +++++++++++-- 07-GD-2D-cylindrical.ipynb | 20 +++++++++++-- 7 files changed, 173 insertions(+), 20 deletions(-) diff --git a/01-spd-helmholtz.ipynb b/01-spd-helmholtz.ipynb index 1218b31..6220487 100644 --- a/01-spd-helmholtz.ipynb +++ b/01-spd-helmholtz.ipynb @@ -364,7 +364,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercises\n", "\n", @@ -387,13 +395,29 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "outputs": [], "source": [] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "### Exercise 2: convergence of the method\n", "For solutions with sufficient smoothness (like the choice we have here), this method with a piecewise linear approximation space should converge in the $L_2$ error with rate $\\mathcal{O}(h^{-2})$, where $h$ is the typical mesh spacing. Confirm this for the example in question by computing the $L_2$ error in the solution for a sequence of finer and finer meshes.\n", @@ -418,7 +442,8 @@ "slide_type": "" }, "tags": [ - "skip-execution" + "skip-execution", + "exercise" ] }, "outputs": [], @@ -442,7 +467,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "outputs": [], "source": [] }, diff --git a/02-poisson.ipynb b/02-poisson.ipynb index 513d7f7..c345cac 100644 --- a/02-poisson.ipynb +++ b/02-poisson.ipynb @@ -176,7 +176,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercises\n", "\n", @@ -199,7 +207,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "outputs": [], "source": [] } diff --git a/03-elasticity.ipynb b/03-elasticity.ipynb index fe6cc04..2da4cbb 100644 --- a/03-elasticity.ipynb +++ b/03-elasticity.ipynb @@ -200,7 +200,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercises\n", "\n", @@ -213,7 +221,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "outputs": [], "source": [] }, @@ -368,7 +384,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercise\n", "\n", @@ -378,7 +402,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "outputs": [], "source": [] } diff --git a/04-burgers.ipynb b/04-burgers.ipynb index c6fe0b9..45e8e15 100644 --- a/04-burgers.ipynb +++ b/04-burgers.ipynb @@ -306,7 +306,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercise 1\n", "\n", @@ -318,13 +326,29 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "outputs": [], "source": [] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercise 2\n", "\n", @@ -345,7 +369,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "outputs": [], "source": [] } diff --git a/05-pde-constrained-optimisation.ipynb b/05-pde-constrained-optimisation.ipynb index f8d41a5..f57a730 100644 --- a/05-pde-constrained-optimisation.ipynb +++ b/05-pde-constrained-optimisation.ipynb @@ -396,7 +396,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercise:\n", "\n", diff --git a/06-GD-2D-convection.ipynb b/06-GD-2D-convection.ipynb index 0f136bb..64cbca5 100644 --- a/06-GD-2D-convection.ipynb +++ b/06-GD-2D-convection.ipynb @@ -397,7 +397,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercises\n", "\n", @@ -542,7 +550,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercises\n", "\n", diff --git a/07-GD-2D-cylindrical.ipynb b/07-GD-2D-cylindrical.ipynb index 952ffca..73a18f3 100644 --- a/07-GD-2D-cylindrical.ipynb +++ b/07-GD-2D-cylindrical.ipynb @@ -112,7 +112,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "### Exercise:\n", "\n", @@ -343,7 +351,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "### Exercise\n", "2. Change the top boundary condition from free-slip to zero-slip (zero velocity). Note that with a zero-slip boundary condition on either boundary, there is no velocity `nullspace` for this problem. How do your results change, is this what you would expect?"