# How to include interpolating solution as input into NDSolveValue

I am trying to solve:

Needs["NDSolveFEM"];
reg = ImplicitRegion[x^2 + y^2 <= 1, {x, y}];
mesh = ToElementMesh[reg]

s = NDSolveValue[{Derivative[0, 2][f][x, y] +
Derivative[2, 0][f][x, y] == 0,
DirichletCondition[f[x, y] == Sin[x y], True]},
f, {x, y} \[Element] mesh];


Test Function

      g[x_, y_] := Evaluate[s[x, y]];
g[0.1, 0.2]

out: 0.0193817

sol2 = NDSolveValue[{D[u[t, x, y], t] ==
D[u[t, x, y], x, x] + g[x, y].Grad[u[t, x, y], {x, y}],
u[0, x, y] == 0, DirichletCondition[u[t, x, y] == 0, True]},
u, {t, 0, 30}, {x, y} \[Element] reg]


getting error as: PDE parsing error of or Inconsistent equation dimensions, I am missing mathematica syntax, how to include interpolating solution into NDSolveValue?

• It will be much easier to help you if you post all the code that is necessary to reproduce the issue. Next, using I as the name of the dependent variable is a bad idea, as I is Sqrt[-1] Apr 20, 2016 at 6:28

Grad (g) returns a vector - but your PDE is scalar. Here is an example where I sum over the squares g and take the sqrt (which is a scalar):

Needs["NDSolveFEM"];
reg = ImplicitRegion[x^2 + y^2 <= 1, {x, y}];
mesh = ToElementMesh[reg];
(*RegionPlot[reg]*)

s = NDSolveValue[{Derivative[0, 2][f][x, y] +
Derivative[2, 0][f][x, y] == 0,
DirichletCondition[f[x, y] == Sin[x y], True]},
f, {x, y} \[Element] mesh];
g[x_, y_] := Evaluate[Grad[s[x, y], {x, y}]];
sol2 = NDSolveValue[{D[u[t, x, y], t] ==
D[u[t, x, y], x, x] + 0.5*Sqrt[Total[g[x, y]^2]], u[0, x, y] == 0,
DirichletCondition[u[t, x, y] == 0, True]},
u, {t, 0, 30}, {x, y} \[Element] mesh]


A version with Dot:

Needs["NDSolveFEM"];
reg = ImplicitRegion[x^2 + y^2 <= 1, {x, y}];
mesh = ToElementMesh[reg];
(*RegionPlot[reg]*)

s = NDSolveValue[{Derivative[0, 2][f][x, y] +
Derivative[2, 0][f][x, y] == 0,
DirichletCondition[f[x, y] == Sin[x y], True]},
f, {x, y} \[Element] mesh];
g[x_, y_] := Evaluate[0.5*Grad[s[x, y], {x, y}]];
sol2 = NDSolveValue[{D[u[t, x, y], t] ==
D[u[t, x, y], x, x] + g[x, y].Grad[u[t, x, y], {x, y}],
u[0, x, y] == 0, DirichletCondition[u[t, x, y] == 0, True]},
u, {t, 0, 30}, {x, y} \[Element] mesh]


This gives a message that the PDE is convection dominated an the result may not be stable.

• @Matica, same issue. Grad returns a vector but you PDE is scalar. What is the PDE you want to model? Apr 21, 2016 at 20:21
• @Matica, g[x, y].Grad[u[t, x, y], {x,y}] works. The 0.5* should go inside the Evaluate. Apr 21, 2016 at 21:11
• @Matica, see the update. Apr 21, 2016 at 21:27
• Better make it a question. Apr 26, 2016 at 0:02