1
$\begingroup$

In some applications, it is advantageous to access components of NDSolve. However, we could also need to observe the step size taken in the numerical integration, as in Stiffness Detection. For example:

{ndssdata} = NDSolve`ProcessEquations[{D[u[t, x], t] == 
0.1 D[u[t, x], x, x] + u[t, x] D[u[t, x], x], 
u[0, x] == Cos[2 Pi x], u[t, 0] == u[t, 1]}, u, t, {x, 0, 1},
Method -> "StiffnessSwitching"
(*Method\[Rule]"ExplicitRungeKutta"*)]

tm = 1;
NDSolve`Iterate[ndssdata, {0, tm}]
sol = NDSolve`ProcessSolutions[ndssdata]

My questions:

  1. How to obtain and plot the step sizes just as using StepDataPlot[] with NDSolve;

  2. How to save the InterpolatingFunction u[t,x] in order to upload and plot with it afterward using Get[...] and Plot3D[u[t, x] /. sol...] after closing and re-opening MMA.

I tried DumpSave["test.mx", sol] and Get["...\\test.mx"] which gives me

Get::noopen: Cannot open ...\test.mx. >> $Failed

Please leave your comments and thoughts. Thank you for any suggestions and help.

$\endgroup$
  • $\begingroup$ Did you already have a look at the code within NDSolveUtilities.m? The implementation of StepDataPlot[] should be there, which you can modify for your needs. $\endgroup$ – J. M.'s discontentment Mar 17 '19 at 14:50
  • $\begingroup$ @J.M.isslightlypensive Sorry I haven't. Did you mean the last subsection in Advanced Numerical Differential Equation Solving? $\endgroup$ – user55777 Mar 17 '19 at 14:55
  • $\begingroup$ No, I meant for you to look at the file in the location returned by FileNameJoin[{$InstallationDirectory, "AddOns", "ExtraPackages", "DifferentialEquations", "NDSolveUtilities.m"}]. $\endgroup$ – J. M.'s discontentment Mar 17 '19 at 15:05
  • $\begingroup$ You can use, sol >> "D:\\sol_data" for storing the data at a particular location (say at D, with a file name sol_data, no extension is required.) To get the data back to a variable, you can write solImport=<<"D:\\sol_data". This will work even after closing and reopening Mathematica. To plot the data, use Plot3D[u[t, x] /. solImport, {t, 0, 1}, {x, 0, 1}]. $\endgroup$ – Soumyajit Roy Apr 30 '19 at 12:52
1
$\begingroup$

The step data is stored in the interpolating function:

sol = NDSolveValue[{D[u[t, x], t] == 
     0.1 D[u[t, x], x, x] + u[t, x] D[u[t, x], x], 
    u[0, x] == Cos[2 Pi x], u[t, 0] == u[t, 1]}, 
   u, {t, 0, 1}, {x, 0, 1}, Method -> "StiffnessSwitching"];

sol["Coordinates"][[1]]
{0.`, 0.06800128840268457`, 0.09489195680748204`, \
0.13502467607112256`, 0.18776999888298834`, 0.2546090610966109`, \
0.33329197483384987`, 0.4236985592366587`, 0.5236985592366588`, \
0.6236985592366587`, 0.7236985592366587`, 0.8236985592366587`, \
0.9236985592366588`, 1.`}
| improve this answer | |
$\endgroup$

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.