diff --git a/01-spd-helmholtz.ipynb b/01-spd-helmholtz.ipynb index e895f24..6cc2779 100644 --- a/01-spd-helmholtz.ipynb +++ b/01-spd-helmholtz.ipynb @@ -312,7 +312,7 @@ "metadata": {}, "outputs": [], "source": [ - "solve(a == L, uh, solver_parameters={'ksp_type': 'cg', 'pc_type': 'none'})" + "solve(a == L, uh)" ] }, { @@ -427,8 +427,7 @@ "L = f * v * dx\n", "\n", "uh = Function(V)\n", - "solve(a == L, uh, solver_parameters={'ksp_type': 'cg',\n", - " 'pc_type': 'none'})\n", + "solve(a == L, uh)\n", "\n", "u_exact = cos(2*pi*x)*cos(2*pi*y)" ] @@ -565,8 +564,22 @@ } ], "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.1" } }, "nbformat": 4, diff --git a/02-poisson.ipynb b/02-poisson.ipynb index fed9e2c..e6be072 100644 --- a/02-poisson.ipynb +++ b/02-poisson.ipynb @@ -175,7 +175,7 @@ "outputs": [], "source": [ "uh = Function(V)\n", - "solve(a == L, uh, bcs=bcs, solver_parameters={\"ksp_type\": \"cg\", \"pc_type\": \"none\"})" + "solve(a == L, uh, bcs=bcs)" ] }, { @@ -223,8 +223,22 @@ } ], "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.1" } }, "nbformat": 4, diff --git a/03-elasticity.ipynb b/03-elasticity.ipynb index 4d27ff0..dd9d859 100644 --- a/03-elasticity.ipynb +++ b/03-elasticity.ipynb @@ -19,7 +19,7 @@ "source": [ "# Linear elasticity\n", "\n", - "*This work is adapted from the FEniCS tutorial: https://fenicsproject.org/pub/tutorial/html/._ftut1008.html#ftut:elast*\n", + "*This work is adapted from an earlier FEniCS tutorial.*\n", "\n", "Having studied a few scalar-valued problems, we now move on to a vector-valued problem. The equations of linear elasticity. Here, we'll treat the isotropic case.\n", "\n", @@ -75,6 +75,7 @@ "outputs": [], "source": [ "from firedrake import *\n", + "from firedrake.__future__ import interpolate\n", "length = 1\n", "width = 0.2\n", "mesh = RectangleMesh(40, 20, length, width)" @@ -109,7 +110,7 @@ "metadata": {}, "outputs": [], "source": [ - "bc = DirichletBC(V, Constant([0, 0]), 1)" + "bc = DirichletBC(V, as_vector([0., 0.]), 1)" ] }, { @@ -189,7 +190,7 @@ "metadata": {}, "outputs": [], "source": [ - "displaced_coordinates = interpolate(SpatialCoordinate(mesh) + uh, V)\n", + "displaced_coordinates = assemble(interpolate(SpatialCoordinate(mesh) + uh, V))\n", "displaced_mesh = Mesh(displaced_coordinates)" ] }, @@ -263,7 +264,7 @@ " lambda_ = Constant(0.25)\n", " Id = Identity(mesh.geometric_dimension()) # 2x2 Identity tensor\n", " \n", - " bc = DirichletBC(V, Constant([0, 0]), 1)\n", + " bc = DirichletBC(V, as_vector([0., 0.]), 1)\n", " u = TrialFunction(V)\n", " v = TestFunction(V)\n", " a = inner(sigma(u), epsilon(v))*dx\n", @@ -344,7 +345,7 @@ "\n", " def sigma(u):\n", " return lambda_*div(u)*Id + 2*mu*epsilon(u) \n", - " bc = DirichletBC(V, Constant([0, 0]), 1)\n", + " bc = DirichletBC(V, as_vector([0., 0.]), 1)\n", " u = TrialFunction(V)\n", " v = TestFunction(V)\n", " a = inner(sigma(u), epsilon(v))*dx\n", @@ -355,8 +356,8 @@ " b0 = Function(V)\n", " b1 = Function(V)\n", " b2 = Function(V)\n", - " b0.interpolate(Constant([1, 0]))\n", - " b1.interpolate(Constant([0, 1]))\n", + " b0.interpolate(as_vector([1., 0.]))\n", + " b1.interpolate(as_vector([0., 1.]))\n", " b2.interpolate(as_vector([-y, x]))\n", " nullmodes = VectorSpaceBasis([b0, b1, b2])\n", " # Make sure they're orthonormal.\n", @@ -406,8 +407,22 @@ } ], "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.1" } }, "nbformat": 4, diff --git a/04-burgers.ipynb b/04-burgers.ipynb index 068ef5b..0fc312b 100644 --- a/04-burgers.ipynb +++ b/04-burgers.ipynb @@ -373,8 +373,22 @@ } ], "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.1" } }, "nbformat": 4, diff --git a/05-mixed-poisson.ipynb b/05-mixed-poisson.ipynb index 58913c3..2739243 100644 --- a/05-mixed-poisson.ipynb +++ b/05-mixed-poisson.ipynb @@ -202,7 +202,7 @@ "\n", "quiver(sigmah, axes=axes[0])\n", "axes[0].set_aspect(\"equal\")\n", - "axes[0].set_title(\"$\\sigma$\")\n", + "axes[0].set_title(r\"$\\sigma$\")\n", "\n", "tripcolor(uh, axes=axes[1])\n", "axes[1].set_aspect(\"equal\")\n", @@ -508,8 +508,22 @@ } ], "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.1" } }, "nbformat": 4, diff --git a/06-pde-constrained-optimisation.ipynb b/06-pde-constrained-optimisation.ipynb index c3ab92c..b970b75 100644 --- a/06-pde-constrained-optimisation.ipynb +++ b/06-pde-constrained-optimisation.ipynb @@ -132,15 +132,10 @@ "metadata": {}, "outputs": [], "source": [ - "!rm -f stokes-control.msh && wget https://raw.githubusercontent.com/firedrakeproject/notebooks/refs/heads/main/stokes-control.msh" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ + "import os\n", + "if not os.path.isfile(\"stokes-control.msh\"):\n", + " # If the mesh is not available locally, we download it.\n", + " !curl -O https://raw.githubusercontent.com/firedrakeproject/notebooks/refs/heads/main/stokes-control.msh\n", "mesh = Mesh(\"stokes-control.msh\")" ] }, @@ -210,7 +205,7 @@ "u_inflow = as_vector([y*(10-y)/25.0, 0])\n", "\n", "noslip = DirichletBC(W.sub(0), (0, 0), (3, 5))\n", - "inflow = DirichletBC(W.sub(0), interpolate(u_inflow, V), 1)\n", + "inflow = DirichletBC(W.sub(0), u_inflow, 1)\n", "static_bcs = [inflow, noslip]" ] }, @@ -448,8 +443,22 @@ } ], "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.1" } }, "nbformat": 4, diff --git a/07-geometric-multigrid.ipynb b/07-geometric-multigrid.ipynb index 883cbfb..caf5cc6 100644 --- a/07-geometric-multigrid.ipynb +++ b/07-geometric-multigrid.ipynb @@ -212,7 +212,7 @@ " 0)\n", "\n", " value = as_vector([gbar*(1 - (12*t)**2), 0])\n", - " bcs = [DirichletBC(W.sub(0), interpolate(value, V), (1, 2)),\n", + " bcs = [DirichletBC(W.sub(0), value, (1, 2)),\n", " DirichletBC(W.sub(0), zero(2), (3, 4))]\n", " \n", " a = (nu*inner(grad(u), grad(v)) - p*div(v) + q*div(u))*dx\n", @@ -427,7 +427,7 @@ " 0)\n", "\n", " value = as_vector([gbar*(1 - (12*t)**2), 0])\n", - " bcs = [DirichletBC(W.sub(0), interpolate(value, V), (1, 2)),\n", + " bcs = [DirichletBC(W.sub(0), value, (1, 2)),\n", " DirichletBC(W.sub(0), zero(2), (3, 4))]\n", " \n", " a = (nu*inner(grad(u), grad(v)) - p*div(v) + q*div(u))*dx\n", @@ -473,8 +473,22 @@ } ], "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.1" } }, "nbformat": 4, diff --git a/08-composable-solvers.ipynb b/08-composable-solvers.ipynb index aff1005..e50b6ae 100644 --- a/08-composable-solvers.ipynb +++ b/08-composable-solvers.ipynb @@ -662,6 +662,13 @@ "#convergence(solver)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, @@ -671,8 +678,22 @@ } ], "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.1" } }, "nbformat": 4, diff --git a/12-HPC_demo.ipynb b/12-HPC_demo.ipynb index 47c2706..fa5ed95 100644 --- a/12-HPC_demo.ipynb +++ b/12-HPC_demo.ipynb @@ -3,7 +3,7 @@ { "cell_type": "code", "execution_count": null, - "id": "fa3648c7", + "id": "662e50fc", "metadata": {}, "outputs": [], "source": [