Set values of PETScVector from numpy array

How can I set the values of a variable of type PETScVector from a numpy array?

1 Like

This is a very general question, whose answer depend on a few things:

  • what version of fenics are you using?
  • should your code work in parallel, if so, how is the numpy array distributed?

To answer the questions above, please provide a minimal reproducible example.

  • FEniCS 2019.1.0
  • not parallel

(not reproducible) code is like this:
def func(u)
“”"
u is a PETScVector
“”"
u_t = func_returning _numpy_array()


I need to fill u with the values in u_t

u.set_local(u_t) should do it.

Thanks dokken. I passed many times by set_local in the documentation but was not sure about using it.

Thanks.