diff --git a/docs/src/versions.md b/docs/src/versions.md index 54b18f5ef..fa4cdf001 100644 --- a/docs/src/versions.md +++ b/docs/src/versions.md @@ -1,5 +1,11 @@ # Version History +## v0.7.2 +(In development) + +* Fix error in `SampledCorrelations` with a coarse ``𝐪``-grid. ([PR + #314](https://github.com/SunnySuite/Sunny.jl/pull/314)) + ## v0.7.1 (Sep 3, 2024) diff --git a/src/SampledCorrelations/DataRetrieval.jl b/src/SampledCorrelations/DataRetrieval.jl index 89f32ee6d..a5b5c01ff 100644 --- a/src/SampledCorrelations/DataRetrieval.jl +++ b/src/SampledCorrelations/DataRetrieval.jl @@ -14,8 +14,10 @@ function pruned_wave_vector_info(sc::SampledCorrelations, qs) # Convert to absolute units (for form factors) qabs_rounded = map(m -> sc.crystal.recipvecs * (m ./ sc.sys_dims), ms) - # List of "starting" pointers i where idcs[i-1] != idcs[i] - starts = findall(i -> i == 1 || idcs[i-1] != idcs[i], eachindex(idcs)) + # List of "starting" pointers i where qabs_rounded[i-1] != qabs_rounded[i], + # i.e., indices where the desired wave vector is distinct from the previous + # one. + starts = findall(i -> i == 1 || !isapprox(qabs_rounded[i-1], qabs_rounded[i]), eachindex(qabs_rounded)) # Length of each run of repeated values counts = starts[2:end] - starts[1:end-1] diff --git a/test/test_correlation_sampling.jl b/test/test_correlation_sampling.jl index a2e24480d..ab6b54506 100644 --- a/test/test_correlation_sampling.jl +++ b/test/test_correlation_sampling.jl @@ -93,6 +93,13 @@ true_static_vals = intensities_static(res, qgrid) true_static_total = sum(true_static_vals.data) @test isapprox(true_static_total / prod(sys.dims), 1.0; atol=1e-12) + + # Test whether two distinct wave vectors referencing the same underlying + # data point in sc.data are in fact treated differently. + formfactors = [1 => FormFactor("Fe2")] + sc.measure = ssf_trace(sys; apply_g=false, formfactors) + res = intensities_static(sc, [[0, 0, 1/2], [1, 0, 1/2]]; kT=nothing) + @test res.data[1] != res.data[2] end @testitem "Merge correlations" begin