Hello,
It seems that dolfinx.fem.FunctionSpace
{.python} can take an optional tuple
{.python} as a shape
{.verbatim} parameter. How is this chosen? In the unit test, it is:
gdim = mesh.geometry.dim
V = FunctionSpace(mesh, ("Lagrange", 1, (gdim,)))
which makes me think that I could always use this construct, but doing this (from the tutorial) fails:
from mpi4py import MPI
from dolfinx import mesh
from dolfinx.fem import FunctionSpace
from dolfinx import fem
domain = mesh.create_unit_square(
MPI.COMM_WORLD, 8, 8, mesh.CellType.quadrilateral)
fe_type = "Lagrange"
fe_degree = 1
gdim = domain.geometry.dim
# Original
# V = FunctionSpace(domain, (fe_type, fe_degree))
V = FunctionSpace(domain, (fe_type, fe_degree, (gdim,)))
uD = fem.Function(V)
uD.interpolate(lambda x_in: 1 + x_in[0]**2 + 2 * x_in[1]**2)
Traceback (most recent call last):
File "/usr/lib/python3.11/site-packages/dolfinx/fem/function.py", line 397, in interpolate
_interpolate(u, cells)
File "/usr/lib/python3.11/functools.py", line 909, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/dolfinx/fem/function.py", line 373, in _interpolate
self._cpp_object.interpolate(u, cells, nmm_interpolation_data)
TypeError: interpolate(): incompatible function arguments. The following argument types are supported:
1. (self: dolfinx.cpp.fem.Function_float64, f: numpy.ndarray[numpy.float64], cells: numpy.ndarray[numpy.int32]) -> None
2. (self: dolfinx.cpp.fem.Function_float64, u: dolfinx.cpp.fem.Function_float64, cells: numpy.ndarray[numpy.int32], nmm_interpolation_data: Tuple[List[int], List[int], List[float], List[int]]) -> None
3. (self: dolfinx.cpp.fem.Function_float64, expr: dolfinx::fem::Expression<double, double>, cells: numpy.ndarray[numpy.int32]) -> None
Invoked with: <dolfinx.cpp.fem.Function_float64 object at 0x7f13febf3570>, <function <lambda> at 0x7f13fea002c0>, array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63], dtype=int32), ((), (), (), ())
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 19, in __PYTHON_EL_eval
File "<string>", line 18, in <module>
File "/usr/lib/python3.11/site-packages/dolfinx/fem/function.py", line 402, in interpolate
self._cpp_object.interpolate(np.asarray(u(x), dtype=self.dtype), cells)
RuntimeError: Interpolation data has the wrong shape/size.
Thank you kindly for your response.
My system
* FEniCSx software
dolfinx: 0.7.0.dev0_r27554.cfeffe0-1
basix: 0.7.0.dev0_r945.1117a8d-1
ufl: 2023.2.0.dev0_r3562.77ae57c-1
ffcx: 0.7.0.dev0_r7077.1d27238-1
* Dependencies
python: 3.11.5-2
python-numpy: 1.26.0-1
petsc: 3.19.5.1171.g37df9106526-1
hdf5-openmpi: 1.14.2-1
boost: 1.83.0-2
adios2: 2.8.3-5
scotch: 7.0.4-1
pybind11: 2.11.1-1
python-build: 1.0.1-1
python-cffi: 1.15.1-4
python-cppimport: 22.08.02.r6.g0849d17-1
python-installer: 0.7.0-3
python-mpi4py: 3.1.4-3
python-pytest: 7.4.2-1
python-scikit-build: 0.17.6-1
python-setuptools: 1:68.0.0-1
python-wheel: 0.40.0-3
xtensor: 0.24.0-2
xtensor-blas: 0.20.0-1
* Operating system
Arch Linux: 6.5.4-arch2-1