Skip to content

Commit 7369481

Browse files
committed
Remove radiative_energy_toa
`radiative_energy_toa` is a field fully owned by atmos. There is no reason for ClimaCoupler to maintain a copy. Instead, we can directly access the value from atmos if we need it (it's only needed for conservation checks).
1 parent ae8c250 commit 7369481

File tree

5 files changed

+23
-17
lines changed

5 files changed

+23
-17
lines changed

experiments/ClimaEarth/setup_run.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ function CoupledSimulation(config_dict::AbstractDict)
418418
Interfacer.add_coupler_fields!(coupler_field_names, sim)
419419
end
420420
# add coupler fields required to track conservation, if specified
421-
energy_check && push!(coupler_field_names, :radiative_energy_flux_toa, :P_net)
421+
energy_check && push!(coupler_field_names, :P_net)
422422

423423
# allocate space for the coupler fields
424424
coupler_fields = Interfacer.init_coupler_fields(FT, coupler_field_names, boundary_space)

experiments/ClimaEarth/test/debug_plots_tests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ plot_field_names(sim::Interfacer.SurfaceStub) = (:stub_field,)
4848
:beta,
4949
:z0b_sfc,
5050
:z0m_sfc,
51-
:radiative_energy_flux_toa,
5251
]
5352
atmos_names = (:atmos_field,)
5453
surface_names = (:surface_field,)

src/ConservationChecker.jl

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,28 @@ function check_conservation!(
8383
for sim in model_sims
8484
sim_name = Symbol(Interfacer.name(sim))
8585
if sim isa Interfacer.AtmosModelSimulation
86-
radiative_energy_flux_toa = coupler_sim.fields.radiative_energy_flux_toa
87-
# save radiation source
88-
parent(radiative_energy_flux_toa) .= parent(Interfacer.get_field(sim, Val(:radiative_energy_flux_toa)))
86+
radiative_energy_flux_toa = Interfacer.get_field(sim, Val(:radiative_energy_flux_toa))
87+
88+
# ClimaCore #1578, if radiative_energy_flux_toa comes from Fields.level
89+
# TODO: Fix this in ClimaCore
90+
rad_grid = CC.Spaces.grid(axes(radiative_energy_flux_toa))
91+
if rad_grid isa CC.Grids.LevelGrid
92+
if rad_grid.level isa CC.Utilities.PlusHalf
93+
# FaceSpace
94+
surface_integral =
95+
sum(radiative_energy_flux_toa ./ CC.Fields.Δz_field(radiative_energy_flux_toa) .* 2)
96+
else
97+
# Center
98+
surface_integral = sum(radiative_energy_flux_toa ./ CC.Fields.Δz_field(radiative_energy_flux_toa))
99+
end
100+
else
101+
surface_integral = sum(radiative_energy_flux_toa)
102+
end
89103

90104
if isempty(ccs.toa_net_source)
91-
radiation_sources_accum = sum(radiative_energy_flux_toa .* FT(float(coupler_sim.Δt_cpl))) # ∫ J / m^2 dA
105+
radiation_sources_accum = surface_integral * FT(float(coupler_sim.Δt_cpl)) # ∫ J / m^2 dA
92106
else
93-
radiation_sources_accum =
94-
sum(radiative_energy_flux_toa .* FT(float(coupler_sim.Δt_cpl))) .+ ccs.toa_net_source[end] # ∫ J / m^2 dA
107+
radiation_sources_accum = surface_integral * FT(float(coupler_sim.Δt_cpl)) + ccs.toa_net_source[end] # ∫ J / m^2 dA
95108
end
96109
push!(ccs.toa_net_source, radiation_sources_accum)
97110

@@ -101,7 +114,6 @@ function check_conservation!(
101114

102115
push!(previous, current)
103116
total += current + radiation_sources_accum
104-
105117
elseif sim isa Interfacer.SurfaceModelSimulation
106118
# save surfaces
107119
area_fraction = Interfacer.get_field(sim, Val(:area_fraction))
@@ -120,7 +132,7 @@ function check_conservation!(
120132
push!(ccs.total, total)
121133

122134
if runtime_check
123-
@assert abs((total[end] - total[1]) / total[end]) < 1e-4
135+
@assert abs((ccs.total[end] - ccs.total[1]) / ccs.total[end]) < 1e-4
124136
end
125137
return total
126138

@@ -185,7 +197,7 @@ function check_conservation!(
185197
push!(ccs.total, total)
186198

187199
if runtime_check
188-
@assert abs((total[end] - total[1]) / total[end]) < 1e-4
200+
@assert abs((ccs.total[end] - ccs.total[1]) / ccs.total[end]) < 1e-4
189201
end
190202

191203
return total

src/Interfacer.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ get_field(
192192
Val{:height_sfc},
193193
Val{:liquid_precipitation},
194194
Val{:radiative_energy_flux_sfc},
195-
Val{:radiative_energy_flux_toa},
196195
Val{:snow_precipitation},
197196
Val{:turblent_energy_flux},
198197
Val{:turbulent_moisture_flux},

test/conservation_checker_tests.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,11 @@ for FT in (Float32, Float64)
5555

5656
# coupler fields
5757
cf = (;
58-
radiative_energy_flux_toa = CC.Fields.ones(space),
5958
P_net = CC.Fields.zeros(space),
6059
P_liq = CC.Fields.zeros(space),
6160
P_snow = CC.Fields.zeros(space),
6261
F_turb_moisture = CC.Fields.zeros(space),
6362
)
64-
@. cf.radiative_energy_flux_toa = 200
6563
@. cf.P_liq = -100
6664

6765
# init
@@ -82,7 +80,7 @@ for FT in (Float32, Float64)
8280
)
8381

8482
# set non-zero radiation and precipitation
85-
F_r = cf.radiative_energy_flux_toa
83+
F_r = 200 .* CC.Fields.ones(space)
8684
P = cf.P_liq
8785
Δt = float(cs.Δt_cpl)
8886

@@ -134,13 +132,11 @@ for FT in (Float32, Float64)
134132

135133
# coupler fields
136134
cf = (;
137-
radiative_energy_flux_toa = CC.Fields.ones(space),
138135
P_net = CC.Fields.zeros(space),
139136
P_liq = CC.Fields.zeros(space),
140137
P_snow = CC.Fields.zeros(space),
141138
F_turb_moisture = CC.Fields.zeros(space),
142139
)
143-
@. cf.radiative_energy_flux_toa = 200
144140
@. cf.P_liq = -100
145141

146142
# init

0 commit comments

Comments
 (0)