2.4.7 SDE with Stratonovich interpretation

This example solves a stochastic diffusion equation with Stratonovich interpretation

stratonovich
  0%|          | 0/10.0 [00:00<?, ?it/s]
Initializing:   0%|          | 0/10.0 [00:00<?, ?it/s]
  0%|          | 0/10.0 [00:04<?, ?it/s]
  0%|          | 0.005/10.0 [00:04<2:42:43, 976.83s/it]
  1%|▏         | 0.143/10.0 [00:04<05:38, 34.31s/it]
 11%|█         | 1.058/10.0 [00:05<00:42,  4.78s/it]
 34%|███▍      | 3.423/10.0 [00:05<00:10,  1.59s/it]
 72%|███████▏  | 7.224/10.0 [00:06<00:02,  1.19it/s]
 72%|███████▏  | 7.224/10.0 [00:06<00:02,  1.11it/s]
100%|██████████| 10.0/10.0 [00:06<00:00,  1.53it/s]
100%|██████████| 10.0/10.0 [00:06<00:00,  1.53it/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 6.629 seconds)