Issues running example code navier_stokes_channel.py
Closed this issue · 3 comments
I am running python 3.8 and I am having an issue with the line
error = np.abs(u_e.vector().array() - u_.vector().array()).max()
The runtime error is below.
(fenicsproject) MacBook-Pro-2017-i7 Python_Codes % python navier_stokes_channel.py
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Traceback (most recent call last):
File "navier_stokes_channel.py", line 117, in
error = np.abs(u_e.vector().array() - u_.vector().array()).max()
AttributeError: 'dolfin.cpp.la.PETScVector' object has no attribute 'array'
I hit this too, a little while ago. I modified the code to
u_e = Expression(('4*x[1]*(1.0 - x[1])', '0'), degree=2)
u_e = interpolate(u_e, V)
error = np.abs(u_e.compute_vertex_values() -
u_.compute_vertex_values()).max()
print('t = %.2f: error = %.3g' % (t, error))
print('max u:', u_.compute_vertex_values().max())
just replace array() by get_local()
correction array obsolete replaced by get_local
error = np.abs(u_e.vector().get_local() - u_.vector().get_local()).max()
print('t = %.2f: error = %.3g' % (t, error))
print('max u:', u_.vector().get_local().max())