Hi again everyone, I’ve got another question…
Using the DifferentialEquations
package, the solutions aren’t just discrete lists of numbers for the function and its derivative, but it’s also an INTERPOLATION scheme which can output the estimated value at ANY value of time. Some of my solutions will eventually take hours or days to complete, is there any way I could save the ENTIRE interpolation scheme to a file, for reading into Julia later?
For example, the (abbreviated) code below does the calc, and saves the discrete values only. Is there any way to save & read "sol"
back in as an interpolatable function? (e.g., for getting sol.u(t)[2]
for any t-value again, etc.)
using DifferentialEquations
using DelimitedFiles
prob = SecondOrderODEProblem(DiffEqToSolve!,vInit,xInit,tspan,Param)
sol = solve(prob, dense=true)
open(TimeSolnFileNm, "w") do file
writedlm(TimeSolnFileNm, getindex.(sol.t, 1))
end
open(dfSolnFileNm, "w") do file
writedlm(dfSolnFileNm, getindex.(sol.u, 1))
end
open(FnSolnFileNm, "w") do file
writedlm(FnSolnFileNm, getindex.(sol.u, 2))
end
ReadSolnTime = readdlm(TimeSolnFileNm)
ReadSolndf = readdlm(dfSolnFileNm)
ReadSolnFn = readdlm(FnSolnFileNm)
All of this stuff works to save & read the DISCRETE values of the solution – so I can always calculate, e.g., sol.u[10]
later – but how to save and read, e.g., sol(5.25)[2]
in a later running of the program, without re-solving everything?
(I saw some mentions elsewhere of BSON.jl and JLD2.jl; but BSON didn’t work when I tried it, and JLD2 seems not to be maintained.)
Thanks for any suggestions!