|
function Base.push!(cache::LatticeIteratorCache, key::Dir2SrcTrg, lattice::AbstractLattice, ϵ=1e-6) |
|
if !haskey(cache.cache, key) |
|
_positions = positions(lattice) |
|
wrap = generate_combinations(lattice_vectors(lattice)) |
|
directions = Vector{Float64}[] |
|
# (src, trg), first index is dir, second index irrelevant |
|
bonds = [Tuple{Int64, Int64}[] for _ in 1:length(lattice)] |
|
|
|
for origin in 1:length(lattice) |
|
for (trg, p) in enumerate(_positions) |
|
d = _positions[origin] .- p .+ wrap[1] |
|
for v in wrap[2:end] |
|
new_d = _positions[origin] .- p .+ v |
|
if directed_norm(new_d, ϵ) + ϵ < directed_norm(d, ϵ) |
|
d .= new_d |
|
end |
|
end |
|
# The rounding will allow us to use == here |
|
idx = findfirst(dir -> isapprox(dir, d, atol=ϵ), directions) |
|
if idx === nothing |
|
push!(directions, d) |
|
if length(bonds) < length(directions) |
|
push!(bonds, Tuple{Int64, Int64}[]) |
|
end |
|
push!(bonds[length(directions)], (origin, trg)) |
|
else |
|
push!(bonds[idx], (origin, trg)) |
|
end |
|
end |
|
end |
|
|
|
temp = sortperm(directions, by = v -> directed_norm(v, ϵ)) |
|
cache.cache[key] = bonds[temp] |
|
end |
|
nothing |
|
end |
MonteCarlo.jl/src/lattices/lattice_iterators.jl
Lines 65 to 100 in 6ae326e
MonteCarlo.jl/src/lattices/lattice_iterators.jl
Lines 666 to 688 in 6ae326e
These take up a lot of time when generating files. Maybe there is a better way to do this?