Skip to content

Commit 6a0cfbd

Browse files
committed
Remove some nested KernelFunctionOperations
1 parent 68007f1 commit 6a0cfbd

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/PotentialEnergyEquationTerms.jl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using Oceananigans.Models: seawater_density
99
using Oceananigans.Models: model_geopotential_height
1010
using Oceananigans.Grids: Center, Face
1111
using Oceananigans.BuoyancyModels: Buoyancy, BuoyancyTracer, SeawaterBuoyancy, LinearEquationOfState
12-
using Oceananigans.BuoyancyModels: buoyancy_perturbationᶜᶜᶜ
12+
using Oceananigans.BuoyancyModels: buoyancy_perturbationᶜᶜᶜ, Zᶜᶜᶜ
1313
using Oceananigans.Models: ShallowWaterModel
1414
using Oceanostics: validate_location
1515
using SeawaterPolynomials: BoussinesqEquationOfState
@@ -19,9 +19,6 @@ const BuoyancyTracerModel = Buoyancy{<:BuoyancyTracer, g} where g
1919
const BuoyancyLinearEOSModel = Buoyancy{<:SeawaterBuoyancy{FT, <:LinearEquationOfState, T, S}} where {FT, T, S}
2020
const BuoyancyBoussinesqEOSModel = Buoyancy{<:SeawaterBuoyancy{FT, <:BoussinesqEquationOfState, T, S}} where {FT, T, S}
2121

22-
linear_eos_buoyancy(model) = linear_eos_buoyancy(model.grid, model.buoyancy.model, model.tracers)
23-
linear_eos_buoyancy(grid, buoyancy, tracers) = KernelFunctionOperation{Center, Center, Center}(buoyancy_perturbationᶜᶜᶜ, grid, buoyancy, tracers)
24-
2522
"""
2623
$(SIGNATURES)
2724
@@ -152,33 +149,33 @@ end
152149

153150
grid = model.grid
154151
b = model.tracers.b
155-
Z = model_geopotential_height(model)
156152

157-
return KernelFunctionOperation{Center, Center, Center}(bz_ccc, grid, b, Z)
153+
return KernelFunctionOperation{Center, Center, Center}(bz_ccc, grid, b)
158154
end
159155

156+
@inline bz_ccc(i, j, k, grid, b) = b[i, j, k] * Zᶜᶜᶜ(i, j, k, grid)
157+
160158
@inline function PotentialEnergy(model, buoyancy_model::BuoyancyLinearEOSModel, geopotential_height)
161159

162160
grid = model.grid
163-
b = linear_eos_buoyancy(model)
164-
Z = model_geopotential_height(model)
161+
C = model.tracers
162+
b = buoyancy_model.model
165163

166-
return KernelFunctionOperation{Center, Center, Center}(bz_ccc, grid, b, Z)
164+
return KernelFunctionOperation{Center, Center, Center}(bz_ccc, grid, b, C)
167165
end
168166

169-
@inline bz_ccc(i, j, k, grid, b, Z) = b[i, j, k] * Z[i, j, k]
167+
@inline bz_ccc(i, j, k, grid, b, C) = buoyancy_perturbationᶜᶜᶜ(i, j, k, grid, b, C) * Zᶜᶜᶜ(i, j, k, grid)
170168

171169
@inline function PotentialEnergy(model, buoyancy_model::BuoyancyBoussinesqEOSModel, geopotential_height)
172170

173171
grid = model.grid
174172
ρ = seawater_density(model; geopotential_height)
175-
Z = model_geopotential_height(model)
176173
parameters = (g = model.buoyancy.model.gravitational_acceleration,
177174
ρ₀ = model.buoyancy.model.equation_of_state.reference_density)
178175

179176
return KernelFunctionOperation{Center, Center, Center}(g′z_ccc, grid, ρ, Z, parameters)
180177
end
181178

182-
@inline g′z_ccc(i, j, k, grid, ρ, Z, p) = (p.g / p.ρ₀) * ρ[i, j, k] * Z[i, j, k]
179+
@inline g′z_ccc(i, j, k, grid, ρ, p) = (p.g / p.ρ₀) * ρ[i, j, k] * Zᶜᶜᶜ(i, j, k, grid)
183180

184181
end # module

0 commit comments

Comments
 (0)