FEniCS / FEniCS/dolfinx

[BUG]: interpolation on CR space

Open
#3,243 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.2k
Forks
261
Avg merge
1d 15h
Merged PRs (30d)
65

Description

### Summarize the issue

I try to interpolate the jump of a DG function on a CR space and I get unexpected results, see the MWE below.

I use the fact the CR function has dofs on facet mid-points, corresponding to integration points on dS with integration degree 1 to obtain the correct reference result.

Am I doing something wrong or there is a bug in the interpolation function?

### How to reproduce the bug

See the script below. I use version 0.8.0.

### Minimal Example (Python)

```Python
# Description: This script shows a possible bug in the interpolation of the jump of a function on a CR space.

from dolfinx import fem, mesh
import ufl
import basix
import numpy as np
from mpi4py import MPI

comm = MPI.COMM_WORLD
msh = mesh.create_unit_square(
comm,
2,
2,
)
CR_el = basix.ufl.element("CR", msh.basix_cell(), 1, discontinuous=False)
DG_el = basix.ufl.element("CR", msh.basix_cell(), 1, discontinuous=True)

# Take a linear function on DG
V_u = fem.functionspace(msh, DG_el)
u = fem.Function(V_u)
u.interpolate(lambda x: x[0])

# Interpolate on CR the jump (CR has DOFs on the facet mid-points)
# The jump should be zero for the given linear function

V_j = fem.functionspace(msh, CR_el)
j = fem.Function(V_j)
j.interpolate(fem.Expression(ufl.jump(u), V_j.element.interpolation_points()))
# The results is not zero
print(f"Interpolation gives result: {j.vector.array}")

# I use the trick below to interpolate the jump on the CR space
# This gives me what I expect

dS = ufl.Measure("dS", domain=msh, metadata={"quadrature_degree": 1})
jump_1 = fem.assemble_vector(
fem.form(
ufl.jump(u)
* ufl.avg(ufl.TestFunction(V_j))
/ ufl.avg(ufl.FacetArea(msh))
* dS
)
)
print(f"Expected result: {jump_1.array}")
```

### Output (Python)

```bash
Interpolation gives result:

[ 2.5e-001 5.0e-001 2.5e-001 7.5e-001 -5.0e-001 -5.0e-001 -5.0e-001
7.5e-001 5.0e-001 2.5e-001 -5.0e-001 2.5e-001 2.5e-001 2.5e-001
2.5e-001 -2.0e-323]

Expected result:

[ 0.00000000e+00 -1.11022302e-16 0.00000000e+00 0.00000000e+00
0.00000000e+00 -2.77555756e-17 0.00000000e+00 0.00000000e+00
-1.11022302e-16 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 -2.77555756e-17 0.00000000e+00 0.00000000e+00]
```

### Version

0.8.0

### DOLFINx git commit

_No response_

### Installation

_No response_

### Additional information

_No response_

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.