FEniCS / FEniCS/dolfinx

Interpolation into symmetric tensor

Open
#3,159 0 comments 0 reactions 1 assignee Claimed by @mscroggs View on GitHub
enhancement roadmap
Dominant language
C++
Stars
1.2k
Forks
261
Avg merge
1d 15h
Merged PRs (30d)
65

Description

### Describe new/missing feature

Currently (after #3158), to interpolate into a symmetric tensor, we must pass in (eq) all 9 entries of a 3x3 symmetric tensor. We should additionally be able to pass in just the (eg) 6 entries of the lower part of the matrix.

See also #3143.

### Suggested user interface

```python3
def test_symmetric_tensor_interpolation():
mesh = create_unit_square(MPI.COMM_WORLD, 10, 10)

def tensor(x):
mat = np.array([[0], [1], [3], [1], [2], [4], [3], [4], [5]])
return np.broadcast_to(mat, (9, x.shape[1]))

def symm_tensor(x):
mat = np.array([[0], [1], [2], [3], [4], [5]])
return np.broadcast_to(mat, (6, x.shape[1]))

element = basix.ufl.element("DG", mesh.basix_cell(), 0, shape=(3, 3))
symm_element = basix.ufl.element("DG", mesh.basix_cell(), 0, shape=(3, 3), symmetry=True)
space = functionspace(mesh, element)
symm_space = functionspace(mesh, symm_element)
f = Function(space)
symm_f = Function(symm_space)

f.interpolate(lambda x: tensor(x))
symm_f.interpolate(lambda x: symm_tensor(x))

l2_error = assemble_scalar(form((f - symm_f) ** 2 * ufl.dx))
atol = 10 * np.finfo(default_scalar_type).resolution
assert np.isclose(l2_error, 0.0, atol=atol)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.