From 1db5fae64e1b9253a6281565526f3be13663218e Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Mon, 25 Mar 2024 11:30:15 +0000 Subject: [PATCH 01/11] updating FEniCSx example --- .../fem/fenicsx-helmholtz-tutorial.ipynb | 167 +++++++++++++----- 1 file changed, 127 insertions(+), 40 deletions(-) diff --git a/tutorials/fem/fenicsx-helmholtz-tutorial.ipynb b/tutorials/fem/fenicsx-helmholtz-tutorial.ipynb index 977603c..a977694 100644 --- a/tutorials/fem/fenicsx-helmholtz-tutorial.ipynb +++ b/tutorials/fem/fenicsx-helmholtz-tutorial.ipynb @@ -2,6 +2,7 @@ "cells": [ { "cell_type": "markdown", + "id": "b20531eb", "metadata": {}, "source": [ "# The Helmholtz Equation with FEniCSx\n", @@ -186,11 +187,15 @@ { "cell_type": "code", "execution_count": 1, + "id": "a78da36c", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", + "import basix\n", + "import basix.ufl\n", "import dolfinx\n", + "import dolfinx.fem.petsc\n", "import ufl\n", "from petsc4py import PETSc\n", "import pyvista\n", @@ -199,6 +204,7 @@ }, { "cell_type": "markdown", + "id": "bc1f36b0", "metadata": {}, "source": [ "#### Simulation Parameters\n", @@ -209,6 +215,7 @@ { "cell_type": "code", "execution_count": 2, + "id": "8e53a19a", "metadata": {}, "outputs": [], "source": [ @@ -227,6 +234,7 @@ }, { "cell_type": "markdown", + "id": "c4266fd9", "metadata": {}, "source": [ "#### Domain Definition and Meshing\n", @@ -244,6 +252,7 @@ { "cell_type": "code", "execution_count": 3, + "id": "f97493a1", "metadata": {}, "outputs": [], "source": [ @@ -255,6 +264,7 @@ }, { "cell_type": "markdown", + "id": "91cb1f7b", "metadata": {}, "source": [ "Now it is the time do define the mesh. Since we have a rectangular room we use the `dolfinx.mesh.create_box` [function](https://docs.fenicsproject.org/dolfinx/main/python/generated/dolfinx.mesh.html?highlight=create_box#dolfinx.mesh.create_box):" @@ -263,6 +273,7 @@ { "cell_type": "code", "execution_count": 4, + "id": "81b075f9", "metadata": {}, "outputs": [], "source": [ @@ -274,6 +285,7 @@ }, { "cell_type": "markdown", + "id": "664eeb0a", "metadata": {}, "source": [ "We then define the element type as a second order Lagrange element. This means that whith each element we express the unknown field as a linear superposition of second order Lagrange polynomials. FEM finds an approximate solution to the PDE by finding the coefficients of this superposition." @@ -282,14 +294,16 @@ { "cell_type": "code", "execution_count": 5, + "id": "9f9249f4", "metadata": {}, "outputs": [], "source": [ - "P = ufl.FiniteElement(\"Lagrange\", mesh.ufl_cell(), 2)" + "P = basix.ufl.element(\"Lagrange\", \"tetrahedron\", 2)" ] }, { "cell_type": "markdown", + "id": "c5086637", "metadata": {}, "source": [ "#### Function Space\n", @@ -300,14 +314,16 @@ { "cell_type": "code", "execution_count": 6, + "id": "41d11a54", "metadata": {}, "outputs": [], "source": [ - "V = dolfinx.fem.FunctionSpace(mesh, P)" + "V = dolfinx.fem.functionspace(mesh, P)" ] }, { "cell_type": "markdown", + "id": "8bab21e6", "metadata": {}, "source": [ "The formulation of the weak form in the simplified space is the same as in the original Sobolev space, except that the integrals reduce to sums. We do not need to worry about it as we simply need to specify the terms of the weak form.\n", @@ -320,6 +336,7 @@ { "cell_type": "code", "execution_count": 7, + "id": "ec5a5be1", "metadata": {}, "outputs": [], "source": [ @@ -329,6 +346,7 @@ }, { "cell_type": "markdown", + "id": "c2231867", "metadata": {}, "source": [ "We are now ready to specify the bilinear form" @@ -337,11 +355,12 @@ { "cell_type": "code", "execution_count": 8, + "id": "f0105640", "metadata": {}, "outputs": [], "source": [ "k_sq = dolfinx.fem.Constant(mesh, PETSc.ScalarType(k**2))\n", - "a = (\n", + "a = dolfinx.fem.form(\n", " ufl.inner(ufl.nabla_grad(u), ufl.nabla_grad(phi)) * ufl.dx\n", " - k_sq * ufl.inner(u, phi) * ufl.dx\n", ")" @@ -349,6 +368,7 @@ }, { "cell_type": "markdown", + "id": "62ec85b6", "metadata": {}, "source": [ ":::{note}\n", @@ -370,6 +390,7 @@ { "cell_type": "code", "execution_count": 9, + "id": "aa8861d9", "metadata": {}, "outputs": [], "source": [ @@ -399,6 +420,7 @@ }, { "cell_type": "markdown", + "id": "9189d1a1", "metadata": {}, "source": [ "We are using the `numpy` function [isclose](https://numpy.org/doc/stable/reference/generated/numpy.isclose.html) since we are dealing with the mesh coordinates, which is expressed as floating point values. This means that there might be small errors; a point `x[0]` can have the value `2.22e-16` instead of `0`.\n", @@ -409,6 +431,7 @@ { "cell_type": "code", "execution_count": 10, + "id": "46167db6", "metadata": {}, "outputs": [], "source": [ @@ -431,6 +454,7 @@ }, { "cell_type": "markdown", + "id": "c84e7b69", "metadata": {}, "source": [ "Next we make the collection of facets and values" @@ -439,6 +463,7 @@ { "cell_type": "code", "execution_count": 11, + "id": "6b58cef1", "metadata": {}, "outputs": [], "source": [ @@ -447,6 +472,7 @@ }, { "cell_type": "markdown", + "id": "ca9b55c3", "metadata": {}, "source": [ "Now that this is done we can define the custom integration variables `ds` for our boundary. `ds` will return the measure for each different boundary if we use, as input, the ID for that boundary. For example, `ds(5)` will return the integration variable for the `bz0` boundary. Note that we apply a non-zero velocity to `by0`, which has ID `3`." @@ -455,6 +481,7 @@ { "cell_type": "code", "execution_count": 12, + "id": "740010a7", "metadata": {}, "outputs": [], "source": [ @@ -463,6 +490,7 @@ }, { "cell_type": "markdown", + "id": "dc85a913", "metadata": {}, "source": [ "Now we simply need to define the acoustic fluxes. We need two: one for the rigid walls and one for the active walls" @@ -471,6 +499,7 @@ { "cell_type": "code", "execution_count": 13, + "id": "6e6db0f5", "metadata": {}, "outputs": [], "source": [ @@ -483,6 +512,7 @@ }, { "cell_type": "markdown", + "id": "9eaf6f18", "metadata": {}, "source": [ "#### Linear Form \n", @@ -492,14 +522,16 @@ { "cell_type": "code", "execution_count": 14, + "id": "f52194fb", "metadata": {}, "outputs": [], "source": [ - "L = ufl.inner(g_rig, phi) * ds((1, 2, 4, 5, 6)) + ufl.inner(g_in, phi) * ds(3)" + "L = dolfinx.fem.form(ufl.inner(g_rig, phi) * ds((1, 2, 4, 5, 6)) + ufl.inner(g_in, phi) * ds(3))" ] }, { "cell_type": "markdown", + "id": "e3b73159", "metadata": {}, "source": [ "#### Solution\n", @@ -510,6 +542,7 @@ { "cell_type": "code", "execution_count": 15, + "id": "35b89e34", "metadata": {}, "outputs": [], "source": [ @@ -519,6 +552,7 @@ }, { "cell_type": "markdown", + "id": "923e412f", "metadata": {}, "source": [ "We next call `problem.solve()` to solve the PDE." @@ -527,12 +561,13 @@ { "cell_type": "code", "execution_count": 16, + "id": "73e9fc7c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Coefficient(FunctionSpace(Mesh(VectorElement(FiniteElement('Lagrange', tetrahedron, 1), dim=3), 0), FiniteElement('Lagrange', tetrahedron, 2)), 0)" + "Coefficient(FunctionSpace(Mesh(blocked element (Basix element (P, tetrahedron, 1, gll_warped, unset, False), (3,)), 0), Basix element (P, tetrahedron, 2, gll_warped, unset, False)), 0)" ] }, "execution_count": 16, @@ -546,6 +581,7 @@ }, { "cell_type": "markdown", + "id": "fb21bb68", "metadata": {}, "source": [ "#### Visualizing Results\n", @@ -555,10 +591,61 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 18, + "id": "2afacc02", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: pythreejs in /usr/local/lib/python3.10/dist-packages (2.4.2)\n", + "Requirement already satisfied: ipywidgets>=7.2.1 in /usr/local/lib/python3.10/dist-packages (from pythreejs) (8.1.1)\n", + "Requirement already satisfied: ipydatawidgets>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from pythreejs) (4.3.5)\n", + "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from pythreejs) (1.23.2)\n", + "Requirement already satisfied: traitlets in /usr/local/lib/python3.10/dist-packages (from pythreejs) (5.11.2)\n", + "Requirement already satisfied: traittypes>=0.2.0 in /usr/local/lib/python3.10/dist-packages (from ipydatawidgets>=1.1.1->pythreejs) (0.2.1)\n", + "Requirement already satisfied: comm>=0.1.3 in /usr/local/lib/python3.10/dist-packages (from ipywidgets>=7.2.1->pythreejs) (0.2.0)\n", + "Requirement already satisfied: ipython>=6.1.0 in /usr/local/lib/python3.10/dist-packages (from ipywidgets>=7.2.1->pythreejs) (8.17.2)\n", + "Requirement already satisfied: widgetsnbextension~=4.0.9 in /usr/local/lib/python3.10/dist-packages (from ipywidgets>=7.2.1->pythreejs) (4.0.9)\n", + "Requirement already satisfied: jupyterlab-widgets~=3.0.9 in /usr/local/lib/python3.10/dist-packages (from ipywidgets>=7.2.1->pythreejs) (3.0.9)\n", + "Requirement already satisfied: decorator in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (5.1.1)\n", + "Requirement already satisfied: jedi>=0.16 in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.19.1)\n", + "Requirement already satisfied: matplotlib-inline in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.1.6)\n", + "Requirement already satisfied: prompt-toolkit!=3.0.37,<3.1.0,>=3.0.30 in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (3.0.41)\n", + "Requirement already satisfied: pygments>=2.4.0 in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (2.16.1)\n", + "Requirement already satisfied: stack-data in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.6.3)\n", + "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (1.1.3)\n", + "Requirement already satisfied: pexpect>4.3 in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (4.8.0)\n", + "Requirement already satisfied: parso<0.9.0,>=0.8.3 in /usr/local/lib/python3.10/dist-packages (from jedi>=0.16->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.8.3)\n", + "Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.10/dist-packages (from pexpect>4.3->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.7.0)\n", + "Requirement already satisfied: wcwidth in /usr/local/lib/python3.10/dist-packages (from prompt-toolkit!=3.0.37,<3.1.0,>=3.0.30->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.2.10)\n", + "Requirement already satisfied: executing>=1.2.0 in /usr/local/lib/python3.10/dist-packages (from stack-data->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (2.0.1)\n", + "Requirement already satisfied: asttokens>=2.1.0 in /usr/local/lib/python3.10/dist-packages (from stack-data->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (2.4.1)\n", + "Requirement already satisfied: pure-eval in /usr/local/lib/python3.10/dist-packages (from stack-data->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.2.2)\n", + "Requirement already satisfied: six>=1.12.0 in /usr/local/lib/python3.10/dist-packages (from asttokens>=2.1.0->stack-data->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (1.16.0)\n", + "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n", + "\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.2.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3 -m pip install --upgrade pip\u001b[0m\n" + ] + }, + { + "ename": "ValueError", + "evalue": "Invalid Jupyter notebook plotting backend \"pythreejs\".\nUse one of the following:\n\"static\", \"client\", \"server\", \"trame\", \"none\"", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[18], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m get_ipython()\u001b[38;5;241m.\u001b[39msystem(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mpip install pythreejs\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m----> 2\u001b[0m \u001b[43mpyvista\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mset_jupyter_backend\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mpythreejs\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3\u001b[0m p_mesh \u001b[38;5;241m=\u001b[39m pyvista\u001b[38;5;241m.\u001b[39mUnstructuredGrid(\u001b[38;5;241m*\u001b[39mdolfinx\u001b[38;5;241m.\u001b[39mplot\u001b[38;5;241m.\u001b[39mcreate_vtk_mesh(mesh, mesh\u001b[38;5;241m.\u001b[39mtopology\u001b[38;5;241m.\u001b[39mdim))\n\u001b[1;32m 4\u001b[0m pyvista_cells, cell_types, geometry \u001b[38;5;241m=\u001b[39m dolfinx\u001b[38;5;241m.\u001b[39mplot\u001b[38;5;241m.\u001b[39mcreate_vtk_mesh(V)\n", + "File \u001b[0;32m/usr/local/lib/python3.10/dist-packages/pyvista/jupyter/__init__.py:107\u001b[0m, in \u001b[0;36mset_jupyter_backend\u001b[0;34m(backend, name, **kwargs)\u001b[0m\n\u001b[1;32m 52\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mset_jupyter_backend\u001b[39m(backend, name\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 53\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Set the plotting backend for a jupyter notebook.\u001b[39;00m\n\u001b[1;32m 54\u001b[0m \n\u001b[1;32m 55\u001b[0m \u001b[38;5;124;03m Parameters\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 105\u001b[0m \n\u001b[1;32m 106\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 107\u001b[0m pyvista\u001b[38;5;241m.\u001b[39mglobal_theme\u001b[38;5;241m.\u001b[39m_jupyter_backend \u001b[38;5;241m=\u001b[39m \u001b[43m_validate_jupyter_backend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mbackend\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 108\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m backend \u001b[38;5;129;01min\u001b[39;00m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mserver\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mclient\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtrame\u001b[39m\u001b[38;5;124m'\u001b[39m]:\n\u001b[1;32m 109\u001b[0m \u001b[38;5;66;03m# Launch the trame server\u001b[39;00m\n\u001b[1;32m 110\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpyvista\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtrame\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mjupyter\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m elegantly_launch\n", + "File \u001b[0;32m/usr/local/lib/python3.10/dist-packages/pyvista/jupyter/__init__.py:36\u001b[0m, in \u001b[0;36m_validate_jupyter_backend\u001b[0;34m(backend)\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m backend \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m ALLOWED_BACKENDS:\n\u001b[1;32m 35\u001b[0m backend_list_str \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m, \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mjoin([\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mitem\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m ALLOWED_BACKENDS])\n\u001b[0;32m---> 36\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 37\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mInvalid Jupyter notebook plotting backend \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mbackend\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 38\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mUse one of the following:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00mbackend_list_str\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 39\u001b[0m )\n\u001b[1;32m 41\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m backend \u001b[38;5;129;01min\u001b[39;00m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mserver\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mclient\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtrame\u001b[39m\u001b[38;5;124m'\u001b[39m]:\n\u001b[1;32m 42\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n", + "\u001b[0;31mValueError\u001b[0m: Invalid Jupyter notebook plotting backend \"pythreejs\".\nUse one of the following:\n\"static\", \"client\", \"server\", \"trame\", \"none\"" + ] + } + ], "source": [ + "!pip install pythreejs\n", "pyvista.set_jupyter_backend(\"pythreejs\")\n", "p_mesh = pyvista.UnstructuredGrid(*dolfinx.plot.create_vtk_mesh(mesh, mesh.topology.dim))\n", "pyvista_cells, cell_types, geometry = dolfinx.plot.create_vtk_mesh(V)\n", @@ -570,24 +657,10 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": null, + "id": "da6bfa83", "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "535b510b0b844f9cbfc505fedee224d5", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Renderer(camera=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(intensity=0.25, positi…" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "p_real = pyvista.Plotter()\n", "p_real.add_text(\"uh real\", position=\"upper_edge\", font_size=14, color=\"black\")\n", @@ -602,22 +675,35 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 19, + "id": "1d586880", "metadata": {}, "outputs": [ { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "36c42b5803234b98a1f6c2d2571aca35", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Renderer(camera=PerspectiveCamera(aspect=1.3333333333333333, children=(DirectionalLight(intensity=0.25, positi…" - ] - }, - "metadata": {}, - "output_type": "display_data" + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING:py.warnings:/usr/local/lib/python3.10/dist-packages/pyvista/plotting/plotter.py:149: UserWarning: \n", + "This system does not appear to be running an xserver.\n", + "PyVista will likely segfault when rendering.\n", + "\n", + "Try starting a virtual frame buffer with xvfb, or using\n", + " ``pyvista.start_xvfb()``\n", + "\n", + " warnings.warn(\n", + "\n" + ] + }, + { + "ename": "NameError", + "evalue": "name 'grid' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[19], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m p_imag \u001b[38;5;241m=\u001b[39m pyvista\u001b[38;5;241m.\u001b[39mPlotter()\n\u001b[0;32m----> 3\u001b[0m \u001b[43mgrid\u001b[49m\u001b[38;5;241m.\u001b[39mset_active_scalars(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mu_imag\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 4\u001b[0m p_imag\u001b[38;5;241m.\u001b[39madd_mesh(p_mesh, show_edges\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m, style\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mwireframe\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 5\u001b[0m p_imag\u001b[38;5;241m.\u001b[39madd_text(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muh imag\u001b[39m\u001b[38;5;124m\"\u001b[39m, position\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mupper_edge\u001b[39m\u001b[38;5;124m\"\u001b[39m, font_size\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m14\u001b[39m, color\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mblack\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "\u001b[0;31mNameError\u001b[0m: name 'grid' is not defined" + ] } ], "source": [ @@ -633,6 +719,7 @@ }, { "cell_type": "markdown", + "id": "f5d6439c", "metadata": {}, "source": [ "### A Comment About the Solution\n", @@ -649,9 +736,9 @@ "formats": "ipynb,py:light" }, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (DOLFINx complex)", "language": "python", - "name": "python3" + "name": "python3-complex" }, "language_info": { "codemirror_mode": { @@ -663,7 +750,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.10.12" } }, "nbformat": 4, From 8b001e72428dd77e5d59a93ab4e1068047567d8c Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Mon, 25 Mar 2024 11:35:26 +0000 Subject: [PATCH 02/11] update docker image --- docker/Dockerfile | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 4a8e61c..31a6f14 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -13,18 +13,17 @@ ARG HDF5_SERIES=1.12 ARG HDF5_PATCH=2 ARG KAHIP_VERSION=3.14 ARG NUMPY_VERSION=1.22.4 -ARG PYBIND11_VERSION=2.9.2 ARG PETSC_VERSION=3.17.2 ARG SLEPC_VERSION=3.17.1 -ARG XTENSOR_VERSION=0.24.2 ARG XTL_VERSION=0.7.4 ARG MPICH_VERSION=4.0.2 ARG OPENMPI_SERIES=4.1 ARG OPENMPI_PATCH=4 -ARG DOLFINX_VERSION=v0.4.1 -ARG FFCX_VERSION=v0.4.2 -ARG BASIX_VERSION=v0.4.2 -ARG UFL_VERSION=2022.1.0 +ARG DOLFINX_VERSION=v0.7.3 +ARG FFCX_VERSION=v0.7.0 +ARG BASIX_VERSION=v0.7.0 +ARG UFL_VERSION=2023.2.0 +ARG NANOBIND_VERSION=1.9.2 ARG PYTHON_VERSION=3.10 ######################################## @@ -36,13 +35,11 @@ LABEL description="Environment with all dependencies for the CA knowledgebase" ARG GMSH_VERSION ARG HDF5_SERIES ARG HDF5_PATCH -ARG PYBIND11_VERSION ARG PETSC_VERSION ARG SLEPC_VERSION ARG ADIOS2_VERSION ARG KAHIP_VERSION ARG NUMPY_VERSION -ARG XTENSOR_VERSION ARG XTL_VERSION ARG MPICH_VERSION ARG OPENMPI_SERIES @@ -51,6 +48,7 @@ ARG DOLFINX_VERSION ARG FFCX_VERSION ARG BASIX_VERSION ARG UFL_VERSION +ARG NANOBIND_VERSION # Compiler optimisation flags for SLEPc and PETSc, all languages. ARG PETSC_SLEPC_OPTFLAGS="-O2" @@ -136,19 +134,7 @@ RUN wget http://www.mpich.org/static/downloads/${MPICH_VERSION}/mpich-${MPICH_VE # - Second set of packages are recommended and/or required to build # documentation or run tests. RUN pip3 install --no-binary="numpy" --no-cache-dir cffi mpi4py numba numpy==${NUMPY_VERSION} scipy && \ - pip3 install --no-cache-dir cppimport flake8 isort jupytext matplotlib mypy myst-parser pybind11==${PYBIND11_VERSION} pytest pytest-xdist sphinx sphinx_rtd_theme - -# Install xtl, xtensor -RUN git clone -b ${XTL_VERSION} --single-branch --depth 1 https://github.com/xtensor-stack/xtl.git && \ - cd xtl && \ - cmake -G Ninja . && \ - ninja install && \ - cd ../ && \ - git clone -b ${XTENSOR_VERSION} --single-branch --depth 1 https://github.com/xtensor-stack/xtensor.git && \ - cd xtensor && \ - cmake -G Ninja . && \ - ninja install && \ - rm -rf /tmp/* + pip3 install --no-cache-dir cppimport flake8 isort jupytext matplotlib mypy myst-parser nanobind==${NANOBIND_VERSION} pytest pytest-xdist sphinx sphinx_rtd_theme # Install KaHIP RUN wget -nc --quiet https://github.com/kahip/kahip/archive/v${KAHIP_VERSION}.tar.gz && \ From 54b2d217d648d7c742d2cb7a605de677e7068d86 Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Mon, 25 Mar 2024 13:41:02 +0000 Subject: [PATCH 03/11] update petsc version and install --- docker/Dockerfile | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 31a6f14..e60ad2e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -13,8 +13,8 @@ ARG HDF5_SERIES=1.12 ARG HDF5_PATCH=2 ARG KAHIP_VERSION=3.14 ARG NUMPY_VERSION=1.22.4 -ARG PETSC_VERSION=3.17.2 -ARG SLEPC_VERSION=3.17.1 +ARG PETSC_VERSION=3.20.5 +ARG SLEPC_VERSION=3.20.1 ARG XTL_VERSION=0.7.4 ARG MPICH_VERSION=4.0.2 ARG OPENMPI_SERIES=4.1 @@ -179,26 +179,22 @@ RUN apt-get -qq update && \ mkdir -p ${PETSC_DIR} && tar -xf petsc-${PETSC_VERSION}.tar.gz -C ${PETSC_DIR} --strip-components 1 && \ cd ${PETSC_DIR} && \ # Complex, 32-bit int - python3 ./configure \ - PETSC_ARCH=linux-gnu-complex-32 \ + ./configure \ + PETSC_ARCH=linux-gnu-complex64-32 \ --COPTFLAGS="${PETSC_SLEPC_OPTFLAGS}" \ --CXXOPTFLAGS="${PETSC_SLEPC_OPTFLAGS}" \ --FOPTFLAGS="${PETSC_SLEPC_OPTFLAGS}" \ - --with-make-np=${PETSC_SLEPC_MAKE_NP} \ --with-64-bit-indices=no \ --with-debugging=${PETSC_SLEPC_DEBUGGING} \ --with-fortran-bindings=no \ --with-shared-libraries \ - --download-hypre \ --download-metis \ --download-mumps \ --download-ptscotch \ --download-scalapack \ - --download-suitesparse \ - --download-superlu \ - --download-superlu_dist \ - --with-scalar-type=complex && \ - make PETSC_DIR=/usr/local/petsc PETSC_ARCH=linux-gnu-complex-32 ${MAKEFLAGS} all && \ + --with-scalar-type=complex \ + --with-precision=single && \ + make PETSC_DIR=/usr/local/petsc PETSC_ARCH=linux-gnu-complex64-32 ${MAKEFLAGS} all && \ # Install petsc4py cd src/binding/petsc4py && \ PETSC_ARCH=linux-gnu-complex-32 pip3 install --no-cache-dir . && \ From a4fe625202a87120fb88b3bf6b58244246bf3f1f Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Mon, 25 Mar 2024 13:42:20 +0000 Subject: [PATCH 04/11] petsc_arch --- docker/Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index e60ad2e..8c0cde6 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -197,7 +197,7 @@ RUN apt-get -qq update && \ make PETSC_DIR=/usr/local/petsc PETSC_ARCH=linux-gnu-complex64-32 ${MAKEFLAGS} all && \ # Install petsc4py cd src/binding/petsc4py && \ - PETSC_ARCH=linux-gnu-complex-32 pip3 install --no-cache-dir . && \ + PETSC_ARCH=linux-gnu-complex64-32 pip3 install --no-cache-dir . && \ # Cleanup apt-get -y purge bison flex && \ apt-get -y autoremove && \ @@ -219,12 +219,12 @@ RUN apt-get -qq update && \ RUN wget -nc --quiet https://gitlab.com/slepc/slepc/-/archive/v${SLEPC_VERSION}/slepc-v${SLEPC_VERSION}.tar.gz && \ mkdir -p ${SLEPC_DIR} && tar -xf slepc-v${SLEPC_VERSION}.tar.gz -C ${SLEPC_DIR} --strip-components 1 && \ cd ${SLEPC_DIR} && \ - export PETSC_ARCH=linux-gnu-complex-32 && \ + export PETSC_ARCH=linux-gnu-complex64-32 && \ python3 ./configure && \ make && \ # Install slepc4py cd src/binding/slepc4py && \ - PETSC_ARCH=linux-gnu-complex-32 pip3 install --no-cache-dir . && \ + PETSC_ARCH=linux-gnu-complex64-32 pip3 install --no-cache-dir . && \ rm -rf ${SLEPC_DIR}/CTAGS ${SLEPC_DIR}/TAGS ${SLEPC_DIR}/docs ${SLEPC_DIR}/src/ ${SLEPC_DIR}/**/obj/ ${SLEPC_DIR}/**/test/ && \ rm -rf /tmp/* @@ -249,15 +249,15 @@ RUN git clone -b ${DOLFINX_VERSION} --single-branch --depth 1 https://github.com cd dolfinx && \ mkdir -p build-complex && \ cd build-complex && \ - PETSC_ARCH=linux-gnu-complex-32 cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local/dolfinx-complex -DCMAKE_BUILD_TYPE=${DOLFINX_CMAKE_BUILD_TYPE} -DCMAKE_CXX_FLAGS=${DOLFIN_CMAKE_CXX_FLAGS} ../cpp && \ + PETSC_ARCH=linux-gnu-complex64-32 cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local/dolfinx-complex -DCMAKE_BUILD_TYPE=${DOLFINX_CMAKE_BUILD_TYPE} -DCMAKE_CXX_FLAGS=${DOLFIN_CMAKE_CXX_FLAGS} ../cpp && \ ninja install && \ . /usr/local/dolfinx-complex/lib/dolfinx/dolfinx.conf && \ cd ../python && \ - CXXFLAGS=${DOLFINX_CMAKE_CXX_FLAGS} PETSC_ARCH=linux-gnu-complex-32 pip3 install -v --target /usr/local/dolfinx-complex/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir . + CXXFLAGS=${DOLFINX_CMAKE_CXX_FLAGS} PETSC_ARCH=linux-gnu-complex64-32 pip3 install -v --target /usr/local/dolfinx-complex/lib/python${PYTHON_VERSION}/dist-packages --no-dependencies --no-cache-dir . ENV PKG_CONFIG_PATH=/usr/local/dolfinx-complex/lib/pkgconfig:$PKG_CONFIG_PATH \ - PETSC_ARCH=linux-gnu-complex-32 \ + PETSC_ARCH=linux-gnu-complex64-32 \ PYTHONPATH=/usr/local/dolfinx-complex/lib/python${PYTHON_VERSION}/dist-packages:$PYTHONPATH \ LD_LIBRARY_PATH=/usr/local/dolfinx-complex/lib:$LD_LIBRARY_PATH From 14778c91a9f6a886d8b60ba107bab00090c88ab4 Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Mon, 25 Mar 2024 14:18:16 +0000 Subject: [PATCH 05/11] petsc --- _toc.yml | 25 +++++++++++++------------ docker/Dockerfile | 4 +--- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/_toc.yml b/_toc.yml index d3948f1..1e05828 100644 --- a/_toc.yml +++ b/_toc.yml @@ -4,7 +4,7 @@ format: jb-book root: intro parts: -- caption: +- caption: chapters: - file: about/get-started - file: about/who-you-are @@ -20,9 +20,10 @@ parts: - file: about/contribute-maintain sections: - file: about/contribute-docker + - file: about/contribute-style - file: CODE_OF_CONDUCT - file: about/who-we-are - + - caption: Core Concepts chapters: - file: core-concepts/why-use-ca @@ -41,12 +42,12 @@ parts: - file: core-concepts/how-to-solve-eikonal - file: core-concepts/how-to-solve-magic-of-matrices - file: core-concepts/geom-and-mesh - sections: + sections: - file: core-concepts/geom-and-mesh-dimensionality - file: core-concepts/geom-and-mesh-mesh-structure - file: core-concepts/geom-and-mesh-elements-and-interpolation - file: core-concepts/geom-and-mesh-mesh-refinement - + - caption: Tutorials chapters: - file: tutorials/bem/bem-tutorials-main @@ -57,28 +58,28 @@ parts: sections: - file: tutorials/fem/fem_1d_impedance_tube - file: tutorials/fem/fenicsx-helmholtz-tutorial - + - file: tutorials/fdtd/fdtd-tutorials-main sections: - file: tutorials/fdtd/fdtd-tutorials-1 - + - caption: Software Guides - chapters: + chapters: - file: software/software-main - + - caption: User Code chapters: - file: user/user - + - caption: Data chapters: - file: data/data - + - caption: Community chapters: - - file: community/bios + - file: community/bios - file: community/discussion - + - caption: Reference chapters: - file: reference/glossary diff --git a/docker/Dockerfile b/docker/Dockerfile index 8c0cde6..71e4cee 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -152,7 +152,6 @@ RUN wget -nc --quiet https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-${HDF5_ make -j${BUILD_NP} install && \ rm -rf /tmp/* - # Install ADIOS2 RUN wget -nc --quiet https://github.com/ornladios/ADIOS2/archive/v${ADIOS2_VERSION}.tar.gz -O adios2-v${ADIOS2_VERSION}.tar.gz && \ mkdir -p adios2-v${ADIOS2_VERSION} && \ @@ -175,8 +174,7 @@ ENV PYTHONPATH=/usr/local/lib:$PYTHONPATH ENV PETSC_DIR=/usr/local/petsc SLEPC_DIR=/usr/local/slepc RUN apt-get -qq update && \ apt-get -y install bison flex && \ - wget -nc --quiet http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-lite-${PETSC_VERSION}.tar.gz -O petsc-${PETSC_VERSION}.tar.gz && \ - mkdir -p ${PETSC_DIR} && tar -xf petsc-${PETSC_VERSION}.tar.gz -C ${PETSC_DIR} --strip-components 1 && \ + git clone -b v${PETSC_VERSION} https://gitlab.com/petsc/petsc.git ${PETSC_DIR} && \ cd ${PETSC_DIR} && \ # Complex, 32-bit int ./configure \ From d99b904396a877cf3819295923dca2a2b4bdf75e Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Mon, 25 Mar 2024 15:20:26 +0000 Subject: [PATCH 06/11] update --- docker/Dockerfile | 13 +- .../fem/fenicsx-helmholtz-tutorial.ipynb | 122 ++++++------------ 2 files changed, 41 insertions(+), 94 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 71e4cee..e7eb515 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -214,15 +214,14 @@ RUN apt-get -qq update && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # Install SLEPc -RUN wget -nc --quiet https://gitlab.com/slepc/slepc/-/archive/v${SLEPC_VERSION}/slepc-v${SLEPC_VERSION}.tar.gz && \ - mkdir -p ${SLEPC_DIR} && tar -xf slepc-v${SLEPC_VERSION}.tar.gz -C ${SLEPC_DIR} --strip-components 1 && \ +RUN git clone -b v${SLEPC_VERSION} https://gitlab.com/slepc/slepc.git ${SLEPC_DIR} && \ cd ${SLEPC_DIR} && \ export PETSC_ARCH=linux-gnu-complex64-32 && \ - python3 ./configure && \ + ./configure && \ make && \ # Install slepc4py cd src/binding/slepc4py && \ - PETSC_ARCH=linux-gnu-complex64-32 pip3 install --no-cache-dir . && \ + PETSC_ARCH=linux-gnu-real32-32:linux-gnu-complex64-32:linux-gnu-real64-32:linux-gnu-complex128-32:linux-gnu-real64-64:linux-gnu-complex128-64 pip3 install --no-cache-dir . && \ rm -rf ${SLEPC_DIR}/CTAGS ${SLEPC_DIR}/TAGS ${SLEPC_DIR}/docs ${SLEPC_DIR}/src/ ${SLEPC_DIR}/**/obj/ ${SLEPC_DIR}/**/test/ && \ rm -rf /tmp/* @@ -266,7 +265,7 @@ RUN pip3 install --upgrade --no-cache-dir jupyter jupyterlab jupytext jupyter-bo # pyvista dependencies from apt RUN apt-get -qq update && \ - apt-get -y install libgl1-mesa-dev xvfb && \ + apt-get -y install libgl1-mesa-dri libgl1-mesa-dev xvfb && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* @@ -275,12 +274,10 @@ RUN apt-get -qq update && \ # ipygany and pythreejs makes plotting in notebooks interactive RUN dpkgArch="$(dpkg --print-architecture)"; \ case "$dpkgArch" in amd64) \ - # pip3 install --no-cache-dir pyvista==${PYVISTA_VERSION} ;; \ pip3 install --find-links https://wheels.pyvista.org/ pyvista ;; \ esac; \ - pip3 install --no-cache-dir matplotlib ipygany pythreejs + pip3 install --no-cache-dir matplotlib trame trame-vtk trame-vuetify -RUN jupyter nbextension enable --py --sys-prefix ipygany WORKDIR /root diff --git a/tutorials/fem/fenicsx-helmholtz-tutorial.ipynb b/tutorials/fem/fenicsx-helmholtz-tutorial.ipynb index a977694..a393091 100644 --- a/tutorials/fem/fenicsx-helmholtz-tutorial.ipynb +++ b/tutorials/fem/fenicsx-helmholtz-tutorial.ipynb @@ -507,7 +507,7 @@ "g_rig = dolfinx.fem.Constant(mesh, PETSc.ScalarType(0))\n", "\n", "# The flux is this for the active walls\n", - "g_in = dolfinx.fem.Constant(mesh, 1j * omega * rho * w)" + "g_in = dolfinx.fem.Constant(mesh, PETSc.ScalarType(1j * omega * rho * w))" ] }, { @@ -591,64 +591,26 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "id": "2afacc02", "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: pythreejs in /usr/local/lib/python3.10/dist-packages (2.4.2)\n", - "Requirement already satisfied: ipywidgets>=7.2.1 in /usr/local/lib/python3.10/dist-packages (from pythreejs) (8.1.1)\n", - "Requirement already satisfied: ipydatawidgets>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from pythreejs) (4.3.5)\n", - "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from pythreejs) (1.23.2)\n", - "Requirement already satisfied: traitlets in /usr/local/lib/python3.10/dist-packages (from pythreejs) (5.11.2)\n", - "Requirement already satisfied: traittypes>=0.2.0 in /usr/local/lib/python3.10/dist-packages (from ipydatawidgets>=1.1.1->pythreejs) (0.2.1)\n", - "Requirement already satisfied: comm>=0.1.3 in /usr/local/lib/python3.10/dist-packages (from ipywidgets>=7.2.1->pythreejs) (0.2.0)\n", - "Requirement already satisfied: ipython>=6.1.0 in /usr/local/lib/python3.10/dist-packages (from ipywidgets>=7.2.1->pythreejs) (8.17.2)\n", - "Requirement already satisfied: widgetsnbextension~=4.0.9 in /usr/local/lib/python3.10/dist-packages (from ipywidgets>=7.2.1->pythreejs) (4.0.9)\n", - "Requirement already satisfied: jupyterlab-widgets~=3.0.9 in /usr/local/lib/python3.10/dist-packages (from ipywidgets>=7.2.1->pythreejs) (3.0.9)\n", - "Requirement already satisfied: decorator in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (5.1.1)\n", - "Requirement already satisfied: jedi>=0.16 in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.19.1)\n", - "Requirement already satisfied: matplotlib-inline in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.1.6)\n", - "Requirement already satisfied: prompt-toolkit!=3.0.37,<3.1.0,>=3.0.30 in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (3.0.41)\n", - "Requirement already satisfied: pygments>=2.4.0 in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (2.16.1)\n", - "Requirement already satisfied: stack-data in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.6.3)\n", - "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (1.1.3)\n", - "Requirement already satisfied: pexpect>4.3 in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (4.8.0)\n", - "Requirement already satisfied: parso<0.9.0,>=0.8.3 in /usr/local/lib/python3.10/dist-packages (from jedi>=0.16->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.8.3)\n", - "Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.10/dist-packages (from pexpect>4.3->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.7.0)\n", - "Requirement already satisfied: wcwidth in /usr/local/lib/python3.10/dist-packages (from prompt-toolkit!=3.0.37,<3.1.0,>=3.0.30->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.2.10)\n", - "Requirement already satisfied: executing>=1.2.0 in /usr/local/lib/python3.10/dist-packages (from stack-data->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (2.0.1)\n", - "Requirement already satisfied: asttokens>=2.1.0 in /usr/local/lib/python3.10/dist-packages (from stack-data->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (2.4.1)\n", - "Requirement already satisfied: pure-eval in /usr/local/lib/python3.10/dist-packages (from stack-data->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (0.2.2)\n", - "Requirement already satisfied: six>=1.12.0 in /usr/local/lib/python3.10/dist-packages (from asttokens>=2.1.0->stack-data->ipython>=6.1.0->ipywidgets>=7.2.1->pythreejs) (1.16.0)\n", - "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n", - "\u001b[0m\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.2.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n", - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3 -m pip install --upgrade pip\u001b[0m\n" - ] - }, - { - "ename": "ValueError", - "evalue": "Invalid Jupyter notebook plotting backend \"pythreejs\".\nUse one of the following:\n\"static\", \"client\", \"server\", \"trame\", \"none\"", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[18], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m get_ipython()\u001b[38;5;241m.\u001b[39msystem(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mpip install pythreejs\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m----> 2\u001b[0m \u001b[43mpyvista\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mset_jupyter_backend\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mpythreejs\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3\u001b[0m p_mesh \u001b[38;5;241m=\u001b[39m pyvista\u001b[38;5;241m.\u001b[39mUnstructuredGrid(\u001b[38;5;241m*\u001b[39mdolfinx\u001b[38;5;241m.\u001b[39mplot\u001b[38;5;241m.\u001b[39mcreate_vtk_mesh(mesh, mesh\u001b[38;5;241m.\u001b[39mtopology\u001b[38;5;241m.\u001b[39mdim))\n\u001b[1;32m 4\u001b[0m pyvista_cells, cell_types, geometry \u001b[38;5;241m=\u001b[39m dolfinx\u001b[38;5;241m.\u001b[39mplot\u001b[38;5;241m.\u001b[39mcreate_vtk_mesh(V)\n", - "File \u001b[0;32m/usr/local/lib/python3.10/dist-packages/pyvista/jupyter/__init__.py:107\u001b[0m, in \u001b[0;36mset_jupyter_backend\u001b[0;34m(backend, name, **kwargs)\u001b[0m\n\u001b[1;32m 52\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mset_jupyter_backend\u001b[39m(backend, name\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 53\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Set the plotting backend for a jupyter notebook.\u001b[39;00m\n\u001b[1;32m 54\u001b[0m \n\u001b[1;32m 55\u001b[0m \u001b[38;5;124;03m Parameters\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 105\u001b[0m \n\u001b[1;32m 106\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 107\u001b[0m pyvista\u001b[38;5;241m.\u001b[39mglobal_theme\u001b[38;5;241m.\u001b[39m_jupyter_backend \u001b[38;5;241m=\u001b[39m \u001b[43m_validate_jupyter_backend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mbackend\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 108\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m backend \u001b[38;5;129;01min\u001b[39;00m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mserver\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mclient\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtrame\u001b[39m\u001b[38;5;124m'\u001b[39m]:\n\u001b[1;32m 109\u001b[0m \u001b[38;5;66;03m# Launch the trame server\u001b[39;00m\n\u001b[1;32m 110\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpyvista\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtrame\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mjupyter\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m elegantly_launch\n", - "File \u001b[0;32m/usr/local/lib/python3.10/dist-packages/pyvista/jupyter/__init__.py:36\u001b[0m, in \u001b[0;36m_validate_jupyter_backend\u001b[0;34m(backend)\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m backend \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m ALLOWED_BACKENDS:\n\u001b[1;32m 35\u001b[0m backend_list_str \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m, \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mjoin([\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mitem\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m ALLOWED_BACKENDS])\n\u001b[0;32m---> 36\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 37\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mInvalid Jupyter notebook plotting backend \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mbackend\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 38\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mUse one of the following:\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00mbackend_list_str\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 39\u001b[0m )\n\u001b[1;32m 41\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m backend \u001b[38;5;129;01min\u001b[39;00m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mserver\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mclient\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtrame\u001b[39m\u001b[38;5;124m'\u001b[39m]:\n\u001b[1;32m 42\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n", - "\u001b[0;31mValueError\u001b[0m: Invalid Jupyter notebook plotting backend \"pythreejs\".\nUse one of the following:\n\"static\", \"client\", \"server\", \"trame\", \"none\"" - ] + "data": { + "text/plain": [ + "(,\n", + " pyvista_ndarray([0., 0., 0., ..., 0., 0., 0.], dtype=float32))" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "!pip install pythreejs\n", - "pyvista.set_jupyter_backend(\"pythreejs\")\n", - "p_mesh = pyvista.UnstructuredGrid(*dolfinx.plot.create_vtk_mesh(mesh, mesh.topology.dim))\n", - "pyvista_cells, cell_types, geometry = dolfinx.plot.create_vtk_mesh(V)\n", + "pyvista.set_jupyter_backend(\"html\")\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", "grid = pyvista.UnstructuredGrid(pyvista_cells, cell_types, geometry)\n", "grid.point_data[\"u_real\"] = uh.x.array.real\n", "grid.point_data[\"u_imag\"] = uh.x.array.imag\n", @@ -657,20 +619,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "id": "da6bfa83", "metadata": {}, "outputs": [], "source": [ "p_real = pyvista.Plotter()\n", - "p_real.add_text(\"uh real\", position=\"upper_edge\", font_size=14, color=\"black\")\n", - "p_real.add_mesh(grid, show_edges=True, style=\"points\", point_size=25)\n", - "p_real.add_mesh(p_mesh, show_edges=True, style=\"wireframe\")\n", - "if not pyvista.OFF_SCREEN:\n", - " p_real.show()\n", + "#p_real.add_text(\"uh real\", position=\"upper_edge\", font_size=14, color=\"black\")\n", + "#p_real.add_mesh(grid, show_edges=True, style=\"points\", point_size=25)\n", + "#p_real.add_mesh(p_mesh, show_edges=True, style=\"wireframe\")\n", + "#if not pyvista.OFF_SCREEN:\n", + "# p_real.show()\n", "\n", - "with dolfinx.io.VTXWriter(mesh.comm, \"output.bp\", [uh]) as vtx:\n", - " vtx.write(0.0)" + "#with dolfinx.io.VTXWriter(mesh.comm, \"output.bp\", [uh]) as vtx:\n", + "# vtx.write(0.0)" ] }, { @@ -680,30 +642,18 @@ "metadata": {}, "outputs": [ { - "name": "stderr", - "output_type": "stream", - "text": [ - "WARNING:py.warnings:/usr/local/lib/python3.10/dist-packages/pyvista/plotting/plotter.py:149: UserWarning: \n", - "This system does not appear to be running an xserver.\n", - "PyVista will likely segfault when rendering.\n", - "\n", - "Try starting a virtual frame buffer with xvfb, or using\n", - " ``pyvista.start_xvfb()``\n", - "\n", - " warnings.warn(\n", - "\n" - ] - }, - { - "ename": "NameError", - "evalue": "name 'grid' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[19], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m p_imag \u001b[38;5;241m=\u001b[39m pyvista\u001b[38;5;241m.\u001b[39mPlotter()\n\u001b[0;32m----> 3\u001b[0m \u001b[43mgrid\u001b[49m\u001b[38;5;241m.\u001b[39mset_active_scalars(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mu_imag\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 4\u001b[0m p_imag\u001b[38;5;241m.\u001b[39madd_mesh(p_mesh, show_edges\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m, style\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mwireframe\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 5\u001b[0m p_imag\u001b[38;5;241m.\u001b[39madd_text(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muh imag\u001b[39m\u001b[38;5;124m\"\u001b[39m, position\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mupper_edge\u001b[39m\u001b[38;5;124m\"\u001b[39m, font_size\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m14\u001b[39m, color\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mblack\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", - "\u001b[0;31mNameError\u001b[0m: name 'grid' is not defined" - ] + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f06044cc451248879d44c4d201d77760", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "EmbeddableWidget(value='