Skip to content

Commit 4b9347a

Browse files
authored
remove 3 vars from canopy cache (#1179)
1 parent 7b6e13e commit 4b9347a

File tree

11 files changed

+125
-50
lines changed

11 files changed

+125
-50
lines changed

lib/ClimaLandSimulations/src/utilities/climaland_output_dataframe.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ function make_output_df(
4545
output_list = vcat(
4646
(1, :SW_u),
4747
(1, :LW_u),
48-
(1, :canopy, :conductance, :gs),
48+
(1, :canopy, :conductance, :r_stomata_canopy),
4949
(1, :canopy, :autotrophic_respiration, :Ra),
5050
(1, :canopy, :photosynthesis, :GPP),
51-
(1, :canopy, :hydraulics, ),
5251
(1, :canopy, :hydraulics, :area_index, :leaf),
5352
(1, :canopy, :turbulent_fluxes, :transpiration),
5453
(1, :canopy, :turbulent_fluxes, :lhf),

lib/ClimaLandSimulations/src/utilities/makie_plots.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,11 @@ function timeseries_H2O_fig(
197197
color = :blue,
198198
)
199199

200-
# Moisture stress
201-
p_MS = lines!(
202-
ax_MS,
203-
datetime2unix.(climaland.DateTime),
204-
climaland.β,
205-
color = :green,
206-
) # not sure about units
207-
208200
# Stomatal conductance
209201
p_SC = lines!(
210202
ax_SC,
211203
datetime2unix.(climaland.DateTime),
212-
climaland.gs,
204+
climaland.r_stomata_canopy,
213205
color = :green,
214206
)
215207

@@ -244,7 +236,7 @@ function timeseries_H2O_fig(
244236
datetime2unix(climaland.DateTime[1]),
245237
datetime2unix(climaland.DateTime[end]),
246238
),
247-
) for axes in [ax_H2O, ax_H2O_rain, ax_MS, ax_SC]
239+
) for axes in [ax_H2O, ax_H2O_rain, ax_SC]
248240
]
249241

250242
fig

src/ClimaLand.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module ClimaLand
22
using DocStringExtensions
33

44
using ClimaCore
5-
using LazyBroadcast: @lazy
5+
using LazyBroadcast: lazy
66
import ClimaCore: Fields, Spaces
77

88
include("shared_utilities/Parameters.jl")

src/diagnostics/Diagnostics.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import ..LandModel
1414

1515
import ..Soil: EnergyHydrology
1616

17+
import ..Canopy: medlyn_conductance, medlyn_term, moisture_stress
1718
import ..Domains:
1819
top_center_to_surface, AbstractDomain, SphericalShell, HybridBox
1920

src/diagnostics/land_compute_methods.jl

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,50 @@ end
8282
@diagnostic_compute "autotrophic_respiration" Union{SoilCanopyModel, LandModel} p.canopy.autotrophic_respiration.Ra
8383

8484
# Canopy - Conductance
85-
@diagnostic_compute "stomatal_conductance" Union{SoilCanopyModel, LandModel} p.canopy.conductance.gs
85+
function compute_stomatal_conductance!(
86+
out,
87+
Y,
88+
p,
89+
t,
90+
land_model::Union{SoilCanopyModel, LandModel},
91+
)
92+
canopy = land_model.canopy
93+
(; g1, g0, Drel) = canopy.conductance.parameters
94+
earth_param_set = canopy.parameters.earth_param_set
95+
thermo_params = LP.thermodynamic_parameters(earth_param_set)
96+
97+
if isnothing(out)
98+
return medlyn_conductance.(
99+
g0,
100+
Drel,
101+
medlyn_term.(
102+
g1,
103+
p.drivers.T,
104+
p.drivers.P,
105+
p.drivers.q,
106+
thermo_params,
107+
),
108+
p.canopy.photosynthesis.An,
109+
p.drivers.c_co2,
110+
)
111+
112+
113+
else
114+
@. out = medlyn_conductance(
115+
g0,
116+
Drel,
117+
medlyn_term(
118+
g1,
119+
p.drivers.T,
120+
p.drivers.P,
121+
p.drivers.q,
122+
thermo_params,
123+
),
124+
p.canopy.photosynthesis.An,
125+
p.drivers.c_co2,
126+
)
127+
end
128+
end
86129

