Skip to content

Commit 608786f

Browse files
authored
Merge pull request #174 from FourierFlows/glw/extend-plan-flows
Extends plan flows to take arbitrary args and kwargs but filter flags…
2 parents 21cd276 + f17430c commit 608786f

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

src/CuFourierFlows.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using .CuArrays
22

33
# Discard `effort` argument for CuArrays
4-
plan_flows_fft(a::CuArray, effort) = plan_fft(a)
5-
plan_flows_rfft(a::CuArray, effort) = plan_rfft(a)
4+
plan_flows_fft(a::CuArray, args...; flags=nothing, kwargs...) = plan_fft(a, args...; kwargs...)
5+
plan_flows_rfft(a::CuArray, args...; flags=nothing, kwargs...) = plan_rfft(a, args...; kwargs...)
66

77
OneDGrid(dev::GPU, args...; kwargs...) = OneDGrid(args...; ArrayType=CuArray, kwargs...)
88
TwoDGrid(dev::GPU, args...; kwargs...) = TwoDGrid(args...; ArrayType=CuArray, kwargs...)

src/domains.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
plan_flows_fft(a::Array, effort) = plan_fft(a; flags=effort)
2-
plan_flows_rfft(a::Array, effort) = plan_rfft(a; flags=effort)
1+
plan_flows_fft(a::Array, args...; kwargs...) = plan_fft(a, args...; kwargs...)
2+
plan_flows_rfft(a::Array, args...; kwargs...) = plan_rfft(a, args...; kwargs...)
33

