From 316461752a205d37f9b8163c11a99818f13afc1c Mon Sep 17 00:00:00 2001 From: nefrathenrici Date: Fri, 16 Feb 2024 15:35:28 -0800 Subject: [PATCH] Use ClimaParameters for EnergyHydrologyParameters --- .../integrated/soil_canopy_tutorial.jl | 3 +- .../standalone/Soil/freezing_front.jl | 25 ++- .../standalone/Soil/soil_energy_hydrology.jl | 34 ++-- experiments/integrated/fluxnet/run_fluxnet.jl | 12 +- .../ozark/conservation/ozark_conservation.jl | 12 +- .../standalone/Biogeochemistry/experiment.jl | 21 ++- experiments/standalone/Soil/evaporation.jl | 34 ++-- ext/CreateParametersExt.jl | 165 +++++++++++++++++- .../fluxnet_sites/US-Ha1/US-Ha1_parameters.jl | 30 ++-- .../fluxnet_sites/US-MOz/US-MOz_parameters.jl | 30 ++-- .../fluxnet_sites/US-NR1/US-NR1_parameters.jl | 30 ++-- .../fluxnet_sites/US-Var/US-Var_parameters.jl | 30 ++-- .../src/Fluxnet/run_fluxnet.jl | 4 +- src/standalone/Soil/energy_hydrology.jl | 107 +----------- .../soil_energy_hydrology_biogeochemistry.jl | 22 +-- test/standalone/Soil/climate_drivers.jl | 28 +-- test/standalone/Soil/soil_bc.jl | 66 +++---- .../standalone/Soil/soil_parameterizations.jl | 36 ++-- test/standalone/Soil/soil_test_3d.jl | 22 +-- test/standalone/Soil/soiltest.jl | 84 ++++----- 20 files changed, 423 insertions(+), 372 deletions(-) diff --git a/docs/tutorials/integrated/soil_canopy_tutorial.jl b/docs/tutorials/integrated/soil_canopy_tutorial.jl index 958fb04b04..1e12f93148 100644 --- a/docs/tutorials/integrated/soil_canopy_tutorial.jl +++ b/docs/tutorials/integrated/soil_canopy_tutorial.jl @@ -147,7 +147,8 @@ soil_α_PAR = FT(0.2) soil_α_NIR = FT(0.4) soil_domain = land_domain -soil_ps = Soil.EnergyHydrologyParameters{FT}(; +soil_ps = Soil.EnergyHydrologyParameters( + FT; ν = soil_ν, ν_ss_om = ν_ss_om, ν_ss_quartz = ν_ss_quartz, diff --git a/docs/tutorials/standalone/Soil/freezing_front.jl b/docs/tutorials/standalone/Soil/freezing_front.jl index 77df05a4f0..591dd94934 100644 --- a/docs/tutorials/standalone/Soil/freezing_front.jl +++ b/docs/tutorials/standalone/Soil/freezing_front.jl @@ -88,11 +88,10 @@ using ClimaLand.Soil import ClimaLand import ClimaLand.Parameters as LP -# # Preliminary set-up +# Preliminary set-up # Choose a floating point precision, and get the parameter set, which holds constants used across CliMA models: FT = Float32 -earth_param_set = LP.LandParameters(FT); # Set the values of other parameters required by the model: ν = FT(0.535) @@ -100,7 +99,7 @@ K_sat = FT(3.2e-6) # m/s S_s = FT(1e-3) #inverse meters vg_n = FT(1.48) vg_α = FT(1.11) # inverse meters -hcm = vanGenuchten{FT}(; α = vg_α, n = vg_n); +hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n); # You could also try the Brooks and Corey model: #ψb = FT(-0.6) #c = FT(0.43) @@ -109,16 +108,16 @@ hcm = vanGenuchten{FT}(; α = vg_α, n = vg_n); ν_ss_om = FT(0.3) ν_ss_quartz = FT(0.7) ν_ss_gravel = FT(0.0) -params = Soil.EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hcm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - earth_param_set = earth_param_set, +params = Soil.EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, ); # Choose the domain and discretization: zmax = FT(0) diff --git a/docs/tutorials/standalone/Soil/soil_energy_hydrology.jl b/docs/tutorials/standalone/Soil/soil_energy_hydrology.jl index c56ecac3b7..72f1632a73 100644 --- a/docs/tutorials/standalone/Soil/soil_energy_hydrology.jl +++ b/docs/tutorials/standalone/Soil/soil_energy_hydrology.jl @@ -100,34 +100,34 @@ earth_param_set = LP.LandParameters(FT); # # Create the model # Set the values of other parameters required by the model: -ν = FT(0.395); +ν = 0.395 # Soil solids # are the components of soil besides water, ice, gases, and air. # We specify the soil component fractions, relative to all soil solids. # These do not sum to unity; the remainder is ν_ss_minerals (=0.08, in this case). -ν_ss_quartz = FT(0.92) -ν_ss_om = FT(0.0) -ν_ss_gravel = FT(0.0); +ν_ss_quartz = 0.92 +ν_ss_om = 0.0 +ν_ss_gravel = 0.0 # Other parameters include the hydraulic conductivity at saturation, the specific # storage, and the van Genuchten parameters for sand. # We recommend Chapter 8 of Bonan (2019) for finding parameters # for other soil types. -Ksat = FT(4.42 / 3600 / 100) # m/s -S_s = FT(1e-3) #inverse meters +Ksat = 4.42 / 3600 / 100 # m/s +S_s = 1e-3 #inverse meters vg_n = FT(1.89) vg_α = FT(7.5) # inverse meters -hcm = vanGenuchten{FT}(; α = vg_α, n = vg_n); -θ_r = FT(0.0); -params = Soil.EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hcm, +hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n) +θ_r = 0.0 +params = Soil.EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, K_sat = Ksat, - S_s = S_s, - θ_r = θ_r, - earth_param_set = earth_param_set, + S_s, + θ_r, ); # We also need to pick a domain on which to solve the equations: diff --git a/experiments/integrated/fluxnet/run_fluxnet.jl b/experiments/integrated/fluxnet/run_fluxnet.jl index 1596712019..9e969b661c 100644 --- a/experiments/integrated/fluxnet/run_fluxnet.jl +++ b/experiments/integrated/fluxnet/run_fluxnet.jl @@ -69,16 +69,16 @@ include( # Now we set up the model. For the soil model, we pick # a model type and model args: soil_domain = land_domain -soil_ps = Soil.EnergyHydrologyParameters{FT}(; +soil_ps = Soil.EnergyHydrologyParameters( + FT; ν = soil_ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, hydrology_cm = vanGenuchten{FT}(; α = soil_vg_α, n = soil_vg_n), K_sat = soil_K_sat, S_s = soil_S_s, - θ_r = θ_r, - earth_param_set = earth_param_set, + θ_r, z_0m = z_0m_soil, z_0b = z_0b_soil, emissivity = soil_ϵ, diff --git a/experiments/integrated/ozark/conservation/ozark_conservation.jl b/experiments/integrated/ozark/conservation/ozark_conservation.jl index ff4d0243d2..930ec04c07 100644 --- a/experiments/integrated/ozark/conservation/ozark_conservation.jl +++ b/experiments/integrated/ozark/conservation/ozark_conservation.jl @@ -70,16 +70,16 @@ for float_type in (Float32, Float64) # Now we set up the model. For the soil model, we pick # a model type and model args: soil_domain = land_domain - soil_ps = Soil.EnergyHydrologyParameters{FT}(; + soil_ps = Soil.EnergyHydrologyParameters( + FT; ν = soil_ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, hydrology_cm = vanGenuchten{FT}(; α = soil_vg_α, n = soil_vg_n), K_sat = soil_K_sat, S_s = soil_S_s, - θ_r = θ_r, - earth_param_set = earth_param_set, + θ_r, z_0m = z_0m_soil, z_0b = z_0b_soil, emissivity = soil_ϵ, diff --git a/experiments/standalone/Biogeochemistry/experiment.jl b/experiments/standalone/Biogeochemistry/experiment.jl index 2c572c9d37..f4cb9b4a8b 100644 --- a/experiments/standalone/Biogeochemistry/experiment.jl +++ b/experiments/standalone/Biogeochemistry/experiment.jl @@ -25,21 +25,20 @@ for (FT, tf) in ((Float32, 2 * dt), (Float64, tf)) S_s = FT(1e-3) #inverse meters vg_n = FT(2.0) vg_α = FT(2.6) # inverse meters - hcm = vanGenuchten{FT}(; α = vg_α, n = vg_n) θ_r = FT(0.1) ν_ss_om = FT(0.0) ν_ss_quartz = FT(1.0) ν_ss_gravel = FT(0.0) - soil_ps = Soil.EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hcm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - earth_param_set = earth_param_set, + soil_ps = Soil.EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n), + K_sat, + S_s, + θ_r, ) zmax = FT(0) diff --git a/experiments/standalone/Soil/evaporation.jl b/experiments/standalone/Soil/evaporation.jl index 20a856ca6b..e7844207ab 100644 --- a/experiments/standalone/Soil/evaporation.jl +++ b/experiments/standalone/Soil/evaporation.jl @@ -33,7 +33,7 @@ for (FT, tf) in ((Float32, 2 * dt), (Float64, tf)) # n and alpha estimated by matching vG curve. vg_n = FT(10.0) vg_α = FT(6.0) - hcm = vanGenuchten{FT}(; α = vg_α, n = vg_n) + hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n) # Alternative parameters for Brooks Corey water retention model #ψb = FT(-0.14) #c = FT(5.5) @@ -92,22 +92,22 @@ for (FT, tf) in ((Float32, 2 * dt), (Float64, tf)) zero_flux = FluxBC((p, t) -> 0) boundary_fluxes = (; top = top_bc, bottom = (water = zero_flux, heat = zero_flux)) - params = ClimaLand.Soil.EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hcm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - PAR_albedo = PAR_albedo, - NIR_albedo = NIR_albedo, - emissivity = emissivity, - z_0m = z_0m, - z_0b = z_0b, - earth_param_set = earth_param_set, - d_ds = d_ds, + params = ClimaLand.Soil.EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, + PAR_albedo, + NIR_albedo, + emissivity, + z_0m, + z_0b, + d_ds, ) #TODO: Run with higher resolution once we have the implicit stepper diff --git a/ext/CreateParametersExt.jl b/ext/CreateParametersExt.jl index 0acb64cc2d..81986b4ddf 100644 --- a/ext/CreateParametersExt.jl +++ b/ext/CreateParametersExt.jl @@ -1,5 +1,6 @@ module CreateParametersExt +import ClimaCore import Thermodynamics.Parameters.ThermodynamicsParameters import Insolation.Parameters.InsolationParameters import SurfaceFluxes.Parameters.SurfaceFluxesParameters @@ -12,10 +13,14 @@ import ClimaLand.Canopy.AutotrophicRespirationParameters import ClimaLand.Canopy.FarquharParameters import ClimaLand.Canopy.OptimalityFarquharParameters -LandParameters(::Type{FT}) where {FT <: AbstractFloat} = - LandParameters(CP.create_toml_dict(FT)) +import ClimaLand.Soil +import ClimaLand.Parameters as LP +import ClimaLand.Soil.EnergyHydrologyParameters -function LandParameters(toml_dict::CP.AbstractTOMLDict) +LP.LandParameters(::Type{FT}) where {FT <: AbstractFloat} = + LP.LandParameters(CP.create_toml_dict(FT)) + +function LP.LandParameters(toml_dict::CP.AbstractTOMLDict) thermo_params = ThermodynamicsParameters(toml_dict) TP = typeof(thermo_params) @@ -46,9 +51,9 @@ function LandParameters(toml_dict::CP.AbstractTOMLDict) :stefan_boltzmann_constant => :Stefan, ) - parameters = CP.get_parameter_values(toml_dict, name_map, "ClimaLand") + parameters = CP.get_parameter_values(toml_dict, name_map, "Land") FT = CP.float_type(toml_dict) - return LandParameters{FT, TP, SFP, IP}(; + return LP.LandParameters{FT, TP, SFP, IP}(; parameters..., thermo_params, surf_flux_params, @@ -220,4 +225,154 @@ function OptimalityFarquharParameters(toml_dict; kwargs...) return OptimalityFarquharParameters{FT}(; params..., kwargs..., mechanism) end + +""" + EnergyHydrologyParameters( + ::Type{FT}; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, + kwargs...,) + + EnergyHydrologyParameters( + toml_dict; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, + kwargs...,) + +EnergyHydrologyParameters has two constructors: float-type and toml dict based. +Additional parameters must be added manually: ν, ν_ss_om, ν_ss_quartz, ν_ss_gravel, hydrology_cm, K_sat, S_s, and θ_r +All parameters can be manually overriden via keyword arguments. +""" +function EnergyHydrologyParameters( + ::Type{FT}; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, + kwargs..., +) where {FT <: AbstractFloat} + return EnergyHydrologyParameters( + CP.create_toml_dict(FT); + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, + kwargs..., + ) +end + +function EnergyHydrologyParameters( + toml_dict::CP.AbstractTOMLDict; + ν::F, + ν_ss_om::F, + ν_ss_quartz::F, + ν_ss_gravel::F, + hydrology_cm::C, + K_sat::F, + S_s::F, + θ_r::F, + PAR_albedo = 0.2, + NIR_albedo = 0.4, + kwargs..., +) where {F <: Union{<:AbstractFloat, ClimaCore.Fields.FieldVector}, C} + earth_param_set = LP.LandParameters(toml_dict) + + # Obtain parameters needed to calculate the derived parameters + derived_param_name_map = (; + :thermal_conductivity_of_quartz => :κ_quartz, + :thermal_conductivity_of_soil_minerals => :κ_minerals, + :thermal_conductivity_of_water_ice => :κ_ice, + :thermal_conductivity_of_liquid_water => :κ_liq, + :thermal_conductivity_of_organic_matter => :κ_om, + :particle_density_quartz => :ρp_quartz, + :particle_density_minerals => :ρp_minerals, + :particle_density_organic_matter => :ρp_om, + :vol_heat_capacity_quartz => :ρc_quartz, + :vol_heat_capacity_organic_matter => :ρc_om, + :vol_heat_capacity_minerals => :ρc_minerals, + ) + p = CP.get_parameter_values(toml_dict, derived_param_name_map, "Land") + # Particle density of the soil - per unit soil solids + # Denoted ρ_ds in the Clima Design Docs (Equation 2.3) + # where ν_ss_i = ν_i/(1-ν) + ρp = @. ( + ν_ss_om * p.ρp_om + + ν_ss_quartz * p.ρp_quartz + + ν_ss_gravel * p.ρp_minerals + + (1 - ν_ss_om - ν_ss_quartz - ν_ss_gravel) * p.ρp_minerals + ) + # Volumetric heat capacity of soil solids - per unit volume soil solids + # This is Equation 2.6a/2.10 in the Clima Design Docs + # where ν_ss_i = ν_i/(1-ν) + ρc_ss = @. ( + ν_ss_om * p.ρc_om + + ν_ss_quartz * p.ρc_quartz + + ν_ss_gravel * p.ρc_minerals + + (1 - ν_ss_om - ν_ss_quartz - ν_ss_gravel) * p.ρc_minerals + ) + # Volumetric heat capacity of dry soil - per unit volume of soil + # This is denoted č_ds (Equation 2.11) and is used in equation 2.9 + ρc_ds = @. (1 - ν) * ρc_ss + + κ_solid = + Soil.κ_solid.(ν_ss_om, ν_ss_quartz, p.κ_om, p.κ_quartz, p.κ_minerals) + κ_dry = Soil.κ_dry.(ρp, ν, κ_solid, LP.K_therm(earth_param_set)) + κ_sat_frozen = Soil.κ_sat_frozen.(κ_solid, ν, p.κ_ice) + κ_sat_unfrozen = Soil.κ_sat_unfrozen.(κ_solid, ν, p.κ_liq) + + name_map = (; + :kersten_number_alpha => :α, + :kersten_number_beta => :β, + :ice_impedance_omega => :Ω, + :temperature_factor_soil_hydraulic_conductivity => :γ, + :temperature_reference_soil_hydraulic_conductivity => :γT_ref, + :emissivity_bare_soil => :emissivity, + :maximum_dry_soil_layer_depth => :d_ds, + :soil_momentum_roughness_length => :z_0m, + :soil_scalar_roughness_length => :z_0b, + ) + parameters = CP.get_parameter_values(toml_dict, name_map, "Land") + PSE = typeof(earth_param_set) + FT = CP.float_type(toml_dict) + EnergyHydrologyParameters{FT, F, C, PSE}(; + PAR_albedo, + NIR_albedo, + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, + κ_dry, + κ_sat_frozen, + κ_sat_unfrozen, + ρc_ds, + earth_param_set, + parameters..., + kwargs..., + ) +end + end diff --git a/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-Ha1/US-Ha1_parameters.jl b/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-Ha1/US-Ha1_parameters.jl index ec4af87b2d..efb91080a3 100644 --- a/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-Ha1/US-Ha1_parameters.jl +++ b/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-Ha1/US-Ha1_parameters.jl @@ -87,21 +87,21 @@ function soil_harvard(; NIR_albedo = FT(0.2), ) hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n) - return EnergyHydrologyParameters{FT}(; # here, calls the src function, not the src struct - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hydrology_cm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - PAR_albedo = PAR_albedo, - NIR_albedo = NIR_albedo, - emissivity = emissivity, - z_0m = z_0m, - z_0b = z_0b, - earth_param_set = earth_param_set, + return EnergyHydrologyParameters( + FT; # here, calls the src function, not the src struct + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, + PAR_albedo, + NIR_albedo, + emissivity, + z_0m, + z_0b, ) end diff --git a/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-MOz/US-MOz_parameters.jl b/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-MOz/US-MOz_parameters.jl index 4b4b2f542e..ed0c561cf7 100644 --- a/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-MOz/US-MOz_parameters.jl +++ b/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-MOz/US-MOz_parameters.jl @@ -87,21 +87,21 @@ function soil_ozark(; # Function that returns the src function, but with ozark d NIR_albedo = FT(0.2), ) hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n) - return EnergyHydrologyParameters{FT}(; # here, calls the src function, not the src struct - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hydrology_cm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - PAR_albedo = PAR_albedo, - NIR_albedo = NIR_albedo, - emissivity = emissivity, - z_0m = z_0m, - z_0b = z_0b, - earth_param_set = earth_param_set, + return EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, + PAR_albedo, + NIR_albedo, + emissivity, + z_0m, + z_0b, ) end diff --git a/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-NR1/US-NR1_parameters.jl b/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-NR1/US-NR1_parameters.jl index 597399e09f..6fc61f14b7 100644 --- a/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-NR1/US-NR1_parameters.jl +++ b/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-NR1/US-NR1_parameters.jl @@ -87,21 +87,21 @@ function soil_niwotridge(; NIR_albedo = FT(0.2), ) hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n) - return EnergyHydrologyParameters{FT}(; # here, calls the src function, not the src struct - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hydrology_cm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - PAR_albedo = PAR_albedo, - NIR_albedo = NIR_albedo, - emissivity = emissivity, - z_0m = z_0m, - z_0b = z_0b, - earth_param_set = earth_param_set, + return EnergyHydrologyParameters( + FT; # here, calls the src function, not the src struct + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, + PAR_albedo, + NIR_albedo, + emissivity, + z_0m, + z_0b, ) end diff --git a/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-Var/US-Var_parameters.jl b/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-Var/US-Var_parameters.jl index 18b3ca26b5..120d9ab952 100644 --- a/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-Var/US-Var_parameters.jl +++ b/lib/ClimaLandSimulations/src/Fluxnet/fluxnet_sites/US-Var/US-Var_parameters.jl @@ -87,21 +87,21 @@ function soil_vairaranch(; NIR_albedo = FT(0.2), ) hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n) - return EnergyHydrologyParameters{FT}(; # here, calls the src function, not the src struct - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hydrology_cm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - PAR_albedo = PAR_albedo, - NIR_albedo = NIR_albedo, - emissivity = emissivity, - z_0m = z_0m, - z_0b = z_0b, - earth_param_set = earth_param_set, + return EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, + PAR_albedo, + NIR_albedo, + emissivity, + z_0m, + z_0b, ) end diff --git a/lib/ClimaLandSimulations/src/Fluxnet/run_fluxnet.jl b/lib/ClimaLandSimulations/src/Fluxnet/run_fluxnet.jl index 9185bf6676..34d3f9cb42 100644 --- a/lib/ClimaLandSimulations/src/Fluxnet/run_fluxnet.jl +++ b/lib/ClimaLandSimulations/src/Fluxnet/run_fluxnet.jl @@ -21,7 +21,8 @@ function run_fluxnet( # Now we set up the model. For the soil model, we pick # a model type and model args: soil_domain = domain.land_domain - soil_ps = Soil.EnergyHydrologyParameters{FT}(; + soil_ps = Soil.EnergyHydrologyParameters( + FT; ν = params.soil.ν, ν_ss_om = params.soil.ν_ss_om, ν_ss_quartz = params.soil.ν_ss_quartz, @@ -30,7 +31,6 @@ function run_fluxnet( K_sat = params.soil.K_sat, S_s = params.soil.S_s, θ_r = params.soil.θ_r, - earth_param_set = earth_param_set, z_0m = params.soil.z_0m, z_0b = params.soil.z_0b, emissivity = params.soil.emissivity, diff --git a/src/standalone/Soil/energy_hydrology.jl b/src/standalone/Soil/energy_hydrology.jl index fd7015bf0c..00c22dfd74 100644 --- a/src/standalone/Soil/energy_hydrology.jl +++ b/src/standalone/Soil/energy_hydrology.jl @@ -9,7 +9,7 @@ A parameter structure for the integrated soil water and energy equation system. $(DocStringExtensions.FIELDS) """ -struct EnergyHydrologyParameters{ +Base.@kwdef struct EnergyHydrologyParameters{ FT <: AbstractFloat, F <: Union{<:AbstractFloat, ClimaCore.Fields.Field}, C, @@ -65,111 +65,6 @@ struct EnergyHydrologyParameters{ earth_param_set::PSE end -function EnergyHydrologyParameters{FT}(; - ν::F, - ν_ss_om::F, - ν_ss_quartz::F, - ν_ss_gravel::F, - hydrology_cm::C, - K_sat::F, - S_s::F, - θ_r::F, - PAR_albedo = FT(0.2), - NIR_albedo = FT(0.4), - emissivity = FT(0.96), - z_0m = FT(0.01), - z_0b = FT(0.01), - d_ds = FT(0.015), - earth_param_set::PSE, -) where {FT, F <: Union{FT, ClimaCore.Fields.FieldVector}, PSE, C} - # All below will be moved to CP - # These were determined in the Balland and Arp paper, from 2003. - α = FT(0.24) - β = FT(18.3) - # Lundin paper - Ω = FT(7) - # Unclear where these are from (design doc) - γ = FT(2.64e-2) - γT_ref = FT(288) - - # Constants from Ballard and Arp paper - will be moved to ClimaParams - κ_minerals = FT(2.5) - κ_om = FT(0.25) - κ_quartz = FT(8.0) - #κ_gravel = κ_minerals implicitly in equation for κ_solid - - ρp_quartz = FT(2.66e3) - ρp_minerals = FT(2.65e3) - ρp_om = FT(1.3e3) - ρp_gravel = ρp_minerals - - ρc_quartz = FT(2.01e6) - ρc_om = FT(2.51e6) - ρc_minerals = FT(2.01e6) - ρc_gravel = ρc_minerals - - # Thermal conductivity of dry air - κ_air = FT(LP.K_therm(earth_param_set)) - κ_ice = FT(2.21) - κ_liq = FT(0.57) - - # Particle density of the soil - per unit soil solids - # Denoted ρ_ds in the Clima Design Docs (Equation 2.3) - # where ν_ss_i = ν_i/(1-ν) - ρp = @. ( - ν_ss_om * ρp_om + - ν_ss_quartz * ρp_quartz + - ν_ss_gravel * ρp_gravel + - (1 - ν_ss_om - ν_ss_quartz - ν_ss_gravel) * ρp_minerals - ) - - # Volumetric heat capacity of soil solids - per unit volume soil solids - # This is Equation 2.6a/2.10 in the Clima Design Docs - # where ν_ss_i = ν_i/(1-ν) - ρc_ss = @. ( - ν_ss_om * ρc_om + - ν_ss_quartz * ρc_quartz + - ν_ss_gravel * ρc_gravel + - (1 - ν_ss_om - ν_ss_quartz - ν_ss_gravel) * ρc_minerals - ) - - # Volumetric heat capacity of dry soil - per unit volume of soil - # This is denoted č_ds (Equation 2.11) and is used in equation 2.9 - ρc_ds = @. (1 - ν) * ρc_ss - - κ_solid = Soil.κ_solid.(ν_ss_om, ν_ss_quartz, κ_om, κ_quartz, κ_minerals) - κ_dry = Soil.κ_dry.(ρp, ν, κ_solid, κ_air) - κ_sat_frozen = Soil.κ_sat_frozen.(κ_solid, ν, κ_ice) - κ_sat_unfrozen = Soil.κ_sat_unfrozen.(κ_solid, ν, κ_liq) - - return EnergyHydrologyParameters{FT, F, C, PSE}( - κ_dry, - κ_sat_frozen, - κ_sat_unfrozen, - ρc_ds, - ν, - ν_ss_om, - ν_ss_quartz, - ν_ss_gravel, - α, - β, - hydrology_cm, - K_sat, - S_s, - θ_r, - Ω, - γ, - γT_ref, - PAR_albedo, - NIR_albedo, - emissivity, - z_0m, - z_0b, - d_ds, - earth_param_set, - ) -end - Base.broadcastable(ps::EnergyHydrologyParameters) = tuple(ps) """ diff --git a/test/integrated/soil_energy_hydrology_biogeochemistry.jl b/test/integrated/soil_energy_hydrology_biogeochemistry.jl index a624d1a5ac..cdd918ac80 100644 --- a/test/integrated/soil_energy_hydrology_biogeochemistry.jl +++ b/test/integrated/soil_energy_hydrology_biogeochemistry.jl @@ -17,22 +17,22 @@ for FT in (Float32, Float64) S_s = FT(1e-3) #inverse meters vg_n = FT(2.0) vg_α = FT(2.6) # inverse meters - hcm = vanGenuchten{FT}(; α = vg_α, n = vg_n) + hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n) θ_r = FT(0.1) ν_ss_om = FT(0.0) ν_ss_quartz = FT(1.0) ν_ss_gravel = FT(0.0) - soil_ps = Soil.EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - K_sat = K_sat, - hydrology_cm = hcm, - S_s = S_s, - θ_r = θ_r, - earth_param_set = earth_param_set, + soil_ps = Soil.EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + K_sat, + hydrology_cm, + S_s, + θ_r, ) zmax = FT(0) zmin = FT(-1) diff --git a/test/standalone/Soil/climate_drivers.jl b/test/standalone/Soil/climate_drivers.jl index 3b26d0730f..4098137c0f 100644 --- a/test/standalone/Soil/climate_drivers.jl +++ b/test/standalone/Soil/climate_drivers.jl @@ -81,21 +81,21 @@ for FT in (Float32, Float64) zero_flux = FluxBC((p, t) -> 0.0) boundary_fluxes = (; top = top_bc, bottom = (water = zero_flux, heat = zero_flux)) - params = ClimaLand.Soil.EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, + params = ClimaLand.Soil.EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, hydrology_cm = hcm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - PAR_albedo = PAR_albedo, - NIR_albedo = NIR_albedo, - emissivity = emissivity, - z_0m = z_0m, - z_0b = z_0b, - earth_param_set = earth_param_set, + K_sat, + S_s, + θ_r, + PAR_albedo, + NIR_albedo, + emissivity, + z_0m, + z_0b, ) for domain in soil_domains diff --git a/test/standalone/Soil/soil_bc.jl b/test/standalone/Soil/soil_bc.jl index 00d3fb8096..3758cbb454 100644 --- a/test/standalone/Soil/soil_bc.jl +++ b/test/standalone/Soil/soil_bc.jl @@ -5,6 +5,7 @@ using ClimaLand using ClimaLand.Soil using ClimaLand.Domains: HybridBox, SphericalShell, Column import ClimaLand.Parameters as LP +import ClimaParams for FT in (Float32, Float64) @testset "WVector usage in gradient, FT = $FT" begin @@ -135,21 +136,22 @@ for FT in (Float32, Float64) S_s = FT(1e-3) #inverse meters vg_n = FT(2.0) vg_α = FT(2.6) # inverse meters - hcm = vanGenuchten{FT}(; α = vg_α, n = vg_n) + hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n) θ_r = FT(0.1) ν_ss_om = FT(0.0) ν_ss_quartz = FT(1.0) ν_ss_gravel = FT(0.0) - parameters = Soil.EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hcm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - earth_param_set = earth_param_set, + + parameters = Soil.EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, ) zmax = FT(0) @@ -197,7 +199,7 @@ end S_s = FT(1e-3) #inverse meters vg_n = FT(2.0) vg_α = FT(2.6) # inverse meters - hcm = vanGenuchten{FT}(; α = vg_α, n = vg_n) + hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n) θ_r = FT(0.1) ν_ss_om = FT(0.0) ν_ss_quartz = FT(1.0) @@ -205,16 +207,16 @@ end κ_minerals = FT(2.5) ρp = FT(2.66 / 1e3 * 1e6) ρc_ds = @. FT(2e6 * (1.0 - ν)) - parameters = Soil.EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hcm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - earth_param_set = earth_param_set, + parameters = Soil.EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, ) zmax = FT(0) zmin = FT(-1) @@ -230,16 +232,16 @@ end bottom = (water = bot_flux_bc, heat = bot_flux_bc), ) - parameters = Soil.EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hcm, + parameters = Soil.EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, K_sat = FT(0), - S_s = S_s, - θ_r = θ_r, - earth_param_set = earth_param_set, + S_s, + θ_r, ) energy_hydrology = Soil.EnergyHydrology{FT}(; parameters = parameters, @@ -287,7 +289,7 @@ end parameters = Soil.RichardsParameters(; ν = ν, - hydrology_cm = hcm, + hydrology_cm, K_sat = FT(0), S_s = S_s, θ_r = θ_r, diff --git a/test/standalone/Soil/soil_parameterizations.jl b/test/standalone/Soil/soil_parameterizations.jl index 6e4814566c..2c6b0d730e 100644 --- a/test/standalone/Soil/soil_parameterizations.jl +++ b/test/standalone/Soil/soil_parameterizations.jl @@ -52,16 +52,16 @@ for FT in (Float32, Float64) κ_ice = FT(2.21) κ_liq = FT(0.57) - parameters = EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, + parameters = EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, hydrology_cm = hcm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - earth_param_set = param_set, + K_sat, + S_s, + θ_r, ) # Test that the preset params are set properly (; α, β, Ω, hydrology_cm, γ, γT_ref) = parameters @@ -308,16 +308,16 @@ for FT in (Float32, Float64) ν_ss_om = FT(0.1) ν_ss_gravel = FT(0.1) ν_ss_quartz = FT(0.1) - parameters = EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, + parameters = EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, hydrology_cm = hcm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - earth_param_set = param_set, + K_sat, + S_s, + θ_r, ) Δz = FT(1.0) diff --git a/test/standalone/Soil/soil_test_3d.jl b/test/standalone/Soil/soil_test_3d.jl index c8047fd39e..c996404eb1 100644 --- a/test/standalone/Soil/soil_test_3d.jl +++ b/test/standalone/Soil/soil_test_3d.jl @@ -240,21 +240,21 @@ for FT in (Float32, Float64) vg_n = FT(2.68) vg_α = FT(14.5) # inverse meters vg_m = 1 - 1 / vg_n - hcm = vanGenuchten{FT}(; α = vg_α, n = vg_n) + hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n) θ_r = FT(0.045) ν_ss_om = FT(0.0) ν_ss_quartz = FT(1.0) ν_ss_gravel = FT(0.0) - parameters = Soil.EnergyHydrologyParameters{FT}( - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hcm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - earth_param_set = earth_param_set, + parameters = Soil.EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, ) zmax = FT(0) zmin = FT(-1) diff --git a/test/standalone/Soil/soiltest.jl b/test/standalone/Soil/soiltest.jl index 4a77c73277..ea1a562fd5 100644 --- a/test/standalone/Soil/soiltest.jl +++ b/test/standalone/Soil/soiltest.jl @@ -92,7 +92,7 @@ for FT in (Float32, Float64) vg_n = FT(2.0) vg_α = FT(2.6) # inverse meters vg_m = FT(1) - FT(1) / vg_n - hcm = vanGenuchten{FT}(; α = vg_α, n = vg_n) + hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n) θ_r = FT(0.1) ν_ss_om = FT(0.0) ν_ss_quartz = FT(1.0) @@ -115,16 +115,16 @@ for FT in (Float32, Float64) ### - hyd_off_en_on = Soil.EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hcm, + hyd_off_en_on = Soil.EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, K_sat = FT(0), - S_s = S_s, - θ_r = θ_r, - earth_param_set = earth_param_set, + S_s, + θ_r, ) soil_heat_on = Soil.EnergyHydrology{FT}(; parameters = hyd_off_en_on, @@ -184,7 +184,7 @@ for FT in (Float32, Float64) hyd_on_en_off = Soil.EnergyHydrologyParameters{ FT, FT, - typeof(hcm), + typeof(hydrology_cm), typeof(earth_param_set), }( FT(0), # κ_dry @@ -197,17 +197,17 @@ for FT in (Float32, Float64) ν_ss_gravel, FT(0.24), #α FT(18.3), #β - hcm, + hydrology_cm, K_sat, S_s, θ_r, - FT(7),#Ω - FT(2.64e-2),#γ - FT(288),#γT_ref - FT(0.2),# NIR_albedo - FT(0.2), #PAR_albedo - FT(0.96),#ϵ - FT(0.001),# z_0m + FT(7), # Ω + FT(2.64e-2), # γ + FT(288), # γT_ref + FT(0.2), # NIR_albedo + FT(0.2), # PAR_albedo + FT(0.96), # ϵ + FT(0.001), # z_0m FT(0.01), # z_0b FT(0.015), #d_ds earth_param_set, @@ -356,7 +356,7 @@ for FT in (Float32, Float64) hyd_off_en_off = Soil.EnergyHydrologyParameters{ FT, FT, - typeof(hcm), + typeof(hydrology_cm), typeof(earth_param_set), }( FT(0), # κ_dry @@ -369,7 +369,7 @@ for FT in (Float32, Float64) ν_ss_gravel, FT(0.24), #α FT(18.3), #β - hcm, + hydrology_cm, FT(0), # K_sat S_s, θ_r, @@ -429,16 +429,16 @@ for FT in (Float32, Float64) ### Test with both energy and hydrology on - hyd_on_en_on = Soil.EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hcm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - earth_param_set = earth_param_set, + hyd_on_en_on = Soil.EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, ) soil_both_on = Soil.EnergyHydrology{FT}(; @@ -548,7 +548,7 @@ for FT in (Float32, Float64) S_s = FT(1e-3) #inverse meters vg_n = FT(2.0) vg_α = FT(2.6) # inverse meters - hcm = vanGenuchten{FT}(; α = vg_α, n = vg_n) + hydrology_cm = vanGenuchten{FT}(; α = vg_α, n = vg_n) θ_r = FT(0.1) ν_ss_om = FT(0.0) ν_ss_quartz = FT(1.0) @@ -570,16 +570,16 @@ for FT in (Float32, Float64) sources = (PhaseChange{FT}(Δz),) ### - hyd_off_en_on = Soil.EnergyHydrologyParameters{FT}(; - ν = ν, - ν_ss_om = ν_ss_om, - ν_ss_quartz = ν_ss_quartz, - ν_ss_gravel = ν_ss_gravel, - hydrology_cm = hcm, - K_sat = K_sat, - S_s = S_s, - θ_r = θ_r, - earth_param_set = earth_param_set, + hyd_off_en_on = Soil.EnergyHydrologyParameters( + FT; + ν, + ν_ss_om, + ν_ss_quartz, + ν_ss_gravel, + hydrology_cm, + K_sat, + S_s, + θ_r, ) soil_heat_on = Soil.EnergyHydrology{FT}(; parameters = hyd_off_en_on,