Hi all,
I’m trying to solve a time-dependent equation using FEniCSx with MPI. At each time step, I need to evaluate the right-hand side of the equation, which takes as input a vector-valued function vel_0. For example:
mesh = mesh.create_box(MPI.COMM_WORLD, [np.array([0, 0, 0]), np.array([1, 1, 1])], [10, 10, 10])
V = fem.functionspace(mesh, ("Lagrange", 1, (mesh.geometry.dim,)))
vel_0 = fem.Function(V)
vel_0.x.array[:] = 1.0 # initialize with constant vector value
# vector output function (RHS)
H_vel = fem.Function(V)
H_vel.x.array[:] = velocity_field(vel_0)
To use this in a time integrator, I need to extract the local part of vel_0.x.array (without ghosts). For the first time step, I do:
start, end = V.dofmap.index_map.local_range
vel_numeric = vel_0.x.array[start:end].copy()
H_vel_numeric = H_vel.x.array[start:end].copy()
My question arises for the next time steps, when uses vel_numeric and H_vel_numeric the time integrator will return a new vector vel_numeric, and I need to map it back into a dolfinx.Function to evaluate velocity_field again:
v_fem = fem.Function(V)
v_fem.x.array[start:end] = vel_numeric
v_fem.x.scatter_forward()
velocity_field(v_fem)
However, this leads to incorrect results when evaluating velocity_field(v_fem), even if vel_numeric is the same as the initial. I’m a little confused as to how to proceed.
Thanks