Interpolate an expression. Args: u0: Callable function, Expression or Function to interpolate. cells0: Cells in mesh associated with ``u0`` to interpolate over. If ``None`` then all cells are interpolated over. cells1: Cells
(
self,
u0: Callable | Expression[Scalar] | Function[Scalar],
cells0: npt.NDArray[np.int32] | None = None,
cells1: npt.NDArray[np.int32] | None = None,
)
| 494 | ) # type: ignore |
| 495 | |
| 496 | def interpolate( |
| 497 | self, |
| 498 | u0: Callable | Expression[Scalar] | Function[Scalar], |
| 499 | cells0: npt.NDArray[np.int32] | None = None, |
| 500 | cells1: npt.NDArray[np.int32] | None = None, |
| 501 | ) -> None: |
| 502 | """Interpolate an expression. |
| 503 | |
| 504 | Args: |
| 505 | u0: Callable function, Expression or Function to |
| 506 | interpolate. |
| 507 | cells0: Cells in mesh associated with ``u0`` to interpolate |
| 508 | over. If ``None`` then all cells are interpolated over. |
| 509 | cells1: Cells in the mesh associated with ``self`` to |
| 510 | interpolate over. If ``None``, then taken to be the same |
| 511 | cells as ``cells0``. If ``cells1`` is not ``None`` it |
| 512 | must have the same length as ``cells0``. |
| 513 | """ |
| 514 | |
| 515 | @singledispatch |
| 516 | def _interpolate(u0): |
| 517 | """Interpolate a cpp.fem.Function.""" |
| 518 | self._cpp_object.interpolate(u0, cells0, cells1) |
| 519 | |
| 520 | @_interpolate.register(Function) |
| 521 | def _(u0: Function): |
| 522 | """Interpolate a fem.Function.""" |
| 523 | self._cpp_object.interpolate(u0._cpp_object, cells0, cells1) |
| 524 | |
| 525 | @_interpolate.register(int) |
| 526 | def _(u0_ptr: int): |
| 527 | """Interpolate using a pointer to a function f(x).""" |
| 528 | self._cpp_object.interpolate_ptr(u0_ptr, cells0) |
| 529 | |
| 530 | @_interpolate.register(Expression) |
| 531 | def _(e0: Expression): |
| 532 | """Interpolate a fem.Expression.""" |
| 533 | self._cpp_object.interpolate_expr(e0._cpp_object, cells0, cells1) |
| 534 | |
| 535 | try: |
| 536 | # u is a Function or Expression (or pointer to one) |
| 537 | _interpolate(u0) |
| 538 | except TypeError: |
| 539 | # u0 is callable |
| 540 | assert callable(u0) |
| 541 | x = _cpp.fem.interpolation_coords( |
| 542 | self._V.element._cpp_object, self._V.mesh.geometry._cpp_object, cells0 |
| 543 | ) |
| 544 | self._cpp_object.interpolate_f(np.asarray(u0(x), dtype=self.dtype), cells0) |
| 545 | |
| 546 | def copy(self) -> Function[Scalar]: |
| 547 | """Create a copy of the Function. |
no outgoing calls