From 9a34165813270013819c12c866c164b8c9898f08 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Sat, 31 Aug 2019 11:42:53 +1000 Subject: [PATCH 1/3] minor additions to increase coverage in BarotropicQG/QGQL modules --- test/runtests.jl | 2 ++ test/test_barotropicqg.jl | 12 +++++++++--- test/test_barotropicqgql.jl | 6 +++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index fa7e873a..b6e37c72 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -61,6 +61,7 @@ end @test test_bqg_formstress(0.01, "ForwardEuler") @test test_bqg_energyenstrophy() @test test_bqg_meanenergyenstrophy() + @test BarotropicQG.nothingfunction() == nothing end @testset "BarotropicQGQL" begin @@ -78,6 +79,7 @@ end @test test_bqgql_stochasticforcingbudgets() @test test_bqgql_advection(0.0005, "ForwardEuler") @test test_bqgql_energyenstrophy() + @test BarotropicQGQL.nothingfunction() == nothing end @testset "MultilayerQG" begin diff --git a/test/test_barotropicqg.jl b/test/test_barotropicqg.jl index 3ebed169..2c6a89f9 100644 --- a/test/test_barotropicqg.jl +++ b/test/test_barotropicqg.jl @@ -279,6 +279,9 @@ function test_bqg_energyenstrophy() k0, l0 = g.k[2], g.l[2] # fundamental wavenumbers x, y = gridpoints(g) + energy_calc = 29/9 + enstrophy_calc = 2701/162 + eta = @. cos(10k0*x)*cos(10l0*y) psi0 = @. sin(2k0*x)*cos(2l0*y) + 2sin(k0*x)*cos(3l0*y) zeta0 = @. -((2k0)^2+(2l0)^2)*sin(2k0*x)*cos(2l0*y) - (k0^2+(3l0)^2)*2sin(k0*x)*cos(3l0*y) @@ -291,7 +294,7 @@ function test_bqg_energyenstrophy() energyzeta0 = BarotropicQG.energy(prob) enstrophyzeta0 = BarotropicQG.enstrophy(prob) - isapprox(energyzeta0, 29.0/9, rtol=1e-13) && isapprox(enstrophyzeta0, 2701.0/162, rtol=1e-13) + isapprox(energyzeta0, energy_calc, rtol=1e-13) && isapprox(enstrophyzeta0, enstrophy_calc, rtol=1e-13) end function test_bqg_meanenergyenstrophy() @@ -308,6 +311,9 @@ function test_bqg_meanenergyenstrophy() beta = 10.0 U = 1.2 + energy_calc = 29/9 + enstrophy_calc = 2701/162 + prob = BarotropicQG.ForcedProblem(nx=nx, Lx=Lx, ny=ny, Ly=Ly, beta=beta, eta=eta, calcFU = calcFU, stepper="ForwardEuler") @@ -323,7 +329,7 @@ function test_bqg_meanenergyenstrophy() (isapprox(energyU, 0.5*U^2, rtol=1e-13) && isapprox(enstrophyU, beta*U, rtol=1e-13) && - isapprox(energyzeta0, 29.0/9, rtol=1e-13) && - isapprox(enstrophyzeta0, 2701.0/162, rtol=1e-13) + isapprox(energyzeta0, energy_calc, rtol=1e-13) && + isapprox(enstrophyzeta0, enstrophy_calc, rtol=1e-13) ) end diff --git a/test/test_barotropicqgql.jl b/test/test_barotropicqgql.jl index fb32bfaa..52bb3be2 100644 --- a/test/test_barotropicqgql.jl +++ b/test/test_barotropicqgql.jl @@ -239,17 +239,21 @@ function test_bqgql_energyenstrophy() k0, l0 = g.k[2], g.l[2] # fundamental wavenumbers x, y = gridpoints(g) + energy_calc = 29/9 + enstrophy_calc = 2701/162 + eta = @. cos(10k0*x)*cos(10l0*y) psi0 = @. sin(2k0*x)*cos(2l0*y) + 2sin(k0*x)*cos(3l0*y) zeta0 = @. -((2k0)^2+(2l0)^2)*sin(2k0*x)*cos(2l0*y) - (k0^2+(3l0)^2)*2sin(k0*x)*cos(3l0*y) prob = BarotropicQGQL.InitialValueProblem(nx=nx, Lx=Lx, ny=ny, Ly=Ly, eta=eta, stepper="ForwardEuler") sol, cl, v, p, g = prob.sol, prob.clock, prob.vars, prob.params, prob.grid + BarotropicQGQL.set_zeta!(prob, zeta0) BarotropicQGQL.updatevars!(prob) energyzeta0 = BarotropicQGQL.energy(prob) enstrophyzeta0 = BarotropicQGQL.enstrophy(prob) - isapprox(energyzeta0, 29.0/9, rtol=1e-13) && isapprox(enstrophyzeta0, 2701.0/162, rtol=1e-13) + isapprox(energyzeta0, energy_calc, rtol=1e-13) && isapprox(enstrophyzeta0, enstrophy_calc, rtol=1e-13) && BarotropicQGQL.addforcing!(prob.timestepper.N, sol, cl.t, cl, v, p, g)==nothing end From 00aeb25f24ff3e5cef0f2747037d8c0a8cf07769 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Sat, 31 Aug 2019 12:12:40 +1000 Subject: [PATCH 2/3] minor additions to increase coverage in MultilayerQG module and utils --- test/runtests.jl | 2 ++ test/test_multilayerqg.jl | 2 +- test/test_utils.jl | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index b6e37c72..5e7075d9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -32,6 +32,7 @@ testtime = @elapsed begin include("test_utils.jl") @test testpeakedisotropicspectrum() + @test_throws ErrorException("the domain is not square") testpeakedisotropicspectrum_rectangledomain() end @testset "TwoDTurb" begin @@ -92,6 +93,7 @@ end @test test_mqg_fluxes() @test test_setqsetpsi() @test test_paramsconstructor() + @test MultilayerQG.nothingfunction() == nothing end end # time diff --git a/test/test_multilayerqg.jl b/test/test_multilayerqg.jl index 292750b2..6ff3c363 100644 --- a/test/test_multilayerqg.jl +++ b/test/test_multilayerqg.jl @@ -269,7 +269,7 @@ function test_mqg_energies(;dt=0.001, stepper="ForwardEuler", n=128, L=2π, nlay KE, PE = MultilayerQG.energies(prob) - isapprox(KE[1], 61/640*1e-6, rtol=rtol_multilayerqg) && isapprox(KE[2], 3*1e-6, rtol=rtol_multilayerqg) && isapprox(PE[1], 1025/1152*1e-6, rtol=rtol_multilayerqg) + isapprox(KE[1], 61/640*1e-6, rtol=rtol_multilayerqg) && isapprox(KE[2], 3*1e-6, rtol=rtol_multilayerqg) && isapprox(PE[1], 1025/1152*1e-6, rtol=rtol_multilayerqg) && MultilayerQG.addforcing!(prob.timestepper.RHS₁, sol, cl.t, cl, vs, pr, gr)==nothing end """ diff --git a/test/test_utils.jl b/test/test_utils.jl index bcddae09..a4c366c5 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -13,3 +13,12 @@ function testpeakedisotropicspectrum() isapprox(abs.(qhρtest)/abs(qhρtest[1]), (ρtest/ρtest[1]).^(-2), rtol=5e-3) end + + +function testpeakedisotropicspectrum_rectangledomain() + nx, ny = 32, 34 + Lx, Ly = 2π, 3π + gr = TwoDGrid(nx, Lx, ny, Ly) + k0, E0 = 6, 0.5 + qi = peakedisotropicspectrum(gr, k0, E0; allones=true) +end From 0a0d6678486056ae64f361f3ccdb03fa9430d0eb Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Sat, 31 Aug 2019 12:27:13 +1000 Subject: [PATCH 3/3] another addition to increase coverage in BarotropicQG module --- test/test_barotropicqg.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_barotropicqg.jl b/test/test_barotropicqg.jl index 2c6a89f9..1d82ff27 100644 --- a/test/test_barotropicqg.jl +++ b/test/test_barotropicqg.jl @@ -294,7 +294,8 @@ function test_bqg_energyenstrophy() energyzeta0 = BarotropicQG.energy(prob) enstrophyzeta0 = BarotropicQG.enstrophy(prob) - isapprox(energyzeta0, energy_calc, rtol=1e-13) && isapprox(enstrophyzeta0, enstrophy_calc, rtol=1e-13) + isapprox(energyzeta0, energy_calc, rtol=1e-13) && isapprox(enstrophyzeta0, enstrophy_calc, rtol=1e-13) && + BarotropicQG.addforcing!(prob.timestepper.N, sol, cl.t, cl, v, p, g)==nothing end function test_bqg_meanenergyenstrophy()