2.4.3 Heterogeneous PDE

This example loads an example image and uses it as the source field for a simple reaction-diffusion equation.

heterogeneous pde
  0%|          | 0/100.0 [00:00<?, ?it/s]
Initializing:   0%|          | 0/100.0 [00:00<?, ?it/s]
  0%|          | 0/100.0 [00:17<?, ?it/s]
  0%|          | 0.00316/100.0 [00:47<418:48:44, 15077.72s/it]
  0%|          | 0.00494/100.0 [01:01<345:18:58, 12432.00s/it]
  0%|          | 0.00627/100.0 [01:01<272:03:58, 9795.00s/it]
  0%|          | 0.06755/100.0 [01:01<25:14:17, 909.19s/it]
  2%|▏         | 1.74173/100.0 [01:01<57:45, 35.26s/it]
 25%|██▌       | 25.23154/100.0 [01:01<03:02,  2.43s/it]
 25%|██▌       | 25.23154/100.0 [01:01<03:02,  2.44s/it]
100%|██████████| 100.0/100.0 [01:01<00:00,  1.63it/s]
100%|██████████| 100.0/100.0 [01:01<00:00,  1.63it/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: (1 minutes 3.027 seconds)