87130
function compute_canopy_transpiration!(
88131
out,
@@ -132,7 +175,32 @@ end
132175
LandModel,
133176
} p.canopy.hydraulics.fa_roots
134177
@diagnostic_compute "leaf_area_index" Union{SoilCanopyModel, LandModel} p.canopy.hydraulics.area_index.leaf
135-
@diagnostic_compute "moisture_stress_factor" Union{SoilCanopyModel, LandModel} p.canopy.hydraulics.β
178+
# Canopy - Hydraulics
179+
function compute_moisture_stress_factor!(
180+
out,
181+
Y,
182+
p,
183+
t,
184+
land_model::Union{SoilCanopyModel, LandModel},
185+
)
186+
canopy = land_model.canopy
187+
188+
hydraulics = canopy.hydraulics
189+
n_stem = hydraulics.n_stem
190+
n_leaf = hydraulics.n_leaf
191+
n = n_stem + n_leaf
192+
193+
earth_param_set = canopy.parameters.earth_param_set
194+
grav = LP.grav(earth_param_set)
195+
ρ_l = LP.ρ_cloud_liq(earth_param_set)
196+
(; sc, pc) = canopy.photosynthesis.parameters
197+
ψ = p.canopy.hydraulics.ψ
198+
if isnothing(out)
199+
return @. moisture_stress(ψ.:($$n) * ρ_l * grav, sc, pc)
200+
else
201+
@. out = moisture_stress(ψ.:($$n) * ρ_l * grav, sc, pc)
202+
end
203+
end
136204
@diagnostic_compute "root_area_index" Union{SoilCanopyModel, LandModel} p.canopy.hydraulics.area_index.root
137205
@diagnostic_compute "stem_area_index" Union{SoilCanopyModel, LandModel} p.canopy.hydraulics.area_index.stem
138206

src/standalone/Snow/Snow.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Snow
33
using DocStringExtensions
44
import ...Parameters as LP
55
using ClimaCore
6-
using LazyBroadcast: @lazy
6+
using LazyBroadcast: lazy
77
using Thermodynamics
88
using ClimaLand
99
using ClimaLand:

src/standalone/Snow/snow_parameterizations.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ function volumetric_energy_flux_falling_snow(atmos, p, parameters)
498498
_LH_f0 = LP.LH_f0(parameters.earth_param_set)
499499
_ρ_liq = LP.ρ_cloud_liq(parameters.earth_param_set)
500500
ρe_snow = -_LH_f0 * _ρ_liq
501-
return @lazy @. ρe_snow * p.drivers.P_snow # per unit vol of liquid water
501+
return @. lazy(ρe_snow * p.drivers.P_snow) # per unit vol of liquid water
502502
end
503503

504504
"""
@@ -513,8 +513,10 @@ CoupledAtmosphere, and the energy flux of the falling rain is passed in the
513513
cache `p`. In that case, this should specify `atmos::PrescribedAtmosphere`.
514514
"""
515515
function volumetric_energy_flux_falling_rain(atmos, p, parameters)
516-
return @lazy @. volumetric_internal_energy_liq(p.drivers.T, parameters) *
517-
p.drivers.P_liq
516+
return @. lazy(
517+
volumetric_internal_energy_liq(p.drivers.T, parameters) *
518+
p.drivers.P_liq,
519+
)
518520
end
519521

520522

