Skip to content

Commit

Permalink
Clarify internal nature of energy_grad_*
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarros committed Sep 4, 2023
1 parent 309ef99 commit 5aea539
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/System/Interactions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,19 @@ function set_energy_grad_coherents!(HZ, Z, sys::System{N}) where N
@. dE_ds = dipoles = Vec3(0,0,0)
end

# Internal testing functions
function energy_grad_dipoles(sys::System{N}) where N
∇E = zero(sys.dipoles)
set_energy_grad_dipoles!(∇E, sys.dipoles, sys)
return ∇E
end
function energy_grad_coherents(sys::System{N}) where N
∇E = zero(sys.coherents)
set_energy_grad_coherents!(∇E, sys.coherents, sys)
return ∇E
end


# Returns (Λ + (dE/ds)⋅S) Z
@generated function mul_spin_matrices(Λ, dE_ds::Sunny.Vec3, Z::Sunny.CVec{N}) where N
S = spin_matrices(; N)
Expand Down Expand Up @@ -428,9 +441,3 @@ function homog_bond_iterator(latsize)
end
end
end

function energy_grad(sys::System{N}) where N
∇E = zero(sys.dipoles)
set_energy_grad_dipoles!(∇E, sys.dipoles, sys)
return ∇E
end
2 changes: 1 addition & 1 deletion test/test_ewald.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
# Calculate energy gradient using a sum over pairs, or using an FFT-based
# convolution
∇E = [Sunny.ewald_grad_at(sys, site) for site in eachsite(sys)]
@test isapprox(Sunny.energy_grad(sys), ∇E; atol=1e-12)
@test isapprox(Sunny.energy_grad_dipoles(sys), ∇E; atol=1e-12)

# Calculation of energy as a sum over pairs
E = sum((1/2)db for (d, b) in zip(sys.dipoles, ∇E))
Expand Down
2 changes: 1 addition & 1 deletion test/test_units_scaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
enable_dipole_dipole!(sys)
end
randomize_spins!(sys)
return energy(sys), Sunny.energy_grad(sys)
return energy(sys), Sunny.energy_grad_dipoles(sys)
end

# All exchange interactions should be invariant under changes to physical
Expand Down

0 comments on commit 5aea539

Please sign in to comment.