"No module named fenics" in FEniCS Docker image

1,434 views
Skip to first unread message

kevin bo

unread,
Jul 13, 2018, 11:03:12 AM7/13/18
to fenics-...@googlegroups.com
Hello, 
I installed docker toolbox and installed fenics in the dockerquickstart terminal.
I this terminal I successfully run a Fenics docker image using "fenicsproject run". 
But when I want to run a script I get the error "no module named fenics" when I do "from fenics import * "
I have absolutly no idea why. Can you help me? 
I puts some sceenshot with the mail
Thank you
Kind regards 
Image 1.png

Jan Blechta

unread,
Jul 14, 2018, 9:42:48 AM7/14/18
to kevin bo, fenics-...@googlegroups.com
Use Python 3. FEniCS does not support Python 2 any more.

Jan

kevin bo

unread,
Jul 25, 2018, 7:57:02 AM7/25/18
to fenics-...@googlegroups.com
Hello,
As proposed by Jan Blechta

kevin bo

unread,
Jul 25, 2018, 8:06:15 AM7/25/18
to fenics-...@googlegroups.com
Hello, 
As proposed by Jan Bletcha, I used Python3 instead of Python and the demo worked well. But I had a new problem when I tried to run my own code. It occured when I tried to define my  own user Expression. I made a quick exemple using the exemple of fenics tutorial ft01_poisson. Ones again I puts some sceenshots with the mail to show my error
Thank you
Kind regards 

The error :

File "/usr/local/lib/python3.5/dist-package/dolfin/function/expression.py" line 408, in __getattr
return self.parameters[name]
RecursionError : maximum recursion depth exceeded

The exemple : 

from __future__ import print_function
from fenics import *
from mshr import *

class UserExpression(Expression):
    def __init__(self, Parameter=1):
        self.Parameter = Parameter
        
    def eval(self, value, x):
        value[0] = self.Parameter*(1 + x[0]*x[0] + 2*x[1]*x[1])

    def value_shape(self):
        return (2,)


# Create mesh  
mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, 'P', 1)

# Define boundary condition
u_D = UserExpression(Parameter=1)
#u_D = Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)
    
def boundary(x, on_boundary):
    return on_boundary

bc = DirichletBC(V, u_D, boundary)

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-6.0)
a = dot(grad(u), grad(v))*dx
L = f*v*dx

# Compute solution
u = Function(V)
solve(a == L, u, bc)

# Plot solution and mesh
plot(u)
plot(mesh)

# Save solution to file in VTK format
vtkfile = File('poisson/solution.pvd')
vtkfile << u

# Compute error in L2 norm
error_L2 = errornorm(u_D, u, 'L2')

# Compute maximum error at vertices
vertex_values_u_D = u_D.compute_vertex_values(mesh)
vertex_values_u = u.compute_vertex_values(mesh)
import numpy as np
error_max = np.max(np.abs(vertex_values_u_D - vertex_values_u))

# Print errors
print('error_L2  =', error_L2)
print('error_max =', error_max)

On Sat, Jul 14, 2018 at 3:42 PM, Jan Blechta <ble...@karlin.mff.cuni.cz> wrote:
Image 1.png

Jan Blechta

unread,
Jul 25, 2018, 8:24:20 AM7/25/18
to kevin bo, fenics-...@googlegroups.com
Are you using FEniCS 2018.1.0? The tutorial has not been updated to
reflect recent changes in FEniCS interface. See
https://fenicsproject.org/docs/dolfin/dev/python/demos/biharmonic/demo_biharmonic.py.html?highlight=userexpression
how to use UserExpression.

Jan


On Wed, 25 Jul 2018 14:06:11 +0200
kevin bo <kevin....@gmail.com> wrote:

> Hello,
> As proposed by Jan Bletcha, I used Python3 instead of Python and the
> demo worked well. But I had a new problem when I tried to run my own
> code. It occured when I tried to define my own user Expression. I
> made a quick exemple using the exemple of fenics tutorial
> ft01_poisson. Ones again I puts some sceenshots with the mail to show
> my error Thank you
> Kind regards
>
> *The error :*
>
> File
> "/usr/local/lib/python3.5/dist-package/dolfin/function/expression.py"
> line 408, in __getattr return self.parameters[name]
> RecursionError : maximum recursion depth exceeded
>
> *The exemple : *

kevin bo

unread,
Jul 25, 2018, 8:51:00 AM7/25/18
to Jan Blechta, fenics-...@googlegroups.com
Hello, 
Firstly thank you very much for your quick answers.
I think I have the latest version because I reinstall everything when I had the error the fisrt time (3 weeks ago maybe).
I tried to use UserExpression instead of Expression and the error I get is the following (where UserExp is the class I have defiened)

File 'ft_01_poisson.py', line 37, in (module)
      bc =  DirichletBC(V, u_D, bondary)
File '/usr/loval/lib/python3.5/dist-packages/dolfin/fem/projection.py', line 129 in project 
      L = ufl.inner(w,v) * dx
File  '/usr/loval/lib/python3.5/dist-packages/ufl/operators.py' line 142 in inner
      if a.ufl_shape == () and b.ufl_shape ==():
File  '/usr/loval/lib/python3.5/dist-packages/ufl/coefficient.py' line 73 in ufl_shape
      return self._ufl_shape
AttributeError : 'UserExp' object has no attribute '_ufl_shape'

Jan Blechta

unread,
Jul 25, 2018, 8:58:26 AM7/25/18
to kevin bo, fenics-...@googlegroups.com
On Wed, 25 Jul 2018 14:50:58 +0200
kevin bo <kevin....@gmail.com> wrote:

> Hello,
> Firstly thank you very much for your quick answers.
> I think I have the latest version because I reinstall everything when
> I had the error the fisrt time (3 weeks ago maybe).
> I tried to use UserExpression instead of Expression and the error I
> get is the following (where UserExp is the class I have defiened)

You have to call the superclass constructor, see
https://fenicsproject.org/docs/dolfin/dev/python/demos/mixed-poisson/demo_mixed-poisson.py.html?highlight=userexpression

Jan

kevin bo

unread,
Jul 25, 2018, 9:16:08 AM7/25/18
to Jan Blechta, fenics-...@googlegroups.com
It work fine thank you very much !
Reply all
Reply to author
Forward
0 new messages