Solving for residual stresses in plasticity on a subdomain

In my plasticity calculations, in a first step I consider plastic loading and subsequent elastic unloading. Then, in a second step I need to remove a part of the domain (the forming tool) and compute the residual stresses from the plastic tensor from the first step.

In a natural approach I define a function space on the subdomain, i.e.,

V_sub = df.VectorFunctionSpace(df.SubMesh(mesh, subdomains, 3), 'CG', 2)

and solve the elasticity equation in this space. However, the plastic tensor p is still defined on the whole mesh, more precisely, it is an element of W, where

W = df.FunctionSpace(mesh, df.VectorElement('Quadrature', mesh.ufl_cell(), degree = 2, dim=4, quad_scheme='default'))

Now, defining my right hand side as

L = df.inner(sigma(as_3D_tensor(p)), eps(psi))*dxm,

where psi is the test function, sigma and eps compute the stresses and strains, respectively, and

dxm = df.dx(metadata = {'quadrature_degree': 2, 'quadrature_scheme': 'default'})

yields an error:

TypeError: ‘<’ not supported between instances of ‘Mesh’ and ‘Mesh’

So, it seems that I need to somehow restrict the plastic tensor p to the subdomain. However, the interpolate method does not work with quadrature functions…