Note
Go to the end to download the full example code
2.8. Diffusion on a Cartesian grid
This example shows how to solve the diffusion equation on a Cartesian grid.
0%| | 0/1.0 [00:00<?, ?it/s]
Initializing: 0%| | 0/1.0 [00:00<?, ?it/s]
0%| | 0/1.0 [00:04<?, ?it/s]
1%|1 | 0.01/1.0 [00:04<08:14, 499.95s/it]
3%|3 | 0.03/1.0 [00:04<02:41, 166.66s/it]
3%|3 | 0.03/1.0 [00:05<02:41, 166.70s/it]
100%|##########| 1.0/1.0 [00:05<00:00, 5.00s/it]
100%|##########| 1.0/1.0 [00:05<00:00, 5.00s/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 5.185 seconds)