Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstate DynamicSmagorinsky tests #3926

Merged
merged 10 commits into from
Dec 13, 2024
18 changes: 3 additions & 15 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,14 @@ steps:
##### Turbulence Closures
#####


- label: "🎣 gpu turbulence closures"
env:
JULIA_DEPOT_PATH: "$SVERDRUP_HOME/.julia-$BUILDKITE_BUILD_NUMBER"
TEST_GROUP: "turbulence_closures"
GPU_TEST: "true"
commands:
- "$SVERDRUP_HOME/julia-$JULIA_VERSION/bin/julia -O0 --color=yes --project -e 'using Pkg; Pkg.test()'"
- "$SVERDRUP_HOME/julia-$JULIA_VERSION/bin/julia --color=yes --project -e 'using Pkg; Pkg.test()'"
agents:
queue: Oceananigans
architecture: GPU
Expand All @@ -335,20 +336,7 @@ steps:
limit: 1
depends_on: "init_gpu"

- label: "🎏 cpu turbulence closures"
env:
JULIA_DEPOT_PATH: "$TARTARUS_HOME/.julia-$BUILDKITE_BUILD_NUMBER"
TEST_GROUP: "turbulence_closures"
commands:
- "$TARTARUS_HOME/julia-$JULIA_VERSION/bin/julia -O0 --color=yes --project -e 'using Pkg; Pkg.test()'"
agents:
queue: Oceananigans
architecture: CPU
retry:
automatic:
- exit_status: 1
limit: 1
depends_on: "init_cpu"
# The CPU turbulence closures test used to be here, but was moved to Github Actions. See https://github.com/CliMA/Oceananigans.jl/pull/3926

#####
##### HydrostaticFreeSurfaceModel
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
navidcy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI
on:
- push
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.10'
os:
- ubuntu-latest
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
TEST_GROUP: "turbulence_closures"
112 changes: 54 additions & 58 deletions test/test_turbulence_closures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ function horizontal_diffusivity_fluxdiv(FT=Float64; νh=FT(0.3), κh=FT(0.7), ν

return (∇_dot_qᶜ(2, 1, 3, grid, closureh, K, Val(1), T, closure_args...) == - 8κh &&
∇_dot_qᶜ(2, 1, 3, grid, closurez, K, Val(1), T, closure_args...) == - 10κz &&
∂ⱼ_τ₁ⱼ(2, 1, 3, grid, closureh, K, closure_args...) == - (2νh) &&
∂ⱼ_τ₁ⱼ(2, 1, 3, grid, closurez, K, closure_args...) == - (4νz) &&
∂ⱼ_τ₂ⱼ(2, 1, 3, grid, closureh, K, closure_args...) == - (4νh) &&
∂ⱼ_τ₂ⱼ(2, 1, 3, grid, closurez, K, closure_args...) == - (6νz) &&
∂ⱼ_τ₃ⱼ(2, 1, 3, grid, closureh, K, closure_args...) == - (6νh) &&
∂ⱼ_τ₃ⱼ(2, 1, 3, grid, closurez, K, closure_args...) == - (8νz))
∂ⱼ_τ₁ⱼ(2, 1, 3, grid, closureh, K, closure_args...) == - 2νh &&
∂ⱼ_τ₁ⱼ(2, 1, 3, grid, closurez, K, closure_args...) == - 4νz &&
∂ⱼ_τ₂ⱼ(2, 1, 3, grid, closureh, K, closure_args...) == - 4νh &&
∂ⱼ_τ₂ⱼ(2, 1, 3, grid, closurez, K, closure_args...) == - 6νz &&
∂ⱼ_τ₃ⱼ(2, 1, 3, grid, closureh, K, closure_args...) == - 6νh &&
∂ⱼ_τ₃ⱼ(2, 1, 3, grid, closurez, K, closure_args...) == - 8νz)
end

function time_step_with_variable_isotropic_diffusivity(arch)
Expand All @@ -113,7 +113,6 @@ function time_step_with_variable_isotropic_diffusivity(arch)
κ = (x, y, z, t) -> exp(z) * cos(x) * cos(y) * cos(t))

model = NonhydrostaticModel(; grid, closure)

time_step!(model, 1)
return true
end
Expand Down Expand Up @@ -157,45 +156,6 @@ function time_step_with_variable_discrete_diffusivity(arch)
return true
end

function diffusivity_fields_sizes_are_correct(arch)
grid = RectilinearGrid(arch, size=(2, 3, 4), extent=(1, 2, 3))

