Open Luthaf opened 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.
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
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.
Ref : doi:10.1016/j.jcp.2009.09.028
Using piecewise polynomials
For doing grid interpolations https://github.com/sisl/GridInterpolations.jl maybe helpful.
See this gist : https://gist.github.com/Luthaf/a30fae741ed9f937a97b
The output on my machine :