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

Simple code doesn't work?

0 votes

I have just reinstalled the newest version of FEniCS, and now even the simplest code example doesn't work. Here is the test code:

from dolfin import *
from math import *
from numpy import *
import datetime

mesh = UnitSquareMesh(6, 4)
V = FunctionSpace(mesh, 'Lagrange', 1)

# Define boundary conditions
u0 = Expression('1 + x[0]*x[0] + 2*x[1]*x[1]')
def u0_boundary(x, on_boundary):
    return on_boundary

bc = DirichletBC(V, u0, u0_boundary)

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-6.0)
b=f*v*dx
a = inner(nabla_grad(u), nabla_grad(v))*dx

Here is the error:

[sobolev:26044] *** Process received signal *** [sobolev:26044]
Signal: Segmentation fault (11) [sobolev:26044] Signal code: Address
not mapped (1) [sobolev:26044] Failing at address: (nil)
[sobolev:26044] [ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0x10340)
[0x7f4995317340] [sobolev:26044] [ 1]
/usr/lib/python2.7/dist-packages/numpy/core/multiarray.so(+0xaf2b1)
[0x7f49940b32b1] [sobolev:26044] [ 2]
/usr/lib/python2.7/dist-packages/numpy/core/_dotblas.so(+0x1eac)
[0x7f4993940eac] [sobolev:26044] [ 3] python(PyEval_EvalFrameEx+0x425)
[0x52c6d5] [sobolev:26044] [ 4] python(PyEval_EvalCodeEx+0x2a4)
[0x55c594] [sobolev:26044] [ 5] python(PyEval_EvalCode+0x32)
[0x5b7392] [sobolev:26044] [ 6] python() [0x469663] [sobolev:26044] [
7] python(PyRun_FileExFlags+0x92) [0x4699e3] [sobolev:26044] [ 8]
python(PyRun_SimpleFileExFlags+0x2ee) [0x469f1c] [sobolev:26044] [ 9]
python(Py_Main+0xb5e) [0x46ab81] [sobolev:26044] [10]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)
[0x7f4994f62ec5] [sobolev:26044] [11] python() [0x57497e]
[sobolev:26044] *** End of error message *** Segmentation fault (core
dumped)

The code can run without the last line

a = inner(nabla_grad(u), nabla_grad(v))*dx

I don't know why this line is wrong?

asked Aug 21, 2014 by vincehouhou FEniCS Novice (540 points)

1 Answer

+3 votes
 
Best answer

Hi, the cause of the error is that by importing all from numpy your code uses inner from numpy and not the one from dolfin. There are more clashes like this e.g. sqrt (in dolfin, math and numpy), dot (in dolfin and numpy). Thus the fix is for example

from dolfin import *
import math
import numpy
import datetime
# Rest of your code 
answered Aug 21, 2014 by MiroK FEniCS Expert (80,920 points)
selected Aug 21, 2014 by vincehouhou
...