Skip to content

Commit

Permalink
added extra methods to allow for in-place ifft without modification
Browse files Browse the repository at this point in the history
  • Loading branch information
tb6g16 committed Dec 17, 2021
1 parent 2dbfdf3 commit 0741e73
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
19 changes: 19 additions & 0 deletions src/fft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ function (f::IFFTPlan!{Ny, Nz, Nt})(u::VectorField{N, P}, û::VectorField{N, S}
for i in 1:N
f(u[i], û[i])
end
end

function (f::IFFTPlan!{Ny, Nz, Nt})(u::PhysicalField{Ny, Nz, Nt},
::SpectralField{Ny, Nz, Nt},
û_tmp::SpectralField{Ny, Nz, Nt}) where {Ny, Nz, Nt}
# copy spectral contents to temporary field
û_tmp .=

# perform transform
FFTW.unsafe_execute!(f.plan, parent(û_tmp), parent(u))

return u
end

function (f::IFFTPlan!{Ny, Nz, Nt})(u::VectorField{N, P}, û::VectorField{N, S}, û_tmp::VectorField{N, S}) where
{Ny, Nz, Nt, N, P<:PhysicalField{Ny, Nz, Nt}, S<:SpectralField{Ny, Nz, Nt}}
for i in 1:N
f(u[i], û[i], û_tmp[i])
end

return u
end
11 changes: 6 additions & 5 deletions test/test_fft.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@testset "FFT Transforms " begin
# randon signal
Ny = rand(3:50)
Nz = rand(3:50)
Nt = rand(3:50)
# Ny = rand(3:50)
# Nz = rand(3:50)
# Nt = rand(3:50)
Ny = 8; Nz = 8; Nt = 8
ω = abs(randn())
β = abs(randn())
grid = Grid(rand(Float64, Ny), Nz, Nt,
Expand All @@ -26,9 +27,9 @@

# is the transform invertible correctly
FFT(Â1, A1)
IFFT(B1, Â1)
IFFT(B1, Â1, copy(Â1))
FFT(𝐀̂, 𝐀)
IFFT(𝐁, 𝐀̂)
IFFT(𝐁, 𝐀̂, VectorField(grid; N = 2))
@test A1 B1
@test 𝐀 𝐁
end

0 comments on commit 0741e73

Please sign in to comment.