Skip to content

Commit

Permalink
adds some comments and deletes test_timesteppers_dt.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
navidcy committed Mar 18, 2018
1 parent 339cfa0 commit 0bd356e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 82 deletions.
16 changes: 10 additions & 6 deletions test/test_fft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ function create_testfuncs(g::TwoDGrid)
f1h_th, f1hr_th, f2h_th, f2hr_th
end

# -----------------------------------------------------------------------------
# FFT's TEST FUNCTIONS

tolerance = 1e-12

function test_fft_cosmx(g::OneDGrid)
f1, f1h, f1hr, f1hr_mul, f1h_th, f1hr_th = create_testfuncs(g)
norm(f1h-f1h_th)/norm(f1h_th) < tolerance
Expand Down Expand Up @@ -140,14 +144,14 @@ function test_rfft_AmulB_sinmxny(g::TwoDGrid)
norm(f2hr_mul-f2hr_th)/norm(f2hr_th) < tolerance
end

# Test square grid
nx = 32 # number of points
Lx = 2π # domain width
# Test 1D grid
nx = 32 # number of points
Lx = 2π # Domain width
g1 = OneDGrid(nx, Lx)

# Test square grid
nx, ny = 32, 64 # number of points
Lx, Ly = 2π, 3π # domain width
# Test 2D rectangular grid
nx, ny = 32, 64 # number of points
Lx, Ly = 2π, 3π # Domain width
g2 = TwoDGrid(nx, Lx, ny, Ly)

@test test_fft_cosmx(g1)
Expand Down
4 changes: 2 additions & 2 deletions test/test_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ testL(g) = sum(g.L[:, 2:Int(g.ny/2)] .+ flipdim(g.L[:, Int(g.ny/2+2):end], 2)) =
testKr(g) = sum(g.K[1:g.nkr, :] .- g.Kr) == 0.0
testLr(g) = sum(g.L[1:g.nkr, :] .- g.Lr) == 0.0

# Test 1d grid
# Test 1D grid
g1 = OneDGrid(32, 2π)

@test testdx(g1)
@test testx(g1)
@test testk(g1)
@test testkr(g1)

# Test 2d anisotropic grid
# Test 2D rectangular grid
g2 = TwoDGrid(32, 2π, 24, 4π)

@test testdx(g2)
Expand Down
41 changes: 23 additions & 18 deletions test/test_ifft.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Requires the create_testfuncs function defined in test_fft.jl


# -----------------------------------------------------------------------------
# IFFT's TEST FUNCTIONS

tolerance = 1e-12

function test_ifft_cosmx(g::OneDGrid)
# test fft for cos(mx+φ)
f1, f1h, f1hr, f1hr_mul, f1h_th, f1hr_th = create_testfuncs(g)
f1b = real(ifft(f1h))
norm(f1-f1b)/norm(f1) < 1e-12
norm(f1-f1b)/norm(f1) < tolerance
end

function test_irfft_cosmx(g::OneDGrid)
Expand All @@ -14,7 +19,7 @@ function test_irfft_cosmx(g::OneDGrid)
f1hr_c = deepcopy(f1hr)
# deepcopy is needed because FFTW irfft messes up with input!
f1b = irfft(f1hr_c, nx)
norm(f1-f1b)/norm(f1) < 1e-12
norm(f1-f1b)/norm(f1) < tolerance
end

function test_irfft_AmulB_cosmx(g::OneDGrid)
Expand All @@ -24,15 +29,15 @@ function test_irfft_AmulB_cosmx(g::OneDGrid)
# deepcopy is needed because FFTW irfft messes up with input!
f1b = Array{Float64}(g.nx)
A_mul_B!( f1b, g.irfftplan, f1hr_c )
norm(f1-f1b)/norm(f1) < 1e-12
norm(f1-f1b)/norm(f1) < tolerance
end

function test_ifft_cosmxcosny(g::TwoDGrid)
# test fft for cos(mx)cos(ny)
f1, f2, f1h, f2h, f1hr, f2hr, f1hr_mul, f2hr_mul,
f1h_th, f1hr_th, f2h_th, f2hr_th = create_testfuncs(g)
f1b = real(ifft(f1h))
norm(f1-f1b)/norm(f1) < 1e-12
norm(f1-f1b)/norm(f1) < tolerance
end

