From 8431b4b7e3390980dfed585825697ad6b37c6403 Mon Sep 17 00:00:00 2001 From: Nuwan Yapa Date: Mon, 1 Jul 2024 12:01:41 -0400 Subject: [PATCH] Berggren R2R calculation --- calculations/3body_Berggren_R2R_EC.jl | 132 ++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 calculations/3body_Berggren_R2R_EC.jl diff --git a/calculations/3body_Berggren_R2R_EC.jl b/calculations/3body_Berggren_R2R_EC.jl new file mode 100644 index 0000000..a1a623a --- /dev/null +++ b/calculations/3body_Berggren_R2R_EC.jl @@ -0,0 +1,132 @@ +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 + +training_ref = reverse([1.4750633616275919 - 0.0003021770706749637im + 1.9567078295375822 - 0.0007646829108872369im + 2.4351117758403076 - 0.001281037843108658im]) + +exact_ref = reverse([4.076662025307587-0.012709842443350328im, + 3.613318119833891-0.007335804709990623im, + 3.1453431847006783-0.004030580410326795im, + 2.672967129943755-0.00211498327461944im, + 2.196542557810288-0.0010719835443437104im, + 1.7164583929199813-0.0005455212208182736im, + 1.233088227541505-0.0003070320106485624im]) + +Λ = 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 = [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 + +@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" test_evals, _ = eigs(Ha, sigma=exact_ref[end], maxiter=5000, tol=1e-5, ritzvec=false, check=1) + +display(test_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() + +training_c = [1.1, 0.9, 0.7] +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") + global current_E = pop!(training_ref) + + H = Ha + c .* Vb + evals, evecs = eigs(H, sigma=current_E, 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 + +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 + +for c in extrapolating_c + println("Extrapolating for c = $c") + global current_E = pop!(exact_ref) + + H = Ha + c .* Vb + evals, _ = eigs(H, sigma=current_E, maxiter=5000, tol=1e-5, ritzvec=false, 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 + +scatter(real.(training),imag.(training), label="training") +scatter!(real.(exact),imag.(exact), label="exact") +scatter!(real.(extrapolated),imag.(extrapolated), label="extrapolated") +savefig("temp/Berggren_R2R.pdf") \ No newline at end of file