diff --git a/calculations/3body_Berggren_B2R_EC.jl b/calculations/3body_Berggren_B2R_EC.jl index 23675f5..5860bf3 100644 --- a/calculations/3body_Berggren_B2R_EC.jl +++ b/calculations/3body_Berggren_B2R_EC.jl @@ -1,9 +1,4 @@ -using Arpack, SparseArrays, LRUCache -using DelimitedFiles, Plots -include("../ho_basis.jl") -include("../p_space.jl") - -println("No of threads = ", Threads.nthreads()) +using Plots training_c = [2.6, 2.4, 2.2, 2.0, 1.8] extrapolating_c = 0.0 : 0.2 : 1.2 @@ -18,113 +13,63 @@ exact_ref = reverse([4.076662025307587-0.012709842443350328im, 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) +include("../p_space_3body_resonance.jl") +H0 = H -atol = 10^-5 -maxevals = 10^5 -R_cutoff = 16 +# Vp = perturbation to make the state artificially bound +Vp_of_r(r) = -exp(-(r/3)^2) +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 -μ1 = m * 1/2 -μ2 = m * 2/3 - -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)...) +@time "Vp block diagonal part" begin + 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] + Vpb = blockdiag(sparse.(Vpb_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=R_cutoff) - 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=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) +@time "Vp2_HO" Vp2_HO = get_jacobi_V2_matrix(Vp_of_r, basis_ho, μω_global; atol=atol, maxevals=maxevals) +@time "Vp2" Vp2 = W_left * Vp2_HO * transpose(W_right) +@time "Vp" Vp = Vpb + Vp2 # 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() -current_E = training_ref - exact = ComplexF64[] training = ComplexF64[] extrapolated = ComplexF64[] training_vecs = Vector{ComplexF64}[] +current_E = training_ref + for c in training_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) push!(training, current_E) push!(training_vecs, evecs[:, nearestIndex(evals, current_E)]) end -# CA-EC -training_vecs = vcat(training_vecs, conj(training_vecs)) - +training_vecs = vcat(training_vecs, conj(training_vecs)) # CA-EC EC_basis = hcat(training_vecs...) +weights_mat = spdiagm(repeat(kron(ws, ws), jmax + 1)) 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 +H0_EC = transpose(EC_basis) * weights_mat * H0 * EC_basis +Vp_EC = transpose(EC_basis) * weights_mat * Vp * 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) + local H = H0 + c .* Vp + local 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 + H_EC = H0_EC + c .* Vp_EC evals = eigvals(H_EC, N_EC) push!(extrapolated, nearest(evals, current_E)) end diff --git a/calculations/3body_Berggren_R2R_EC.jl b/calculations/3body_Berggren_R2R_EC.jl index 1b2c6bc..0b3c038 100644 --- a/calculations/3body_Berggren_R2R_EC.jl +++ b/calculations/3body_Berggren_R2R_EC.jl @@ -1,9 +1,4 @@ -using Arpack, SparseArrays, LRUCache -using DelimitedFiles, Plots -include("../ho_basis.jl") -include("../p_space.jl") - -println("No of threads = ", Threads.nthreads()) +using Plots training_c = [1.1, 0.9, 0.7, 0.5] extrapolating_c = 0.0 : 0.2 : 1.2 @@ -21,74 +16,24 @@ exact_ref = reverse([4.076662025307587-0.012709842443350328im, 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) +include("../p_space_3body_resonance.jl") +H0 = H -atol = 10^-5 -maxevals = 10^5 -R_cutoff = 16 +# Vp = perturbation to make the state artificially bound +Vp_of_r(r) = -exp(-(r/3)^2) +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 -μ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)...) +@time "Vp block diagonal part" begin + 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] + Vpb = blockdiag(sparse.(Vpb_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=R_cutoff) - 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=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) +@time "Vp2_HO" Vp2_HO = get_jacobi_V2_matrix(Vp_of_r, basis_ho, μω_global; atol=atol, maxevals=maxevals) +@time "Vp2" Vp2 = W_left * Vp2_HO * transpose(W_right) +@time "Vp" Vp = Vpb + Vp2 # 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() exact = ComplexF64[] @@ -100,8 +45,8 @@ 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) + 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) push!(training, current_E) @@ -109,22 +54,23 @@ for c in training_c end EC_basis = hcat(training_vecs...) +weights_mat = spdiagm(repeat(kron(ws, ws), jmax + 1)) 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 +H0_EC = transpose(EC_basis) * weights_mat * H0 * EC_basis +Vp_EC = transpose(EC_basis) * weights_mat * Vp * 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) + local H = H0 + c .* Vp + local 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 + H_EC = H0_EC + c .* Vp_EC evals = eigvals(H_EC, N_EC) push!(extrapolated, nearest(evals, current_E)) end diff --git a/p_space_3body_resonance.jl b/p_space_3body_resonance.jl index 81264d9..b595855 100644 --- a/p_space_3body_resonance.jl +++ b/p_space_3body_resonance.jl @@ -36,14 +36,14 @@ println("Basis size = $basis_size") Hb = blockdiag(sparse.(Hb_blocks)...) end -E_max = 30 +E_max = 40 μω_global = 0.5 μ1ω1 = μω_global * 1/2 μ2ω2 = μω_global * 2 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_left" W_left = get_W_matrix(basis, basis_ho, μ1ω1, μ2ω2; weights=false)