I am trying to solve a rxn-diffusion problem (Diffusive Fischer Kolmogorov eqns) in the form:
the solution seems to stay the same throughout the loop, so I am worried I am missing something on that.
I primarily used the tutorial examples for the heat equation and the advection - reaction system. I would also be interested in using the Crank-Nicolson method for time-stepping, if that would be better for the problem.
Here is my minimal example code:
T = 1 # final time
num_steps = 100 # number of time steps
dt = T / num_steps # time step size
eta = 0.01 # diffusion coefficient
D_b = 0.01 # diffusion coeff
D_n = 0.002 # diffusion coeff
# Create mesh
nx = ny = 50
square_side = 10
mesh = RectangleMesh(Point(-square_side/2, -square_side/2), Point(square_side/2, square_side/2), nx, ny, "crossed")
# Define function space
P1 = FiniteElement('P', triangle, 1)
element = MixedElement([P1,P1]) # b, n
# Define function space
V = FunctionSpace(mesh, element)
# Define test functions
v_1, v_2 = TestFunctions(V)
# Define functions for scalar fields
# and split to access components
u = Function(V)
u_1, u_2 = split(u) # u_1 == b, u_2 == n
u_n = Function(V)
u_n1, u_n2 = split(u_n)
# Define expressions used in variational forms
k = Constant(dt)
D_n = Constant(D_n)
D_b = Constant(D_b)
eta = Constant(eta)
# Define variational problem
# # Define boundary condition
# assume homogeneous Neumann boundary
# conditions on the entire boundary for u1, u2
# that is, \partial u_i/ \partial n = 0
# # Define initial value
u_0 = Expression(('exp(-a*(pow(x[0], 2) + pow(x[1], 2)))', 'exp(-b*(pow(x[0], 2) + pow(x[1], 2)))'),
degree=1, a=1, b = 0.01)
u_n1, u_n2 = interpolate(u_0, V)
# Define variational problem
F_b = ((u_1-u_n1)/dt)*v_1*dx - D_b*dot(grad(u_1), grad(v_1))*dx - u_1*u_2*v_1*dx
F_n = ((u_2-u_n2)/dt)*v_2*dx - D_n*dot(grad(u_2), grad(v_2))*dx + eta*u_1*u_2*v_2*dx
F = F_b + F_n
# Time-stepping
t = 0
for n in range(num_steps):
# Update current time
t = t + dt
# Compute solution
solve(F == 0, u)
# Update previous solution
u_n.assign(u)
u_n1, u_n2 = split(u_n)