Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration performance optimization: de-broadcast dipole integration #258

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 15 additions & 7 deletions src/Integrators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,12 @@ end
(; dt, damping) = integrator
λ = damping

if iszero(λ)
@. Δs = -s × (- dt*∇E)
else
@. Δs = -s × (- dt*∇E + ξ - dt*λ*(s × ∇E))
for i = eachindex(Δs)
if iszero(λ)
Δs[i] = -s[i] × (- dt*∇E[i])
else
Δs[i] = -s[i] × (- dt*∇E[i] + ξ[i] - dt*λ*(s[i] × ∇E[i]))
end
end
end

Expand Down Expand Up @@ -383,18 +385,24 @@ function step!(sys::System{0}, integrator::ImplicitMidpoint; max_iters=100)

for _ in 1:max_iters
# Current guess for midpoint ŝ
@. ŝ = normalize_dipole((s + s′)/2, sys.κs)
for i = eachindex(ŝ )
ŝ[i] = normalize_dipole((s[i] + s′[i])/2, sys.κs[i])
end

set_energy_grad_dipoles!(∇E, ŝ, sys)
rhs_dipole!(Δs, ŝ, ξ, ∇E, integrator)

@. s″ = s + Δs
for i = eachindex(s″)
s″[i] = s[i] + Δs[i]
end

# If converged, then we can return
if fast_isapprox(s′, s″; atol)
# Normalization here should not be necessary in principle, but it
# could be useful in practice for finite `atol`.
@. s = normalize_dipole(s″, sys.κs)
for i = eachindex(s)
s[i] = normalize_dipole(s″[i], sys.κs[i])
end
return
end

Expand Down
Loading