In [1]:
Copied!
import torch
from torchfsm.mesh import MeshGrid
from torchfsm.plot import plot_traj
from torchfsm.traj_recorder import AutoRecorder
device='cuda' if torch.cuda.is_available() else 'cpu'
L=1.0; N=128;
import torch
from torchfsm.mesh import MeshGrid
from torchfsm.plot import plot_traj
from torchfsm.traj_recorder import AutoRecorder
device='cuda' if torch.cuda.is_available() else 'cpu'
L=1.0; N=128;
In [2]:
Copied!
from torchfsm.operator import HyperDiffusion
from torchfsm.operator import HyperDiffusion
In [3]:
Copied!
hyper_diffusion=-0.0001*HyperDiffusion()
mesh=MeshGrid([(0,L,N)],device=device)
x=mesh.bc_mesh_grid()
u_0=torch.where((x >0.3) & (x < 0.5), 1.0, 0.)
traj=hyper_diffusion.integrate(
u_0=u_0,
mesh=mesh,
dt=0.01,
step=200,
trajectory_recorder=AutoRecorder(),
)
hyper_diffusion=-0.0001*HyperDiffusion()
mesh=MeshGrid([(0,L,N)],device=device)
x=mesh.bc_mesh_grid()
u_0=torch.where((x >0.3) & (x < 0.5), 1.0, 0.)
traj=hyper_diffusion.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!
mesh=MeshGrid([(0,L,N)]*2,device=device)
x,y=mesh.bc_mesh_grid()
u_0=torch.sin(2*torch.pi*x/L)*torch.cos(4*torch.pi*y/L)
traj=hyper_diffusion.integrate(
u_0=u_0,
mesh=mesh,
dt=0.01,
step=50,
trajectory_recorder=AutoRecorder(),
)
mesh=MeshGrid([(0,L,N)]*2,device=device)
x,y=mesh.bc_mesh_grid()
u_0=torch.sin(2*torch.pi*x/L)*torch.cos(4*torch.pi*y/L)
traj=hyper_diffusion.integrate(
u_0=u_0,
mesh=mesh,
dt=0.01,
step=50,
trajectory_recorder=AutoRecorder(),
)
In [6]:
Copied!
plot_traj(traj,fps=10)
plot_traj(traj,fps=10)
Out[6]:
Solution in 3D¶
In [7]:
Copied!
from torchfsm.plot import plot_traj, plot_field
from torchfsm.plot import plot_traj, plot_field
In [8]:
Copied!
mesh=MeshGrid([(0,L,N)]*3,device=device)
x,y,z=mesh.bc_mesh_grid()
u_0=torch.sin(2*torch.pi*x/L)*torch.cos(4*torch.pi*y/L)*torch.sin(6*torch.pi*z/L)
traj=hyper_diffusion.integrate(
u_0=u_0,
mesh=mesh,
dt=0.01,
step=50,
trajectory_recorder=AutoRecorder(),
)
plot_traj(traj,fps=10)
mesh=MeshGrid([(0,L,N)]*3,device=device)
x,y,z=mesh.bc_mesh_grid()
u_0=torch.sin(2*torch.pi*x/L)*torch.cos(4*torch.pi*y/L)*torch.sin(6*torch.pi*z/L)
traj=hyper_diffusion.integrate(
u_0=u_0,
mesh=mesh,
dt=0.01,
step=50,
trajectory_recorder=AutoRecorder(),
)
plot_traj(traj,fps=10)
Out[8]: