Skip to content

Commit 1d58d9f

Browse files
authored
Split up anelastic pressure tests for better load balancing (#73)
1 parent 728ddcb commit 1d58d9f

File tree

3 files changed

+84
-85
lines changed

3 files changed

+84
-85
lines changed

test/anelastic_pressure_solver.jl

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Test
2+
using Breeze
3+
using Oceananigans
4+
using Oceananigans.Fields: fill_halo_regions!
5+
6+
@testset "Anelastic pressure solver recovers analytic solution [$FT]" for FT in (Float32, Float64)
7+
grid = RectilinearGrid(FT; size=48, z=(0, 1), topology=(Flat, Flat, Bounded))
8+
thermodynamics = ThermodynamicConstants(FT)
9+
reference_constants = ReferenceStateConstants(FT; base_pressure=101325.0, potential_temperature=288.0)
10+
formulation = AnelasticFormulation(grid, reference_constants, thermodynamics)
11+
12+
#=
13+
ρᵣ = 2 + cos(π z / 2)
14+
∂z ρᵣ ∂z ϕ = ?
15+
16+
ϕ = cos(π z)
17+
⟹ ∂z ϕ = -π sin(π z)
18+
⟹ (2 + cos(π z)) ∂z ϕ = -π (2 sin(π z) + cos(π z) sin(π z))
19+
⟹ ∂z (1 + cos(π z / 2)) ∂z ϕ = -π² (2 cos(π z) + 2 cos²(π z) - 1)
20+
21+
ϕ = z² / 2 - z³ / 3 = z² (1/2 - z/3)
22+
∂z ϕ = z (1 - z) = z - z²
23+
∂z² ϕ = 1 - 2z
24+
⟹ z ∂z ϕ = z² - z³
25+
⟹ ∂z (z ∂z ϕ) = 2 z - 3 z²
26+
27+
R = ∂z ρw = 2 z - 3 z²
28+
⟹ ρw = z² - z³
29+
=#
30+
31+
set!(formulation.reference_density, z -> z)
32+
fill_halo_regions!(formulation.reference_density)
33+
model = AtmosphereModel(grid; thermodynamics, formulation)
34+
set!(model, ρw = z -> z^2 - z^3)
35+
36+
ϕ_exact = CenterField(grid)
37+
set!(ϕ_exact, z -> z^2 / 2 - z^3 / 3 - 1 / 12)
38+
@test isapprox(ϕ_exact, model.nonhydrostatic_pressure, rtol=1e-3)
39+
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Test
2+
using Breeze
3+
using Oceananigans
4+
5+
@testset "Pressure solver matches NonhydrostaticModel with ρᵣ == 1 [$FT]" for FT in (Float32, Float64)
6+
Nx = Ny = Nz = 32
7+
z = 0:(1/Nz):1
8+
grid = RectilinearGrid(FT; size=(Nx, Ny, Nz), x=(0, 1), y=(0, 1), z)
9+
thermodynamics = ThermodynamicConstants(FT)
10+
reference_constants = ReferenceStateConstants(FT; base_pressure=101325, potential_temperature=288)
11+
12+
formulation = AnelasticFormulation(grid, reference_constants, thermodynamics)
13+
parent(formulation.reference_density) .= 1
14+
15+
anelastic = AtmosphereModel(grid; thermodynamics=thermodynamics, formulation)
16+
boussinesq = NonhydrostaticModel(; grid)
17+
18+
uᵢ = rand(size(grid)...)
19+
vᵢ = rand(size(grid)...)
20+
wᵢ = rand(size(grid)...)
21+
22+
set!(anelastic, ρu=uᵢ, ρv=vᵢ, ρw=wᵢ)
23+
set!(boussinesq, u=uᵢ, v=vᵢ, w=wᵢ)
24+
25+
ρu = anelastic.momentum.ρu
26+
ρv = anelastic.momentum.ρv
27+
ρw = anelastic.momentum.ρw
28+
δᵃ = Field(∂x(ρu) + ∂y(ρv) + ∂z(ρw))
29+
30+
u = boussinesq.velocities.u
31+
v = boussinesq.velocities.v
32+
w = boussinesq.velocities.w
33+
δᵇ = Field(∂x(u) + ∂y(v) + ∂z(w))
34+
35+
boussinesq_solver = boussinesq.pressure_solver
36+
anelastic_solver = anelastic.pressure_solver
37+
@test anelastic_solver.batched_tridiagonal_solver.a == boussinesq_solver.batched_tridiagonal_solver.a
38+
@test anelastic_solver.batched_tridiagonal_solver.b == boussinesq_solver.batched_tridiagonal_solver.b
39+
@test anelastic_solver.batched_tridiagonal_solver.c == boussinesq_solver.batched_tridiagonal_solver.c
40+
@test anelastic_solver.source_term == boussinesq_solver.source_term
41+
42+
@test maximum(abs, δᵃ) < prod(size(grid)) * eps(FT)
43+
@test maximum(abs, δᵇ) < prod(size(grid)) * eps(FT)
44+
@test anelastic.nonhydrostatic_pressure == boussinesq.pressures.pNHS
45+
end

0 commit comments

Comments
 (0)