1

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?

xzczd
  • 65,995
  • 9
  • 163
  • 468
H. Kuwae
  • 83
  • 4
  • 1
    @MapleSE-Area51Proposal This question isn't a duplicate of former question of OP, notice this time OP asked about performance tuning of numerical integration. – xzczd Mar 05 '17 at 14:27
  • 1
    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. – xzczd Mar 05 '17 at 14:30
  • @xzczd Thanks for pointing that out, My bad! – zhk Mar 05 '17 at 14:36
  • @xzczd OP used NDSolveValue so your suggestion doesn't seem to immediately run. – Chris K Mar 05 '17 at 22:10
  • 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. – Chris K Mar 05 '17 at 22:12
  • @ChrisK Oh, didn't notice that. (I used the code in the previous post of OP. ) Then mid[t_?NumericQ] := NIntegrate[sol[t, x], {x, 0, a}, Method -> {Automatic, "SymbolicProcessing" -> 0}]; Plot[mid@t, {t, 0, 60}] // AbsoluteTiming is enough :) – xzczd Mar 06 '17 at 03:19

0 Answers0