I am struggling to have Mathematica 10.3 solve a system of PDE's (with periodic boundary conditions and random initial conditions), but either it produces a set of very noisy InterpolatingFunction objects that are then nearly impossible to NIntegrate, or it fails to solve it altogether. My best try so far was this:
rs = 0.1;
rn = 0.1;
Diff = 100;
Difn = 0.001;
sigmas0 = 1;
sigmans0 = 1;
s0 = 1000.; (* Initial biomass of Starters *)
cs = 10; (* Number of starter colonies *)
ns0 = .1; (* Initial biomass of Non-starters *)
time = 500;
size = 50;
rnd = RandomReal[2 size, 2 cs];
rnd = rnd - size;
top = 0;
soln = NDSolve[{
D[S[t, x, y], t] == -rs S[t, x, y],
D[F[t, x, y], t] ==
Diff (D[F[t, x, y], x, x] + D[F[t, x, y], y, y]) + rs S[t, x, y] -
rn F[t, x, y] NS[t, x, y],
D[NS[t, x, y], t] ==
Difn (D[NS[t, x, y], x, x] + D[NS[t, x, y], y, y]) +
rn F[t, x, y] NS[t, x, y],
S[t, -size, y] == S[t, size, y], S[t, x, -size] == S[t, x, size],
F[t, -size, y] == F[t, size, y], F[t, x, -size] == F[t, x, size],
NS[t, -size, y] == NS[t, size, y],
NS[t, x, -size] == NS[t, x, size],
S[0, x, y] ==
Sum[s0/cs Exp[-((x - rnd[[n]])^2/(2 sigmas0^2) + (y -
rnd[[cs + n]])^2/(2 sigmas0^2))], {n, 1, cs}],
F[0, x, y] == 0.,
NS[0, x, y] == ns0 Exp[-(x^2/(2 sigmans0^2) + y^2/(2 sigmans0^2))]},
{S, F, NS}, {t, 0, time}, {x, -size, size}, {y, -size, size},
MaxStepSize -> .5]
This seems to work (except for Mathematica warning me that the initial and the boundary conditions are inconsistent, but that cannot be helped with random initial and periodic boundary conditions, I guess):
NDSolve::ibcinc: Warning: boundary and initial conditions are inconsistent. >>
However, trying to NIntegrate the resulting InterpolatingFunction objects:
FoodCurve =
Table[NIntegrate[
F[t, x, y] /. soln, {x, -size, size}, {y, -size, size},
Method -> "InterpolationPointsSubdivision",
WorkingPrecision -> 100, PrecisionGoal -> 10,
AccuracyGoal -> 6], {t, 0, 10}]
I get error messages related to ...
NIntegrate::slwcon: Numerical integration converging too slowly;
suspect one of the following: singularity, value of the integration is
0, highly oscillatory integrand, or WorkingPrecision too small. >>
The problem might be either that the result of the integration approaches 0 towards the end of the simulation, or that the integrand is singular at places, which is the result of insufficiently dense sampling, I guess. I have figured out from the manual that decreasing MaxStepSize in NDSolve could smooth the resultant InterpolatingFunction, but if I set it to 0.1 the kernel crashes after half a day of working on the PDF.
Is there another way to speed up NDSolve for this problem and/or to smooth the resulting InterpolatingFunction so that NIntegrate does not complain and does the job fast on it?
Thanks for your attention!
MaxStepSize -> .5
. If you remove that it integrates much faster. Is the result not correct? $\endgroup$