Skip to content

Commit f081127

Browse files
authored
remove allocations in ground albedo of snowy land (#981)
1 parent 260b427 commit f081127

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

src/ClimaLand.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function initialize_lsm_aux(land::AbstractLandModel, land_coords)
126126
types = lsm_aux_types(land)
127127
domains = lsm_aux_domain_names(land)
128128
additional_aux = map(zip(types, domains)) do (T, domain)
129-
zero_instance = zero(T)
129+
zero_instance = ClimaCore.RecursiveApply.rzero(T)
130130
map(_ -> zero_instance, getproperty(land_coords, domain))
131131
end
132132
return NamedTuple{vars}(additional_aux)

src/integrated/land.jl

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ lsm_aux_vars(m::LandModel) = (
205205
:T_sfc,
206206
:ϵ_sfc,
207207
:α_sfc,
208+
:α_ground,
208209
)
209210

210211
"""
@@ -213,8 +214,28 @@ lsm_aux_vars(m::LandModel) = (
213214
The types of the additional auxiliary variables that are
214215
included in the land model.
215216
"""
216-
lsm_aux_types(m::LandModel{FT}) where {FT} =
217-
(FT, FT, FT, FT, FT, FT, FT, FT, FT, FT, FT, FT, FT, FT, FT, FT, FT, FT, FT)
217+
lsm_aux_types(m::LandModel{FT}) where {FT} = (
218+
FT,
219+
FT,
220+
FT,
221+
FT,
222+
FT,
223+
FT,
224+
FT,
225+
FT,
226+
FT,
227+
FT,
228+
FT,
229+
FT,
230+
FT,
231+
FT,
232+
FT,
233+
FT,
234+
FT,
235+
FT,
236+
FT,
237+
NamedTuple{(:PAR, :NIR), Tuple{FT, FT}},
238+
)
218239

219240
"""
220241
lsm_aux_domain_names(m::LandModel)
@@ -242,6 +263,7 @@ lsm_aux_domain_names(m::LandModel) = (
242263
:surface,
243264
:surface,
244265
:surface,
266+
:surface,
245267
)
246268

247269
"""
@@ -555,12 +577,11 @@ end
555577
PrognosticGroundConditions{FT <: AbstractFloat, F <: Union{FT, ClimaCore.Fields.Field}} <: Canopy.AbstractGroundConditions
556578
557579
A type of Canopy.AbstractGroundConditions to use when the soil model is prognostic and
558-
of type `EnergyHydrology`. This is required because the canopy model needs albedo of the ground
559-
in order to compute its update_aux! function, and that function must only depend on the canopy model.
580+
of type `EnergyHydrology`, and the snow model is prognostic and included.
560581
561-
In the future, we will allocate space for albedo in the cache. In that case, we would *not*
562-
store them here, twice. `PrognosticGroundConditions` would
563-
then just be a flag, essentially.
582+
The canopy model needs albedo of the ground
583+
in order to compute its update_aux! function, and that function must only depend on the canopy model.
584+
Because of this, α_snow must be stored in this struct until it is stored in the cache.
564585
565586
Note that this struct is linked with the EnergyHydrology model. If we ever had a different
566587
soil model, we might need to construct a different `PrognosticGroundConditions` because
@@ -582,7 +603,8 @@ end
582603
t,
583604
)
584605
585-
A method of Canopy.ground_albedo_PAR for a prognostic soil/snow.
606+
A method of Canopy.ground_albedo_PAR for a prognostic soil/snow. This function is called in
607+
the Canopy update_aux! function.
586608
"""
587609
function Canopy.ground_albedo_PAR(
588610
prognostic_land_components::Val{(:canopy, :snow, :soil, :soilco2)},
@@ -591,8 +613,10 @@ function Canopy.ground_albedo_PAR(
591613
p,
592614
t,
593615
)
594-
return @. (1 - p.snow.snow_cover_fraction) * p.soil.PAR_albedo +
595-
p.snow.snow_cover_fraction * ground.α_snow
616+
@. p.α_ground.PAR =
617+
(1 - p.snow.snow_cover_fraction) * p.soil.PAR_albedo +
618+
p.snow.snow_cover_fraction * ground.α_snow
619+
return p.α_ground.PAR
596620
end
597621

598622
"""
@@ -604,7 +628,8 @@ end
604628
t,
605629
)
606630
607-
A method of Canopy.ground_albedo_NIR for a prognostic soil/snow.
631+
A method of Canopy.ground_albedo_NIR for a prognostic soil/snow. This function is called in
632+
the Canopy update_aux! function.
608633
"""
609634
function Canopy.ground_albedo_NIR(
610635
prognostic_land_components::Val{(:canopy, :snow, :soil, :soilco2)},
@@ -613,8 +638,10 @@ function Canopy.ground_albedo_NIR(
613638
p,
614639
t,
615640
)
616-
return @. (1 - p.snow.snow_cover_fraction) * p.soil.NIR_albedo +
617-
p.snow.snow_cover_fraction * ground.α_snow
641+
@. p.α_ground.NIR =
642+
(1 - p.snow.snow_cover_fraction) * p.soil.NIR_albedo +
643+
p.snow.snow_cover_fraction * ground.α_snow
644+
return p.α_ground.NIR
618645
end
619646

620647
"""

0 commit comments

Comments
 (0)