diff --git a/README.md b/README.md
index fe880655..e01706c6 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,5 @@
-[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/mfem/PyMFEM/HEAD?labpath=examples%2Fjupyter)
-[![badge](examples/jupyter/ex1.svg)](https://mybinder.org/v2/gh/mfem/PyMFEM/HEAD?labpath=examples%2Fjupyter%2Fex1.ipynb)
-[![badge](examples/jupyter/ex9.svg)](https://mybinder.org/v2/gh/mfem/PyMFEM/HEAD?labpath=examples%2Fjupyter%2Fex9.ipynb)
+[![badge](examples/jupyter/.assets/ex1.svg)](https://colab.research.google.com/github/mfem/pymfem/blob/main/examples/jupyter/ex1.ipynb)
+[![badge](examples/jupyter/.assets/ex9.svg)](https://colab.research.google.com/github/mfem/pymfem/blob/main/examples/jupyter/ex9.ipynb)
# MFEM + PyMFEM (FEM library)
@@ -57,7 +56,7 @@ $ python setup.py install --help
This example (modified from `ex1.cpp`) solves the Poisson equation,
$$\nabla \cdot (\alpha \nabla u) = f$$
in a square and plots the result using matplotlib.
-Use the badge above to open this in Binder.
+Use the badge above to open this in Colab.
```python
import mfem.ser as mfem
diff --git a/binder/postBuild b/binder/postBuild
deleted file mode 100644
index 8f7b2179..00000000
--- a/binder/postBuild
+++ /dev/null
@@ -1,3 +0,0 @@
-# install jupyter-lab extension
-jupyter labextension install @jupyter-widgets/jupyterlab-manager --no-build
-jupyter labextension install glvis-jupyter
diff --git a/binder/requirements.txt b/binder/requirements.txt
deleted file mode 100644
index 93aa10ae..00000000
--- a/binder/requirements.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-numpy>=1.19.4; python_version<"3.7"
-numpy>=1.20.0; python_version>="3.7"
-scipy>=1.5.2
-six>1.13.0
-matplotlib
-mfem==4.3.0.5
-glvis>=0.3.2
diff --git a/examples/jupyter/.assets/ex1.svg b/examples/jupyter/.assets/ex1.svg
new file mode 100644
index 00000000..f957c5d6
--- /dev/null
+++ b/examples/jupyter/.assets/ex1.svg
@@ -0,0 +1,128 @@
+
+
diff --git a/examples/jupyter/.assets/ex9.svg b/examples/jupyter/.assets/ex9.svg
new file mode 100644
index 00000000..34ad1d70
--- /dev/null
+++ b/examples/jupyter/.assets/ex9.svg
@@ -0,0 +1,162 @@
+
+Open in ColabOpen in Colabex9
diff --git a/examples/jupyter/README.md b/examples/jupyter/README.md
index 02ff689d..e7dea545 100644
--- a/examples/jupyter/README.md
+++ b/examples/jupyter/README.md
@@ -1,7 +1,8 @@
# Jupyter Versions of the Examples
-[![badge](ex1.svg)](https://mybinder.org/v2/gh/mfem/PyMFEM/HEAD?labpath=examples%2Fjupyter%2Fex1.ipynb)
-[![badge](ex9.svg)](https://mybinder.org/v2/gh/mfem/PyMFEM/HEAD?labpath=examples%2Fjupyter%2Fex9.ipynb)
+[![badge](.assets/ex1.svg)](https://colab.research.google.com/github/mfem/pymfem/blob/main/examples/jupyter/ex1.ipynb)
+[![badge](.assets/ex9.svg)](https://colab.research.google.com/github/mfem/pymfem/blob/main/examples/jupyter/ex9.ipynb)
+
This directory contains [Jupyter](https://jupyter.org/) versions of some of the PyMFEM examples with inline visualization using [pyglvis](https://github.com/GLVis/pyglvis).
diff --git a/examples/jupyter/ex1.ipynb b/examples/jupyter/ex1.ipynb
index 7ee5ddcd..6d01f832 100644
--- a/examples/jupyter/ex1.ipynb
+++ b/examples/jupyter/ex1.ipynb
@@ -4,32 +4,95 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "## MFEM Example 1\n",
+ "## Imports"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Pip installs pyglvis (and pymfem) if in a colab notebook. Can comment out if not required\n",
+ "!pip install --quiet glvis\n",
+ "from glvis import glvis, GlvisData"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Visualizing from stream"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Load a remote data stream\n",
+ "stream = GlvisData.ex9\n",
+ "# Visualize the above stream (all GLVis keys and mouse commands work)\n",
+ "glvis(stream, 300, 300)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Another visualization instance of the same stream\n",
+ "glvis(stream, 300, 300, keys='rljg****ttta0')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Load in another stream (press Q to cycle between quadrature representations)\n",
+ "glvis(GlvisData.quadrature_lor, keys=\"gcQ/////////\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Solving and visualizing the Laplace equation"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "tags": []
+ },
+ "source": [
+ "### MFEM Example 1\n",
"\n",
- "Adapted from [PyMFEM/ex1.py]( https://github.com/mfem/PyMFEM/blob/master/examples/ex1.py).\n",
+ "Adapted from [PyMFEM/ex1.py](https://github.com/mfem/PyMFEM/blob/master/examples/ex1.py).\n",
"Compare with the [original Example 1](https://github.com/mfem/mfem/blob/master/examples/ex1.cpp) in MFEM.\n",
"\n",
"This example code demonstrates the use of MFEM to define a simple finite element discretization of the Laplace problem\n",
"\n",
"\\begin{equation*}\n",
"-\\Delta x = 1\n",
- "\\label{laplace}\\tag{1}\n",
"\\end{equation*}\n",
"\n",
"in a domain $\\Omega$ with homogeneous Dirichlet boundary conditions\n",
"\n",
"\\begin{equation*}\n",
"x = 0\n",
- "\\label{laplace2}\\tag{2}\n",
"\\end{equation*}\n",
"\n",
"on the boundary $\\partial \\Omega$.\n",
"\n",
- "The problme is discretized on a computational mesh in either 2D or 3D using a finite elements space of the specified order (2 by default) resulting in the global sparse linear system\n",
+ "The problem is discretized on a computational mesh in either 2D or 3D using a finite elements space of the specified order (2 by default) resulting in the global sparse linear system\n",
"\n",
"\\begin{equation*}\n",
"A X = B.\n",
- "\\label{laplace3}\\tag{3}\n",
"\\end{equation*}\n",
"\n",
"The example highlights the use of mesh refinement, finite element grid functions, as well as linear and bilinear forms corresponding to the left-hand side and right-hand side of the\n",
@@ -39,12 +102,13 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {},
+ "metadata": {
+ "tags": []
+ },
"outputs": [],
"source": [
- "# Requires pymfem and pyglvis see https://github.com/glvis/pyglvis\n",
- "import mfem.ser as mfem\n",
- "from glvis import glvis, to_stream"
+ "# Requires PyMFEM, see https://github.com/mfem/PyMFEM\n",
+ "import mfem.ser as mfem"
]
},
{
@@ -107,11 +171,14 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {},
+ "metadata": {
+ "tags": []
+ },
"outputs": [],
"source": [
"# Plot the mesh + solution (all GLVis keys and mouse commands work)\n",
- "glvis((mesh, x), 400, 400)"
+ "g = glvis((mesh, x))\n",
+ "g"
]
},
{
@@ -131,15 +198,14 @@
"outputs": [],
"source": [
"# Visualization with additional GLVis keys\n",
- "g = glvis(to_stream(mesh,x) + 'keys ARjlmcbp*******')\n",
- "g.set_size(600, 400)\n",
+ "g = glvis((mesh,x), keys='ARjlmcbp**')\n",
"g"
]
}
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -153,7 +219,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.9.1"
+ "version": "3.10.12"
}
},
"nbformat": 4,
diff --git a/examples/jupyter/ex1.svg b/examples/jupyter/ex1.svg
deleted file mode 100644
index df9156a7..00000000
--- a/examples/jupyter/ex1.svg
+++ /dev/null
@@ -1 +0,0 @@
-ex1: launch binderex1ex1launch binderlaunch binder
\ No newline at end of file
diff --git a/examples/jupyter/ex9.ipynb b/examples/jupyter/ex9.ipynb
index f1d055ce..cfc44e28 100644
--- a/examples/jupyter/ex9.ipynb
+++ b/examples/jupyter/ex9.ipynb
@@ -31,17 +31,19 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {},
+ "metadata": {
+ "tags": []
+ },
"outputs": [],
"source": [
+ "# Pip installs pyglvis (and pymfem) if in a colab notebook. Can comment out if not required\n",
+ "!pip install --quiet glvis\n",
"from __future__ import print_function\n",
"from os.path import expanduser, join\n",
"import time\n",
"import numpy as np\n",
"from numpy import sqrt, pi, cos, sin, hypot, arctan2\n",
"from scipy.special import erfc\n",
- "\n",
- "# Requires pymfem and pyglvis see https://github.com/glvis/pyglvis\n",
"import mfem.ser as mfem\n",
"from mfem.ser import intArray\n",
"from glvis import glvis"
@@ -50,7 +52,9 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {},
+ "metadata": {
+ "tags": []
+ },
"outputs": [],
"source": [
"# 1. Setup problem parameters\n",
@@ -91,7 +95,9 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {},
+ "metadata": {
+ "tags": []
+ },
"outputs": [],
"source": [
"# 2. Download the mesh from GitHub and read it. \n",
@@ -108,7 +114,9 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {},
+ "metadata": {
+ "tags": []
+ },
"outputs": [],
"source": [
"# 3. Define the ODE solver used for time integration. \n",
@@ -126,24 +134,28 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {},
+ "metadata": {
+ "tags": []
+ },
"outputs": [],
"source": [
"# 4. Refine the mesh to increase the resolution. In this example we do\n",
- "# 'ref_levels' of uniform refinement. If the mesh is of NURBS type, \n",
+ "# 'ref_levels' of uniform refinement. If the mesh is of NURBS type,\n",
"# we convert it to a (piecewise-polynomial) high-order mesh.\n",
"\n",
"for lev in range(ref_levels):\n",
- " mesh.UniformRefinement();\n",
+ " mesh.UniformRefinement()\n",
" if mesh.NURBSext:\n",
" mesh.SetCurvature(max(order, 1))\n",
- " bb_min, bb_max = mesh.GetBoundingBox(max(order, 1));"
+ " bb_min, bb_max = mesh.GetBoundingBox(max(order, 1))"
]
},
{
"cell_type": "code",
"execution_count": null,
- "metadata": {},
+ "metadata": {
+ "tags": []
+ },
"outputs": [],
"source": [
"# 5. Define the discontinuous DG finite element space of the given\n",
@@ -220,7 +232,9 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {},
+ "metadata": {
+ "tags": []
+ },
"outputs": [],
"source": [
"# 6. Set up and assemble the bilinear and linear forms corresponding to \n",
@@ -262,43 +276,46 @@
{
"cell_type": "code",
"execution_count": null,
- "metadata": {},
+ "metadata": {
+ "tags": []
+ },
"outputs": [],
"source": [
- "g = glvis((mesh, u))\n",
- "g.show()\n",
+ "g = glvis((mesh, u), 400, 400, keys=\"Agj*****\")\n",
+ "g.render()\n",
"\n",
"class FE_Evolution(mfem.PyTimeDependentOperator):\n",
" def __init__(self, M, K, b):\n",
" mfem.PyTimeDependentOperator.__init__(self, M.Size())\n",
- " self.K = K \n",
+ " self.K = K\n",
" self.M = M\n",
" self.b = b\n",
" self.z = mfem.Vector(M.Size())\n",
" self.zp = np.zeros(M.Size())\n",
- " self.M_prec = mfem.DSmoother() \n",
+ " self.M_prec = mfem.DSmoother()\n",
" self.M_solver = mfem.CGSolver()\n",
- " self.M_solver.SetPreconditioner(self.M_prec) \n",
+ " self.M_solver.SetPreconditioner(self.M_prec)\n",
" self.M_solver.SetOperator(M)\n",
" self.M_solver.iterative_mode = False\n",
" self.M_solver.SetRelTol(1e-9)\n",
" self.M_solver.SetAbsTol(0.0)\n",
" self.M_solver.SetMaxIter(100)\n",
" self.M_solver.SetPrintLevel(0)\n",
- " \n",
+ "\n",
" def Mult(self, x, y):\n",
- " self.K.Mult(x, self.z);\n",
- " self.z += b;\n",
+ " self.K.Mult(x, self.z)\n",
+ " self.z += b\n",
" self.M_solver.Mult(self.z, y)\n",
"\n",
"adv = FE_Evolution(m.SpMat(), k.SpMat(), b)\n",
"\n",
"ode_solver.Init(adv)\n",
- "t = 0.0; ti = 0;\n",
+ "t = 0.0\n",
+ "ti = 0\n",
"time.sleep(1)\n",
"while True:\n",
" if t > t_final - dt/2: break\n",
- " t, dt = ode_solver.Step(u, t, dt);\n",
+ " t, dt = ode_solver.Step(u, t, dt)\n",
" ti = ti + 1\n",
" if ti % vis_steps == 0:\n",
" g.update((mesh, u))\n",
@@ -309,7 +326,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -323,7 +340,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.9.1"
+ "version": "3.10.12"
}
},
"nbformat": 4,
diff --git a/examples/jupyter/ex9.svg b/examples/jupyter/ex9.svg
deleted file mode 100644
index e59c7b32..00000000
--- a/examples/jupyter/ex9.svg
+++ /dev/null
@@ -1 +0,0 @@
-ex9: launch binderex9ex9launch binderlaunch binder
\ No newline at end of file