Skip to content

Commit

Permalink
Update to work with latest FEniCSx (#200)
Browse files Browse the repository at this point in the history
* Fix bounding box tree

* comment

* update test

* Add weekly test against FEniCSx v0.6

* }

* actually set the tags

* -release

* Support FEniCSx 0.6.0

* don't test released on each push
  • Loading branch information
mscroggs committed Jul 21, 2023
1 parent c96f0bf commit 5e69d6c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 17 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/weekly-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Run tests with FEniCSx releases

on:
schedule:
- cron: "0 7 * * 1"

jobs:
build-and-publish-docker-fenicsx-release:
name: Build testing docker image with FEniCSx release
runs-on: ubuntu-latest
strategy:
matrix:
fenics-version: [ "v0.6.0", "main" ]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push testing Docker image with FEniCSx ${{ matrix.fenics-version }}
uses: docker/build-push-action@v2
with:
push: true
tags: bempp/cl-dev-env-with-dolfinx:main-fenicsx-${{ matrix.fenics-version }}
target: bempp-dev-env-with-dolfinx
build-args: |
FENICSX_BASIX_TAG=${{ matrix.fenics-version }}
FENICSX_FFCX_TAG=${{ matrix.fenics-version }}
FENICSX_DOLFINX_TAG=${{ matrix.fenics-version }}
build-and-test-with-fenicsx-release:
name: Build Bempp and run tests with FEniCSx release
needs:
- build-and-publish-docker-fenicsx-release
strategy:
matrix:
fenics-version: [ "v0.6.0", "main" ]
runs-on: ubuntu-latest
container: bempp/cl-dev-env-with-dolfinx:main-fenicsx-${{ matrix.fenics-version }}
steps:
- uses: actions/checkout@v2
- run: python3 setup.py install
name: Install Bempp
- run: python3 -m pytest -n4 --durations=50 test/unit --has-dolfin 0 --has-dolfinx 1 --has-exafmm 1
name: Run Bempp unit tests
8 changes: 5 additions & 3 deletions bempp/api/external/fenicsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ def p1_trace(fenics_space):
dof_to_vertex_map = np.zeros(num_fenics_vertices, dtype=np.int64)
tets = fenics_mesh.geometry.dofmap

try:
# Support older versions of FEniCSx
if hasattr(tets, "get_links"):
ntets = tets.num_nodes
tets = [tets.get_links(i) for i in range(ntets)]
except AttributeError:
pass
if hasattr(tets, "links"):
ntets = tets.num_nodes
tets = [tets.links(i) for i in range(ntets)]

for tet, cell_verts in enumerate(tets):
cell_dofs = fenics_space.dofmap.cell_dofs(tet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,11 @@
"plot_me[bem_x] -= slp_pot.evaluate(neumann_fun).flat\n",
"\n",
"fem_points = points[:, np.logical_not(bem_x)].transpose()\n",
"tree = dolfinx.geometry.BoundingBoxTree(mesh, 3)\n",
"try:\n",
" # Compatibility with older versions of DOLFINx\n",
" tree = dolfinx.geometry.BoundingBoxTree(mesh, 3)\n",
"except TypeError:\n",
" tree = dolfinx.geometry.bb_tree(mesh, 3)\n",
"midpoint_tree = dolfinx.geometry.create_midpoint_tree(\n",
" mesh, 3, list(range(mesh.topology.connectivity(3, 0).num_nodes))\n",
")\n",
Expand Down
24 changes: 11 additions & 13 deletions test/unit/external/test_fenicsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,39 @@ def test_p1_trace(has_dolfinx):
"""Test the trace of a P1 DOLFINx function."""
try:
from mpi4py import MPI
from dolfinx.geometry import (
BoundingBoxTree,
create_midpoint_tree,
compute_closest_entity,
)
from dolfinx.fem import FunctionSpace, Function
from dolfinx.mesh import create_unit_cube
import dolfinx
except ImportError:
if has_dolfinx:
raise ImportError("DOLFINx is not installed")
pytest.skip("DOLFINx must be installed to run this test")

fenics_mesh = create_unit_cube(MPI.COMM_WORLD, 2, 2, 2)
fenics_space = FunctionSpace(fenics_mesh, ("CG", 1))
fenics_mesh = dolfinx.mesh.create_unit_cube(MPI.COMM_WORLD, 2, 2, 2)
fenics_space = dolfinx.fem.FunctionSpace(fenics_mesh, ("CG", 1))

bempp_space, trace_matrix = fenics_to_bempp_trace_data(fenics_space)

fenics_coeffs = np.random.rand(fenics_space.dofmap.index_map.size_global)
bempp_coeffs = trace_matrix @ fenics_coeffs

fenics_fun = Function(fenics_space)
fenics_fun = dolfinx.fem.Function(fenics_space)
fenics_fun.vector[:] = fenics_coeffs
bempp_fun = bempp.api.GridFunction(bempp_space, coefficients=bempp_coeffs)

tree = BoundingBoxTree(fenics_mesh, 3)
try:
tree = dolfinx.geometry.bb_tree(fenics_mesh, 3)
except AttributeError:
# Support older FEniCSx
tree = dolfinx.geometry.BoundingBoxTree(fenics_mesh, 3)

midpoint_tree = create_midpoint_tree(
midpoint_tree = dolfinx.geometry.create_midpoint_tree(
fenics_mesh, 3, list(range(fenics_mesh.topology.connectivity(3, 0).num_nodes))
)

for cell in bempp_space.grid.entity_iterator(0):
mid = cell.geometry.centroid
bempp_val = bempp_fun.evaluate(cell.index, np.array([[1 / 3], [1 / 3]]))

fenics_cell = compute_closest_entity(tree, midpoint_tree, fenics_mesh, mid)[0]
fenics_cell = dolfinx.geometry.compute_closest_entity(tree, midpoint_tree, fenics_mesh, mid)[0]
fenics_val = fenics_fun.eval([mid.T], [fenics_cell])
assert np.isclose(bempp_val[0, 0], fenics_val[0])

Expand Down

0 comments on commit 5e69d6c

Please sign in to comment.