errornorm() in the tutorial won't run in parallel

Bug #887359 reported by Lizao (Larry) Li
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
FEniCS Book Project
New
Undecided
Unassigned

Bug Description

The errornum(u_e, u, Ve) code in the tutorial (page 25 in the final version) won't run in parallel.

The line which is causing the problem is:
e_Ve.vector()[:] = u_e_Ve.vector().array() - u_Ve.vector().array()

Running the code with mpirun -np 2 gives:
Traceback (most recent call last):
  File "calibrate_difference.py", line 19, in <module>
Traceback (most recent call last):
    e_Ve.vector()[:] = u_e_Ve.vector().array() - u_Ve.vector().array()
  File "/usr/lib/python2.7/dist-packages/dolfin/cpp.py", line 3601, in __setslice__
    self.__setitem__(slice(i, j, 1), values)
  File "/usr/lib/python2.7/dist-packages/dolfin/cpp.py", line 3632, in __setitem__
  File "calibrate_difference.py", line 19, in <module>
    e_Ve.vector()[:] = u_e_Ve.vector().array() - u_Ve.vector().array()
    _set_vector_items_array_of_float(self, indices, values)
RuntimeError: non matching dimensions on input
  File "/usr/lib/python2.7/dist-packages/dolfin/cpp.py", line 3601, in __setslice__
    self.__setitem__(slice(i, j, 1), values)
  File "/usr/lib/python2.7/dist-packages/dolfin/cpp.py", line 3632, in __setitem__
    _set_vector_items_array_of_float(self, indices, values)

It seems the problem is caused by the numpy array. The fix is very simple. The following does exactly the same and works in parallel:
e_Ve.vector()[:] = u_e_Ve.vector() - u_Ve.vector()

The following code demonstrates this gives the right answer:

from numpy.random import rand
from dolfin import *

N = 10
mesh = UnitInterval(N)
V = FunctionSpace(mesh, "CG", 1)
u = Function(V)
v = Function(V)
w = Function(V)
z = Function(V)
q = Function(V)

u.vector()[:] = 1.0 + rand(N+1)*1e-8
v.vector()[:] = 1.0 + rand(N+1)*1e-8
w = u - v; print(assemble(w**2*dx))
#z.vector()[:] = u.vector().array() - v.vector().array(); print(assemble(z**2*dx))
q.vector()[:] = u.vector() - v.vector(); print(assemble(q**2*dx))

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.