Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
1  
Please see lots of related questions using this search. – Szabolcs Mar 6 at 3:36
2  
The solution does appear fine ... and afaict the boundary conditions are indeed consistent with the initial cond – Szabolcs Mar 6 at 3:46
@ Szabolcs: thanks for having a look. – Rick Mar 6 at 6:25
the IC and BC look to be consistent. But something to look at, your I.C. lead to $k\left( \frac{\partial^{2}u}{\partial x^{2}}+\frac{\partial^{2}u}{\partial y^{2}}\right) =-5k\pi^{2}\cos\left( \pi x\right) \sin\left( 2\pi y\right) $. Hence from the pde itself, this means at $t=0,\frac{\partial u}{\partial t}=-5k\pi^{2}\cos\left( \pi x\right) \sin\left( 2\pi y\right)$ Now see if this is consistent with the B.C.'s shown. I could not find conflict. But it could be becuase you have neumann boundary conditions at the 2 other sides, it could not verify the consistency there, that is all. – Nasser Mar 6 at 6:31
Somewhat irrelevant, have you tried separation of variables? I think you can express the solution using fourrier series ... – Spawn1701D Mar 6 at 18:55
show 1 more comment

1 Answer

up vote 11 down vote accepted

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

share|improve this answer
+1 good find! But this makes one wonder if M error message in this case could have been made more helpful to users. Since M knows the B.C. is Neumann, and so internally it must have gone through this code path. Then why not make a more informative error message in this case? This would have saved the user much time. WHat I mean, it says This happens due to discretization error in approximating Neumann boundary conditions So, M knows the error! then why not issue this error instead of one given? – Nasser Mar 6 at 20:10
Yep. This kind of quirks may cause madness – belisarius Mar 6 at 20:28
1  
btw, doing Neumann B.C. can be tricky in finite difference. I spend sometime to write a note on this since I kept making mistakes in it. Here is the note, it shows how to discretize 2D for Neumann on the different edges. This is only useful for someone doing FDM by hand ofcourse, not using NDSolve : 12000.org/my_courses/UC_davis/fall_2010/math_228a/HWs/HW3/… – Nasser Mar 6 at 20:54
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 at 20:58
@Nasser I don't suppose you have a pdf version of that note of yours available? – Daniel Lichtblau Mar 6 at 20:59
show 9 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.