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/01-spd-helmholtz.ipynb b/01-spd-helmholtz.ipynb index dbef946..6220487 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" ] }, { @@ -363,7 +364,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercises\n", "\n", @@ -386,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", @@ -411,7 +436,16 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "skip-execution", + "exercise" + ] + }, "outputs": [], "source": [ "mesh = UnitSquareMesh(10, 10)\n", @@ -433,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 68278c4..c345cac 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)" ] @@ -175,7 +176,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercises\n", "\n", @@ -198,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 936b697..2da4cbb 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)" @@ -199,7 +200,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercises\n", "\n", @@ -212,7 +221,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "outputs": [], "source": [] }, @@ -367,7 +384,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercise\n", "\n", @@ -377,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 ade8e18..45e8e15 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", @@ -305,7 +306,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercise 1\n", "\n", @@ -317,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", @@ -344,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 76370b3..f57a730 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" ] }, { @@ -395,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 3399f14..64cbca5 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", @@ -396,7 +397,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "## Exercises\n", "\n", @@ -467,7 +476,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", @@ -488,7 +505,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", @@ -521,7 +538,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", @@ -533,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 9eb13af..73a18f3 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", @@ -112,7 +112,15 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [ + "exercise" + ] + }, "source": [ "### Exercise:\n", "\n", @@ -163,7 +171,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 +192,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 +218,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 +305,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 +341,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", @@ -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?" 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 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