# NIntegrate crashes for Interpolating function

I am trying to integrate the output of NDSolve over 2D-space and time in the triangular domain that it's solved. It should be straight forward, but I haven't been able to set it up. Here is the code.

region = Polygon[{{0, 0}, {0, 1}, {1, 0}}];
fksol = NDSolve[{Derivative[2, 0, 0][u][x, y, t] + Derivative[0, 2, 0]
[u][x, y, t] + Derivative[1, 0, 0][u][x, y, t] + Derivative[0, 1, 0]
[u][x, y, t] == Derivative[0, 0, 1][u][x, y, t] +
NeumannValue[0, x + y >= 1], u[x, y,0] ==
(Erf[x/.1] - Erf[(x - 1)/.1] - 1) (Erf[y/.1] -
Erf[(y - 1)/.1] -1) (PDF[NormalDistribution[.2, .1], x]*
PDF[NormalDistribution[.8, .1], y] // Evaluate),u[0, y,t] == 0,
u[x, 0, t] == 0}, u[x, y,t], {x, y} ∈ region, {t, 0, 1}];

Table[ContourPlot[u[x, y, t] /. fksol /. {t -> tt}, {x, y} ∈
region], {tt, {0.01, 0.3, 0.5, 1}}]


For the integration. I tried to set it up different ways, but nothing is working. I hope someone can suggest me how to set it up. Thanks.

pr[x_, y_, t_] := u[x, y, t] /. fksol
NIntegrate[pr[x, y, t], {x, y} ∈ region, {t,0,1}]


This gives an error.

NIntegrate[pr[x, y, t], {x, 0, 1}, {y, 0, 1}, {t, 0, 1}]


This crashes Mathematica.

• The fkskol=... part does not parse, let alone evaluate. So this example needs to be fixed before further investigation. Aug 1, 2017 at 14:53
• That is in essence a duplicate with the addition that this is also time dependent. Aug 1, 2017 at 15:09
• @DanielLichtblau I fixed syntax errors, if that is what you mean. Thanks.
– sdc
Aug 1, 2017 at 19:29

## 1 Answer

Would this suit your needs?

region = Polygon[{{0, 0}, {0, 1}, {1, 0}}];
fksol = NDSolveValue[{Derivative[2, 0, 0][u][x, y, t] +
Derivative[0, 2, 0][u][x, y, t] +
Derivative[1, 0, 0][u][x, y, t] +
Derivative[0, 1, 0][u][x, y, t] ==
Derivative[0, 0, 1][u][x, y, t] + NeumannValue[0, x + y >= 1],
u[x, y, 0] == (Erf[x/.1] - Erf[(x - 1)/.1] - 1) (Erf[y/.1] -
Erf[(y - 1)/.1] -
1) (PDF[NormalDistribution[.2, .1], x]*
PDF[NormalDistribution[.8, .1], y] // Evaluate),
u[0, y, t] == 0, u[x, 0, t] == 0},
u, {x, y} ∈ region, {t, 0, 1}];

Table[ContourPlot[
fksol[x, y, t], {x, y} ∈ region], {t, {0.01, 0.3, 0.5,
1}}]
NIntegrate[
NIntegrate[
fksol[x, y, t], {x, y} ∈ fksol["ElementMesh"]], {t, 0, 1}]
0.017628414754904762
`

This is the same issue as shown here with the addition that is time dependent.

• Thanks, this worked in my actual solution. I kind of tried this way too but I didn't use NDSolveValue earlier and got errors. learning it :)
– sdc
Aug 1, 2017 at 19:33