Skip to content

Commit 23e8adb

Browse files
committed
Fix removed function arg + add validate_gravity_unit_vector
1 parent 6a0cfbd commit 23e8adb

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/PotentialEnergyEquationTerms.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using Oceananigans.AbstractOperations: KernelFunctionOperation
88
using Oceananigans.Models: seawater_density
99
using Oceananigans.Models: model_geopotential_height
1010
using Oceananigans.Grids: Center, Face
11+
using Oceananigans.Grids: NegativeZDirection
1112
using Oceananigans.BuoyancyModels: Buoyancy, BuoyancyTracer, SeawaterBuoyancy, LinearEquationOfState
1213
using Oceananigans.BuoyancyModels: buoyancy_perturbationᶜᶜᶜ, Zᶜᶜᶜ
1314
using Oceananigans.Models: ShallowWaterModel
@@ -19,6 +20,10 @@ const BuoyancyTracerModel = Buoyancy{<:BuoyancyTracer, g} where g
1920
const BuoyancyLinearEOSModel = Buoyancy{<:SeawaterBuoyancy{FT, <:LinearEquationOfState, T, S}} where {FT, T, S}
2021
const BuoyancyBoussinesqEOSModel = Buoyancy{<:SeawaterBuoyancy{FT, <:BoussinesqEquationOfState, T, S}} where {FT, T, S}
2122

23+
validate_gravity_unit_vector(gravity_unit_vector::NegativeZDirection) = nothing
24+
validate_gravity_unit_vector(gravity_unit_vector) =
25+
throw(ArgumentError("`PotentialEnergy` is curently only defined for models that have a `NegativeZDirection` gravity unit vector."))
26+
2227
"""
2328
$(SIGNATURES)
2429
@@ -62,8 +67,8 @@ NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
6267
julia> PotentialEnergy(model)
6368
KernelFunctionOperation at (Center, Center, Center)
6469
├── grid: 1×1×100 RectilinearGrid{Float64, Flat, Flat, Bounded} on CPU with 0×0×3 halo
65-
├── kernel_function: bz_ccc (generic function with 1 method)
66-
└── arguments: ("1×1×100 Field{Center, Center, Center} on RectilinearGrid on CPU", "KernelFunctionOperation at (Center, Center, Center)")
70+
├── kernel_function: bz_ccc (generic function with 2 methods)
71+
└── arguments: ("1×1×100 Field{Center, Center, Center} on RectilinearGrid on CPU",)
6772
```
6873
6974
The default behaviour of `PotentialEnergy` uses the *in-situ density* in the calculation
@@ -127,17 +132,18 @@ julia> model = NonhydrostaticModel(; grid, buoyancy, tracers);
127132
128133
julia> geopotential_height = 0; # density variable will be σ₀
129134
130-
julia> PotentialEnergy(model; geopotential_height)
135+
julia> PotentialEnergy(model)
131136
KernelFunctionOperation at (Center, Center, Center)
132137
├── grid: 1×1×100 RectilinearGrid{Float64, Flat, Flat, Bounded} on CPU with 0×0×3 halo
133138
├── kernel_function: g′z_ccc (generic function with 1 method)
134-
└── arguments: ("KernelFunctionOperation at (Center, Center, Center)", "KernelFunctionOperation at (Center, Center, Center)", "(g=9.80665, ρ₀=1020.0)")
139+
└── arguments: ("KernelFunctionOperation at (Center, Center, Center)", "(g=9.80665, ρ₀=1020.0)")
135140
```
136141
"""
137142
@inline function PotentialEnergy(model; location = (Center, Center, Center),
138143
geopotential_height = model_geopotential_height(model))
139144

140145
validate_location(location, "PotentialEnergy")
146+
validate_gravity_unit_vector(model.buoyancy.gravity_unit_vector)
141147

142148
return PotentialEnergy(model, model.buoyancy, geopotential_height)
143149
end
@@ -173,7 +179,7 @@ end
173179
parameters = (g = model.buoyancy.model.gravitational_acceleration,
174180
ρ₀ = model.buoyancy.model.equation_of_state.reference_density)
175181

176-
return KernelFunctionOperation{Center, Center, Center}(g′z_ccc, grid, ρ, Z, parameters)
182+
return KernelFunctionOperation{Center, Center, Center}(g′z_ccc, grid, ρ, parameters)
177183
end
178184

179185
@inline g′z_ccc(i, j, k, grid, ρ, p) = (p.g / p.ρ₀) * ρ[i, j, k] * Zᶜᶜᶜ(i, j, k, grid)

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ function test_potential_energy_equation_terms(model; geopotential_height = nothi
344344

345345
if model.buoyancy isa BuoyancyBoussinesqEOSModel
346346
ρ = isnothing(geopotential_height) ? Field(seawater_density(model)) :
347-
Field(seawater_density(model; geopotential_height))
347+
Field(seawater_density(model; geopotential_height))
348348

349349
compute!(ρ)
350350
Z = Field(model_geopotential_height(model))

0 commit comments

Comments
 (0)