How did the Function object change in dolfinx v0.9.0?

I am going trough this FEniCSx Tutorial:
https://bleyerj.github.io/comet-fenicsx/tours/linear_problems/axisymmetric_elasticity/axisymmetric_elasticity.html

and I ran into a problem with this part of the code:

u = fem.Function(V, name="Displacement")

ur = u.sub(0).collapse()
ur_FEM = ur.vector.array[bottom_dofsx]

It returns the error

Traceback (most recent call last):
  File "/home/codes/axis_symmetry.py", line 119, in <module>
    ur_FEM = ur.vector.array[bottom_dofsx]
             ^^^^^^^^^
AttributeError: 'Function' object has no attribute 'vector'

The code is written for version 0.8 and I want to run it using version 0.9, so I expect there to be a breaking change for this release. None of the changes listed at Release v0.9.0 · FEniCS/dolfinx · GitHub seem to help me. How did it change and how can I update the code to make it work for 0.9?

There is a modified release note coming up:

which explains it in the following way:

PETSc object memory management {#petsc-mem}

Main Contributors: Umberto Villa, Jack Hale and Garth N. Wells

Removal of dolfinx.fem.Function.vector

To avoid extra MPI communicator duplication when re-using the underlying dolfinx.la.Vector the PETSc.Vec wrapper in DOLFINx now lives in dolfinx.fem.Function.x.petsc_vec.

Note on memory management

A note on the memory management of all PETSc objects created with DOLFINx has been added to relevant functions.

Relevant pull requests

2 Likes

Thank you for this fast answer!