5
$\begingroup$

I have a system of coupled first order partial differential equations. Minimal code is shown below:

de1 = D[f[t, p], t] == 
   p/t D[ 1/3 f[t, p] + 2/15 g[t, p], p] + 2/5 1/t g[t, p];
de2 = D[g[t, p], t] == 
   p/t D[11/21 g[t, p] + 2/3 f[t, p], p] + 2/7 1/t g[t, p] - g[t, p];
IC = {f[t0, p] == Exp[-p], g[t0, p] == 1/2 Exp[-p]};

t0 = 0.1;
sol = NDSolve[{de1, de2, IC}, {f, g}, {t, t0, 1}, {p, 10^-2, 10}, 
   Method -> {"MethodOfLines", "TemporalVariable" -> t, 
     "SpatialDiscretization" -> {"FiniteElement", 
       "MeshOptions" -> {"MaxCellMeasure" -> 0.5}}}] // Flatten

First, note that the initial conditions are only specified on one boundary. I want to export the values of functions f and g at specific t (say t1) in format {p, f(t1,p), g(t1,p)}. Also, is it possible to export at any t1 (not just at the evaluated grid)?

I am newbie in solving PDE's. Any suggestions to improve the code is much appreciated.

$\endgroup$

1 Answer 1

6
$\begingroup$

modified

The result of NDSolve offers interpolation functions, which might be evaluated at arbitrary gridpoints.

Try

{F, G} = NDSolveValue[{de1, de2, IC}, {f, g}, {t, t0, 1}, {p,10^-2,10}, Method -> {"MethodOfLines", "TemporalVariable" -> t,"SpatialDiscretization" -> {"FiniteElement","MeshOptions" -> {"MaxCellMeasure" -> 0.5}}}] // Flatten

grid=Table[{t,p,F[t,p],G[t,p]},{t,Subdivide[t0,1,10]},{p,Subdivide[10^-2,10,  10]}]

This works too in a predefined spatial mesh:

n = 10;
meshp = ToElementMesh[Table[{10^-2 + (10 - 10^-2 ) ((i - 1)/( n - 1 ))^2}, {i, 1,n}]]
{F, G} = NDSolveValue[{de1, de2, IC}, {f, g}, {t, t0, 1}
,Element[p, meshp],Method -> {"MethodOfLines", "TemporalVariable" -> t,"SpatialDiscretization" -> {"FiniteElement","MeshOptions" -> {"MaxCellMeasure" -> 0.5}}}] //Flatten
$\endgroup$
5
  • $\begingroup$ Thanks a lot! Precisely what I wanted. $\endgroup$ Jun 10, 2021 at 13:12
  • $\begingroup$ You're welcome. Alternatively if you intend to use the result of NDSolve in another Mathematica session perhaps DumpSave might be helpful! $\endgroup$ Jun 10, 2021 at 13:52
  • $\begingroup$ Thanks. On a related question, is it possible to specify nonuniform (say exponential) grid in MeshOptions? $\endgroup$ Jun 11, 2021 at 7:55
  • 1
    $\begingroup$ @SunilJaiswal NDSolve works in a predefined mesh too. See my modified answer! $\endgroup$ Jun 11, 2021 at 8:44
  • $\begingroup$ Thanks again! Works after including the package << NDSolve`FEM . $\endgroup$ Jun 11, 2021 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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