Skip to content

Commit

Permalink
Stricter Mat3 -> Float64 criterion
Browse files Browse the repository at this point in the history
Only convert an exchange matrix J to a Float64 if it is _exactly_
diagonal.
  • Loading branch information
kbarros committed Jul 21, 2023
1 parent 573b6c2 commit 7ed0226
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/System/PairExchange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ function bond_parity(bond)
return bond_delta > (0, 0, 0, 0)
end

# Convert J to Union{Float64, Mat3}
# Convert J to Union{Float64, Mat3}. If J is _exactly_ the identity matrix, we
# can compactly represent it using a single float. If J is near (but not
# exactly) the identity matrix, retain the full matrix representation. This
# could hypothetically be important to preserve symmetry breaking effects. For
# example, a user might select J=diagm([a,a,a+ϵ]) for infinitesimal ϵ to favor
# the z direction.
function to_float_or_mat3(J)
if J isa Number || isapprox(J, J[1] * I, atol=1e-12)
if J isa Number || J == J[1] * I
J = Float64(first(J))
else
J = Mat3(J)
Expand Down

0 comments on commit 7ed0226

Please sign in to comment.