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
2 changes: 1 addition & 1 deletion .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ runs:
- name: Install apt dependencies and upgrade pip
shell: bash -el {0}
run: |
apt-get update && apt-get install -y libxrender1 xvfb
apt-get update && apt-get install -y libxrender1
3 changes: 0 additions & 3 deletions .github/workflows/book_stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
env:
HDF5_MPI: "ON"
HDF5_DIR: "/usr/local/"
DISPLAY: ":99.0"
DEB_PYTHON_INSTALL_LAYOUT: deb_system
LIBGL_ALWAYS_SOFTWARE: 1

Expand All @@ -20,8 +19,6 @@ jobs:
container: ghcr.io/fenics/dolfinx/lab:stable

env:
PYVISTA_TRAME_SERVER_PROXY_PREFIX: "/proxy/"
PYVISTA_TRAME_SERVER_PROXY_ENABLED: "True"
PYVISTA_OFF_SCREEN: false
PYVISTA_JUPYTER_BACKEND: "html"

Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/test_nightly.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test release branch against DOLFINx nightly build
name: Test against DOLFINx nightly build

# Controls when the action will run.
on:
Expand All @@ -22,7 +22,6 @@ jobs:
env:
HDF5_MPI: "ON"
PYVISTA_OFF_SCREEN: true
DISPLAY: ":99.0"
PYVISTA_JUPYTER_BACKEND: html
LIBGL_ALWAYS_SOFTWARE: 1

Expand Down Expand Up @@ -53,7 +52,6 @@ jobs:
- name: Test chapter 1
working-directory: chapter1
run: |
python3 -c "from pyvista import start_xvfb; start_xvfb(0.1)"
mpirun -n 2 python3 fundamentals_code.py
mpirun -n 2 python3 nitsche.py
mpirun -n 2 python3 membrane_code.py
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test_stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ jobs:
- name: Test chapter 1
working-directory: chapter1
run: |
python3 -c "from pyvista import start_xvfb; start_xvfb(0.1)"
mpirun -n 2 python3 fundamentals_code.py
mpirun -n 2 python3 nitsche.py
mpirun -n 2 python3 membrane_code.py
Expand Down
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,36 @@ If you have any comments, corrections or questions, please submit an issue in th

## Contributing