function test_irfft_cosmxcosny(g::TwoDGrid)
Expand All @@ -42,7 +47,7 @@ function test_irfft_cosmxcosny(g::TwoDGrid)
f1hr_c = deepcopy(f1hr)
# deepcopy is needed because FFTW irfft messes up with input!
f1b = irfft(f1hr_c, nx)
norm(f1-f1b)/norm(f1) < 1e-12
norm(f1-f1b)/norm(f1) < tolerance
end

function test_irfft_AmulB_cosmxcosny(g::TwoDGrid)
Expand All @@ -53,25 +58,25 @@ function test_irfft_AmulB_cosmxcosny(g::TwoDGrid)
# deepcopy is needed because FFTW irfft messes up with input!
f1b = Array{Float64}(g.nx, g.ny)
A_mul_B!( f1b, g.irfftplan, f1hr_c )
norm(f1-f1b)/norm(f1) < 1e-12
norm(f1-f1b)/norm(f1) < tolerance
end

function test_ifft_sinmxny(g::TwoDGrid)
# test fft for sin(mx+ny)
f1, f2, f1h, f2h, f1hr, f2hr, f1hr_mul, f2hr_mul,
f1h_th, f1hr_th, f2h_th, f2hr_th = create_testfuncs(g)
f2hr_c = deepcopy(f2hr);
f2hr_c = deepcopy(f2hr)
# deepcopy is needed because FFTW irfft messes up with input!
f2b3 = irfft(f2hr_c, g.nx);
norm(f2-f2b3)/norm(f2) < 1e-12
f2b3 = irfft(f2hr_c, g.nx)
norm(f2-f2b3)/norm(f2) < tolerance
end

function test_irfft_sinmxny(g::TwoDGrid)
# test irfft for sin(mx+ny)
f1, f2, f1h, f2h, f1hr, f2hr, f1hr_mul, f2hr_mul,
f1h_th, f1hr_th, f2h_th, f2hr_th = create_testfuncs(g)
f2b4 = real(ifft(f2h));
norm(f2-f2b4)/norm(f2) < 1e-12
f2b4 = real(ifft(f2h))
norm(f2-f2b4)/norm(f2) < tolerance
end

function test_irfft_AmulB_sinmxny(g::TwoDGrid)
Expand All @@ -82,22 +87,22 @@ function test_irfft_AmulB_sinmxny(g::TwoDGrid)
# deepcopy is needed because FFTW irfft messes up with input!
f2b = Array{Float64}(g.nx, g.ny)
A_mul_B!( f2b, g.irfftplan, f2hr_c )
norm(f2-f2b)/norm(f2) < 1e-12
norm(f2-f2b)/norm(f2) < tolerance
end



# -----------------------------------------------------------------------------
# Running the tests

# Test square grid
nx = 32 # number of points
Lx = 2.0π # Domain width
# Test 1D grid
nx = 32 # number of points
Lx = 2π # Domain width
g1 = OneDGrid(nx, Lx)

# Test square grid
nx, ny = 32, 64 # number of points
Lx, Ly = 2π, 3π # Domain width
# Test 2D rectangular grid
nx, ny = 32, 64 # number of points
Lx, Ly = 2π, 3π # Domain width
g2 = TwoDGrid(nx, Lx, ny, Ly)

@test test_ifft_cosmx(g1)
Expand Down
3 changes: 1 addition & 2 deletions test/test_timesteppers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ We integrate a random IC from 0 to t=tf.
The amplitude of the initial condition is kept low (e.g. multiplied by 1e-5)
so that nonlinear terms do not come into play. This way we can compare the final
state qh(t=tf) with qh(t=0)*exp(-ν k^nν tf).
We choose to linear drag (nν=0) so that we can test the energy since in that
We choose linear drag (nν=0) so that we can test the energy since in that
case E(t=tf) = E(t=0)*exp(-2ν tf).
"""
function testtwodturbstepforward(n=64, L=2π, ν=1e-2, nν=0;
Expand Down Expand Up @@ -68,7 +68,6 @@ end
n = 64
tf = 0.2


for (stepper, steps) in steppersteps
@test testtwodturbstepforward(n; stepper=stepper, nsteps=steps)
end
54 changes: 0 additions & 54 deletions test/test_timesteppers_dt.jl

This file was deleted.

0 comments on commit 0bd356e

Please sign in to comment.