44
"""
55
ZeroDGrid()
@@ -75,8 +75,8 @@ function OneDGrid(nx, Lx; x0=-Lx/2, nthreads=Sys.CPU_THREADS, effort=FFTW.MEASUR
7575
invkrsq[1] = 0
7676

7777
FFTW.set_num_threads(nthreads)
78-
fftplan = plan_flows_fft(ArrayType{Complex{T}, 1}(undef, nx), effort)
79-
rfftplan = plan_flows_rfft(ArrayType{T, 1}(undef, nx), effort)
78+
fftplan = plan_flows_fft(ArrayType{Complex{T}, 1}(undef, nx), flags=effort)
79+
rfftplan = plan_flows_rfft(ArrayType{T, 1}(undef, nx), flags=effort)
8080

8181
kalias, kralias = getaliasedwavenumbers(nk, nkr, dealias)
8282

@@ -155,8 +155,8 @@ function TwoDGrid(nx, Lx, ny=nx, Ly=Lx; x0=-Lx/2, y0=-Ly/2, nthreads=Sys.CPU_THR
155155

156156
# FFT plans
157157
FFTW.set_num_threads(nthreads)
158-
fftplan = plan_flows_fft(ArrayType{Complex{T}, 2}(undef, nx, ny), effort)
159-
rfftplan = plan_flows_rfft(ArrayType{T, 2}(undef, nx, ny), effort)
158+
fftplan = plan_flows_fft(ArrayType{Complex{T}, 2}(undef, nx, ny), flags=effort)
159+
rfftplan = plan_flows_rfft(ArrayType{T, 2}(undef, nx, ny), flags=effort)
160160

161161
# Index endpoints for aliasfrac i, j wavenumbers
162162
kalias, kralias = getaliasedwavenumbers(nk, nkr, dealias)
@@ -248,8 +248,8 @@ function ThreeDGrid(nx, Lx, ny=nx, Ly=Lx, nz=nx, Lz=Lx; x0=-Lx/2, y0=-Ly/2, z0=-
248248

249249
# FFT plans
250250
FFTW.set_num_threads(nthreads)
251-
fftplan = plan_flows_fft(ArrayType{Complex{T}, 3}(undef, nx, ny, nz), effort)
252-
rfftplan = plan_flows_rfft(ArrayType{T, 3}(undef, nx, ny, nz), effort)
251+
fftplan = plan_flows_fft(ArrayType{Complex{T}, 3}(undef, nx, ny, nz), flags=effort)
252+
rfftplan = plan_flows_rfft(ArrayType{T, 3}(undef, nx, ny, nz), flags=effort)
253253

254254
# Index endpoints for aliasfrac i, j wavenumbers
255255
kalias, kralias = getaliasedwavenumbers(nk, nkr, dealias)

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ for dev in devices
9595
@test testgridpoints(dev, g₃)
9696
@test testdealias(g₃)
9797
@test testmakefilter(dev, g₃)
98+
@test test_plan_flows_fftrfft(dev)
9899

99100
# Test typed grids
100101
T = Float32
102+
@test test_plan_flows_fftrfft(dev, T=T)
101103
@test testtypedonedgrid(dev, nx, Lx; T=T)
102104
@test testtypedtwodgrid(dev, nx, Lx, ny, Ly; T=T)
103105
@test testtypedthreedgrid(dev, nx, Lx, ny, Ly, nz, Lz; T=T)

test/test_grid.jl

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,35 @@ function testtypedthreedgrid(dev::Device, nx, Lx, ny=nx, Ly=Lx, nz=nx, Lz=Lx; T=
123123
typeof(gr.dx)==T && typeof(gr.dy)==T && typeof(gr.dz)==T && typeof(gr.x[1])==T && typeof(gr.y[1])==T && typeof(gr.z[1])==T && typeof(gr.Lx)==T && typeof(gr.Ly)==T && typeof(gr.Lz)==T && eltype(gr) == T
124124
end
125125

126-
function testmakefilter(dev::Device, g::AbstractGrid{T}) where T
126+
function testmakefilter(dev::Device, g::AbstractGrid)
127+
T = eltype(g)
127128
filter = FourierFlows.makefilter(g)
128129
G = typeof(g)
129130
nofilter = G<:OneDGrid ? filter[@. g.kr*g.dx/π < 0.65] : ( G<:TwoDGrid ? filter[@. sqrt((g.kr*g.dx/π)^2 + (g.l*g.dy/π)^2) < 0.65] : filter[@. sqrt((g.kr*g.dx/π)^2 + (g.l*g.dy/π)^2 + (g.m*g.dz/π)^2) < 0.65] )
130131
fullfilter = G<:OneDGrid ? filter[@. g.kr*g.dx/π > 0.999] : ( G<:TwoDGrid ? filter[@. sqrt((g.kr*g.dx/π)^2 + (g.l*g.dy/π)^2) > 0.999] : filter[@. sqrt((g.kr*g.dx/π)^2 + (g.l*g.dy/π)^2 + (g.m*g.dz/π)^2) > 0.999] )
131132
nofilter== zeros(dev, T, size(nofilter)) .+ 1 && isapprox(fullfilter, zeros(dev, T, size(fullfilter)), atol=1e-12)
132133
end
134+
135+
function test_plan_flows_fftrfft(::CPU; T=Float64)
136+
A = ArrayType(CPU())
137+
return ( typeof(FourierFlows.plan_flows_fft(A(rand(Complex{T}, (4,))))) == FFTW.cFFTWPlan{Complex{T},-1,false,1} &&
138+
typeof(FourierFlows.plan_flows_fft(A(rand(Complex{T}, (4, 6))))) == FFTW.cFFTWPlan{Complex{T},-1,false,2} &&
139+
typeof(FourierFlows.plan_flows_fft(A(rand(Complex{T}, (4, 6, 8))))) == FFTW.cFFTWPlan{Complex{T},-1,false,3} &&
140+
FourierFlows.plan_flows_fft(A(rand(Complex{T}, (4, 6, 8))), [1, 2]).region == [1, 2] &&
141+
typeof(FourierFlows.plan_flows_rfft(A(rand(T, (4,))))) == FFTW.rFFTWPlan{T,-1,false,1} &&
142+
typeof(FourierFlows.plan_flows_rfft(A(rand(T, (4, 6))))) == FFTW.rFFTWPlan{T,-1,false,2} &&
143+
typeof(FourierFlows.plan_flows_rfft(A(rand(T, (4, 6, 8))))) == FFTW.rFFTWPlan{T,-1,false,3} &&
144+
FourierFlows.plan_flows_rfft(A(rand(T, (4, 6, 8))), [1, 2]).region == [1, 2] )
145+
end
146+
147+
function test_plan_flows_fftrfft(::GPU; T=Float64)
148+
A = ArrayType(GPU())
149+
return ( typeof(FourierFlows.plan_flows_fft(A(rand(Complex{T}, (4,))))) == CuArrays.CUFFT.cCuFFTPlan{Complex{T},-1,false,1} &&
150+
typeof(FourierFlows.plan_flows_fft(A(rand(Complex{T}, (4, 6))))) == CuArrays.CUFFT.cCuFFTPlan{Complex{T},-1,false,2} &&
151+
typeof(FourierFlows.plan_flows_fft(A(rand(Complex{T}, (4, 6, 8))))) == CuArrays.CUFFT.cCuFFTPlan{Complex{T},-1,false,3} &&
152+
FourierFlows.plan_flows_fft(A(rand(Complex{T}, (4, 6, 8))), [1, 2]).region == [1, 2] &&
153+
typeof(FourierFlows.plan_flows_rfft(A(rand(T, (4,))))) == CuArrays.CUFFT.rCuFFTPlan{T,-1,false,1} &&
154+
typeof(FourierFlows.plan_flows_rfft(A(rand(T, (4, 6))))) == CuArrays.CUFFT.rCuFFTPlan{T,-1,false,2} &&
155+
typeof(FourierFlows.plan_flows_rfft(A(rand(T, (4, 6, 8))))) == CuArrays.CUFFT.rCuFFTPlan{T,-1,false,3} &&
156+
FourierFlows.plan_flows_rfft(A(rand(T, (4, 6, 8))), [1, 2]).region == [1, 2] )
157+
end

0 commit comments

Comments
 (0)