If you want to contribute to this tutorial, please make a fork of the repository, make your changes, and test that the CI passes. You can do this locally by downloading [act](https://github.com/nektos/act) and call
If you want to contribute to this tutorial, please make a fork of the repository, make your changes, and test that the CI passes.

Alternatively, if you want to add a separate chapter, a Jupyter notebook can be added to a pull request, without integrating it into the tutorial. If so, the notebook will be reviewed and modified to be included in the tutorial.

Any code added to the tutorial should work in parallel. If any changes are made to `ipynb` files, please ensure that these changes are reflected in the corresponding `py` files by using [`jupytext`](https://jupytext.readthedocs.io/en/latest/faq.html#can-i-use-jupytext-with-jupyterhub-binder-nteract-colab-saturn-or-azure):


## Building the book and running code
The book is built using [jupyterbook](https://jupyterbook.org/). The following environment variables should be set if you want to build the book
```bash
act -j test-nightly
PYVISTA_OFF_SCREEN=false
PYVISTA_JUPYTER_BACKEND="html"
JUPYTER_EXTENSION_ENABLED=true
LIBGL_ALWAYS_SOFTWARE=1
```

Alternatively, if you want to add a separate chapter, a Jupyter notebook can be added to a pull request, without integrating it into the tutorial. If so, the notebook will be reviewed and modified to be included in the tutorial.
If you run the tutorial using `jupyter-lab`, for instance through `conda`, one should set the following environment variables
```bash
PYVISTA_OFF_SCREEN=false
PYVISTA_JUPYTER_BACKEND="trame"
JUPYTER_EXTENSION_ENABLED=true
LIBGL_ALWAYS_SOFTWARE=1
```
If you use docker to run your code, you should set the following variables:
```bash
docker run -ti -e DISPLAY=$DISPLAY -e LIBGL_ALWAYS_SOFTWARE=1 -e PYVISTA_OFF_SCREEN=false -e PYVISTA_JUPYTER_BACKEND="trame" -e JUPYTER_EXTENSION_ENABLED=true --network=host -v $(pwd):/root/shared -w /root/shared ....
```

To run python scripts, either choose `PYVISTA_OFF_SCREEN=True` to get screenshots, or render interactive plots with `PYVISTA_OFF_SCREEN=False`

Any code added to the tutorial should work in parallel. If any changes are made to `ipynb` files, please ensure that these changes are reflected in the corresponding `py` files by using [`jupytext`](https://jupytext.readthedocs.io/en/latest/faq.html#can-i-use-jupytext-with-jupyterhub-binder-nteract-colab-saturn-or-azure):

```bash
python3 -m jupytext --sync */*.ipynb --set-formats ipynb,py:light
Expand Down
1 change: 0 additions & 1 deletion chapter1/complex_mode.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@
"source": [
"import pyvista\n",
"\n",
"pyvista.start_xvfb(0.1)\n",
"mesh.topology.create_connectivity(mesh.topology.dim, mesh.topology.dim)\n",
"p_mesh = pyvista.UnstructuredGrid(*dolfinx.plot.vtk_mesh(mesh, mesh.topology.dim))\n",
"pyvista_cells, cell_types, geometry = dolfinx.plot.vtk_mesh(V)\n",
Expand Down
1 change: 0 additions & 1 deletion chapter1/complex_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@
# +
import pyvista

pyvista.start_xvfb(0.1)
mesh.topology.create_connectivity(mesh.topology.dim, mesh.topology.dim)
p_mesh = pyvista.UnstructuredGrid(*dolfinx.plot.vtk_mesh(mesh, mesh.topology.dim))
pyvista_cells, cell_types, geometry = dolfinx.plot.vtk_mesh(V)
Expand Down
4 changes: 1 addition & 3 deletions chapter1/fundamentals_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@
"We start by converting the mesh to a format that can be used with {py:mod}`pyvista`.\n",
"To do this we use the function {py:func}`dolfinx.plot.vtk_mesh`.\n",
"It creates the data required to create a {py:class}`pyvista.UnstructuredGrid`.\n",
"On Linux (in docker) we need to start a virtual framebuffer for plotting through docker containers.\n",
"You can print the current backend and change it with {py:func}`pyvista.set_jupyter_backend`."
]
},
Expand All @@ -486,8 +485,7 @@
"source": [
"import pyvista\n",
"\n",
"print(pyvista.global_theme.jupyter_backend)\n",
"pyvista.start_xvfb(0.1)"
"print(pyvista.global_theme.jupyter_backend)"
]
},
{
Expand Down
2 changes: 0 additions & 2 deletions chapter1/fundamentals_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,12 @@
# We start by converting the mesh to a format that can be used with {py:mod}`pyvista`.
# To do this we use the function {py:func}`dolfinx.plot.vtk_mesh`.
# It creates the data required to create a {py:class}`pyvista.UnstructuredGrid`.
# On Linux (in docker) we need to start a virtual framebuffer for plotting through docker containers.
# You can print the current backend and change it with {py:func}`pyvista.set_jupyter_backend`.

# +
import pyvista

print(pyvista.global_theme.jupyter_backend)
pyvista.start_xvfb(0.1)

# +
from dolfinx import plot
Expand Down
4 changes: 1 addition & 3 deletions chapter1/membrane_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,7 @@
"outputs": [],
"source": [
"from dolfinx.plot import vtk_mesh\n",
"import pyvista\n",
"\n",
"pyvista.start_xvfb(0.1)"
"import pyvista\n"
]
},
{
Expand Down
3 changes: 0 additions & 3 deletions chapter1/membrane_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,9 @@ def on_boundary(x):
# ## Plotting the solution over a line
# We first plot the deflection $u_h$ over the domain $\Omega$.

# +
from dolfinx.plot import vtk_mesh
import pyvista

pyvista.start_xvfb(0.1)
# -

# Extract topology from mesh and create pyvista mesh

Expand Down
2 changes: 0 additions & 2 deletions chapter1/nitsche.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@
"source": [
"import pyvista\n",
"\n",
"pyvista.start_xvfb(1.0)\n",
"\n",
"grid = pyvista.UnstructuredGrid(*plot.vtk_mesh(V))\n",
"grid.point_data[\"u\"] = uh.x.array.real\n",
"grid.set_active_scalars(\"u\")\n",
Expand Down
2 changes: 0 additions & 2 deletions chapter1/nitsche.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@
# +
import pyvista

pyvista.start_xvfb(1.0)

grid = pyvista.UnstructuredGrid(*plot.vtk_mesh(V))
grid.point_data["u"] = uh.x.array.real
grid.set_active_scalars("u")
Expand Down
1 change: 0 additions & 1 deletion chapter2/amr.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
},
"outputs": [],
"source": [
"pyvista.start_xvfb(1.0)\n",
"\n",
"grid = pyvista.UnstructuredGrid(*dolfinx.plot.vtk_mesh(mesh))\n",
"grid.cell_data[\"ct\"] = ct.values\n",
Expand Down
1 change: 0 additions & 1 deletion chapter2/amr.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
# We use pyvista to visualize the mesh.

# + tags=["hide-input"]
pyvista.start_xvfb(1.0)

grid = pyvista.UnstructuredGrid(*dolfinx.plot.vtk_mesh(mesh))
grid.cell_data["ct"] = ct.values
Expand Down
2 changes: 0 additions & 2 deletions chapter2/diffusion_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@
"metadata": {},
"outputs": [],
"source": [
"pyvista.start_xvfb(1.0)\n",
"\n",
"grid = pyvista.UnstructuredGrid(*plot.vtk_mesh(V))\n",
"\n",
"plotter = pyvista.Plotter()\n",
Expand Down
2 changes: 0 additions & 2 deletions chapter2/diffusion_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ def initial_condition(x, a=5):
# We use the DOLFINx plotting functionality, which is based on pyvista to plot the solution at every $15$th time step. We would also like to visualize a colorbar reflecting the minimal and maximum value of $u$ at each time step. We use the following convenience function `plot_function` for this:

# +
pyvista.start_xvfb(1.0)

grid = pyvista.UnstructuredGrid(*plot.vtk_mesh(V))

plotter = pyvista.Plotter()
Expand Down
1 change: 0 additions & 1 deletion chapter2/hyperelasticity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@
"metadata": {},
"outputs": [],
"source": [
"pyvista.start_xvfb(1.0)\n",
"plotter = pyvista.Plotter()\n",
"plotter.open_gif(\"deformation.gif\", fps=3)\n",
"\n",
Expand Down
1 change: 0 additions & 1 deletion chapter2/hyperelasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def right(x):
# We create a function to plot the solution at each time step.

# +
pyvista.start_xvfb(1.0)
plotter = pyvista.Plotter()
plotter.open_gif("deformation.gif", fps=3)

Expand Down
2 changes: 0 additions & 2 deletions chapter2/linearelasticity_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@
"metadata": {},
"outputs": [],
"source": [
"pyvista.start_xvfb(1.0)\n",
"\n",
"# Create plotter and pyvista grid\n",
"p = pyvista.Plotter()\n",
"topology, cell_types, geometry = plot.vtk_mesh(V)\n",
Expand Down
2 changes: 0 additions & 2 deletions chapter2/linearelasticity_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ def sigma(u):
# In previous tutorials, we have considered scalar values, while the following section considers vectors.

# +
pyvista.start_xvfb(1.0)

# Create plotter and pyvista grid
p = pyvista.Plotter()
topology, cell_types, geometry = plot.vtk_mesh(V)
Expand Down
2 changes: 0 additions & 2 deletions chapter2/ns_code1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,6 @@
"metadata": {},
"outputs": [],
"source": [
"pyvista.start_xvfb(1.0)\n",
"\n",
"topology, cell_types, geometry = vtk_mesh(V)\n",
"values = np.zeros((geometry.shape[0], 3), dtype=np.float64)\n",
"values[:, : len(u_n)] = u_n.x.array.real.reshape((geometry.shape[0], len(u_n)))\n",
Expand Down
2 changes: 0 additions & 2 deletions chapter2/ns_code1.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,6 @@ def u_exact(x):
# In this section we will look at how to visualize vector functions with glyphs, instead of warping the mesh.

# +
pyvista.start_xvfb(1.0)

topology, cell_types, geometry = vtk_mesh(V)
values = np.zeros((geometry.shape[0], 3), dtype=np.float64)
values[:, : len(u_n)] = u_n.x.array.real.reshape((geometry.shape[0], len(u_n)))
Expand Down
2 changes: 0 additions & 2 deletions chapter3/component_bc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@
},
"outputs": [],
"source": [
"pyvista.start_xvfb(1.0)\n",
"\n",
"# Create plotter and pyvista grid\n",
"p = pyvista.Plotter()\n",
"topology, cell_types, x = vtk_mesh(V)\n",
Expand Down
2 changes: 0 additions & 2 deletions chapter3/component_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ def sigma(u):
# ## Visualization

# +
pyvista.start_xvfb(1.0)

# Create plotter and pyvista grid
p = pyvista.Plotter()
topology, cell_types, x = vtk_mesh(V)
Expand Down
1 change: 0 additions & 1 deletion chapter3/em.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@
},
"outputs": [],
"source": [
"pyvista.start_xvfb(1.0)\n",
"plotter = pyvista.Plotter()\n",
"tdim = mesh.topology.dim\n",
"mesh.topology.create_connectivity(tdim, tdim)\n",
Expand Down
1 change: 0 additions & 1 deletion chapter3/em.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@

# We can also visualize the subdommains using pyvista

pyvista.start_xvfb(1.0)
plotter = pyvista.Plotter()
tdim = mesh.topology.dim
mesh.topology.create_connectivity(tdim, tdim)
Expand Down
1 change: 0 additions & 1 deletion chapter3/multiple_dirichlet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@
"metadata": {},
"outputs": [],
"source": [
"pyvista.start_xvfb(1.0)\n",
"pyvista_cells, cell_types, geometry = vtk_mesh(V)\n",
"grid = pyvista.UnstructuredGrid(pyvista_cells, cell_types, geometry)\n",
"grid.point_data[\"u\"] = uh.x.array\n",
Expand Down
1 change: 0 additions & 1 deletion chapter3/multiple_dirichlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def u_exact(x):
# To visualize the solution, run the script with in a Jupyter notebook with `off_screen=False` or as a python script with `off_screen=True`.

# +
pyvista.start_xvfb(1.0)
pyvista_cells, cell_types, geometry = vtk_mesh(V)
grid = pyvista.UnstructuredGrid(pyvista_cells, cell_types, geometry)
grid.point_data["u"] = uh.x.array
Expand Down
10 changes: 0 additions & 10 deletions chapter3/neumann_dirichlet_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,6 @@
"To look at the actual solution, run the script as a python script with `off_screen=True` or as a Jupyter notebook with `off_screen=False`"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9",
"metadata": {},
"outputs": [],
"source": [
"pyvista.start_xvfb(1.0)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
2 changes: 0 additions & 2 deletions chapter3/neumann_dirichlet_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ def boundary_D(x):
# ## Visualization
# To look at the actual solution, run the script as a python script with `off_screen=True` or as a Jupyter notebook with `off_screen=False`

pyvista.start_xvfb(1.0)

# +
pyvista_cells, cell_types, geometry = vtk_mesh(V)
grid = pyvista.UnstructuredGrid(pyvista_cells, cell_types, geometry)
Expand Down
1 change: 0 additions & 1 deletion chapter3/robin_neumann_dirichlet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@
"uh = problem.solve()\n",
"\n",
"# Visualize solution\n",
"pyvista.start_xvfb(1.0)\n",
"pyvista_cells, cell_types, geometry = vtk_mesh(V)\n",
"grid = pyvista.UnstructuredGrid(pyvista_cells, cell_types, geometry)\n",
"grid.point_data[\"u\"] = uh.x.array\n",
Expand Down
1 change: 0 additions & 1 deletion chapter3/robin_neumann_dirichlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ def type(self):
uh = problem.solve()

# Visualize solution
pyvista.start_xvfb(1.0)
pyvista_cells, cell_types, geometry = vtk_mesh(V)
grid = pyvista.UnstructuredGrid(pyvista_cells, cell_types, geometry)
grid.point_data["u"] = uh.x.array
Expand Down
2 changes: 0 additions & 2 deletions chapter3/subdomains.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
"import numpy as np\n",
"import pyvista\n",
"\n",
"pyvista.start_xvfb(1.0)\n",
"\n",
"mesh = create_unit_square(MPI.COMM_WORLD, 10, 10)\n",
"Q = functionspace(mesh, (\"DG\", 0))"
]
Expand Down
2 changes: 0 additions & 2 deletions chapter3/subdomains.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
import numpy as np
import pyvista

pyvista.start_xvfb(1.0)

mesh = create_unit_square(MPI.COMM_WORLD, 10, 10)
Q = functionspace(mesh, ("DG", 0))

Expand Down
1 change: 0 additions & 1 deletion chapter4/newton-solver.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@
"metadata": {},
"outputs": [],
"source": [
"pyvista.start_xvfb(1.0)\n",
"u_topology, u_cell_types, u_geometry = dolfinx.plot.vtk_mesh(V)\n",
"u_grid = pyvista.UnstructuredGrid(u_topology, u_cell_types, u_geometry)\n",
"u_grid.point_data[\"u\"] = uh.x.array.real\n",
Expand Down
1 change: 0 additions & 1 deletion chapter4/newton-solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ def u_exact(x):
if domain.comm.rank == 0:
print(f"Error_max: {error_max:.2e}")

pyvista.start_xvfb(1.0)
u_topology, u_cell_types, u_geometry = dolfinx.plot.vtk_mesh(V)
u_grid = pyvista.UnstructuredGrid(u_topology, u_cell_types, u_geometry)
u_grid.point_data["u"] = uh.x.array.real
Expand Down
Loading