Implement assign in dolfinx

Hello,

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)),
                            cell_type=dolfinx.mesh.CellType.triangle)

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!

Claire

wouldn’t this just be

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

Don’t forget to update ghosts if necessary. E.g. https://github.com/FEniCS/dolfinx/blob/main/python/demo/demo_navier-stokes.py#L321-L324.

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