errornorm() in the tutorial won't run in parallel
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.
Running the code with mpirun -np 2 gives:
Traceback (most recent call last):
File "calibrate_
Traceback (most recent call last):
e_Ve.
File "/usr/lib/
self.
File "/usr/lib/
File "calibrate_
e_Ve.
_set_
RuntimeError: non matching dimensions on input
File "/usr/lib/
self.
File "/usr/lib/
_set_
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(
#z.vector()[:] = u.vector().array() - v.vector().array(); print(assemble(
q.vector()[:] = u.vector() - v.vector(); print(assemble(