Skip to content

Commit 8b3ae79

Browse files
Use periodic boundary conditions for brusselator_1d
Loop over all N points using the existing `limit` function for index wrapping (consistent with the 2D brusselator). Update dx to 1/N and fix docstring to document periodic BCs. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9d492d5 commit 8b3ae79

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

lib/ODEProblemLibrary/src/brusselator_prob.jl

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,13 @@ function brusselator_1d_loop(du, u, p, t)
117117
A, B, alpha, dx = p
118118
alpha = alpha / dx^2
119119
N = N_brusselator_1d
120-
@inbounds begin
121-
du[1, 1] = 0
122-
du[1, 2] = 0
123-
du[N, 1] = 0
124-
du[N, 2] = 0
125-
for i in 2:(N - 1)
126-
ip1, im1 = i + 1, i - 1
127-
du[i, 1] = alpha * (u[im1, 1] + u[ip1, 1] - 2u[i, 1]) +
128-
A + u[i, 1]^2 * u[i, 2] - (B + 1) * u[i, 1]
129-
du[i, 2] = alpha * (u[im1, 2] + u[ip1, 2] - 2u[i, 2]) +
130-
B * u[i, 1] - u[i, 1]^2 * u[i, 2]
131-
end
120+
@inbounds for i in 1:N
121+
ip1 = limit(i + 1, N)
122+
im1 = limit(i - 1, N)
123+
du[i, 1] = alpha * (u[im1, 1] + u[ip1, 1] - 2u[i, 1]) +
124+
A + u[i, 1]^2 * u[i, 2] - (B + 1) * u[i, 1]
125+
du[i, 2] = alpha * (u[im1, 2] + u[ip1, 2] - 2u[i, 2]) +
126+
B * u[i, 1] - u[i, 1]^2 * u[i, 2]
132127
end
133128
end
134129

@@ -161,12 +156,12 @@ v(x,0) &= 3
161156
\end{align*}
162157
```
163158
164-
with the boundary condition
159+
with periodic boundary conditions
165160
166161
```math
167162
\begin{align*}
168-
u(0,t) = u(1,t) = 1 \\
169-
v(0,t) = v(1,t) = 3
163+
u(0,t) &= u(1,t) \\
164+
v(0,t) &= v(1,t)
170165
\end{align*}
171166
```
172167
@@ -176,5 +171,5 @@ prob_ode_brusselator_1d = ODEProblem(
176171
brusselator_1d_loop,
177172
init_brusselator_1d(N_brusselator_1d),
178173
(0.0, 10.0),
179-
(1.0, 3.0, 0.02, 1.0 / (N_brusselator_1d - 1))
174+
(1.0, 3.0, 0.02, 1.0 / N_brusselator_1d)
180175
)

0 commit comments

Comments
 (0)