1
$\begingroup$

I want to get results of integral of PDE model result. The PDE model is 1D heat diffusion equation with Neumann boundary conditions. The key problem is that integral of PDE model result take too much time to calculate, and I haven't gottten the results yet. I consider the following code:

h = 6000;
a = 200;
Dif = 3.67*10^-14*10^18;
Ni = 1;

deqN = D[u[t, x], t] - Dif*D[u[t, x], {x, 2}] == 
      NeumannValue[0, x == 0] + NeumannValue[0, x == h];
ic = u[0, x] == If[0 <= x <= a , Ni, 0]

sol = NDSolveValue[{deqN, ic}, u, {t, 0, 60}, {x, 0, h}, 
 Method -> {"MethodOfLines", 
  "SpatialDiscretization" -> {"FiniteElement", 
    "MeshOptions" -> {"MaxCellMeasure" -> {"Length" -> 0.1}}}}];

Plot3D[sol[t, x], {t, 0, 60}, {x, 0, h}, PlotRange -> Full, 
       PlotStyle -> Automatic, ColorFunction -> "DarkRainbow"]
Plot[NIntegrate[sol[t, x], {x, 0, a}], {t, 0, 60}]

enter image description here

I successfully got a result of the PDE calculation, but the code take lot of time in the integral part. It doesn't finish even I wait for a few hours.

Any suggestions how to speed it up or fix it?

$\endgroup$
6
  • 1
    $\begingroup$ @MapleSE-Area51Proposal This question isn't a duplicate of former question of OP, notice this time OP asked about performance tuning of numerical integration. $\endgroup$
    – xzczd
    Commented Mar 5, 2017 at 14:27
  • 1
    $\begingroup$ To be more specific, core = u /. sol[[1]]; mid[t_?NumericQ] := NIntegrate[core[t, x], {x, 0, a}, Method -> {Automatic, "SymbolicProcessing" -> 0}]; Plot[mid@t, {t, 0, 60}] // AbsoluteTiming will resolve your problem. $\endgroup$
    – xzczd
    Commented Mar 5, 2017 at 14:30
  • $\begingroup$ @xzczd Thanks for pointing that out, My bad! $\endgroup$
    – zhk
    Commented Mar 5, 2017 at 14:36
  • $\begingroup$ @xzczd OP used NDSolveValue so your suggestion doesn't seem to immediately run. $\endgroup$
    – Chris K
    Commented Mar 5, 2017 at 22:10
  • $\begingroup$ Maybe the Method values are overkill. I simply used sol = NDSolve[{deqN, ic}, u, {t, 0, 60}, {x, 0, h}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"FiniteElement"}}] as @Andre suggested here and it ran very quickly. $\endgroup$
    – Chris K
    Commented Mar 5, 2017 at 22:12

0