Jumos.jl icon indicating copy to clipboard operation
Jumos.jl copied to clipboard

Use a lookup in a table to save time in potential computations ?

Open Luthaf opened this issue 9 years ago • 6 comments

See this gist : https://gist.github.com/Luthaf/a30fae741ed9f937a97b

The output on my machine :

Relative difference: 0.0030037844682750453
Direct computing
elapsed time: 1.238753331 seconds (320000000 bytes allocated, 10.19% gc time)
Table lookup
elapsed time: 0.195861645 seconds (0 bytes allocated)

Luthaf avatar Nov 27 '14 15:11 Luthaf

This could be OK with a relative diff of 10^-6 at least.

So closing for now, I may try again with non linear interpolation someday.

Luthaf avatar Nov 30 '14 19:11 Luthaf

This can be implemented as a BaseForceComputer subtype :

    type TableLookupForces <: BaseForcesComputer
        data::Array{Float64, 2}
        interactions::Dict{(Int, Int), Int}
        bins::Int
        dr::Float64
    end

    function TableLookupForces(bins::Integer, rmax::Float64)
        dr = rmax/bins
        data = Array(Float64, bins , 0)
        return TableLookupForces(data, Dict{(Int, Int), Int}, bins)
    end

    function force(f::TableLookupForces, atom_i::Int, atom_j::Int, r::Real)
        idx = f.interactions[(atom_i, atom_j)]
        bin = int(r/f.dr)
        return f.data[bin, idx] # Have a better function here.
    end

Luthaf avatar Dec 16 '14 23:12 Luthaf

Even better : use the gist implementation, i.e. a subtype of Potential. This allow for computations of forces using Verlet Lists and table lookup at the same time.

Luthaf avatar Dec 17 '14 12:12 Luthaf

Ref : doi:10.1016/j.jcp.2009.09.028

Using piecewise polynomials

Luthaf avatar Jan 24 '15 20:01 Luthaf

Done in 9ee0a2f8c9669a26a99ed9100b15979c774d5982, using a linear interpolation.

@mcprentiss if you wants to have a look at this and use a better approximation, feels free ! The interpolation is here and here.

Luthaf avatar Jan 26 '15 23:01 Luthaf

For doing grid interpolations https://github.com/sisl/GridInterpolations.jl maybe helpful.

mcprentiss avatar Feb 12 '15 19:02 mcprentiss