Skip to content

Commit

Permalink
Switch to gadopt-restructure version of tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
angus-g committed Feb 11, 2024
1 parent f6e7a1d commit 3c26415
Show file tree
Hide file tree
Showing 14 changed files with 2,508 additions and 967 deletions.
45 changes: 38 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Test notebook execution
name: Test and deploy notebooks

on:
pull_request:
workflow_dispatch:

jobs:
build:
name: Test notebook execution
name: Test and deploy notebooks
runs-on: self-hosted
container:
image: firedrakeproject/firedrake:latest
Expand All @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v3

- name: Load pyrol wheel from cache
uses: actions/cache@v3
uses: actions/cache/restore@v3
id: cache-pyrol
with:
path: /tmp/wheels
Expand All @@ -28,16 +28,47 @@ jobs:
- name: Build pyrol wheel
if: steps.cache-pyrol.outputs.cache-hit != 'true'
run: |
/home/firedrake/firedrake/bin/pip wheel -r git+https://github.com/angus-g/[email protected] -w /tmp/wheels
/home/firedrake/firedrake/bin/pip wheel git+https://github.com/angus-g/[email protected] -w /tmp/wheels
- name: Install Python dependencies
- name: Save pyrol to cache
if: steps.cache-pyrol.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
with:
path: /tmp/wheels
key: pyrol

