Skip to content

Commit

Permalink
Refactor SoilCO2ModelParameters constructor (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
nefrathenrici authored Mar 19, 2024
1 parent a370aa8 commit 8152587
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 244 deletions.
14 changes: 1 addition & 13 deletions docs/src/standalone/apps/hetero_resp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,7 @@ function ParamViz.parameterisation(
D_oa,
) # constants

params = SoilCO2ModelParameters{FT}(;
ν = ν,
θ_a100 = θ_a100,
D_liq = D_liq,
α_sx = α_sx,
Ea_sx = Ea_sx,
kM_sx = kM_sx,
kM_o2 = kM_O₂,
O2_a = O₂_a,
D_oa = D_oa,
p_sx = p_sx,
earth_param_set = earth_param_set,
)
params = SoilCO2ModelParameters(FT; ν)
# θ has to be lower than porosity
if θ > ν
θ = ν
Expand Down
29 changes: 1 addition & 28 deletions docs/tutorials/integrated/soil_canopy_tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,36 +172,9 @@ soil_model_type = Soil.EnergyHydrology{FT}
# [documentation](https://clima.github.io/ClimaLand.jl/previews/PR214/dynamicdocs/pages/soil_biogeochemistry/microbial_respiration/)
# to understand the parameterisation.
# The domain is defined similarly to the soil domain described above.
ν = soil_ν # defined above
θ_a100 = FT(0.1816)
D_ref = FT(1.39e-5)
b = FT(4.547)
D_liq = FT(3.17)
α_sx = FT(194e3)
Ea_sx = FT(61e3)
kM_sx = FT(5e-3)
kM_o2 = FT(0.004)
O2_a = FT(0.209)
D_oa = FT(1.67)
p_sx = FT(0.024)

soilco2_type = Soil.Biogeochemistry.SoilCO2Model{FT}

soilco2_ps = SoilCO2ModelParameters{FT}(;
ν = soil_ν,
θ_a100 = θ_a100,
D_ref = D_ref,
b = b,
D_liq = D_liq,
α_sx = α_sx,
Ea_sx = Ea_sx,
kM_sx = kM_sx,
kM_o2 = kM_o2,
O2_a = O2_a,
D_oa = D_oa,
p_sx = p_sx,
earth_param_set = earth_param_set,
);
soilco2_ps = SoilCO2ModelParameters(FT; ν = soil_ν);

# soil microbes args
Csom = (z, t) -> eltype(z)(5); # kg C m⁻³, this is a guess, not measured at the site
Expand Down
15 changes: 0 additions & 15 deletions experiments/integrated/fluxnet/US-Ha1/US-Ha1_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@ long = FT(-72.1715) # degree
atmos_h = FT(30)
# https://atmos.seas.harvard.edu/research-harvard_forest-instrumentation

## LAI data from MODIS
# Heterotrophic respiration parameters
θ_a100 = FT(0.1816)
D_ref = FT(1.39e-5)
b = FT(4.547)
D_liq = FT(3.17)
# DAMM
α_sx = FT(194e3)
Ea_sx = FT(61e3)
kM_sx = FT(5e-3)
kM_o2 = FT(0.004)
O2_a = FT(0.209)
D_oa = FT(1.67)
p_sx = FT(0.024)

# Soil parameters
soil_ν = FT(0.5) # m3/m3
soil_K_sat = FT(4e-7) # m/s, matches Natan
Expand Down
14 changes: 0 additions & 14 deletions experiments/integrated/fluxnet/US-MOz/US-MOz_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@ atmos_h = FT(32)
lat = FT(38.7441) # degree
long = FT(-92.2000) # degree

# Heterotrophic respiration parameters
θ_a100 = FT(0.1816)
D_ref = FT(1.39e-5)
b = FT(4.547)
D_liq = FT(3.17)
# DAMM
α_sx = FT(194e3)
Ea_sx = FT(61e3)
kM_sx = FT(5e-3)
kM_o2 = FT(0.004)
O2_a = FT(0.209)
D_oa = FT(1.67)
p_sx = FT(0.024)

# Soil parameters
soil_ν = FT(0.5) # m3/m3
soil_K_sat = FT(4e-7) # m/s, matches Natan
Expand Down
15 changes: 0 additions & 15 deletions experiments/integrated/fluxnet/US-NR1/US-NR1_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@ atmos_h = FT(21.5)
# gas analyzer sampling system for measuring eddy covariance fluxes of H2O and
# CO2. Atmospheric Measurement Techniques. 9. 1341-1359. 10.5194/amt-9-1341-2016.

## LAI data from MODIS
# Heterotrophic respiration parameters
θ_a100 = FT(0.1816)
D_ref = FT(1.39e-5)
b = FT(4.547)
D_liq = FT(3.17)
# DAMM
α_sx = FT(194e3)
Ea_sx = FT(61e3)
kM_sx = FT(5e-3)
kM_o2 = FT(0.004)
O2_a = FT(0.209)
D_oa = FT(1.67)
p_sx = FT(0.024)

# Soil parameters
soil_ν = FT(0.45) # m3/m3
soil_K_sat = FT(4e-7) # m/s, matches Natan
Expand Down
14 changes: 0 additions & 14 deletions experiments/integrated/fluxnet/US-Var/US-Var_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,6 @@ time_offset = 8
lat = FT(38.4133) # degree
long = FT(-120.9508) # degree

# Heterotrophic respiration parameters
θ_a100 = FT(0.1816)
D_ref = FT(1.39e-5)
b = FT(4.547)
D_liq = FT(3.17)
# DAMM
α_sx = FT(194e3)
Ea_sx = FT(61e3)
kM_sx = FT(5e-3)
kM_o2 = FT(0.004)
O2_a = FT(0.209)
D_oa = FT(1.67)
p_sx = FT(0.024)

# Soil parameters
soil_ν = FT(0.45) # m3/m3
soil_K_sat = FT(0.45 / 3600 / 100) # m/s,
Expand Down
16 changes: 2 additions & 14 deletions experiments/integrated/fluxnet/ozark_pft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,9 @@ soil_model_type = Soil.EnergyHydrology{FT}
# Soil microbes model
soilco2_type = Soil.Biogeochemistry.SoilCO2Model{FT}

soilco2_ps = SoilCO2ModelParameters{FT}(;
soilco2_ps = SoilCO2ModelParameters(
FT;
ν = soil_ν, # same as soil
θ_a100 = θ_a100,
D_ref = D_ref,
b = b,
D_liq = D_liq,
# DAMM
α_sx = α_sx,
Ea_sx = Ea_sx,
kM_sx = kM_sx,
kM_o2 = kM_o2,
O2_a = O2_a,
D_oa = D_oa,
p_sx = p_sx,
earth_param_set = earth_param_set,
)

# soil microbes args
Expand Down
16 changes: 2 additions & 14 deletions experiments/integrated/fluxnet/run_fluxnet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,9 @@ soil_model_type = Soil.EnergyHydrology{FT}
# Soil microbes model
soilco2_type = Soil.Biogeochemistry.SoilCO2Model{FT}

soilco2_ps = SoilCO2ModelParameters{FT}(;
soilco2_ps = SoilCO2ModelParameters(
FT;
ν = soil_ν, # same as soil
θ_a100 = θ_a100,
D_ref = D_ref,
b = b,
D_liq = D_liq,
# DAMM
α_sx = α_sx,
Ea_sx = Ea_sx,
kM_sx = kM_sx,
kM_o2 = kM_o2,
O2_a = O2_a,
D_oa = D_oa,
p_sx = p_sx,
earth_param_set = earth_param_set,
)

# soil microbes args
Expand Down
17 changes: 1 addition & 16 deletions experiments/integrated/ozark/conservation/ozark_conservation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,7 @@ for float_type in (Float32, Float64)
# Soil microbes model
soilco2_type = Soil.Biogeochemistry.SoilCO2Model{FT}

soilco2_ps = SoilCO2ModelParameters{FT}(;
ν = soil_ν,
θ_a100 = θ_a100,
D_ref = D_ref,
b = b,
D_liq = D_liq,
# DAMM
α_sx = α_sx,
Ea_sx = Ea_sx,
kM_sx = kM_sx,
kM_o2 = kM_o2,
O2_a = O2_a,
D_oa = D_oa,
p_sx = p_sx,
earth_param_set = earth_param_set,
)
soilco2_ps = SoilCO2ModelParameters(FT; ν = soil_ν)

# soil microbes args
Csom = (z, t) -> eltype(z)(5.0)
Expand Down
4 changes: 1 addition & 3 deletions experiments/standalone/Biogeochemistry/experiment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ for (FT, tf) in ((Float32, 2 * dt), (Float64, tf))
# Make biogeochemistry model args
Csom = (z, t) -> eltype(z)(5.0)

co2_parameters = Soil.Biogeochemistry.SoilCO2ModelParameters{FT}(;
earth_param_set = earth_param_set,
)
co2_parameters = Soil.Biogeochemistry.SoilCO2ModelParameters(FT; ν = 0.556)
C = FT(100)

co2_top_bc = Soil.Biogeochemistry.SoilCO2StateBC((p, t) -> 0.0)
Expand Down
49 changes: 43 additions & 6 deletions ext/CreateParametersExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import SurfaceFluxes.UniversalFunctions as UF
import ClimaParams as CP

import ClimaLand
import ClimaLand.Parameters.LandParameters
import ClimaLand.Soil
# Parameter structs
import ClimaLand.Parameters as LP
import ClimaLand.Soil.EnergyHydrologyParameters
import ClimaLand.Canopy.AutotrophicRespirationParameters
import ClimaLand.Canopy.FarquharParameters
import ClimaLand.Canopy.OptimalityFarquharParameters
import ClimaLand.Bucket.BucketModelParameters

import ClimaLand.Soil
import ClimaLand.Parameters as LP
import ClimaLand.Soil.EnergyHydrologyParameters
import ClimaLand.Soil.Biogeochemistry.SoilCO2ModelParameters

LP.LandParameters(::Type{FT}) where {FT <: AbstractFloat} =
LP.LandParameters(CP.create_toml_dict(FT))
Expand Down Expand Up @@ -442,7 +442,7 @@ function BucketModelParameters(
parameters = CP.get_parameter_values(toml_dict, name_map, "Land")

AAM = typeof(albedo)
earth_param_set = LandParameters(toml_dict)
earth_param_set = LP.LandParameters(toml_dict)
PSE = typeof(earth_param_set)
FT = CP.float_type(toml_dict)
BucketModelParameters{FT, AAM, PSE}(;
Expand All @@ -456,5 +456,42 @@ function BucketModelParameters(
)
end

"""
SoilCO2ModelParameters(FT; kwargs...)
SoilCO2ModelParameters(toml_dict; kwargs...)
SoilCO2ModelParameters has two constructors: float-type and toml dict based.
Keywords arguments can be used to directly override any parameters.
"""
SoilCO2ModelParameters(::Type{FT}; kwargs...) where {FT <: AbstractFloat} =
SoilCO2ModelParameters(CP.create_toml_dict(FT); kwargs...)

function SoilCO2ModelParameters(toml_dict::CP.AbstractTOMLDict; kwargs...)
# These parameters have defaults that should not go in ClimaParams
θ_a100 = 0.1816
b = 4.547

name_map = (;
:CO2_diffusion_coefficient => :D_ref,
:soil_C_substrate_diffusivity => :D_liq,
:soilCO2_pre_expontential_factor => :α_sx,
:soilCO2_activation_energy => :Ea_sx,
:michaelis_constant => :kM_sx,
:O2_michaelis_constant => :kM_o2,
:O2_volume_fraction => :O2_a,
:oxygen_diffusion_coefficient => :D_oa,
:soluble_soil_carbon_fraction => :p_sx,
)
parameters = CP.get_parameter_values(toml_dict, name_map, "Land")
FT = CP.float_type(toml_dict)
earth_param_set = LP.LandParameters(toml_dict)
return SoilCO2ModelParameters{FT, typeof(earth_param_set)}(;
earth_param_set,
θ_a100,
b,
parameters...,
kwargs...,
)
end

end
3 changes: 2 additions & 1 deletion lib/ClimaLandSimulations/src/Fluxnet/run_fluxnet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function run_fluxnet(
# Soil microbes model
soilco2_type = Soil.Biogeochemistry.SoilCO2Model{FT}

soilco2_ps = SoilCO2ModelParameters{FT}(;
soilco2_ps = SoilCO2ModelParameters(
FT;
ν = params.soil.ν,
θ_a100 = params.hetero_resp.θ_a100,
D_ref = params.hetero_resp.D_ref,
Expand Down
58 changes: 1 addition & 57 deletions src/standalone/Soil/Biogeochemistry/Biogeochemistry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export SoilCO2ModelParameters,
A struct for storing parameters of the `SoilCO2Model`.
$(DocStringExtensions.FIELDS)
"""
struct SoilCO2ModelParameters{FT <: AbstractFloat, PSE}
Base.@kwdef struct SoilCO2ModelParameters{FT <: AbstractFloat, PSE}
"Soil porosity (m³ m⁻³)"
ν::FT
"Air-filled porosity at soil water potential of -100 cm H₂O (~ 10 Pa)"
Expand Down Expand Up @@ -71,62 +71,6 @@ struct SoilCO2ModelParameters{FT <: AbstractFloat, PSE}
earth_param_set::PSE
end

"""
SoilCO2ModelParameters{FT}(;
ν = FT(0.556),
θ_a100 = FT(0.1816),
D_ref = FT(1.39e-5),
b = FT(4.547),
D_liq = FT(3.17),
# DAMM
α_sx = FT(194e3),
Ea_sx = FT(61e3),
kM_sx = FT(5e-3),
kM_o2 = FT(0.004),
O2_a = FT(0.209),
D_oa = FT(1.67),
p_sx = FT(0.024),
earth_param_set::PSE
) where {FT, PSE}
An outer constructor for creating the parameter struct of the `SoilCO2Model`,
based on keyword arguments.
"""
function SoilCO2ModelParameters{FT}(;
ν = FT(0.556),
θ_a100 = FT(0.1816),
D_ref = FT(1.39e-5),
b = FT(4.547),
D_liq = FT(3.17),
# DAMM
α_sx = FT(194e3), # kgC m⁻³ s⁻¹
Ea_sx = FT(61e3), # J mol⁻¹
kM_sx = FT(5e-3), # kgC m⁻³
kM_o2 = FT(0.004), # L L⁻¹
O2_a = FT(0.209),
D_oa = FT(1.67),
p_sx = FT(0.024),
earth_param_set::PSE,
) where {FT, PSE}
return SoilCO2ModelParameters{FT, PSE}(
ν,
θ_a100,
D_ref,
b,
D_liq,
# DAMM
α_sx,
Ea_sx,
kM_sx,
kM_o2,
O2_a,
D_oa,
p_sx,
earth_param_set,
)
end

"""
AbstractSoilBiogeochemistryModel{FT} <: ClimaLand.AbstractExpModel{FT}
Expand Down
Loading

0 comments on commit 8152587

Please sign in to comment.