# 2D Heat equation: inconsistent boundary and initial conditions

I'm attempting to use NDSolve on a 2D boundary value problem with initial conditions. Upon running my code, I get the following message:

"NDSolve::ibcinc: Warning: Boundary and initial conditions are inconsistent."

After much head-scratching, I can't seem to find my mistake. It seems to me that my initial condition is consistent with my boundary conditions:

k = 1 / (5*(Pi^2));
soln = NDSolve[
{
(* PDE *)
D[u[x, y, t], t] == k*(D[u[x, y, t], x, x] + D[u[x, y, t], y, y]),

(* initial condition *)
u[x, y, 0] == y + Cos[Pi*x] Sin[2*Pi*y],

(* boundary conditions *)
u[x, 0, t] == 0,
u[x, 1, t] == 1,
(D[u[x, y, t], x] /. x -> 0) == 0,
(D[u[x, y, t], x] /. x -> 1) == 0
},
u,
{x, 0, 1},
{y, 0, 1},
{t, 0, 1}
]


Rick

-
Please see lots of related questions using this search. –  Szabolcs Mar 6 '13 at 3:36
The solution does appear fine ... and afaict the boundary conditions are indeed consistent with the initial cond –  Szabolcs Mar 6 '13 at 3:46
@ Szabolcs: thanks for having a look. –  Rick Mar 6 '13 at 6:25
Somewhat irrelevant, have you tried separation of variables? I think you can express the solution using fourrier series ... –  Spawn1701D Mar 6 '13 at 18:55
@Spawn1701D: I'm writing my own implementation of FTCS to solve the problem. Separation of variables gives an exact answer, but I wanted to solve it first with Mathematica so that I can compare my output to the result as a cross-check. –  Rick Mar 7 '13 at 5:04

The documentation has a full section dedicated to inconsistent boundary conditions in PDEs.

Quoting it,

Occasionally, NDSolve will issue the NDSolve::ibcinc message warning about inconsistent boundary conditions when they are actually consistent. This happens due to discretization error in approximating Neumann boundary conditions or any boundary condition that involves a spatial derivative. The reason this happens is that spatial error estimates (see "Spatial Error Estimates") used to determine how many points to discretize with are based on the PDE and the initial condition, but not the boundary conditions. The one-sided finite difference formulas that are used to approximate the boundary conditions also have larger error than a centered formula of the same order, leading to additional discretization error at the boundary. Typically this is not a problem, but it is possible to construct examples where it does occur.

Then an example follows, and a possible solution using the Method option's "TensorProductGrid" suboption, which we can also apply to your problem.

When the boundary conditions are consistent, a way to correct this error is to specify that NDSolve use a finer spatial discretization.

k = 1/(5*(Pi^2));
soln = NDSolve[{
D[u[x, y, t], t] == k*(D[u[x, y, t], x, x] + D[u[x, y, t], y, y]),
u[x, y, 0] == y + Cos[Pi*x] Sin[2*Pi*y],
u[x, 0, t] == 0,
u[x, 1, t] == 1,
(D[u[x, y, t], x] /. x -> 0) == 0,
(D[u[x, y, t], x] /. x -> 1) == 0},

u, {x, 0, 1}, {y, 0, 1}, {t, 0, 1},

Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 20}}]


In this instance "MinPoints" -> 20 was sufficient to make the problem go away.

The same problem was discussed here. I vaguely remembered it, but it took me a while to find it again ...

-
Yep. This kind of quirks may cause madness –  belisarius Mar 6 '13 at 20:28
Very nice find. I don't want to admit to how much time I spent last night looking for something in the Advanced Documentation.. regarding that issue. And I even knew, more or less, what to look for (error from discretization and numerical differencing). Oh well. –  Daniel Lichtblau Mar 6 '13 at 20:58
@Nasser I don't suppose you have a pdf version of that note of yours available? –  Daniel Lichtblau Mar 6 '13 at 20:59
@Daniel It would be really good to have a link to that advanced tutorial on the NDSolve::ibcinc doc page (what you get when you click >>). I sent a suggestion to support@wolfram half an hour ago, but I don't know if such user suggestions make a difference or not ... –  Szabolcs Mar 6 '13 at 20:59
@Szabolcs I echoed your request to some people involved in NDSolve development. Of course that does not mean it will carry any more weight than your note to Support... –  Daniel Lichtblau Mar 6 '13 at 21:03