Skip to content

Commit

Permalink
Merge pull request #46 from jorgensd/dokken/pre-08-release
Browse files Browse the repository at this point in the history
Update workflows and add dependabot
  • Loading branch information
jorgensd authored Oct 27, 2024
2 parents 791598c + 12f285e commit 6f2c7d3
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 118 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
2 changes: 1 addition & 1 deletion .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
build-docs:
uses: ./.github/workflows/test-build.yml
with:
tag: "stable"
tag: "v0.8.0"

deploy:
needs: [build-docs]
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@ on:
inputs:
tag:
description: "Tag of DOLFINx docker image"
default: "stable"
default: "v0.8.0"
required: true
type: string
workflow_dispatch:
inputs:
tag:
description: "Tag of DOLFINx docker image"
default: "stable"
default: "v0.8.0"
required: true
type: string
schedule:
- cron: "* 9 * * 1"

env:
DEFAULT_TAG: stable

DEFAULT_TAG: v0.8.0
jobs:
get_image_tag:
runs-on: ubuntu-latest
Expand All @@ -53,8 +52,13 @@ jobs:
python3 -m pip install --upgrade pip
python3 -m pip install -e .[dev] -U
- name: flake8 checks
run: flake8-nb *.ipynb
- name: Ruff formatting checks
run: |
ruff format .
ruff check .
- name: Run mypy
run: python3 -m mypy .

