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

Getting linear and bilinear form

+1 vote

Hi, I am completely new to FEniCS, before we solved problems in MATLAB, now I am coming up with the problem, that I don't really know, how FEniCS wants the linear and bilinear form assembled, I will include my written code, which is almost 1 to 1 taken from my MATLAB program.

The error I get is about that a(u,v) and L(v). That far okay, I can follow, but how would I rewrite this in my case?

init = Expression(...) #initial data --> works to be plotted as u0
u_old = u0
[...]
u = Function(Q)
v = TestFunction(Q)
f = constant(0.0)
g = Constant(0.0)
a = -u*v*dx + dt*alpha*inner(grad(u),grad(v))*0.5*dx
L = (u*v*dx - dt*alpha*inner(grad(u),grad(v))*0.5*dx)*u_old
[...]
WHILE ...
    solve(a == L, u, bc)
    u0.assign
END

Would appreciate if anyone could help a complete beginner with this! Thanks!

asked Dec 22, 2016 by Maethor FEniCS Novice (130 points)

1 Answer

+1 vote

Hi, the problem is that you should set three functions:

u = TrialFunction(Q)
v = TestFunction(Q)
sol = Function(Q),

where your problem would be written as

a(u,v) = L(v). You have the issue of having the unknown u in L, which should only depend on v. Finally, keep your solution in the sol variable with

solve(a == L, sol, bc),

where you areactually rewriting the function u, which should have been a TrialFunction. Watch out for the reassignment during your iterations, you might have data reference problems, so you might have to define separately u_old and current u, assigning new values through

u_old.assign(u).

Let me know if something wasn't clear or if I didn't get something correctly.

Best regards

answered Jan 5, 2017 by nabarnaf FEniCS User (2,940 points)
...