- name: Install dependencies
run: |
sudo apt update
sudo apt install -y libgl1-mesa-glx xvfb
. /home/firedrake/firedrake/bin/activate
python3 -m pip install --no-index -f /tmp/wheels pyroltrilinos
python3 -m pip install nbval
python3 -m pip install git+https://github.com/g-adopt/g-adopt@adjoint-cases-testing
python3 -m pip install nbval pyvista
python3 -m pip install git+https://github.com/g-adopt/g-adopt
- name: Run test
run: |
. /home/firedrake/firedrake/bin/activate
export DISPLAY=:99
export PYVISTA_OFF_SCREEN=true
Xvfb $DISPLAY -screen 0 1024x768x24 > /dev/null 2>&1 &
sleep 3
pytest --nbval *.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
ln -s ../stokes-control.msh docs
export DISPLAY=:99
export PYVISTA_OFF_SCREEN=true
Xvfb $DISPLAY -screen 0 1024x768x24 > /dev/null 2>&1 &
sleep 3
jupyter-book build docs
- name: Archive built book
uses: actions/upload-artifact@v3
with:
name: tutorials-html
path: docs/_build/html
58 changes: 33 additions & 25 deletions 01-spd-helmholtz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"outputs": [],
"source": [
"# This magic makes plots appear in the browser\n",
"%matplotlib notebook\n",
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# Load Firedrake on Colab\n",
"try:\n",
" import firedrake\n",
"except ImportError:\n",
" !wget \"https://fem-on-colab.github.io/releases/firedrake-install-real.sh\" -O \"/tmp/firedrake-install.sh\" && bash \"/tmp/firedrake-install.sh\"\n",
" !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"
]
},
Expand Down Expand Up @@ -52,7 +52,9 @@
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
"jupyter": {
"outputs_hidden": true
}
},
"source": [
"$$ \\int_\\Omega \\nabla u\\cdot\\nabla v + uv\\ \\mathrm{d}x = \\int_\\Omega\n",
Expand Down Expand Up @@ -129,7 +131,7 @@
"metadata": {},
"outputs": [],
"source": [
"from firedrake import *"
"from gadopt import *"
]
},
{
Expand Down Expand Up @@ -187,10 +189,13 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": [
"nbval-ignore-output"
]
},
"outputs": [],
"source": [
"# NBVAL_IGNORE_OUTPUT\n",
"# We test the output of the notebooks with out continuous integration system to\n",
"# make sure they run.\n",
"# Unfortunately we can't compare the plots from run to run, so the above line\n",
Expand Down Expand Up @@ -312,10 +317,13 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": [
"nbval-ignore-output"
]
},
"outputs": [],
"source": [
"# NBVAL_IGNORE_OUTPUT\n",
"fig, axes = plt.subplots()\n",
"collection = tripcolor(uh, axes=axes, cmap='coolwarm')\n",
"fig.colorbar(collection);"
Expand All @@ -340,10 +348,13 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": [
"nbval-ignore-output"
]
},
"outputs": [],
"source": [
"# NBVAL_IGNORE_OUTPUT\n",
"difference = assemble(interpolate(u_exact, V) - uh)\n",
"fig, axes = plt.subplots()\n",
"collection = tripcolor(difference, axes=axes, cmap='coolwarm')\n",
Expand All @@ -354,17 +365,17 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercises\n",
"## Exercises\n",
"\n",
"## Exercise 1: \n",
"### Exercise 1: \n",
"\n",
"### 1a: use a higher approximation degree\n",
"#### 1a: use a higher approximation degree\n",
"\n",
"Solve the same problem, only this time, use a piecewise quadratic approximation space.\n",
"\n",
"- Hint: check the help for `FunctionSpace` to see how to specify the degree.\n",
"\n",
"### 1b: use a quadrilateral mesh\n",
"#### 1b: use a quadrilateral mesh\n",
"\n",
"Solve the same problem, but using quadrilateral, rather than triangular, cells.\n",
"\n",
Expand All @@ -383,14 +394,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise 2: convergence of the method\n",
"### 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",
"\n",
"- Hint 1: You can compute errors using [errornorm](http://firedrakeproject.org/firedrake.html#firedrake.norms.errornorm)\n",
"- Hint 2: If the error is $\\mathcal{O}(h^{-2})$ then $\\log_2 (e_H/e_h) \\approx 2$.\n",
" The Python module `math` contains an implementation of `log`.\n",
" \n",
"### What works better? Mesh refinement, or increasing the approximation degree?\n",
"#### What works better? Mesh refinement, or increasing the approximation degree?\n",
"\n",
"Instead of (or as well as!) refining the mesh, we can increase the degree of the approximating polynomial space.\n",
"\n",
Expand Down Expand Up @@ -430,7 +441,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Part II: inhomogeneous Neuman conditions\n",
"## Part II: inhomogeneous Neuman conditions\n",
"\n",
"Let us recall again the statement of our problem. We seek $u \\in V$ satisfying\n",
"\n",
Expand All @@ -449,7 +460,9 @@
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
"jupyter": {
"outputs_hidden": true
}
},
"source": [
"As previously, we introduce a test function $v \\in V$, multiply and integrate. After integrating by parts, we obtain\n",
Expand Down Expand Up @@ -548,11 +561,6 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
Expand All @@ -563,9 +571,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.2"
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
28 changes: 14 additions & 14 deletions 02-poisson.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
"jupyter": {
"outputs_hidden": true
}
},
"source": [
"Let's move on from the Helmholtz problem to Poisson:\n",
Expand Down Expand Up @@ -49,15 +51,15 @@
"metadata": {},
"outputs": [],
"source": [
"%matplotlib notebook\n",
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"# Load Firedrake on Colab\n",
"try:\n",
" import firedrake\n",
"except ImportError:\n",
" !wget \"https://fem-on-colab.github.io/releases/firedrake-install-real.sh\" -O \"/tmp/firedrake-install.sh\" && bash \"/tmp/firedrake-install.sh\"\n",
" !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 firedrake import *\n",
"from gadopt import *\n",
"mesh = UnitSquareMesh(10, 10)\n",
"V = FunctionSpace(mesh, \"Lagrange\", 1)"
]
Expand Down Expand Up @@ -159,10 +161,13 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": [
"nbval-ignore-output"
]
},
"outputs": [],
"source": [
"# NBVAL_IGNORE_OUTPUT\n",
"fig, axes = plt.subplots()\n",
"collection = tripcolor(uh, axes=axes)\n",
"fig.colorbar(collection);"
Expand All @@ -172,7 +177,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercises\n",
"## Exercises\n",
"\n",
"Most of the time, we don't want to impose the same Dirichlet condition everywhere. Instead of solving with homogeneous Dirichlet conditions everywhere, solve the following problem.\n",
"\n",
Expand All @@ -199,11 +204,6 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
Expand All @@ -214,9 +214,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
Loading

0 comments on commit 3c26415

Please sign in to comment.