{"id":21595776,"url":"https://github.com/wigging/gray-scott","last_synced_at":"2026-03-06T19:35:25.577Z","repository":{"id":167090802,"uuid":"637570146","full_name":"wigging/gray-scott","owner":"wigging","description":"Examples of the Gray-Scott model","archived":false,"fork":false,"pushed_at":"2023-09-04T18:26:18.000Z","size":7306,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T00:29:46.993Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wigging.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-08T00:11:58.000Z","updated_at":"2023-06-28T14:23:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"cce4888b-8ce8-43bd-b149-f9fa1cdbf44b","html_url":"https://github.com/wigging/gray-scott","commit_stats":null,"previous_names":["wigging/gray-scott"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/wigging/gray-scott","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wigging%2Fgray-scott","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wigging%2Fgray-scott/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wigging%2Fgray-scott/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wigging%2Fgray-scott/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wigging","download_url":"https://codeload.github.com/wigging/gray-scott/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wigging%2Fgray-scott/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30193650,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"ssl_error","status_checked_at":"2026-03-06T18:57:34.882Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T17:43:57.423Z","updated_at":"2026-03-06T19:35:24.623Z","avatar_url":"https://github.com/wigging.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gray-Scott model\n\nThis repository contains examples of implementing the Gray-Scott model in various programming languages.\n\n## Governing equations\n\nThe Gray-Scott model represents the following irreversible reactions where $P$ is an inert product:\n\n```math\n\\begin{align}\n    U + 2V \u0026\\rightarrow 3V \\\\\n    V \u0026\\rightarrow P\n\\end{align}\n```\n\nThe resulting reaction-diffusion equations in dimensionless units are shown below where $k$ is the dimensionless rate constant of the second reaction and $F$ is the dimensionless feed rate. The diffusion coefficients are $D_u$ and $D_v$ and $\\nabla^2$ represents the Laplacian operator.\n\n```math\n\\begin{align}\n    \\frac{\\partial U}{\\partial t} \u0026= D_u \\nabla^2 U - U V^2 + F (1 - U) \\\\\n    \\frac{\\partial V}{\\partial t} \u0026= D_v \\nabla^2 V + U V^2 - (F + k) V\n\\end{align}\n```\n\n## Examples\n\nExamples of solving the Gray-Scott model in Python, Swift, and Julia are available in this repository. See the comments in the code for more information about that particular example. The examples use model parameters and boundary conditions defined in the Pearson 1993 article. The Laplacian is calculated using a five-point stencil with periodic boundary conditions.\n\n### Julia\n\nThe `center.jl` is an example of assigning values at the center of a matrix. The `stencil.jl` demonstrates a two-dimensional five-point stencil. The Gray-Scott model is solved in `grayscott_loops.jl`, `grayscott_slices.jl`, and `grayscott_views.jl` using loops, array slices, and views.\n\n### Python\n\nThe `laplacian.py` contains examples of calculating the Laplacian using a five-point stencil and periodic boundary conditions. The Gray-Scott model is solved in `grayscott_slices.py` and `grayscott_movie.py` saves an animation of the results.\n\n\u003cimg src=\"assets/fig1-python.png\" width=\"49%\"/\u003e \u003cimg src=\"assets/fig2-python.png\" width=\"49%\"/\u003e\n\nThe table below compares the elapsed times for each Laplacian function in `laplacian.py` for a 512x512 array. The results are from a 2019 MacBook Pro running a 2.6 GHz 6-core Intel i7 CPU with 32 GB of RAM.\n\n| Function              | Run 1    | Run 2    | Run 3    |\n| --------------------- | -------- | -------- | -------- |\n| lap5_loops            | 0.5555 s | 0.5794 s | 0.5660 s |\n| lap5_loops2           | 0.5516 s | 0.5396 s | 0.5209 s |\n| lap5_slices           | 0.0045 s | 0.0039 s | 0.0034 s |\n| lap5_roll             | 0.0064 s | 0.0056 s | 0.0051 s |\n| lap5_shift            | 0.0026 s | 0.0025 s | 0.0025 s |\n| lap5_convolve         | 0.3192 s | 0.3120 s | 0.3136 s |\n| scipy.ndimage.laplace | 0.0737 s | 0.0693 s | 0.0659 s |\n\n### Swift\n\nThe Swift examples are available as Xcode projects and a playground in the `swift-examples` folder. The `matrix` project demonstrates a two-dimensional `Matrix` struct that makes matrix calculations easier to work with in Swift. The `laplacian` project calculates the Laplacian of a matrix using a five-point stencil and periodic boundary conditions. The `grayscott` project runs the Gray-Scott model and saves the results to a text file. This text file can be used with NumPy and Matplotlib to plot the results. The `grayscott-jeff` playground uses a `Lattice2d` struct for solving the Gray-Scott model and uses PythonKit to plot the results.\n\nThe `GrayScottCharts` project is a macOS app that uses Swift Charts to plot the results as shown in the figure below.\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"assets/fig3-charts.png\" width=\"60%\"/\u003e\n\u003c/div\u003e\n\nThe `GrayScottColormap` project is a macOS app that uses Core Graphics to plot the results as seen below. This uses the viridis colormap.\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"assets/fig4-colormap.png\" width=\"90%\"/\u003e\n\u003c/div\u003e\n\nThe `Gray-Scott Torus` project is a MacOS app using Metal to explore various values of F and k with periodic boundary conditions, displaying the results in live time on either a plane or a torus projection.\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"assets/fig5-torus.jpg\" width=\"60%\"/\u003e\n\u003c/div\u003e\n\nThe `GrayScottMetal` project is a macOS app the uses compute (kernel) shaders in Metal to perform the Gray-Scott calculations and animate the results.\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"assets/fig6-metal.png\" width=\"40%\"/\u003e\n\u003c/div\u003e\n\n## Contributing\n\nIf you would like to contribute an example to this respository, please create a folder for the example and submit a pull request. Literature such as articles, books, websites, etc. that were used to develop the example should be added to the References section (see below).\n\n## References\n\nReferences about the Gray-Scott model and numerical techniques for solving it are provided below:\n\n1. John E. Pearson, \"Complex Patterns in a Simple System,\" Science, vol. 261, no. 5118, pp. 189–192, 1993, doi: [10.1126/science.261.5118.189](https://doi.org/10.1126/science.261.5118.189).\n2. Abelson, Adams, Coore, Hanson, Nagpal, Sussman, \"Gray Scott Model of Reaction Diffusion,\" Accessed: Aug. 24, 2023. [Online]. Available: https://groups.csail.mit.edu/mac/projects/amorphous/GrayScott/\n3. Katharina Kafer and Mirjam Schulz, \"Gray-Scott Model of a Reaction-Diffusion System,\" Accessed: Aug. 24, 2023. [Online]. Available: https://itp.uni-frankfurt.de/~gros/StudentProjects/Projects_2020/projekt_schulz_kaefer/\n4. \"Five-point stencil,\" Wikipedia. Jan. 31, 2023. Accessed: Aug. 24, 2023. [Online]. Available: https://en.wikipedia.org/wiki/Five-point_stencil.\n5. D. C. Root, \"How to obtain the 9-point Laplacian formula?,\" Mathematics Stack Exchange, Sep. 15, 2018. Accessed: Aug. 24, 2023. [Online]. Available: https://math.stackexchange.com/q/2916234\n6. \"Discrete Laplace operator,\" Wikipedia. Jul. 23, 2023. Accessed: Aug. 24, 2023. [Online]. Available: https://en.wikipedia.org/wiki/Discrete_Laplace_operator\n7. R. P. Munafo, \"Pearson’s Classification (Extended) of Gray-Scott System Parameter Values at MROB,\" Mar. 18, 2022. Accessed: Aug. 24, 2023. [Online]. Available: http://www.mrob.com/pub/comp/xmorphia/pearson-classes.html\n8. K. Sims, \"Reaction-Diffusion Tutorial,\" 2016. Accessed: Aug. 24, 2023. [Online]. Available: http://www.karlsims.com/rd.html\n9. K. Sims, \"Reaction-Diffusion Explorer Tool,\" 2016. Accessed: Aug. 24, 2023. [Online]. Available: http://karlsims.com/rdtool.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwigging%2Fgray-scott","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwigging%2Fgray-scott","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwigging%2Fgray-scott/lists"}