Note
Go to the end to download the full example code.
2.4.8 SDE with Stratonovich interpretation
This example solves a stochastic diffusion equation with Stratonovich interpretation

0%| | 0/10.0 [00:00<?, ?it/s]
Initializing: 0%| | 0/10.0 [00:00<?, ?it/s]
0%| | 0/10.0 [00:05<?, ?it/s]
0%| | 0.004/10.0 [00:05<3:54:54, 1409.96s/it]
1%|▏ | 0.139/10.0 [00:05<06:41, 40.74s/it]
10%|█ | 1.021/10.0 [00:05<00:51, 5.69s/it]
33%|███▎ | 3.3/10.0 [00:06<00:12, 1.88s/it]
70%|██████▉ | 6.958/10.0 [00:06<00:02, 1.02it/s]
70%|██████▉ | 6.958/10.0 [00:07<00:03, 1.05s/it]
100%|██████████| 10.0/10.0 [00:07<00:00, 1.36it/s]
100%|██████████| 10.0/10.0 [00:07<00:00, 1.36it/s]
from pde import PDE, ScalarField, UnitGrid
class AllenCahnNoisePDE(PDE):
"""Allen–Cahn PDE with custom noise implementation."""
use_noise_variance = True
def make_noise_variance(self, state, *, backend, ret_diff=False):
"""Make function that calculates noise variance."""
noise = float(self.noise)
if ret_diff:
def noise_variance(state_data, t):
return noise * state_data**2, 2 * noise * state_data
else:
def noise_variance(state_data, t):
return noise * state_data**2
return noise_variance
eq = AllenCahnNoisePDE(
rhs={"c": "laplace(c) + c - c**3"}, noise=1.0, noise_interpretation="stratonovich"
)
state = ScalarField.random_uniform(UnitGrid([64, 64]), -1, 1)
result = eq.solve(state, t_range=10, dt=1e-3, solver="milstein")
result.plot()
Total running time of the script: (0 minutes 7.444 seconds)