Hi. I am trying to solve the Fisher's equation using the FEniCS library. Here is the code I am using:
from fenics import *
mesh = UnitSquareMesh(32, 32)
V = FunctionSpace(mesh, "CG", 1)
g = Expression('1 - (x[0] - 0.5) * (x[0] - 0.5) - (x[1] - 0.5) * (x[1] - 0.5)', degree=2)
u = TrialFunction(V)
v = TestFunction(V)
u_k = interpolate(g, V)
u_k1 = Function(V)
dt = 0.1
a = u * v * dx + dt * inner(grad(u), grad(v)) * dx - dt * u * (1 - u) * v * dx
L = u_k * v * dx
t = 0.0
while t <= 1.8:
solve(a == L, u_k1)
u_k.assign(u_k1)
t += float(dt)
plot(u_k)
interactive()
When run it throws the following exception:
ArityMismatch: Multiplying expressions with overlapping form argument number 1, argument is v_1.
The problem is with my definition of a
:
a = u * v * dx + dt * inner(grad(u), grad(v)) * dx - dt * u * (1 - u) * v * dx
If I change it to something like
a = u * v * dx + dt * inner(grad(u), grad(v)) * dx - dt * u * v * dx
then it works (the program runs fine but this solution is obviously not the correct one). It ends with the same exception even if I change it to
a = u * v * dx + dt * inner(grad(u), grad(v)) * dx - dt * u * u * v * dx
So the problem arises if there is a term of form u * u
or v * v
or something equivalent. Why is this happening and how can I help it?
Thanks.