- name: Test building the book
run: jupyter-book build . --all
Expand Down
4 changes: 0 additions & 4 deletions access.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,3 @@ The BibTeX for this citation is:
NOTE = {[Online; accessed 22-August-2022]}
}
```

## Contents
```{tableofcontents}
```
124 changes: 82 additions & 42 deletions comparing_elements.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@
},
"outputs": [],
"source": [
"from dolfinx import fem, mesh\n",
"import dolfinx.fem.petsc\n",
"from mpi4py import MPI\n",
"from petsc4py import PETSc\n",
"\n",
"import basix.ufl\n",
"import matplotlib.pylab as plt\n",
"import numpy as np"
"import numpy as np\n",
"\n",
"import basix.ufl\n",
"import dolfinx.fem.petsc\n",
"from dolfinx import fem, mesh"
]
},
{
Expand Down Expand Up @@ -130,8 +131,19 @@
},
"outputs": [],
"source": [
"from ufl import (SpatialCoordinate, TrialFunction, TestFunction,\n",
" as_vector, cos, sin, inner, div, grad, dx, pi)"
"from ufl import (\n",
" SpatialCoordinate,\n",
" TestFunction,\n",
" TrialFunction,\n",
" as_vector,\n",
" cos,\n",
" div,\n",
" dx,\n",
" grad,\n",
" inner,\n",
" pi,\n",
" sin,\n",
")"
]
},
{
Expand Down Expand Up @@ -173,7 +185,8 @@
" cosx = cos(pi * x[0])\n",
" cosy = cos(pi * x[1])\n",
" c_factor = 2 * pi * sinx * siny\n",
" return c_factor * as_vector((cosy * sinx, - cosx * siny))\n",
" return c_factor * as_vector((cosy * sinx, -cosx * siny))\n",
"\n",
"\n",
"def p_ex(x):\n",
" return sin(2 * pi * x[0]) * sin(2 * pi * x[1])"
Expand Down Expand Up @@ -208,7 +221,7 @@
"source": [
"def source(x):\n",
" u, p = u_ex(x), p_ex(x)\n",
" return - div(grad(u)) + grad(p)"
" return -div(grad(u)) + grad(p)"
]
},
{
Expand Down Expand Up @@ -291,8 +304,7 @@
" domain = V.mesh\n",
" x = SpatialCoordinate(domain)\n",
" f = source(x)\n",
" return fem.form([inner(f, v) * dx,\n",
" inner(fem.Constant(domain, 0.), q) * dx])"
" return fem.form([inner(f, v) * dx, inner(fem.Constant(domain, 0.0), q) * dx])"
]
},
{
Expand Down Expand Up @@ -322,7 +334,7 @@
"source": [
"def create_velocity_bc(V):\n",
" domain = V.mesh\n",
" g = fem.Constant(domain, [0., 0.])\n",
" g = fem.Constant(domain, [0.0, 0.0])\n",
" tdim = domain.topology.dim\n",
" domain.topology.create_connectivity(tdim - 1, tdim)\n",
" bdry_facets = mesh.exterior_facet_indices(domain.topology)\n",
Expand Down Expand Up @@ -404,8 +416,7 @@
"def create_preconditioner(Q, a, bcs):\n",
" p, q = TrialFunction(Q), TestFunction(Q)\n",
" a_p11 = fem.form(inner(p, q) * dx)\n",
" a_p = fem.form([[a[0][0], None],\n",
" [None, a_p11]])\n",
" a_p = fem.form([[a[0][0], None], [None, a_p11]])\n",
" P = dolfinx.fem.petsc.assemble_matrix_nest(a_p, bcs)\n",
" P.assemble()\n",
" return P"
Expand Down Expand Up @@ -438,8 +449,7 @@
" b = dolfinx.fem.petsc.assemble_vector_nest(rhs_form)\n",
" dolfinx.fem.petsc.apply_lifting_nest(b, lhs_form, bcs=bcs)\n",
" for b_sub in b.getNestSubVecs():\n",
" b_sub.ghostUpdate(addv=PETSc.InsertMode.ADD,\n",
" mode=PETSc.ScatterMode.REVERSE)\n",
" b_sub.ghostUpdate(addv=PETSc.InsertMode.ADD, mode=PETSc.ScatterMode.REVERSE)\n",
" spaces = fem.extract_function_spaces(rhs_form)\n",
" bcs0 = fem.bcs_by_block(spaces, bcs)\n",
" dolfinx.fem.petsc.set_bc_nest(b, bcs0)\n",
Expand Down Expand Up @@ -489,8 +499,7 @@
" ksp.getPC().setFieldSplitType(PETSc.PC.CompositeType.ADDITIVE)\n",
"\n",
" nested_IS = P.getNestISs()\n",
" ksp.getPC().setFieldSplitIS((\"u\", nested_IS[0][0]),\n",
" (\"p\", nested_IS[0][1]))\n",
" ksp.getPC().setFieldSplitIS((\"u\", nested_IS[0][0]), (\"p\", nested_IS[0][1]))\n",
"\n",
" # Set the preconditioners for each block\n",
" ksp_u, ksp_p = ksp.getPC().getFieldSplitSubKSP()\n",
Expand Down Expand Up @@ -548,6 +557,7 @@
" local_J = fem.assemble_scalar(scalar_form)\n",
" return comm.allreduce(local_J, op=MPI.SUM)\n",
"\n",
"\n",
"def compute_errors(u, p):\n",
" domain = u.function_space.mesh\n",
" x = SpatialCoordinate(domain)\n",
Expand Down Expand Up @@ -634,27 +644,33 @@
},
"outputs": [],
"source": [
"def error_plot(element_u, element_p, convergence_u=None,\n",
" convergence_p=None, refinements=5, N0=7):\n",
"def error_plot(element_u, element_p, convergence_u=None, convergence_p=None, refinements=5, N0=7):\n",
" hs = np.zeros(refinements)\n",
" u_errors = np.zeros(refinements)\n",
" p_errors = np.zeros(refinements)\n",
" comm = MPI.COMM_WORLD\n",
" for i in range(refinements):\n",
" N = N0 * 2**i\n",
" domain = mesh.create_unit_square(\n",
" comm, N, N, mesh.CellType.triangle)\n",
" domain = mesh.create_unit_square(comm, N, N, mesh.CellType.triangle)\n",
" u_errors[i], p_errors[i] = solve_stokes(element_u, element_p, domain)\n",
" hs[i] = 1. / N\n",
" hs[i] = 1.0 / N\n",
" legend = []\n",
"\n",
" if convergence_u is not None:\n",
" y_value = u_errors[-1] * 1.4\n",
" plt.plot([hs[0], hs[-1]], [y_value * (hs[0] / hs[-1])**convergence_u, y_value], \"k--\")\n",
" plt.plot(\n",
" [hs[0], hs[-1]],\n",
" [y_value * (hs[0] / hs[-1]) ** convergence_u, y_value],\n",
" \"k--\",\n",
" )\n",
" legend.append(f\"order {convergence_u}\")\n",
" if convergence_p is not None:\n",
" y_value = p_errors[-1] * 1.4\n",
" plt.plot([hs[0], hs[-1]], [y_value * (hs[0] / hs[-1])**convergence_p, y_value], \"k--\")\n",
" plt.plot(\n",
" [hs[0], hs[-1]],\n",
" [y_value * (hs[0] / hs[-1]) ** convergence_p, y_value],\n",
" \"k--\",\n",
" )\n",
" legend.append(f\"order {convergence_p}\")\n",
"\n",
" plt.plot(hs, u_errors, \"bo-\")\n",
Expand Down Expand Up @@ -745,7 +761,7 @@
}
],
"source": [
"element_u = basix.ufl.element(\"Lagrange\", \"triangle\", 1, shape=(2, ))\n",
"element_u = basix.ufl.element(\"Lagrange\", \"triangle\", 1, shape=(2,))\n",
"element_p = basix.ufl.element(\"DG\", \"triangle\", 0)\n",
"error_plot(element_u, element_p)"
]
Expand Down Expand Up @@ -813,7 +829,7 @@
}
],
"source": [
"element_u = basix.ufl.element(\"Lagrange\", \"triangle\", 2, shape=(2, ))\n",
"element_u = basix.ufl.element(\"Lagrange\", \"triangle\", 2, shape=(2,))\n",
"element_p = basix.ufl.element(\"DG\", \"triangle\", 0)\n",
"error_plot(element_u, element_p, convergence_p=1)"
]
Expand Down Expand Up @@ -870,7 +886,7 @@
}
],
"source": [
"element_u = basix.ufl.element(\"CR\", \"triangle\", 1, shape=(2, ))\n",
"element_u = basix.ufl.element(\"CR\", \"triangle\", 1, shape=(2,))\n",
"element_p = basix.ufl.element(\"DG\", \"triangle\", 0)\n",
"error_plot(element_u, element_p, 1)"
]
Expand Down Expand Up @@ -928,9 +944,12 @@
],
"source": [
"enriched_element = basix.ufl.enriched_element(\n",
" [basix.ufl.element(\"Lagrange\", \"triangle\", 2),\n",
" basix.ufl.element(\"Bubble\", \"triangle\", 3)])\n",
"element_u = basix.ufl.blocked_element(enriched_element, shape=(2, ))\n",
" [\n",
" basix.ufl.element(\"Lagrange\", \"triangle\", 2),\n",
" basix.ufl.element(\"Bubble\", \"triangle\", 3),\n",
" ]\n",
")\n",
"element_u = basix.ufl.blocked_element(enriched_element, shape=(2,))\n",
"element_p = basix.ufl.element(\"DG\", \"triangle\", 1)\n",
"error_plot(element_u, element_p, 2)"
]
Expand Down Expand Up @@ -989,7 +1008,7 @@
}
],
"source": [
"element_u = basix.ufl.element(\"Lagrange\", \"triangle\", 3, shape=(2, ))\n",
"element_u = basix.ufl.element(\"Lagrange\", \"triangle\", 3, shape=(2,))\n",
"element_p = basix.ufl.element(\"Lagrange\", \"triangle\", 2)\n",
"error_plot(element_u, element_p, 3)"
]
Expand Down Expand Up @@ -1095,11 +1114,22 @@
"poly = basix.tabulate_polynomials(basix.PolynomialType.legendre, basix.CellType.triangle, 4, pts)\n",
"x = pts[:, 0]\n",
"y = pts[:, 1]\n",
"for j, f in enumerate([\n",
" 1, x, y, x ** 2 * y, x * y ** 2, (1 - x - y) ** 2 * y, (1 - x - y) * y ** 2,\n",
" x ** 2 * (1 - x - y), x * (1 - x - y) ** 2,\n",
" x * y * (1 - x - y), x ** 2 * y * (1 - x - y), x * y ** 2 * (1 - x - y)\n",
"]):\n",
"for j, f in enumerate(\n",
" [\n",
" 1,\n",
" x,\n",
" y,\n",
" x**2 * y,\n",
" x * y**2,\n",
" (1 - x - y) ** 2 * y,\n",
" (1 - x - y) * y**2,\n",
" x**2 * (1 - x - y),\n",
" x * (1 - x - y) ** 2,\n",
" x * y * (1 - x - y),\n",
" x**2 * y * (1 - x - y),\n",
" x * y**2 * (1 - x - y),\n",
" ]\n",
"):\n",
" for i in range(15):\n",
" wcoeffs[j, i] = sum(f * poly[i, :] * wts)"
]
Expand Down Expand Up @@ -1142,10 +1172,10 @@
"\n",
"M = [[], [], [], []]\n",
"for _ in range(3):\n",
" M[0].append(np.array([[[[1.]]]]))\n",
" M[0].append(np.array([[[[1.0]]]]))\n",
"for _ in range(3):\n",
" M[1].append(np.array([[[[1.], [0.]]], [[[0.], [1.]]]]))\n",
"M[2].append(np.array([[[[1.], [0.], [0.]]], [[[0.], [1.], [0.]]], [[[0.], [0.], [1.]]]]))"
" M[1].append(np.array([[[[1.0], [0.0]]], [[[0.0], [1.0]]]]))\n",
"M[2].append(np.array([[[[1.0], [0.0], [0.0]]], [[[0.0], [1.0], [0.0]]], [[[0.0], [0.0], [1.0]]]]))"
]
},
{
Expand Down Expand Up @@ -1187,10 +1217,20 @@
],
"source": [
"p3_plus_bubbles = basix.ufl.custom_element(\n",
" basix.CellType.triangle, [], wcoeffs, x, M, 0, basix.MapType.identity,\n",
" basix.SobolevSpace.H1, False, 3, 4)\n",
" basix.CellType.triangle,\n",
" [],\n",
" wcoeffs,\n",
" x,\n",
" M,\n",
" 0,\n",
" basix.MapType.identity,\n",
" basix.SobolevSpace.H1,\n",
" False,\n",
" 3,\n",
" 4,\n",
")\n",
"\n",
"element_u = basix.ufl.blocked_element(p3_plus_bubbles, shape=(2, ))\n",
"element_u = basix.ufl.blocked_element(p3_plus_bubbles, shape=(2,))\n",
"element_p = basix.ufl.element(\"DG\", \"triangle\", 2)\n",
"error_plot(element_u, element_p, 3, refinements=4)"
]
Expand Down
17 changes: 12 additions & 5 deletions example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@
],
"source": [
"import dolfinx\n",
"print(f\"You have DOLFINx {dolfinx.__version__} installed, \"\n",
" \"based on commit \\nhttps://github.com/FEniCS/dolfinx/commit/\"\n",
" f\"{dolfinx.common.git_commit_hash}\")"
"\n",
"print(\n",
" f\"You have DOLFINx {dolfinx.__version__} installed, \"\n",
" \"based on commit \\nhttps://github.com/FEniCS/dolfinx/commit/\"\n",
" f\"{dolfinx.common.git_commit_hash}\"\n",
")"
]
},
{
Expand Down Expand Up @@ -106,8 +109,10 @@
},
"outputs": [],
"source": [
"import dolfinx\n",
"from mpi4py import MPI\n",
"\n",
"import dolfinx\n",
"\n",
"mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)"
]
},
Expand Down Expand Up @@ -141,8 +146,10 @@
"metadata": {},
"outputs": [],
"source": [
"import dolfinx.plot\n",
"import pyvista\n",
"\n",
"import dolfinx.plot\n",
"\n",
"topology, cells, geometry = dolfinx.plot.vtk_mesh(mesh)\n",
"grid = pyvista.UnstructuredGrid(topology, cells, geometry)"
]
Expand Down
Loading

0 comments on commit 6f2c7d3

Please sign in to comment.