23
$\begingroup$

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

$\endgroup$
5
  • 1
    $\begingroup$ Please see lots of related questions using this search. $\endgroup$
    – Szabolcs
    Commented Mar 6, 2013 at 3:36
  • 2
    $\begingroup$ The solution does appear fine ... and afaict the boundary conditions are indeed consistent with the initial cond $\endgroup$
    – Szabolcs
    Commented Mar 6, 2013 at 3:46
  • $\begingroup$ @ Szabolcs: thanks for having a look. $\endgroup$
    – Rick
    Commented Mar 6, 2013 at 6:25
  • $\begingroup$ Somewhat irrelevant, have you tried separation of variables? I think you can express the solution using fourrier series ... $\endgroup$
    – Spawn1701D
    Commented Mar 6, 2013 at 18:55
  • $\begingroup$ @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. $\endgroup$
    – Rick
    Commented Mar 7, 2013 at 5:04

1 Answer 1

18
$\begingroup$

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

$\endgroup$
12
  • $\begingroup$ Yep. This kind of quirks may cause madness $\endgroup$ Commented Mar 6, 2013 at 20:28
  • $\begingroup$ 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. $\endgroup$ Commented Mar 6, 2013 at 20:58
  • $\begingroup$ @Nasser I don't suppose you have a pdf version of that note of yours available? $\endgroup$ Commented Mar 6, 2013 at 20:59
  • $\begingroup$ @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 ... $\endgroup$
    – Szabolcs
    Commented Mar 6, 2013 at 20:59
  • $\begingroup$ @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... $\endgroup$ Commented Mar 6, 2013 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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