Skip to content

Commit 69a6f39

Browse files
author
Daniel Precioso, PhD
committed
Add Gray-Scott model implementations and update references
- Implemented the Gray-Scott model in `gray_scott.py` with Laplacian calculations and simulation controls. - Created `gray_scott_art.py` for an interactive version of the Gray-Scott model using image masks. - Updated references in documentation to point to the new file structure for Gierer-Meinhardt and Gray-Scott models. - Enhanced the user interface with sliders for parameter adjustments and mouse interactions for perturbations.
1 parent 374cb3d commit 69a6f39

12 files changed

Lines changed: 59 additions & 10 deletions

amlab/pdes/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Shared PDE models and interactive demos for the Applied Math Lab package."""
2+
3+
from .gierer_meinhardt_1d import (
4+
find_unstable_spatial_modes as find_unstable_spatial_modes_1d,
5+
)
6+
from .gierer_meinhardt_1d import gierer_meinhardt_pde as gierer_meinhardt_pde_1d
7+
from .gierer_meinhardt_1d import is_turing_instability
8+
from .gierer_meinhardt_2d import (
9+
find_unstable_spatial_modes as find_unstable_spatial_modes_2d,
10+
)
11+
from .gierer_meinhardt_2d import gierer_meinhardt_pde as gierer_meinhardt_pde_2d
12+
from .gray_scott import gray_scott_pde
13+
14+
__all__ = [
15+
"find_unstable_spatial_modes_1d",
16+
"find_unstable_spatial_modes_2d",
17+
"gierer_meinhardt_pde_1d",
18+
"gierer_meinhardt_pde_2d",
19+
"gray_scott_pde",
20+
"is_turing_instability",
21+
]

modules/pde/assignment.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Include a brief paragraph that answers these questions:
5757
- Reuse your 2D Laplacian in both Gierer-Meinhardt and Gray-Scott.
5858

5959
::: {.callout-tip}
60-
Reference code is available in [amlab/pdes_1d/gierer_meinhardt_1d.py](https://github.com/daniprec/BAM-Applied-Math-Lab/blob/main/amlab/pdes_1d/gierer_meinhardt_1d.py), [amlab/pdes_2d/gierer_meinhardt_2d.py](https://github.com/daniprec/BAM-Applied-Math-Lab/blob/main/amlab/pdes_2d/gierer_meinhardt_2d.py), and [amlab/pdes_2d/gray_scott.py](https://github.com/daniprec/BAM-Applied-Math-Lab/blob/main/amlab/pdes_2d/gray_scott.py).
60+
Reference code is available in [amlab/pdes/gierer_meinhardt_1d.py](https://github.com/daniprec/BAM-Applied-Math-Lab/blob/main/amlab/pdes/gierer_meinhardt_1d.py), [amlab/pdes/gierer_meinhardt_2d.py](https://github.com/daniprec/BAM-Applied-Math-Lab/blob/main/amlab/pdes/gierer_meinhardt_2d.py), and [amlab/pdes/gray_scott.py](https://github.com/daniprec/BAM-Applied-Math-Lab/blob/main/amlab/pdes/gray_scott.py).
6161
:::
6262

6363
\vspace{1cm}

modules/pde/gierer-meinhardt-1d.qmd

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ where $u(x,t)$ is the activator, $v(x,t)$ is the inhibitor, and $d$ is the diffu
2929
import matplotlib.pyplot as plt
3030
import numpy as np
3131
32-
from amlab.pdes_1d.gierer_meinhardt_1d import gierer_meinhardt_pde
32+
from amlab.pdes.gierer_meinhardt_1d import gierer_meinhardt_pde
3333
3434
np.random.seed(3)
3535
@@ -71,6 +71,34 @@ $$
7171
\Delta u(x) \approx \frac{u(x+dx) - 2u(x) + u(x-dx)}{dx^2}.
7272
$$ {#eq-pde-gm-1d-fd}
7373
74+
:::{.callout-tip}
75+
## Where does this formula come from?
76+
77+
The second derivative is the limit of the difference quotient:
78+
79+
$$
80+
\frac{d^2 u}{dx^2} = \lim_{dx \to 0} \frac{u(x+dx) - 2u(x) + u(x-dx)}{dx^2}.
81+
$$
82+
83+
This is a direct consequence of the Taylor expansion of $u$ around $x$:
84+
85+
$$
86+
\begin{aligned}
87+
u(x+dx) &= u(x) + u'(x) dx + \frac{1}{2} u''(x) dx^2 + \mathcal{O}(dx^3), \\
88+
u(x-dx) &= u(x) - u'(x) dx + \frac{1}{2} u''(x) dx^2 + \mathcal{O}(dx^3).
89+
\end{aligned}
90+
$$
91+
92+
Adding these two expansions gives
93+
94+
$$
95+
u(x+dx) + u(x-dx) = 2u(x) + u''(x) dx^2 + \mathcal{O}(dx^3),
96+
$$
97+
98+
which can be rearranged to give the finite difference formula, ignoring the higher-order terms $\mathcal{O}(dx^3)$.
99+
:::
100+
101+
74102
Write a helper that computes this second derivative for a 1D field.
75103
76104
```python
@@ -289,5 +317,5 @@ You now have a working 1D solver. The next question is theoretical: for which pa
289317
[Turing Instability](turing-instability.qmd){.btn .btn-primary}
290318
291319
::: {.callout-tip}
292-
Reference code is available in [amlab/pdes_1d/gierer_meinhardt_1d.py](https://github.com/daniprec/BAM-Applied-Math-Lab/blob/main/amlab/pdes_1d/gierer_meinhardt_1d.py).
320+
Reference code is available in [amlab/pdes/gierer_meinhardt_1d.py](https://github.com/daniprec/BAM-Applied-Math-Lab/blob/main/amlab/pdes/gierer_meinhardt_1d.py).
293321
:::

modules/pde/gierer-meinhardt-2d.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ but now $u$ and $v$ depend on $(x, y, t)$.
2929
import matplotlib.pyplot as plt
3030
import numpy as np
3131
32-
from amlab.pdes_2d.gierer_meinhardt_2d import gierer_meinhardt_pde
32+
from amlab.pdes.gierer_meinhardt_2d import gierer_meinhardt_pde
3333
3434
np.random.seed(3)
3535
@@ -270,5 +270,5 @@ The Gierer-Meinhardt model is a good training ground, but the final target of th
270270
[Gray-Scott](gray-scott.qmd){.btn .btn-primary}
271271
272272
::: {.callout-tip}
273-
Reference code is available in [amlab/pdes_2d/gierer_meinhardt_2d.py](https://github.com/daniprec/BAM-Applied-Math-Lab/blob/main/amlab/pdes_2d/gierer_meinhardt_2d.py).
273+
Reference code is available in [amlab/pdes/gierer_meinhardt_2d.py](https://github.com/daniprec/BAM-Applied-Math-Lab/blob/main/amlab/pdes/gierer_meinhardt_2d.py).
274274
:::

modules/pde/gray-scott-art.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,5 @@ At this point you have all the ingredients of the session: a 1D solver, the Turi
186186
[Assignment](assignment.qmd){.btn .btn-secondary}
187187

188188
::: {.callout-tip}
189-
Reference code is available in [amlab/pdes_2d/gray_scott.py](https://github.com/daniprec/BAM-Applied-Math-Lab/blob/main/amlab/pdes_2d/gray_scott.py).
189+
Reference code is available in [amlab/pdes/gray_scott.py](https://github.com/daniprec/BAM-Applied-Math-Lab/blob/main/amlab/pdes/gray_scott.py).
190190
:::

0 commit comments

Comments
 (0)