Simplify Hamiltonian struct
This commit is contained in:
parent
f002b36820
commit
247d564071
|
|
@ -10,26 +10,27 @@ struct Hamiltonian{T}
|
||||||
N::Int
|
N::Int
|
||||||
L::T
|
L::T
|
||||||
μ::T
|
μ::T
|
||||||
∂1 # Matrix{Complex{T}} or Nothing
|
K_partial::Matrix{Complex{T}}
|
||||||
K_diag # CuTensor{Complex{T}} or Nothing
|
K_diag::Union{CuTensor{Complex{T}},Nothing}
|
||||||
K_mixed # CuTensor{Complex{T}} or Nothing
|
K_mixed::Union{CuTensor{Complex{T}},Nothing}
|
||||||
Vs # Array{Complex{T}} or CuArray{Complex{T}}
|
Vs::Union{Array{Complex{T}},CuArray{Complex{T}}}
|
||||||
hermitian::Bool
|
hermitian::Bool
|
||||||
mode::Hamiltonian_backend
|
mode::Hamiltonian_backend
|
||||||
|
|
||||||
function Hamiltonian{T}(V_twobody::Function, d::Int, n::Int, N::Int, L::T, ϕ::T, μ::T, n_image::Int, mode::Hamiltonian_backend) where {T<:Float}
|
function Hamiltonian{T}(V_twobody::Function, d::Int, n::Int, N::Int, L::T, ϕ::T, μ::T, n_image::Int, mode::Hamiltonian_backend) where {T<:Float}
|
||||||
@assert mode != gpu_cutensor || CUDA.functional() && CUDA.has_cuda() && CUDA.has_cuda_gpu() "CUDA not available"
|
@assert mode != gpu_cutensor || CUDA.functional() && CUDA.has_cuda() && CUDA.has_cuda_gpu() "CUDA not available"
|
||||||
k = -N÷2:N÷2-1
|
k = -N÷2:N÷2-1
|
||||||
Vs = calculate_Vs(V_twobody, d, n, N, L, ϕ, n_image)
|
Vs = calculate_Vs(V_twobody, d, n, N, L, ϕ, n_image)
|
||||||
hermitian = ϕ == 0.0
|
hermitian = ϕ == 0.0
|
||||||
if mode == cpu_tensor
|
K_partial = (exp(-im * ϕ) * im / sqrt(2 * μ)) .* ∂_1DOF.(L, N, k, k')
|
||||||
∂1 = exp(-im * ϕ) .* ∂_1DOF.(L, N, k, k')
|
K_diag = nothing
|
||||||
return new{T}(d, n, N, L, μ, ∂1, nothing, nothing, Vs, hermitian, mode)
|
K_mixed = nothing
|
||||||
elseif mode == gpu_cutensor
|
if mode == gpu_cutensor
|
||||||
K_partial = (exp(-im * ϕ) * im / sqrt(2 * μ)) .* ∂_1DOF.(L, N, k, k')
|
|
||||||
K_diag = CuTensor(CuArray(K_partial * K_partial), ['a', 'A'])
|
K_diag = CuTensor(CuArray(K_partial * K_partial), ['a', 'A'])
|
||||||
K_mixed = CuTensor(CuArray(K_partial), ['a', 'A']) * CuTensor(CuArray(K_partial), ['b', 'B'])
|
K_mixed = CuTensor(CuArray(K_partial), ['a', 'A']) * CuTensor(CuArray(K_partial), ['b', 'B'])
|
||||||
return new{T}(d, n, N, L, μ, nothing, K_diag, K_mixed, CuArray(Vs), hermitian, mode)
|
Vs = CuArray(Vs)
|
||||||
end
|
end
|
||||||
|
return new{T}(d, n, N, L, μ, K_partial, K_diag, K_mixed, Vs, hermitian, mode)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -45,7 +46,6 @@ function LinearAlgebra.mul!(out::Array{Complex{T}}, H::Hamiltonian{T}, v::Array{
|
||||||
# apply V operator
|
# apply V operator
|
||||||
@. out = H.Vs * v
|
@. out = H.Vs * v
|
||||||
# apply K opereator
|
# apply K opereator
|
||||||
coeff = -1 / (2 * H.μ)
|
|
||||||
coords = H.n - 1
|
coords = H.n - 1
|
||||||
nconList_v_template = -collect(1:H.d*(coords))
|
nconList_v_template = -collect(1:H.d*(coords))
|
||||||
for dim = 1:H.d
|
for dim = 1:H.d
|
||||||
|
|
@ -62,8 +62,8 @@ function LinearAlgebra.mul!(out::Array{Complex{T}}, H::Hamiltonian{T}, v::Array{
|
||||||
nconList_v[i1] = 1
|
nconList_v[i1] = 1
|
||||||
end
|
end
|
||||||
nconList_v[i2] = 2
|
nconList_v[i2] = 2
|
||||||
v_new = @ncon((H.∂1, H.∂1, v), (nconList_1, nconList_2, nconList_v))
|
v_new = @ncon((H.K_partial, H.K_partial, v), (nconList_1, nconList_2, nconList_v))
|
||||||
out = axpy!(coeff, v_new, out)
|
out = axpy!(1, v_new, out)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue