Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
michalhabera opened this issue Nov 18, 2024 · 1 comment
Open

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

michalhabera opened this issue Nov 18, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@michalhabera
Copy link
Contributor

michalhabera commented Nov 18, 2024

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

@michalhabera michalhabera added the bug Something isn't working label Nov 18, 2024
@garth-wells
Copy link
Member

I'd say the underlying issue here is that for 3x3 symmetric tensors UFL (or is it now Basix?) reports a value shape of (6,) rather than (3, 3) plus a 'block size' of 6. I left a comment at

// TODO: symmetric rank-2 symmetric tensors are presently constructed
. Before we had a hack where function spaces and elements sometimes reported the same value shape, and sometimes different, and sometimes did some implicit mutations behind the scenes.

The value shape is (3, 3) because they're rank-2 tensors, Symmetry just implies a constraint. We could try a UFL-level fix, or we could try a temporary hack in DOLFINx to address the isssue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants