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

Interpolation into symmetric tensor #3159

Open
mscroggs opened this issue Apr 23, 2024 · 0 comments
Open

Interpolation into symmetric tensor #3159

mscroggs opened this issue Apr 23, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@mscroggs
Copy link
Member

mscroggs commented Apr 23, 2024

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

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant