I am trying to solve numerically a system of linear ODEs with some quickly varying driving functions. The basic command is:
NDSolve[Eqs, Vars, {t, 0, 1}, MaxSteps -> 10^7, MaxStepSize -> 10^(-7), AccuracyGoal -> 10, PrecisionGoal -> 10];
The lists of equations and variables contain 30 elements. My problem is that Mathematica V10.1.0.0 uses inordinate amount of memory, more than 40 GB.
Even if I assume that at each point the interpolation function stores first and second derivatives and it uses double-precision numbers with 8 bytes, I get 10^7*30*8*3=7.2GB.
I tried InterpolationOrder->2 in NDSolve, but that does not reduce the memory used.
3`takes 16 bytes (ByteCount[3`]) on my machine, but arbitrary precision3`10occupies a whopping 80 bytes. At that rate with your settings, just storing the function value alone will cost you ca. 20 GB; value + 1st derivative may run into 40 GB or so. Do you see any difference without the accuracy and precision goals? – MarcoB Feb 04 '16 at 02:34ByteCount[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}]=280if I type the list explicitly. ButByteCount[Range[10]]=184,ByteCount[Range[10^6]]/10.0^6=8.00014. So it seems asymptotically it uses 8 bytes, but not always. Similarly in NDSolve, sometimes I getInterpolationFunctionthat usesDeveloperPackedArrayForm` and 48 bytes per point. And sometimes I get just a regular-looking array that uses 200 bytes per point. – Mike Feb 05 '16 at 16:37Rangegenerates a packed array object (seeNeeds["Developer`"]; PackedArrayQ@Range[10]). Compare alsoByteCount /@ FromPackedArray@Range[10^6]which returns 16 bytes per value once the list is unpacked. – MarcoB Feb 05 '16 at 16:51PackedArrayseems to be part of the issue here. If I look at theInterpolatingFunctionobject coming from NDSolve, in particular part[[4]]sometimes it containsDeveloperPackedArrayForm` and sometimes it doesn't. I haven't been able to determine why similar ODEs give different results – Mike Feb 05 '16 at 18:54InterpolatingFunctionobject here is a funny thing. Take part[[2,2]], which is an integer and change it to n. The number of bytes used changes. For n=0-3 its equal to 200 per data point, for n=4-7 it is 48 and for n=8 its 200 again and keeps repeating with period of 4. The actual evaluation result does not change. – Mike Feb 05 '16 at 19:15NDSolve, changing the method to "ExplicitRungeKutta" gives solutions with small memory use (48 bytes/point). But setting the method to "Adams" gives 200 bytes/point in theInterpolating Function. – Mike Feb 05 '16 at 22:20MaxStepSize -> 10^(-7)causes a lot of memory to be used. It seems unusually small. – Michael E2 Feb 08 '16 at 23:46InterpolatingFunction, see (q28337); some more info at (a98349). – Michael E2 Feb 08 '16 at 23:49InterpolatingFunctiondocumentation. As for step-size, well that is what is making the problem hard, the driving function has multiple time scales. – Mike Feb 09 '16 at 04:57