Skip to content

Commit 1e7baf4

Browse files
authored
Merge pull request #6 from firedrakeproject/dham/bitrot
fix lots of bitrot in notebooks
2 parents be87d93 + 841dd5c commit 1e7baf4

9 files changed

+147
-33
lines changed

01-spd-helmholtz.ipynb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@
312312
"metadata": {},
313313
"outputs": [],
314314
"source": [
315-
"solve(a == L, uh, solver_parameters={'ksp_type': 'cg', 'pc_type': 'none'})"
315+
"solve(a == L, uh)"
316316
]
317317
},
318318
{
@@ -427,8 +427,7 @@
427427
"L = f * v * dx\n",
428428
"\n",
429429
"uh = Function(V)\n",
430-
"solve(a == L, uh, solver_parameters={'ksp_type': 'cg',\n",
431-
" 'pc_type': 'none'})\n",
430+
"solve(a == L, uh)\n",
432431
"\n",
433432
"u_exact = cos(2*pi*x)*cos(2*pi*y)"
434433
]
@@ -565,8 +564,22 @@
565564
}
566565
],
567566
"metadata": {
567+
"kernelspec": {
568+
"display_name": "Python 3 (ipykernel)",
569+
"language": "python",
570+
"name": "python3"
571+
},
568572
"language_info": {
569-
"name": "python"
573+
"codemirror_mode": {
574+
"name": "ipython",
575+
"version": 3
576+
},
577+
"file_extension": ".py",
578+
"mimetype": "text/x-python",
579+
"name": "python",
580+
"nbconvert_exporter": "python",
581+
"pygments_lexer": "ipython3",
582+
"version": "3.13.1"
570583
}
571584
},
572585
"nbformat": 4,

02-poisson.ipynb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
"outputs": [],
176176
"source": [
177177
"uh = Function(V)\n",
178-
"solve(a == L, uh, bcs=bcs, solver_parameters={\"ksp_type\": \"cg\", \"pc_type\": \"none\"})"
178+
"solve(a == L, uh, bcs=bcs)"
179179
]
180180
},
181181
{
@@ -223,8 +223,22 @@
223223
}
224224
],
225225
"metadata": {
226+
"kernelspec": {
227+
"display_name": "Python 3 (ipykernel)",
228+
"language": "python",
229+
"name": "python3"
230+
},
226231
"language_info": {
227-
"name": "python"
232+
"codemirror_mode": {
233+
"name": "ipython",
234+
"version": 3
235+
},
236+
"file_extension": ".py",
237+
"mimetype": "text/x-python",
238+
"name": "python",
239+
"nbconvert_exporter": "python",
240+
"pygments_lexer": "ipython3",
241+
"version": "3.13.1"
228242
}
229243
},
230244
"nbformat": 4,

