BergEC-jl/calculations/3body_Berggren_B2R_EC.jl

127 lines
4.1 KiB
Julia

using Arpack, SparseArrays, LRUCache
using DelimitedFiles, Plots
include("../ho_basis.jl")
include("../p_space.jl")
include("../berggren.jl")
println("No of threads = ", Threads.nthreads())
atol = 10^-5
maxevals = 10^5
Λ = 0
m = 1.0
Va_of_r(r) = 2 * exp(-(r-3)^2 / (1.5)^2)
Vb_of_r(r) = -exp(-(r/3)^2)
# due to Jacobi coordinates
μ1 = m * 1/2
μ2 = m * 2/3
vertices = [0, 2 - 0.1im, 3, 4]
subdivisions = [10, 10, 10]
ks, ws = get_mesh(vertices, subdivisions)
jmax = 4
tri((j1, j2)) = triangle_ineq(j1, j2, Λ)
js = collect(Iterators.filter(tri, iter_prod(0:jmax, 0:jmax)))
basis = iter_prod(js, zip(ks, ws), zip(ks, ws)) # basis = ((j1, j2), (k1, w1), (k2, w2))
basis_size = length(js) * length(ks)^2
weights_mat = spdiagm(repeat(kron(ws, ws), jmax + 1))
@assert length(basis) == basis_size "Something wrong with the basis"
println("Basis size = $basis_size")
@time "T" begin
T_blocks = [kron_sum(get_T_matrix(ks, μ1), get_T_matrix(ks, μ2)) for _ in js]
T = blockdiag(sparse.(T_blocks)...)
end
@time "Va1" begin
Va_l(j, k, kp) = Vl_mat_elem(Va_of_r, j, k, kp; atol=atol, maxevals=maxevals, R_cutoff=16)
Va1_blocks = [kron(get_V_matrix((k, kp) -> Va_l(j1, k, kp), ks, ws), I(length(ks))) for (j1, _) in js]
Va1 = blockdiag(sparse.(Va1_blocks)...)
end
@time "Vb1" begin
Vb_l(j, k, kp) = Vl_mat_elem(Vb_of_r, j, k, kp; atol=atol, maxevals=maxevals, R_cutoff=16)
Vb1_blocks = [kron(get_V_matrix((k, kp) -> Vb_l(j1, k, kp), ks, ws), I(length(ks))) for (j1, _) in js]
Vb1 = blockdiag(sparse.(Vb1_blocks)...)
end
E_max = 40
μω_global = 0.5
μ1ω1 = μω_global * 1/2
μ2ω2 = μω_global * 2
@time "Va2_HO" Va2_HO = get_jacobi_V2_matrix(Va_of_r, E_max, Λ, μω_global; atol=atol, maxevals=maxevals)
@time "Vb2_HO" Vb2_HO = get_jacobi_V2_matrix(Vb_of_r, E_max, Λ, μω_global; atol=atol, maxevals=maxevals)
@time "W_right" W_right = get_W_matrix(basis, E_max, Λ, μ1ω1, μ2ω2; weights=true)
@time "W_left" W_left = get_W_matrix(basis, E_max, Λ, μ1ω1, μ2ω2; weights=false)
@time "Va2" Va2 = W_left * Va2_HO * transpose(W_right)
@time "Vb2" Vb2 = W_left * Vb2_HO * transpose(W_right)
@time "Ha" Ha = T + Va1 + Va2
@time "Vb" Vb = Vb1 + Vb2
@time "Eigenvalues" target_evals, _ = eigs(Ha, nev=3, ncv=24, which=:LI, maxiter=5000, tol=1e-5, ritzvec=false, check=1)
display(target_evals)
# free memory
Es = n1s = l1s = n2s = l2s = mask1 = mask2 = T1 = T2 = V1_cache = V_relative_cache = V1 = V_relative = U = V2 = nothing
GC.gc()
current_E = -0.72763
training_c = [2.0, 1.9, 1.8]
extrapolating_c = 0.0 : 0.2 : 1.2
exact = ComplexF64[]
training = ComplexF64[]
extrapolated = ComplexF64[]
training_vecs = Vector{ComplexF64}[]
for c in training_c
println("Training for c = $c")
H = Ha + c .* Vb
evals, evecs = eigs(H, nev=3, ncv=24, which=:LI, maxiter=5000, tol=1e-5, ritzvec=true, check=1)
global current_E = nearest(evals, current_E)
push!(training, current_E)
push!(training_vecs, evecs[:, nearestIndex(evals, current_E)])
end
# CA-EC
training_vecs = vcat(training_vecs, conj(training_vecs))
EC_basis = hcat(training_vecs...)
N_EC = transpose(EC_basis) * weights_mat * EC_basis
Ha_EC = transpose(EC_basis) * weights_mat * Ha * EC_basis
Vb_EC = transpose(EC_basis) * weights_mat * Vb * EC_basis
current_E = 4.0766890719636635 - 0.01275892774109674im
for c in extrapolating_c
println("Extrapolating for c = $c")
H = Ha + c .* Vb
evals, evecs = eigs(H, nev=3, ncv=24, which=:LI, maxiter=5000, tol=1e-5, ritzvec=true, check=1)
global current_E = nearest(evals, current_E)
push!(exact, current_E)
# extrapolation
H_EC = Ha_EC + c .* Vb_EC
evals = eigvals(H_EC, N_EC)
push!(extrapolated, nearest(evals, current_E))
end
open("temp/Berggren_B2R.training.csv", "w") do f; writedlm(f, hcat(reim(training)...)); end
open("temp/Berggren_B2R.exact.csv", "w") do f; writedlm(f, hcat(reim(exact)...)); end
open("temp/Berggren_B2R.extrapolated.csv", "w") do f; writedlm(f, hcat(reim(extrapolated)...)); end
scatter(real.(training),imag.(training), label="training")
scatter!(real.(exact),imag.(exact), label="exact")
scatter!(real.(extrapolated),imag.(extrapolated), label="extrapolated")
savefig("temp/Berggren_B2R.pdf")