Interpolate "Real" function space

Here I have defined a “Real” function space for the macroscopic strain. And at the end I interpolate the solution:

import dolfin
import numpy as np

mesh = dolfin.RectangleMesh(
    dolfin.Point(0, 0, 0), dolfin.Point(1, 1, 0),
    2, 2,

boundaries_mf = dolfin.MeshFunction("size_t", mesh, mesh.topology().dim()-1)

V_element  = dolfin.VectorElement("CG", mesh.ufl_cell(), 2)
T_element  = dolfin.TensorElement("R", mesh.ufl_cell(), 0, symmetry=True) 
TH         = dolfin.MixedElement([V_element, T_element]) 

fs_V     = dolfin.FunctionSpace(mesh, V_element)
fs_T     = dolfin.FunctionSpace(mesh, T_element)
W        = dolfin.FunctionSpace(mesh, TH)

du = dolfin.TrialFunction(W)            
v  = dolfin.TestFunction(W)            
w  = dolfin.Function(W)

(u, eps)             = dolfin.split(w)
(delta_v, delta_eps) = dolfin.split(v)

V_CG2_out = dolfin.VectorFunctionSpace(mesh, 'CG', 2)

X_0     = dolfin.Constant((1/2.,1/2.))
X_coord = dolfin.Expression(('x[0]','x[1]'),degree=1,domain=mesh)
u_bar   = eps*(X_coord-X_0)
u_tot   = u + u_bar

d = len(u)
I = dolfin.Identity(d)               
F = I + dolfin.grad(u + u_bar)   
C = F.T*F                      

Ic =
J  = dolfin.det(F)
mu = dolfin.Constant(31.7) 

I1b = Ic*J**(-2./3.)
psi = (mu/2.0)*(I1b - 3.0) 

dx = dolfin.dx 
Pi = psi*dx

dPi = dolfin.derivative(Pi, w, v)
Jac = dolfin.derivative(dPi, w, du)

bcs = []

u_tot = dolfin.project(u_bar+u, V_CG2_out, solver_type='mumps')

dolfin.solve(dPi == 0, w, bcs, J=Jac)

func = dolfin.Function(fs_V)

I’m facing the following error:

AttributeError: 'ListTensor' object has no attribute '_cpp_object'

That comes from the last line. Can you please let me know if there is any solution for this?

Could you specify what version of DOLFIN you are running. I do not get the error-massage that you are supplying using the docker image:
Instead, the Newton solver does not converge.

Thanks for your response,

For the interpolation, might I suggest using:

func = dolfin.Function(fs_V)

1 Like

Thank you so much. It works in this way.
But if I replace func.interpolate(u) with func.interpolate(u + u_bar), or with this method func.interpolate(w.sub(0,deepcopy=True) + w.sub(1,deepcopy=True)*(X_coord-X_0)), a similar error happens:

AttributeError: 'Sum' object has no attribute '_cpp_object'

Do you know what can I do for this?
P.S. In my real problem I can’t use w.sub(0,deepcopy=True). So, is there an alternative solution to this?

I dolfin, you cannot interpolate ufl-expression, such as those you describe here. You can do this in dolfinx. However, dolfinx does not support real spaces.

I would suggest you use a projection in place of the interpolation.

1 Like

Thank you so much. It works with projection!