Swift-Hohenberg Equation¶
The Swift–Hohenberg equation is a partial differential equation noted for its pattern-forming behaviour. It is defined as:
$$ \frac{\partial \phi}{\partial t} = r \phi - (1 + \Delta)^2 \phi + \phi^2 - \phi^3 $$Solution in 1D¶
In [1]:
Copied!
from torchfsm.operator import Operator, Laplacian, ImplicitSource, HyperDiffusion
def SwiftHohenberg(r:float) -> Operator:
return -HyperDiffusion()-2*Laplacian()+ImplicitSource(lambda phi:r*phi-phi+phi**2-phi**3)
swift_hohenberg = SwiftHohenberg(r=2)
from torchfsm.operator import Operator, Laplacian, ImplicitSource, HyperDiffusion
def SwiftHohenberg(r:float) -> Operator:
return -HyperDiffusion()-2*Laplacian()+ImplicitSource(lambda phi:r*phi-phi+phi**2-phi**3)
swift_hohenberg = SwiftHohenberg(r=2)
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=20.0*torch.pi; 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=20.0*torch.pi; N=100;
In [3]:
Copied!
mesh=MeshGrid([(0,L,N)],device=device)
x=mesh.bc_mesh_grid()
u_0=truncated_fourier_series(
mesh=mesh,
freq_threshold=10,
normalize_mode="-1_1",
)
traj=swift_hohenberg.integrate(
u_0=u_0,
mesh=mesh,
dt=0.1,
step=200,
trajectory_recorder=AutoRecorder(),
)
mesh=MeshGrid([(0,L,N)],device=device)
x=mesh.bc_mesh_grid()
u_0=truncated_fourier_series(
mesh=mesh,
freq_threshold=10,
normalize_mode="-1_1",
)
traj=swift_hohenberg.integrate(
u_0=u_0,
mesh=mesh,
dt=0.1,
step=200,
trajectory_recorder=AutoRecorder(),
)
In [4]:
Copied!
plot_traj(traj,animation=False)
plot_traj(traj,animation=False)
Solution in 2D¶
In [5]:
Copied!
mesh=MeshGrid([(0,L,N)]*2,device=device)
x=mesh.bc_mesh_grid()
u_0=truncated_fourier_series(
mesh=mesh,
freq_threshold=10,
normalize_mode="-1_1",
)
traj=swift_hohenberg.integrate(
u_0=u_0,
mesh=mesh,
dt=0.1,
step=50,
trajectory_recorder=AutoRecorder(),
)
mesh=MeshGrid([(0,L,N)]*2,device=device)
x=mesh.bc_mesh_grid()
u_0=truncated_fourier_series(
mesh=mesh,
freq_threshold=10,
normalize_mode="-1_1",
)
traj=swift_hohenberg.integrate(
u_0=u_0,
mesh=mesh,
dt=0.1,
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!
mesh=MeshGrid([(0,L,N)]*3,device=device)
x=mesh.bc_mesh_grid()
u_0=truncated_fourier_series(
mesh=mesh,
freq_threshold=10,
normalize_mode="-1_1",
)
traj=swift_hohenberg.integrate(
u_0=u_0,
mesh=mesh,
dt=0.1,
step=50,
trajectory_recorder=AutoRecorder(),
)
mesh=MeshGrid([(0,L,N)]*3,device=device)
x=mesh.bc_mesh_grid()
u_0=truncated_fourier_series(
mesh=mesh,
freq_threshold=10,
normalize_mode="-1_1",
)
traj=swift_hohenberg.integrate(
u_0=u_0,
mesh=mesh,
dt=0.1,
step=50,
trajectory_recorder=AutoRecorder(),
)
In [8]:
Copied!
plot_traj(traj,animation=True,)
plot_traj(traj,animation=True,)
Out[8]: