Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Source

The Brusselator PDE:

ut=1+u2v4.4u+α(2ux2+2uy2)+f(x,y,t)vt=3.4uu2v+α(2ux2+2uy2)\begin{align} \frac{\partial u}{\partial t} &= 1 + u^2v - 4.4u + \alpha (\frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2}) + f(x, y, t) \\ \frac{\partial v}{\partial t} &= 3.4u - u^2 v + \alpha (\frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2}) \end{align}

where

f(x,y,t)={5if(x0.3)2+(y0.6)20.12 and t1.10otherwisef(x, y, t) = \begin{cases} 5 \qquad \text{if} (x - 0.3)^2 + (y - 0.6)^2 \leq 0.1^2 \ \text{and} \ t \geq 1.1 \\ 0 \qquad \text{otherwise} \end{cases}

and the initial conditions are

u(x,y,0)=22(y(1y))1.5v(x,y,0)=27(x(1x))1.5\begin{align} u(x, y, 0) &= 22(y(1-y))^{1.5} \\ v(x, y, 0) &= 27(x(1-x))^{1.5} \end{align}

with the periodic boundary condition

u(x+1,y,0)=u(x,y,t)u(x,y+1,0)=u(x,y,t)\begin{align} u(x+1, y, 0) &= u(x, y, t) \\ u(x, y+1, 0) &= u(x, y, t) \end{align}

on a time span of t[0,11.5]t \in [0, 11.5].

using ModelingToolkit
using MethodOfLines
using OrdinaryDiffEq
using DomainSets
using Plots

Setup parameters, variables, and differential operators

function model_bru(; x_min=0.0, x_max=1.0, y_min=0.0, y_max=1.0, t_min=0.0, t_max=11.5, α=10.0, N::Int = 20, order::Int = 2)
    @independent_variables x y t
    @variables u(..) v(..)
    Dt = Differential(t)
    Dx = Differential(x)
    Dy = Differential(y)
    Dxx = Differential(x)^2
    Dyy = Differential(y)^2
    ∇²(u) = Dxx(u) + Dyy(u)

    # Dynamics on each grid point
    brusselator_f(x, y, t) = (((x - 0.3)^2 + (y - 0.6)^2) <= 0.1^2) * (t >= 1.1) * 5
    u0(x, y, t) = 22 * (y * (1 - y))^(3 / 2)
    v0(x, y, t) = 27 * (x * (1 - x))^(3 / 2)

    eqs = [
        Dt(u(x, y, t)) ~ 1.0 + v(x, y, t) * u(x, y, t)^2 - 4.4 * u(x, y, t) + α * ∇²(u(x, y, t)) + brusselator_f(x, y, t),
        Dt(v(x, y, t)) ~ 3.4 * u(x, y, t) - v(x, y, t) * u(x, y, t)^2 + α * ∇²(v(x, y, t))
    ]
    domains = [
        x ∈ Interval(x_min, x_max),
        y ∈ Interval(y_min, y_max),
        t ∈ Interval(t_min, t_max)
    ]
    # Periodic boundary conditions
    bcs = [
        u(x, y, 0) ~ u0(x, y, 0),
        u(0, y, t) ~ u(1, y, t),
        u(x, 0, t) ~ u(x, 1, t),
        v(x, y, 0) ~ v0(x, y, 0),
        v(0, y, t) ~ v(1, y, t),
        v(x, 0, t) ~ v(x, 1, t)
    ]
    @named pdesys = PDESystem(eqs, bcs, domains, [x, y, t], [u(x, y, t), v(x, y, t)])
    disc = MOLFiniteDifference([x=>N, y=>N], t; approx_order=order)
    prob = discretize(pdesys, disc)
    return (; prob, x, y, t, u, v)
end

@time prob, x, y, t, u, v = model_bru()
@time sol = solve(prob, FBDF(), saveat=0.1);
┌ Warning: The system contains interface boundaries, which are not compatible with system transformation. The system will not be transformed. Please post an issue if you need this feature.
└ @ MethodOfLines ~/.julia/packages/MethodOfLines/BHjnI/src/system_parsing/pde_system_transformation.jl:47
 64.618830 seconds (85.74 M allocations: 5.257 GiB, 2.44% gc time, 93.26% compilation time: 9% of which was recompilation)
 43.517690 seconds (57.56 M allocations: 3.255 GiB, 2.01% gc time, 77.62% compilation time: <1% of which was recompilation)

Extract data

discrete_x = sol[x]
discrete_y = sol[y]
discrete_t = sol[t]

solu = sol[u(x, y, t)]
solv = sol[v(x, y, t)]

umax = maximum(maximum, solu)
vmax = maximum(maximum, solv)
4.928012529985555

Visualization

Interval == 2:end since in periodic condition, end == 1

anim = @animate for k in eachindex(discrete_t)
    heatmap(solu[2:end, 2:end, k], title="u @ t=$(discrete_t[k])", clims = (0.0, umax))
end

mp4(anim, fps = 8)
[ Info: Saved animation to /tmp/jl_y3CDMBmVen.mp4
Loading...
anim = @animate for k in eachindex(discrete_t)
    heatmap(solv[2:end, 2:end, k], title="v @ t=$(discrete_t[k])", clims = (0.0, vmax))
end

mp4(anim, fps = 8)
[ Info: Saved animation to /tmp/jl_e58peLUf0d.mp4
Loading...

This notebook was generated using Literate.jl.