MRaster examples 22.0.0.0
Image Processing Library
|
Simulate the brusselator on a random initial set. More...
Go to the source code of this file.
Simulate the brusselator on a random initial set.
Copyright (c) 2025, Mitchell Jay Richling https://www.mitchr.me All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The Brusselator is a reaction-diffusion model for an autocatalytic chemical reaction in space and time. This system was was proposed by Ilya Romanovich Prigogine and Rene Lefever from Universite libre de Bruxelles – hence the name. The model is given by the following equations:
\[ \begin{eqnarray} \frac{\partial u_1}{\partial t} & = & 1-(b+1)u_1+au_1^2u_2+d_1 \left(\frac{\partial^2 u_1}{\partial x_1^2}+\frac{\partial^2 u_1}{\partial x_2^2}\right) \\ \frac{\partial u_2}{\partial t} & = & bu_1-au_1^2u_2+d_2 \left(\frac{\partial^2 u_2}{\partial x_1^2}+\frac{\partial^2 u_2}{\partial x_2^2}\right) \end{eqnarray} \]
The functions \( u_1 \) and \( u_2 \) represent dimensionless concentrations of two of the reactants – an activator and an inhibitor. The values \( a \) and \( b \) represent normalized reaction rates. The values \( d_1 \) and \( d_2 \) are "diffusion coefficients", and may be combined into a single value \( d=\frac{d_2}{d_1} \) like this:
\[ \begin{eqnarray} \frac{\partial u_1}{\partial t} & = & 1-(b+1)u_1+au_1^2u_2 \left(\frac{\partial^2 u_1}{\partial x_1^2}+\frac{\partial^2 u_1}{\partial x_2^2}\right) \\ \frac{\partial u_2}{\partial t} & = & bu_1-au_1^2u_2+d \left(\frac{\partial^2 u_2}{\partial x_1^2}+\frac{\partial^2 u_2}{\partial x_2^2}\right) \end{eqnarray} \]
In the code below, we use the following values for the parameters:
\[ \begin{array}{lcc} a & = & 9 \\ b & = & \frac{98}{10} \\ d & = & 3 \end{array} \]
We use a simple finite differences method to solve the equations with a step size of \( \Delta t=0.007 \) over 3000 steps. The spatial grid has a grid size of \( h=0.3 \). The spatial second derivatives at a point \( (x,y) \) are approximated with the five point stencil":
\[ \frac{\partial^2 u_j}{\partial x_1^2}+\frac{\partial^2 u_j}{\partial x_2^2} \approx \frac{u_j(x+h, y)+u_j(x-h, y)+u_j(x, y+h)+u_j(x, y-h)-4u_j(x,y)}{h^2} \]
The code uses four images to store the state of the system at two steps. At each time step it uses two of the images to update the other two. This doubles the RAM required, but simplifies the code and eliminates the need for swapping data. At the end of the run the last updated state images are combined into a 24-bit RGB image which is written to disk.
Definition in file brusselator.cpp.