Convert dolfin vector to numpy array

Hello,
I’d like to convert velocity vector array in dolfin into numpy array, but it fails. In fact, I am running the ft08_navier_stokes_cylinder.py example of the fenics python interface tutorial book, although that I installed fenics and I can import and use it, I get this error in the mentioned .py example:
code:
u_.vector().array().max()
error:
AttributeErrorL: 'dolfin.cpp.la.petscVector object has no attribute ‘array’

The .array() method was removed (not sure when because it’s missing in the change log)
https://fenics.readthedocs.io/projects/dolfin/en/latest/ChangeLog.html
Instead, you can use: u_.vector().get_local().max()

2 Likes

The whole Python wrapper for Dolfin was rewritten for the 2018.1 version. There were many changes, including trying to have only one way to do things. The array() method did more or less the same as get_local(), but did not have an easy equivalent to set_local() in all cases, so it was removed

The 2019.1 release will be much smaller and mainly bring back some things that were removed in 2018.1 (or not reimplemented in the new wrapper to be precise), but it will not bring back array() as far as I know

1 Like

Thank you both for reply, it works for me now.

use u_magnitude.vector().get_local().min() and u_magnitude.vector().get_local().max()

1 Like