Skip to content

Commit

Permalink
Some fixes for GPU (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjarvinen committed May 4, 2023
1 parent 978d55f commit b6acf0f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "HKQM"
uuid = "95871d0a-b0d4-4f82-9ec8-411977f2e218"
authors = ["Teemu Järvinen <teemu.jarvinen@helsinki.fi> and contributors"]
version = "0.2.1"
version = "0.2.2-DEV"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
2 changes: 1 addition & 1 deletion src/HKQM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ include("integrations.jl")
include("accuracytests.jl")
include("scf.jl")
include("initial_states.jl")
include("submodules/ToroidalCurrent.jl")


function __init__()
@require TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2" begin
include("tensor_operations.jl")
include("submodules/ToroidalCurrent.jl")
@require CUDA="052768ef-5323-5732-b1bb-66c8b64840ba" include("tensor_operations_cuda.jl")
end
end
Expand Down
11 changes: 11 additions & 0 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,10 @@ struct HamiltonOperatorFreeParticle{T} <: AbstractHamiltonOperator
@assert dimension(m) == dimension(u"kg")
new{typeof(m)}(ceg, LaplaceOperator(ceg), m)
end
function HamiltonOperatorFreeParticle(T, ceg::AbstractElementGrid;m=1u"me_au")
@assert dimension(m) == dimension(u"kg")
new{typeof(m)}(ceg, LaplaceOperator(T, ceg), m)
end
end

Unitful.unit(H::HamiltonOperatorFreeParticle) =u"hartree*bohr^2"*unit(H.∇²)
Expand Down Expand Up @@ -778,6 +782,13 @@ struct HamiltonOperator{TF,TV} <: AbstractHamiltonOperator
T = HamiltonOperatorFreeParticle(get_elementgrid(V); m=m)
new{typeof(T.m),typeof(V)}(get_elementgrid(V), T, V)
end
function HamiltonOperator(Tt, V::AbstractOperator{1}; m=1u"me_au")
@assert dimension(V) == dimension(u"J")
@assert dimension(m) == dimension(u"kg")
T = HamiltonOperatorFreeParticle(Tt, get_elementgrid(V); m=m)
vv = convert_array_type(Tt, V)
new{typeof(T.m),typeof(vv)}(get_elementgrid(V), T, vv)
end
end

Unitful.unit(H::HamiltonOperator) = unit(H.T)
Expand Down
3 changes: 2 additions & 1 deletion src/states.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ julia> ψ⋆ψ;
"""
function ketbra(qs1::QuantumState{<:Any,<:Any}, qs2::QuantumState{<:Any,<:Any})
@assert size(qs1) == size(qs2)
conj(qs1).psi .* qs2.psi
_f(x,y) = conj(x) * y
_f.(qs1.psi, qs2.psi)
end

const = ketbra
Expand Down
5 changes: 0 additions & 5 deletions src/submodules/ToroidalCurrent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ using DelimitedFiles
using Distributed
using Distances
using Interpolations
using TensorOperations

using ..HKQM

Expand Down Expand Up @@ -192,10 +191,6 @@ function greens_function_2d(ceg; eps=1E-6u"Å")
return reshape(out, i,j, i,j, i,j, i,j)
end

function solve_2d_poisson(G, psi)
@tensoropt tmp[x,y,z,X,Y,Z] := G[x,X,y,Y,i,I,j,J] * psi.psi[i,j,z,I,J,Z]
return QuantumState(get_elementgrid(psi), tmp, unit(psi)*u"bohr^2")
end

function solve_2d_poisson(psi)
return solve_2d_poisson( greens_function_2d( get_elementgrid(psi) ) , psi)
Expand Down
7 changes: 7 additions & 0 deletions src/tensor_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ end
function operate_z!(dψ::AbstractArray{<:Any,6}, dt::DerivativeTensor, ψ::Array{<:Any,6})
@tensor dψ[i,j,k,I,J,K] = dt.values[k,l] * ψ[i,j,l,I,J,K]
return
end

##

function ToroidalCurrent.solve_2d_poisson(G, psi)
@tensoropt tmp[x,y,z,X,Y,Z] := G[x,X,y,Y,i,I,j,J] * psi.psi[i,j,z,I,J,Z]
return QuantumState(get_elementgrid(psi), tmp, unit(psi)*u"bohr^2")
end

0 comments on commit b6acf0f

Please sign in to comment.