Integrating and gradient across internal boundary in Dolfinx: Compile Error


I am solving the heat equation over a square plate with a tri-material distribution with different thermal conductivities. In the centre of the plate I have a circle, and I would like to calculate the heat flux into this circle. I have seen this topic Calculate flux from solution with Fenicsx - #19 by dokken and have tried unsuccesfully to interpolate grad(Th) into a DG0 space.

I am getting an error I have gotten before since switching from legacy fenics, and previously resolved by either restarting the computer or creating a new environment. This time, neither of those have worked. Here is the terminal output:

hwloc/linux: Ignoring PCI device with non-16bit domain.
Pass --enable-32bits-pci-domain to configure to support such devices
(warning: it would break the library ABI, don't enable unless really needed).
Info    : Meshing 1D...
Info    : [  0%] Meshing curve 1 (Line)
Info    : [ 20%] Meshing curve 2 (Line)
Info    : [ 40%] Meshing curve 3 (Line)
Info    : [ 60%] Meshing curve 4 (Line)
Info    : [ 80%] Meshing curve 5 (Ellipse)
Info    : Done meshing 1D (Wall 0.000599726s, CPU 0.00273s)
Info    : Meshing 2D...
Info    : [  0%] Meshing surface 1 (Plane, Frontal-Delaunay)
Info    : [ 50%] Meshing surface 2 (Plane, Frontal-Delaunay)
Info    : Done meshing 2D (Wall 0.117702s, CPU 0.619779s)
Info    : 3198 nodes 6477 elements
Info    : Writing 'example_mesh.msh'...
Info    : Done writing 'example_mesh.msh'
Info    : Reading 'example_mesh.msh'...
Info    : 12 entities
Info    : 3060 nodes
Info    : 5958 elements
Info    : Done reading 'example_mesh.msh'
INFO:root:running build_ext
INFO:root:building 'libffcx_elements_fe1a0993602258ab98fb05640c655d4a385d47cf' extension
INFO:root:/home/matei/anaconda3/envs/fenicsx-v1/bin/x86_64-conda-linux-gnu-cc -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/matei/anaconda3/envs/fenicsx-v1/include -fPIC -O2 -isystem /home/matei/anaconda3/envs/fenicsx-v1/include -march -DNDEBUG -D_FORTIFY_SOURCE -fPIC -I/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/ffcx/codegeneration -I/home/matei/anaconda3/envs/fenicsx-v1/include/python3.10 -c libffcx_elements_fe1a0993602258ab98fb05640c655d4a385d47cf.c -o ./libffcx_elements_fe1a0993602258ab98fb05640c655d4a385d47cf.o -O2 -g0
x86_64-conda-linux-gnu-cc: error: unrecognized command-line option '-march'
Traceback (most recent call last):
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/setuptools/_distutils/", line 185, in _compile
    self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/setuptools/_distutils/", line 1041, in spawn
    spawn(cmd, dry_run=self.dry_run, **kwargs)
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/setuptools/_distutils/", line 70, in spawn
    raise DistutilsExecError(
distutils.errors.DistutilsExecError: command '/home/matei/anaconda3/envs/fenicsx-v1/bin/x86_64-conda-linux-gnu-cc' failed with exit code 1
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/cffi/", line 48, in _build
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/setuptools/", line 989, in run_command
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/setuptools/_distutils/", line 988, in run_command
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/setuptools/command/", line 88, in run
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/setuptools/_distutils/command/", line 345, in run
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/setuptools/_distutils/command/", line 467, in build_extensions
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/setuptools/_distutils/command/", line 493, in _build_extensions_serial
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/setuptools/command/", line 249, in build_extension
    _build_ext.build_extension(self, ext)
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/setuptools/_distutils/command/", line 548, in build_extension
    objects = self.compiler.compile(
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/setuptools/_distutils/", line 600, in compile
    self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/setuptools/_distutils/", line 187, in _compile
    raise CompileError(msg)
distutils.errors.CompileError: command '/home/matei/anaconda3/envs/fenicsx-v1/bin/x86_64-conda-linux-gnu-cc' failed with exit code 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/matei/PhD/GAOpt/src/solvers/", line 70, in <module>
    V = fem.VectorFunctionSpace(msh, ("DG", 0))
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/dolfinx/fem/", line 609, in VectorFunctionSpace
    return FunctionSpace(mesh, ufl_element)
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/dolfinx/fem/", line 487, in __init__
    (self._ufcx_element, self._ufcx_dofmap), module, code = jit.ffcx_jit(
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/dolfinx/", line 56, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/dolfinx/", line 206, in ffcx_jit
    r = ffcx.codegeneration.jit.compile_elements([ufl_object], options=p_ffcx, **p_jit)
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/ffcx/codegeneration/", line 144, in compile_elements
    impl = _compile_objects(decl, elements, names, module_name, p, cache_dir,
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/ffcx/codegeneration/", line 270, in _compile_objects
    ffibuilder.compile(tmpdir=cache_dir, verbose=True, debug=cffi_debug)
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/cffi/", line 725, in compile
    return recompile(self, module_name, source, tmpdir=tmpdir,
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/cffi/", line 1564, in recompile
    outputfilename = ffiplatform.compile('.', ext,
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/cffi/", line 20, in compile
    outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
  File "/home/matei/anaconda3/envs/fenicsx-v1/lib/python3.10/site-packages/cffi/", line 54, in _build
    raise VerificationError('%s: %s' % (e.__class__.__name__, e))
cffi.VerificationError: CompileError: command '/home/matei/anaconda3/envs/fenicsx-v1/bin/x86_64-conda-linux-gnu-cc' failed with exit code 1

In this MWE, I have set the conductivity as uniform (1.0), as I still get the same error. I am using fenicsx 0.6.0 installed via conda-forge on Ubuntu. I am not sure if this error is because of my instillation or because of a mistake in the way I am trying to acquire the heat flux. Many thanks for any help.

import numpy as np
from dolfinx import fem
from dolfinx.mesh import meshtags
from dolfinx.fem import (Function, FunctionSpace)
from import gmshio
import ufl
from ufl import (ds, dx, grad, inner, TrialFunction, TestFunction)
from mpi4py import MPI
from petsc4py.PETSc import ScalarType
import gmsh

proc = MPI.COMM_WORLD.rank
r = 0.125  # Circle radius
cx, cy = 0.5, 0.5  # Circle center
element_size = 0.02  # Mesh element size
if proc == 0:
    # Set the mesh element size
    gmsh.option.setNumber("Mesh.CharacteristicLengthMin", element_size)
    gmsh.option.setNumber("Mesh.CharacteristicLengthMax", element_size)

    square = gmsh.model.occ.addRectangle(0, 0, 0, 1, 1)

    # Create circle within the rectangle
    circle = gmsh.model.occ.addDisk(cx, cy, 0, r, r)


    # Marking the physical groups (modify as per your needs)

    circle_boundary = gmsh.model.getBoundary([(2, circle)])
    gmsh.model.mesh.embed(1, [circle_boundary[0][1]], 2, square)

    gmsh.model.addPhysicalGroup(2, [square], 1)
    gmsh.model.addPhysicalGroup(1, [circle_boundary[0][1]], 2)
    # gmsh.model.mesh.generate(1)


msh, cell_markers, facet_markers = gmshio.read_from_msh("example_mesh.msh", MPI.COMM_WORLD, gdim=2)
V = FunctionSpace(msh, ("CG", 1))

# locate DOFs associated w boundary
dofs_L = fem.locate_dofs_geometrical(V, lambda x: np.isclose(x[0], 0))
bc_L = fem.dirichletbc(value=ScalarType(293), dofs=dofs_L, V=V)
dofs_R = fem.locate_dofs_geometrical(V, lambda x: np.isclose(x[0], 1))
bc_R = fem.dirichletbc(value=ScalarType(393), dofs=dofs_R, V=V)

T, v = TrialFunction(V), TestFunction(V)
a = inner(1.0 * grad(T), grad(v)) * dx
L = fem.Constant(msh, ScalarType(0)) * v * dx + fem.Constant(msh, ScalarType(0)) * v * ds  # No source term and zero-neumann
problem = fem.petsc.LinearProblem(a, L, bcs=[bc_L, bc_R],
                                  petsc_options={"ksp_type": "preonly",  # preonly / gmres
                                                 "pc_type": "lu"})  # lu / ilu
Th = problem.solve()

bnd_tag = 2  # boundary tag
arc_indices = facet_markers.indices[facet_markers.values == bnd_tag]
arc_tags = meshtags(msh, 1, arc_indices, bnd_tag)
dS = ufl.Measure("dS", domain=msh, subdomain_data=arc_tags)

n = ufl.FacetNormal(msh)  # normal vector
V = fem.VectorFunctionSpace(msh, ("DG", 0))
qw = Function(V)
qw_expr = fem.Expression(1*grad(Th), V.element.interpolation_points())

flux =, n('+'))*dS  # heat flux
flux_form = fem.form(flux)  # fem form
flux_local = fem.assemble_scalar(flux_form)  # assemble over cell
total_flux = msh.comm.allreduce(flux_local, op=MPI.SUM)  # sum all procs