I am trying to extend a following code https://github.com/FEniCS/dolfinx/issues/3165 to include mixed space elements.
import basix.ufl
import numpy as np
from dolfinx.mesh import create_unit_square
from dolfinx.fem import functionspace, Function
from mpi4py import MPI
mesh = create_unit_square(MPI.COMM_WORLD, 10, 10)
def tensor(x):
mat = np.array([[1], [0], [0], [2], [3], [0], [4], [5], [6]])
return np.broadcast_to(mat, (9, x.shape[1]))
def tensor2(x):
mat = np.array([[1], [2], [3], [4], [5], [6]])
return np.broadcast_to(mat, (6, x.shape[1]))
element = basix.ufl.element("DG", mesh.basix_cell(), 0, shape=(3, 3), symmetry=True)
space = functionspace(mesh, element)
space_mix = functionspace(mesh, basix.ufl.mixed_element([element,element]))
subspace,_ = space_mix.sub(0).collapse()
f = Function(subspace)
# f = Function(space)
# f.interpolate(lambda x: tensor2(x))
f.interpolate(lambda x: tensor(x))
print(f.eval([[0, 0, 0]], [0]))
-
When using a standard space, function with full tensor (
tensor(x)
) works properly (prints[1. 2. 4. 2. 3. 5. 4. 5. 6.]
), while the other approach with only symmetrical part (usingtensor2
) givesInterpolation data has the wrong shape/size.
error. -
When using the mixed space, the first approach (
tensor(x)
) gives theInterpolation ...
error, while the second (usingtensor2(x)
) sometimes ends up with Ubuntu (invalid pointer) or MPI (SEGV) memory errors. Regardless of errorsprint
always executes printing incorrect result:[1.0000e+000 4.0000e+000 9.5750e-321 4.0000e+000 5.0000e+000 1.0563e-320]
-
Both approaches (with standard and mixed space) work well when
symmetry=False
Am I doing something wrong?