2.2.6 Diffusion on a Cartesian grid

This example shows how to solve the diffusion equation on a Cartesian grid.

cartesian grid
  0%|          | 0/1.0 [00:00<?, ?it/s]
Initializing:   0%|          | 0/1.0 [00:00<?, ?it/s]
  0%|          | 0/1.0 [00:10<?, ?it/s]
  1%|          | 0.01/1.0 [00:10<16:51, 1021.54s/it]
 25%|██▌       | 0.25/1.0 [00:10<00:30, 40.86s/it]
 25%|██▌       | 0.25/1.0 [00:10<00:30, 40.87s/it]
100%|██████████| 1.0/1.0 [00:10<00:00, 10.22s/it]
100%|██████████| 1.0/1.0 [00:10<00:00, 10.22s/it]

from pde import CartesianGrid, DiffusionPDE, ScalarField

grid = CartesianGrid([[-1, 1], [0, 2]], [30, 16])  # generate grid
state = ScalarField(grid)  # generate initial condition
state.insert([0, 1], 1)

eq = DiffusionPDE(0.1)  # define the pde
result = eq.solve(state, t_range=1, dt=0.01)
result.plot(cmap="magma")

Total running time of the script: (0 minutes 10.298 seconds)