closure = Smagorinsky(coefficient=DynamicCoefficient(averaging=1))
model = NonhydrostaticModel(; grid, closure)
@test size(model.diffusivity_fields.𝒥ᴸᴹ) == (1, grid.Ny, grid.Nz)
@test size(model.diffusivity_fields.𝒥ᴹᴹ) == (1, grid.Ny, grid.Nz)
@test size(model.diffusivity_fields.LM) == size(grid)
@test size(model.diffusivity_fields.MM) == size(grid)
@test size(model.diffusivity_fields.Σ) == size(grid)
@test size(model.diffusivity_fields.Σ̄) == size(grid)

closure = DynamicSmagorinsky(averaging=(1, 2))
model = NonhydrostaticModel(; grid, closure)
@test size(model.diffusivity_fields.𝒥ᴸᴹ) == (1, 1, grid.Nz)
@test size(model.diffusivity_fields.𝒥ᴹᴹ) == (1, 1, grid.Nz)

closure = DynamicSmagorinsky(averaging=Colon())
model = NonhydrostaticModel(; grid, closure)
@test size(model.diffusivity_fields.𝒥ᴸᴹ) == (1, 1, 1)
@test size(model.diffusivity_fields.𝒥ᴹᴹ) == (1, 1, 1)

closure = DynamicSmagorinsky(averaging=(2, 3))
model = NonhydrostaticModel(; grid, closure)
@test size(model.diffusivity_fields.𝒥ᴸᴹ) == (grid.Nx, 1, 1)
@test size(model.diffusivity_fields.𝒥ᴹᴹ) == (grid.Nx, 1, 1)

closure = DynamicSmagorinsky(averaging=LagrangianAveraging())
model = NonhydrostaticModel(; grid, closure)
@test size(model.diffusivity_fields.𝒥ᴸᴹ) == size(grid)
@test size(model.diffusivity_fields.𝒥ᴹᴹ) == size(grid)
@test size(model.diffusivity_fields.𝒥ᴸᴹ⁻) == size(grid)
@test size(model.diffusivity_fields.𝒥ᴹᴹ⁻) == size(grid)
@test size(model.diffusivity_fields.Σ) == size(grid)
@test size(model.diffusivity_fields.Σ̄) == size(grid)

return true
end

function time_step_with_tupled_closure(FT, arch)
closure_tuple = (AnisotropicMinimumDissipation(FT), ScalarDiffusivity(FT))

Expand Down Expand Up @@ -274,18 +234,20 @@ function compute_closure_specific_diffusive_cfl(closure)
grid = RectilinearGrid(CPU(), size=(2, 2, 2), extent=(1, 2, 3))

model = NonhydrostaticModel(; grid, closure, buoyancy=BuoyancyTracer(), tracers=:b)
args = (model.closure, model.diffusivity_fields, Val(1), model.tracers.b, model.clock, fields(model), model.buoyancy)
dcfl = DiffusiveCFL(0.1)
@test dcfl(model) isa Number
@test diffusive_flux_x(1, 1, 1, grid, model.closure, model.diffusivity_fields, Val(1), model.tracers.b, model.clock, fields(model), model.buoyancy) == 0
@test diffusive_flux_y(1, 1, 1, grid, model.closure, model.diffusivity_fields, Val(1), model.tracers.b, model.clock, fields(model), model.buoyancy) == 0
@test diffusive_flux_z(1, 1, 1, grid, model.closure, model.diffusivity_fields, Val(1), model.tracers.b, model.clock, fields(model), model.buoyancy) == 0
@test diffusive_flux_x(1, 1, 1, grid, args...) == 0
@test diffusive_flux_y(1, 1, 1, grid, args...) == 0
@test diffusive_flux_z(1, 1, 1, grid, args...) == 0

tracerless_model = NonhydrostaticModel(; grid, closure, buoyancy=nothing, tracers=nothing)
args = (model.closure, model.diffusivity_fields, model.clock, fields(model), model.buoyancy)
dcfl = DiffusiveCFL(0.2)
@test dcfl(tracerless_model) isa Number
@test viscous_flux_ux(1, 1, 1, grid, model.closure, model.diffusivity_fields, model.clock, fields(model), model.buoyancy) == 0
@test viscous_flux_uy(1, 1, 1, grid, model.closure, model.diffusivity_fields, model.clock, fields(model), model.buoyancy) == 0
@test viscous_flux_uz(1, 1, 1, grid, model.closure, model.diffusivity_fields, model.clock, fields(model), model.buoyancy) == 0
@test viscous_flux_ux(1, 1, 1, grid, args...) == 0
@test viscous_flux_uy(1, 1, 1, grid, args...) == 0
@test viscous_flux_uz(1, 1, 1, grid, args...) == 0

