From 190035c1a0d4e49b8f8ee8868e79c0caf2b335f2 Mon Sep 17 00:00:00 2001 From: Joergen Schartum Dokken Date: Tue, 4 Aug 2026 14:54:08 +0000 Subject: [PATCH 1/2] Update to main API and start adding deprecation warnings on functions that should be removed at some point --- src/scifem/mesh.py | 8 ++++++++ src/scifem/petsc.py | 3 +++ src/scifem/spaces.py | 10 +++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/scifem/mesh.py b/src/scifem/mesh.py index 692d39bb..34140992 100644 --- a/src/scifem/mesh.py +++ b/src/scifem/mesh.py @@ -1,5 +1,7 @@ from __future__ import annotations +from warnings import deprecated + from . import _scifem # type: ignore import collections import dolfinx @@ -118,6 +120,12 @@ def create_entity_markers( return dolfinx.mesh.meshtags(domain, dim, facets, markers[facets]) +@deprecated( + reason="This function is deprecated and will be removed in a future version. " + + "Please use `dolfinx.mesh.transfer_meshtags_to_submesh()` instead.", + category=DeprecationWarning, + stacklevel=2, +) def transfer_meshtags_to_submesh( entity_tag: dolfinx.mesh.MeshTags, submesh: dolfinx.mesh.Mesh, diff --git a/src/scifem/petsc.py b/src/scifem/petsc.py index 322aa563..aad8cef2 100644 --- a/src/scifem/petsc.py +++ b/src/scifem/petsc.py @@ -97,6 +97,9 @@ def apply_lifting_and_set_bc( except AssertionError: bcs0 = bcs bcs1 = bcs + except ValueError: # Changed error type post https://github.com/FEniCS/dolfinx/pull/4312 + bcs0 = bcs + bcs1 = bcs dolfinx.fem.petsc.apply_lifting(b, a, bcs=bcs1, x0=x, alpha=alpha) ghost_update(b, PETSc.InsertMode.ADD_VALUES, PETSc.ScatterMode.REVERSE) diff --git a/src/scifem/spaces.py b/src/scifem/spaces.py index 2ff2f385..fb5df741 100644 --- a/src/scifem/spaces.py +++ b/src/scifem/spaces.py @@ -1,3 +1,5 @@ +from warnings import warn + from mpi4py import MPI import dolfinx import basix @@ -22,7 +24,13 @@ def create_real_functionspace( For scalar elements value shape is ``()``. """ - + if Version(dolfinx.__version__) >= Version("0.11.0"): + warn( + "`create_real_functionspace()` is deprecated and will be removed in a future version." + + "Please use `basix.ufl.create_real_element()` instead.", + category=DeprecationWarning, + stacklevel=2, + ) dtype = mesh.geometry.x.dtype ufl_e = basix.ufl.element( "P", mesh.basix_cell(), 0, dtype=dtype, discontinuous=True, shape=value_shape From 56f4f8c7c49c83e02af1e79271e97bc1263ec4eb Mon Sep 17 00:00:00 2001 From: Joergen Schartum Dokken Date: Tue, 4 Aug 2026 15:09:09 +0000 Subject: [PATCH 2/2] Fix eval deprecation warning as well as deprecating some more functions. --- src/scifem/eval.py | 12 ++++++++---- src/scifem/mesh.py | 8 ++++++-- src/scifem/solvers.py | 12 ++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/scifem/eval.py b/src/scifem/eval.py index 8e0ec8d2..24c843aa 100644 --- a/src/scifem/eval.py +++ b/src/scifem/eval.py @@ -145,8 +145,10 @@ def find_cell_extrema( else: raise NotImplementedError(f"Unknown type of extrema ({kind}), expected {min} or {max}") - ud = u.ufl_domain() - assert ud is not None + uds = ufl.domain.extract_domains(u) + if uds is None or len(uds) != 1: + raise ValueError(f"Expression {u:s} must be defined on a single domain") + ud = uds[0] mesh = dolfinx.mesh.Mesh(ud.ufl_cargo(), ud) if x0 is None: @@ -307,8 +309,10 @@ def compute_extrema( """ # Extract DOLFINx mesh - ud = u.ufl_domain() - assert ud is not None + uds = ufl.domain.extract_domains(u) + if uds is None or len(uds) != 1: + raise ValueError(f"Expression {u:s} must be defined on a single domain") + ud = uds[0] mesh = dolfinx.mesh.Mesh(ud.ufl_cargo(), ud) if kind is builtins.max: diff --git a/src/scifem/mesh.py b/src/scifem/mesh.py index 34140992..b594a6ff 100644 --- a/src/scifem/mesh.py +++ b/src/scifem/mesh.py @@ -1,6 +1,10 @@ from __future__ import annotations +import sys -from warnings import deprecated +if sys.version_info >= (3, 13): + from warnings import deprecated +else: + from typing_extensions import deprecated from . import _scifem # type: ignore import collections @@ -121,7 +125,7 @@ def create_entity_markers( @deprecated( - reason="This function is deprecated and will be removed in a future version. " + "This function is deprecated and will be removed in a future version. " + "Please use `dolfinx.mesh.transfer_meshtags_to_submesh()` instead.", category=DeprecationWarning, stacklevel=2, diff --git a/src/scifem/solvers.py b/src/scifem/solvers.py index 5c79d052..57a7103f 100644 --- a/src/scifem/solvers.py +++ b/src/scifem/solvers.py @@ -1,7 +1,15 @@ from __future__ import annotations +import sys from typing import Callable import logging + +if sys.version_info >= (3, 13): + from warnings import deprecated +else: + from typing_extensions import deprecated + + from packaging.version import parse as _v import numpy as np @@ -23,6 +31,7 @@ if _v(dolfinx.__version__) < _v("0.9"): _alpha_kw = "scale" + @deprecated("NewtonSolver is deprecated in favor of `dolfinx.fem.petsc.NonlinearProblem`.") class NewtonSolver: max_iterations: int _bcs: list[dolfinx.fem.DirichletBC] @@ -307,6 +316,9 @@ def __del__(self): self._solver.destroy() self.x.destroy() + @deprecated( + "BlockedNewtonSolver is deprecated in favor of `dolfinx.fem.petsc.NonlinearProblem`." + ) class BlockedNewtonSolver(dolfinx.cpp.nls.petsc.NewtonSolver): def __init__( self,