Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions docs/src/DB.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ entry.energy

Add a benchmark using `TwoBody.put!`:

```@repl db-usage
hamiltonian = Hamiltonian(
Kinetic(ℏ = 1.0, m = 1.0),
Coulomb(coefficient = -1.0),
)
TwoBody.put!(:example, hamiltonian, -0.5)
```julia-repl
julia> hamiltonian = Hamiltonian(
Kinetic(hbar = 1.0, m = 1.0),
Coulomb(coefficient = -1.0),
)

julia> TwoBody.put!(:example, hamiltonian, -0.5)
```

Duplicate keys are rejected, and Hamiltonians are copied on registration and
Expand Down
2 changes: 1 addition & 1 deletion docs/src/FDM.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Define the [Hamiltoninan](@ref Hamiltonian). This is an example for the non-rela
```
```@example example
H = Hamiltonian(
Kinetic( = 1, m = 1),
Kinetic(hbar = 1, m = 1),
Coulomb(coefficient = -1),
)
nothing # hide
Expand Down
2 changes: 1 addition & 1 deletion docs/src/Rayleigh-Ritz.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Define the [Hamiltoninan](@ref Hamiltonian). This is an example for the non-rela

```@example example
H = Hamiltonian(
Kinetic( = 1, m = 1),
Kinetic(hbar = 1, m = 1),
Coulomb(coefficient = -1),
)
nothing # hide
Expand Down
2 changes: 1 addition & 1 deletion docs/src/VMC.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ using TwoBody

