4
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ You could try increasing PrecisionGoal and/or AccuracyGoal $\endgroup$ – Heike May 25 '12 at 8:21
6
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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