Problem in passing a numpy matrix in expression

Hi Community,

I am trying to call the right Cauchy-green tensor (C) power - \alpha as follows:

from dolfin import *
import numpy as np
from scipy.linalg import fractional_matrix_power

Ue_x = Expression('( 0.5*pow(x[1], 3) + 0.5*Coef_e*sin(0.5*pi*x[1]) )', Coef_e =1.0, 
   degree = basedegree + degreeCG)        # x-component of displacment
Ue_y = Constant(0.0)                                 # y-component of displacment

Ke_1 = Expression(("0.0","alph * ( 1.5*x[1]*x[1] + 0.25*Coef_e*pi*cos(0.5*pi*x[1]) )"), Coef_e = Coef_e,
                  alph = 1.0, degree = basedegree + degreeCurl)  # the first row of displacement gradient
Ke_2 = Constant((0.0,0.0))                           # the second row of displacement gradient

F = as_tensor([[1.0 + Ke_1[0], Ke_1[1]], [Ke_2[0], 1.0 + Ke_2[1]]]) #deformation gradient
CC = F.T*F  #right cauchy-green tensor
C = np.array([[CC[0,0],CC[0,1]],[CC[1,0],CC[1,1]]]) 
FinvT = inv(F.T)
I = Identity(2) 
stress_ES = FinvT*((-1/3)*tr(fractional_matrix_power(C,1/2)*I + fractional_matrix_power(C,1/2))

When I am running this code I am getting this error:

ufl.log.UFLValueError: Invalid type conversion: [[1.0 0.0]
[0.0 1.0]] can not be converted to any UFL type.

Thank you in advance,
Ali

You can convert a NumPy matrix to a UFL matrix as follows:

from dolfin import *
from numpy import array

a = array([[1,1],
           [1,1]])

# Needed to avoid error:
a = as_matrix(a.tolist())

print(assemble(inner(a,a)*dx(domain=UnitIntervalMesh(1))))