# Hamiltonian
H = Hamiltonian(
Kinetic(=1, m=1),
Kinetic(hbar=1, m=1),
Coulomb(coefficient=-1),
)

Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Define the [Hamiltoninan](@ref Hamiltonian). This is an example for the non-rela
```
```@example index
H = Hamiltonian(
Kinetic( = 1, m = 1),
Kinetic(hbar = 1, m = 1),
Coulomb(coefficient = -1),
)
nothing # hide
Expand Down
6 changes: 3 additions & 3 deletions src/DB.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ put!(key::AbstractString, hamiltonian::Hamiltonian, energy::Real) =
put!(
:hydrogen,
Hamiltonian(
Kinetic( = 1.0, m = 1.0),
Kinetic(hbar = 1.0, m = 1.0),
Coulomb(coefficient = -1.0),
),
-0.5,
Expand All @@ -47,7 +47,7 @@ put!(
put!(
:positronium,
Hamiltonian(
Kinetic( = 1.0, m = 0.5),
Kinetic(hbar = 1.0, m = 0.5),
Coulomb(coefficient = -1.0),
),
-0.25,
Expand All @@ -56,7 +56,7 @@ put!(
put!(
:harmonic_oscillator,
Hamiltonian(
Kinetic( = 1.0, m = 1.0),
Kinetic(hbar = 1.0, m = 1.0),
PowerLaw(coefficient = 0.5, exponent = 2.0),
),
1.5,
Expand Down
2 changes: 1 addition & 1 deletion src/FDM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ end
function matrix(o::Kinetic, method::FiniteDifferenceMethod)
D = FiniteDifferenceMatrices.fdmatrix(Int64(length(method.R)), n=1, m=2, d=method.direction, h=method.Δr, t=typeof(method.Δr))
D² = FiniteDifferenceMatrices.fdmatrix(Int64(length(method.R)), n=2, m=2, d=method.direction, h=method.Δr, t=typeof(method.Δr))
return -o.^2/2/o.m * (D² + SparseArrays.spdiagm(2 ./ method.R) * D - method.l*(method.l+1) * SparseArrays.spdiagm(1 ./ method.R .^ 2))
return -o.hbar^2/2/o.m * (D² + SparseArrays.spdiagm(2 ./ method.R) * D - method.l*(method.l+1) * SparseArrays.spdiagm(1 ./ method.R .^ 2))
end

function matrix(o::PotentialTerm, method::FiniteDifferenceMethod)
Expand Down
6 changes: 3 additions & 3 deletions src/Hamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Base.@kwdef struct Laplacian <: KineticTerm
end

Base.@kwdef struct Kinetic <: KineticTerm
= 1
hbar = 1
m = 1
end

Expand Down Expand Up @@ -135,7 +135,7 @@ The Hamiltonian is the input for each solver. This is an example for the non-rel

```@example
H = Hamiltonian(
Kinetic( = 1, m = 1),
Kinetic(hbar = 1, m = 1),
Coulomb(coefficient = -1),
)
```
Expand All @@ -152,7 +152,7 @@ H = Hamiltonian(
""" Laplacian

@doc raw"""
`Kinetic(=1, m=1)`
`Kinetic(hbar=1, m=1)`
```math
-\frac{\hbar^2}{2m} \nabla^2
```
Expand Down
2 changes: 1 addition & 1 deletion src/Rayleigh-Ritz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ function element(o::Laplacian, SGB1::SimpleGaussianBasis, SGB2::SimpleGaussianBa
end

function element(o::Kinetic, SGB1::SimpleGaussianBasis, SGB2::SimpleGaussianBasis)
return o.^2/(2*o.m) * 6*π^(3/2)*SGB1.a*SGB2.a/(SGB1.a+SGB2.a)^(5/2)
return o.hbar^2/(2*o.m) * 6*π^(3/2)*SGB1.a*SGB2.a/(SGB1.a+SGB2.a)^(5/2)
end

function element(o::Constant, SGB1::SimpleGaussianBasis, SGB2::SimpleGaussianBasis)
Expand Down
2 changes: 1 addition & 1 deletion src/VMC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function _local_energy(term::Laplacian, wavefunction::Function, position, ψ)
end

function _local_energy(term::Kinetic, wavefunction::Function, position, ψ)
return -term.^2 / (2 * term.m) * _laplacian(wavefunction, position) / ψ
return -term.hbar^2 / (2 * term.m) * _laplacian(wavefunction, position) / ψ
end

_local_energy(term::RestEnergy, wavefunction::Function, position, ψ) = term.m * term.c^2
Expand Down
2 changes: 1 addition & 1 deletion test/DB.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

key = :temporary_test_problem
hamiltonian = Hamiltonian(
Kinetic( = 1.0, m = 1.0),
Kinetic(hbar = 1.0, m = 1.0),
Coulomb(coefficient = -2.0),
)

Expand Down
2 changes: 1 addition & 1 deletion test/FDM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Testing Results

H = Hamiltonian(
Kinetic( = 1, m = 1),
Kinetic(hbar = 1, m = 1),
Coulomb(coefficient = -1),
)
FDM = FiniteDifferenceMethod(
Expand Down
6 changes: 3 additions & 3 deletions test/Rayleigh-Ritz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Testing Results

H = Hamiltonian(
Kinetic( = 1, m = 1),
Kinetic(hbar = 1, m = 1),
Coulomb(coefficient = -1),
)
BS = BasisSet(
Expand Down Expand Up @@ -75,7 +75,7 @@
@testset "element()" begin

# kinetic terms
o = Kinetic(=1, m=1)
o = Kinetic(hbar=1, m=1)
println(o)
println(" i j\tnumerical \tanalytical")
l = 0
Expand All @@ -85,7 +85,7 @@
φⱼ(r) = TwoBody.φ(BS.basis[j], r)
dφⱼ(r) = ForwardDiff.derivative(r -> φⱼ(r), r)
d²φⱼ(r) = ForwardDiff.derivative(r -> dφⱼ(r), r)
numerical = 4*π*QuadGK.quadgk(r -> r^2 * φᵢ(r) * (-o.^2/2/o.m * (d²φⱼ(r) + 2/r*dφⱼ(r) - l*(l+1)/r^2*φⱼ(r))), 0, Inf, maxevals=10^3)[1]
numerical = 4*π*QuadGK.quadgk(r -> r^2 * φᵢ(r) * (-o.hbar^2/2/o.m * (d²φⱼ(r) + 2/r*dφⱼ(r) - l*(l+1)/r^2*φⱼ(r))), 0, Inf, maxevals=10^3)[1]
analytical = TwoBody.element(o, BS.basis[i], BS.basis[j])
error = isinf(analytical) ? 0.0 : abs((numerical-analytical)/analytical)
acceptance = error < 1e-5
Expand Down
10 changes: 5 additions & 5 deletions test/VMC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@testset "local energy" begin
H = Hamiltonian(
Kinetic(=1, m=1),
Kinetic(hbar=1, m=1),
PowerLaw(coefficient=1 / 2, exponent=2),
)
ψ(r) = exp(-sum(abs2, r) / 2)
Expand All @@ -28,7 +28,7 @@

@testset "harmonic oscillator" begin
H = Hamiltonian(
Kinetic(=1, m=1),
Kinetic(hbar=1, m=1),
PowerLaw(coefficient=1 / 2, exponent=2),
)
ψ(r) = exp(-sum(abs2, r) / 2)
Expand All @@ -53,7 +53,7 @@
@test mean_radius_squared ≈ 1.5 atol=0.5

singular_H = Hamiltonian(
Kinetic(=1, m=1),
Kinetic(hbar=1, m=1),
Custom(f=r -> r < 1 ? Inf : r^2 / 2),
)
singular_result = solve(
Expand All @@ -70,7 +70,7 @@

@testset "multiple walkers" begin
H = Hamiltonian(
Kinetic(=1, m=1),
Kinetic(hbar=1, m=1),
PowerLaw(coefficient=1 / 2, exponent=2),
)
ψ(r) = exp(-sum(abs2, r) / 2)
Expand Down Expand Up @@ -103,7 +103,7 @@

@testset "Coulomb singularity" begin
H = Hamiltonian(
Kinetic(=1, m=1),
Kinetic(hbar=1, m=1),
Coulomb(coefficient=-1),
)
α = 0.2829
Expand Down
Loading