03-elasticity.ipynb

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"source": [
2020
"# Linear elasticity\n",
2121
"\n",
22-
"*This work is adapted from the FEniCS tutorial: https://fenicsproject.org/pub/tutorial/html/._ftut1008.html#ftut:elast*\n",
22+
"*This work is adapted from an earlier FEniCS tutorial.*\n",
2323
"\n",
2424
"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",
2525
"\n",
@@ -75,6 +75,7 @@
7575
"outputs": [],
7676
"source": [
7777
"from firedrake import *\n",
78+
"from firedrake.__future__ import interpolate\n",
7879
"length = 1\n",
7980
"width = 0.2\n",
8081
"mesh = RectangleMesh(40, 20, length, width)"
@@ -109,7 +110,7 @@
109110
"metadata": {},
110111
"outputs": [],
111112
"source": [
112-
"bc = DirichletBC(V, Constant([0, 0]), 1)"
113+
"bc = DirichletBC(V, as_vector([0., 0.]), 1)"
113114
]
114115
},
115116
{
@@ -189,7 +190,7 @@
189190
"metadata": {},
190191
"outputs": [],
191192
"source": [
192-
"displaced_coordinates = interpolate(SpatialCoordinate(mesh) + uh, V)\n",
193+
"displaced_coordinates = assemble(interpolate(SpatialCoordinate(mesh) + uh, V))\n",
193194
"displaced_mesh = Mesh(displaced_coordinates)"
194195
]
195196
},
@@ -263,7 +264,7 @@
263264
" lambda_ = Constant(0.25)\n",
264265
" Id = Identity(mesh.geometric_dimension()) # 2x2 Identity tensor\n",
265266
" \n",
266-
" bc = DirichletBC(V, Constant([0, 0]), 1)\n",
267+
" bc = DirichletBC(V, as_vector([0., 0.]), 1)\n",
267268
" u = TrialFunction(V)\n",
268269
" v = TestFunction(V)\n",
269270
" a = inner(sigma(u), epsilon(v))*dx\n",
@@ -344,7 +345,7 @@
344345
"\n",
345346
" def sigma(u):\n",
346347
" return lambda_*div(u)*Id + 2*mu*epsilon(u) \n",
347-
" bc = DirichletBC(V, Constant([0, 0]), 1)\n",
348+
" bc = DirichletBC(V, as_vector([0., 0.]), 1)\n",
348349
" u = TrialFunction(V)\n",
349350
" v = TestFunction(V)\n",
350351
" a = inner(sigma(u), epsilon(v))*dx\n",
@@ -355,8 +356,8 @@
355356
" b0 = Function(V)\n",
356357
" b1 = Function(V)\n",
357358
" b2 = Function(V)\n",
358-
" b0.interpolate(Constant([1, 0]))\n",
359-
" b1.interpolate(Constant([0, 1]))\n",
359+
" b0.interpolate(as_vector([1., 0.]))\n",
360+
" b1.interpolate(as_vector([0., 1.]))\n",
360361
" b2.interpolate(as_vector([-y, x]))\n",
361362
" nullmodes = VectorSpaceBasis([b0, b1, b2])\n",
362363
" # Make sure they're orthonormal.\n",
@@ -406,8 +407,22 @@
406407
}
407408
],
408409
"metadata": {
410+
"kernelspec": {
411+
"display_name": "Python 3 (ipykernel)",
412+
"language": "python",
413+
"name": "python3"
414+
},
409415
"language_info": {
410-
"name": "python"
416+
"codemirror_mode": {
417+
"name": "ipython",
418+
"version": 3
419+
},
420+
"file_extension": ".py",
421+
"mimetype": "text/x-python",
422+
"name": "python",
423+
"nbconvert_exporter": "python",
424+
"pygments_lexer": "ipython3",
425+
"version": "3.13.1"
411426
}
412427
},
413428
"nbformat": 4,

04-burgers.ipynb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,22 @@
373373
}
374374
],
375375
"metadata": {
376+
"kernelspec": {
377+
"display_name": "Python 3 (ipykernel)",
378+
"language": "python",
379+
"name": "python3"
380+
},
376381
"language_info": {
377-
"name": "python"
382+
"codemirror_mode": {
383+
"name": "ipython",
384+
"version": 3
385+
},
386+
"file_extension": ".py",
387+
"mimetype": "text/x-python",
388+
"name": "python",
389+
"nbconvert_exporter": "python",
390+
"pygments_lexer": "ipython3",
391+
"version": "3.13.1"
378392
}
379393
},
380394
"nbformat": 4,

05-mixed-poisson.ipynb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@
202202
"\n",
203203
"quiver(sigmah, axes=axes[0])\n",
204204
"axes[0].set_aspect(\"equal\")\n",
205-
"axes[0].set_title(\"$\\sigma$\")\n",
205+
"axes[0].set_title(r\"$\\sigma$\")\n",
206206
"\n",
207207
"tripcolor(uh, axes=axes[1])\n",
208208
"axes[1].set_aspect(\"equal\")\n",
@@ -508,8 +508,22 @@
508508
}
509509
],
510510
"metadata": {
511+
"kernelspec": {
512+
"display_name": "Python 3 (ipykernel)",
513+
"language": "python",
514+
"name": "python3"
515+
},
511516
"language_info": {
512-
"name": "python"
517+
"codemirror_mode": {
518+
"name": "ipython",
519+
"version": 3
520+
},
521+
"file_extension": ".py",
522+
"mimetype": "text/x-python",
523+
"name": "python",
524+
"nbconvert_exporter": "python",
525+
"pygments_lexer": "ipython3",
526+
"version": "3.13.1"
513527
}
514528
},
515529
"nbformat": 4,

