Hello everybody,
I want to assign the result ‘up’ based on mixed functions to a previous timestep. Knowing from former fenics, I naively wanted to adopt
(_ua, _pa) = up.split(deepcopy=True)
But using
_ua, _pa = up.split()
within dolfinx, I get unexpected behavior. To confirm this, an MWE is
from mpi4py import MPI
from dolfinx.generation import UnitSquareMesh
from dolfinx.cpp.mesh import CellType
from dolfinx import fem, FunctionSpace
from ufl import TestFunctions, TrialFunctions, VectorElement, FiniteElement, MixedElement, dot, grad, div, dx, lhs, rhs
import numpy as np
mesh = UnitSquareMesh(MPI.COMM_WORLD, 4, 4, CellType.triangle)
U = VectorElement("Lagrange", mesh.ufl_cell(), 1)
P = FiniteElement("Lagrange", mesh.ufl_cell(), 1)
W = FunctionSpace(mesh, MixedElement([U, P]))
(ua_n2, pa_n2) = TrialFunctions(W)
(qu, qp) = TestFunctions(W)
up = fem.Function(W)
ua_n1 = fem.Function(FunctionSpace(mesh, U))
pa_n1 = fem.Function(FunctionSpace(mesh, P))
F = (\
dot(\
ua_n2-ua_n1
+grad(pa_n2)
, qu)+
dot(
pa_n2-pa_n1
+div(ua_n2)
, qp)
)*dx
problem = fem.LinearProblem(lhs(F), rhs(F) , u=up)
problem.solve()
_ua, _pa = up.split()
print(f'ua_n1 pre: {np.shape(ua_n1.x.array)}')
print(f'pa_n1 pre: {np.shape(pa_n1.x.array)}')
print(f'u_a post: {np.shape(_ua.x.array)}')
print(f'_ua post: {np.shape(_ua.compute_point_values()[:])}')
ua_n1.x.array[:] = _ua.x.array
ua_n1.x.scatter_forward()
As you can see, scattering _ua to ua_n1 doesn’t work caused by a compatibility mismatch. Does anybody have an idea, how I definitely get the values of _ua in order to update ua_n1? It seems that the missing deepcopy-keyword is the reason for this mismatch.
Many thanks!