23

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}
 ]

Any advice is greatly appreciated,

Rick

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
Rick
  • 333
  • 2
  • 5
  • 1
    Please see lots of related questions using this search. – Szabolcs Mar 06 '13 at 03:36
  • 2
    The solution does appear fine ... and afaict the boundary conditions are indeed consistent with the initial cond – Szabolcs Mar 06 '13 at 03:46
  • @ Szabolcs: thanks for having a look. – Rick Mar 06 '13 at 06:25
  • Somewhat irrelevant, have you tried separation of variables? I think you can express the solution using fourrier series ... – Spawn1701D Mar 06 '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 07 '13 at 05:04

1 Answers1

18

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 ...

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • Yep. This kind of quirks may cause madness – Dr. belisarius Mar 06 '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 06 '13 at 20:58
  • @Nasser I don't suppose you have a pdf version of that note of yours available? – Daniel Lichtblau Mar 06 '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 06 '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 06 '13 at 21:03
  • @Nasser Thanks for the link to the pdf et al. – Daniel Lichtblau Mar 06 '13 at 21:07
  • @Szabolcs, I filed this as a suggestion against myself. –  Mar 06 '13 at 23:54
  • @ruebenko I am sorry, I did not know that. It has been said several times that if more users report a bug it will have more weight, so I thought it might be the same for suggestions like this ... it took me quite a bit of time to find your SO post, so I thought it would be really valuable to have a link in the warning message doc page. – Szabolcs Mar 07 '13 at 04:18
  • @Szabolcs thanks a million; frankly I'm rather embarrassed that I somehow didn't see this in the documentation. – Rick Mar 07 '13 at 04:57
  • @Nasser: yep, that's exactly the technique I'm using (learning) in my own implementation of FTCS. Thanks for the link! – Rick Mar 07 '13 at 05:15
  • @Szabolcs, it's only now that I filed this as a suggestion and because of this post, so there is nothing to be sorry about ;-) no worries. –  Mar 07 '13 at 07:13
  • @Szabolcs but by searching "inconsistent" on the link you provided, I didn't find such a section dedicated to inconsistent boundary conditions... – Nobody Nov 28 '21 at 06:34