Skip to content

Commit d55000f

Browse files
committed
Centralise common names
1 parent 349edca commit d55000f

10 files changed

Lines changed: 117 additions & 109 deletions

File tree

python/dolfinx/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from dolfinx import common
3131
from dolfinx import cpp as _cpp
32-
from dolfinx import fem, geometry, graph, io, jit, la, log, mesh, nls, plot
32+
from dolfinx import fem, geometry, graph, io, jit, la, log, mesh, nls, plot, typing
3333

3434
from dolfinx.common import (
3535
git_commit_hash,
@@ -79,6 +79,7 @@ def get_include(user=False):
7979
"mesh",
8080
"nls",
8181
"plot",
82+
"typing",
8283
"git_commit_hash",
8384
"hardware_concurrency",
8485
"has_adios2",

python/dolfinx/fem/bcs.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
from __future__ import annotations
1414

1515
from collections.abc import Callable, Iterable
16-
from typing import Generic, TypeVar
16+
from typing import Generic
1717

1818
import numpy as np
1919
import numpy.typing as npt
2020

2121
import dolfinx
2222
from dolfinx import cpp as _cpp
2323
from dolfinx.fem.function import Constant, Function, FunctionSpace
24+
from dolfinx.typing import Scalar
2425

2526

2627
def locate_dofs_geometrical(
@@ -91,10 +92,7 @@ def locate_dofs_topological(
9192
return _cpp.fem.locate_dofs_topological(_V, entity_dim, _entities, remote)
9293

9394

94-
_T = TypeVar("_T", np.float32, np.float64, np.complex64, np.complex128)
95-
96-
97-
class DirichletBC(Generic[_T]):
95+
class DirichletBC(Generic[Scalar]):
9896
"""Representation of Dirichlet boundary conditions.
9997
10098
The conditions are imposed on a linear system.
@@ -133,7 +131,9 @@ def function_space(self) -> dolfinx.fem.FunctionSpace:
133131
"""Function space on which the boundary condition is defined."""
134132
return self._cpp_object.function_space
135133

136-
def set(self, x: npt.NDArray[_T], x0: npt.NDArray[_T] | None = None, alpha: float = 1) -> None:
134+
def set(
135+
self, x: npt.NDArray[Scalar], x0: npt.NDArray[Scalar] | None = None, alpha: float = 1
136+
) -> None:
137137
"""Set array entries that are constrained by a Dirichlet condition.
138138
139139
Entries in ``x`` that are constrained by a Dirichlet boundary
@@ -174,10 +174,10 @@ def dof_indices(self) -> tuple[npt.NDArray[np.int32], int]:
174174

175175

176176
def dirichletbc(
177-
value: Function | Constant | npt.NDArray[_T] | float | complex,
177+
value: Function | Constant | npt.NDArray[Scalar] | float | complex,
178178
dofs: npt.NDArray[np.int32],
179179
V: dolfinx.fem.FunctionSpace | None = None,
180-
) -> DirichletBC[_T]:
180+
) -> DirichletBC[Scalar]:
181181
"""Representation of Dirichlet boundary condition.
182182
183183
Args:
@@ -234,8 +234,8 @@ def dirichletbc(
234234

235235

236236
def bcs_by_block(
237-
spaces: Iterable[FunctionSpace | None], bcs: Iterable[DirichletBC[_T]]
238-
) -> list[list[DirichletBC[_T]]]:
237+
spaces: Iterable[FunctionSpace | None], bcs: Iterable[DirichletBC[Scalar]]
238+
) -> list[list[DirichletBC[Scalar]]]:
239239
"""Arrange boundary conditions by the space that they constrain.
240240
241241
Given a sequence of function spaces ``spaces`` and a sequence of

python/dolfinx/fem/element.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@
66
"""Finite elements."""
77

88
from functools import singledispatch
9-
from typing import Generic, TypeVar
9+
from typing import Generic
1010

1111
import numpy as np
1212
import numpy.typing as npt
1313

1414
import basix
1515
import basix.ufl
1616
from dolfinx import cpp as _cpp
17+
from dolfinx.typing import Real
1718

18-
_T = TypeVar("_T", np.float32, np.float64)
1919

20-
21-
class CoordinateElement(Generic[_T]):
20+
class CoordinateElement(Generic[Real]):
2221
"""Coordinate element describing the geometry map for mesh cells."""
2322

2423
_cpp_object: _cpp.fem.CoordinateElement_float32 | _cpp.fem.CoordinateElement_float64
@@ -63,7 +62,9 @@ def create_dof_layout(self) -> _cpp.fem.ElementDofLayout:
6362
"""Compute and return the dof layout."""
6463
return self._cpp_object.create_dof_layout()
6564

66-
def push_forward(self, X: npt.NDArray[_T], cell_geometry: npt.NDArray[_T]) -> npt.NDArray[_T]:
65+
def push_forward(
66+
self, X: npt.NDArray[Real], cell_geometry: npt.NDArray[Real]
67+
) -> npt.NDArray[Real]:
6768
"""Push points on the reference cell forward to the physical cell.
6869
6970
Args:
@@ -81,11 +82,11 @@ def push_forward(self, X: npt.NDArray[_T], cell_geometry: npt.NDArray[_T]) -> np
8182

8283
def pull_back(
8384
self,
84-
x: npt.NDArray[_T],
85-
cell_geometry: npt.NDArray[_T],
85+
x: npt.NDArray[Real],
86+
cell_geometry: npt.NDArray[Real],
8687
tol: float = 1.0e-6,
8788
maxit: int = 15,
88-
) -> npt.NDArray[_T]:
89+
) -> npt.NDArray[Real]:
8990
"""Pull points on the physical cell back to the reference cell.
9091
9192
For non-affine cells, the pull-back is a nonlinear operation.
@@ -169,7 +170,7 @@ def _(e: basix.finite_element.FiniteElement) -> CoordinateElement:
169170
return CoordinateElement(_cpp.fem.CoordinateElement_float64(e._e))
170171

171172

172-
class FiniteElement(Generic[_T]):
173+
class FiniteElement(Generic[Real]):
173174
"""A finite element."""
174175

175176
_cpp_object: _cpp.fem.FiniteElement_float32 | _cpp.fem.FiniteElement_float64
@@ -223,7 +224,7 @@ def value_shape(self) -> npt.NDArray[np.integer]:
223224
return self._cpp_object.value_shape
224225

225226
@property
226-
def interpolation_points(self) -> npt.NDArray[_T]:
227+
def interpolation_points(self) -> npt.NDArray[Real]:
227228
"""Points at which to evaluate the function to be interpolated.
228229
229230
Interpolation point coordinates on the reference cell, returning
@@ -281,7 +282,7 @@ def signature(self) -> str:
281282
return self._cpp_object.signature
282283

283284
def T_apply(
284-
self, x: npt.NDArray[_T], cell_permutations: npt.NDArray[np.uint32], dim: int
285+
self, x: npt.NDArray[Real], cell_permutations: npt.NDArray[np.uint32], dim: int
285286
) -> None:
286287
"""Transform basis from reference to physical ordering/orientation.
287288
@@ -304,7 +305,7 @@ def T_apply(
304305
self._cpp_object.T_apply(x, cell_permutations, dim)
305306

306307
def Tt_apply(
307-
self, x: npt.NDArray[_T], cell_permutations: npt.NDArray[np.uint32], dim: int
308+
self, x: npt.NDArray[Real], cell_permutations: npt.NDArray[np.uint32], dim: int
308309
) -> None:
309310
"""Apply the transpose of the operator applied by T_apply().
310311
@@ -318,7 +319,7 @@ def Tt_apply(
318319
self._cpp_object.Tt_apply(x, cell_permutations, dim)
319320

320321
def Tt_inv_apply(
321-
self, x: npt.NDArray[_T], cell_permutations: npt.NDArray[np.uint32], dim: int
322+
self, x: npt.NDArray[Real], cell_permutations: npt.NDArray[np.uint32], dim: int
322323
) -> None:
323324
"""Apply the inverse transpose of T_apply().
324325

python/dolfinx/fem/forms.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,16 @@
2525
from dolfinx import default_scalar_type, jit
2626
from dolfinx.fem import IntegralType
2727
from dolfinx.fem.function import Constant, Function, FunctionSpace
28+
from dolfinx.typing import Scalar
2829

2930
if typing.TYPE_CHECKING:
3031
# import dolfinx.mesh just when doing type checking to avoid
3132
# circular import
3233
from dolfinx.mesh import EntityMap as _EntityMap
3334
from dolfinx.mesh import Mesh, MeshTags
3435

35-
_S = typing.TypeVar("_S", np.float32, np.float64, np.complex64, np.complex128) # scalar
3636

37-
38-
class Form(typing.Generic[_S]):
37+
class Form(typing.Generic[Scalar]):
3938
"""A finite element form."""
4039

4140
_cpp_object: (

0 commit comments

Comments
 (0)