I'm trying to solve a PDE system reaction-diffusion type (2D spatial + 1 temporal) coupled as described below. Another question of this same system was solved here: System of nonlinear PDE 2D (Reaction-Diffusion type) with periodic boundary condition
The boundary conditions are:
And the initial conditions are:
or by scheme
The code is written below
(parameters)
L = 5;
T = 10;
(*system of nonlinear PDE*)
pde = {D[N1[t, x, y], t] ==
D[N1[t, x, y], x, x] +
D[N1[t, x, y], y,
y] + (1 - N1[t, x, y] - 0.5 N2[t, x, y]) N1[t, x, y],
D[N2[t, x, y], t] ==
D[N2[t, x, y], x, x] +
D[N2[t, x, y], y,
y] + (1 - N2[t, x, y] - 0.5 N1[t, x, y]) N2[t, x, y]};
(*periodic boundary condition*)
bc = {N1[t, -L, y] == N1[t, L, y], N1[t, x, -L] == N1[t, x, L],
N2[t, -L, y] == N2[t, L, y], N2[t, x, -L] == N2[t, x, L]};
(*initial condition*)
ic = {N1[0, x, y] ==
If[-4.2 <= x <= -4.7 && -4.2 <= y <= -4.7 &&
4.2 <= x <= 4.7 && -4.2 <= y <= -4.7 && -4.2 <= x <= -4.7 &&
4.2 <= y <= 4.7 && -0.5 <= x <= 0.5 && -0.5 <= y <= 0.5 &&
4.2 <= x <= 4.7 && 4.2 <= y <= 4.7, 1, 0],
N2[0, x, y] ==
If[-4.2 <= x <= -4.7 && -4.2 <= y <= -4.7 &&
4.2 <= x <= 4.7 && -4.2 <= y <= -4.7 && -4.2 <= x <= -4.7 &&
4.2 <= y <= 4.7 && -0.5 <= x <= 0.5 && -0.5 <= y <= 0.5 &&
4.2 <= x <= 4.7 && 4.2 <= y <= 4.7, 0, 1]}
eqns = Flatten@{pde, bc, ic};
{N1, N2} =
NDSolve[eqns, {N1, N2}, {t, 0, T}, {x, -L, L}, {y, -L, L},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid"}}]
I believe the problem arises from the way the initial condition was implemented. Besides trying to implement these conditions using If
, I tried to use Piecewise
, but I was not successful. Can anybody help me?