Skip to content

Commit

Permalink
Reduce LSWT regularization by factor 1/2
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarros committed Jan 11, 2025
1 parent f3affd6 commit 0f70257
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
3 changes: 3 additions & 0 deletions docs/src/versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
[`print_site`](@ref) accepts an optional reference atom `i_ref`, with default
of `i`. The optional reference bond `b_ref` of [`print_bond`](@ref) now
defaults to `b`.
* The `regularization` parameter in [`SpinWaveTheory`](@ref) is reduced by half,
and now corresponds to an effective energy shift. This may affect intensities,
especially at small excitation energies.

## v0.7.4
(Dec 6, 2024)
Expand Down
2 changes: 1 addition & 1 deletion src/EntangledUnits/EntangledSpinWaveTheory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,6 @@ function swt_hamiltonian_SUN!(H::Matrix{ComplexF64}, swt::EntangledSpinWaveTheor

# Add small constant shift for positive-definiteness
for i in 1:2L
H[i,i] += 2 * swt.regularization
H[i,i] += swt.regularization
end
end
4 changes: 2 additions & 2 deletions src/SpinWaveTheory/HamiltonianDipole.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function swt_hamiltonian_dipole!(H::Matrix{ComplexF64}, swt::SpinWaveTheory, q_r

# Add small constant shift for positive-definiteness
for i in 1:2L
H[i, i] += 2 * swt.regularization
H[i, i] += swt.regularization
end
end

Expand Down Expand Up @@ -279,7 +279,7 @@ function multiply_by_hamiltonian_dipole!(y::AbstractMatrix{ComplexF64}, x::Abstr
end

# Add small constant shift for positive-definiteness.
@inbounds @. Y += 2 * swt.regularization * X
@inbounds @. Y += swt.regularization * X

nothing
end
4 changes: 2 additions & 2 deletions src/SpinWaveTheory/HamiltonianSUN.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function swt_hamiltonian_SUN!(H::Matrix{ComplexF64}, swt::SpinWaveTheory, q_resh

# Add small constant shift for positive-definiteness
for i in 1:2L
H[i,i] += 2 * swt.regularization
H[i,i] += swt.regularization
end
end

Expand Down Expand Up @@ -209,7 +209,7 @@ function multiply_by_hamiltonian_SUN!(y::AbstractMatrix{ComplexF64}, x::Abstract
end

# Add small constant shift for positive-definiteness
@inbounds @. Y += 2 * swt.regularization * X
@inbounds @. Y += swt.regularization * X

nothing
end
2 changes: 1 addition & 1 deletion src/Spiral/SpinWaveTheorySpiral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function swt_hamiltonian_dipole_spiral!(H::Matrix{ComplexF64}, sswt::SpinWaveThe
hermitianpart!(H)

for i in 1:2L
H[i, i] += 2 * swt.regularization
H[i, i] += swt.regularization
end
end

Expand Down
24 changes: 12 additions & 12 deletions test/test_lswt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
swt = SpinWaveTheory(sys; measure=ssf_perp(sys; apply_g=false))

res = intensities_bands(swt, qs)
# println(round.(res.disp; digits=12))
# println(round.(res.data; digits=12))
disps_golden = [1394.440092589898 1393.728009961772 1393.008551261241 1392.919524984054 1279.23991907861 1279.094568482213 1278.22451852538 1277.691761492894 1194.366336265056 1193.750083635324 1191.583519669771 1189.794451350786 1131.422439597908 1131.202770084574 1065.242927860663 1065.095892456642 1026.649340932941 1024.028348568104 1022.830406309672 1020.767349649408 945.202397540707 944.795817861582 835.545028404179 832.001588705254 827.939501419137 827.307586957877 821.216582176438 820.430993577092 820.294548786087 818.594571008014 810.207001100209 808.553158283705 766.524411081004 766.516102760229 766.513825862473 766.508655568197 758.579854177684 754.683765895715 750.572578901226 750.471006262524 665.954573018229 662.421047663209 651.46556256004 651.417940134413 581.258189162714 568.105209810117 559.053702306466 558.493005833015 552.043762746846 550.131096080954 539.733572957862 530.698033203026 499.661483520139 494.928560833195 435.233706072008 427.70227707436 408.128705863823 399.856401759966 370.069343073402 369.845327696313 365.049514250289 363.639416679443 354.648012601512 346.609483937092 341.98916517756 339.373361078069 318.363717394716 276.219249213429 263.1610538422 257.409506256945 230.539454204132 229.778324183075 203.971681289205 197.504237163938 193.879371544746 189.866421885131 189.815806977935 167.944134441876 154.923566511974 146.21953885867]
data_golden = natoms * [9.6662565e-5 0.0 0.001807884262 0.0 0.002166250472 0.0 0.003835132693 0.0 0.0 0.013550066967 0.018327409336 0.0 0.001319003523 0.0 0.0 0.006677115951 0.0 0.015583193495 0.028006929969 0.0 0.007782414773 0.0 0.028892276057 0.0 0.0 0.009748743725 0.0 0.007788123595 0.007278285719 0.0 0.0 0.00116773942 0.000190731866 0.000235139044 0.0 0.0 0.002193317995 0.0 0.008315770402 0.0 0.016520647062 0.0 0.0 0.014989172648 0.08363192972 0.001902190356 0.0 0.0 0.0 0.017111545439 0.007341641476 0.0 0.0 0.151419922476 0.094666992635 0.0 0.214639628105 0.0 0.0 0.072514184691 0.087279329707 0.0 0.0 0.23891458934 0.0 0.401546184942 0.0 0.050427766439 0.04544662783 0.0 0.0 0.078427781361 0.192350495231 0.0 0.002594420277 0.0 0.037800182163 0.081921558936 0.0 0.0]
@test isapprox(res.disp, disps_golden'; atol=1e-9)
@test isapprox(res.data, data_golden'; atol=1e-9)
# println(round.(vec(res.disp); digits=12))
# println(round.(vec(res.data); digits=12))
disps_golden = [1394.440092579932, 1393.728009951748, 1393.008551251227, 1392.919524974106, 1279.239919068656, 1279.094568472208, 1278.224518515369, 1277.691761482934, 1194.366336255048, 1193.750083625344, 1191.583519659752, 1189.794451340786, 1131.422439587814, 1131.202770074483, 1065.242927850645, 1065.095892446623, 1026.649340922942, 1024.028348558074, 1022.830406299683, 1020.767349639389, 945.202397530637, 944.795817851532, 835.545028394177, 832.001588695239, 827.939501409159, 827.307586947865, 821.216582166477, 820.430993567146, 820.294548776124, 818.594570998049, 810.207001090183, 808.553158273676, 766.524411071072, 766.516102750272, 766.51382585253, 766.508655558251, 758.5798541677, 754.683765885704, 750.572578891224, 750.47100625256, 665.954573008178, 662.421047653195, 651.465562549975, 651.417940124351, 581.258189152584, 568.105209800095, 559.053702296455, 558.493005822971, 552.043762736843, 550.131096070956, 539.733572947825, 530.698033192909, 499.661483510074, 494.928560823138, 435.233706061892, 427.702277064325, 408.128705853663, 399.856401749648, 370.069343063308, 369.845327686246, 365.049514240266, 363.639416669427, 354.648012591404, 346.609483927002, 341.989165167266, 339.373361067994, 318.363717384335, 276.219249203178, 263.1610538318, 257.409506246766, 230.539454193854, 229.778324172693, 203.971681278992, 197.504237153931, 193.879371534726, 189.866421875022, 189.815806967694, 167.94413443161, 154.923566498384, 146.21953884777]
data_golden = [0.00038665026, 0.0, 0.007231537047, 0.0, 0.008665001888, 0.0, 0.015340530772, 0.0, 0.0, 0.054200267869, 0.073309637341, 0.0, 0.005276014091, 0.0, 0.0, 0.026708463804, 0.0, 0.062332773978, 0.112027719874, 0.0, 0.031129659091, 0.0, 0.115569104228, 0.0, 0.0, 0.038994974901, 0.0, 0.031152494381, 0.029113142876, 0.0, 0.0, 0.00467095768, 0.000762927464, 0.000940556177, 0.0, 0.0, 0.00877327198, 0.0, 0.033263081608, 0.0, 0.066082588247, 0.0, 0.0, 0.059956690592, 0.334527718881, 0.007608761425, 0.0, 0.0, 0.0, 0.068446181755, 0.029366565904, 0.0, 0.0, 0.605679689903, 0.378667970539, 0.0, 0.858558512424, 0.0, 0.0, 0.290056738762, 0.349117318827, 0.0, 0.0, 0.955658357376, 0.0, 1.606184739756, 0.0, 0.201711065754, 0.181786511323, 0.0, 0.0, 0.313711125445, 0.769401980923, 0.0, 0.010377681107, 0.0, 0.151200728665, 0.327686235743, 0.0, 0.0]
@test isapprox(res.disp, disps_golden; atol=1e-9)
@test isapprox(res.data, data_golden; atol=1e-9)

# Test first 5 output matrices
formfactors = [1 => FormFactor("Fe2")]
Expand Down Expand Up @@ -329,8 +329,8 @@ end
disp1 = dispersion(swt1, [q])
disp2 = dispersion(swt2, [q])

@test disp1 [1.3236778213351734, 0.9206655419611791]
@test disp2 [0.9206655419611772]
@test disp1 [1.3236778041378718, 0.9206655245623444]
@test disp2 [0.9206655245623366]
end
end

Expand Down Expand Up @@ -609,12 +609,12 @@ end
swt = SpinWaveTheory(sys; measure)

qs = [[0,0,0], [0.5,0,0], [1,0,0]]
energies = 0:0.1:5
energies = 0:0.5:5
kernel = lorentzian(fwhm=0.3)
res = intensities(swt, qs; energies, kernel)
data_ref = [0.042551643530614226 0.05061618774203612 0.06118972834822155 0.07541981401191966 0.09518339306332815 0.12371078181463013 0.1669136576105103 0.23644634156679015 0.3574143016120729 0.589319004913063 1.0795750388213625 2.0570916947398903 2.6569442073245604 1.6749367428248116 0.8709898932656854 0.4927038808971025 0.30849624153704924 0.20903618563778026 0.1502266820186879 0.11286975075833217 0.08777050885259896 0.07013929292833648 0.057300827672198455 0.047672208009393216 0.04027090049655778 0.0344619791000266 0.02982086993597283 0.02605519995256082 0.022958441606058772 0.020381422739929135 0.01821426297223774 0.016374601990583864 0.014799738769001156 0.013441266708211906 0.01226133976759786 0.01123002734145714 0.010323410070056573 0.009522188815697288 0.008810654796662341 0.008175917662895354 0.007607320304517221 0.007095990541228231 0.006634494316422953 0.006216564975067639 0.005836890143659928 0.00549094262866035 0.005174845247781923 0.0048852620341421574 0.004619310095626147 0.004374487768740016 0.00414861571474443; 0.14853118271457438 0.19360218524421224 0.2621797495216911 0.3732135013522173 0.5678610986270936 0.944407657666259 1.7450675448755357 3.2945578443571577 3.9947874291087895 2.418790606759786 1.2612861617795654 0.7201697967624341 0.45442367736983386 0.30970051154679945 0.22353509755861065 0.1685055354270234 0.1313752454162916 0.10520387618639207 0.0860938574888819 0.0717287252840356 0.060665219355115055 0.05196772774655005 0.045008912709399315 0.03935576182418519 0.03470177881993486 0.030825189142763776 0.027562374631854493 0.024790523018178495 0.02241601889071837 0.020366506674885078 0.018585357752204528 0.017027745220739847 0.015657814448345492 0.014446613655329999 0.013370560099471452 0.01241028925551664 0.011549781566933818 0.010775692876605122 0.010076836041215703 0.009443775967574439 0.008868510590520351 0.008344217576743833 0.007865051732026552 0.007425981842385972 0.007022658419610481 0.006651305841367626 0.006308633878300496 0.005991764727412878 0.005698172523177506 0.0054256329470820505 0.005172181054614204; 0.042551643530614205 0.0506161877420361 0.06118972834822153 0.07541981401191963 0.0951833930633281 0.12371078181463005 0.16691365761051016 0.23644634156678992 0.3574143016120724 0.5893190049130621 1.0795750388213603 2.0570916947398867 2.656944207324563 1.6749367428248163 0.8709898932656877 0.4927038808971036 0.30849624153704985 0.20903618563778062 0.15022668201868813 0.1128697507583323 0.08777050885259907 0.07013929292833657 0.05730082767219852 0.04767220800939327 0.04027090049655782 0.03446197910002663 0.02982086993597286 0.026055199952560844 0.02295844160605879 0.020381422739929156 0.018214262972237757 0.016374601990583878 0.014799738769001168 0.013441266708211913 0.01226133976759787 0.011230027341457147 0.010323410070056582 0.009522188815697295 0.008810654796662348 0.00817591766289536 0.007607320304517226 0.007095990541228234 0.006634494316422957 0.006216564975067644 0.005836890143659932 0.005490942628660353 0.005174845247781927 0.00488526203414216 0.00461931009562615 0.0043744877687400185 0.0041486157147444325]

@test res.data data_ref'
# println(round.(res.data; digits=10))
data_ref = [0.0425516442 0.148531187 0.0425516442; 0.1237107851 0.9444077155 0.1237107851; 1.0795751088 1.2612860859 1.0795751088; 0.4927038544 0.1685055314 0.4927038544; 0.0877705066 0.0606652185 0.0877705066; 0.0344619785 0.0308251889 0.0344619785; 0.0182142627 0.0185853576 0.0182142627; 0.0112300272 0.0124102892 0.0112300272; 0.0076073202 0.0088685106 0.0076073202; 0.0054909426 0.0066513058 0.0054909426; 0.0041486157 0.005172181 0.0041486157]
@test res.data data_ref
end


Expand Down

0 comments on commit 0f70257

Please sign in to comment.