MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / interpolate

Method interpolate

python/dolfinx/fem/function.py:496–544  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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.

Callers 15

test_copyFunction · 0.95
test_evalFunction · 0.95
test_eval_manifoldFunction · 0.95
test_interpolation_rank0Function · 0.95
test_interpolation_rank1Function · 0.95
test_cffi_expressionFunction · 0.95
test_transposeFunction · 0.95
test_interpolationFunction · 0.95

Calls

no outgoing calls

Tested by 15

test_copyFunction · 0.76
test_evalFunction · 0.76
test_eval_manifoldFunction · 0.76
test_interpolation_rank0Function · 0.76
test_interpolation_rank1Function · 0.76
test_cffi_expressionFunction · 0.76
test_transposeFunction · 0.76
test_interpolationFunction · 0.76