This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

demo_poison.py TypeError: Expression needs an integer argument 'degree'

+1 vote

When I ran the demo_poison.py https://fenicsproject.org/olddocs/dolfin//1.5.0/python/demo/documented/poisson/python/documentation.html#demo-pde-poisson-python-documentation
I get this error. I hope anybody can help me.

Traceback (most recent call last):
File "-/demo_poisson.py", line 54, in
f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)")
File "/usr/lib/python2.7/dist-packages/dolfin/functions/expression.py", line 157, in init
element = _auto_select_element_from_shape(value_shape, degree, cell)
File "/usr/lib/python2.7/dist-packages/dolfin/functions/expression.py", line 888, in _auto_select_element_from_shape
raise TypeError("Expression needs an integer argument 'degree' if no 'element' is provided.")
TypeError: Expression needs an integer argument 'degree' if no 'element' is provided.
Aborted

asked May 15, 2017 by benchfrooser FEniCS Novice (170 points)

1 Answer

+2 votes
 
Best answer

Add the keyword degree=2 when creating the Expression's:

f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)", degree=2)
g = Expression("sin(5*x[0])", degree=2)

That said, you are using a version of FEniCS that is not compatible with the demo you are looking at (version 1.5.0). You should make sure that the documentation you are reading matches the version of FEniCS that you are using.

answered May 16, 2017 by johannr FEniCS Expert (17,350 points)
selected May 16, 2017 by benchfrooser
...