Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisRenchon committed Jul 27, 2024
1 parent e33f4a8 commit 0c247a9
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 27 deletions.
15 changes: 9 additions & 6 deletions ext/CreateParametersExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ClimaLand.Soil.EnergyHydrologyParameters
import ClimaLand.Canopy.AutotrophicRespirationParameters
import ClimaLand.Canopy.FarquharParameters
import ClimaLand.Canopy.OptimalityFarquharParameters
import ClimaLand.Canopy.SIFParameters
import ClimaLand.Canopy.MedlynConductanceParameters
import ClimaLand.Canopy.BeerLambertParameters
import ClimaLand.Canopy.TwoStreamParameters
Expand Down Expand Up @@ -203,13 +204,15 @@ toml_dict = CP.create_toml_dict(Float32);
ClimaLand.Canopy.OptimalityFarquharParameters(toml_dict; pc = 444444444)
```
"""
OptimalityFarquharParameters(
function OptimalityFarquharParameters(
::Type{FT};
kwargs...,
) where {FT <: AbstractFloat} =
OptimalityFarquharParameters(CP.create_toml_dict(FT); kwargs...)
) where {FT <: AbstractFloat}
sif_parameters = SIFParameters{FT}()
OptimalityFarquharParameters(CP.create_toml_dict(FT), sif_parameters; kwargs...)
end

function OptimalityFarquharParameters(toml_dict; kwargs...)
function OptimalityFarquharParameters(toml_dict, sif_parameters; kwargs...)
name_map = (;
:Jmax_activation_energy => :ΔHJmax,
:intercellular_O2_concentration => :oi,
Expand All @@ -229,11 +232,11 @@ function OptimalityFarquharParameters(toml_dict; kwargs...)
:CO2_activation_energy => :ΔHkc,
:moisture_stress_ref_water_pressure => :pc,
)

params = CP.get_parameter_values(toml_dict, name_map, "Land")
FT = CP.float_type(toml_dict)
mechanism = ClimaLand.Canopy.C3()
return OptimalityFarquharParameters{FT}(; params..., kwargs..., mechanism)
return OptimalityFarquharParameters{FT, typeof(sif_parameters)}(; sif_parameters, params..., kwargs..., mechanism)
end


Expand Down
2 changes: 2 additions & 0 deletions src/standalone/Vegetation/Canopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,12 @@ function ClimaLand.make_update_aux(

# Update Rd, An, Vcmax25 (if applicable to model) in place
Vcmax25 = p.canopy.photosynthesis.Vcmax25
SIF == p.canopy.photosynthesis.SIF
update_photosynthesis!(
Rd,
An,
Vcmax25,
SIF,
canopy.photosynthesis,
T_canopy,
p.canopy.radiative_transfer.par.abs,
Expand Down
13 changes: 6 additions & 7 deletions src/standalone/Vegetation/canopy_parameterizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1057,17 +1057,16 @@ function compute_SIF_at_a_point(
Tc::FT,
Vcmax25::FT,
R::FT,
photosynthesis_params,
sif_params,
photosynthesis_parameters,
) where {FT}

(; ΔHJmax, To, θj, ϕ) = photosynthesis_parameters
Jmax = max_electron_transport(Vcmax25, ΔHJmax, T, To, R)
(; ΔHJmax, To, θj, ϕ, sif_parameters) = photosynthesis_parameters
Jmax = max_electron_transport(Vcmax25, ΔHJmax, Tc, To, R)
J = electron_transport(APAR, Jmax, θj, ϕ)
(; kf, kd_p1, kd_p2, min_kd, kn_p1, kn_p2, kp, kappa_p1, kappa_p2) =
sif_params
Tf = 273.15
kd = maximum(kd_p1 * (Tc - Tf) + kd_p2, min_kd)
sif_parameters
Tf = FT(273.15)
kd = max(kd_p1 * (Tc - Tf) + kd_p2, min_kd)
x = 1 - J / Jmax
kn = (kn_p1 * x - kn_p2) * x
ϕp0 = kp / (kf + kp + kn)
Expand Down
22 changes: 17 additions & 5 deletions src/standalone/Vegetation/optimality_farquhar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The required parameters for the optimality Farquhar photosynthesis model.
Currently, only C3 photosynthesis is supported.
$(DocStringExtensions.FIELDS)
"""
Base.@kwdef struct OptimalityFarquharParameters{FT <: AbstractFloat}
Base.@kwdef struct OptimalityFarquharParameters{FT <: AbstractFloat, SP}
"Photosynthesis mechanism: C3 only"
mechanism::C3
"Γstar at 25 °C (mol/mol)"
Expand Down Expand Up @@ -45,6 +45,8 @@ Base.@kwdef struct OptimalityFarquharParameters{FT <: AbstractFloat}
pc::FT
"Constant describing cost of maintaining electron transport (unitless)"
c::FT
"SIF Parameters"
sif_parameters::SP
end

Base.eltype(::OptimalityFarquharParameters{FT}) where {FT} = FT
Expand Down Expand Up @@ -72,14 +74,14 @@ function OptimalityFarquharModel{FT}(
end

ClimaLand.auxiliary_vars(model::OptimalityFarquharModel) =
(:An, :GPP, :Rd, :Vcmax25)
(:An, :GPP, :Rd, :Vcmax25, :SIF)
ClimaLand.auxiliary_types(model::OptimalityFarquharModel{FT}) where {FT} =
(FT, FT, FT, FT)
(FT, FT, FT, FT, FT)
ClimaLand.auxiliary_domain_names(::OptimalityFarquharModel) =
(:surface, :surface, :surface, :surface)
(:surface, :surface, :surface, :surface, :surface)

"""
update_photosynthesis!(Rd, An, Vcmax25,
update_photosynthesis!(Rd, An, Vcmax25,SIF,
model::OptimalityFarquharModel,
T,
APAR,
Expand All @@ -101,6 +103,7 @@ function update_photosynthesis!(
Rd,
An,
Vcmax25,
SIF,
model::OptimalityFarquharModel,
T,
APAR,
Expand Down Expand Up @@ -152,4 +155,13 @@ function update_photosynthesis!(
@. Vcmax25 = Vcmax / arrhenius_function(T, To, R, ΔHVcmax)
@. Rd = dark_respiration(Vcmax25, β, f, ΔHRd, T, To, R)
@. An = net_photosynthesis(Ac, Aj, Rd, β)
@. SIF = compute_SIF_at_a_point(
APAR,
T,
Vcmax25,
R,
model.parameters,
)
end
Base.broadcastable(m::OptimalityFarquharParameters) = tuple(m)

9 changes: 3 additions & 6 deletions src/standalone/Vegetation/photosynthesis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,13 @@ struct FarquharModel{FT, FP <: FarquharParameters{FT}} <:
end

function FarquharModel{FT}(
parameters::FarquharParameters{FT};
sif_parameters = SIFParameters{FT}(),
parameters::FarquharParameters{FT}
) where {FT <: AbstractFloat}
return FarquharModel{
eltype(parameters),
typeof(parameters),
typeof(sif_parameters),
}(
parameters,
sif_parameters,
)
end

Expand Down Expand Up @@ -166,7 +163,7 @@ function photosynthesis_at_a_point_Farquhar(
end

"""
update_photosynthesis!(Rd, An, Vcmax25,
update_photosynthesis!(Rd, An, Vcmax25, SIF,
model::FarquharModel,
T,
APAR,
Expand All @@ -188,6 +185,7 @@ function update_photosynthesis!(
Rd,
An,
Vcmax25field,
SIF,
model::FarquharModel,
T,
APAR,
Expand Down Expand Up @@ -216,7 +214,6 @@ function update_photosynthesis!(
Vcmax25,
R,
model.parameters,
model.sif_parameters,
)

end
Expand Down
9 changes: 6 additions & 3 deletions test/standalone/Vegetation/test_bigleaf_parameterizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ for FT in (Float32, Float64)
params = OptimalityFarquharParameters(FT)
@test params.mechanism == C3()
model = OptimalityFarquharModel(params)
@test ClimaLand.auxiliary_vars(model) == (:An, :GPP, :Rd, :Vcmax25)
@test ClimaLand.auxiliary_types(model) == (FT, FT, FT, FT)
@test ClimaLand.auxiliary_vars(model) == (:An, :GPP, :Rd, :Vcmax25, :SIF)
@test ClimaLand.auxiliary_types(model) == (FT, FT, FT, FT, FT)
@test ClimaLand.auxiliary_domain_names(model) ==
(:surface, :surface, :surface, :surface)
(:surface, :surface, :surface, :surface, :surface)
Rd = zeros(FT, 1)
An = similar(Rd)
Vcmax25 = similar(An)
SIF = similar(An)
T = FT(280)
β = FT(1)
medlyn_factor = FT(10.0)
Expand All @@ -57,6 +58,7 @@ for FT in (Float32, Float64)
Rd,
An,
Vcmax25,
SIF,
model,
T,
APAR,
Expand All @@ -68,6 +70,7 @@ for FT in (Float32, Float64)
@test Rd[1] != 0.0
@test Vcmax25[1] != 0.0
@test An[1] != 0.0
@test SIF[1] !=0.0
end

@testset "Big Leaf Parameterizations, FT = $FT" begin
Expand Down

0 comments on commit 0c247a9

Please sign in to comment.