From 1db6f87bd8025633522f61ccdaf43f7a7745a886 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Sun, 1 Sep 2019 14:08:38 +1000 Subject: [PATCH 01/11] =?UTF-8?q?changes=20notation:=20mu,=20nu=20->=20?= =?UTF-8?q?=CE=BC,=20=CE=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/barotropicqg.jl | 74 ++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/barotropicqg.jl b/src/barotropicqg.jl index a9befda8..077f768e 100644 --- a/src/barotropicqg.jl +++ b/src/barotropicqg.jl @@ -40,28 +40,28 @@ Construct a BarotropicQG turbulence problem. function Problem(; # Numerical parameters - nx = 256, - Lx = 2π, - ny = nx, - Ly = Lx, - dt = 0.01, - # Physical parameters - f0 = 1.0, - beta = 0.0, - eta = nothing, - # Drag and/or hyper-/hypo-viscosity - nu = 0.0, - nnu = 1, - mu = 0.0, - # Timestepper and eqn options - stepper = "RK4", - calcFU = nothingfunction, - calcFq = nothingfunction, - stochastic = false, - T = Float64) + nx = 256, + Lx = 2π, + ny = nx, + Ly = Lx, + dt = 0.01, + # Physical parameters + f0 = 1.0, + β = 0.0, + eta = nothing, + # Drag and/or hyper-/hypo-viscosity + ν = 0.0, + nν = 1, + μ = 0.0, + # Timestepper and eqn options + stepper = "RK4", + calcFU = nothingfunction, + calcFq = nothingfunction, + stochastic = false, + T = Float64) # the grid - gr = TwoDGrid(nx, Lx, ny, Ly) + gr = TwoDGrid(nx, Lx, ny, Ly) x, y = gridpoints(gr) # topographic PV @@ -71,9 +71,9 @@ function Problem(; end if typeof(eta)!=Array{Float64,2} #this is true if eta was passes in Problem as a function - pr = Params(gr, f0, beta, eta, mu, nu, nnu, calcFU, calcFq) + pr = Params(gr, f0, β, eta, μ, ν, nν, calcFU, calcFq) else - pr = Params(f0, beta, eta, rfft(eta), mu, nu, nnu, calcFU, calcFq) + pr = Params(f0, β, eta, rfft(eta), μ, ν, nν, calcFU, calcFq) end if calcFq == nothingfunction && calcFU == nothingfunction @@ -98,33 +98,33 @@ ForcedProblem(; kwargs...) = Problem(; kwargs...) # ---------- """ - Params(g::TwoDGrid, f0, beta, FU, eta, mu, nu, nnu, calcFU, calcFq) + Params(g::TwoDGrid, f0, β, FU, eta, μ, ν, nν, calcFU, calcFq) Returns the params for an unforced two-dimensional barotropic QG problem. """ struct Params{T} <: AbstractParams f0::T # Constant planetary vorticity - beta::T # Planetary vorticity y-gradient + β::T # Planetary vorticity y-gradient eta::Array{T,2} # Topographic PV etah::Array{Complex{T},2} # FFT of Topographic PV - mu::T # Linear drag - nu::T # Viscosity coefficient - nnu::Int # Hyperviscous order (nnu=1 is plain old viscosity) + μ::T # Linear drag + ν::T # Viscosity coefficient + nν::Int # Hyperviscous order (nν=1 is plain old viscosity) calcFU::Function # Function that calculates the forcing F(t) on # domain-averaged zonal flow U(t) calcFq!::Function # Function that calculates the forcing on QGPV q end """ - Params(g::TwoDGrid, f0, beta, eta::Function, mu, nu, nnu, calcFU, calcFq) + Params(g::TwoDGrid, f0, β, eta::Function, μ, ν, nν, calcFU, calcFq) Constructor for Params that accepts a generating function for the topographic PV. """ -function Params(g, f0, beta, eta::Function, mu, nu, nnu, calcFU, calcFq) +function Params(g, f0, β, eta::Function, μ, ν, nν, calcFU, calcFq) x, y = gridpoints(g) etagrid = eta(x, y) etah = rfft(etagrid) - Params(f0, beta, etagrid, etah, mu, nu, nnu, calcFU, calcFq) + Params(f0, β, etagrid, etah, μ, ν, nν, calcFU, calcFq) end @@ -138,7 +138,7 @@ end Returns the equation for two-dimensional barotropic QG problem with params p and grid g. """ function Equation(p::Params, g::AbstractGrid{T}) where T - LC = @. -p.mu - p.nu*g.Krsq^p.nnu + im*p.beta*g.kr*g.invKrsq + LC = @. -p.μ - p.ν*g.Krsq^p.nν + im*p.β*g.kr*g.invKrsq LC[1, 1] = 0 FourierFlows.Equation(LC, calcN!, g) end @@ -357,18 +357,18 @@ meanenergy(prob) = real(0.5*prob.sol[1, 1].^2) """ Returns the enstrophy of the domain-averaged U. """ -meanenstrophy(prob) = real(prob.params.beta*prob.sol[1, 1]) +meanenstrophy(prob) = real(prob.params.β*prob.sol[1, 1]) """ dissipation(prob) dissipation(s, v, p, g) -Returns the domain-averaged dissipation rate. nnu must be >= 1. +Returns the domain-averaged dissipation rate. nν must be >= 1. """ @inline function dissipation(sol, v, p, g) - @. v.uh = g.Krsq^(p.nnu-1) * abs2(sol) + @. v.uh = g.Krsq^(p.nν-1) * abs2(sol) v.uh[1, 1] = 0 - p.nu/(g.Lx*g.Ly)*parsevalsum(v.uh, g) + p.ν/(g.Lx*g.Ly)*parsevalsum(v.uh, g) end @inline dissipation(prob) = dissipation(prob.sol, prob.vars, prob.params, prob.grid) @@ -396,12 +396,12 @@ end drag(prob) drag(s, v, p, g) -Returns the extraction of domain-averaged energy by drag mu. +Returns the extraction of domain-averaged energy by drag μ. """ @inline function drag(sol, v, p, g) @. v.uh = g.Krsq^(-1) * abs2(sol) v.uh[1, 1] = 0 - p.mu/(g.Lx*g.Ly)*FourierFlows.parsevalsum(v.uh, g) + p.μ/(g.Lx*g.Ly)*FourierFlows.parsevalsum(v.uh, g) end @inline drag(prob) = drag(prob.sol, prob.vars, prob.params, prob.grid) From e63517496d95c1434cca0a2af8198b276c2b0837 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Sun, 1 Sep 2019 14:18:57 +1000 Subject: [PATCH 02/11] =?UTF-8?q?changes=20notation:=20mu,=20nu=20->=20?= =?UTF-8?q?=CE=BC,=20=CE=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test_barotropicqg.jl | 50 +++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/test/test_barotropicqg.jl b/test/test_barotropicqg.jl index 1d82ff27..c51da18e 100644 --- a/test/test_barotropicqg.jl +++ b/test/test_barotropicqg.jl @@ -7,8 +7,8 @@ function test_bqg_rossbywave(stepper, dt, nsteps) nx = 64 beta = 2.0 Lx = 2π - mu = 0.0 - nu = 0.0 + μ = 0.0 + ν = 0.0 gr = TwoDGrid(nx, Lx) x, y = gridpoints(gr) @@ -21,7 +21,7 @@ function test_bqg_rossbywave(stepper, dt, nsteps) eta(x, y) = 0*x end - prob = BarotropicQG.InitialValueProblem(nx=nx, Lx=Lx, eta=eta, beta=beta, mu=mu, nu=nu, stepper=stepper, dt=dt) + prob = BarotropicQG.InitialValueProblem(nx=nx, Lx=Lx, eta=eta, beta=beta, μ=μ, ν=ν, stepper=stepper, dt=dt) sol, cl, v, p, g = prob.sol, prob.clock, prob.vars, prob.params, prob.grid x, y = gridpoints(g) @@ -50,11 +50,11 @@ end Tests if the energy budgets are closed for BarotropicQG with stochastic forcing. """ -function test_bqg_stochasticforcingbudgets(; n=256, dt=0.01, L=2π, nu=1e-7, nnu=2, mu=1e-1, message=false) +function test_bqg_stochasticforcingbudgets(; n=256, dt=0.01, L=2π, ν=1e-7, nν=2, μ=1e-1, message=false) n, L = 256, 2π - nu, nnu = 1e-7, 2 - mu = 1e-1 - dt, tf = 0.005, 0.1/mu + ν, nν = 1e-7, 2 + μ = 1e-1 + dt, tf = 0.005, 0.1/μ nt = round(Int, tf/dt) ns = 1 @@ -84,7 +84,7 @@ function test_bqg_stochasticforcingbudgets(; n=256, dt=0.01, L=2π, nu=1e-7, nnu nothing end - prob = BarotropicQG.ForcedProblem(nx=n, Lx=L, nu=nu, nnu=nnu, mu=mu, dt=dt, + prob = BarotropicQG.ForcedProblem(nx=n, Lx=L, ν=ν, nν=nν, μ=μ, dt=dt, stepper="RK4", calcFq=calcFq!, stochastic=true) sol, cl, v, p, g = prob.sol, prob.clock, prob.vars, prob.params, prob.grid @@ -106,7 +106,7 @@ function test_bqg_stochasticforcingbudgets(; n=256, dt=0.01, L=2π, nu=1e-7, nnu E, D, W, R = diags - t = round(mu*cl.t, digits=2) + t = round(μ*cl.t, digits=2) i₀ = 1 dEdt = (E[(i₀+1):E.i] - E[i₀:E.i-1])/cl.dt @@ -133,11 +133,11 @@ end Tests if the energy budgets are closed for BarotropicQG with stochastic forcing. """ -function test_bqg_deterministicforcingbudgets(; n=256, dt=0.01, L=2π, nu=1e-7, nnu=2, mu=1e-1, message=false) +function test_bqg_deterministicforcingbudgets(; n=256, dt=0.01, L=2π, ν=1e-7, nν=2, μ=1e-1, message=false) n, L = 256, 2π - nu, nnu = 1e-7, 2 - mu = 1e-1 - dt, tf = 0.005, 0.1/mu + ν, nν = 1e-7, 2 + μ = 1e-1 + dt, tf = 0.005, 0.1/μ nt = round(Int, tf/dt) ns = 1 @@ -154,7 +154,7 @@ function test_bqg_deterministicforcingbudgets(; n=256, dt=0.01, L=2π, nu=1e-7, nothing end - prob = BarotropicQG.ForcedProblem(nx=n, Lx=L, nu=nu, nnu=nnu, mu=mu, dt=dt, + prob = BarotropicQG.ForcedProblem(nx=n, Lx=L, ν=ν, nν=nν, μ=μ, dt=dt, stepper="RK4", calcFq=calcFq!, stochastic=false) sol, cl, v, p, g = prob.sol, prob.clock, prob.vars, prob.params, prob.grid @@ -176,7 +176,7 @@ function test_bqg_deterministicforcingbudgets(; n=256, dt=0.01, L=2π, nu=1e-7, E, D, W, R = diags - t = round(mu*cl.t, digits=2) + t = round(μ*cl.t, digits=2) i₀ = 1 dEdt = (E[(i₀+1):E.i] - E[i₀:E.i-1])/cl.dt @@ -202,14 +202,14 @@ Tests the advection term in the twodturb module by timestepping a test problem with timestep dt and timestepper identified by the string stepper. The test problem is derived by picking a solution ζf (with associated streamfunction ψf) for which the advection term J(ψf, ζf) is non-zero. Next, a -forcing Ff is derived according to Ff = ∂ζf/∂t + J(ψf, ζf) - nuΔζf. One solution +forcing Ff is derived according to Ff = ∂ζf/∂t + J(ψf, ζf) - νΔζf. One solution to the vorticity equation forced by this Ff is then ζf. (This solution may not be realized, at least at long times, if it is unstable.) """ -function test_bqg_advection(dt, stepper; n=128, L=2π, nu=1e-2, nnu=1, mu=0.0, message=false) +function test_bqg_advection(dt, stepper; n=128, L=2π, ν=1e-2, nν=1, μ=0.0, message=false) n, L = 128, 2π - nu, nnu = 1e-2, 1 - mu = 0.0 + ν, nν = 1e-2, 1 + μ = 0.0 tf = 1.0 nt = round(Int, tf/dt) @@ -220,7 +220,7 @@ function test_bqg_advection(dt, stepper; n=128, L=2π, nu=1e-2, nnu=1, mu=0.0, m qf = @. -8sin(2x)*cos(2y) - 20sin(x)*cos(3y) Ff = @. -( - nu*( 64sin(2x)*cos(2y) + 200sin(x)*cos(3y) ) + ν*( 64sin(2x)*cos(2y) + 200sin(x)*cos(3y) ) + 8*( cos(x)*cos(3y)*sin(2x)*sin(2y) - 3cos(2x)*cos(2y)*sin(x)*sin(3y) ) ) @@ -232,7 +232,7 @@ function test_bqg_advection(dt, stepper; n=128, L=2π, nu=1e-2, nnu=1, mu=0.0, m nothing end - prob = BarotropicQG.ForcedProblem(nx=n, Lx=L, nu=nu, nnu=nnu, mu=mu, dt=dt, stepper=stepper, calcFq=calcFq!) + prob = BarotropicQG.ForcedProblem(nx=n, Lx=L, ν=ν, nν=nν, μ=μ, dt=dt, stepper=stepper, calcFq=calcFq!) sol, cl, v, p, g = prob.sol, prob.clock, prob.vars, prob.params, prob.grid BarotropicQG.set_zeta!(prob, qf) @@ -247,10 +247,10 @@ end Tests the form stress term that forces the domain-averaged zonal flow U(t). """ -function test_bqg_formstress(dt, stepper; n=128, L=2π, nu=0.0, nnu=1, mu=0.0, message=false) +function test_bqg_formstress(dt, stepper; n=128, L=2π, ν=0.0, nν=1, μ=0.0, message=false) n, L = 128, 2π - nu, nnu = 1e-2, 1 - mu = 0.0 + ν, nν = 1e-2, 1 + μ = 0.0 tf = 1 nt = 1 @@ -263,7 +263,7 @@ function test_bqg_formstress(dt, stepper; n=128, L=2π, nu=0.0, nnu=1, mu=0.0, m answer = 0.25 # this is what should be - prob = BarotropicQG.ForcedProblem(nx=n, Lx=L, nu=nu, nnu=nnu, mu=mu, dt=dt, stepper=stepper, eta=topoPV, calcFU = F) + prob = BarotropicQG.ForcedProblem(nx=n, Lx=L, ν=ν, nν=nν, μ=μ, dt=dt, stepper=stepper, eta=topoPV, calcFU = F) BarotropicQG.set_zeta!(prob, zetai) BarotropicQG.updatevars!(prob) From 0bc2e28cdab5aa0031592a5fa914fa9b8e25baf3 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Thu, 2 Jan 2020 10:57:09 +1100 Subject: [PATCH 03/11] GPUifies BarotropicQG module; tests now run on both CPU and GPU --- Manifest.toml | 392 -------------------------------------- src/barotropicqg.jl | 142 +++++++------- test/runtests.jl | 41 ++-- test/test_barotropicqg.jl | 110 +++++------ test/test_twodturb.jl | 4 +- 5 files changed, 140 insertions(+), 549 deletions(-) delete mode 100644 Manifest.toml diff --git a/Manifest.toml b/Manifest.toml deleted file mode 100644 index e9e0561a..00000000 --- a/Manifest.toml +++ /dev/null @@ -1,392 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -[[AbstractFFTs]] -deps = ["LinearAlgebra"] -git-tree-sha1 = "380e36c66edfa099cd90116b24c1ce8cafccac40" -uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" -version = "0.4.1" - -[[Adapt]] -deps = ["LinearAlgebra"] -git-tree-sha1 = "82dab828020b872fa9efd3abec1152b075bc7cbf" -uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" -version = "1.0.0" - -[[AxisAlgorithms]] -deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"] -git-tree-sha1 = "a4d07a1c313392a77042855df46c5f534076fab9" -uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" -version = "1.0.0" - -[[Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" - -[[BinDeps]] -deps = ["Compat", "Libdl", "SHA", "URIParser"] -git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9" -uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee" -version = "0.8.10" - -[[BinaryProvider]] -deps = ["Libdl", "Logging", "SHA"] -git-tree-sha1 = "c7361ce8a2129f20b0e05a89f7070820cfed6648" -uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" -version = "0.5.6" - -[[CEnum]] -git-tree-sha1 = "62847acab40e6855a9b5905ccb99c2b5cf6b3ebb" -uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82" -version = "0.2.0" - -[[CSTParser]] -deps = ["Tokenize"] -git-tree-sha1 = "c69698c3d4a7255bc1b4bc2afc09f59db910243b" -uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f" -version = "0.6.2" - -[[CUDAapi]] -deps = ["Libdl", "Logging"] -git-tree-sha1 = "9b2b4b71d6b7f946c9689bb4dea03ff92e3c7091" -uuid = "3895d2a7-ec45-59b8-82bb-cfc6a382f9b3" -version = "1.1.0" - -[[CUDAdrv]] -deps = ["CUDAapi", "Libdl", "Printf"] -git-tree-sha1 = "9ce99b5732c70e06ed97c042187baed876fb1698" -uuid = "c5f51814-7f29-56b8-a69c-e4d8f6be1fde" -version = "3.1.0" - -[[CUDAnative]] -deps = ["Adapt", "CUDAapi", "CUDAdrv", "DataStructures", "InteractiveUtils", "LLVM", "Libdl", "Logging", "Printf", "TimerOutputs"] -git-tree-sha1 = "0a00bef482b7c9127495c7f4a2a85e73b13b5af8" -uuid = "be33ccc6-a3ff-5ff2-a52e-74243cff1e17" -version = "2.3.0" - -[[CodecZlib]] -deps = ["BinaryProvider", "Libdl", "TranscodingStreams"] -git-tree-sha1 = "05916673a2627dd91b4969ff8ba6941bc85a960e" -uuid = "944b1d66-785c-5afd-91f1-9de20f533193" -version = "0.6.0" - -[[ColorTypes]] -deps = ["FixedPointNumbers", "Random"] -git-tree-sha1 = "10050a24b09e8e41b951e9976b109871ce98d965" -uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" -version = "0.8.0" - -[[Colors]] -deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport"] -git-tree-sha1 = "c9c1845d6bf22e34738bee65c357a69f416ed5d1" -uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" -version = "0.9.6" - -[[Compat]] -deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] -git-tree-sha1 = "84aa74986c5b9b898b0d1acaf3258741ee64754f" -uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "2.1.0" - -[[Conda]] -deps = ["JSON", "VersionParsing"] -git-tree-sha1 = "9a11d428dcdc425072af4aea19ab1e8c3e01c032" -uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d" -version = "1.3.0" - -[[Coverage]] -deps = ["HTTP", "JSON", "LibGit2", "MbedTLS"] -git-tree-sha1 = "f9780daf3fea51ad2d7b7ed4f480ac34ab36587f" -uuid = "a2441757-f6aa-5fb2-8edb-039e3f45d037" -version = "0.9.2" - -[[Crayons]] -deps = ["Test"] -git-tree-sha1 = "f621b8ef51fd2004c7cf157ea47f027fdeac5523" -uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f" -version = "4.0.0" - -[[CuArrays]] -deps = ["AbstractFFTs", "Adapt", "CUDAapi", "CUDAdrv", "CUDAnative", "GPUArrays", "LinearAlgebra", "MacroTools", "NNlib", "Printf", "Random", "Requires", "SparseArrays", "TimerOutputs"] -git-tree-sha1 = "46b48742a84bb839e74215b7e468a4a1c6ba30f9" -uuid = "3a865a2d-5b23-5a0f-bc46-62713ec82fae" -version = "1.2.1" - -[[DataStructures]] -deps = ["InteractiveUtils", "OrderedCollections"] -git-tree-sha1 = "0809951a1774dc724da22d26e4289bbaab77809a" -uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.17.0" - -[[Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[DelimitedFiles]] -deps = ["Mmap"] -uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" - -[[Distributed]] -deps = ["Random", "Serialization", "Sockets"] -uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" - -[[FFTW]] -deps = ["AbstractFFTs", "BinaryProvider", "Conda", "Libdl", "LinearAlgebra", "Reexport", "Test"] -git-tree-sha1 = "e1a479d3c972f20c9a70563eec740bbfc786f515" -uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" -version = "0.3.0" - -[[FileIO]] -deps = ["Pkg"] -git-tree-sha1 = "351f001a78aa1b7ad2696e386e110b5abd071c71" -uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" -version = "1.0.7" - -[[FillArrays]] -deps = ["LinearAlgebra", "Random", "SparseArrays"] -git-tree-sha1 = "8fba6ddaf66b45dec830233cea0aae43eb1261ad" -uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "0.6.4" - -[[FixedPointNumbers]] -git-tree-sha1 = "d14a6fa5890ea3a7e5dcab6811114f132fec2b4b" -uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" -version = "0.6.1" - -[[FourierFlows]] -deps = ["CUDAapi", "Coverage", "CuArrays", "FFTW", "Interpolations", "JLD2", "LinearAlgebra", "Printf", "Random", "Reexport", "Requires", "Statistics"] -git-tree-sha1 = "8b58b99504aec93275be09ae5bb8a39817956d17" -repo-rev = "ImplementCUDAapi" -repo-url = "https://github.com/FourierFlows/FourierFlows.jl.git" -uuid = "2aec4490-903f-5c70-9b11-9bed06a700e1" -version = "0.3.1" - -[[GPUArrays]] -deps = ["Adapt", "FFTW", "FillArrays", "LinearAlgebra", "Printf", "Random", "Serialization", "StaticArrays", "Test"] -git-tree-sha1 = "dd169c636d1d3656a9faca772f5bd7c226a61254" -uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7" -version = "1.0.1" - -[[HTTP]] -deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"] -git-tree-sha1 = "c4a527dba1d26add0e85946e1a53f42a1b343acc" -uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" -version = "0.8.5" - -[[IniFile]] -deps = ["Test"] -git-tree-sha1 = "098e4d2c533924c921f9f9847274f2ad89e018b8" -uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f" -version = "0.5.0" - -[[InteractiveUtils]] -deps = ["Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" - -[[Interpolations]] -deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "WoodburyMatrices"] -git-tree-sha1 = "e1bac96b5ef3ea23b50e801b4a988ec21861a47f" -uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" -version = "0.12.2" - -[[JLD2]] -deps = ["CodecZlib", "DataStructures", "FileIO", "LinearAlgebra", "Mmap", "Printf", "Random", "Test"] -git-tree-sha1 = "3ba90ff93e1d5b9b2103588051c2d349fae54dac" -uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819" -version = "0.1.2" - -[[JSON]] -deps = ["Dates", "Mmap", "Parsers", "Unicode"] -git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" -uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -version = "0.21.0" - -[[LLVM]] -deps = ["CEnum", "Libdl", "Printf", "Unicode"] -git-tree-sha1 = "52cfea426bd248a427aace7d88eb5d45b84ea297" -uuid = "929cbde3-209d-540e-8aea-75f648917ca0" -version = "1.2.0" - -[[LaTeXStrings]] -deps = ["Compat"] -git-tree-sha1 = "7ab9b8788cfab2bdde22adf9004bda7ad9954b6c" -uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" -version = "1.0.3" - -[[LibGit2]] -uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" - -[[Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[LinearAlgebra]] -deps = ["Libdl"] -uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[[Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" - -[[MacroTools]] -deps = ["CSTParser", "Compat", "DataStructures", "Test", "Tokenize"] -git-tree-sha1 = "d6e9dedb8c92c3465575442da456aec15a89ff76" -uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" -version = "0.5.1" - -[[Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" - -[[MbedTLS]] -deps = ["BinaryProvider", "Dates", "Libdl", "Random", "Sockets"] -git-tree-sha1 = "85f5947b53c8cfd53ccfa3f4abae31faa22c2181" -uuid = "739be429-bea8-5141-9913-cc70e7f3736d" -version = "0.7.0" - -[[Mmap]] -uuid = "a63ad114-7e13-5084-954f-fe012c677804" - -[[NNlib]] -deps = ["Libdl", "LinearAlgebra", "Requires", "Statistics", "TimerOutputs"] -git-tree-sha1 = "0c667371391fc6bb31f7f12f96a56a17098b3de8" -uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" -version = "0.6.0" - -[[OffsetArrays]] -git-tree-sha1 = "1af2f79c7eaac3e019a0de41ef63335ff26a0a57" -uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" -version = "0.11.1" - -[[OrderedCollections]] -deps = ["Random", "Serialization", "Test"] -git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1" -uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.1.0" - -[[Parsers]] -deps = ["Dates", "Test"] -git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b" -uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "0.3.7" - -[[Pkg]] -deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] -uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" - -[[Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[PyCall]] -deps = ["Conda", "Dates", "Libdl", "LinearAlgebra", "MacroTools", "Pkg", "Serialization", "Statistics", "Test", "VersionParsing"] -git-tree-sha1 = "6e5bac1b1faf3575731a6a5b76f638f2389561d3" -uuid = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" -version = "1.91.2" - -[[PyPlot]] -deps = ["Colors", "LaTeXStrings", "PyCall", "Sockets", "Test", "VersionParsing"] -git-tree-sha1 = "3ea391c3211f799df20396d256cee5c8bd755605" -uuid = "d330b81b-6aea-500a-939a-2ce795aea3ee" -version = "2.8.1" - -[[REPL]] -deps = ["InteractiveUtils", "Markdown", "Sockets"] -uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" - -[[Random]] -deps = ["Serialization"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" - -[[Ratios]] -deps = ["Compat"] -git-tree-sha1 = "cdbbe0f350581296f3a2e3e7a91b214121934407" -uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" -version = "0.3.1" - -[[Reexport]] -deps = ["Pkg"] -git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" -uuid = "189a3867-3050-52da-a836-e630ba90ab69" -version = "0.2.0" - -[[Requires]] -deps = ["Test"] -git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" -uuid = "ae029012-a4dd-5104-9daa-d747884805df" -version = "0.5.2" - -[[SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" - -[[Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" - -[[SharedArrays]] -deps = ["Distributed", "Mmap", "Random", "Serialization"] -uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" - -[[Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" - -[[SparseArrays]] -deps = ["LinearAlgebra", "Random"] -uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" - -[[SpecialFunctions]] -deps = ["BinDeps", "BinaryProvider", "Libdl", "Test"] -git-tree-sha1 = "0b45dc2e45ed77f445617b99ff2adf0f5b0f23ea" -uuid = "276daf66-3868-5448-9aa4-cd146d93841b" -version = "0.7.2" - -[[StaticArrays]] -deps = ["LinearAlgebra", "Random", "Statistics"] -git-tree-sha1 = "db23bbf50064c582b6f2b9b043c8e7e98ea8c0c6" -uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "0.11.0" - -[[Statistics]] -deps = ["LinearAlgebra", "SparseArrays"] -uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[[Test]] -deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] -uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[[TimerOutputs]] -deps = ["Crayons", "Printf", "Test", "Unicode"] -git-tree-sha1 = "b80671c06f8f8bae08c55d67b5ce292c5ae2660c" -uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" -version = "0.5.0" - -[[Tokenize]] -git-tree-sha1 = "dfcdbbfb2d0370716c815cbd6f8a364efb6f42cf" -uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624" -version = "0.5.6" - -[[TranscodingStreams]] -deps = ["Random", "Test"] -git-tree-sha1 = "7c53c35547de1c5b9d46a4797cf6d8253807108c" -uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" -version = "0.9.5" - -[[URIParser]] -deps = ["Test", "Unicode"] -git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" -uuid = "30578b45-9adc-5946-b283-645ec420af67" -version = "0.4.0" - -[[UUIDs]] -deps = ["Random", "SHA"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" - -[[Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[VersionParsing]] -deps = ["Compat"] -git-tree-sha1 = "c9d5aa108588b978bd859554660c8a5c4f2f7669" -uuid = "81def892-9a0e-5fdd-b105-ffc91e053289" -version = "1.1.3" - -[[WoodburyMatrices]] -deps = ["LinearAlgebra", "Random", "SparseArrays", "Test"] -git-tree-sha1 = "21772c33b447757ec7d3e61fcdfb9ea5c47eedcf" -uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" -version = "0.4.1" diff --git a/src/barotropicqg.jl b/src/barotropicqg.jl index 077f768e..2f2af098 100644 --- a/src/barotropicqg.jl +++ b/src/barotropicqg.jl @@ -22,13 +22,6 @@ using LinearAlgebra: mul!, ldiv! using FourierFlows: getfieldspecs, structvarsexpr, parsevalsum, parsevalsum2 abstract type BarotropicQGVars <: AbstractVars end -abstract type BarotropicQGForcedVars <: BarotropicQGVars end - -const realscalarvars = [:U] -const physicalvars = [:q, :zeta, :psi, :u, :v] -const transformvars = [ Symbol(var, :h) for var in physicalvars ] -const forcedvars = [:Fqh] -const stochforcedvars = [:prevsol] nothingfunction(args...) = nothing @@ -58,40 +51,37 @@ function Problem(; calcFU = nothingfunction, calcFq = nothingfunction, stochastic = false, - T = Float64) + T = Float64, + dev = CPU()) # the grid - gr = TwoDGrid(nx, Lx, ny, Ly) + gr = TwoDGrid(dev, nx, Lx, ny, Ly) x, y = gridpoints(gr) # topographic PV if eta==nothing - eta = 0*x - etah = rfft(eta) + eta = ArrayType(dev)(0*x) end - if typeof(eta)!=Array{Float64,2} #this is true if eta was passes in Problem as a function + if typeof(eta)!=ArrayType(dev, T, 2) #this is true if eta was passes in Problem as a function pr = Params(gr, f0, β, eta, μ, ν, nν, calcFU, calcFq) else pr = Params(f0, β, eta, rfft(eta), μ, ν, nν, calcFU, calcFq) end if calcFq == nothingfunction && calcFU == nothingfunction - vs = Vars(gr) + vs = Vars(dev, gr) else - if stochastic == false - vs = ForcedVars(gr) - elseif stochastic == true - vs = StochasticForcedVars(gr) - end + if stochastic == false + vs = ForcedVars(dev, gr) + elseif stochastic == true + vs = StochasticForcedVars(dev, gr) + end end eq = Equation(pr, gr) - FourierFlows.Problem(eq, stepper, dt, gr, vs, pr) + FourierFlows.Problem(eq, stepper, dt, gr, vs, pr, dev) end -InitialValueProblem(; kwargs...) = Problem(; kwargs...) -ForcedProblem(; kwargs...) = Problem(; kwargs...) - # ---------- # Parameters @@ -102,17 +92,17 @@ ForcedProblem(; kwargs...) = Problem(; kwargs...) Returns the params for an unforced two-dimensional barotropic QG problem. """ -struct Params{T} <: AbstractParams - f0::T # Constant planetary vorticity - β::T # Planetary vorticity y-gradient - eta::Array{T,2} # Topographic PV - etah::Array{Complex{T},2} # FFT of Topographic PV - μ::T # Linear drag - ν::T # Viscosity coefficient - nν::Int # Hyperviscous order (nν=1 is plain old viscosity) - calcFU::Function # Function that calculates the forcing F(t) on - # domain-averaged zonal flow U(t) - calcFq!::Function # Function that calculates the forcing on QGPV q +struct Params{T, Aphys, Atrans} <: AbstractParams + f0 :: T # Constant planetary vorticity + β :: T # Planetary vorticity y-gradient + eta :: Aphys # Topographic PV + etah :: Atrans # FFT of Topographic PV + μ :: T # Linear drag + ν :: T # Viscosity coefficient + nν :: Int # Hyperviscous order (nν=1 is plain old viscosity) + calcFU :: Function # Function that calculates the forcing F(t) on + # domain-averaged zonal flow U(t) + calcFq! :: Function # Function that calculates the forcing on QGPV q end """ @@ -120,10 +110,9 @@ end Constructor for Params that accepts a generating function for the topographic PV. """ -function Params(g, f0, β, eta::Function, μ, ν, nν, calcFU, calcFq) - x, y = gridpoints(g) - etagrid = eta(x, y) - etah = rfft(etagrid) +function Params(g::AbstractGrid{T, A}, f0, β, eta::Function, μ, ν, nν, calcFU, calcFq) where {T, A} + etagrid = A([eta(g.x[i], g.y[j]) for i=1:g.nx, j=1:g.ny]) + etah = rfft(etagrid) Params(f0, β, etagrid, etah, μ, ν, nν, calcFU, calcFq) end @@ -137,10 +126,10 @@ end Returns the equation for two-dimensional barotropic QG problem with params p and grid g. """ -function Equation(p::Params, g::AbstractGrid{T}) where T - LC = @. -p.μ - p.ν*g.Krsq^p.nν + im*p.β*g.kr*g.invKrsq - LC[1, 1] = 0 - FourierFlows.Equation(LC, calcN!, g) +function Equation(p::Params, g::AbstractGrid) + L = @. - p.μ - p.ν*g.Krsq^p.nν + im*p.β*g.kr*g.invKrsq + L[1, 1] = 0 + FourierFlows.Equation(L, calcN!, g) end @@ -148,52 +137,59 @@ end # Vars # ---- -varspecs = cat( - getfieldspecs(realscalarvars, :(Array{T,0})), - getfieldspecs(physicalvars, :(Array{T,2})), - getfieldspecs(transformvars, :(Array{Complex{T},2})), - dims=1) - -forcedvarspecs = cat(varspecs, getfieldspecs(forcedvars, :(Array{Complex{T},2})), dims=1) -stochforcedvarspecs = cat(forcedvarspecs, getfieldspecs(stochforcedvars, :(Array{Complex{T},2})), dims=1) +struct Vars{Ascalar, Aphys, Atrans, F, P} <: BarotropicQGVars + U :: Ascalar + q :: Aphys + zeta :: Aphys + psi :: Aphys + u :: Aphys + v :: Aphys + qh :: Atrans + zetah :: Atrans + psih :: Atrans + uh :: Atrans + vh :: Atrans + Fqh :: F + prevsol :: P +end -# Construct Vars types -eval(structvarsexpr(:Vars, varspecs; parent=:BarotropicQGVars)) -eval(structvarsexpr(:ForcedVars, forcedvarspecs; parent=:BarotropicQGForcedVars)) -eval(structvarsexpr(:StochasticForcedVars, stochforcedvarspecs; parent=:BarotropicQGForcedVars)) +const ForcedVars = Vars{<:AbstractArray, <:AbstractArray, <:AbstractArray, <:AbstractArray, Nothing} +const StochasticForcedVars = Vars{<:AbstractArray, <:AbstractArray, <:AbstractArray, <:AbstractArray, <:AbstractArray} """ - Vars(g) + Vars(dev, g) -Returns the vars for unforced two-dimensional barotropic QG problem with grid g. +Returns the vars for unforced two-dimensional barotropic QG problem on device dev and with grid g. """ -function Vars(g; T=typeof(g.Lx)) - U = Array{T,0}(undef, ); U[] = 0 - @createarrays T (g.nx, g.ny) q u v psi zeta - @createarrays Complex{T} (g.nkr, g.nl) qh uh vh psih zetah - Vars(U, q, zeta, psi, u, v, qh, zetah, psih, uh, vh) +function Vars(dev::Dev, g::AbstractGrid{T}) where {Dev, T} + U = ArrayType(dev, T, 0)(undef, ); U[] = 0 + @devzeros Dev T (g.nx, g.ny) q u v psi zeta + @devzeros Dev Complex{T} (g.nkr, g.nl) qh uh vh psih zetah + Vars(U, q, zeta, psi, u, v, qh, zetah, psih, uh, vh, nothing, nothing) end """ - ForcedVars(g) + ForcedVars(dev, g) -Returns the vars for forced two-dimensional barotropic QG problem with grid g. +Returns the vars for forced two-dimensional barotropic QG problem on device dev and with grid g. """ -function ForcedVars(g; T=typeof(g.Lx)) - v = Vars(g; T=T) - Fqh = zeros(Complex{T}, (g.nkr, g.nl)) - ForcedVars(getfield.(Ref(v), fieldnames(typeof(v)))..., Fqh) +function ForcedVars(dev::Dev, g::AbstractGrid{T}) where {Dev, T} + U = ArrayType(dev, T, 0)(undef, ); U[] = 0 + @devzeros Dev T (g.nx, g.ny) q u v psi zeta + @devzeros Dev Complex{T} (g.nkr, g.nl) qh uh vh psih zetah Fqh + Vars(U, q, zeta, psi, u, v, qh, zetah, psih, uh, vh, Fqh, nothing) end """ - StochasticForcedVars(g) + StochasticForcedVars(dev, g) -Returns the vars for stochastically forced two-dimensional barotropic QG problem with grid g. +Returns the vars for stochastically forced two-dimensional barotropic QG problem on device dev and with grid g. """ -function StochasticForcedVars(g; T=typeof(g.Lx)) - v = ForcedVars(g; T=T) - prevsol = zeros(Complex{T}, (g.nkr, g.nl)) - StochasticForcedVars(getfield.(Ref(v), fieldnames(typeof(v)))..., prevsol) +function StochasticForcedVars(dev::Dev, g::AbstractGrid{T}) where {Dev, T} + U = ArrayType(dev, T, 0)(undef, ); U[] = 0 + @devzeros Dev T (g.nx, g.ny) q u v psi zeta + @devzeros Dev Complex{T} (g.nkr, g.nl) qh uh vh psih zetah Fqh prevsol + Vars(U, q, zeta, psi, u, v, qh, zetah, psih, uh, vh, Fqh, prevsol) end @@ -301,7 +297,7 @@ function set_zeta!(sol, v::Vars, p, g, zeta) nothing end -function set_zeta!(sol, v::BarotropicQGForcedVars, p, g, zeta) +function set_zeta!(sol, v::Union{ForcedVars, StochasticForcedVars}, p, g, zeta) v.U[] = deepcopy(sol[1, 1]) mul!(v.zetah, g.rfftplan, zeta) v.zetah[1, 1] = 0.0 diff --git a/test/runtests.jl b/test/runtests.jl index 0e9e9a20..1fd06a27 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -23,6 +23,7 @@ devices = (CPU(),) const rtol_lambdipole = 1e-2 # tolerance for lamb dipole tests const rtol_multilayerqg = 1e-13 # tolerance for multilayerqg forcing tests const rtol_twodturb = 1e-13 # tolerance for twodturb forcing tests +const rtol_barotropicQG = 1e-13 # tolerance for twodturb forcing tests "Get the CFL number, assuming a uniform grid with `dx=dy`." cfl(u, v, dt, dx) = maximum([maximum(abs.(u)), maximum(abs.(v))]*dt/dx) @@ -54,31 +55,31 @@ for dev in devices @test TwoDTurb.nothingfunction() == nothing end + @testset "BarotropicQG" begin + include("test_barotropicqg.jl") + + @test test_bqg_rossbywave("ETDRK4", 1e-2, 20, dev) + @test test_bqg_rossbywave("FilteredETDRK4", 1e-2, 20, dev) + @test test_bqg_rossbywave("RK4", 1e-2, 20, dev) + @test test_bqg_rossbywave("FilteredRK4", 1e-2, 20, dev) + @test test_bqg_rossbywave("AB3", 1e-3, 200, dev) + @test test_bqg_rossbywave("FilteredAB3", 1e-3, 200, dev) + @test test_bqg_rossbywave("ForwardEuler", 1e-4, 2000, dev) + @test test_bqg_rossbywave("FilteredForwardEuler", 1e-4, 2000, dev) + @test test_bqg_stochasticforcingbudgets(dev) + @test test_bqg_deterministicforcingbudgets(dev) + @test test_bqg_advection(0.0005, "ForwardEuler", dev) + @test test_bqg_formstress(0.01, "ForwardEuler", dev) + @test test_bqg_energyenstrophy(dev) + @test test_bqg_meanenergyenstrophy(dev) + @test BarotropicQG.nothingfunction() == nothing + end + end println("rest of tests only on CPU") -@testset "BarotropicQG" begin - include("test_barotropicqg.jl") - - @test test_bqg_rossbywave("ETDRK4", 1e-2, 20) - @test test_bqg_rossbywave("FilteredETDRK4", 1e-2, 20) - @test test_bqg_rossbywave("RK4", 1e-2, 20) - @test test_bqg_rossbywave("FilteredRK4", 1e-2, 20) - @test test_bqg_rossbywave("AB3", 1e-3, 200) - @test test_bqg_rossbywave("FilteredAB3", 1e-3, 200) - @test test_bqg_rossbywave("ForwardEuler", 1e-4, 2000) - @test test_bqg_rossbywave("FilteredForwardEuler", 1e-4, 2000) - @test test_bqg_stochasticforcingbudgets() - @test test_bqg_deterministicforcingbudgets() - @test test_bqg_advection(0.0005, "ForwardEuler") - @test test_bqg_formstress(0.01, "ForwardEuler") - @test test_bqg_energyenstrophy() - @test test_bqg_meanenergyenstrophy() - @test BarotropicQG.nothingfunction() == nothing -end - @testset "BarotropicQGQL" begin include("test_barotropicqgql.jl") diff --git a/test/test_barotropicqg.jl b/test/test_barotropicqg.jl index c51da18e..d3ec7a39 100644 --- a/test/test_barotropicqg.jl +++ b/test/test_barotropicqg.jl @@ -3,25 +3,23 @@ Evolves a Rossby wave and compares with the analytic solution. """ -function test_bqg_rossbywave(stepper, dt, nsteps) +function test_bqg_rossbywave(stepper, dt, nsteps, dev::Device=CPU()) nx = 64 - beta = 2.0 Lx = 2π - μ = 0.0 - ν = 0.0 - - gr = TwoDGrid(nx, Lx) - x, y = gridpoints(gr) + β = 2.0 + μ = 0.0 + ν = 0.0 + T = Float64 # the following if statement is called so that all the cases of # Problem() fuction are tested if stepper=="ForwardEuler" - eta = zeros(nx, nx) + eta = zeros(dev, T, (nx, nx)) else eta(x, y) = 0*x end - prob = BarotropicQG.InitialValueProblem(nx=nx, Lx=Lx, eta=eta, beta=beta, μ=μ, ν=ν, stepper=stepper, dt=dt) + prob = BarotropicQG.Problem(nx=nx, Lx=Lx, eta=eta, β=β, μ=μ, ν=ν, stepper=stepper, dt=dt, dev=dev) sol, cl, v, p, g = prob.sol, prob.clock, prob.vars, prob.params, prob.grid x, y = gridpoints(g) @@ -30,7 +28,7 @@ function test_bqg_rossbywave(stepper, dt, nsteps) ampl = 1e-2 kwave = 3.0*2π/g.Lx lwave = 2.0*2π/g.Ly - ω = -p.beta*kwave/(kwave^2.0 + lwave^2.0) + ω = -p.β*kwave/(kwave^2.0 + lwave^2.0) ζ0 = @. ampl*cos(kwave*x)*cos(lwave*y) ζ0h = rfft(ζ0) @@ -50,24 +48,23 @@ end Tests if the energy budgets are closed for BarotropicQG with stochastic forcing. """ -function test_bqg_stochasticforcingbudgets(; n=256, dt=0.01, L=2π, ν=1e-7, nν=2, μ=1e-1, message=false) +function test_bqg_stochasticforcingbudgets(dev::Device=CPU(); n=256, dt=0.01, L=2π, ν=1e-7, nν=2, μ=1e-1, T=Float64) n, L = 256, 2π ν, nν = 1e-7, 2 μ = 1e-1 dt, tf = 0.005, 0.1/μ nt = round(Int, tf/dt) - ns = 1 - + # Forcing kf, dkf = 12.0, 2.0 ε = 0.1 - gr = TwoDGrid(n, L) + gr = TwoDGrid(dev, n, L) x, y = gridpoints(gr) - Kr = [ gr.kr[i] for i=1:gr.nkr, j=1:gr.nl] + Kr = ArrayType(dev)([ gr.kr[i] for i=1:gr.nkr, j=1:gr.nl]) - force2k = zero(gr.Krsq) + force2k = zeros(dev, T, (gr.nkr, gr.nl)) @. force2k = exp.(-(sqrt(gr.Krsq)-kf)^2/(2*dkf^2)) @. force2k[gr.Krsq .< 2.0^2 ] = 0 @. force2k[gr.Krsq .> 20.0^2 ] = 0 @@ -78,14 +75,14 @@ function test_bqg_stochasticforcingbudgets(; n=256, dt=0.01, L=2π, ν=1e-7, nν Random.seed!(1234) function calcFq!(Fqh, sol, t, cl, v, p, g) - eta = exp.(2π*im*rand(Float64, size(sol)))/sqrt(cl.dt) + eta = ArrayType(dev)(exp.(2π*im*rand(T, size(sol)))/sqrt(cl.dt)) eta[1, 1] = 0 @. Fqh = eta * sqrt(force2k) nothing end - prob = BarotropicQG.ForcedProblem(nx=n, Lx=L, ν=ν, nν=nν, μ=μ, dt=dt, - stepper="RK4", calcFq=calcFq!, stochastic=true) + prob = BarotropicQG.Problem(nx=n, Lx=L, ν=ν, nν=nν, μ=μ, dt=dt, + stepper="RK4", calcFq=calcFq!, stochastic=true, dev=dev) sol, cl, v, p, g = prob.sol, prob.clock, prob.vars, prob.params, prob.grid @@ -102,8 +99,6 @@ function test_bqg_stochasticforcingbudgets(; n=256, dt=0.01, L=2π, ν=1e-7, nν BarotropicQG.updatevars!(prob) - cfl = cl.dt*maximum([maximum(v.v)/g.dx, maximum(v.u)/g.dy]) - E, D, W, R = diags t = round(μ*cl.t, digits=2) @@ -121,10 +116,6 @@ function test_bqg_stochasticforcingbudgets(; n=256, dt=0.01, L=2π, ν=1e-7, nν residual = dEdt - total - if message - println("step: %04d, t: %.1f, cfl: %.3f, time: %.2f s\n", cl.step, cl.t, cfl, t) - end - # println(mean(abs.(residual))) isapprox(mean(abs.(residual)), 0, atol=1e-4) end @@ -133,29 +124,27 @@ end Tests if the energy budgets are closed for BarotropicQG with stochastic forcing. """ -function test_bqg_deterministicforcingbudgets(; n=256, dt=0.01, L=2π, ν=1e-7, nν=2, μ=1e-1, message=false) +function test_bqg_deterministicforcingbudgets(dev::Device=CPU(); n=256, dt=0.01, L=2π, ν=1e-7, nν=2, μ=1e-1) n, L = 256, 2π ν, nν = 1e-7, 2 μ = 1e-1 dt, tf = 0.005, 0.1/μ nt = round(Int, tf/dt) - ns = 1 - - # Forcing = 0.01cos(4x)cos(5y)cos(2t) - gr = TwoDGrid(n, L) + gr = TwoDGrid(dev, n, L) x, y = gridpoints(gr) k0, l0 = gr.kr[2], gr.l[2] - f = @. 0.01*cos(4*k0*x)*cos(5*l0*y) + # Forcing = 0.01cos(4x)cos(5y)cos(2t) + f = @. 0.01*cos(4k0*x)*cos(5l0*y) fh = rfft(f) function calcFq!(Fqh, sol, t, cl, v, p, g) - @. Fqh = fh*cos(2*t) + Fqh = fh*cos(2t) nothing end - prob = BarotropicQG.ForcedProblem(nx=n, Lx=L, ν=ν, nν=nν, μ=μ, dt=dt, - stepper="RK4", calcFq=calcFq!, stochastic=false) + prob = BarotropicQG.Problem(nx=n, Lx=L, ν=ν, nν=nν, μ=μ, dt=dt, + stepper="RK4", calcFq=calcFq!, stochastic=false, dev=dev) sol, cl, v, p, g = prob.sol, prob.clock, prob.vars, prob.params, prob.grid @@ -188,10 +177,6 @@ function test_bqg_deterministicforcingbudgets(; n=256, dt=0.01, L=2π, ν=1e-7, residual = dEdt - total - if message - println("step: %04d, t: %.1f, cfl: %.3f, time: %.2f s\n", prob.step, cl.t, cfl, tc) - end - # println(mean(abs.(residual))) isapprox(mean(abs.(residual)), 0, atol=1e-8) end @@ -202,22 +187,22 @@ Tests the advection term in the twodturb module by timestepping a test problem with timestep dt and timestepper identified by the string stepper. The test problem is derived by picking a solution ζf (with associated streamfunction ψf) for which the advection term J(ψf, ζf) is non-zero. Next, a -forcing Ff is derived according to Ff = ∂ζf/∂t + J(ψf, ζf) - νΔζf. One solution +forcing Ff is derived according to Ff = ∂ζf/∂t + J(ψf, ζf) - ν∇²ζf. One solution to the vorticity equation forced by this Ff is then ζf. (This solution may not be realized, at least at long times, if it is unstable.) """ -function test_bqg_advection(dt, stepper; n=128, L=2π, ν=1e-2, nν=1, μ=0.0, message=false) +function test_bqg_advection(dt, stepper, dev::Device=CPU(); n=128, L=2π, ν=1e-2, nν=1, μ=0.0) n, L = 128, 2π ν, nν = 1e-2, 1 μ = 0.0 tf = 1.0 nt = round(Int, tf/dt) - gr = TwoDGrid(n, L) + gr = TwoDGrid(dev, n, L) x, y = gridpoints(gr) psif = @. sin(2x)*cos(2y) + 2sin(x)*cos(3y) - qf = @. -8sin(2x)*cos(2y) - 20sin(x)*cos(3y) + qf = @. -8sin(2x)*cos(2y) - 20sin(x)*cos(3y) Ff = @. -( ν*( 64sin(2x)*cos(2y) + 200sin(x)*cos(3y) ) @@ -232,14 +217,15 @@ function test_bqg_advection(dt, stepper; n=128, L=2π, ν=1e-2, nν=1, μ=0.0, m nothing end - prob = BarotropicQG.ForcedProblem(nx=n, Lx=L, ν=ν, nν=nν, μ=μ, dt=dt, stepper=stepper, calcFq=calcFq!) + prob = BarotropicQG.Problem(nx=n, Lx=L, ν=ν, nν=nν, μ=μ, dt=dt, stepper=stepper, calcFq=calcFq!, dev=dev) sol, cl, v, p, g = prob.sol, prob.clock, prob.vars, prob.params, prob.grid BarotropicQG.set_zeta!(prob, qf) # Step forward stepforward!(prob, round(Int, nt)) BarotropicQG.updatevars!(prob) - isapprox(v.q, qf, rtol=1e-13) + + isapprox(v.q, qf, rtol=rtol_barotropicQG) end """ @@ -247,35 +233,35 @@ end Tests the form stress term that forces the domain-averaged zonal flow U(t). """ -function test_bqg_formstress(dt, stepper; n=128, L=2π, ν=0.0, nν=1, μ=0.0, message=false) +function test_bqg_formstress(dt, stepper, dev::Device=CPU(); n=128, L=2π, ν=0.0, nν=1, μ=0.0) n, L = 128, 2π ν, nν = 1e-2, 1 μ = 0.0 tf = 1 nt = 1 - gr = TwoDGrid(n, L) + gr = TwoDGrid(dev, n, L) x, y = gridpoints(gr) - zetai = @. -20*sin(10*x)*cos(10*y) + zetai = @. -20*sin(10x)*cos(10y) topoPV(x, y) = @. cos(10x)*cos(10y) F(t) = 0 #no forcing answer = 0.25 # this is what should be - prob = BarotropicQG.ForcedProblem(nx=n, Lx=L, ν=ν, nν=nν, μ=μ, dt=dt, stepper=stepper, eta=topoPV, calcFU = F) + prob = BarotropicQG.Problem(nx=n, Lx=L, ν=ν, nν=nν, μ=μ, dt=dt, stepper=stepper, eta=topoPV, calcFU=F, dev=dev) BarotropicQG.set_zeta!(prob, zetai) BarotropicQG.updatevars!(prob) # Step forward stepforward!(prob, nt) - isapprox(prob.timestepper.N[1, 1], answer, rtol=1e-13) + isapprox(prob.timestepper.N[1, 1], answer, rtol=rtol_barotropicQG) end -function test_bqg_energyenstrophy() +function test_bqg_energyenstrophy(dev::Device=CPU()) nx, Lx = 64, 2π ny, Ly = 64, 3π - g = TwoDGrid(nx, Lx, ny, Ly) + g = TwoDGrid(dev, nx, Lx, ny, Ly) k0, l0 = g.k[2], g.l[2] # fundamental wavenumbers x, y = gridpoints(g) @@ -286,7 +272,7 @@ function test_bqg_energyenstrophy() 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 = BarotropicQG.InitialValueProblem(nx=nx, Lx=Lx, ny=ny, Ly=Ly, eta = eta, stepper="ForwardEuler") + prob = BarotropicQG.Problem(nx=nx, Lx=Lx, ny=ny, Ly=Ly, eta = eta, stepper="ForwardEuler", dev=dev) sol, cl, v, p, g = prob.sol, prob.clock, prob.vars, prob.params, prob.grid BarotropicQG.set_zeta!(prob, zeta0) BarotropicQG.updatevars!(prob) @@ -294,14 +280,14 @@ 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=rtol_barotropicQG) && isapprox(enstrophyzeta0, enstrophy_calc, rtol=rtol_barotropicQG) && BarotropicQG.addforcing!(prob.timestepper.N, sol, cl.t, cl, v, p, g)==nothing end -function test_bqg_meanenergyenstrophy() +function test_bqg_meanenergyenstrophy(dev::Device=CPU()) nx, Lx = 64, 2π ny, Ly = 96, 3π - g = TwoDGrid(nx, Lx, ny, Ly) + g = TwoDGrid(dev, nx, Lx, ny, Ly) k0, l0 = g.k[2], g.l[2] # fundamental wavenumbers x, y = gridpoints(g) @@ -309,14 +295,14 @@ function test_bqg_meanenergyenstrophy() eta(x, y) = @. cos(10x)*cos(10y) 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) - beta = 10.0 + β = 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") + prob = BarotropicQG.Problem(nx=nx, Lx=Lx, ny=ny, Ly=Ly, β=β, eta=eta, calcFU = calcFU, + stepper="ForwardEuler", dev=dev) BarotropicQG.set_zeta!(prob, zeta0) BarotropicQG.set_U!(prob, U) @@ -328,9 +314,9 @@ function test_bqg_meanenergyenstrophy() energyzeta0 = BarotropicQG.energy(prob) enstrophyzeta0 = BarotropicQG.enstrophy(prob) - (isapprox(energyU, 0.5*U^2, rtol=1e-13) && - isapprox(enstrophyU, beta*U, rtol=1e-13) && - isapprox(energyzeta0, energy_calc, rtol=1e-13) && - isapprox(enstrophyzeta0, enstrophy_calc, rtol=1e-13) + (isapprox(energyU, 0.5*U^2, rtol=rtol_barotropicQG) && + isapprox(enstrophyU, β*U, rtol=rtol_barotropicQG) && + isapprox(energyzeta0, energy_calc, rtol=rtol_barotropicQG) && + isapprox(enstrophyzeta0, enstrophy_calc, rtol=rtol_barotropicQG) ) end diff --git a/test/test_twodturb.jl b/test/test_twodturb.jl index 8a7918e5..c639b8d9 100644 --- a/test/test_twodturb.jl +++ b/test/test_twodturb.jl @@ -140,7 +140,7 @@ Tests the advection term in the twodturb module by timestepping a test problem with timestep dt and timestepper identified by the string stepper. The test problem is derived by picking a solution ζf (with associated streamfunction ψf) for which the advection term J(ψf, ζf) is non-zero. Next, a -forcing Ff is derived according to Ff = ∂ζf/∂t + J(ψf, ζf) - νΔζf. One solution +forcing Ff is derived according to Ff = ∂ζf/∂t + J(ψf, ζf) - ν∇²ζf. One solution to the vorticity equation forced by this Ff is then ζf. (This solution may not be realized, at least at long times, if it is unstable.) """ @@ -151,7 +151,7 @@ function test_twodturb_advection(dt, stepper, dev::Device=CPU(); n=128, L=2π, tf = 1.0 nt = round(Int, tf/dt) - gr = TwoDGrid(dev, n, L) + gr = TwoDGrid(dev, n, L) x, y = gridpoints(gr) psif = @. sin(2x)*cos(2y) + 2sin(x)*cos(3y) From eb797ca434dd91344408981da9e5c2366b1a34a2 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Thu, 2 Jan 2020 11:02:19 +1100 Subject: [PATCH 04/11] removes Manifest.toml --- Manifest.toml | 390 -------------------------------------------------- 1 file changed, 390 deletions(-) delete mode 100644 Manifest.toml diff --git a/Manifest.toml b/Manifest.toml deleted file mode 100644 index a4a68be2..00000000 --- a/Manifest.toml +++ /dev/null @@ -1,390 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -[[AbstractFFTs]] -deps = ["LinearAlgebra"] -git-tree-sha1 = "380e36c66edfa099cd90116b24c1ce8cafccac40" -uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" -version = "0.4.1" - -[[Adapt]] -deps = ["LinearAlgebra"] -git-tree-sha1 = "82dab828020b872fa9efd3abec1152b075bc7cbf" -uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" -version = "1.0.0" - -[[AxisAlgorithms]] -deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"] -git-tree-sha1 = "a4d07a1c313392a77042855df46c5f534076fab9" -uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" -version = "1.0.0" - -[[Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" - -[[BinDeps]] -deps = ["Compat", "Libdl", "SHA", "URIParser"] -git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9" -uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee" -version = "0.8.10" - -[[BinaryProvider]] -deps = ["Libdl", "Logging", "SHA"] -git-tree-sha1 = "c7361ce8a2129f20b0e05a89f7070820cfed6648" -uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" -version = "0.5.6" - -[[CEnum]] -git-tree-sha1 = "62847acab40e6855a9b5905ccb99c2b5cf6b3ebb" -uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82" -version = "0.2.0" - -[[CSTParser]] -deps = ["Tokenize"] -git-tree-sha1 = "c69698c3d4a7255bc1b4bc2afc09f59db910243b" -uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f" -version = "0.6.2" - -[[CUDAapi]] -deps = ["Libdl", "Logging"] -git-tree-sha1 = "9b2b4b71d6b7f946c9689bb4dea03ff92e3c7091" -uuid = "3895d2a7-ec45-59b8-82bb-cfc6a382f9b3" -version = "1.1.0" - -[[CUDAdrv]] -deps = ["CUDAapi", "Libdl", "Printf"] -git-tree-sha1 = "9ce99b5732c70e06ed97c042187baed876fb1698" -uuid = "c5f51814-7f29-56b8-a69c-e4d8f6be1fde" -version = "3.1.0" - -[[CUDAnative]] -deps = ["Adapt", "CUDAapi", "CUDAdrv", "DataStructures", "InteractiveUtils", "LLVM", "Libdl", "Logging", "Printf", "TimerOutputs"] -git-tree-sha1 = "52ae1ce10ebfa686e227655c47b19add89308623" -uuid = "be33ccc6-a3ff-5ff2-a52e-74243cff1e17" -version = "2.3.1" - -[[CodecZlib]] -deps = ["BinaryProvider", "Libdl", "TranscodingStreams"] -git-tree-sha1 = "05916673a2627dd91b4969ff8ba6941bc85a960e" -uuid = "944b1d66-785c-5afd-91f1-9de20f533193" -version = "0.6.0" - -[[ColorTypes]] -deps = ["FixedPointNumbers", "Random"] -git-tree-sha1 = "10050a24b09e8e41b951e9976b109871ce98d965" -uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" -version = "0.8.0" - -[[Colors]] -deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport"] -git-tree-sha1 = "c9c1845d6bf22e34738bee65c357a69f416ed5d1" -uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" -version = "0.9.6" - -[[Compat]] -deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] -git-tree-sha1 = "84aa74986c5b9b898b0d1acaf3258741ee64754f" -uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "2.1.0" - -[[Conda]] -deps = ["JSON", "VersionParsing"] -git-tree-sha1 = "9a11d428dcdc425072af4aea19ab1e8c3e01c032" -uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d" -version = "1.3.0" - -[[Coverage]] -deps = ["HTTP", "JSON", "LibGit2", "MbedTLS"] -git-tree-sha1 = "f9780daf3fea51ad2d7b7ed4f480ac34ab36587f" -uuid = "a2441757-f6aa-5fb2-8edb-039e3f45d037" -version = "0.9.2" - -[[Crayons]] -deps = ["Test"] -git-tree-sha1 = "f621b8ef51fd2004c7cf157ea47f027fdeac5523" -uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f" -version = "4.0.0" - -[[CuArrays]] -deps = ["AbstractFFTs", "Adapt", "CUDAapi", "CUDAdrv", "CUDAnative", "GPUArrays", "LinearAlgebra", "MacroTools", "NNlib", "Printf", "Random", "Requires", "SparseArrays", "TimerOutputs"] -git-tree-sha1 = "46b48742a84bb839e74215b7e468a4a1c6ba30f9" -uuid = "3a865a2d-5b23-5a0f-bc46-62713ec82fae" -version = "1.2.1" - -[[DataStructures]] -deps = ["InteractiveUtils", "OrderedCollections"] -git-tree-sha1 = "0809951a1774dc724da22d26e4289bbaab77809a" -uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.17.0" - -[[Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[DelimitedFiles]] -deps = ["Mmap"] -uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" - -[[Distributed]] -deps = ["Random", "Serialization", "Sockets"] -uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" - -[[FFTW]] -deps = ["AbstractFFTs", "BinaryProvider", "Conda", "Libdl", "LinearAlgebra", "Reexport", "Test"] -git-tree-sha1 = "e1a479d3c972f20c9a70563eec740bbfc786f515" -uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" -version = "0.3.0" - -[[FileIO]] -deps = ["Pkg"] -git-tree-sha1 = "351f001a78aa1b7ad2696e386e110b5abd071c71" -uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" -version = "1.0.7" - -[[FillArrays]] -deps = ["LinearAlgebra", "Random", "SparseArrays"] -git-tree-sha1 = "8fba6ddaf66b45dec830233cea0aae43eb1261ad" -uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "0.6.4" - -[[FixedPointNumbers]] -git-tree-sha1 = "d14a6fa5890ea3a7e5dcab6811114f132fec2b4b" -uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" -version = "0.6.1" - -[[FourierFlows]] -deps = ["CUDAapi", "Coverage", "CuArrays", "FFTW", "Interpolations", "JLD2", "LinearAlgebra", "Printf", "Random", "Reexport", "Requires", "Statistics"] -git-tree-sha1 = "153b295514c016e30b300b9e65b0615061976166" -uuid = "2aec4490-903f-5c70-9b11-9bed06a700e1" -version = "0.3.2" - -[[GPUArrays]] -deps = ["Adapt", "FFTW", "FillArrays", "LinearAlgebra", "Printf", "Random", "Serialization", "StaticArrays", "Test"] -git-tree-sha1 = "b5009ac44b141ded5e6f04c4db83807970f56e91" -uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7" -version = "1.0.2" - -[[HTTP]] -deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"] -git-tree-sha1 = "f1e1b417a34cf73a70cbed919915bf8f8bad1806" -uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" -version = "0.8.6" - -[[IniFile]] -deps = ["Test"] -git-tree-sha1 = "098e4d2c533924c921f9f9847274f2ad89e018b8" -uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f" -version = "0.5.0" - -[[InteractiveUtils]] -deps = ["Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" - -[[Interpolations]] -deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "WoodburyMatrices"] -git-tree-sha1 = "e1bac96b5ef3ea23b50e801b4a988ec21861a47f" -uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" -version = "0.12.2" - -[[JLD2]] -deps = ["CodecZlib", "DataStructures", "FileIO", "LinearAlgebra", "Mmap", "Printf", "Random", "Test"] -git-tree-sha1 = "3ba90ff93e1d5b9b2103588051c2d349fae54dac" -uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819" -version = "0.1.2" - -[[JSON]] -deps = ["Dates", "Mmap", "Parsers", "Unicode"] -git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" -uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -version = "0.21.0" - -[[LLVM]] -deps = ["CEnum", "Libdl", "Printf", "Unicode"] -git-tree-sha1 = "4a05f742837779a00bd8c9a18da6817367c4245d" -uuid = "929cbde3-209d-540e-8aea-75f648917ca0" -version = "1.3.0" - -[[LaTeXStrings]] -deps = ["Compat"] -git-tree-sha1 = "7ab9b8788cfab2bdde22adf9004bda7ad9954b6c" -uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" -version = "1.0.3" - -[[LibGit2]] -uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" - -[[Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[LinearAlgebra]] -deps = ["Libdl"] -uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[[Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" - -[[MacroTools]] -deps = ["CSTParser", "Compat", "DataStructures", "Test", "Tokenize"] -git-tree-sha1 = "d6e9dedb8c92c3465575442da456aec15a89ff76" -uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" -version = "0.5.1" - -[[Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" - -[[MbedTLS]] -deps = ["BinaryProvider", "Dates", "Libdl", "Random", "Sockets"] -git-tree-sha1 = "85f5947b53c8cfd53ccfa3f4abae31faa22c2181" -uuid = "739be429-bea8-5141-9913-cc70e7f3736d" -version = "0.7.0" - -[[Mmap]] -uuid = "a63ad114-7e13-5084-954f-fe012c677804" - -[[NNlib]] -deps = ["Libdl", "LinearAlgebra", "Requires", "Statistics", "TimerOutputs"] -git-tree-sha1 = "0c667371391fc6bb31f7f12f96a56a17098b3de8" -uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" -version = "0.6.0" - -[[OffsetArrays]] -git-tree-sha1 = "1af2f79c7eaac3e019a0de41ef63335ff26a0a57" -uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" -version = "0.11.1" - -[[OrderedCollections]] -deps = ["Random", "Serialization", "Test"] -git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1" -uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.1.0" - -[[Parsers]] -deps = ["Dates", "Test"] -git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b" -uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "0.3.7" - -[[Pkg]] -deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] -uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" - -[[Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[PyCall]] -deps = ["Conda", "Dates", "Libdl", "LinearAlgebra", "MacroTools", "Pkg", "Serialization", "Statistics", "Test", "VersionParsing"] -git-tree-sha1 = "6e5bac1b1faf3575731a6a5b76f638f2389561d3" -uuid = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" -version = "1.91.2" - -[[PyPlot]] -deps = ["Colors", "LaTeXStrings", "PyCall", "Sockets", "Test", "VersionParsing"] -git-tree-sha1 = "3ea391c3211f799df20396d256cee5c8bd755605" -uuid = "d330b81b-6aea-500a-939a-2ce795aea3ee" -version = "2.8.1" - -[[REPL]] -deps = ["InteractiveUtils", "Markdown", "Sockets"] -uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" - -[[Random]] -deps = ["Serialization"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" - -[[Ratios]] -deps = ["Compat"] -git-tree-sha1 = "cdbbe0f350581296f3a2e3e7a91b214121934407" -uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" -version = "0.3.1" - -[[Reexport]] -deps = ["Pkg"] -git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" -uuid = "189a3867-3050-52da-a836-e630ba90ab69" -version = "0.2.0" - -[[Requires]] -deps = ["Test"] -git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" -uuid = "ae029012-a4dd-5104-9daa-d747884805df" -version = "0.5.2" - -[[SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" - -[[Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" - -[[SharedArrays]] -deps = ["Distributed", "Mmap", "Random", "Serialization"] -uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" - -[[Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" - -[[SparseArrays]] -deps = ["LinearAlgebra", "Random"] -uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" - -[[SpecialFunctions]] -deps = ["BinDeps", "BinaryProvider", "Libdl"] -git-tree-sha1 = "3bdd374b6fd78faf0119b8c5d538788dbf910c6e" -uuid = "276daf66-3868-5448-9aa4-cd146d93841b" -version = "0.8.0" - -[[StaticArrays]] -deps = ["LinearAlgebra", "Random", "Statistics"] -git-tree-sha1 = "db23bbf50064c582b6f2b9b043c8e7e98ea8c0c6" -uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "0.11.0" - -[[Statistics]] -deps = ["LinearAlgebra", "SparseArrays"] -uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[[Test]] -deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] -uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[[TimerOutputs]] -deps = ["Crayons", "Printf", "Test", "Unicode"] -git-tree-sha1 = "b80671c06f8f8bae08c55d67b5ce292c5ae2660c" -uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" -version = "0.5.0" - -[[Tokenize]] -git-tree-sha1 = "dfcdbbfb2d0370716c815cbd6f8a364efb6f42cf" -uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624" -version = "0.5.6" - -[[TranscodingStreams]] -deps = ["Random", "Test"] -git-tree-sha1 = "7c53c35547de1c5b9d46a4797cf6d8253807108c" -uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" -version = "0.9.5" - -[[URIParser]] -deps = ["Test", "Unicode"] -git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" -uuid = "30578b45-9adc-5946-b283-645ec420af67" -version = "0.4.0" - -[[UUIDs]] -deps = ["Random", "SHA"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" - -[[Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[VersionParsing]] -deps = ["Compat"] -git-tree-sha1 = "c9d5aa108588b978bd859554660c8a5c4f2f7669" -uuid = "81def892-9a0e-5fdd-b105-ffc91e053289" -version = "1.1.3" - -[[WoodburyMatrices]] -deps = ["LinearAlgebra", "Random", "SparseArrays", "Test"] -git-tree-sha1 = "21772c33b447757ec7d3e61fcdfb9ea5c47eedcf" -uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" -version = "0.4.1" From 7b96ce7939c54f0d07298057af9c73407499a2a3 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Thu, 2 Jan 2020 12:39:12 +1100 Subject: [PATCH 05/11] adds Manifest.toml in gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 73d89e6a..1d59ed83 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,9 @@ **/*.pdf **/.nfs* **/*.cov +**/Manifest.toml docs/build/ docs/site/ coverage/ -docs/Manifest.toml + From b0f1b1df72d74dc1d6461919f8ad12d0431643de Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Thu, 2 Jan 2020 12:42:06 +1100 Subject: [PATCH 06/11] fixes bug related with CuArrays.jl update typeof(array) != ArrayType(dev, T, 2) was too strict since this was true even when array was a CuArray; changed to !(typeof(array)<:ArrayType(dev)) --- src/barotropicqg.jl | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/barotropicqg.jl b/src/barotropicqg.jl index 2f2af098..c01166dc 100644 --- a/src/barotropicqg.jl +++ b/src/barotropicqg.jl @@ -60,29 +60,19 @@ function Problem(; # topographic PV if eta==nothing - eta = ArrayType(dev)(0*x) + eta = zeros(dev, T, (nx, ny)) end - if typeof(eta)!=ArrayType(dev, T, 2) #this is true if eta was passes in Problem as a function - pr = Params(gr, f0, β, eta, μ, ν, nν, calcFU, calcFq) - else - pr = Params(f0, β, eta, rfft(eta), μ, ν, nν, calcFU, calcFq) - end + pr = !(typeof(eta)<:ArrayType(dev)) ? Params(gr, f0, β, eta, μ, ν, nν, calcFU, calcFq) : Params(f0, β, eta, rfft(eta), μ, ν, nν, calcFU, calcFq) - if calcFq == nothingfunction && calcFU == nothingfunction - vs = Vars(dev, gr) - else - if stochastic == false - vs = ForcedVars(dev, gr) - elseif stochastic == true - vs = StochasticForcedVars(dev, gr) - end - end + vs = (calcFq == nothingfunction && calcFU == nothingfunction) ? Vars(dev, gr) : (stochastic ? StochasticForcedVars(dev, gr) : ForcedVars(dev, gr)) + eq = Equation(pr, gr) FourierFlows.Problem(eq, stepper, dt, gr, vs, pr, dev) end + # ---------- # Parameters # ---------- @@ -110,7 +100,7 @@ end Constructor for Params that accepts a generating function for the topographic PV. """ -function Params(g::AbstractGrid{T, A}, f0, β, eta::Function, μ, ν, nν, calcFU, calcFq) where {T, A} +function Params(g::AbstractGrid{T, A}, f0, β, eta::Function, μ, ν, nν::Int, calcFU, calcFq) where {T, A} etagrid = A([eta(g.x[i], g.y[j]) for i=1:g.nx, j=1:g.ny]) etah = rfft(etagrid) Params(f0, β, etagrid, etah, μ, ν, nν, calcFU, calcFq) From c6d861076a0147980f8efbcaeb4f8296e94da571 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Thu, 2 Jan 2020 13:19:36 +1100 Subject: [PATCH 07/11] restricts FFTW up to v1.1 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 29deccfe..059d134c 100644 --- a/Project.toml +++ b/Project.toml @@ -19,7 +19,7 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] -FFTW = "≥ 0.2.4" +FFTW = "< 1.2" FourierFlows = "≥ 0.3.2" JLD2 = "≥ 0.1.2" julia = "≥ 1.0.0" From 1a2cf000a58ef002f1074663928a789d7e7cf9fb Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Fri, 3 Jan 2020 17:03:25 +1100 Subject: [PATCH 08/11] removes FFTW compat restriction --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 059d134c..29deccfe 100644 --- a/Project.toml +++ b/Project.toml @@ -19,7 +19,7 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] -FFTW = "< 1.2" +FFTW = "≥ 0.2.4" FourierFlows = "≥ 0.3.2" JLD2 = "≥ 0.1.2" julia = "≥ 1.0.0" From 7d9ad6bfc3e637eda25360c1a70c6dce51274e27 Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Fri, 10 Jan 2020 10:50:25 +1100 Subject: [PATCH 09/11] removes coverage from .travis and updates gitlab-ci to template v6 --- .gitlab-ci.yml | 62 +++++++++++++++++++++++++++++++------------------- .travis.yml | 10 ++++---- Project.toml | 6 ++--- 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7d101274..fcd146a2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,35 +1,51 @@ variables: CI_IMAGE_TAG: 'cuda' JULIA_NUM_THREADS: '4' + JULIA_CUDA_VERBOSE: 'true' # See: https://github.com/JuliaGPU/gitlab-ci include: - - 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v5/test.yml' - - 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v5/coverage.yml' + - 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v6.yml' -test:v1.2: - extends: .test:v1.2 +image: nvidia/cuda:10.1-cudnn7-devel -test:v1.3: - extends: .test:v1.3 - allow_failure: true +julia:1.0: + extends: + - .julia:1.0 + - .test + tags: + - nvidia -test:dev: - extends: .test:dev - allow_failure: true +julia:1.1: + extends: + - .julia:1.1 + - .test + tags: + - nvidia -coverage: - stage: post - extends: .root +# the "primary" target, where we require a new GPU to make sure all tests are run +julia:1.2: + image: juliagpu/cuda:10.1-cudnn7-cutensor1-devel-ubuntu18.04 + extends: + - .julia:1.2 + - .test + tags: + - nvidia + - sm_75 variables: - CI_VERSION_TAG: 'v1.2' - script: - - julia --project -e 'using Pkg; - Pkg.add("Coverage")' - - julia --project -e 'using Coverage; - cl, tl = get_summary(process_folder()); - println("(", cl/tl*100, "%) covered"); - Codecov.submit_local(Codecov.process_folder(), ".")' - coverage: '/\(\d+.\d+\%\) covered/' + CI_THOROUGH: 'true' + +julia:1.3: + extends: + - .julia:1.3 + - .test + tags: + - nvidia allow_failure: true - + + +# other tasks +coverage: + extends: + - .julia:1.2 + - .coverage \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index c08c9cab..058ed2f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,21 +5,21 @@ os: - linux julia: - - 1.2 + - 1.3 - nightly matrix: allow_failures: - julia: nightly -after_success: - - julia --project -e 'using Pkg; Pkg.add("Coverage"); import GeophysicalFlows; joinpath(dirname(pathof(GeophysicalFlows)), ".."); using Coverage; Coveralls.submit(Coveralls.process_folder());' - - julia --project -e 'using Pkg; Pkg.add("Coverage"); import GeophysicalFlows; joinpath(dirname(pathof(GeophysicalFlows)), ".."); using Coverage; Codecov.submit(Codecov.process_folder())' +# after_success: +# - julia --project -e 'using Pkg; Pkg.add("Coverage"); import GeophysicalFlows; joinpath(dirname(pathof(GeophysicalFlows)), ".."); using Coverage; Coveralls.submit(Coveralls.process_folder());' +# - julia --project -e 'using Pkg; Pkg.add("Coverage"); import GeophysicalFlows; joinpath(dirname(pathof(GeophysicalFlows)), ".."); using Coverage; Codecov.submit(Codecov.process_folder())' jobs: include: - stage: "Documentation" - julia: 1.2 + julia: 1.3 os: linux script: - julia --project=docs/ -e 'using Pkg; Pkg.instantiate(); diff --git a/Project.toml b/Project.toml index 29deccfe..9db76377 100644 --- a/Project.toml +++ b/Project.toml @@ -5,14 +5,11 @@ authors = ["Navid C. Constantinou ", "Gregory L. Wagner Date: Fri, 10 Jan 2020 10:59:41 +1100 Subject: [PATCH 10/11] fix type instability problem --- src/barotropicqg.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/barotropicqg.jl b/src/barotropicqg.jl index c01166dc..b46dd400 100644 --- a/src/barotropicqg.jl +++ b/src/barotropicqg.jl @@ -55,7 +55,7 @@ function Problem(; dev = CPU()) # the grid - gr = TwoDGrid(dev, nx, Lx, ny, Ly) + gr = TwoDGrid(dev, nx, Lx, ny, Ly; T=T) x, y = gridpoints(gr) # topographic PV From c5d1bd86596695e8b32a2a5523bf5877be7784ca Mon Sep 17 00:00:00 2001 From: Navid Constantinou Date: Fri, 10 Jan 2020 11:21:13 +1100 Subject: [PATCH 11/11] order deps alphabetical --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 9db76377..f8726929 100644 --- a/Project.toml +++ b/Project.toml @@ -22,8 +22,8 @@ JLD2 = "≥ 0.1.2" julia = "≥ 1.0.0" [extras] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Coverage = "a2441757-f6aa-5fb2-8edb-039e3f45d037" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] test = ["Test", "Coverage"]