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

Problem compiling UFL: Trace of tensor with rank != 2 is undefined

+2 votes

Hello Everyone,

Please use: ffc -l dolfin filename.ufl to run the following form file.

I have the following UFL. The UFL used to compile successfully before I added a damping term in it. You can observe that the damping term is the one with constant "eta", in both the RHS and LHS. If you remove that, it will compile. So don't worry about understanding other terms in RHS/ LHS. The problem I am solving is a dynamic problem using predictor-corrector Newmark Beta scheme. The issue is with the way "v_pred" is defined. It is the predicted velocity containing the initial velocity "v" and initial accn "a". I understand that to find trace, you at least need a matrix (i.e. a tensor of rank 2).

degree = 2
elementA = VectorElement("Lagrange", triangle, degree)
elementT = VectorElement("Quadrature", triangle, degree, 9)
elementS = VectorElement("Quadrature", triangle, degree, 3)

w = TestFunction(elementA)
du = TrialFunction(elementA)

u = Coefficient(elementA) # current displacement

f = Coefficient(elementA) # body force
g = Coefficient(elementA) # surface traction
t = Coefficient(elementT)  # vectorized tangent matrix
s = Coefficient(elementS) # vectorized stress matrix

u0 = Coefficient(elementA) # displacement prediction
v = Coefficient(elementA) #velocity
a = Coefficient(elementA) #accn

rho = Constant(triangle) # density
beta = Constant(triangle) # beta-parameter in the Newmark time stepping
dt = Constant(triangle) # time increment
eta = Constant(triangle) # Damping

def eps(u):
    return as_vector([u[i].dx(i) for i in range(2)] + [u[i].dx(j) + u[j].dx(i) for i, j in [(0, 1)]])

def sigma(s):
    return as_matrix([[s[0], s[2]], [s[2], s[1]]])

def tangent(t):
    return as_matrix([[t[i*3 + j] for j in range(3)] for i in range(3)])

#def v_pred():             # velocity prediction
#    return (v+(dt/2)*a)

# Nonlinear elastoplastic dynamic equation after discretization (with a damping term)

L += eta*tr((grad(u)/2*beta*dt)+grad(v_pred)-(grad(u0)/2*beta*dt))*tr(grad(w))*dx      #damping

# Jacobian (with the damping term)

J += eta*tr(eps(du)/2*beta*dt)*tr(grad(w))*dx    #damping
asked Sep 24, 2016 by Chaitanya_Raj_Goyal FEniCS User (4,150 points)
edited Sep 26, 2016 by Chaitanya_Raj_Goyal

1 Answer

0 votes
 
Best answer

Hi Chaitanya,
the error message is due to the term eps(du) in the last line of the .ufl file. The rank of eps(du) is equal to 1 (is a vector!) and hence you can't take the trace of that term.

answered Sep 25, 2016 by hernan_mella FEniCS Expert (19,460 points)
selected Sep 25, 2016 by Chaitanya_Raj_Goyal

Hi Hernan,

I changed that term to grad(du) instead of eps(du) and it worked. If you look at the weak form I have shown above (only at the damping terms with η), do you think it is correctly written?

Also, do I need to define 'v_pred' or is it ok to directly write $v+(dt/2)*a$ in LHS, with respect to the Newmark Scheme.

Thanks a lot!
Chaitanya

Yes to the first question and i think that it's fine just write v+(dt/2)∗a in the lhs.

...