Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions 01-spd-helmholtz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
"metadata": {},
"outputs": [],
"source": [
"solve(a == L, uh, solver_parameters={'ksp_type': 'cg', 'pc_type': 'none'})"
"solve(a == L, uh)"
]
},
{
Expand Down Expand Up @@ -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)"
]
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 16 additions & 2 deletions 02-poisson.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
},
{
Expand Down Expand Up @@ -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,
Expand Down
31 changes: 23 additions & 8 deletions 03-elasticity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)"
Expand Down Expand Up @@ -109,7 +110,7 @@
"metadata": {},
"outputs": [],
"source": [
"bc = DirichletBC(V, Constant([0, 0]), 1)"
"bc = DirichletBC(V, as_vector([0., 0.]), 1)"
]
},
{
Expand Down Expand Up @@ -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)"
]
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 15 additions & 1 deletion 04-burgers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 16 additions & 2 deletions 05-mixed-poisson.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
31 changes: 20 additions & 11 deletions 06-pde-constrained-optimisation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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\")"
]
},
Expand Down Expand Up @@ -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]"
]
},
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 17 additions & 3 deletions 07-geometric-multigrid.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 22 additions & 1 deletion 08-composable-solvers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,13 @@
"#convergence(solver)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion 12-HPC_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "fa3648c7",
"id": "662e50fc",
"metadata": {},
"outputs": [],
"source": [
Expand Down