How to do Gray-Scott - the base model

"It is suggested that a system of chemical substances, called morphogens, reacting together and diffusing through a tissue, is adequate to account for the main phenomena of morphogenesis."

Alan Turing

Seriously! This post is about how to model a reaction diffusion in CATIA with Visual Scripting. within all the reaction diffusion models, the 1st to make a try is the Gray-Scott model. I won't go deep into philosophy, yet, after this post, I hope you can do it for yourself an enjoy the results as much as I did...

3dxml at the bottom

1 What you need to know before

I had a good search in the web. I recommend those sites about Reaction Diffusion

  • Below explains the logic of the equations that will be used. must understand all...(most important article for me)

Reaction-Diffusion Tutorial (karlsims.com)

 
  • Below is more in details, paragraph "formula"

Reaction-Diffusion by the Gray-Scott Model: Pearson's Parameterization at MROB

 
  • This one is to feel the extreme sensitivity of the parameters. It was hell to find some for me.

WebGL Gray-Scott Explorer at MROB

 
  • for hardcore readers

Reaction–diffusion system - Wikipedia

 
  • for super hardcore readers (which I am not...) Alan Turing's paper on biology: "the-chemical basis of morphogenesis" published in 1952

2 Setup python in CATIA

To replay my model, you need to setup Python in CATIA. It requires an additional license to Visual Scripting. This license is called "Templates, Optimization and Rules Designer". With this license, you can do Python scripts within Visual Scripting.

To set up the code, I used this version(3.7.9) which is supported by CATIA and downloaded Windows x86-64 MSI installer

Python Release Python 3.7.9 | Python.org

 

With PIP, I installed the external library numpy (for calculations with lists and tables). So, in Command Prompt, type "pip install numpy"

Then specify the preference pages of CATIA as follows to take into account numpy:

  • From Me > Preferences AppPreferences in the 3D Modeling > Multidiscipline Automated Engineering > Basics > Python Scripts, select Enable the use of external Python packages.
  • Select the file directory where the installed external Python packages are stored (numpy).
    • In my case, it was in C:\\Users\\cbt\\AppData\\Local\\Programs\\Python\\Python37\\Lib\\site-packages

3 About Modeling

in this post I will use on a simple flat square surface and will share how to do with "complex surfaces" in another one.

overall size looks not so big

Here is my cooking recipe.

1. Create a Flat surface and divide it into little square surfaces.

Basically, I pixelized the surface 50X50 in the attached 3dxml. This surface is the "skin" to bear the Reaction Diffusion (RD) pattern. but the more the pixels, the better the effect. 150X150 is very good to me but it will take time to calculate.

2. I flatten the matrix of pixels, to get a single list. I found it easier to read.

3. Create a list of 1s of the size of the list of pixels, by using functions size and sequence. It corresponds to the A substrate's concentration. (it is supposed to be between 0 and 1, but in my model, it could go negative or diverge, so I must be careful on the Gray Scott parameters)

4. Create a list of 0s of the size of the list of pixels. it corresponds to the B substrate's concentration.

5. Initiate the reaction with a few B. for this, I created a square in the middle and set 1 in the B list at the index of

the pixels that are within the middle rectangle.

6. To prepare the calculation of the Laplacian, I select the neighboring points of all the points around the square. in this model, I take only the side pixels, not the corner ones.

maybe a link to understand Laplacian/Convolution (learnt at 18, "understood..." at 49...punaise):

 A simple image convolution (youtube.com)

7. I decrease of 1 all the numbers in the previous list, because in Python script, the indexation of a list starts at 0, while in Visual scripting list, it starts at 1.

7. Gray Scott Python Script - with numpy

in addition to the A and B lists, my inputs are 

  • Da (Diffusion for A): 0.12
  • Db (Diffusion for B) half of Da
  • Feed: 0.035
  • Kill: 0.06
  • 5000 steps in the loop of the attached 3dxml

Finding a "sweet spot" was not easy at all. this is where I started to ask ChatGPT for advice. it did not give me right numbers but more like encouragement to continue. also, how many steps... I thought 50 was enough, while Rohan told me that it could be few 10000!!!

about the laplacian. it is the sum of the neighbouring concentrations minus the central concentration multiplied by the number of neighbors used... in case of a pixel with 8 neighbours (all around), I do top pixel+bottom pixel+right pixel+left pixel - 4 X central pixel. the corner pixels are not used in this case.

here is the corresponding Python script

import numpy as np

Anp = np.array(A)
Bnp = np.array(B)
LapListnp = np.array(LaplacianList)
LapA = np.array(A)
LapB = np.array(B)
size = len(LapListnp)

for k in range(steps):
  for i in range(len(LapListnp)):
    l=0
    for j in range(len(LapListnp[i])):
      l += Anp[LapListnp[i][j]]
    LapA[i] = l-len(LapListnp[i])*Anp[i]

  for i in range(len(LapListnp)):
    l=0
    for j in range(len(LapListnp[i])):
      l += Bnp[LapListnp[i][j]]
    LapB[i] = l-len(LapListnp[i])*Bnp[i]

  Anp = Anp + Da * (LapA) - (Anp * Bnp * Bnp) + (1-Anp) * feed
  Bnp = Bnp + Db * (LapB) + (Anp * Bnp * Bnp) - (kill + feed) * Bnp

AOut = Anp
BOut = Bnp

8. rescale the result with "Scale Numbers" and colorize the initial pixels with "color gradient"