Simplification of 3-body Berggren calculations

This commit is contained in:
Nuwan Yapa 2024-12-20 20:20:38 -05:00
parent 9c83e3e56b
commit 0204903bc6
3 changed files with 48 additions and 157 deletions

View File

@ -1,9 +1,4 @@
using Arpack, SparseArrays, LRUCache using Plots
using DelimitedFiles, Plots
include("../ho_basis.jl")
include("../p_space.jl")
println("No of threads = ", Threads.nthreads())
training_c = [2.6, 2.4, 2.2, 2.0, 1.8] training_c = [2.6, 2.4, 2.2, 2.0, 1.8]
extrapolating_c = 0.0 : 0.2 : 1.2 extrapolating_c = 0.0 : 0.2 : 1.2
@ -18,113 +13,63 @@ exact_ref = reverse([4.076662025307587-0.012709842443350328im,
1.7164583929199813-0.0005455212208182736im, 1.7164583929199813-0.0005455212208182736im,
1.233088227541505-0.0003070320106485624im]) 1.233088227541505-0.0003070320106485624im])
Λ = 0 include("../p_space_3body_resonance.jl")
m = 1.0 H0 = H
Va_of_r(r) = 2 * exp(-(r-3)^2 / (1.5)^2)
Vb_of_r(r) = -exp(-(r/3)^2)
atol = 10^-5 # Vp = perturbation to make the state artificially bound
maxevals = 10^5 Vp_of_r(r) = -exp(-(r/3)^2)
R_cutoff = 16 Vp_l(j, k, kp) = Vl_mat_elem(Vp_of_r, j, k, kp; atol=atol, maxevals=maxevals, R_cutoff=R_cutoff)
# due to Jacobi coordinates @time "Vp block diagonal part" begin
μ1 = m * 1/2 Vpb_blocks = [kron_sum(get_V_matrix((k, kp) -> Vp_l(j1, k, kp), ks, ws), spzeros(length(ks), length(ks))) for (j1, _) in js]
μ2 = m * 2/3 Vpb = blockdiag(sparse.(Vpb_blocks)...)
vertices = [0, 2 - 0.2im, 3, 4]
subdivisions = [16, 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 end
@time "Va1" begin @time "Vp2_HO" Vp2_HO = get_jacobi_V2_matrix(Vp_of_r, basis_ho, μω_global; atol=atol, maxevals=maxevals)
Va_l(j, k, kp) = Vl_mat_elem(Va_of_r, j, k, kp; atol=atol, maxevals=maxevals, R_cutoff=R_cutoff) @time "Vp2" Vp2 = W_left * Vp2_HO * transpose(W_right)
Va1_blocks = [kron(get_V_matrix((k, kp) -> Va_l(j1, k, kp), ks, ws), I(length(ks))) for (j1, _) in js] @time "Vp" Vp = Vpb + Vp2
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=R_cutoff)
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
basis_ho = ho_basis_2B(E_max, Λ)
@time "Va2_HO" Va2_HO = get_jacobi_V2_matrix(Va_of_r, basis_ho, μω_global; atol=atol, maxevals=maxevals)
@time "Vb2_HO" Vb2_HO = get_jacobi_V2_matrix(Vb_of_r, basis_ho, μω_global; atol=atol, maxevals=maxevals)
@time "W_right" W_right = get_W_matrix(basis, basis_ho, μ1ω1, μ2ω2; weights=true)
@time "W_left" W_left = get_W_matrix(basis, basis_ho, μ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" test_evals, _ = eigs(Ha, sigma=exact_ref[end], maxiter=5000, tol=1e-5, ritzvec=false, check=1)
display(test_evals)
# free memory # free memory
basis = T1 = T2 = V1_cache = V_relative_cache = V1 = V_relative = U = V2 = nothing basis = Hb_blocks = Hb = basis_ho = V2_HO = W_right = W_left = V2 = nothing
GC.gc() GC.gc()
current_E = training_ref
exact = ComplexF64[] exact = ComplexF64[]
training = ComplexF64[] training = ComplexF64[]
extrapolated = ComplexF64[] extrapolated = ComplexF64[]
training_vecs = Vector{ComplexF64}[] training_vecs = Vector{ComplexF64}[]
current_E = training_ref
for c in training_c for c in training_c
println("Training for c = $c") println("Training for c = $c")
H = Ha + c .* Vb
evals, evecs = eigs(H, sigma=current_E, maxiter=5000, tol=1e-5, ritzvec=true, check=1) local H = H0 + c .* Vp
local evals, evecs = eigs(H, sigma=current_E, maxiter=5000, tol=1e-5, ritzvec=true, check=1)
global current_E = nearest(evals, current_E) global current_E = nearest(evals, current_E)
push!(training, current_E) push!(training, current_E)
push!(training_vecs, evecs[:, nearestIndex(evals, current_E)]) push!(training_vecs, evecs[:, nearestIndex(evals, current_E)])
end end
# CA-EC training_vecs = vcat(training_vecs, conj(training_vecs)) # CA-EC
training_vecs = vcat(training_vecs, conj(training_vecs))
EC_basis = hcat(training_vecs...) EC_basis = hcat(training_vecs...)
weights_mat = spdiagm(repeat(kron(ws, ws), jmax + 1))
N_EC = transpose(EC_basis) * weights_mat * EC_basis N_EC = transpose(EC_basis) * weights_mat * EC_basis
Ha_EC = transpose(EC_basis) * weights_mat * Ha * EC_basis H0_EC = transpose(EC_basis) * weights_mat * H0 * EC_basis
Vb_EC = transpose(EC_basis) * weights_mat * Vb * EC_basis Vp_EC = transpose(EC_basis) * weights_mat * Vp * EC_basis
for c in extrapolating_c for c in extrapolating_c
println("Extrapolating for c = $c") println("Extrapolating for c = $c")
global current_E = pop!(exact_ref) global current_E = pop!(exact_ref)
H = Ha + c .* Vb local H = H0 + c .* Vp
evals, _ = eigs(H, sigma=current_E, maxiter=5000, tol=1e-5, ritzvec=false, check=1) local evals, _ = eigs(H, sigma=current_E, maxiter=5000, tol=1e-5, ritzvec=false, check=1)
global current_E = nearest(evals, current_E) global current_E = nearest(evals, current_E)
push!(exact, current_E) push!(exact, current_E)
# extrapolation # extrapolation
H_EC = Ha_EC + c .* Vb_EC H_EC = H0_EC + c .* Vp_EC
evals = eigvals(H_EC, N_EC) evals = eigvals(H_EC, N_EC)
push!(extrapolated, nearest(evals, current_E)) push!(extrapolated, nearest(evals, current_E))
end end

View File

@ -1,9 +1,4 @@
using Arpack, SparseArrays, LRUCache using Plots
using DelimitedFiles, Plots
include("../ho_basis.jl")
include("../p_space.jl")
println("No of threads = ", Threads.nthreads())
training_c = [1.1, 0.9, 0.7, 0.5] training_c = [1.1, 0.9, 0.7, 0.5]
extrapolating_c = 0.0 : 0.2 : 1.2 extrapolating_c = 0.0 : 0.2 : 1.2
@ -21,74 +16,24 @@ exact_ref = reverse([4.076662025307587-0.012709842443350328im,
1.7164583929199813-0.0005455212208182736im, 1.7164583929199813-0.0005455212208182736im,
1.233088227541505-0.0003070320106485624im]) 1.233088227541505-0.0003070320106485624im])
Λ = 0 include("../p_space_3body_resonance.jl")
m = 1.0 H0 = H
Va_of_r(r) = 2 * exp(-(r-3)^2 / (1.5)^2)
Vb_of_r(r) = -exp(-(r/3)^2)
atol = 10^-5 # Vp = perturbation to make the state artificially bound
maxevals = 10^5 Vp_of_r(r) = -exp(-(r/3)^2)
R_cutoff = 16 Vp_l(j, k, kp) = Vl_mat_elem(Vp_of_r, j, k, kp; atol=atol, maxevals=maxevals, R_cutoff=R_cutoff)
# due to Jacobi coordinates @time "Vp block diagonal part" begin
μ1 = m * 1/2 Vpb_blocks = [kron_sum(get_V_matrix((k, kp) -> Vp_l(j1, k, kp), ks, ws), spzeros(length(ks), length(ks))) for (j1, _) in js]
μ2 = m * 2/3 Vpb = blockdiag(sparse.(Vpb_blocks)...)
vertices = [0, 2 - 0.1im, 3, 4]
subdivisions = [16, 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 end
@time "Va1" begin @time "Vp2_HO" Vp2_HO = get_jacobi_V2_matrix(Vp_of_r, basis_ho, μω_global; atol=atol, maxevals=maxevals)
Va_l(j, k, kp) = Vl_mat_elem(Va_of_r, j, k, kp; atol=atol, maxevals=maxevals, R_cutoff=R_cutoff) @time "Vp2" Vp2 = W_left * Vp2_HO * transpose(W_right)
Va1_blocks = [kron(get_V_matrix((k, kp) -> Va_l(j1, k, kp), ks, ws), I(length(ks))) for (j1, _) in js] @time "Vp" Vp = Vpb + Vp2
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=R_cutoff)
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
basis_ho = ho_basis_2B(E_max, Λ)
@time "Va2_HO" Va2_HO = get_jacobi_V2_matrix(Va_of_r, basis_ho, μω_global; atol=atol, maxevals=maxevals)
@time "Vb2_HO" Vb2_HO = get_jacobi_V2_matrix(Vb_of_r, basis_ho, μω_global; atol=atol, maxevals=maxevals)
@time "W_right" W_right = get_W_matrix(basis, basis_ho, μ1ω1, μ2ω2; weights=true)
@time "W_left" W_left = get_W_matrix(basis, basis_ho, μ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" test_evals, _ = eigs(Ha, sigma=exact_ref[end], maxiter=5000, tol=1e-5, ritzvec=false, check=1)
display(test_evals)
# free memory # free memory
basis = T1 = T2 = V1_cache = V_relative_cache = V1 = V_relative = U = V2 = nothing basis = Hb_blocks = Hb = basis_ho = V2_HO = W_right = W_left = V2 = nothing
GC.gc() GC.gc()
exact = ComplexF64[] exact = ComplexF64[]
@ -100,8 +45,8 @@ for c in training_c
println("Training for c = $c") println("Training for c = $c")
global current_E = pop!(training_ref) global current_E = pop!(training_ref)
H = Ha + c .* Vb local H = H0 + c .* Vp
evals, evecs = eigs(H, sigma=current_E, maxiter=5000, tol=1e-5, ritzvec=true, check=1) local evals, evecs = eigs(H, sigma=current_E, maxiter=5000, tol=1e-5, ritzvec=true, check=1)
global current_E = nearest(evals, current_E) global current_E = nearest(evals, current_E)
push!(training, current_E) push!(training, current_E)
@ -109,22 +54,23 @@ for c in training_c
end end
EC_basis = hcat(training_vecs...) EC_basis = hcat(training_vecs...)
weights_mat = spdiagm(repeat(kron(ws, ws), jmax + 1))
N_EC = transpose(EC_basis) * weights_mat * EC_basis N_EC = transpose(EC_basis) * weights_mat * EC_basis
Ha_EC = transpose(EC_basis) * weights_mat * Ha * EC_basis H0_EC = transpose(EC_basis) * weights_mat * H0 * EC_basis
Vb_EC = transpose(EC_basis) * weights_mat * Vb * EC_basis Vp_EC = transpose(EC_basis) * weights_mat * Vp * EC_basis
for c in extrapolating_c for c in extrapolating_c
println("Extrapolating for c = $c") println("Extrapolating for c = $c")
global current_E = pop!(exact_ref) global current_E = pop!(exact_ref)
H = Ha + c .* Vb local H = H0 + c .* Vp
evals, _ = eigs(H, sigma=current_E, maxiter=5000, tol=1e-5, ritzvec=false, check=1) local evals, _ = eigs(H, sigma=current_E, maxiter=5000, tol=1e-5, ritzvec=false, check=1)
global current_E = nearest(evals, current_E) global current_E = nearest(evals, current_E)
push!(exact, current_E) push!(exact, current_E)
# extrapolation # extrapolation
H_EC = Ha_EC + c .* Vb_EC H_EC = H0_EC + c .* Vp_EC
evals = eigvals(H_EC, N_EC) evals = eigvals(H_EC, N_EC)
push!(extrapolated, nearest(evals, current_E)) push!(extrapolated, nearest(evals, current_E))
end end

View File

@ -36,14 +36,14 @@ println("Basis size = $basis_size")
Hb = blockdiag(sparse.(Hb_blocks)...) Hb = blockdiag(sparse.(Hb_blocks)...)
end end
E_max = 30 E_max = 40
μω_global = 0.5 μω_global = 0.5
μ1ω1 = μω_global * 1/2 μ1ω1 = μω_global * 1/2
μ2ω2 = μω_global * 2 μ2ω2 = μω_global * 2
basis_ho = ho_basis_2B(E_max, Λ) basis_ho = ho_basis_2B(E_max, Λ)
@time "V2_HO" V2_HO = get_jacobi_V2_matrix(V_of_r, basis_ho, μω_global) @time "V2_HO" V2_HO = get_jacobi_V2_matrix(V_of_r, basis_ho, μω_global; atol=atol, maxevals=maxevals)
@time "W_right" W_right = get_W_matrix(basis, basis_ho, μ1ω1, μ2ω2; weights=true) @time "W_right" W_right = get_W_matrix(basis, basis_ho, μ1ω1, μ2ω2; weights=true)
@time "W_left" W_left = get_W_matrix(basis, basis_ho, μ1ω1, μ2ω2; weights=false) @time "W_left" W_left = get_W_matrix(basis, basis_ho, μ1ω1, μ2ω2; weights=false)