Skip to content

Commit e60ee5e

Browse files
committed
store fields as NamedTuple of Fields
1 parent 6df3d91 commit e60ee5e

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

src/FluxCalculator.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ TODO:
4646
(NB: Radiation surface fluxes are calculated by the atmosphere.)
4747
"""
4848
function turbulent_fluxes!(csf, model_sims, thermo_params)
49-
boundary_space = axes(csf)
49+
boundary_space = axes(first(csf))
5050
atmos_sim = model_sims.atmos_sim
5151
FT = CC.Spaces.undertype(boundary_space)
5252

@@ -232,7 +232,7 @@ function compute_surface_fluxes!(
232232
atmos_sim::Interfacer.AbstractAtmosSimulation,
233233
thermo_params,
234234
)
235-
boundary_space = axes(csf)
235+
boundary_space = axes(first(csf))
236236
FT = CC.Spaces.undertype(boundary_space)
237237
surface_fluxes_params = FluxCalculator.get_surface_params(atmos_sim)
238238

src/Interfacer.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,16 @@ default_coupler_fields() = [
145145
"""
146146
init_coupler_fields(FT, coupler_field_names, boundary_space)
147147
148-
Allocate a Field of NamedTuples on the provided boundary space to store
148+
Allocate a NamedTuple of Fields on the provided boundary space to store
149149
the provided coupler fields.
150150
"""
151151
function init_coupler_fields(FT, coupler_field_names, boundary_space)
152152
# First remove any duplicate field names
153153
unique!(coupler_field_names)
154154

155-
key_types = (coupler_field_names...,)
156-
val_types = Tuple{(FT for _ in 1:length(coupler_field_names))...}
157-
158-
nt_type = NamedTuple{key_types, val_types}
159-
coupler_fields = zeros(nt_type, boundary_space)
160-
return coupler_fields
155+
keys = Tuple(coupler_field_names)
156+
vals = ntuple(_ -> zeros(FT, boundary_space), length(coupler_field_names))
157+
return NamedTuple{keys}(vals)
161158
end
162159

163160
"""
@@ -667,7 +664,7 @@ AtmosSimulation(::Val{model_type}; kwargs...) where {model_type} =
667664
Return the `ClimaCore.Field` over which the exchange fields are defined.
668665
"""
669666
function boundary_space(sim::CoupledSimulation)
670-
return axes(sim.fields)
667+
return axes(first(sim.fields))
671668
end
672669

673670
"""
@@ -676,7 +673,7 @@ end
676673
Return the `ClimaComms.context` associated to the simulation.
677674
"""
678675
function ClimaComms.context(sim::CoupledSimulation)
679-
return ClimaComms.context(sim.fields)
676+
return ClimaComms.context(first(sim.fields))
680677
end
681678

682679
"""
@@ -685,7 +682,7 @@ end
685682
Return the `ClimaComms.device` associated to the simulation.
686683
"""
687684
function ClimaComms.device(sim::CoupledSimulation)
688-
return ClimaComms.device(sim.fields)
685+
return ClimaComms.device(first(sim.fields))
689686
end
690687

691688
"""

test/flux_calculator_tests.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,11 @@ for FT in (Float32, Float64)
234234
)
235235

236236
# Compare expected and computed fluxes
237-
@test fields.F_turb_ρτxz fluxes_expected.F_turb_ρτxz
238-
@test fields.F_turb_ρτyz fluxes_expected.F_turb_ρτyz
239-
@test fields.F_lh fluxes_expected.F_lh
240-
@test fields.F_sh fluxes_expected.F_sh
241-
@test fields.F_turb_moisture fluxes_expected.F_turb_moisture
237+
@test all(parent(fields.F_turb_ρτxz) .≈ parent(fluxes_expected.F_turb_ρτxz))
238+
@test all(parent(fields.F_turb_ρτyz) .≈ parent(fluxes_expected.F_turb_ρτyz))
239+
@test all(parent(fields.F_lh) .≈ parent(fluxes_expected.F_lh))
240+
@test all(parent(fields.F_sh) .≈ parent(fluxes_expected.F_sh))
241+
@test all(parent(fields.F_turb_moisture) .≈ parent(fluxes_expected.F_turb_moisture))
242242
end
243243

244244
@testset "get_surface_params for FT=$FT" begin

test/interfacer_tests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ for FT in (Float32, Float64)
4444
context,
4545
)
4646

47-
fields = ones(boundary_space_)
47+
fields = Interfacer.init_coupler_fields(FT, [:field], boundary_space_)
4848

4949
cs = Interfacer.CoupledSimulation{FT}(
5050
nothing, # dates

0 commit comments

Comments
 (0)