6
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ A related question. $\endgroup$ – J. M. is away Aug 14 '17 at 17:12
  • 1
    $\begingroup$ Here's another related question. Unfortunately it uses if["Grid"], which also causes the kernel to crash on your example. $\endgroup$ – Chris K Aug 14 '17 at 17:23
  • $\begingroup$ @J.M. This also uses the NDSolve, I have tried to do the same, but haven't been able to make it work. $\endgroup$ – sdc Aug 14 '17 at 19:19
  • $\begingroup$ @MichaelE2 I want the function along x=0 and y= 0 for all time t. So it's spatial slice rather than time slice. $\endgroup$ – sdc Aug 15 '17 at 1:12
  • 1
    $\begingroup$ 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...." $\endgroup$ – Michael E2 Aug 15 '17 at 18:27
3
$\begingroup$

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["NDSolve`FEM`"]

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  *)
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – sdc Aug 15 '17 at 20:41
  • $\begingroup$ @sdc tpts has been added -- thanks! $\endgroup$ – Michael E2 Aug 15 '17 at 22:07
  • $\begingroup$ 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]]]] $\endgroup$ – sdc Aug 17 '17 at 23:23
5
$\begingroup$

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"]
$\endgroup$
  • $\begingroup$ This is good to know. Thanks. :) $\endgroup$ – sdc Aug 17 '17 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.