How to apply the utility Packages for Numerical Differential Equation Solving

I have solved two coupled equations with {Solf, Solg} = NDSolveValue[eqns, {f, g}, {x, 0, L}, {t, 0, tmax}] and want to extract the computational grid {x,t} with InterpolatingFunctionDomain and InterpolatingFunctionGrid to observe the spatial mesh and to plot the time steps. In addition, sometimes it cannot compute a solution over the full time-interval that I specified, so I want to plot the solution that was computed in order to understand what might have gone wrong.

By reading the document, I know how to do this when using NDSolve to solve a single equation for h[x,t]. For example,

hSol = First[h/.NDSolve[eqn, f, {x, 0, L}, {t, 0, tmax}]]

hGrid = InterpolatingFunctionGrid[hSol]

Dimensions[hGrid] (*determine mesh points in each dimension*)

{Tini, Tfinal} = InterpolatingFunctionDomain[hSol][[2]] (*extract the time interval*)

tList = hGrid[[mesh-position, All, 2]]; (*here the 'mesh-position' can be chosen according to the output of Dimensions[hGrid]*)


Then we can plot the time steps at the mesh-position using

ListLogPlot[tList, PlotRange -> All, Frame -> True, FrameLabel -> {"step", "t"}]


But I cannot extend these to the case in which I used NDSolveValue to solve two coupled equations for f[x,t] and g[x,t], as mentioned above. For example, using hGrid = InterpolatingFunctionGrid[Solf] and Dimensions[hGrid] I obtained {1}, which was clearly wrong and should be in the form of {number-of-space-mesh, number-of-time-step, 2}.

I think the problem results form the structure of the output of {Solf, Solg} = NDSolveValue[...]. In this case the output is in this form: {InterpolatingFunction[{{0.,L},{0.,tmax}},<>],InterpolatingFunction[{{0.,L},{0.,tmax}},<>]}. Please help.

Here is an example from the document of NDSolveValue:

pde={\!$$\*SubscriptBox[\(\[PartialD]$$, $$t$$]$$u[t, x]$$\)==\!$$\*SubscriptBox[\(\[PartialD]$$, $$x$$]$$(\((v[t, x] - 1)$$\
\*SubscriptBox[$$\[PartialD]$$, $$x$$]u[t, x])\)\)+(16 x t-2 t-16 (v[t,x]-1)) (u[t,x]-1)+10 x E^(-4 x),\!$$\*SubscriptBox[\(\[PartialD]$$, $$t$$]$$v[t, x]$$\)==\!$$\*SubscriptBox[\(\[PartialD]$$, $${x, 2}$$]$$v[t, x]$$\)+\!$$\*SubscriptBox[\(\[PartialD]$$, $$x$$]$$u[t, x]$$\)+4 u[t,x]-4+x^2-2 t-10 t E^(-4 x)};

bc={u[0,x]==1,v[0,x]==1,u[t,0]==1,v[t,0]==1,3 u[t,1]+(u^(0,1))[t,1]==3,5 (v^(0,1))[t,1]==E^4 (u[t,1]-1)};

{usol, vsol} = NDSolveValue[{pde, bc}, {u, v}, {x, 0, 1}, {t, 0, 2}]

• There should be no difference. Please show us a specific example that reproduces the issue. – xzczd Aug 26 '19 at 7:58
• @xzczd please see the update. – Nobody Aug 26 '19 at 8:05
• You haven't pasted the example correctly. After correcting the mistake, the output of InterpolatingFunctionGrid@usol // Dimensions is {38,25,2}. – xzczd Aug 26 '19 at 8:14
• Thank you @xzczd, but how to plot the time step in the middle of space (i.e. position 19) with ListLogPlot[tList, PlotRange -> All, Frame -> True, FrameLabel -> {"step", "t"}]? – Nobody Aug 26 '19 at 8:46
• In this case NDSolve is using a uniform grid i.e. just choose any member of 2nd dimension: e.g. usol["Grid"][[All, 1, 1]] // ListPlot, or even simpler: usol["Coordinates"][[1]] // ListPlot – xzczd Aug 26 '19 at 10:14