Note
Go to the end to download the full example code.
2.2.8 Setting boundary conditions
This example shows how different boundary conditions can be specified.

0%| | 0/10.0 [00:00<?, ?it/s]
Initializing: 0%| | 0/10.0 [00:00<?, ?it/s]
0%| | 0/10.0 [00:08<?, ?it/s]
0%| | 0.005/10.0 [00:08<4:29:34, 1618.29s/it]
3%|▎ | 0.295/10.0 [00:08<04:26, 27.43s/it]
3%|▎ | 0.295/10.0 [00:08<04:26, 27.47s/it]
100%|██████████| 10.0/10.0 [00:08<00:00, 1.23it/s]
100%|██████████| 10.0/10.0 [00:08<00:00, 1.23it/s]
from pde import DiffusionPDE, ScalarField, UnitGrid
grid = UnitGrid([32, 32], periodic=[False, True]) # generate grid
state = ScalarField.random_uniform(grid, 0.2, 0.3) # generate initial condition
# set boundary conditions `bc` for all axes
eq = DiffusionPDE(
bc={"x-": {"derivative": 0.1}, "x+": {"value": "sin(y / 2)"}, "y": "periodic"}
)
result = eq.solve(state, t_range=10, dt=0.005)
result.plot()
Total running time of the script: (0 minutes 8.159 seconds)