Implement assign in dolfinx


While trying to convert an old dolfin code into dolfinx, I am wondering how to replace the assign command, which I used to initialize the values of a function with the result of a previous calculation, for example :

import dolfinx

L = 1
d = L/10.
h = d/6. 

my_domain = dolfinx.mesh.create_rectangle(comm=MPI.COMM_WORLD,
                            points=((0.0, -0.5*d), (L, 0.5*d)), n=(int(L/h), int(d/h)),

V = dolfinx.fem.VectorFunctionSpace(my_domain, ("CG", 2))
u = dolfinx.fem.Function(V)
u_saved = dolfinx.fem.Function(V)

### follows a calculation: u is the solution

u_saved.assign(u) #old dolfin command which I try to replace

Many thanks in advance!


wouldn’t this just be

u_saved.x.array[:] = u.x.array

Don’t forget to update ghosts if necessary. E.g.

Could you please explain what you mean by ghost in this context?

See @dokken’s excellent tutorial: Parallel Computations with Dolfinx using MPI — MPI tutorial

1 Like