Demo code not working using my installation of FEniCS


My name is Athul Shaji, a researcher from India. I have the following problem while using FEniCS.

I had installed FEniCS in Ubuntu 18.04.1. The laptop has 8GB RAM and Core i3 7100 processor. I am getting error messages the demo codes provided the FEniCS webpage is run. The IDE used is Spyder. I am not using Anaconda package. The different packages like Spyder, Numpy, Scipy, and Matplotlib are installed using pip. I have installed FEniCS project 2018.1.0.

The code which I tried to run is as follows:

import matplotlib.pyplot as plt
from fenics import *

class DirichletBoundary(SubDomain):
    def inside(self, x, on_boundary):
        return abs(x[0] - 1.0) < DOLFIN_EPS and on_boundary

mesh = UnitSquareMesh(32, 32)
File("mesh.pvd") << mesh

V = FunctionSpace(mesh, "CG", 1)

g = Constant(1.0)
bc = DirichletBC(V, g, DirichletBoundary())

u = Function(V)
v = TestFunction(V)
f = Expression("x[0]*sin(x[1])", degree=2)
F = inner((1 + u**2)*grad(u), grad(v))*dx - f*v*dx

solve(F == 0, u, bc,

plot(u, title="Solution")

plot(grad(u), title="Solution gradient")
file = File("nonlinear_poisson.pvd")
file << u

The error message obtained when I ran the program is as follows:

athul@athul-X510UA:~/Desktop$ python3 
Calling FFC just-in-time (JIT) compiler, this may take some time.
Traceback (most recent call last):
  File "", line 134, in <module>
    V = FunctionSpace(mesh, "CG", 1)
  File "/usr/lib/python3/dist-packages/dolfin/function/", line 33, in __init__
    self._init_convenience(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/dolfin/function/", line 100, in _init_convenience
    self._init_from_ufl(mesh, element, constrained_domain=constrained_domain)
  File "/usr/lib/python3/dist-packages/dolfin/function/", line 43, in _init_from_ufl
  File "/usr/lib/python3/dist-packages/dolfin/jit/", line 47, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/dolfin/jit/", line 97, in ffc_jit
    return ffc.jit(ufl_form, parameters=p)
  File "/usr/lib/python3/dist-packages/ffc/", line 217, in jit
    module = jit_build(ufl_object, module_name, parameters)
  File "/usr/lib/python3/dist-packages/ffc/", line 133, in jit_build
  File "/usr/lib/python3/dist-packages/dijitso/", line 165, in jit
    header, source, dependencies = generate(jitable, name, signature, params["generator"])
  File "/usr/lib/python3/dist-packages/ffc/", line 66, in jit_generate
    prefix=module_name, parameters=parameters, jit=True)
  File "/usr/lib/python3/dist-packages/ffc/", line 150, in compile_element
    prefix, parameters, jit)
  File "/usr/lib/python3/dist-packages/ffc/", line 190, in compile_ufl_objects
    ir = compute_ir(analysis, prefix, parameters, jit)
  File "/usr/lib/python3/dist-packages/ffc/", line 168, in compute_ir
    for e in elements]
  File "/usr/lib/python3/dist-packages/ffc/", line 168, in <listcomp>
    for e in elements]
  File "/usr/lib/python3/dist-packages/ffc/", line 200, in _compute_element_ir
    fiat_element = create_element(ufl_element)
  File "/usr/lib/python3/dist-packages/ffc/", line 99, in create_element
    element = _create_fiat_element(ufl_element)
  File "/usr/lib/python3/dist-packages/ffc/", line 192, in _create_fiat_element
    element = ElementClass(fiat_cell, degree)
  File "/usr/lib/python3/dist-packages/FIAT/", line 54, in __init__
    poly_set = polynomial_set.ONPolynomialSet(ref_el, degree)
  File "/usr/lib/python3/dist-packages/FIAT/", line 174, in __init__
    dv = expansion_set.tabulate_derivatives(degree, pts)
  File "/usr/lib/python3/dist-packages/FIAT/", line 260, in tabulate_derivatives
    data = _tabulate_dpts(self._tabulate, 2, n, order, numpy.array(pts))
  File "/usr/lib/python3/dist-packages/FIAT/", line 102, in _tabulate_dpts
  File "/usr/lib/python3/dist-packages/FIAT/", line 48, in form_derivative
    out = [sympy.diff(F, X[j]) for j in range(D)]
  File "/usr/lib/python3/dist-packages/FIAT/", line 48, in <listcomp>
    out = [sympy.diff(F, X[j]) for j in range(D)]
  File "/home/athul/.local/lib/python3.6/site-packages/sympy/core/", line 1979, in diff
    return Derivative(f, *symbols, **kwargs)
  File "/home/athul/.local/lib/python3.6/site-packages/sympy/core/", line 1121, in __new__
    it cannot be differentiated.''' % expr))
Since there are no variables in the expression [0, 0], it cannot be

Please help me with this error. Thank you.

Athul Shaji


Your post is difficult to read because you have not formatted the code correctly - please do that (Read before posting: How do I get my question answered?).

Also, I do not see an error message, only a RuntimeWarning.

Note that installing NumPy via pip will most likely not work if you are using the FEniCS Ubuntu packages, because these packages are already linked to a specific version of NumPy.

Hi, I have edited the code so it is more readable. Please have a look at the error message generated when the I tried to execute the code from the terminal of the Linux machine. Looking forward to your reply.

Thank you.


Your example works just fine on my Linux machine, version 2018.1.0. You may want to take a look at the FEniCS support group on Google (!forum/fenics-support) where people have reported the same bug. Personally, I would recommend installing FEniCS either using Anaconda or Docker.

Good luck,


Hi Rudy,

Have you installed FEniCS using Anaconda or Docker? If yes, then I will try to install the software in the same manner in my machine.

Athul Shaji


Choosing which prebuilt package you adopt for your research is a very personal choice as both Docker and Anaconda installations work great on Linux machines (including Ubuntu 18.04). My recommendation for the less experienced user is Anaconda.


Rudy, thanks for the reply.

The problem is the SymPy version you have installed in /home/athul/.local/. This version has a regression bug and does not work with FEniCS 2018.1.0. This is a common problem and the simplest fix is to remove the installation of SymPy in /home/athul/.local/.