return nothing
end
Expand All @@ -294,12 +256,11 @@ end
@info "Testing turbulence closures..."

@testset "Closure instantiation" begin
@info " Testing closure instantiation..."
for closurename in closures
closure = @eval $closurename()
@test closure isa TurbulenceClosures.AbstractTurbulenceClosure

closure isa DynamicSmagorinsky && continue # `DynamicSmagorinsky`s `_compute_LM_MM!()` kernel isn't compiling on buildkite
@info " Testing the instantiation of NonhydrostaticModel with $closurename..."
grid = RectilinearGrid(CPU(), size=(2, 2, 2), extent=(1, 2, 3))
model = NonhydrostaticModel(; grid, closure, tracers=:c)
c = model.tracers.c
Expand Down Expand Up @@ -376,8 +337,40 @@ end
@testset "Dynamic Smagorinsky closures" begin
@info " Testing that dynamic Smagorinsky closures produce diffusivity fields of correct sizes..."
for arch in archs
# `DynamicSmagorinsky`s `_compute_LM_MM!()` kernel isn't compiling on buildkite
@test_skip diffusivity_fields_sizes_are_correct(arch)
grid = RectilinearGrid(arch, size=(2, 3, 4), extent=(1, 2, 3))

closure = Smagorinsky(coefficient=DynamicCoefficient(averaging=1))
model = NonhydrostaticModel(; grid, closure)
@test size(model.diffusivity_fields.𝒥ᴸᴹ) == (1, grid.Ny, grid.Nz)
@test size(model.diffusivity_fields.𝒥ᴹᴹ) == (1, grid.Ny, grid.Nz)
@test size(model.diffusivity_fields.LM) == size(grid)
@test size(model.diffusivity_fields.MM) == size(grid)
@test size(model.diffusivity_fields.Σ) == size(grid)
@test size(model.diffusivity_fields.Σ̄) == size(grid)

closure = DynamicSmagorinsky(averaging=(1, 2))
model = NonhydrostaticModel(; grid, closure)
@test size(model.diffusivity_fields.𝒥ᴸᴹ) == (1, 1, grid.Nz)
@test size(model.diffusivity_fields.𝒥ᴹᴹ) == (1, 1, grid.Nz)

closure = DynamicSmagorinsky(averaging=(2, 3))
model = NonhydrostaticModel(; grid, closure)
@test size(model.diffusivity_fields.𝒥ᴸᴹ) == (grid.Nx, 1, 1)
@test size(model.diffusivity_fields.𝒥ᴹᴹ) == (grid.Nx, 1, 1)

closure = DynamicSmagorinsky(averaging=Colon())
model = NonhydrostaticModel(; grid, closure)
@test size(model.diffusivity_fields.𝒥ᴸᴹ) == (1, 1, 1)
@test size(model.diffusivity_fields.𝒥ᴹᴹ) == (1, 1, 1)

closure = DynamicSmagorinsky(averaging=LagrangianAveraging())
model = NonhydrostaticModel(; grid, closure)
@test size(model.diffusivity_fields.𝒥ᴸᴹ) == size(grid)
@test size(model.diffusivity_fields.𝒥ᴹᴹ) == size(grid)
@test size(model.diffusivity_fields.𝒥ᴸᴹ⁻) == size(grid)
@test size(model.diffusivity_fields.𝒥ᴹᴹ⁻) == size(grid)
@test size(model.diffusivity_fields.Σ) == size(grid)
@test size(model.diffusivity_fields.Σ̄) == size(grid)
end
end

Expand Down Expand Up @@ -429,11 +422,14 @@ end
@info " Testing turbulence closure diagnostics..."
for closurename in closures
closure = @eval $closurename()
closure isa DynamicSmagorinsky && continue # `DynamicSmagorinsky`s `_compute_LM_MM!()` kernel isn't compiling on buildkite
compute_closure_specific_diffusive_cfl(closure)
end

# now test also a case for a tuple of closures
compute_closure_specific_diffusive_cfl((ScalarDiffusivity(), ScalarBiharmonicDiffusivity(), SmagorinskyLilly(), AnisotropicMinimumDissipation()))
compute_closure_specific_diffusive_cfl((ScalarDiffusivity(),
ScalarBiharmonicDiffusivity(),
SmagorinskyLilly(),
AnisotropicMinimumDissipation()))
end
end

Loading