Skip to content

Commit 121dda8

Browse files
authored
Merge pull request #1519 from CliMA/js/zs/sf-af
fixes for sea ice and fluxes
2 parents 3807833 + 16ea334 commit 121dda8

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

experiments/ClimaEarth/components/ocean/prescr_seaice.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ function PrescribedIceSimulation(
124124
# Overwrite ice fraction with the static land area fraction anywhere we have nonzero land area
125125
# max needed to avoid Float32 errors (see issue #271; Heisenbug on HPC)
126126
ice_fraction = @. max(min(SIC_init, FT(1) - land_fraction), FT(0))
127+
ice_fraction = ifelse.(ice_fraction .> FT(0.5), FT(1), FT(0))
127128

128129
params = IceSlabParameters{FT}()
129130

@@ -263,17 +264,20 @@ function ice_rhs!(dY, Y, p, t)
263264

264265
# Update the cached area fraction with the current SIC
265266
evaluate!(p.area_fraction, p.SIC_timevaryinginput, t)
267+
@. p.area_fraction = ifelse(p.area_fraction > FT(0.5), FT(1), FT(0))
266268

267269
# Overwrite ice fraction with the static land area fraction anywhere we have nonzero land area
268270
# max needed to avoid Float32 errors (see issue #271; Heisenbug on HPC)
269271
@. p.area_fraction = max(min(p.area_fraction, FT(1) - p.land_fraction), FT(0))
270272

271273
# Calculate the conductive flux, and set it to zero if the area fraction is zero
272274
F_conductive = @. params.k_ice / (params.h) * (params.T_base - Y.T_sfc) # fluxes are defined to be positive when upward
273-
@. F_conductive = ifelse(p.area_fraction 0, zero(F_conductive), F_conductive)
274-
275275
rhs = @. (-p.F_turb_energy - p.F_radiative + F_conductive) /
276276
(params.h * params.ρ * params.c)
277+
278+
# Zero out tendencies where there is no ice, so that ice temperature remains constant there
279+
@. rhs = ifelse(p.area_fraction 0, zero(rhs), rhs)
280+
277281
# If tendencies lead to temperature above freezing, set temperature to freezing
278282
@. dY.T_sfc = min(rhs, (params.T_freeze - Y.T_sfc) / float(p.dt))
279283
end

experiments/ClimaEarth/components/ocean/slab_ocean.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ function slab_ocean_rhs!(dY, Y, cache, t)
199199
p, F_turb_energy, F_radiative = cache
200200
rhs = @. -(F_turb_energy + F_radiative) / (p.h * p.ρ * p.c)
201201

202+
# Zero out tendencies where there is no ocean, so that temperature remains constant there
203+
@. rhs = ifelse(cache.area_fraction 0, zero(rhs), rhs)
204+
202205
# Note that the area fraction has already been applied to the fluxes,
203206
# so we don't need to multiply by it here.
204207
@. dY.T_sfc = rhs * p.evolving_switch

experiments/ClimaEarth/setup_run.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ function CoupledSimulation(config_dict::AbstractDict)
373373

374374
## ocean model using prescribed data
375375
ice_fraction = Interfacer.get_field(ice_sim, Val(:area_fraction))
376+
ice_fraction = ifelse.(ice_fraction .> FT(0.5), FT(1), FT(0))
376377
ocean_fraction = FT(1) .- ice_fraction .- land_fraction
377378

378379
if sim_mode <: CMIPMode

experiments/ClimaEarth/test/component_model_tests/prescr_seaice_tests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ for FT in (Float32, Float64)
7171
# check that nothing changes with no fluxes (zero conduction when T_base == initial T_sfc)
7272
T_base_eq = IceSlabParameters{FT}().T_freeze - FT(5.0)
7373
dY, Y, p = test_sea_ice_rhs(T_base = T_base_eq)
74-
@test all([i for i in extrema(dY)] .≈ [FT(0.0), FT(0.0)])
74+
@test all(T -> T == FT(0), Array(parent(dY.T_sfc)))
7575

7676
# check expected dT due to radiative flux only (again set T_base == initial T_sfc)
7777
dY, Y, p = test_sea_ice_rhs(F_radiative = 1.0, T_base = T_base_eq)
7878
dT_expected = -1.0 / (p.params.h * p.params.ρ * p.params.c)
79-
@test all(extrema(dY) .≈ FT(dT_expected))
79+
@test all(T -> T == FT(0) || T dT_expected, Array(parent(dY.T_sfc)))
8080

8181
# check that tendency will not result in above freezing T
8282
dY, Y, p = test_sea_ice_rhs(F_radiative = 0.0, T_base = 330.0) # Float32 requires a large number here!

src/FluxCalculator.jl

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -356,26 +356,18 @@ function compute_surface_fluxes!(
356356
@. ustar = ifelse(area_fraction 0, zero(ustar), ustar)
357357
@. buoyancy_flux = ifelse(area_fraction 0, zero(buoyancy_flux), buoyancy_flux)
358358

359-
# multiply fluxes by area fraction
360-
F_turb_ρτxz .*= area_fraction
361-
F_turb_ρτyz .*= area_fraction
362-
F_sh .*= area_fraction
363-
F_lh .*= area_fraction
364-
F_turb_moisture .*= area_fraction
365-
366359
# update the fluxes, which are now area-weighted, of this surface model
367360
fields = (; F_turb_ρτxz, F_turb_ρτyz, F_lh, F_sh, F_turb_moisture)
368361
FluxCalculator.update_turbulent_fluxes!(sim, fields)
369362

370363
# update fluxes in the coupler fields
371364
# add the flux contributing from this surface to the coupler field
372-
# note that the fluxes area-weighted, so if a surface model is
373-
# not present at a point, the fluxes are zero
374-
@. csf.F_turb_ρτxz += F_turb_ρτxz
375-
@. csf.F_turb_ρτyz += F_turb_ρτyz
376-
@. csf.F_lh += F_lh
377-
@. csf.F_sh += F_sh
378-
@. csf.F_turb_moisture += F_turb_moisture
365+
# note that the fluxes are area-weighted here when we provide them to the atmosphere
366+
@. csf.F_turb_ρτxz += F_turb_ρτxz * area_fraction
367+
@. csf.F_turb_ρτyz += F_turb_ρτyz * area_fraction
368+
@. csf.F_lh += F_lh * area_fraction
369+
@. csf.F_sh += F_sh * area_fraction
370+
@. csf.F_turb_moisture += F_turb_moisture * area_fraction
379371

380372
# NOTE: This is still an area weighted contribution, which maybe doesn't make
381373
# too much sense for these quantities...

0 commit comments

Comments
 (0)