I'm writing some code at the moment that schematically looks like:
(set initial conditions for some differential equation for given parameters (M,R,...))
(NDSolve differential equation taking ~10mins or more to give solution dependent on some more paramaters (w,l,m); defining a memoized function)
Phi[w_?NumericQ,l_?IntegerQ,m_?IntegerQ]:=Phi[w,l,m]= "Interpolated Func result of NDSolve taking 10mins to compute"
(For a given parameter set (w,l,m) compute a few things, such as coefficients and the (w,l,m) term in a sum, for which numerical differentiation ND[..] is needed, hence the necessity of memoizing this Phi to speed this step up)
A[w,l,m]:= "some calc dependent on the Phi"; B[w,l,m]:= "some calc dependent on the Phi" termSum[w,l,m]:= "some calc dependent on the Phi and A,B"
(write termSum to file)
(clear cache of the memoized Phi[w,l,m] interp func and the other variables like A[w,l,m])
. . . (after the rinse now repeat for a different (w,l,m))
Implemented by some 'do' or 'for' loop.
Some issues I'm considering:
1) Is there a way to use
Module say to allow me to better handle my caching of the variables (especially the huge memory hogs like the Phi that is a very large Interpolating Function)?
2) Also if I change my initial parameters M, R etc. I have to start all over again with setting initial conditions and so forth and functions that depend. Could I use
Module to incorporate this?
3) Is there a way to run some kind of initialization script in Mathematica that will set my constants, run my standard definitions etc. each time I load the notebook?
4) In a later calculation I will probably use the Phi,A,B for a given (w,l,m) all over again but for different values of 'r' along the range of the interpolating function. I've thought of saving to hard memory the actual interpolating functions of a given (w,l,m) but normal
Save leads to 200MB files, and even
DumpSave >20MB. Anything I could do about this or do I just have to recompute?