### Problem with running FEniS

45
views
0
15 days ago by
I followed the instructions on https://fenicsproject.org/download/ to install FEniCS on Ubuntu (I am using Ubuntu 18.04). It seems everything went well. Even I tested it with python2 -c 'import fenics'.
But now when I run the following code:
from _future_ import print_function
from fenics import *
import matplotlib.pyplot as plt

# Create mesh and define function space
mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, 'P', 1)

# Define boundary condition
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)
L = f*v*dx

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

# Plot solution and mesh
plot(u)
plt.show()
plot(mesh)
plt.show()

# 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)

I got the error:
import matplotlib.pyplot as plt
ImportError: No module named matplotlib.pyplot
Aborted (core dumped)
I guess the problem is from the installation, because in another run which I use abs() function I got the following error:
File "/usr/lib/python2.7/dist-packages/dolfin/functions/expression.py", line 679, in _new_
mpi_comm=kwargs.get("mpi_comm"))
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/expressions.py", line 266, in compile_expressions
mpi_comm=mpi_comm)
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/expressions.py", line 183, in compile_expression_code
mpi_comm=mpi_comm)
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 70, in mpi_jit
return local_jit(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/compilemodule.py", line 603, in compile_extension_module
**instant_kwargs)
File "/usr/lib/python2.7/dist-packages/instant/build.py", line 577, in build_module
build_system)
File "/usr/lib/python2.7/dist-packages/instant/build.py", line 170, in recompile
instant_error(msg % (cmd, compile_log_filename_dest))
File "/usr/lib/python2.7/dist-packages/instant/output.py", line 96, in instant_error
raise RuntimeError(text)
RuntimeError: In instant.recompile: The module did not compile with command 'make VERBOSE=1', see '/home/amireh/.cache/instant/python2.7/error/dolfin_794ba6db911c146e641187a991c4ff98c8807542/compile.log'
Aborted (core dumped)

I removed and installed FEniCS many times but the problem remain yet.
Any help is highly appreciated.
Community: FEniCS Project
You should install the matplotlib module. So open a terminal and write pip install matplotlib --user.
written 15 days ago by Sami Ben Romdhane