Dolfinx Discontinuous Expressions SIGSEGV

Hi all, I am receiving SIGSEGV running code from linked anwer. I am attaching an example code and stack trace.

import dolfinx

mesh = dolfinx.UnitSquareMesh(dolfinx.MPI.comm_world, 9, 9)
V = dolfinx.FunctionSpace(mesh, ("DG", 0))
v = dolfinx.Function(V)
x = V.tabulate_dof_coordinates()
for i in range(x.shape[0]):
    midpoint = x[i,:]
    if midpoint[0]> 0.5 and midpoint[1]>0.25:
        v.vector.setValueLocal(i, 2)
        v.vector.setValueLocal(i, 1), "DG.xdmf").write(v)
Loguru caught a signal: SIGSEGV
Stack trace:
22            0x5f6ede _start + 46
21      0x7fa349ca20b3 __libc_start_main + 243
20            0x6afa59 Py_BytesMain + 41
19            0x6af6ce Py_RunMain + 526
18            0x67845a PyRun_SimpleFileExFlags + 378
17            0x6780d7 PyRun_FileExFlags + 151
16            0x67801f python3() [0x67801f]
15            0x677fa1 python3() [0x677fa1]
14            0x687033 PyEval_EvalCode + 35
13            0x565332 _PyEval_EvalCodeWithName + 610
12            0x567228 _PyEval_EvalFrameDefault + 2248
11            0x5f2b85 _PyFunction_Vectorcall + 933
10            0x565332 _PyEval_EvalCodeWithName + 610
9             0x56bed7 _PyEval_EvalFrameDefault + 21879
8             0x508312 python3() [0x508312]
7             0x5f31fe _PyObject_MakeTpCall + 654
6             0x5f25e5 PyCFunction_Call + 85
5       0x7fa3497e116e /usr/local/lib/python3.8/dist-packages/dolfinx/ [0x7fa3497e116e]
4       0x7fa349787770 /usr/local/lib/python3.8/dist-packages/dolfinx/ [0x7fa349787770]
3       0x7fa34953358d dolfinx::io::XDMFFile::write(dolfinx::function::Function const&, double) + 109
2       0x7fa349543104 dolfinx::io::xdmf_function::write(dolfinx::function::Function const&, double, int, pugi::xml_document&, long) + 3188
1       0x7fa34954bd2c dolfinx::io::xdmf_utils::get_cell_data_values(dolfinx::function::Function const&) + 556
0       0x7fa349cc1210 /lib/x86_64-linux-gnu/ [0x7fa349cc1210]
2020-03-30 19:10:24.656 (   1.707s) [main thread     ]                       :0     FATL| Signal: SIGSEGV
Segmentation fault (core dumped)

I am running latest dolfinx:complex docker build.

Dolfinx discontinous expression

This does indeed seem like a bug. Could you report it on the dolfinx issue tracker?
Note that it is only visualizing the function as a DG function that doesn’t work. (For the sake of running an actual program, you can project the function to a CG1 space for visualization of it, and use the actual DG 0 function everywhere else).

First of all, thanks for the quick response! Sure thing, I will report it on the issue tracker. If the developers think that this is a beginner-friendly issue, I could even try to fix it.

Could you help me find where projection is defined in dolfinx? I know that dolfin had dolfin.project but I can’t seem to find it in dolfinx.

I will probably take a little while to fix it, as we are currently rewriting the IO from scratch.

A projection in dolfinx has no shortcut, But i can sketch how to do it (might be prone to typos, as Im on my phone).

V = dolfinx.FunctionSpace(mesh, ("DG",0))
v = dolfinx.Function(V)
# Do the set values as described above
# ....

W= dolfinx.FunctionSpace(mesh, ("CG",1))
u, w = ufl.TrialFunction(W), ufl.TestFunction(W)
a= ufl.inner(u, w) * ufl.dx
l = ufl.inner(v, w) * ufl.dx
uh = dolfinx.Function(V)
dolfinx.solve(a==l, uh)

I will mark this as solved because projecting function to CG1 works. Thanks!