Note
Go to the end to download the full example code.
2.4.3 Heterogeneous PDE
This example loads an example image and uses it as the source field for a simple reaction-diffusion equation.

0%| | 0/100.0 [00:00<?, ?it/s]
Initializing: 0%| | 0/100.0 [00:00<?, ?it/s]
0%| | 0/100.0 [00:07<?, ?it/s]
0%| | 0.00365/100.0 [00:20<153:39:07, 5531.67s/it]
0%| | 0.00556/100.0 [00:24<124:51:55, 4495.41s/it]
0%| | 0.00694/100.0 [00:24<100:02:13, 3601.59s/it]
0%| | 0.07316/100.0 [00:24<9:29:00, 341.66s/it]
2%|▏ | 2.39015/100.0 [00:24<17:00, 10.46s/it]
42%|████▏ | 41.99785/100.0 [00:25<00:34, 1.68it/s]
42%|████▏ | 41.99785/100.0 [00:25<00:34, 1.68it/s]
100%|██████████| 100.0/100.0 [00:25<00:00, 4.00it/s]
100%|██████████| 100.0/100.0 [00:25<00:00, 4.00it/s]
import inspect
from pathlib import Path
from pde import PDE, ScalarField
# load a field relative to the current file
package_path = Path(inspect.getfile(lambda: None)).parents[2]
img_path = package_path / "docs" / "source" / "_images" / "logo_small.png"
background = ScalarField.from_image(img_path) # create source field from image
state = ScalarField(background.grid) # generate initial condition
# define the pde
eq = PDE({"c": "laplace(c) + 0.2 * source - 0.1 * c"}, consts={"source": background})
result = eq.solve(state, t_range=100, adaptive=True)
result.plot()
Total running time of the script: (0 minutes 26.726 seconds)