2.8. Diffusion on a Cartesian grid

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

cartesian grid

Out:

  0%|          | 0/1.0 [00:00<?, ?it/s]
Initializing:   0%|          | 0/1.0 [00:00<?, ?it/s]
  0%|          | 0/1.0 [00:06<?, ?it/s]
  1%|1         | 0.01/1.0 [00:07<12:24, 751.68s/it]
  2%|2         | 0.02/1.0 [00:08<07:00, 428.99s/it]
  3%|3         | 0.03/1.0 [00:08<04:37, 286.01s/it]
 28%|##8       | 0.28/1.0 [00:08<00:22, 30.64s/it]
 28%|##8       | 0.28/1.0 [00:08<00:22, 30.65s/it]
100%|##########| 1.0/1.0 [00:08<00:00,  8.58s/it]
100%|##########| 1.0/1.0 [00:08<00:00,  8.58s/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 8.730 seconds)

Gallery generated by Sphinx-Gallery