Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/transfer_tags_to_submesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import os
import sys
import pyvista
from scifem import transfer_meshtags_to_submesh
from scifem import transfer_meshtags_to_submesh, compat
from mpi4py import MPI
import gmsh
import dolfinx
Expand Down Expand Up @@ -82,7 +82,7 @@ def plot_mesh(mesh: dolfinx.mesh.Mesh, values=None):
plotter = pyvista.Plotter()
V_linear = dolfinx.fem.functionspace(mesh, ("Lagrange", 1))
linear_grid = pyvista.UnstructuredGrid(*dolfinx.plot.vtk_mesh(V_linear))
if mesh.geometry.cmap.degree > 1:
if compat.get_cmap(mesh).degree > 1:
ugrid = pyvista.UnstructuredGrid(*dolfinx.plot.vtk_mesh(mesh))
if values is not None:
ugrid.cell_data["Marker"] = values
Expand Down
11 changes: 11 additions & 0 deletions src/scifem/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Layer for small backward compatibility wrappers for DOLFINx"""

import dolfinx


def get_cmap(mesh: dolfinx.mesh.Mesh) -> dolfinx.fem.CoordinateElement:
"""Get the basix Cmap for the mesh."""
if callable(mesh.geometry.cmap):
return mesh.geometry.cmap()
else:
return mesh.geometry.cmap
8 changes: 6 additions & 2 deletions src/scifem/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import ufl
from scipy.optimize import minimize
from ufl.algorithms.signature import compute_expression_signature
from .compat import get_cmap


T = typing.TypeVar("T", int, float)
MinMaxFunc = typing.Callable[[typing.Sequence[T]], T]
Expand Down Expand Up @@ -155,6 +157,7 @@ def find_cell_extrema(
_cell = np.array([cell], dtype=np.int32)
mesh_nodes = mesh.geometry.x[mesh.geometry.dofmap[cell], : mesh.geometry.dim]
_x_p = np.zeros(3)
cmap = get_cmap(mesh)

def eval_J(x_ref):
# Evaluating basis functions through {py:func}`dolfinx.fem.Function.eval`
Expand All @@ -163,7 +166,8 @@ def eval_J(x_ref):
# This could in theory be made even faster by taking out some of the eval code
# However, quite a lot of work needs to be reimplemented for minimal gain
# to do so, so we rather push forward, then let eval pull back again.
_x_p[: mesh.geometry.dim] = mesh.geometry.cmap.push_forward(

_x_p[: mesh.geometry.dim] = cmap.push_forward(
x_ref.reshape(-1, mesh.topology.dim), mesh_nodes
)[0]
try:
Expand Down Expand Up @@ -233,7 +237,7 @@ def eval_dJ(x_ref):
tol=tol,
)

X_phys = mesh.geometry.cmap.push_forward(result.x.reshape(-1, mesh.topology.dim), mesh_nodes)[0]
X_phys = cmap.push_forward(result.x.reshape(-1, mesh.topology.dim), mesh_nodes)[0]
return X_phys, sign * result.fun


Expand Down
3 changes: 2 additions & 1 deletion src/scifem/point_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import numpy.typing as npt
import ufl

from .compat import get_cmap
from .utils import unroll_dofmap

__all__ = ["PointSource"]
Expand Down Expand Up @@ -121,7 +122,7 @@ def compute_cell_contributions(self):
mesh = self._function_space.mesh
# Pull owning points back to reference cell
mesh_nodes = mesh.geometry.x
cmap = mesh.geometry.cmap
cmap = get_cmap(mesh)

ref_x = np.zeros((len(self._cells), mesh.topology.dim), dtype=mesh.geometry.x.dtype)
for i, (point, cell) in enumerate(zip(self._points, self._cells)):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_point_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import basix
import numpy as np
import ufl
from scifem import PointSource
from scifem import PointSource, compat


def test_midpoint():
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_outside():
if cells.offsets[-1] > 0:
cell = cells.links(0)[0]
geom_dofs = mesh.geometry.dofmap[cell]
ref_x = mesh.geometry.cmap.pull_back(point.reshape(-1, 3), mesh.geometry.x[geom_dofs])
ref_x = compat.get_cmap(mesh).pull_back(point.reshape(-1, 3), mesh.geometry.x[geom_dofs])
ref_values = V.ufl_element().tabulate(0, ref_x).flatten()
b_nonzero = np.flatnonzero(b.x.array)
dofs = V.dofmap.cell_dofs(cell)
Expand Down
Loading