I have a long simulation. I’m trying to find a way to save the values of my simulation to disk and truncate the values held in memory.
My guess is to use a callback. So far I have:
using MAT
function save_and_clear(u, t, integ)
outFile = matopen("$(t)_X.mat","w");
write(outFile,"u",u);
close(outFile);
end
cb = FunctionCallingCallback(save_and_clear; funcat = [1000, 2000, 3000])
@time sim = solve(prob, Tsit5(), maxiters=1e10, saveat=SaveTimes, reltol = reltolVal, callback = cb);
This is sort of working. I’m getting the values at t = 1000, 2000, 3000. What I want are all the values from t \in [0, 1000), t \in [1000, 2000) and t \in [2000, 3000). How I access those values? I was guessing they were in integrator but I can’t find them. Furthermore, once I save, t \in [0, 1000), how do I remove them from memory?
If you instead do FunctionCallingCallback(save_and_clear), it will use the default func_everystep = true and thus fire at every step, thus saving at every step.
If you also save integ.k you can also rebuild the interpolant if you wanted.