Can't run example: KeyError: 'Must supply element or degree'

Hello!
I’ve installed fenics on Ubuntu system from ppa repository following instructions from the site. I’m trying to run the basic Poisson example but getting an error:

$ python3 demo_poisson.py 
Traceback (most recent call last):
  File "demo_poisson.py", line 54, in <module>
    f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)")
  File "/usr/lib/python3/dist-packages/dolfin/function/expression.py", line 409, in __init__
    raise KeyError("Must supply element or degree")
KeyError: 'Must supply element or degree'

Am I missing something?

Yes. Looks like you’ve copied an old example from a previous version of dolfin.

You need to supply the polynomial approximation order degree=2 which sets up a CG space approximation for you, or a specific finite element element=some_element_of_your_choosing.

1 Like