Question about working principle in MixedElement

Dear community,
I have a code working without problems, however, I found some un-intuitive parts. Here is my code for solving time-dependent multiphysics equations:

# Test functions
eta, psi = ufl.TestFunctions(V)

# Trial functions: 'up' will be our interst to be solved for each step
up = Function(V)
u, p = split(up) # By splitting, u and p is extracted
  
# Trial functions of the previous step: 'up_n' will store 'up' of previous step
up_n = Function(V)
up_n.sub(1).interpolate(lambda x : np.full((x.shape[1],), -trac0)) # Initial condition
u_n, p_n = split(up_n)

# Time 
for (i, dt) in enumerate(np.diff(time_step)):
    (...)
  # Solve system
   solver.solve(up)
          
   up_n.x.array[:] = up.x.array[:]

The last line ALSO updates u_n and p_n during the for loop. How can it be? Am I missing something?

Thanks for reading!

ufl.split only gives a view into up_n
so that it can be used in a variational for. The underlying dof data (.x.array) points to the same memory. You can verify this by printing the array/the length of it.

If you want a function in the sub space that is not associated with the mixed variable, use for instance u_n_new = up_n.sub(0).collapse()

2 Likes