06-pde-constrained-optimisation.ipynb

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,10 @@
132132
"metadata": {},
133133
"outputs": [],
134134
"source": [
135-
"!rm -f stokes-control.msh && wget https://raw.githubusercontent.com/firedrakeproject/notebooks/refs/heads/main/stokes-control.msh"
136-
]
137-
},
138-
{
139-
"cell_type": "code",
140-
"execution_count": null,
141-
"metadata": {},
142-
"outputs": [],
143-
"source": [
135+
"import os\n",
136+
"if not os.path.isfile(\"stokes-control.msh\"):\n",
137+
" # If the mesh is not available locally, we download it.\n",
138+
" !curl -O https://raw.githubusercontent.com/firedrakeproject/notebooks/refs/heads/main/stokes-control.msh\n",
144139
"mesh = Mesh(\"stokes-control.msh\")"
145140
]
146141
},
@@ -210,7 +205,7 @@
210205
"u_inflow = as_vector([y*(10-y)/25.0, 0])\n",
211206
"\n",
212207
"noslip = DirichletBC(W.sub(0), (0, 0), (3, 5))\n",
213-
"inflow = DirichletBC(W.sub(0), interpolate(u_inflow, V), 1)\n",
208+
"inflow = DirichletBC(W.sub(0), u_inflow, 1)\n",
214209
"static_bcs = [inflow, noslip]"
215210
]
216211
},
@@ -448,8 +443,22 @@
448443
}
449444
],
450445
"metadata": {
446+
"kernelspec": {
447+
"display_name": "Python 3 (ipykernel)",
448+
"language": "python",
449+
"name": "python3"
450+
},
451451
"language_info": {
452-
"name": "python"
452+
"codemirror_mode": {
453+
"name": "ipython",
454+
"version": 3
455+
},
456+
"file_extension": ".py",
457+
"mimetype": "text/x-python",
458+
"name": "python",
459+
"nbconvert_exporter": "python",
460+
"pygments_lexer": "ipython3",
461+
"version": "3.13.1"
453462
}
454463
},
455464
"nbformat": 4,

07-geometric-multigrid.ipynb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
" 0)\n",
213213
"\n",
214214
" value = as_vector([gbar*(1 - (12*t)**2), 0])\n",
215-
" bcs = [DirichletBC(W.sub(0), interpolate(value, V), (1, 2)),\n",
215+
" bcs = [DirichletBC(W.sub(0), value, (1, 2)),\n",
216216
" DirichletBC(W.sub(0), zero(2), (3, 4))]\n",
217217
" \n",
218218
" a = (nu*inner(grad(u), grad(v)) - p*div(v) + q*div(u))*dx\n",
@@ -427,7 +427,7 @@
427427
" 0)\n",
428428
"\n",
429429
" value = as_vector([gbar*(1 - (12*t)**2), 0])\n",
430-
" bcs = [DirichletBC(W.sub(0), interpolate(value, V), (1, 2)),\n",
430+
" bcs = [DirichletBC(W.sub(0), value, (1, 2)),\n",
431431
" DirichletBC(W.sub(0), zero(2), (3, 4))]\n",
432432
" \n",
433433
" a = (nu*inner(grad(u), grad(v)) - p*div(v) + q*div(u))*dx\n",
@@ -473,8 +473,22 @@
473473
}
474474
],
475475
"metadata": {
476+
"kernelspec": {
477+
"display_name": "Python 3 (ipykernel)",
478+
"language": "python",
479+
"name": "python3"
480+
},
476481
"language_info": {
477-
"name": "python"
482+
"codemirror_mode": {
483+
"name": "ipython",
484+
"version": 3
485+
},
486+
"file_extension": ".py",
487+
"mimetype": "text/x-python",
488+
"name": "python",
489+
"nbconvert_exporter": "python",
490+
"pygments_lexer": "ipython3",
491+
"version": "3.13.1"
478492
}
479493
},
480494
"nbformat": 4,

08-composable-solvers.ipynb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,13 @@
662662
"#convergence(solver)"
663663
]
664664
},
665+
{
666+
"cell_type": "code",
667+
"execution_count": null,
668+
"metadata": {},
669+
"outputs": [],
670+
"source": []
671+
},
665672
{
666673
"cell_type": "code",
667674
"execution_count": null,
@@ -671,8 +678,22 @@
671678
}
672679
],
673680
"metadata": {
681+
"kernelspec": {
682+
"display_name": "Python 3 (ipykernel)",
683+
"language": "python",
684+
"name": "python3"
685+
},
674686
"language_info": {
675-
"name": "python"
687+
"codemirror_mode": {
688+
"name": "ipython",
689+
"version": 3
690+
},
691+
"file_extension": ".py",
692+
"mimetype": "text/x-python",
693+
"name": "python",
694+
"nbconvert_exporter": "python",
695+
"pygments_lexer": "ipython3",
696+
"version": "3.13.1"
676697
}
677698
},
678699
"nbformat": 4,

12-HPC_demo.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "fa3648c7",
6+
"id": "662e50fc",
77
"metadata": {},
88
"outputs": [],
99
"source": [

0 commit comments

Comments
 (0)