Gray Scott model in FEniCS

Joined
Nov 20, 2024
Messages
1
Reaction score
0
Hallo everyone, i dont know if it is okay to ask about FEniCS on here, but since it is mostly Python Code, I Will try.
I am trying to illustrate pattern formation of reaction diffusion systems, this is my Code so far:

"""
nonlinear reaction diffusion system with Neumann conditions
implicit

python 3.11.5, fenics 2019.1.0, 12/11-24
"""
from fenics import *
import numpy as np
import matplotlib.pyplot as plt

#Define model parameters
D_u = 0.01
D_v = 0.005
F = 0.025
k = 0.06

#Time stepping parameters
t=0.0
dt = 0.1
T = 1000.0 # time step / end time

# Create mesh and define function space
mesh = UnitSquareMesh(256,256)
#mesh = RectangleMesh(Point(0.0,0.0),Point(10.0,10.0), 256, 256)

W = VectorFunctionSpace(mesh, "P", 1,2)

# set initial conditions
class InitialConditions(UserExpression):
def eval_cell(self, value, x, ufc_cell):
# u
value[0]=0.5
value[1]=0.0
if 0.48 < x[0] < 0.52 and 0.48 < x[1] < 0.52:
value[0]=0.5
value[1]=0.25

def value_shape(self):
return (2,)

# define functions
w = Function(W)
w_1 = Function(W)
# define test functions
(phi, psi) = TestFunctions(W)
dp = TrialFunction(W)

w_init = InitialConditions(degree=2)
w_1.interpolate(w_init)

# notation for easy form writing
(u, v) = as_vector((w[0], w[1]))
(u_1, v_1) = as_vector((w_1[0], w_1[1]))

#print ("time = %g, |u|_L2 = %g" %(t, sqrt(assemble(u_1*u_1*dx ))) )

# Define variational problem
F1 = (u-u_1)*phi*dx + dt*D_u*inner(nabla_grad(u), nabla_grad(phi))*dx \
+ dt*(u*v*2)*phi*dx-dt(F*(1-u))*phi*dx
F2 = (v-v_1)*psi*dx + dt*D_v*inner(nabla_grad(v), nabla_grad(psi))*dx \
- dt*(u*v*2)*psi*dx + dt((F+k)*v)*psi*dx

F = F1+F2

while t <= T-1e-14:
t+=dt
solve(F==0,w)
w_1.assign(w)
(u,v)=w.split()


print ("time = %g, |u|_L2 = %g, |v|_L2 = %g" %(t, sqrt(assemble(u*u*dx)),sqrt(assemble(v*v*dx))) )
#plot solution
pl = plot(u, cmap="viridis")
plt.colorbar(pl)
plt.draw()
plt.pause(0.05)
plt.clf()

But it is not producing the interesting patterns that you see for the Gray Scott model (I have been spending alot of time playing with the diffusion parameters, F and k).
Can anyone give any help in how I maybe Can obtain the patterns or atleast get closer?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,008
Messages
2,570,268
Members
46,867
Latest member
Lonny Petersen

Latest Threads

Top