KPP Fisher Equation¶
The Fisher-KPP equation is a reaction-diffusion equation that can be used to model population growth and wave propagation. It is given by:
$$ \frac{\partial \phi}{\partial t} = \nu \nabla^2 \phi + r \phi (1 - \phi) $$Solution in 1D¶
In [1]:
Copied!
from torchfsm.operator import Operator, Laplacian, ImplicitSource
def KPPFisher(nu:float,r:float) -> Operator:
return nu*Laplacian()+r*ImplicitSource(lambda phi:phi*(1-phi))
from torchfsm.operator import Operator, Laplacian, ImplicitSource
def KPPFisher(nu:float,r:float) -> Operator:
return nu*Laplacian()+r*ImplicitSource(lambda phi:phi*(1-phi))
In [2]:
Copied!
import torch
from torchfsm.mesh import MeshGrid
from torchfsm.traj_recorder import AutoRecorder
from torchfsm.plot import plot_traj
from torchfsm.field import truncated_fourier_series
device='cuda' if torch.cuda.is_available() else 'cpu'
L=10.0; N=100;
import torch
from torchfsm.mesh import MeshGrid
from torchfsm.traj_recorder import AutoRecorder
from torchfsm.plot import plot_traj
from torchfsm.field import truncated_fourier_series
device='cuda' if torch.cuda.is_available() else 'cpu'
L=10.0; N=100;
In [3]:
Copied!
kpp_fisher = KPPFisher(nu=0.1, r=0.01)
mesh=MeshGrid([(0,L,N)],device=device)
x=mesh.bc_mesh_grid()
u_0=truncated_fourier_series(
mesh=mesh,
freq_threshold=5.0,
normalize_mode="0_1",
)
traj=kpp_fisher.integrate(
u_0=u_0,
mesh=mesh,
dt=0.01,
step=200,
trajectory_recorder=AutoRecorder(),
)
kpp_fisher = KPPFisher(nu=0.1, r=0.01)
mesh=MeshGrid([(0,L,N)],device=device)
x=mesh.bc_mesh_grid()
u_0=truncated_fourier_series(
mesh=mesh,
freq_threshold=5.0,
normalize_mode="0_1",
)
traj=kpp_fisher.integrate(
u_0=u_0,
mesh=mesh,
dt=0.01,
step=200,
trajectory_recorder=AutoRecorder(),
)
In [4]:
Copied!
plot_traj(traj,animation=False)
plot_traj(traj,animation=False)
Solution in 2D¶
In [5]:
Copied!
kpp_fisher = KPPFisher(nu=0.01, r=10.0)
mesh=MeshGrid([(0,L,N)]*2,device=device)
x=mesh.bc_mesh_grid()
u_0=truncated_fourier_series(
mesh=mesh,
freq_threshold=5,
normalize_mode="0_1",
)
traj=kpp_fisher.integrate(
u_0=u_0,
mesh=mesh,
dt=0.01,
step=50,
trajectory_recorder=AutoRecorder(),
)
kpp_fisher = KPPFisher(nu=0.01, r=10.0)
mesh=MeshGrid([(0,L,N)]*2,device=device)
x=mesh.bc_mesh_grid()
u_0=truncated_fourier_series(
mesh=mesh,
freq_threshold=5,
normalize_mode="0_1",
)
traj=kpp_fisher.integrate(
u_0=u_0,
mesh=mesh,
dt=0.01,
step=50,
trajectory_recorder=AutoRecorder(),
)
In [6]:
Copied!
plot_traj(traj,animation=True)
plot_traj(traj,animation=True)
Out[6]:
Solution in 3D¶
In [7]:
Copied!
kpp_fisher = KPPFisher(nu=0.01, r=10.0)
mesh=MeshGrid([(0,L,N)]*3,device=device)
x=mesh.bc_mesh_grid()
u_0=truncated_fourier_series(
mesh=mesh,
freq_threshold=2,
normalize_mode="0_1",
)
traj=kpp_fisher.integrate(
u_0=u_0,
mesh=mesh,
dt=0.01,
step=50,
trajectory_recorder=AutoRecorder(),
)
kpp_fisher = KPPFisher(nu=0.01, r=10.0)
mesh=MeshGrid([(0,L,N)]*3,device=device)
x=mesh.bc_mesh_grid()
u_0=truncated_fourier_series(
mesh=mesh,
freq_threshold=2,
normalize_mode="0_1",
)
traj=kpp_fisher.integrate(
u_0=u_0,
mesh=mesh,
dt=0.01,
step=50,
trajectory_recorder=AutoRecorder(),
)
In [8]:
Copied!
plot_traj(traj,animation=True)
plot_traj(traj,animation=True)
Out[8]: