Skip to content

Instantly share code, notes, and snippets.

@greenbagels
Created April 15, 2022 03:27
Show Gist options
  • Save greenbagels/68f917a5b5c8b6f2c35599433e58eaa2 to your computer and use it in GitHub Desktop.
Save greenbagels/68f917a5b5c8b6f2c35599433e58eaa2 to your computer and use it in GitHub Desktop.
function calculate_sfs(cf::T) where {R <: Real, T <: Matrix{Measurement{R}}}
# cf is an nxn matrix of correlation function values indexed by site offset
# so first make a matrix with the same shape...
n = size(cf, 1)
sf = similar(cf)
coeff = 2. * pi / n
for iqx in 1:n, iqy in 1:n
qy = iqy * coeff
qx = iqx * coeff
sf[iqy, iqx] = calculate_single_sf(cf, qx, qy, n)
end
return sf
end
function calculate_single_sf(cf::T, qx::R, qy::R, n::N) where {R <: Real, N <: Integer, T <: Matrix{Measurement{R}}}
sf = measurement(0., 0.)
for ix in 1:n, iy in 1:n,
jx in 1:n, jy in 1:n
dx = ix - jx
dy = iy - jy
absdx = Int(abs(dx))
absdy = Int(abs(dy))
sf += cos(qx * dx + qy * dy) * cf[absdy + 1, absdx + 1]
end
return sf / n^2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment