Skip to content

Commit 02d2be5

Browse files
committed
use ocean fraction, minimize diff [skip ci]
1 parent 15ccf8f commit 02d2be5

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

experiments/ClimaEarth/components/ocean/oceananigans.jl

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ It contains the following objects:
2222
- `ocean_properties::OPROP`: A NamedTuple of ocean properties and parameters
2323
- `remapping::REMAP`: Objects needed to remap from the exchange (spectral) grid to Oceananigans spaces.
2424
"""
25-
struct OceananigansSimulation{SIM, A, OPROP, REMAP} <: Interfacer.OceanModelSimulation
25+
struct OceananigansSimulation{SIM, A, OPROP, REMAP, SIC} <: Interfacer.OceanModelSimulation
2626
ocean::SIM
2727
area_fraction::A
2828
ocean_properties::OPROP
@@ -189,6 +189,9 @@ This matters in the case of a LatitudeLongitudeGrid, which is only
189189
defined between -80 and 80 degrees latitude. In this case, we want to
190190
set the ice fraction to `1 - land_fraction` on [-90, -80] and [80, 90]
191191
degrees latitude, and make sure the ocean fraction is 0 there.
192+
193+
The land fraction is expected to be set to 1 at the poles before calling this function,
194+
and doesn't need to be set again since its fraction is static.
192195
"""
193196
function FieldExchanger.resolve_ocean_ice_fractions!(
194197
ocean_sim::OceananigansSimulation,
@@ -206,6 +209,7 @@ function FieldExchanger.resolve_ocean_ice_fractions!(
206209
polar_mask = CC.Fields.zeros(boundary_space)
207210
polar_mask .= abs.(lat) .>= FT(80)
208211

212+
# TODO do we want both to be 0 since we use capped lat/lon?
209213
# Set ice fraction to 1 - land_fraction and ocean fraction to 0 where polar_mask is 1
210214
@. ice_fraction = ifelse.(polar_mask == FT(1), FT(1) - land_fraction, ice_fraction)
211215
@. ocean_fraction = ifelse.(polar_mask == FT(1), FT(0), ocean_fraction)
@@ -259,9 +263,11 @@ and Oceananigans represents moisture moving from atmosphere to ocean as a positi
259263
so a sign change is needed when we convert from moisture to salinity flux.
260264
"""
261265
function FluxCalculator.update_turbulent_fluxes!(sim::OceananigansSimulation, fields)
266+
# TODO multiply all fluxes by 1 - SIC
267+
# TODO clarify where we need to add and where we set fluxes directly
262268
(; F_lh, F_sh, F_turb_ρτxz, F_turb_ρτyz, F_turb_moisture) = fields
263-
264269
grid = sim.ocean.model.grid
270+
area_fraction = sim.area_fraction
265271

266272
# Remap momentum fluxes onto reduced 2D Center, Center fields using scratch arrays and fields
267273
CC.Remapping.interpolate!(
@@ -289,7 +295,7 @@ function FluxCalculator.update_turbulent_fluxes!(sim::OceananigansSimulation, fi
289295
grid,
290296
F_turb_ρτxz_cc,
291297
F_turb_ρτyz_cc,
292-
)
298+
) # TODO multiply by area_fraction?
293299

294300
(; ocean_reference_density, ocean_heat_capacity, ocean_fresh_water_density) =
295301
sim.ocean_properties
@@ -308,7 +314,8 @@ function FluxCalculator.update_turbulent_fluxes!(sim::OceananigansSimulation, fi
308314
oc_flux_T = surface_flux(sim.ocean.model.tracers.T)
309315
OC.interior(oc_flux_T, :, :, 1) .=
310316
OC.interior(oc_flux_T, :, :, 1) .+
311-
(remapped_F_lh .+ remapped_F_sh) ./ (ocean_reference_density * ocean_heat_capacity)
317+
area_fraction .* (remapped_F_lh .+ remapped_F_sh) ./
318+
(ocean_reference_density * ocean_heat_capacity)
312319

313320
# Add the part of the salinity flux that comes from the moisture flux, we also need to
314321
# add the component due to precipitation (that was done with the radiative fluxes)
@@ -321,7 +328,8 @@ function FluxCalculator.update_turbulent_fluxes!(sim::OceananigansSimulation, fi
321328
oc_flux_S = surface_flux(sim.ocean.model.tracers.S)
322329
surface_salinity = OC.interior(sim.ocean.model.tracers.S, :, :, 1)
323330
OC.interior(oc_flux_S, :, :, 1) .=
324-
OC.interior(oc_flux_S, :, :, 1) .- (surface_salinity .* moisture_fresh_water_flux)
331+
OC.interior(oc_flux_S, :, :, 1) .-
332+
area_fraction .* surface_salinity .* moisture_fresh_water_flux
325333
return nothing
326334
end
327335

@@ -353,7 +361,7 @@ so a sign change is needed when we convert from precipitation to salinity flux.
353361
function FieldExchanger.update_sim!(sim::OceananigansSimulation, csf)
354362
(; ocean_reference_density, ocean_heat_capacity, ocean_fresh_water_density) =
355363
sim.ocean_properties
356-
ocean_fraction = sim.area_fraction
364+
area_fraction = sim.area_fraction # TODO use sea ice instead?
357365

358366
# Remap radiative flux onto scratch array; rename for clarity
359367
CC.Remapping.interpolate!(
@@ -377,8 +385,8 @@ function FieldExchanger.update_sim!(sim::OceananigansSimulation, csf)
377385
σ = 5.67e-8
378386
α = Interfacer.get_field(sim, Val(:surface_direct_albedo)) # scalar
379387
ϵ = Interfacer.get_field(sim, Val(:emissivity)) # scalar
380-
OC.interior(oc_flux_T, :, :, 1) .= OC.interior(oc_flux_T, :, :, 1) .+
381-
(
388+
OC.interior(oc_flux_T, :, :, 1) .=
389+
area_fraction .* (
382390
-(1 - α) .* remapped_SW_d .-
383391
ϵ * (
384392
remapped_LW_d .-
@@ -390,20 +398,20 @@ function FieldExchanger.update_sim!(sim::OceananigansSimulation, csf)
390398
CC.Remapping.interpolate!(
391399
sim.remapping.scratch_arr1,
392400
sim.remapping.remapper_cc,
393-
ocean_fraction .* csf.P_liq,
401+
area_fraction .* csf.P_liq,
394402
)
395403
CC.Remapping.interpolate!(
396404
sim.remapping.scratch_arr2,
397405
sim.remapping.remapper_cc,
398-
ocean_fraction .* csf.P_snow,
406+
area_fraction .* csf.P_snow,
399407
)
400408
remapped_P_liq = sim.remapping.scratch_arr1
401409
remapped_P_snow = sim.remapping.scratch_arr2
402410

403411
# Virtual salt flux
404412
oc_flux_S = surface_flux(sim.ocean.model.tracers.S)
405413
precipitating_fresh_water_flux =
406-
(remapped_P_liq .+ remapped_P_snow) ./ ocean_fresh_water_density
414+
area_fraction .* (remapped_P_liq .+ remapped_P_snow) ./ ocean_fresh_water_density
407415
surface_salinity_flux =
408416
OC.interior(sim.ocean.model.tracers.S, :, :, 1) .* precipitating_fresh_water_flux
409417
OC.interior(oc_flux_S, :, :, 1) .=

src/FieldExchanger.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ Updates the surface component model cache with the current coupler fields
212212
# Arguments
213213
- `sim`: [Interfacer.SurfaceModelSimulation] containing a surface model simulation object.
214214
- `csf`: [NamedTuple] containing coupler fields.
215-
- `area_fraction`: [CC.Fields.Field] containing the area fraction of this surface model.
216215
"""
217216
function update_sim!(sim::Interfacer.SurfaceModelSimulation, csf)
218217
# radiative fluxes

0 commit comments

Comments
 (0)