Demo code not working using my installation of FEniCS

Hello,

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,
      solver_parameters={"newton_solver":{"relative_tolerance":1e-6}})

plt.figure()
plot(u, title="Solution")

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

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

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

Please help me with this error. Thank you.

Athul Shaji

Hi,

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.

Athul,

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 (https://groups.google.com/forum/?nomobile=true#!forum/fenics-support) where people have reported the same bug. Personally, I would recommend installing FEniCS either using Anaconda or Docker.

Good luck,

Rudy.

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

Athul,

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.

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/.

i am getting error like this while running demo code
hemanth@CMS:~/Documents$ python3 demo_cahn-hilliard.py
Traceback (most recent call last):
File “demo_cahn-hilliard.py”, line 63, in
ME = V*V
TypeError: unsupported operand type(s) for *: ‘FunctionSpace’ and ‘FunctionSpace’

I am experiencing the same issue as OP on Ubuntu 18.04, but with the system version of Sympy.