This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

eigen value of strain tensor and energy density

0 votes

Hi, I am trying to find energy density from eigen value of strain tensor. I am getting error: numpy.linalg.linalg.LinAlgError: 0-dimensional array given. Array must be at least two-dimensional

Thanks in advance.

from dolfin import *
import numpy as np
from numpy import linalg as LA
mesh = UnitSquareMesh(10,10)
V = VectorFunctionSpace(mesh, 'CG',1)

u,v,du = TrialFunction(V), TestFunction(V), Function(V)

def eps(u):
    return sym(grad(u))
lmbda = 121.15e3
mu = 80.77e3
def sigma(u):
    return 2.0*mu*eps(u) + lmbda*tr(eps(u))*Identity(2)

Eu = inner(grad(v),sigma(u))*dx 

class left(SubDomain):
    def inside(self,x,on_boundary):
        tol = 1e-10
        return abs(x[0]) < tol and on_boundary

class right(SubDomain):
    def inside(self,x,on_boundary):
        tol = 1e-10
        return abs(x[0]-1.0) < tol and on_boundary


Left = left()
Right = right()
u_L = Expression("t",t = 1.0)
fix_b_left_x =  DirichletBC(V.sub(1),Constant(0.0),Left)
fix_b_left_y =  DirichletBC(V.sub(0),Constant(0.0),Left)

disp_right = DirichletBC(V.sub(0),u_L, Right) # check after implimentation
bc_disp = [fix_b_left_x,fix_b_left_y, disp_right ]

solve(lhs(Eu)==rhs(Eu), du, bc_disp)


plot(du, interactive = True)

F = FunctionSpace(mesh, 'DG', 0)

def eigVal(du):
    return LA.eigvals(eps(du))
k=0.0


for i in range(0,2):
   k=k+ (0.5* (eigval[i] + abs(eigval[i]) ) )**2
   print k
def histN(u):
    return 0.5*lmbda*( 0.5*(sum(eigVal(du)) + abs(sum(eigVal(du)))) )**2  + mu*k


M3 = histN(du)
M3 = project(M3, F)

plot(M3, interactive = True)
asked Jun 26, 2017 by hirshikesh FEniCS User (1,890 points)
edited Jun 26, 2017 by hirshikesh

Hi, eps(du) is not a numpy array which eigvals expects, cf. type(eps(du). The following threads might be relevant: ufl-based, numpy-based.

Thanks for the help.

...