src/standalone/Vegetation/Canopy.jl

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Canopy
22
using DocStringExtensions
33
using Thermodynamics
44
using ClimaLand
5+
using LazyBroadcast: lazy
56
using ClimaCore
67
using ClimaCore.MatrixFields
78
import ClimaCore.MatrixFields: @name,
@@ -438,10 +439,6 @@ function ClimaLand.make_update_aux(
438439

439440
# Other auxiliary variables being updated:
440441
Ra = p.canopy.autotrophic_respiration.Ra
441-
β = p.canopy.hydraulics.β
442-
medlyn_factor = p.canopy.conductance.medlyn_term
443-
gs = p.canopy.conductance.gs # leaf level
444-
rs_canopy = p.canopy.conductance.r_stomata_canopy
445442
An = p.canopy.photosynthesis.An
446443
GPP = p.canopy.photosynthesis.GPP
447444
Rd = p.canopy.photosynthesis.Rd
@@ -461,13 +458,13 @@ function ClimaLand.make_update_aux(
461458

462459
# unpack parameters
463460
earth_param_set = canopy.parameters.earth_param_set
464-
c = FT(LP.light_speed(earth_param_set))
465-
planck_h = FT(LP.planck_constant(earth_param_set))
466-
N_a = FT(LP.avogadro_constant(earth_param_set))
467-
grav = FT(LP.grav(earth_param_set))
468-
ρ_l = FT(LP.ρ_cloud_liq(earth_param_set))
469-
R = FT(LP.gas_constant(earth_param_set))
470-
T_freeze = FT(LP.T_freeze(earth_param_set))
461+
c = LP.light_speed(earth_param_set)
462+
planck_h = LP.planck_constant(earth_param_set)
463+
N_a = LP.avogadro_constant(earth_param_set)
464+
grav = LP.grav(earth_param_set)
465+
ρ_l = LP.ρ_cloud_liq(earth_param_set)
466+
R = LP.gas_constant(earth_param_set)
467+
T_freeze = LP.T_freeze(earth_param_set)
471468
thermo_params = earth_param_set.thermo_params
472469
(; G_Function, Ω, λ_γ_PAR) = canopy.radiative_transfer.parameters
473470
energy_per_mole_photon_par = planck_h * c / λ_γ_PAR * N_a
@@ -560,14 +557,14 @@ function ClimaLand.make_update_aux(
560557
# We update the fa[n_stem+n_leaf] element once we have computed transpiration, below
561558
# update photosynthesis and conductance terms
562559
# This should still use T_air, P_air, q_air
563-
medlyn_factor .=
564-
medlyn_term.(g1, T_air, P_air, q_air, Ref(thermo_params))
560+
medlyn_factor =
561+
@. lazy(medlyn_term(g1, T_air, P_air, q_air, thermo_params))
565562
# Anywhere we use an Arrhenius factor, use T_canopy instead T_air
566563
T_canopy = canopy_temperature(canopy.energy, canopy, Y, p, t)
567564

568565
# update moisture stress
569566
i_end = n_stem + n_leaf
570-
@. β = moisture_stress(ψ.:($$i_end) * ρ_l * grav, sc, pc)
567+
β = @. lazy(moisture_stress(ψ.:($$i_end) * ρ_l * grav, sc, pc))
571568

572569
# Update Rd, An, Vcmax25 (if applicable to model) in place
573570
Vcmax25 = p.canopy.photosynthesis.Vcmax25
@@ -600,8 +597,14 @@ function ClimaLand.make_update_aux(
600597
par_d,
601598
)
602599
@. GPP = compute_GPP(An, extinction_coeff(G_Function, cosθs), LAI, Ω)
603-
@. gs = medlyn_conductance(g0, Drel, medlyn_factor, An, c_co2_air)
604-
@. rs_canopy = 1 / upscale_leaf_conductance(gs, LAI, T_air, R, P_air)
600+
@. p.canopy.conductance.r_stomata_canopy =
601+
1 / upscale_leaf_conductance(
602+
medlyn_conductance(g0, Drel, medlyn_factor, An, c_co2_air), #conductance, leaf level
603+
LAI,
604+
T_air,
605+
R,
606+
P_air,
607+
)
605608
# update autotrophic respiration
606609
h_canopy = hydraulics.compartment_surfaces[end]
607610
@. Ra = compute_autrophic_respiration(

src/standalone/Vegetation/PlantHydraulics.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,11 @@ prognostic_vars(model::PlantHydraulicsModel) = (:ϑ_l,)
287287
288288
A function which returns the names of the auxiliary
289289
variables of the `PlantHydraulicsModel`,
290-
the transpiration stress factor `β` (unitless),
291290
the water potential `ψ` (m), the volume flux*cross section `fa` (1/s),
292291
and the volume flux*root cross section in the roots `fa_roots` (1/s),
293292
where the cross section can be represented by an area index.
294293
"""
295-
auxiliary_vars(model::PlantHydraulicsModel) =
296-
(, , :fa, :fa_roots, :area_index)
294+
auxiliary_vars(model::PlantHydraulicsModel) = (, :fa, :fa_roots, :area_index)
297295

298296
"""
299297
ClimaLand.prognostic_types(model::PlantHydraulicsModel{FT}) where {FT}
@@ -310,14 +308,13 @@ ClimaLand.prognostic_domain_names(::PlantHydraulicsModel) = (:surface,)
310308
Defines the auxiliary types for the PlantHydraulicsModel.
311309
"""
312310
ClimaLand.auxiliary_types(model::PlantHydraulicsModel{FT}) where {FT} = (
313-
FT,
314311
NTuple{model.n_stem + model.n_leaf, FT},
315312
NTuple{model.n_stem + model.n_leaf, FT},
316313
FT,
317314
NamedTuple{(:root, :stem, :leaf), Tuple{FT, FT, FT}},
318315
)
319316
ClimaLand.auxiliary_domain_names(::PlantHydraulicsModel) =
320-
(:surface, :surface, :surface, :surface, :surface)
317+
(:surface, :surface, :surface, :surface)
321318

322319
function clip(x::FT, threshold::FT) where {FT}
323320
x > threshold ? x : FT(0)

src/standalone/Vegetation/stomatalconductance.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ end
3838

3939
ClimaLand.name(model::AbstractStomatalConductanceModel) = :conductance
4040

41-
ClimaLand.auxiliary_vars(model::MedlynConductanceModel) =
42-
(:medlyn_term, :gs, :r_stomata_canopy)
43-
ClimaLand.auxiliary_types(model::MedlynConductanceModel{FT}) where {FT} =
44-
(FT, FT, FT)
45-
ClimaLand.auxiliary_domain_names(::MedlynConductanceModel) =
46-
(:surface, :surface, :surface)
41+
ClimaLand.auxiliary_vars(model::MedlynConductanceModel) = (:r_stomata_canopy,)
42+
ClimaLand.auxiliary_types(model::MedlynConductanceModel{FT}) where {FT} = (FT,)
43+
ClimaLand.auxiliary_domain_names(::MedlynConductanceModel) = (:surface,)

0 commit comments

Comments
 (0)