|
14 | 14 |
|
15 | 15 | import numbers |
16 | 16 | from collections.abc import Callable, Iterable |
| 17 | +from typing import Generic, TypeVar |
17 | 18 |
|
18 | 19 | import numpy as np |
19 | 20 | import numpy.typing as npt |
@@ -91,7 +92,10 @@ def locate_dofs_topological( |
91 | 92 | return _cpp.fem.locate_dofs_topological(_V, entity_dim, _entities, remote) |
92 | 93 |
|
93 | 94 |
|
94 | | -class DirichletBC: |
| 95 | +_T = TypeVar("_T", np.float32, np.float64, np.complex64, np.complex128) |
| 96 | + |
| 97 | + |
| 98 | +class DirichletBC(Generic[_T]): |
95 | 99 | """Representation of Dirichlet boundary conditions. |
96 | 100 |
|
97 | 101 | The conditions are imposed on a linear system. |
@@ -120,18 +124,17 @@ class initialiser. This class is combined with different |
120 | 124 | self._cpp_object = bc |
121 | 125 |
|
122 | 126 | @property |
123 | | - def g(self) -> Function | Constant | np.ndarray: |
| 127 | + def g(self) -> Function | Constant: |
124 | 128 | """The boundary condition value(s).""" |
| 129 | + # TODO: needs to be wrapped into Function or Constant |
125 | 130 | return self._cpp_object.value |
126 | 131 |
|
127 | 132 | @property |
128 | 133 | def function_space(self) -> dolfinx.fem.FunctionSpace: |
129 | 134 | """Function space on which the boundary condition is defined.""" |
130 | 135 | return self._cpp_object.function_space |
131 | 136 |
|
132 | | - def set( |
133 | | - self, x: npt.NDArray, x0: npt.NDArray[np.int32] | None = None, alpha: float = 1 |
134 | | - ) -> None: |
| 137 | + def set(self, x: npt.NDArray[_T], x0: npt.NDArray[_T] | None = None, alpha: float = 1) -> None: |
135 | 138 | """Set array entries that are constrained by a Dirichlet condition. |
136 | 139 |
|
137 | 140 | Entries in ``x`` that are constrained by a Dirichlet boundary |
@@ -172,10 +175,10 @@ def dof_indices(self) -> tuple[npt.NDArray[np.int32], int]: |
172 | 175 |
|
173 | 176 |
|
174 | 177 | def dirichletbc( |
175 | | - value: Function | Constant | np.ndarray, |
| 178 | + value: Function | Constant | npt.NDArray[_T], |
176 | 179 | dofs: npt.NDArray[np.int32], |
177 | 180 | V: dolfinx.fem.FunctionSpace | None = None, |
178 | | -) -> DirichletBC: |
| 181 | +) -> DirichletBC[_T]: |
179 | 182 | """Representation of Dirichlet boundary condition. |
180 | 183 |
|
181 | 184 | Args: |
@@ -232,8 +235,8 @@ def dirichletbc( |
232 | 235 |
|
233 | 236 |
|
234 | 237 | def bcs_by_block( |
235 | | - spaces: Iterable[FunctionSpace | None], bcs: Iterable[DirichletBC] |
236 | | -) -> list[list[DirichletBC]]: |
| 238 | + spaces: Iterable[FunctionSpace | None], bcs: Iterable[DirichletBC[_T]] |
| 239 | +) -> list[list[DirichletBC[_T]]]: |
237 | 240 | """Arrange boundary conditions by the space that they constrain. |
238 | 241 |
|
239 | 242 | Given a sequence of function spaces ``spaces`` and a sequence of |
|
0 commit comments