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

Error with UFL form

0 votes

Hello,

I am trying to modifiy the undocumented elastodynamics demo which deals with a nonlinear weak form, to a linear weak form. However, post editing, I am stuck at the very first step, i.e., compiling the UFL form file. I have the following UFL but it won't compile.

element = VectorElement("Lagrange", triangle, 1)
DG0     = FiniteElement("Discontinuous Lagrange", triangle, 0)

r = TestFunction(element)
u = TrialFunction(element)
f  = Coefficient(element)  # body forces

# Fields from previous time step
u0      = Coefficient(element)   # displacement
v0      = Coefficient(element)   # velocity
a0      = Coefficient(element)   # acceleration

# Material parameters
rho     = Coefficient(DG0)  # mass density
lmbda   = Coefficient(DG0)  # Lame coefficient
mu      = Coefficient(DG0)  # Lame coefficient

# Time stepping parameters (Newmark scheme)
beta    = Coefficient(DG0)
gamma   = Coefficient(DG0)
dt      = Coefficient(DG0)

# Stress tensor
def sigma(r):
    return 2.0*mu*sym(grad(r)) + lmbda*tr(sym(grad(r)))*Identity(r.geometric_dimension())

# Acceleration at t_n+1
def ddot_u(u):
    return ((u - u0 - dt*v0)/(beta*dt*dt) - a0*(1 - 2*beta)/(2*beta))

a = (rho*inner(ddot_u(u), r) + inner(grad(r), sigma(u)))*dx
L = inner(r, f)*dx 

I get the following error:

Compiler stage 1: Analyzing form(s)

*** FFC: Adding expressions with non-matching form arguments () vs (Argument(VectorElement('Lagrange', Domain(Cell('triangle', 2),
label=None, data=None), 1, dim=2, quad_scheme=None), 1, None),).

asked Jun 10, 2016 by Chaitanya_Raj_Goyal FEniCS User (4,150 points)
edited Jun 12, 2016 by Chaitanya_Raj_Goyal

1 Answer

0 votes
 
Best answer

Instead of defining a and L separately, I tried the following and it worked. However, I don't completely understand why. If any one could shed some light on this, then this answer would be complete.

eq = (rho*inner(ddot_u(u), r) + inner(sigma(u), sym(grad(r))))*dx - inner(f, r)*dx

a = lhs(eq)
L = rhs(eq)
answered Jun 10, 2016 by Chaitanya_Raj_Goyal FEniCS User (4,150 points)
selected Jun 11, 2016 by Chaitanya_Raj_Goyal

The error message appears because the lhs must be bilinear, i.e., the form a must be contain only test and trial functions. In your case, a isn't a bilinear form due to the term ddot_u(u) which depend not only on u.

Thanks Hernan!

...