Korteweg–De Vries equation¶
The Korteweg–De Vries equation is defined on 1D space with the following form:
$$ \frac{\partial \phi}{\partial t} =-c_1\frac{\partial^3 \phi}{\partial x^3} + c_2 \phi\frac{\partial\phi}{\partial x} $$where $c_1$ and $c_2$ are constants.
In [1]:
Copied!
from torchfsm.operator import Operator, Convection, SpatialDerivative
def KortewegDeVries(dispersion_coef=1,convection_coef:float=6.0) -> Operator:
return -dispersion_coef*SpatialDerivative(0,3)+convection_coef*Convection()
# same configuration as the animation in wikipedia
kdv=KortewegDeVries(0.022**2,-1)
from torchfsm.operator import Operator, Convection, SpatialDerivative
def KortewegDeVries(dispersion_coef=1,convection_coef:float=6.0) -> Operator:
return -dispersion_coef*SpatialDerivative(0,3)+convection_coef*Convection()
# same configuration as the animation in wikipedia
kdv=KortewegDeVries(0.022**2,-1)
In [2]:
Copied!
import torch
from torchfsm.mesh import MeshGrid
from torchfsm.plot import plot_traj
from torchfsm.traj_recorder import AutoRecorder,IntervalController
device='cuda' if torch.cuda.is_available() else 'cpu'
L=2.0; N=256;
mesh=MeshGrid([(0,L,N)],device=device)
x=mesh.bc_mesh_grid()
u_0=torch.cos(torch.pi*x)
traj=kdv.integrate(
u_0=u_0,
mesh=mesh,
dt=0.001,
step=2000,
trajectory_recorder=AutoRecorder(IntervalController(10))
)
import torch
from torchfsm.mesh import MeshGrid
from torchfsm.plot import plot_traj
from torchfsm.traj_recorder import AutoRecorder,IntervalController
device='cuda' if torch.cuda.is_available() else 'cpu'
L=2.0; N=256;
mesh=MeshGrid([(0,L,N)],device=device)
x=mesh.bc_mesh_grid()
u_0=torch.cos(torch.pi*x)
traj=kdv.integrate(
u_0=u_0,
mesh=mesh,
dt=0.001,
step=2000,
trajectory_recorder=AutoRecorder(IntervalController(10))
)
In [3]:
Copied!
plot_traj(traj)
# check https://en.wikipedia.org/wiki/File:KdV_equation.gif for comparison
plot_traj(traj)
# check https://en.wikipedia.org/wiki/File:KdV_equation.gif for comparison
Out[3]: