@@ -8,6 +8,7 @@ using Oceananigans.AbstractOperations: KernelFunctionOperation
88using Oceananigans. Models: seawater_density
99using Oceananigans. Models: model_geopotential_height
1010using Oceananigans. Grids: Center, Face
11+ using Oceananigans. Grids: NegativeZDirection
1112using Oceananigans. BuoyancyModels: Buoyancy, BuoyancyTracer, SeawaterBuoyancy, LinearEquationOfState
1213using Oceananigans. BuoyancyModels: buoyancy_perturbationᶜᶜᶜ, Zᶜᶜᶜ
1314using Oceananigans. Models: ShallowWaterModel
@@ -19,6 +20,10 @@ const BuoyancyTracerModel = Buoyancy{<:BuoyancyTracer, g} where g
1920const BuoyancyLinearEOSModel = Buoyancy{<: SeawaterBuoyancy{FT, <:LinearEquationOfState, T, S} } where {FT, T, S}
2021const 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)
6267julia> PotentialEnergy(model)
6368KernelFunctionOperation 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
6974The default behaviour of `PotentialEnergy` uses the *in-situ density* in the calculation
@@ -127,17 +132,18 @@ julia> model = NonhydrostaticModel(; grid, buoyancy, tracers);
127132
128133julia> geopotential_height = 0; # density variable will be σ₀
129134
130- julia> PotentialEnergy(model; geopotential_height )
135+ julia> PotentialEnergy(model)
131136KernelFunctionOperation 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)
143149end
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)
177183end
178184
179185@inline g′z_ccc (i, j, k, grid, ρ, p) = (p. g / p. ρ₀) * ρ[i, j, k] * Zᶜᶜᶜ (i, j, k, grid)
0 commit comments