Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to set up a PDE model, which takes a two-dimensional diffusion equation into account. The key problem is that I have some trouble in solving the two-dimensional diffusion equation numerically. Consider the following code:

L = 10;
T = 10;
system = {
   D[c[x, y, t], {t, 1}] == D[c[x, y, t], {x, 2}] + D[c[x, y, t], {y, 2}],
   Derivative[1, 0, 0][c][0, y, t] == 0,
   Derivative[1, 0, 0][c][L, y, t] == 0,
   c[x, 0, t] == c[x, L, t],
   c[x, y, 0] == 1
   };
sol = NDSolve[system, c, {x, 0, L}, {y, 0, L}, {t, 0, T}];
Manipulate[Plot3D[Evaluate[c[x, y, t] /. sol], {x, 0, L}, {y, 0, L}], {{t,T}, 0, T}]

Mathematica graphics

As you can see for t = 10 there are artifacts at the two edges where the Neumann conditions were applied.

Obviously, c[x, y, t] = 1 solves the system and since this is the initial condition Mathematica should have no trouble to compute it numerically. It tried various ODE solvers ("ImplicitRungeKutta", "BDF", "Adams"), but it seems that there is some problem with the spatial discretization, perhaps because of the Neumann boundary condition for the variable x.

Any suggestions how to fix it?

share|improve this question
    
You could try increasing PrecisionGoal and/or AccuracyGoal –  Heike May 25 '12 at 8:21

1 Answer 1

up vote 6 down vote accepted

One option is to use a pseudospectral difference order, explained here.

This then works:

L = 10;
T = 10;
system = {D[c[x, y, t], {t, 1}] == 
    D[c[x, y, t], {x, 2}] + D[c[x, y, t], {y, 2}], 
   Derivative[1, 0, 0][c][0, y, t] == 0,
   Derivative[1, 0, 0][c][ L, y, t] == 0,
   c[x, 0, t] == c[x, L, t],
   c[x, y, 0] == 1};
sol = NDSolve[system, c, {x, 0, L}, {y, 0, L}, {t, 0, T}, 
   Method -> {"MethodOfLines", 
     "SpatialDiscretization" -> {"TensorProductGrid", 
       "DifferenceOrder" -> "Pseudospectral"}}];
Manipulate[
 Plot3D[Evaluate[c[x, y, T] /. sol], {x, 0, L}, {y, 0, L}, 
  PlotRange -> {0.9, 1.1}], {{t, T}, 0, T}]

Other things you might want to try is to use a finer grid, also explained in the above document.

share|improve this answer

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.