Dot product of constant matrix with UFL (form based) vector


I wanted to compute the sigma of periodic homogenization using user defined eps(v).
Periodic homogenization of linear elastic materials — Numerical tours of continuum mechanics using FEniCS master documentation (

def eps(dv):
return ([1,
dv[1].dx(1)]) (* 6X1 vector*)

(dv[0].dx(0) - derivate of dv[0] w.r.t x; dv[0].dx(1)- derivate of dv w.r.t y)
def sigma(v):
Em = 50e3
num = 0.2
lmbda = Enu/(1+nu)/(1-2nu)
mu = E/2/(1+nu)

return dot(C,eps(v))
(*getting typeerror in computing dot(C,eps(v)) – mentioned below *)

Ve = VectorElement(“CG”, mesh.ufl_cell(), 2)
Re = VectorElement(“R”, mesh.ufl_cell(), 0)
W = FunctionSpace(mesh, MixedElement([Ve, Re]), constrained_domain=PeriodicBoundary(vertices, tolerance=1e-10))

v_,lamb_ = TestFunctions(W)
dv, dlamb = TrialFunctions(W)
dx = Measure(‘dx’)(subdomain_data=subdomains)
F = sum([inner(sigma(dv, i), eps(v_))*dx(i) for i in range(nphases)])

(* typeerror: ComponentTensor.float returned non-float (type NotImplementedType) *)

I wanted to find general anisotropic stress using stiffness matrix (constant for each phase) and strain (which is user-defined gradient 6X3 matrix).
The test function is an argument in UFL form. So, for computing sigma(v,i), we need tensor C and eps(v) in UFL. How can I modify eps(v) and C to get dot(C,eps(v)) ?

I also tried with as_tensor and as_matrix to define C and eps(v_) but, got error (*Cannot create a tensor by joining subexpressions with different shapes *)