Luthaf / Jumos.jl

Julia toolbox for molecular simulations
http://jumos.readthedocs.org/en/latest/
Other
23 stars 11 forks source link

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

Open Luthaf opened 9 years ago

Luthaf commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

Ref : doi:10.1016/j.jcp.2009.09.028

Using piecewise polynomials

Luthaf commented 9 years ago

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.

mcprentiss commented 9 years ago

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