Skip to content

Commit

Permalink
fix 3d hypot_fast
Browse files Browse the repository at this point in the history
  • Loading branch information
AshtonSBradley committed Oct 10, 2023
1 parent 21cda24 commit 6ec67f2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/QuantumFluidSpectra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ using PaddedViews
using UnPack
using TensorCast

# fallback since fast_hypot is 2 argument only
@fastmath hypot(x::Float64, y::Float64, z::Float64)=sqrt(x^2+y^2+z^2)
export hypot

abstract type Field end
struct Psi{D} <: Field
ψ::Array{Complex{Float64},D}
Expand Down
50 changes: 49 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using QuantumFluidSpectra
using Test

@testset "Analysis" begin
@testset "2D Analysis" begin
# Velocity and Helmholtz tests
n = 100
L = (1,1)
Expand Down Expand Up @@ -46,3 +46,51 @@ using Test
@test AC == AC

end

@testset "3D Analysis" begin
# Velocity and Helmholtz tests
n = 20
L = (1,1,1)
N = (n,n,n)
X,K,dX,dK = xk_arrays(L,N)
kx,ky,kz = K

##
ktest = K[1][2]
ψ = exp.(im*ktest*X[1].*one.(X[2]').*one.(reshape(X[3],(1,1,n))))
psi = Psi(ψ,X,K)

## flow only in x direction, of correct value
vx,vy,vz = velocity(psi)
@test vx ktest*one.(vx)
@test vy zero.(vy)
@test vz zero.(vz)

## helmholtz decomposition
Vi,Vc = helmholtz(vx,vy,vz,kx,ky,kz)

## Orthogonality
vidotvc = Vi[1].*Vc[1] .+ Vi[2].*Vc[2] .+ Vi[3].*Vc[3]
@test maximum(abs.(vidotvc)) < 1e-10

## Projective
@test Vi[1] .+ Vc[1] vx
@test Vi[2] .+ Vc[2] vy
@test Vi[3] .+ Vc[3] vz

## autocorrelation
x,y,z = X; kx,ky,kz = K
dx = x[2]-x[1];dk = kx[2]-kx[1] # (isotropic grid)

Natoms = sum(abs2.(ψ))*dx^3
AC = auto_correlate(ψ,X,K)
Nr,Nim = AC[21,21,21] .|> (real,imag)

@test Natoms Nr
@test Nim 0.0

## cross correlated reduces to autocorrelate correctly
CC = cross_correlate(ψ,ψ,X,K)
@test AC == AC
incompressible_spectrum(kx,psi) # not really a test, but at least it errors
end

0 comments on commit 6ec67f2

Please sign in to comment.