I try to solve viscoporoelasticity problem in FEniCS, and the variational form is obtained with minimizing the incremental potential, which is derivative(potential,u,u_) in ufl. But there is an issue when u is tensor function, and error message is “Cannot take length of non-vector expression”. Following is part of my code:
V = VectorElement(‘CG’,mesh.ufl_cell(),2)
Q = FiniteElement(‘CG’,mesh.ufl_cell(),1)
Qe = TensorElement(“DG”,mesh.ufl_cell(),0)
W = FunctionSpace(mesh,MixedElement([V,Q,Qe]))
w = Function(W, name=“Variables at current step”)
(u, p, epsv) = split(w)
w_old = Function(W, name=“Variables at previous step”)
(u_old, p_old, epsv_old) = split(w_old)
w_ = TestFunction(W)
(u_,p_,epsv_) = split(w_)
dw = TrialFunction(W)
(du,dp,depsv) = split(dw)
incremental_potential=strain_energy(u,p,epsv)dx + dtdissipation_potential((epsv-epsv_old)/dt)*dx-dot(f,u)*dx-dot(Ts, u)*ds(3)
F = derivative(incremental_potential,epsv,epsv_)
error message:
Traceback (most recent call last):
File “2D_dry_linear_visco_potential.py”, line 116, in
F = derivative(incremental_potential,epsv,epsv_)
File “/usr/lib/python3/dist-packages/dolfin/fem/formmanipulations.py”, line 82, in derivative
return ufl.derivative(form, u, du, coefficient_derivatives)
File “/usr/lib/python3/dist-packages/ufl/formoperators.py”, line 281, in derivative
argument)
File “/usr/lib/python3/dist-packages/ufl/formoperators.py”, line 167, in _handle_derivative_arguments
coefficients = tuple(coefficient)
File “/usr/lib/python3/dist-packages/ufl/core/expr.py”, line 406, in len
raise NotImplementedError(“Cannot take length of non-vector expression.”)
NotImplementedError: Cannot take length of non-vector expression.
Could anyone help me to figure it out?