From 7986ada58a6c65d676eda31c7260b6239fea7193 Mon Sep 17 00:00:00 2001 From: Justin Laughlin Date: Mon, 9 Sep 2024 10:58:52 -0700 Subject: [PATCH 1/6] remove binder/ --- binder/postBuild | 3 --- binder/requirements.txt | 7 ------- 2 files changed, 10 deletions(-) delete mode 100644 binder/postBuild delete mode 100644 binder/requirements.txt 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 From 5c29df2556565aec9c861076f99c8270809d805f Mon Sep 17 00:00:00 2001 From: Justin Laughlin Date: Mon, 9 Sep 2024 10:59:56 -0700 Subject: [PATCH 2/6] replace binder->colab badges --- examples/jupyter/ex1.svg | 129 ++++++++++++++++++++++++++++++- examples/jupyter/ex9.svg | 163 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 290 insertions(+), 2 deletions(-) diff --git a/examples/jupyter/ex1.svg b/examples/jupyter/ex1.svg index df9156a7..f957c5d6 100644 --- a/examples/jupyter/ex1.svg +++ b/examples/jupyter/ex1.svg @@ -1 +1,128 @@ -ex1: launch binderex1launch binder \ No newline at end of file + +Open in ColabOpen in Colabex1 diff --git a/examples/jupyter/ex9.svg b/examples/jupyter/ex9.svg index e59c7b32..34ad1d70 100644 --- a/examples/jupyter/ex9.svg +++ b/examples/jupyter/ex9.svg @@ -1 +1,162 @@ -ex9: launch binderex9launch binder \ No newline at end of file + +Open in ColabOpen in Colabex9 From f6d41b8a3a0730334933f992c6ebce7af2cf1e1b Mon Sep 17 00:00:00 2001 From: Justin Laughlin Date: Mon, 9 Sep 2024 11:15:36 -0700 Subject: [PATCH 3/6] update readme --- examples/jupyter/{ => .assets}/ex1.svg | 0 examples/jupyter/{ => .assets}/ex9.svg | 0 examples/jupyter/README.md | 5 +++-- 3 files changed, 3 insertions(+), 2 deletions(-) rename examples/jupyter/{ => .assets}/ex1.svg (100%) rename examples/jupyter/{ => .assets}/ex9.svg (100%) diff --git a/examples/jupyter/ex1.svg b/examples/jupyter/.assets/ex1.svg similarity index 100% rename from examples/jupyter/ex1.svg rename to examples/jupyter/.assets/ex1.svg diff --git a/examples/jupyter/ex9.svg b/examples/jupyter/.assets/ex9.svg similarity index 100% rename from examples/jupyter/ex9.svg rename to examples/jupyter/.assets/ex9.svg diff --git a/examples/jupyter/README.md b/examples/jupyter/README.md index 02ff689d..a3b75350 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/update-notebooks/examples/jupyter/ex1.ipynb) +[![badge](.assets/ex9.svg)](https://colab.research.google.com/github/mfem/PyMFEM/blob/update-notebooks/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). From 5f96f272fbcf46681d54fd879365c14d76a9ecb5 Mon Sep 17 00:00:00 2001 From: Justin Laughlin Date: Mon, 9 Sep 2024 11:49:29 -0700 Subject: [PATCH 4/6] update notebooks --- examples/jupyter/ex1.ipynb | 98 +++++++++++++++++++++++++++++++------- examples/jupyter/ex9.ipynb | 67 ++++++++++++++++---------- 2 files changed, 124 insertions(+), 41 deletions(-) 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/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, From 9c8cb91d72b8ded0fa09cf43f5fa350d204d62fe Mon Sep 17 00:00:00 2001 From: Justin Laughlin Date: Mon, 9 Sep 2024 11:52:27 -0700 Subject: [PATCH 5/6] update readmes --- README.md | 5 ++--- examples/jupyter/README.md | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fe880655..55a0b903 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) diff --git a/examples/jupyter/README.md b/examples/jupyter/README.md index a3b75350..e7dea545 100644 --- a/examples/jupyter/README.md +++ b/examples/jupyter/README.md @@ -1,7 +1,7 @@ # Jupyter Versions of the Examples -[![badge](.assets/ex1.svg)](https://colab.research.google.com/github/mfem/PyMFEM/blob/update-notebooks/examples/jupyter/ex1.ipynb) -[![badge](.assets/ex9.svg)](https://colab.research.google.com/github/mfem/PyMFEM/blob/update-notebooks/examples/jupyter/ex9.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). From 000a0632961752e447421a678be0ef63aa574e7c Mon Sep 17 00:00:00 2001 From: Justin Laughlin Date: Mon, 9 Sep 2024 11:58:55 -0700 Subject: [PATCH 6/6] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 55a0b903..e01706c6 100644 --- a/README.md +++ b/README.md @@ -56,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