Skip to content

[BUG]: Interpolation into symmetric rank-2 tensors broken #3516

@michalhabera

Description

@michalhabera

Summarize the issue

Recent changes altered the value shape of symmetric rank-2 tensors, being rank-1 with shape (dim * (dim + 1)/2, ). This means that interpolation of objects with shape (dim, dim) into symmetric rank-2 tensors does not work anymore.

See https://github.com/FEniCS/dolfinx/blob/main/cpp/dolfinx/fem/FiniteElement.cpp#L118

How to reproduce the bug

Interpolate into symmetric rank-2 tensors.

Minimal Example (Python)

import dolfinx
from mpi4py import MPI

mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 1, 1)

REG = dolfinx.fem.functionspace(mesh, ("Regge", 1))
Psymm = dolfinx.fem.functionspace(mesh, ("P", 1, (2, 2), True))

print(f"Regge value shape: {REG.element.value_shape}")
print(f"Psymm value shape: {Psymm.element.value_shape}")

f0 = dolfinx.fem.Function(REG)
f1 = dolfinx.fem.Function(Psymm)

f0.interpolate(f1)

Output (Python)

Regge value shape: [2 2]
Psymm value shape: [3]
Traceback (most recent call last):
  File "/home/UNILU/symm_interp.py", line 15, in <module>
    f0.interpolate(f1)
  File "/home/UNILU/dolfinx/python/dolfinx/fem/function.py", line 459, in interpolate
    _interpolate(u0)
  File "/usr/lib/python3.12/functools.py", line 909, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/UNILU/dolfinx/python/dolfinx/fem/function.py", line 445, in _
    self._cpp_object.interpolate(u0._cpp_object, cells0, cells1)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Interpolation: elements have different value dimensions

Version

main branch

DOLFINx git commit

No response

Installation

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions