# Reduce the dimension of InterpolatingFunction

So I have been trying to extract 2D interpolating function(x,t) or (y,t) from 3D interpolating function(x,y,t) by replacing y=0 or x=0. My domain is triangular(see below). Ultimately, I want to integrate this extracted function along the line(x=0) over the time. So far I am having trouble doing it. Here is the example code:

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}];


Why doesn't the fksol[0,y,t] give me interpolating function with only two variables domain?

I tried to workaround similar to here, but kernel crashes for fksol["ValuesOnGrid"].

Thanks.

• A related question. – J. M.'s technical difficulties Aug 14 '17 at 17:12
• Here's another related question. Unfortunately it uses if["Grid"], which also causes the kernel to crash on your example. – Chris K Aug 14 '17 at 17:23
• @J.M. This also uses the NDSolve, I have tried to do the same, but haven't been able to make it work. – sdc Aug 14 '17 at 19:19
• @MichaelE2 I want the function along x=0 and y= 0 for all time t. So it's spatial slice rather than time slice. – sdc Aug 15 '17 at 1:12
• I was thinking something like Table[{{y, t}, fksol[y, t]}, {y, 0., 1., 0.01}, {t, 0., 1., 0.01}] and not "Grid". -- I'm confused about the NIntegrate: The code in your comment has no derivatives but you say "integration of derivative...." – Michael E2 Aug 15 '17 at 18:27

Too long for a comment, and possibly an answer....

Question/comment, based on the OP and comments:

The following integrates fksol[0.1, y, t] over the slice of the interpolating function's domain where x == 0.1. Is that what you're after?

Needs["NDSolveFEM"]

emesh = fksol["ElementMesh"];

getY[x0_] :=
With[{emx = ToElementMesh@ DiscretizeRegion@
RegionIntersection[MeshRegion@emesh, ImplicitRegion[x >= x0, {x, y}]]},
With[{coords = emx["Coordinates"]},
With[{bdy = emx["BoundaryElements"] /. LineElement -> List /.
idcs : {__Integer} :> coords[[idcs]]},
Union @@
Cases[bdy, seg : {{x_ /; x == x0, _} ..} :> seg[[All, 2]], Infinity]
]]];

tpts = Last@fksol["Coordinates"];

int[x_?NumericQ, y_?NumericQ, t_?NumericQ] := fksol[x, y, t];
With[{x = 0.1},
NIntegrate[int[x, y, t],
Evaluate@{y, Sequence @@ getY[x]},
Evaluate@{t, Sequence @@ tpts}, AccuracyGoal -> 17]
]
(*  0.039357  *)

• Yes, ultimately I want to integrate the function fksol[0.1, y, t] . I think you missed to define tpts in here. I mean integration of derivative like: With[{x = 0.1}, NIntegrate[Derivative[1,0,0][int][x, y, t], Evaluate@{y, Sequence @@ getY[x]}, Evaluate@{t, Sequence @@ tpts}, AccuracyGoal -> 17] ] . Thanks. – sdc Aug 15 '17 at 20:41
• @sdc tpts has been added -- thanks! – Michael E2 Aug 15 '17 at 22:07
• I am adding this code which can get x-points for specified y0value. getX[y0_] := With[{emy = ToElementMesh@DiscretizeRegion@ RegionIntersection[MeshRegion@emesh, ImplicitRegion[y >= y0, {x, y}]]}, With[{coordy = emy["Coordinates"]}, With[{bdx = emy["BoundaryElements"] /. LineElement -> List /. idx : {__Integer} :> coordy[[idx]]}, Union @@ Cases[bdx, segx : {{_, y_ /; y == y0} ..} :> segx[[All, 1]], Infinity]]]] – sdc Aug 17 '17 at 23:23

To avoid the (reported) crash you can swap the order of t and the spatial variables like so:

region = Polygon[{{0, 0}, {0, 1}, {1, 0}}];
fksol = NDSolveValue[{Derivative[0, 2, 0][u][t, x, y] +
Derivative[0, 0, 2][u][t, x, y] +
Derivative[0, 1, 0][u][t, x, y] +
Derivative[0, 0, 1][u][t, x, y] ==
Derivative[1, 0, 0][u][t, x, y],
u[0, x, y] == (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[t, 0, y] == 0, u[t, x, 0] == 0},
u, {t, 0, 1}, {x, y} \[Element] region];
fksol["ValuesOnGrid"]

• This is good to know. Thanks. :) – sdc Aug 17 '17 at 23:30