Skip to content

Commit

Permalink
Add more tests for external field
Browse files Browse the repository at this point in the history
  • Loading branch information
ddahlbom committed Oct 10, 2024
1 parent e811fcb commit 34b604c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion test/test_entangled_units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ end
# ordering).

@testitem "Dimer Tests" begin
import LinearAlgebra: norm
J = 1.0
J′ = 0.1
latvecs = [
Expand Down Expand Up @@ -54,6 +55,25 @@ end
field_offset = 2*(Sl[3] + Su[3]) # 2 for g-factor
@test onsite_operator onsite_ref + field_offset

# Test external field works in action
set_field!(esys, [0, 0, 10])
randomize_spins!(esys)
minimize_energy!(esys)
esys.sys_origin.dipoles[1][3] -1/2
esys.sys_origin.dipoles[2][3] -1/2

set_field!(esys, [0, 0, -10])
randomize_spins!(esys)
minimize_energy!(esys)
esys.sys_origin.dipoles[1][3] 1/2
esys.sys_origin.dipoles[2][3] 1/2

set_field!(esys, [0, 0, 0])
randomize_spins!(esys)
minimize_energy!(esys; g_tol=1e-14)
norm(esys.sys_origin.dipoles[1]) < 1e-14
norm(esys.sys_origin.dipoles[2]) < 1e-14

# Test inter-bond exchange
pc = Sunny.as_general_pair_coupling(interactions.pair[1], esys.sys)
Sl1, Sl2 = to_product_space(Sl, Sl)
Expand Down Expand Up @@ -97,7 +117,7 @@ end
end
add_sample!(sc, esys)
res = intensities(sc, qpts; energies, kT=0.05)
intensities_ref = [-0.0021805338918195185 -0.00323580926131731 -0.003475460861305824 -0.003235809261317303 -0.0021805338918195185; 0.015394114132126614 0.05504458917464571 0.006363628894456872 0.024858210899731406 0.015394114132126614; -0.062439105112575104 -0.24430343196998291 -0.1124375404098702 -0.02581168756492061 -0.062439105112575104; 0.392194235986946 2.8241763179059833 4.85842932490045 0.4259092656302079 0.392194235986946; 9.761448823359627 18.38878057796522 15.41704091322518 2.3935803890294105 9.761448823359627; 19.84319371801515 22.70779362388382 11.689296089047344 2.883234285853617 19.84319371801515; 9.747007990151367 5.296141862559427 0.8103824155070479 0.6877505519539169 9.747007990151367; -0.42870193438878 -0.9643857517663812 -0.0903901605398698 -0.22212424683216814 -0.42870193438878; 0.14524976514187082 0.2766893084879453 0.20093635005032084 0.032539493064106036 0.14524976514187082; -0.11486352541237474 -0.2600088555205098 -0.0036428642723143265 -0.26000885552050884 -0.11486352541237474]
intensities_ref = [-0.0009151914880177183 -0.002340042772876626 -0.0037316702420023395 -0.002340042772876612 -0.0009151914880177183; 0.02116154679963919 0.05967703767242055 0.009161242329689078 0.03233210977077469 0.02116154679963919; -0.04206086791537969 -0.2227189243447692 -0.12040711429107293 -0.025389877189384635 -0.04206086791537969; 0.3962131659090294 2.7150236439903197 4.3968225602687 0.5625477581811109 0.3962131659090294; 8.48497330044607 17.689468342820923 14.169270995083266 3.1979660472637534 8.48497330044607; 17.1145045637742 21.877166922282075 10.751399167760733 3.8125499846147113 17.1145045637742; 8.490961712258231 5.100854031990811 0.6862255516496436 0.8503635473494539 8.490961712258231; -0.3334143274663385 -0.966097718147396 -0.1252420669485946 -0.2868227954981837 -0.3334143274663385; 0.07518063142323421 0.2337350060517672 0.13638239262286792 0.012717547170902647 0.07518063142323421; -0.09925761646769077 -0.29077390054022495 -0.03237049466881591 -0.290773900540224 -0.09925761646769077]
@test isapprox(res.data, intensities_ref)
end

Expand Down

0 comments on commit 34b604c

Please sign in to comment.