autosim.simulations.spatiotemporal.reaction_diffusion#

Spatiotemporal reaction-diffusion simulator.

class ReactionDiffusion(parameters_range=None, output_names=None, return_timeseries=False, log_level='progress_bar', n=32, L=20, T=10.0, dt=0.1, integrator_kwargs=None)[source]#

Bases: SpatioTemporalSimulator

Simulate a two-species reaction-diffusion PDE.

The model evolves two fields \(u\) and \(v\) as:

\[\begin{split}\begin{aligned} \partial_t u &= d_1 \nabla^2 u + u - u^3 - uv^2 \\ &\quad + \beta u^2v + \beta v^3 \\ \partial_t v &= d_2 \nabla^2 v + v - u^2v - v^3 \\ &\quad - \beta u^3 - \beta uv^2 \end{aligned}\end{split}\]

The sampled parameters control the reaction coefficient \(\beta\) and diffusion scale.

Parameters:
forward_samples_spatiotemporal(n, random_seed=None, ensure_exact_n=False)[source]#

Reshape to spatiotemporal format.

Parameters:
  • n (int) – Number of samples to generate.

  • random_seed (int | None) – Random seed for reproducibility. Defaults to None.

  • ensure_exact_n (bool) – Whether to resample failed trajectories until exactly n succeed.

Returns:

A dictionary containing the reshaped spatiotemporal data, constant scalars, and constant fields.

Return type:

dict

reaction_diffusion(t, uvt, K22, d1, d2, beta, n, N)[source]#

Define the reaction-diffusion PDE in the Fourier (kx, ky) space.

Parameters:
  • t (float) – The current time step (not used).

  • uvt (ndarray) – Fourier transformed solution vector at current time step (length 2*N, 1-D).

  • K22 (ndarray) – Squared Fourier wavenumbers, shape (N,).

  • d1 (float) – The diffusion coefficient for species 1.

  • d2 (float) – The diffusion coefficient for species 2.

  • beta (float) – The reaction coefficient controlling reaction between the two species.

  • n (int) – Number of spatial points in each direction.

  • N (int) – Total number of spatial grid points (n*n).

simulate_reaction_diffusion(x, return_timeseries=False, n=32, L=20, T=10.0, dt=0.1, integrator_kwargs=None)[source]#

Simulate the reaction-diffusion PDE for a given set of parameters.

Parameters:
  • x (ndarray) – The parameters of the reaction-diffusion model. The first element is the reaction coefficient (beta) and the second element is the diffusion coefficient (d).

  • return_timeseries (bool) – Whether to return the full timeseries or just the spatial solution at the final time step. Defaults to False.

  • n (int) – Number of spatial points in each direction. Defaults to 32.

  • L (int) – Domain size in X and Y directions. Defaults to 20.

  • T (float) – Total time to simulate. Defaults to 10.0.

  • dt (float) – Time step size. Defaults to 0.1.

  • integrator_kwargs (dict | None) – Extra keyword arguments forwarded to scipy.integrate.solve_ivp.

Returns:

[u_sol, v_sol], the spatial solution of the reaction-diffusion PDE, either as a timeseries or at the final time point of return_timeseries is False.

Return type:

tuple[ndarray, ndarray]